mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 16:15:55 +01:00
WIP: Work towards SMS replies / canned replies, round 3
- put random id/phone number pair into limited lookup list (last 16 sms messages) when sms arrives - lookup the phone number when replying from the a device THIS STILL DOES NOT DO ANYTHING USEFUL
This commit is contained in:
parent
14f8929439
commit
de5f30ae97
@ -1,7 +1,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import android.app.Application;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -26,11 +25,11 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBConstants;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.IDSenderLookup;
|
||||
|
||||
/**
|
||||
* Main Application class that initializes and provides access to certain things like
|
||||
@ -44,6 +43,7 @@ public class GBApplication extends Application {
|
||||
private static final Lock dbLock = new ReentrantLock();
|
||||
private static DeviceService deviceService;
|
||||
private static SharedPreferences sharedPrefs;
|
||||
private static IDSenderLookup mIDSenderLookup = new IDSenderLookup();
|
||||
|
||||
public static final String ACTION_QUIT
|
||||
= "nodomain.freeyourgadget.gadgetbridge.gbapplication.action.quit";
|
||||
@ -189,6 +189,7 @@ public class GBApplication extends Application {
|
||||
public static boolean isRunningOnKitkatOrLater() {
|
||||
return VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
}
|
||||
|
||||
public static boolean isRunningLollipopOrLater() {
|
||||
return VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
}
|
||||
@ -226,6 +227,7 @@ public class GBApplication extends Application {
|
||||
|
||||
/**
|
||||
* Deletes the entire Activity database and recreates it with empty tables.
|
||||
*
|
||||
* @return true on successful deletion
|
||||
*/
|
||||
public static synchronized boolean deleteActivityDatabase() {
|
||||
@ -237,4 +239,8 @@ public class GBApplication extends Application {
|
||||
mActivityDatabaseHandler = new ActivityDatabaseHandler(getContext());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IDSenderLookup getIDSenderLookup() {
|
||||
return mIDSenderLookup;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class DebugActivity extends Activity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
NotificationSpec notificationSpec = new NotificationSpec();
|
||||
notificationSpec.phoneNumber = getResources().getText(R.string.app_name).toString();
|
||||
notificationSpec.phoneNumber = editContent.getText().toString();
|
||||
notificationSpec.body = editContent.getText().toString();
|
||||
notificationSpec.type = NotificationType.SMS;
|
||||
notificationSpec.id = -1;
|
||||
|
@ -20,6 +20,7 @@ import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AppManagerActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsHost;
|
||||
@ -227,7 +228,10 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
action = NotificationListener.ACTION_MUTE;
|
||||
break;
|
||||
case REPLY:
|
||||
GB.toast(context, "got notfication reply: " + deviceEvent.reply, 2, GB.INFO);
|
||||
String phoneNumber = GBApplication.getIDSenderLookup().lookup(deviceEvent.handle);
|
||||
if (phoneNumber != null) {
|
||||
GB.toast(context, "got notfication reply for " + phoneNumber + " : " + deviceEvent.reply, 2, GB.INFO);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (action != null) {
|
||||
|
@ -21,8 +21,10 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.K9Receiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.MusicPlaybackReceiver;
|
||||
@ -37,6 +39,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.IDSenderLookup;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CALLSTATE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
||||
@ -94,6 +97,8 @@ public class DeviceCommunicationService extends Service {
|
||||
private MusicPlaybackReceiver mMusicPlaybackReceiver = null;
|
||||
private TimeChangeReceiver mTimeChangeReceiver = null;
|
||||
|
||||
private Random mRandom = new Random();
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@ -218,6 +223,9 @@ public class DeviceCommunicationService extends Service {
|
||||
if (notificationSpec.type == NotificationType.SMS && notificationSpec.phoneNumber != null) {
|
||||
notificationSpec.sender = getContactDisplayNameByNumber(notificationSpec.phoneNumber);
|
||||
|
||||
notificationSpec.id = mRandom.nextInt(); // FIXME: add this in external SMS Receiver?
|
||||
GBApplication.getIDSenderLookup().add(notificationSpec.id, notificationSpec.phoneNumber);
|
||||
|
||||
// NOTE: maybe not where it belongs
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (sharedPrefs.getBoolean("pebble_force_untested", false)) {
|
||||
|
@ -398,7 +398,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
|
||||
@Override
|
||||
public byte[] encodeNotification(NotificationSpec notificationSpec) {
|
||||
boolean hasHandle = notificationSpec.id != -1;
|
||||
boolean hasHandle = notificationSpec.id != -1 && notificationSpec.phoneNumber == null;
|
||||
int id = notificationSpec.id != -1 ? notificationSpec.id : mRandom.nextInt();
|
||||
String title;
|
||||
String subtitle = null;
|
||||
|
@ -0,0 +1,26 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import android.util.Pair;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class IDSenderLookup {
|
||||
private static final int LIMIT = 16;
|
||||
private LinkedList<Pair> list = new LinkedList<>();
|
||||
|
||||
public void add(int id, String sender) {
|
||||
if (list.size() > LIMIT - 1) {
|
||||
list.removeFirst();
|
||||
}
|
||||
list.add(new Pair<>(id, sender));
|
||||
}
|
||||
|
||||
public String lookup(int id) {
|
||||
for (Pair entry : list) {
|
||||
if (id == (Integer) entry.first) {
|
||||
return (String) entry.second;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user