Added always sync checkbox to main setup screen

pull/210/head
M66B 2 years ago
parent 4caf7ae438
commit 38102edbfe

@ -50,6 +50,8 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.ScrollView;
import android.widget.TextView;
@ -72,7 +74,7 @@ import androidx.preference.PreferenceManager;
import java.util.ArrayList;
import java.util.List;
public class FragmentSetup extends FragmentBase {
public class FragmentSetup extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private ViewGroup view;
private TextView tvWelcome;
@ -115,6 +117,7 @@ public class FragmentSetup extends FragmentBase {
private Button btnBackgroundRestricted;
private Button btnDataSaver;
private TextView tvStamina;
private CheckBox cbAlways;
private TextView tvBatteryUsage;
private TextView tvSyncStopped;
@ -148,6 +151,8 @@ public class FragmentSetup extends FragmentBase {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_setup);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (savedInstanceState != null)
manual = savedInstanceState.getBoolean("fair:manual");
@ -199,6 +204,7 @@ public class FragmentSetup extends FragmentBase {
btnBackgroundRestricted = view.findViewById(R.id.btnBackgroundRestricted);
btnDataSaver = view.findViewById(R.id.btnDataSaver);
tvStamina = view.findViewById(R.id.tvStamina);
cbAlways = view.findViewById(R.id.cbAlways);
tvBatteryUsage = view.findViewById(R.id.tvBatteryUsage);
tvSyncStopped = view.findViewById(R.id.tvSyncStopped);
@ -255,7 +261,6 @@ public class FragmentSetup extends FragmentBase {
ibWelcome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(view.getContext());
boolean setup_welcome = !prefs.getBoolean("setup_welcome", true);
prefs.edit().putBoolean("setup_welcome", setup_welcome).apply();
updateWelcome();
@ -587,6 +592,14 @@ public class FragmentSetup extends FragmentBase {
}
});
cbAlways.setChecked(ServiceSynchronize.getPollInterval(getContext()) == 0);
cbAlways.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton v, boolean isChecked) {
prefs.edit().putInt("poll_interval", isChecked ? 0 : EntityAccount.DEFAULT_POLL_INTERVAL).apply();
}
});
tvBatteryUsage.setPaintFlags(tvBatteryUsage.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
tvBatteryUsage.setOnClickListener(new View.OnClickListener() {
@Override
@ -608,7 +621,6 @@ public class FragmentSetup extends FragmentBase {
ibExtra.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(v.getContext());
boolean setup_extra = !prefs.getBoolean("setup_extra", false);
prefs.edit().putBoolean("setup_extra", setup_extra).apply();
updateExtra();
@ -779,9 +791,23 @@ public class FragmentSetup extends FragmentBase {
grpDataSaver.setVisibility(View.GONE);
tvStamina.setVisibility(View.GONE);
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
return view;
}
@Override
public void onDestroyView() {
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroyView();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if ("poll_interval".equals(key))
cbAlways.setChecked(ServiceSynchronize.getPollInterval(getContext()) == 0);
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean("fair:manual", manual);

@ -867,6 +867,27 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnDataSaver" />
<CheckBox
android:id="@+id/cbAlways"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_always"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvStamina" />
<TextView
android:id="@+id/tvAlwaysRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_setup_always_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbAlways" />
<TextView
android:id="@+id/tvBatteryUsage"
android:layout_width="wrap_content"
@ -879,7 +900,7 @@
android:textColor="?android:attr/textColorLink"
app:drawableTint="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvStamina" />
app:layout_constraintTop_toBottomOf="@id/tvAlwaysRemark" />
<TextView
android:id="@+id/tvSyncStopped"

@ -270,6 +270,8 @@
<string name="title_setup_background">Background restrictions are enabled</string>
<string name="title_setup_data">Data saver is enabled</string>
<string name="title_setup_stamina" translatable="false">Stamina mode is enabled</string>
<string name="title_setup_always">Instant new message notifications</string>
<string name="title_setup_always_remark">If enabled, unstable connections, old network hardware, etc. may result in higher battery usage</string>
<string name="title_setup_advanced_options">Show advanced options</string>
<string name="title_setup_inbox">Go to inbox</string>
<string name="title_setup_go">Go</string>

Loading…
Cancel
Save