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_PERIOD = "pref_watchxplus_longsit_period";
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

View File

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

View File

@ -65,7 +65,7 @@ public class Watch9DeviceCoordinator extends AbstractDeviceCoordinator {
return DeviceType.WATCH9;
// add support for Watch X non-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;
} else if (deviceName.equals("WATCH 9")) {
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.StringUtils;
import static android.content.Context.MODE_PRIVATE;
public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
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 outCall = false; // store outgoing call state
private boolean isMissedCall = false; // missed call state
private int remainingRepeats = 0; // initialize 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) {
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
// get settings for continuous vibration while phone rings
final boolean continuousRing = WatchXPlusDeviceCoordinator.getContiniousVibrationOnCall();
// set settings for missed call
boolean missedCall = WatchXPlusDeviceCoordinator.getMissedCallReminder();
int repeatCount = WatchXPlusDeviceCoordinator.getRepeatOnCall();
int repeatCountMissed = WatchXPlusDeviceCoordinator.getMissedCallRepeat();
// check if repeatCount is in boundaries min=0, max=10
@ -504,12 +502,13 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
switch (callSpec.command) {
case CallSpec.CALL_INCOMING:
isRinging = true;
isMissedCall = false;
remainingRepeats = repeatCount;
LOG.info(" Incomming call ");
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
} else {
// possible missed call
isMissedCall = true;
// send first notification
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, callSpec.name);
// init repeat handler
@ -517,7 +516,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
handler.postDelayed(new Runnable() {
public void run() {
// Actions to do after repeatDelay seconds
if (((isRinging) && (remainingRepeats > 0)) || ((isRinging) && (continuousRing))) {
if (((isRinging) && (remainingRepeats > 0)) || ((isRinging) && (WatchXPlusDeviceCoordinator.getContiniousVibrationOnCall()))) {
remainingRepeats = remainingRepeats - 1;
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, callSpec.name);
// re-run handler
@ -534,43 +533,37 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
break;
case CallSpec.CALL_START:
isRinging = false;
outCall = false;
isMissedCall = false;
cancelNotification();
LOG.info(" Call start ");
break;
case CallSpec.CALL_REJECT:
isRinging = false;
outCall = false;
isMissedCall = false;
cancelNotification();
LOG.info(" Call reject ");
break;
case CallSpec.CALL_ACCEPT:
isRinging = false;
outCall = false;
isMissedCall = false;
cancelNotification();
LOG.info(" Call accept ");
break;
case CallSpec.CALL_OUTGOING:
outCall = true;
isRinging = false;
isMissedCall = false;
cancelNotification();
LOG.info(" Outgoing call ");
break;
case CallSpec.CALL_END:
if ((isRinging) && (!outCall)) {
LOG.info(" End call ");
// it's a missed call, don't clear notification to preserve small icon near bluetooth
isRinging = false;
outCall = false;
isMissedCall = true;
LOG.info(" End call ");
isRinging = false;
// it's a missed call, don't clear notification to preserve small icon near bluetooth
if (isMissedCall) {
remainingMissedRepeats = repeatCountMissed;
// send missed call notification if enabled in settings
if (missedCall) {
LOG.info(" Missed call ");
if (WatchXPlusDeviceCoordinator.getMissedCallReminder()) {
LOG.info(" Missed call reminder ");
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call");
// repeat missed call notification
final Handler handler = new Handler();
@ -580,10 +573,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
if ((isMissedCall) && (remainingMissedRepeats > 0)) {
remainingMissedRepeats = remainingMissedRepeats - 1;
sendNotification(WatchXPlusConstants.NOTIFICATION_CHANNEL_PHONE_CALL, "Missed call");
LOG.info(" Missed call reminder repeats to go: " + remainingMissedRepeats);
// re-run handler
handler.postDelayed(this, repeatMissedDelay);
} else {
remainingMissedRepeats = 0;
LOG.info(" Missed call reminder repeats to go: " + remainingMissedRepeats);
isMissedCall = false;
// stop handler
handler.removeCallbacks(this);
@ -591,10 +586,13 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
}
}
}, repeatMissedDelay);
} else {
remainingMissedRepeats = 0;
isMissedCall = false;
cancelNotification();
}
} else {
isRinging = false;
outCall = false;
isMissedCall = false;
cancelNotification();
LOG.info(" Outgoing call end ");
@ -1016,6 +1014,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (IOException e) {
LOG.warn("Unable to set power mode", e);
}
//prefs.getPreferences().edit().putInt("PREF_POWER_MODE", 0).apply();
}
/** 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_summary">Possible values min=0, max=10</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="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="prefs_wxp_reject">Button ignore/reject call</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">
<PreferenceScreen
android:key="pref_category_watchxplus_ringing"
android:title="@string/pref_header_wxp_notification_call">
android:title="@string/pref_screen_notification_profile_incoming_call">
<PreferenceCategory
android:title="@string/pref_header_wxp_notification_call"/>
android:title="@string/pref_screen_notification_profile_incoming_call"/>
<EditTextPreference
android:defaultValue="0"
android:key="watchxplus_repeat"
@ -21,9 +21,9 @@
</PreferenceScreen>
<PreferenceScreen
android:key="pref_category_watchxplus_miss"
android:title="@string/pref_header_wxp_notification_misscall">
android:title="@string/pref_screen_notification_profile_missed_call">
<PreferenceCategory
android:title="@string/pref_header_wxp_notification_misscall"/>
android:title="@string/pref_screen_notification_profile_missed_call"/>
<EditTextPreference
android:defaultValue="0"
android:key="watchxplus_repeat_missedcall"
@ -33,7 +33,7 @@
android:layout="@layout/preference_checkbox"
android:defaultValue="false"
android:key="watchxplus_missed"
android:title="@string/prefs_wxp_missed" />
android:title="@string/pref_screen_notification_profile_incoming_call" />
</PreferenceScreen>
<PreferenceScreen
android:key="pref_category_watchxplus_callhandling"
@ -63,7 +63,7 @@
android:title="@string/wxp_power_mode_title"
android:entries="@array/wxp_mode"
android:entryValues="@array/wxp_mode_values"
android:key="pref_wxp_power_mode"
android:key="pref_wxp_power"
android:summary="%s" />
<ListPreference
android:defaultValue="1"
@ -123,4 +123,4 @@
android:summary="@string/prefs_wxp_button_bp_calibration_sum" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>