From 82c57f9b49b99754ec5de94840596b0c7e9beb52 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Thu, 5 Apr 2018 20:37:23 +0300 Subject: [PATCH] Add ExploreTabFragment and SavedArticlesTabFragment to the WikivoyageExploreDialogFragment --- .../plus/wikivoyage/ExploreTabFragment.java | 7 +++ .../wikivoyage/SavedArticlesTabFragment.java | 7 +++ .../WikivoyageExploreDialogFragment.java | 60 ++++++++++++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/ExploreTabFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/SavedArticlesTabFragment.java diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/ExploreTabFragment.java new file mode 100644 index 0000000000..27bf00d77f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/ExploreTabFragment.java @@ -0,0 +1,7 @@ +package net.osmand.plus.wikivoyage; + +import net.osmand.plus.base.BaseOsmAndFragment; + +public class ExploreTabFragment extends BaseOsmAndFragment { + +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/SavedArticlesTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/SavedArticlesTabFragment.java new file mode 100644 index 0000000000..ced917bad6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/SavedArticlesTabFragment.java @@ -0,0 +1,7 @@ +package net.osmand.plus.wikivoyage; + +import net.osmand.plus.base.BaseOsmAndFragment; + +public class SavedArticlesTabFragment extends BaseOsmAndFragment { + +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java index 3cf610112a..b1fc9b1e6f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageExploreDialogFragment.java @@ -5,21 +5,33 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.BottomNavigationView; +import android.support.design.widget.BottomNavigationView.OnNavigationItemSelectedListener; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import net.osmand.AndroidUtils; +import net.osmand.plus.LockableViewPager; import net.osmand.plus.R; import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragment { public static final String TAG = "WikivoyageExploreDialogFragment"; + private static final int EXPLORE_POSITION = 0; + private static final int SAVED_ARTICLES_POSITION = 1; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -37,10 +49,34 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen } }); - ColorStateList navColorStateList = createBottomNavColorStateList(); - BottomNavigationView bottomNav = (BottomNavigationView) mainView.findViewById(R.id.bottom_navigation); + final LockableViewPager viewPager = (LockableViewPager) mainView.findViewById(R.id.view_pager); + viewPager.setOffscreenPageLimit(2); + viewPager.setSwipeLocked(true); + viewPager.setAdapter(new ViewPagerAdapter(getChildFragmentManager())); + + final ColorStateList navColorStateList = createBottomNavColorStateList(); + final BottomNavigationView bottomNav = (BottomNavigationView) mainView.findViewById(R.id.bottom_navigation); bottomNav.setItemIconTintList(navColorStateList); bottomNav.setItemTextColor(navColorStateList); + bottomNav.setOnNavigationItemSelectedListener(new OnNavigationItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + int position = -1; + switch (item.getItemId()) { + case R.id.action_explore: + position = EXPLORE_POSITION; + break; + case R.id.action_saved_articles: + position = SAVED_ARTICLES_POSITION; + break; + } + if (position != -1 && position != viewPager.getCurrentItem()) { + viewPager.setCurrentItem(position); + return true; + } + return false; + } + }); return mainView; } @@ -60,4 +96,24 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen return false; } } + + private static class ViewPagerAdapter extends FragmentPagerAdapter { + + private final List fragments = new ArrayList<>(); + + ViewPagerAdapter(FragmentManager fm) { + super(fm); + fragments.addAll(Arrays.asList(new ExploreTabFragment(), new SavedArticlesTabFragment())); + } + + @Override + public Fragment getItem(int position) { + return fragments.get(position); + } + + @Override + public int getCount() { + return fragments.size(); + } + } }