FairEmail/app/src/main/java/eu/faircode/email/FragmentLegend.java

153 lines
5.1 KiB
Java
Raw Normal View History

2018-08-22 06:20:31 +00:00
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,
2018-08-22 06:20:31 +00:00
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-08-22 06:20:31 +00:00
2022-01-01 08:46:36 +00:00
Copyright 2018-2022 by Marcel Bokhorst (M66B)
2018-08-22 06:20:31 +00:00
*/
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-13 07:51:51 +00:00
import androidx.fragment.app.Fragment;
2020-05-19 09:10:59 +00:00
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
2019-05-13 07:51:51 +00:00
import com.google.android.material.tabs.TabLayout;
2018-08-22 06:20:31 +00:00
2019-01-15 17:41:55 +00:00
public class FragmentLegend extends FragmentBase {
2019-05-13 07:51:51 +00:00
private int layout = -1;
2020-05-19 09:10:59 +00:00
private ViewPager pager;
private PagerAdapter adapter;
2019-05-13 07:51:51 +00:00
2020-04-15 07:46:20 +00:00
private FragmentLegend setLayout(int layout) {
2019-05-13 07:51:51 +00:00
this.layout = layout;
return this;
}
2018-08-22 06:20:31 +00:00
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.menu_legend);
if (savedInstanceState != null)
layout = savedInstanceState.getInt("fair:layout");
2019-05-13 07:51:51 +00:00
View view;
if (layout < 0) {
view = inflater.inflate(R.layout.fragment_legend, container, false);
pager = view.findViewById(R.id.pager);
2020-05-19 09:10:59 +00:00
adapter = new PagerAdapter(getChildFragmentManager());
2019-05-13 07:51:51 +00:00
pager.setAdapter(adapter);
2020-10-31 08:06:06 +00:00
} else {
2019-05-13 07:51:51 +00:00
view = inflater.inflate(layout, container, false);
2020-10-31 08:06:06 +00:00
if (layout == R.layout.fragment_legend_synchronization) {
view.findViewById(R.id.ibInfoBackoff).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2020-11-11 16:35:32 +00:00
Helper.viewFAQ(v.getContext(), 123);
2020-10-31 08:06:06 +00:00
}
});
}
}
2021-09-14 07:52:08 +00:00
FragmentDialogTheme.setBackground(getContext(), view, false);
2019-05-13 07:51:51 +00:00
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
if (savedInstanceState != null)
layout = savedInstanceState.getInt("fair:layout");
2019-05-13 07:51:51 +00:00
if (layout < 0) {
TabLayout tabLayout = view.findViewById(R.id.tab_layout);
2020-05-19 09:10:59 +00:00
tabLayout.setupWithViewPager(pager);
2020-01-12 08:12:20 +00:00
Bundle args = getArguments();
if (args != null) {
String tab = args.getString("tab");
if ("compose".equals(tab))
pager.setCurrentItem(3);
args.remove("tab");
setArguments(args);
}
2019-05-13 07:51:51 +00:00
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt("fair:layout", layout);
super.onSaveInstanceState(outState);
}
2020-05-19 09:10:59 +00:00
private class PagerAdapter extends FragmentStatePagerAdapter {
public PagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return 5;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new FragmentLegend().setLayout(R.layout.fragment_legend_synchronization);
case 1:
return new FragmentLegend().setLayout(R.layout.fragment_legend_folders);
case 2:
return new FragmentLegend().setLayout(R.layout.fragment_legend_messages);
case 3:
return new FragmentLegend().setLayout(R.layout.fragment_legend_compose);
case 4:
return new FragmentLegend().setLayout(R.layout.fragment_legend_keyboard);
default:
throw new IllegalArgumentException();
}
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return getString(R.string.title_legend_section_synchronize);
case 1:
return getString(R.string.title_legend_section_folders);
case 2:
return getString(R.string.title_legend_section_messages);
case 3:
return getString(R.string.title_legend_section_compose);
case 4:
return getString(R.string.title_legend_section_keyboard);
default:
throw new IllegalArgumentException();
}
}
}
2018-08-22 06:20:31 +00:00
}