|
|
|
@ -27,18 +27,18 @@ import android.view.ViewGroup;
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
|
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
|
|
|
|
import androidx.viewpager2.widget.ViewPager2;
|
|
|
|
|
|
|
|
|
|
import com.google.android.material.tabs.TabLayout;
|
|
|
|
|
import com.google.android.material.tabs.TabLayoutMediator;
|
|
|
|
|
|
|
|
|
|
public class FragmentLegend extends FragmentBase {
|
|
|
|
|
private int layout = -1;
|
|
|
|
|
private ViewPager pager;
|
|
|
|
|
private PagerAdapter adapter;
|
|
|
|
|
private ViewPager2 pager;
|
|
|
|
|
private FragmentStateAdapter adapter;
|
|
|
|
|
|
|
|
|
|
FragmentLegend setLayout(int layout) {
|
|
|
|
|
private FragmentLegend setLayout(int layout) {
|
|
|
|
|
this.layout = layout;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
@ -56,53 +56,16 @@ public class FragmentLegend extends FragmentBase {
|
|
|
|
|
view = inflater.inflate(R.layout.fragment_legend, container, false);
|
|
|
|
|
|
|
|
|
|
pager = view.findViewById(R.id.pager);
|
|
|
|
|
adapter = new PagerAdapter(getChildFragmentManager());
|
|
|
|
|
pager.setAdapter(adapter);
|
|
|
|
|
} else
|
|
|
|
|
view = inflater.inflate(layout, container, false);
|
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
if (savedInstanceState != null)
|
|
|
|
|
layout = savedInstanceState.getInt("fair:layout");
|
|
|
|
|
|
|
|
|
|
if (layout < 0) {
|
|
|
|
|
TabLayout tabLayout = view.findViewById(R.id.tab_layout);
|
|
|
|
|
tabLayout.setupWithViewPager(pager);
|
|
|
|
|
|
|
|
|
|
Bundle args = getArguments();
|
|
|
|
|
if (args != null) {
|
|
|
|
|
String tab = args.getString("tab");
|
|
|
|
|
if ("compose".equals(tab))
|
|
|
|
|
pager.setCurrentItem(3);
|
|
|
|
|
|
|
|
|
|
args.remove("tab");
|
|
|
|
|
setArguments(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
outState.putInt("fair:layout", layout);
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class PagerAdapter extends FragmentStatePagerAdapter {
|
|
|
|
|
public PagerAdapter(FragmentManager fm) {
|
|
|
|
|
super(fm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adapter = new FragmentStateAdapter(this) {
|
|
|
|
|
@Override
|
|
|
|
|
public int getCount() {
|
|
|
|
|
public int getItemCount() {
|
|
|
|
|
return 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
|
@Override
|
|
|
|
|
public Fragment getItem(int position) {
|
|
|
|
|
public Fragment createFragment(int position) {
|
|
|
|
|
switch (position) {
|
|
|
|
|
case 0:
|
|
|
|
|
return new FragmentLegend().setLayout(R.layout.fragment_legend_synchronization);
|
|
|
|
@ -118,23 +81,62 @@ public class FragmentLegend extends FragmentBase {
|
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pager.setAdapter(adapter);
|
|
|
|
|
} else
|
|
|
|
|
view = inflater.inflate(layout, container, false);
|
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CharSequence getPageTitle(int position) {
|
|
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
if (savedInstanceState != null)
|
|
|
|
|
layout = savedInstanceState.getInt("fair:layout");
|
|
|
|
|
|
|
|
|
|
if (layout < 0) {
|
|
|
|
|
TabLayout tabLayout = view.findViewById(R.id.tab_layout);
|
|
|
|
|
new TabLayoutMediator(tabLayout, pager, new TabLayoutMediator.TabConfigurationStrategy() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
|
|
|
|
|
switch (position) {
|
|
|
|
|
case 0:
|
|
|
|
|
return getString(R.string.title_legend_section_synchronize);
|
|
|
|
|
tab.setText(R.string.title_legend_section_synchronize);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
return getString(R.string.title_legend_section_folders);
|
|
|
|
|
tab.setText(R.string.title_legend_section_folders);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
return getString(R.string.title_legend_section_messages);
|
|
|
|
|
tab.setText(R.string.title_legend_section_messages);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
return getString(R.string.title_legend_section_compose);
|
|
|
|
|
tab.setText(R.string.title_legend_section_compose);
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
return getString(R.string.title_legend_section_keyboard);
|
|
|
|
|
tab.setText(R.string.title_legend_section_keyboard);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
|
throw new IllegalArgumentException("Position=" + position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).attach();
|
|
|
|
|
|
|
|
|
|
Bundle args = getArguments();
|
|
|
|
|
if (args != null) {
|
|
|
|
|
String tab = args.getString("tab");
|
|
|
|
|
if ("compose".equals(tab))
|
|
|
|
|
pager.setCurrentItem(3);
|
|
|
|
|
|
|
|
|
|
args.remove("tab");
|
|
|
|
|
setArguments(args);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
outState.putInt("fair:layout", layout);
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|