1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-16 04:37:33 +01:00

Code cleanup and bug fixes

This commit is contained in:
mamutcho 2019-12-21 18:48:19 +02:00
parent cfa0b6bf21
commit e6049438e7
6 changed files with 31 additions and 32 deletions

View File

@ -51,7 +51,7 @@ public final class WatchXPlusConstants extends LenovoWatchConstants {
public static final String PREF_LONGSIT_SWITCH = "pref_watchxplus_longsit_switch"; public static final String PREF_LONGSIT_SWITCH = "pref_watchxplus_longsit_switch";
public static final String PREF_LONGSIT_PERIOD = "pref_watchxplus_longsit_period"; public static final String PREF_LONGSIT_PERIOD = "pref_watchxplus_longsit_period";
public static final String PREF_WXP_LANGUAGE = "pref_wxp_language"; public static final String PREF_WXP_LANGUAGE = "pref_wxp_language";
public static final String PREF_POWER_MODE = "pref_wxp_power_mode"; public static final String PREF_POWER_MODE = "pref_wxp_power";
// time format constants // time format constants

View File

@ -12,10 +12,13 @@ import nodomain.freeyourgadget.gadgetbridge.entities.WatchXPlusActivitySampleDao
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class WatchXPlusSampleProvider extends AbstractSampleProvider<WatchXPlusActivitySample> { public class WatchXPlusSampleProvider extends AbstractSampleProvider<WatchXPlusActivitySample> {
private GBDevice mDevice;
private DaoSession mSession;
public WatchXPlusSampleProvider(GBDevice device, DaoSession session) { public WatchXPlusSampleProvider(GBDevice device, DaoSession session) {
super(device, session); super(device, session);
mSession = session;
mDevice = device;
} }
@Override @Override

View File

@ -65,7 +65,7 @@ public class Watch9DeviceCoordinator extends AbstractDeviceCoordinator {
return DeviceType.WATCH9; return DeviceType.WATCH9;
// add support for Watch X non-plus (same MAC address) // add support for Watch X non-plus (same MAC address)
// add support for Watch X Plus (same MAC address) // add support for Watch X Plus (same MAC address)
} else if ((macAddress.startsWith("1C:87:79")) && ((!deviceName.equalsIgnoreCase("WATCH X")) || (!deviceName.equalsIgnoreCase("WATCH XPLUS")))) { } else if ((macAddress.startsWith("1C:87:79")) && ((!deviceName.equalsIgnoreCase("WATCH X")) && (!deviceName.equalsIgnoreCase("WATCH XPLUS")))) {
return DeviceType.WATCH9; return DeviceType.WATCH9;
} else if (deviceName.equals("WATCH 9")) { } else if (deviceName.equals("WATCH 9")) {
return DeviceType.WATCH9; return DeviceType.WATCH9;

View File

@ -90,6 +90,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
import static android.content.Context.MODE_PRIVATE;
public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
private static final Prefs prefs = GBApplication.getPrefs(); private static final Prefs prefs = GBApplication.getPrefs();
@ -471,7 +473,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
private boolean isRinging = false; // store ringing state private boolean isRinging = false; // store ringing state
private boolean outCall = false; // store outgoing call state
private boolean isMissedCall = false; // missed call state private boolean isMissedCall = false; // missed call state
private int remainingRepeats = 0; // initialize call notification reminds private int remainingRepeats = 0; // initialize call notification reminds
private int remainingMissedRepeats = 0; // initialize missed call notification reminds private int remainingMissedRepeats = 0; // initialize missed call notification reminds
@ -488,10 +489,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
public void onSetCallState(final CallSpec callSpec) { public void onSetCallState(final CallSpec callSpec) {
final int repeatDelay = 5000; // repeat delay of 5 sec (watch show call notifications for about 5 sec.) final int repeatDelay = 5000; // repeat delay of 5 sec (watch show call notifications for about 5 sec.)
final int repeatMissedDelay = 60000; // repeat missed call delay of 60 sec final int repeatMissedDelay = 60000; // repeat missed call delay of 60 sec
// get settings for continuous vibration while phone rings
final boolean continuousRing = WatchXPlusDeviceCoordinator.getContiniousVibrationOnCall();
// set settings for missed call // set settings for missed call
boolean missedCall = WatchXPlusDeviceCoordinator.getMissedCallReminder();
int repeatCount = WatchXPlusDeviceCoordinator.getRepeatOnCall(); int repeatCount = WatchXPlusDeviceCoordinator.getRepeatOnCall();
int repeatCountMissed = WatchXPlusDeviceCoordinator.getMissedCallRepeat(); int repeatCountMissed = WatchXPlusDeviceCoordinator.getMissedCallRepeat();
// check if repeatCount is in boundaries min=0, max=10 // check if repeatCount is in boundaries min=0, max=10
@ -504,12 +502,13 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
switch (callSpec.command) { switch (callSpec.command) {
case CallSpec.CALL_INCOMING: case CallSpec.CALL_INCOMING:
isRinging = true; isRinging = true;
isMissedCall = false;
remainingRepeats = repeatCount; remainingRepeats = repeatCount;
LOG.info(" Incomming call "); LOG.info(" Incomming call ");
if (("Phone".equals(callSpec.name)) || (callSpec.name.contains("ropusn")) || (callSpec.name.contains("issed"))) { if (("Phone".equals(callSpec.name)) || (callSpec.name.contains("ropusn")) || (callSpec.name.contains("issed"))) {
// do nothing for notifications without caller name, e.g. system call event // do nothing for notifications without caller name, e.g. system call event
} else { } else {
// possible missed call
isMissedCall = true;
// send first notification // send first notification
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, callSpec.name); sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, callSpec.name);
// init repeat handler // init repeat handler
@ -517,7 +516,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
public void run() { public void run() {
// Actions to do after repeatDelay seconds // Actions to do after repeatDelay seconds
if (((isRinging) && (remainingRepeats > 0)) || ((isRinging) && (continuousRing))) { if (((isRinging) && (remainingRepeats > 0)) || ((isRinging) && (WatchXPlusDeviceCoordinator.getContiniousVibrationOnCall()))) {
remainingRepeats = remainingRepeats - 1; remainingRepeats = remainingRepeats - 1;
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, callSpec.name); sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, callSpec.name);
// re-run handler // re-run handler
@ -534,43 +533,37 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
break; break;
case CallSpec.CALL_START: case CallSpec.CALL_START:
isRinging = false; isRinging = false;
outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Call start "); LOG.info(" Call start ");
break; break;
case CallSpec.CALL_REJECT: case CallSpec.CALL_REJECT:
isRinging = false; isRinging = false;
outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Call reject "); LOG.info(" Call reject ");
break; break;
case CallSpec.CALL_ACCEPT: case CallSpec.CALL_ACCEPT:
isRinging = false; isRinging = false;
outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Call accept "); LOG.info(" Call accept ");
break; break;
case CallSpec.CALL_OUTGOING: case CallSpec.CALL_OUTGOING:
outCall = true;
isRinging = false; isRinging = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Outgoing call "); LOG.info(" Outgoing call ");
break; break;
case CallSpec.CALL_END: case CallSpec.CALL_END:
if ((isRinging) && (!outCall)) { LOG.info(" End call ");
LOG.info(" End call "); isRinging = false;
// it's a missed call, don't clear notification to preserve small icon near bluetooth // it's a missed call, don't clear notification to preserve small icon near bluetooth
isRinging = false; if (isMissedCall) {
outCall = false;
isMissedCall = true;
remainingMissedRepeats = repeatCountMissed; remainingMissedRepeats = repeatCountMissed;
// send missed call notification if enabled in settings // send missed call notification if enabled in settings
if (missedCall) { if (WatchXPlusDeviceCoordinator.getMissedCallReminder()) {
LOG.info(" Missed call "); LOG.info(" Missed call reminder ");
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call"); sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call");
// repeat missed call notification // repeat missed call notification
final Handler handler = new Handler(); final Handler handler = new Handler();
@ -580,10 +573,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
if ((isMissedCall) && (remainingMissedRepeats > 0)) { if ((isMissedCall) && (remainingMissedRepeats > 0)) {
remainingMissedRepeats = remainingMissedRepeats - 1; remainingMissedRepeats = remainingMissedRepeats - 1;
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call"); sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call");
LOG.info(" Missed call reminder repeats to go: " + remainingMissedRepeats);
// re-run handler // re-run handler
handler.postDelayed(this, repeatMissedDelay); handler.postDelayed(this, repeatMissedDelay);
} else { } else {
remainingMissedRepeats = 0; remainingMissedRepeats = 0;
LOG.info(" Missed call reminder repeats to go: " + remainingMissedRepeats);
isMissedCall = false; isMissedCall = false;
// stop handler // stop handler
handler.removeCallbacks(this); handler.removeCallbacks(this);
@ -591,10 +586,13 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} }
} }
}, repeatMissedDelay); }, repeatMissedDelay);
} else {
remainingMissedRepeats = 0;
isMissedCall = false;
cancelNotification();
} }
} else { } else {
isRinging = false; isRinging = false;
outCall = false;
isMissedCall = false; isMissedCall = false;
cancelNotification(); cancelNotification();
LOG.info(" Outgoing call end "); LOG.info(" Outgoing call end ");
@ -1016,6 +1014,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (IOException e) { } catch (IOException e) {
LOG.warn("Unable to set power mode", e); LOG.warn("Unable to set power mode", e);
} }
//prefs.getPreferences().edit().putInt("PREF_POWER_MODE", 0).apply();
} }
/** request watch units /** request watch units

View File

@ -197,11 +197,8 @@
<string name="pref_wxp_title_repeat_on_call">Repeat call notification</string> <string name="pref_wxp_title_repeat_on_call">Repeat call notification</string>
<string name="pref_wxp_title_repeat_on_call_summary">Possible values min=0, max=10</string> <string name="pref_wxp_title_repeat_on_call_summary">Possible values min=0, max=10</string>
<string name="prefs_wxp_continious">Vibration during phone ring</string> <string name="prefs_wxp_continious">Vibration during phone ring</string>
<string name="prefs_wxp_missed">Vibration on missed call</string>
<string name="preferences_watchxplus_settings">Watch X Plus settings</string> <string name="preferences_watchxplus_settings">Watch X Plus settings</string>
<string name="pref_header_wxp_call_notification">Notifications and Calls</string> <string name="pref_header_wxp_call_notification">Notifications and Calls</string>
<string name="pref_header_wxp_notification_call">Call notifications</string>
<string name="pref_header_wxp_notification_misscall">MissCall notifications</string>
<string name="pref_wxp_title_reject_summary">Off - ignore, On - reject</string> <string name="pref_wxp_title_reject_summary">Off - ignore, On - reject</string>
<string name="prefs_wxp_reject">Button ignore/reject call</string> <string name="prefs_wxp_reject">Button ignore/reject call</string>
<string name="pref_wxp_title_shake_reject_summary">Duplicates watch button action</string> <string name="pref_wxp_title_shake_reject_summary">Duplicates watch button action</string>

View File

@ -5,9 +5,9 @@
android:title="@string/pref_header_wxp_call_notification"> android:title="@string/pref_header_wxp_call_notification">
<PreferenceScreen <PreferenceScreen
android:key="pref_category_watchxplus_ringing" android:key="pref_category_watchxplus_ringing"
android:title="@string/pref_header_wxp_notification_call"> android:title="@string/pref_screen_notification_profile_incoming_call">
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_header_wxp_notification_call"/> android:title="@string/pref_screen_notification_profile_incoming_call"/>
<EditTextPreference <EditTextPreference
android:defaultValue="0" android:defaultValue="0"
android:key="watchxplus_repeat" android:key="watchxplus_repeat"
@ -21,9 +21,9 @@
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen
android:key="pref_category_watchxplus_miss" android:key="pref_category_watchxplus_miss"
android:title="@string/pref_header_wxp_notification_misscall"> android:title="@string/pref_screen_notification_profile_missed_call">
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_header_wxp_notification_misscall"/> android:title="@string/pref_screen_notification_profile_missed_call"/>
<EditTextPreference <EditTextPreference
android:defaultValue="0" android:defaultValue="0"
android:key="watchxplus_repeat_missedcall" android:key="watchxplus_repeat_missedcall"
@ -33,7 +33,7 @@
android:layout="@layout/preference_checkbox" android:layout="@layout/preference_checkbox"
android:defaultValue="false" android:defaultValue="false"
android:key="watchxplus_missed" android:key="watchxplus_missed"
android:title="@string/prefs_wxp_missed" /> android:title="@string/pref_screen_notification_profile_incoming_call" />
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen
android:key="pref_category_watchxplus_callhandling" android:key="pref_category_watchxplus_callhandling"
@ -63,7 +63,7 @@
android:title="@string/wxp_power_mode_title" android:title="@string/wxp_power_mode_title"
android:entries="@array/wxp_mode" android:entries="@array/wxp_mode"
android:entryValues="@array/wxp_mode_values" android:entryValues="@array/wxp_mode_values"
android:key="pref_wxp_power_mode" android:key="pref_wxp_power"
android:summary="%s" /> android:summary="%s" />
<ListPreference <ListPreference
android:defaultValue="1" android:defaultValue="1"
@ -123,4 +123,4 @@
android:summary="@string/prefs_wxp_button_bp_calibration_sum" /> android:summary="@string/prefs_wxp_button_bp_calibration_sum" />
</PreferenceScreen> </PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>