Hide advanced options by default

pull/180/head
M66B 5 years ago
parent 10e69a44b5
commit 05789c1a8d

@ -26,6 +26,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@ -47,7 +48,8 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
public class FragmentOptions extends FragmentBase {
public class FragmentOptions extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private boolean advanced;
private ViewPager pager;
private PagerAdapter adapter;
@ -73,6 +75,14 @@ public class FragmentOptions extends FragmentBase {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String tab = getActivity().getIntent().getStringExtra("tab");
if (!TextUtils.isEmpty(tab))
prefs.edit().putBoolean("setup_advanced", true).apply();
advanced = prefs.getBoolean("setup_advanced", false);
View view = inflater.inflate(R.layout.fragment_options, container, false);
pager = view.findViewById(R.id.pager);
@ -139,6 +149,29 @@ public class FragmentOptions extends FragmentBase {
getActivity().getIntent().removeExtra("tab");
}
@Override
public void onResume() {
super.onResume();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if ("setup_advanced".equals(key)) {
advanced = prefs.getBoolean(key, false);
Log.i("Show advanced=" + advanced);
adapter.notifyDataSetChanged();
}
}
@Override
protected void finish() {
onExit();
@ -222,7 +255,7 @@ public class FragmentOptions extends FragmentBase {
@Override
public int getCount() {
return 10;
return (advanced ? 10 : 1);
}
@Override

@ -108,7 +108,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"selected_folders", "move_1_confirmed", "move_n_confirmed",
"last_search_senders", "last_search_recipients", "last_search_subject", "last_search_keywords", "last_search_message", "last_search",
"identities_asked", "cc_bcc", "inline_image_hint", "compose_reference", "send_dialog",
"setup_reminder", "setup_advanced"
"setup_reminder"
};
@Override

@ -39,6 +39,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.TextView;
import android.widget.Toast;
@ -82,6 +84,7 @@ public class FragmentSetup extends FragmentBase {
private Button btnDataSaver;
private CheckBox cbAdvanced;
private Button btnInbox;
private Group grpWelcome;
@ -128,6 +131,7 @@ public class FragmentSetup extends FragmentBase {
btnDataSaver = view.findViewById(R.id.btnDataSaver);
cbAdvanced = view.findViewById(R.id.cbAdvanced);
btnInbox = view.findViewById(R.id.btnInbox);
grpWelcome = view.findViewById(R.id.grpWelcome);
@ -277,6 +281,13 @@ public class FragmentSetup extends FragmentBase {
btnDataSaver.setEnabled(settings.resolveActivity(pm) != null);
}
cbAdvanced.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("setup_advanced", isChecked).apply();
}
});
btnInbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -303,6 +314,8 @@ public class FragmentSetup extends FragmentBase {
tvDozeDone.setCompoundDrawables(null, null, null, null);
btnDoze.setEnabled(false);
boolean setup_advanced = prefs.getBoolean("setup_advanced", false);
cbAdvanced.setChecked(setup_advanced);
btnInbox.setEnabled(false);
boolean welcome = prefs.getBoolean("welcome", true);

@ -559,6 +559,15 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/five" />
<CheckBox
android:id="@+id/cbAdvanced"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/title_setup_advanced_options"
app:layout_constraintBottom_toBottomOf="@id/btnInbox"
app:layout_constraintEnd_toStartOf="@id/btnInbox"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/btnInbox"
android:layout_width="wrap_content"

@ -193,6 +193,7 @@
<string name="title_setup_doze_battery">High battery usage?</string>
<string name="title_setup_doze_stopped">Sync stopped?</string>
<string name="title_setup_data">Data saver is enabled</string>
<string name="title_setup_advanced_options">Show advanced options</string>
<string name="title_setup_inbox">Go to messages</string>
<string name="title_setup_go">Go</string>
<string name="title_setup_to_do">To do</string>

Loading…
Cancel
Save