Files
FairEmail/app/src/main/java/eu/faircode/email/FragmentOptions.java

162 lines
6.1 KiB
Java
Raw Normal View History

package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-12-31 08:04:33 +00:00
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2019-05-06 09:10:13 +02:00
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
2019-03-15 13:54:25 +00:00
import androidx.preference.PreferenceManager;
2019-05-06 09:10:13 +02:00
import androidx.viewpager.widget.ViewPager;
2019-05-06 09:10:13 +02:00
public class FragmentOptions extends FragmentBase {
private ViewPager pager;
private PagerAdapter adapter;
2019-01-21 18:12:22 +00:00
static String[] OPTIONS_RESTART = new String[]{
2019-04-25 08:37:48 +02:00
"startup", "date", "threading", "avatars", "identicons", "circular", "name_email", "subject_italic", "flags", "preview",
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext",
"subscriptions",
"authentication", "debug"
2019-01-21 18:12:22 +00:00
};
private final static String[] ADVANCED_OPTIONS = new String[]{
2019-04-26 12:45:45 +02:00
"enabled", "poll_interval", "schedule", "schedule_start", "schedule_end",
"metered", "download", "roaming",
2019-04-25 08:37:48 +02:00
"startup", "date", "threading", "avatars", "identicons", "circular", "name_email", "subject_italic", "flags", "preview",
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
2019-04-17 17:27:57 +02:00
"autoresize", "resize", "prefix_once", "autosend",
2019-05-06 10:33:29 +02:00
"notify_trash", "notify_archive", "notify_reply", "notify_flag", "notify_seen", "notify_preview", "light", "sound",
2019-05-05 22:28:07 +02:00
"badge", "subscriptions", "search_local", "english", "authentication", "paranoid", "updates", "debug",
2019-01-30 19:35:36 +00:00
"first", "why", "last_update_check", "app_support", "message_swipe", "message_select", "folder_actions", "folder_sync",
2019-03-26 18:26:21 +00:00
"edit_ref_confirmed", "show_html_confirmed", "show_images_confirmed", "print_html_confirmed", "show_organization", "style_toolbar"
};
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_advanced);
2018-12-10 13:36:05 +01:00
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_options, container, false);
2019-05-06 09:10:13 +02:00
pager = view.findViewById(R.id.pager);
adapter = new PagerAdapter(getChildFragmentManager());
pager.setAdapter(adapter);
2019-05-05 22:28:07 +02:00
2019-05-06 09:10:13 +02:00
return view;
}
2019-05-05 22:28:07 +02:00
2019-05-06 09:10:13 +02:00
private class PagerAdapter extends FragmentStatePagerAdapter {
public PagerAdapter(FragmentManager fm) {
super(fm);
2019-04-18 09:27:19 +02:00
}
2019-05-06 09:10:13 +02:00
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new FragmentOptionsGeneral();
case 1:
return new FragmentOptionsConnection();
case 2:
return new FragmentOptionsDisplay();
case 3:
return new FragmentOptionsBehavior();
case 4:
return new FragmentOptionsNotifications();
case 5:
return new FragmentOptionsMisc();
default:
throw new IllegalArgumentException();
2019-05-05 22:28:07 +02:00
}
2019-05-06 09:10:13 +02:00
}
2019-05-05 22:28:07 +02:00
2019-05-06 09:10:13 +02:00
@Override
public int getCount() {
return 6;
}
2019-04-18 09:27:19 +02:00
2019-05-06 09:10:13 +02:00
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getString(R.string.title_advanced_section_general);
case 1:
return getString(R.string.title_advanced_section_connection);
case 2:
return getString(R.string.title_advanced_section_display);
case 3:
return getString(R.string.title_advanced_section_behavior);
case 4:
return getString(R.string.title_advanced_section_notifications);
case 5:
return getString(R.string.title_advanced_section_misc);
default:
throw new IllegalArgumentException();
}
2019-05-06 09:10:13 +02:00
}
2019-05-06 10:40:05 +02:00
@Override
public int getItemPosition(@NonNull Object object) {
return POSITION_NONE; // always recreate fragment
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_options, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_default:
onMenuDefault();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuDefault() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor editor = prefs.edit();
for (String option : ADVANCED_OPTIONS)
editor.remove(option);
editor.apply();
2019-05-06 10:40:05 +02:00
adapter.notifyDataSetChanged();
2018-11-10 10:45:03 +00:00
}
}