Uses switches instead of check boxes for advanced options

pull/146/head
M66B 6 years ago
parent 2a88f6aaab
commit 4c212f07d1

@ -25,21 +25,21 @@ import android.preference.PreferenceManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
public class FragmentOptions extends FragmentEx { public class FragmentOptions extends FragmentEx {
private CheckBox cbEnabled; private SwitchCompat swEnabled;
private CheckBox cbAvatars; private SwitchCompat swAvatars;
private CheckBox cbLight; private SwitchCompat swLight;
private CheckBox cbBrowse; private SwitchCompat swBrowse;
private CheckBox cbSwipe; private SwitchCompat swSwipe;
private CheckBox cbCompact; private SwitchCompat swCompact;
private CheckBox cbInsecure; private SwitchCompat swInsecure;
private CheckBox cbDebug; private SwitchCompat swDebug;
@Override @Override
@Nullable @Nullable
@ -49,21 +49,21 @@ public class FragmentOptions extends FragmentEx {
View view = inflater.inflate(R.layout.fragment_options, container, false); View view = inflater.inflate(R.layout.fragment_options, container, false);
// Get controls // Get controls
cbEnabled = view.findViewById(R.id.cbEnabled); swEnabled = view.findViewById(R.id.swEnabled);
cbAvatars = view.findViewById(R.id.cbAvatars); swAvatars = view.findViewById(R.id.swAvatars);
cbLight = view.findViewById(R.id.cbLight); swLight = view.findViewById(R.id.swLight);
cbBrowse = view.findViewById(R.id.cbBrowse); swBrowse = view.findViewById(R.id.swBrowse);
cbSwipe = view.findViewById(R.id.cbSwipe); swSwipe = view.findViewById(R.id.swSwipe);
cbCompact = view.findViewById(R.id.cbCompact); swCompact = view.findViewById(R.id.swCompact);
cbInsecure = view.findViewById(R.id.cbInsecure); swInsecure = view.findViewById(R.id.swInsecure);
cbDebug = view.findViewById(R.id.cbDebug); swDebug = view.findViewById(R.id.swDebug);
// Wire controls // Wire controls
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
cbEnabled.setChecked(prefs.getBoolean("enabled", true)); swEnabled.setChecked(prefs.getBoolean("enabled", true));
cbEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("enabled", checked).apply(); prefs.edit().putBoolean("enabled", checked).apply();
@ -74,56 +74,56 @@ public class FragmentOptions extends FragmentEx {
} }
}); });
cbAvatars.setChecked(prefs.getBoolean("avatars", true)); swAvatars.setChecked(prefs.getBoolean("avatars", true));
cbAvatars.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swAvatars.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("avatars", checked).apply(); prefs.edit().putBoolean("avatars", checked).apply();
} }
}); });
cbLight.setChecked(prefs.getBoolean("light", false)); swLight.setChecked(prefs.getBoolean("light", false));
cbLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("light", checked).apply(); prefs.edit().putBoolean("light", checked).apply();
} }
}); });
cbBrowse.setChecked(prefs.getBoolean("browse", true)); swBrowse.setChecked(prefs.getBoolean("browse", true));
cbBrowse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swBrowse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("browse", checked).apply(); prefs.edit().putBoolean("browse", checked).apply();
} }
}); });
cbSwipe.setChecked(prefs.getBoolean("swipe", true)); swSwipe.setChecked(prefs.getBoolean("swipe", true));
cbSwipe.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swSwipe.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("swipe", checked).apply(); prefs.edit().putBoolean("swipe", checked).apply();
} }
}); });
cbCompact.setChecked(prefs.getBoolean("compact", false)); swCompact.setChecked(prefs.getBoolean("compact", false));
cbCompact.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swCompact.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("compact", checked).apply(); prefs.edit().putBoolean("compact", checked).apply();
} }
}); });
cbInsecure.setChecked(prefs.getBoolean("insecure", false)); swInsecure.setChecked(prefs.getBoolean("insecure", false));
cbInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("insecure", checked).apply(); prefs.edit().putBoolean("insecure", checked).apply();
} }
}); });
cbDebug.setChecked(prefs.getBoolean("debug", false)); swDebug.setChecked(prefs.getBoolean("debug", false));
cbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("debug", checked).apply(); prefs.edit().putBoolean("debug", checked).apply();
@ -131,7 +131,7 @@ public class FragmentOptions extends FragmentEx {
} }
}); });
cbLight.setVisibility(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE); swLight.setVisibility(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
return view; return view;
} }

@ -9,86 +9,78 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:layout_margin="12dp">
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbEnabled" android:id="@+id/swEnabled"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_enabled" android:text="@string/title_advanced_enabled"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbAvatars" android:id="@+id/swAvatars"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_avatars" android:text="@string/title_advanced_avatars"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbEnabled" /> app:layout_constraintTop_toBottomOf="@id/swEnabled" />
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbLight" android:id="@+id/swLight"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_light" android:text="@string/title_advanced_light"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbAvatars" /> app:layout_constraintTop_toBottomOf="@id/swAvatars" />
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbBrowse" android:id="@+id/swBrowse"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_browse" android:text="@string/title_advanced_browse"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbLight" /> app:layout_constraintTop_toBottomOf="@id/swLight" />
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbSwipe" android:id="@+id/swSwipe"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_swipe" android:text="@string/title_advanced_swipe"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbBrowse" /> app:layout_constraintTop_toBottomOf="@id/swBrowse" />
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbCompact" android:id="@+id/swCompact"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_compact" android:text="@string/title_advanced_compact"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSwipe" /> app:layout_constraintTop_toBottomOf="@id/swSwipe" />
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbInsecure" android:id="@+id/swInsecure"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_allow_insecure" android:text="@string/title_allow_insecure"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbCompact" /> app:layout_constraintTop_toBottomOf="@id/swCompact" />
<CheckBox <androidx.appcompat.widget.SwitchCompat
android:id="@+id/cbDebug" android:id="@+id/swDebug"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_debug" android:text="@string/title_advanced_debug"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbInsecure" /> app:layout_constraintTop_toBottomOf="@id/swInsecure" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>
Loading…
Cancel
Save