Added option to force polling on (un)metered networks

pull/214/head
M66B 6 months ago
parent 1909411855
commit 5c9b6a347f

@ -229,6 +229,18 @@ public class EntityAccount extends EntityOrder implements Serializable {
} }
boolean isExempted(Context context) { boolean isExempted(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean poll_metered = prefs.getBoolean("poll_metered", false);
boolean poll_unmetered = prefs.getBoolean("poll_unmetered", false);
if (poll_metered || poll_unmetered) {
ConnectionHelper.NetworkState state = ConnectionHelper.getNetworkState(context);
if (poll_metered && state.isConnected() && !state.isUnmetered())
return false;
if (poll_unmetered && state.isConnected() && state.isUnmetered())
return false;
}
return this.poll_exempted; return this.poll_exempted;
} }

@ -82,6 +82,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private Spinner spPollInterval; private Spinner spPollInterval;
private TextView tvPollBattery; private TextView tvPollBattery;
private RecyclerView rvExempted; private RecyclerView rvExempted;
private SwitchCompat swPollMetered;
private SwitchCompat swPollUnmetered;
private SwitchCompat swSchedule; private SwitchCompat swSchedule;
private TextView tvSchedulePro; private TextView tvSchedulePro;
private TextView tvScheduleStart; private TextView tvScheduleStart;
@ -132,6 +134,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( private final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"enabled", "poll_interval", "auto_optimize", "enabled", "poll_interval", "auto_optimize",
"poll_metered", "poll_unmetered",
"schedule", "schedule_start", "schedule_end", "schedule_start_weekend", "schedule_end_weekend", "weekend", "schedule", "schedule_start", "schedule_end", "schedule_start_weekend", "schedule_end_weekend", "weekend",
"sync_quick_imap", "sync_quick_pop", "sync_quick_imap", "sync_quick_pop",
"sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept",
@ -172,6 +175,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
tvPollBattery = view.findViewById(R.id.tvPollBattery); tvPollBattery = view.findViewById(R.id.tvPollBattery);
rvExempted = view.findViewById(R.id.rvExempted); rvExempted = view.findViewById(R.id.rvExempted);
swPollMetered = view.findViewById(R.id.swPollMetered);
swPollUnmetered = view.findViewById(R.id.swPollUnmetered);
swSchedule = view.findViewById(R.id.swSchedule); swSchedule = view.findViewById(R.id.swSchedule);
tvSchedulePro = view.findViewById(R.id.tvSchedulePro); tvSchedulePro = view.findViewById(R.id.tvSchedulePro);
@ -369,6 +374,20 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
adapter = new AdapterAccountExempted(getViewLifecycleOwner(), getContext()); adapter = new AdapterAccountExempted(getViewLifecycleOwner(), getContext());
rvExempted.setAdapter(adapter); rvExempted.setAdapter(adapter);
swPollMetered.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("poll_metered", checked).apply();
}
});
swPollUnmetered.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("poll_unmetered", checked).apply();
}
});
swSchedule.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swSchedule.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -706,6 +725,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
} }
tvPollBattery.setVisibility(pollInterval > 0 && pollInterval < 15 ? View.VISIBLE : View.GONE); tvPollBattery.setVisibility(pollInterval > 0 && pollInterval < 15 ? View.VISIBLE : View.GONE);
swPollMetered.setChecked(prefs.getBoolean("poll_metered", false));
swPollUnmetered.setChecked(prefs.getBoolean("poll_unmetered", false));
grpExempted.setVisibility(pollInterval == 0 ? View.GONE : View.VISIBLE); grpExempted.setVisibility(pollInterval == 0 ? View.GONE : View.VISIBLE);
swSchedule.setChecked(prefs.getBoolean("schedule", false) && pro); swSchedule.setChecked(prefs.getBoolean("schedule", false) && pro);

@ -160,7 +160,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static final String ACTION_NEW_MESSAGE_COUNT = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE_COUNT"; private static final String ACTION_NEW_MESSAGE_COUNT = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE_COUNT";
private static final List<String> PREF_EVAL = Collections.unmodifiableList(Arrays.asList( private static final List<String> PREF_EVAL = Collections.unmodifiableList(Arrays.asList(
"enabled", "poll_interval", "last_daily" // restart account(s) "enabled", "poll_interval", "poll_metered", "poll_unmetered", "last_daily" // restart account(s)
)); ));
private static final List<String> PREF_RELOAD = Collections.unmodifiableList(Arrays.asList( private static final List<String> PREF_RELOAD = Collections.unmodifiableList(Arrays.asList(

@ -250,6 +250,30 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvExempted" /> app:layout_constraintTop_toBottomOf="@id/tvExempted" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPollMetered"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_poll_metered"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvExempted"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPollUnmetered"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_poll_unmetered"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPollMetered"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSchedule" android:id="@+id/swSchedule"
android:layout_width="0dp" android:layout_width="0dp"
@ -258,7 +282,7 @@
android:text="@string/title_advanced_schedule" android:text="@string/title_advanced_schedule"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rvExempted" app:layout_constraintTop_toBottomOf="@id/swPollUnmetered"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<TextView <TextView
@ -477,7 +501,7 @@
android:id="@+id/grpExempted" android:id="@+id/grpExempted"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="tvExempted,rvExempted" /> app:constraint_referenced_ids="tvExempted,rvExempted,swPollMetered,swPollUnmetered" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>

@ -420,6 +420,8 @@
<string name="title_advanced_when">When</string> <string name="title_advanced_when">When</string>
<string name="title_advanced_optimize">Automatically optimize</string> <string name="title_advanced_optimize">Automatically optimize</string>
<string name="title_advanced_always">Always receive messages for these accounts</string> <string name="title_advanced_always">Always receive messages for these accounts</string>
<string name="title_advanced_poll_metered">Periodically check for new messages while on a metered network</string>
<string name="title_advanced_poll_unmetered">Periodically check for new messages while on a unmetered network</string>
<string name="title_advanced_schedule">Schedule</string> <string name="title_advanced_schedule">Schedule</string>
<string name="title_advanced_schedule_workdays">Workdays</string> <string name="title_advanced_schedule_workdays">Workdays</string>
<string name="title_advanced_schedule_weekend">Weekend</string> <string name="title_advanced_schedule_weekend">Weekend</string>

Loading…
Cancel
Save