mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-17 21:06:48 +01:00
added time limited on auto-fetch, and removed the creation of multiple autoFetchReceivers
This commit is contained in:
parent
d1cba54425
commit
91cbdfde10
@ -326,6 +326,26 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pref = findPreference("auto_fetch_interval_limit");
|
||||||
|
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object autoFetchInterval) {
|
||||||
|
String summary = String.format(
|
||||||
|
getApplicationContext().getString(R.string.pref_auto_fetch_limit_fetches_summary),
|
||||||
|
Integer.valueOf((String) autoFetchInterval));
|
||||||
|
preference.setSummary(summary);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
int autoFetchInterval = GBApplication.getPrefs().getInt("auto_fetch_interval_limit", 0);
|
||||||
|
summary = String.format(
|
||||||
|
getApplicationContext().getString(R.string.pref_auto_fetch_limit_fetches_summary),
|
||||||
|
(int) autoFetchInterval);
|
||||||
|
pref.setSummary(summary);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final Preference displayPages = findPreference("bip_display_items");
|
final Preference displayPages = findPreference("bip_display_items");
|
||||||
displayPages.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
displayPages.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -680,7 +680,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GBApplication.getPrefs().getBoolean("auto_fetch_enabled", false) &&
|
if (GBApplication.getPrefs().getBoolean("auto_fetch_enabled", false) &&
|
||||||
coordinator != null && coordinator.supportsActivityDataFetching()) {
|
coordinator != null && coordinator.supportsActivityDataFetching() && mGBAutoFetchReceiver == null) {
|
||||||
mGBAutoFetchReceiver = new GBAutoFetchReceiver();
|
mGBAutoFetchReceiver = new GBAutoFetchReceiver();
|
||||||
registerReceiver(mGBAutoFetchReceiver, new IntentFilter("android.intent.action.USER_PRESENT"));
|
registerReceiver(mGBAutoFetchReceiver, new IntentFilter("android.intent.action.USER_PRESENT"));
|
||||||
}
|
}
|
||||||
|
@ -20,20 +20,22 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import org.slf4j.LoggerFactory;
|
import java.util.Date;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||||
|
|
||||||
|
|
||||||
public class GBAutoFetchReceiver extends BroadcastReceiver {
|
public class GBAutoFetchReceiver extends BroadcastReceiver {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GBAutoFetchReceiver.class);
|
private Date lastSync = new Date();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
//LOG.info("User is present!");
|
Date nextSync = DateUtils.addMinutes(lastSync, GBApplication.getPrefs().getInt("auto_fetch_interval_limit", 0));
|
||||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
if (nextSync.before(new Date())) {
|
||||||
|
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||||
|
lastSync = new Date();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +202,8 @@
|
|||||||
<!-- Auto fetch activity preferences -->
|
<!-- Auto fetch activity preferences -->
|
||||||
<string name="pref_auto_fetch">Auto fetch activity data</string>
|
<string name="pref_auto_fetch">Auto fetch activity data</string>
|
||||||
<string name="pref_auto_fetch_summary">Fetch happens upon screen unlock. Only works if a lock mechanism is set!</string>
|
<string name="pref_auto_fetch_summary">Fetch happens upon screen unlock. Only works if a lock mechanism is set!</string>
|
||||||
|
<string name="pref_auto_fetch_limit_fetches">Minimum time between fetches</string>
|
||||||
|
<string name="pref_auto_fetch_limit_fetches_summary">Fetches every %d minutes</string>
|
||||||
|
|
||||||
<string name="not_connected">Not connected</string>
|
<string name="not_connected">Not connected</string>
|
||||||
<string name="connecting">Connecting</string>
|
<string name="connecting">Connecting</string>
|
||||||
|
@ -535,6 +535,13 @@
|
|||||||
android:key="auto_fetch_enabled"
|
android:key="auto_fetch_enabled"
|
||||||
android:title="@string/pref_auto_fetch"
|
android:title="@string/pref_auto_fetch"
|
||||||
android:summary="@string/pref_auto_fetch_summary"/>
|
android:summary="@string/pref_auto_fetch_summary"/>
|
||||||
|
<EditTextPreference
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="auto_fetch_interval_limit"
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:maxLength="3"
|
||||||
|
android:title="@string/pref_auto_fetch_limit_fetches"
|
||||||
|
android:summary="@string/pref_auto_fetch_limit_fetches_summary"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user