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

136 lines
4.8 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.os.Bundle;
import android.view.LayoutInflater;
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;
import androidx.viewpager.widget.ViewPager;
2019-05-06 11:05:29 +02:00
import com.google.android.material.tabs.TabLayout;
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", "attachments_alt", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext",
"subscriptions",
"authentication", "debug"
2019-01-21 18:12:22 +00:00
};
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
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 11:05:29 +02:00
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
TabLayout tabLayout = view.findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(pager);
2019-06-14 21:41:53 +02:00
String tab = getActivity().getIntent().getStringExtra("tab");
2019-06-14 22:03:56 +02:00
if ("connection".equals(tab))
pager.setCurrentItem(3);
else if ("display".equals(tab))
2019-06-14 21:41:53 +02:00
pager.setCurrentItem(4);
2019-05-06 11:05:29 +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-13 09:12:24 +02:00
@Override
public int getCount() {
2019-06-12 16:15:46 +02:00
return 8;
2019-05-13 09:12:24 +02:00
}
2019-05-06 09:10:13 +02:00
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
2019-06-12 16:15:46 +02:00
return new FragmentSetup();
2019-05-06 09:10:13 +02:00
case 1:
2019-06-12 16:15:46 +02:00
return new FragmentOptionsSynchronize();
2019-05-06 09:10:13 +02:00
case 2:
2019-06-12 16:15:46 +02:00
return new FragmentOptionsSend();
2019-05-06 09:10:13 +02:00
case 3:
2019-06-12 16:15:46 +02:00
return new FragmentOptionsConnection();
2019-05-06 09:10:13 +02:00
case 4:
2019-06-12 16:15:46 +02:00
return new FragmentOptionsDisplay();
2019-05-06 09:10:13 +02:00
case 5:
2019-06-12 16:15:46 +02:00
return new FragmentOptionsBehavior();
case 6:
2019-06-12 16:15:46 +02:00
return new FragmentOptionsNotifications();
case 7:
2019-05-06 09:10:13 +02:00
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 CharSequence getPageTitle(int position) {
switch (position) {
case 0:
2019-06-12 16:15:46 +02:00
return getString(R.string.title_advanced_section_main);
2019-05-06 09:10:13 +02:00
case 1:
2019-06-12 16:15:46 +02:00
return getString(R.string.title_advanced_section_synchronize);
2019-05-06 09:10:13 +02:00
case 2:
2019-06-12 16:15:46 +02:00
return getString(R.string.title_advanced_section_send);
2019-05-06 09:10:13 +02:00
case 3:
2019-06-12 16:15:46 +02:00
return getString(R.string.title_advanced_section_connection);
2019-05-06 09:10:13 +02:00
case 4:
2019-06-12 16:15:46 +02:00
return getString(R.string.title_advanced_section_display);
2019-05-06 09:10:13 +02:00
case 5:
2019-06-12 16:15:46 +02:00
return getString(R.string.title_advanced_section_behavior);
case 6:
2019-06-12 16:15:46 +02:00
return getString(R.string.title_advanced_section_notifications);
case 7:
2019-05-06 09:10:13 +02:00
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
}
}
}