Update saved articles list after clearing cache or changing "Download images" setting
This commit is contained in:
parent
b5a6260a0e
commit
682450dc7f
3 changed files with 70 additions and 9 deletions
|
@ -82,6 +82,12 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
|||
diffRes.dispatchUpdatesTo(adapter);
|
||||
}
|
||||
|
||||
public void updateAdapter() {
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Object> getItems() {
|
||||
List<Object> items = new ArrayList<>();
|
||||
List<TravelArticle> savedArticles = dataHelper.getSavedArticles();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus.wikivoyage.explore;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -22,10 +23,10 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.PicassoUtils;
|
||||
import net.osmand.plus.LockableViewPager;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,6 +37,11 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
private static final int EXPLORE_POSITION = 0;
|
||||
private static final int SAVED_ARTICLES_POSITION = 1;
|
||||
|
||||
private ExploreTabFragment exploreTabFragment;
|
||||
private SavedArticlesTabFragment savedArticlesTabFragment;
|
||||
|
||||
private ViewPagerAdapter adapter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -48,6 +54,24 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
FragmentManager childFm = getChildFragmentManager();
|
||||
List<Fragment> fragments = childFm.getFragments();
|
||||
if (fragments != null) {
|
||||
for (Fragment fragment : fragments) {
|
||||
if (fragment instanceof ExploreTabFragment) {
|
||||
exploreTabFragment = (ExploreTabFragment) fragment;
|
||||
} else if (fragment instanceof SavedArticlesTabFragment) {
|
||||
savedArticlesTabFragment = (SavedArticlesTabFragment) fragment;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exploreTabFragment == null) {
|
||||
exploreTabFragment = new ExploreTabFragment();
|
||||
}
|
||||
if (savedArticlesTabFragment == null) {
|
||||
savedArticlesTabFragment = new SavedArticlesTabFragment();
|
||||
}
|
||||
|
||||
final View mainView = inflate(R.layout.fragment_wikivoyage_explore_dialog, container);
|
||||
|
||||
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
|
||||
|
@ -55,9 +79,15 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm == null) {
|
||||
return;
|
||||
}
|
||||
WikivoyageOptionsBottomSheetDialogFragment fragment = new WikivoyageOptionsBottomSheetDialogFragment();
|
||||
fragment.setUsedOnMap(false);
|
||||
fragment.show(getChildFragmentManager(), WikivoyageOptionsBottomSheetDialogFragment.TAG);
|
||||
fragment.setTargetFragment(WikivoyageExploreDialogFragment.this,
|
||||
WikivoyageOptionsBottomSheetDialogFragment.REQUEST_CODE);
|
||||
fragment.show(fm, WikivoyageOptionsBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -73,10 +103,11 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
}
|
||||
});
|
||||
|
||||
adapter = new ViewPagerAdapter(childFm);
|
||||
final LockableViewPager viewPager = (LockableViewPager) mainView.findViewById(R.id.view_pager);
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
viewPager.setSwipeLocked(true);
|
||||
viewPager.setAdapter(new ViewPagerAdapter(getChildFragmentManager()));
|
||||
viewPager.setAdapter(adapter);
|
||||
|
||||
final ColorStateList navColorStateList = createBottomNavColorStateList();
|
||||
final BottomNavigationView bottomNav = (BottomNavigationView) mainView.findViewById(R.id.bottom_navigation);
|
||||
|
@ -105,6 +136,19 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == WikivoyageOptionsBottomSheetDialogFragment.REQUEST_CODE) {
|
||||
if (resultCode == WikivoyageOptionsBottomSheetDialogFragment.DOWNLOAD_IMAGES_CHANGED
|
||||
|| resultCode == WikivoyageOptionsBottomSheetDialogFragment.CACHE_CLEARED) {
|
||||
if (savedArticlesTabFragment != null) {
|
||||
savedArticlesTabFragment.updateAdapter();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ColorStateList createBottomNavColorStateList() {
|
||||
return AndroidUtils.createCheckedColorStateList(getContext(), nightMode,
|
||||
R.color.icon_color, R.color.wikivoyage_active_light,
|
||||
|
@ -121,13 +165,12 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
}
|
||||
}
|
||||
|
||||
private static class ViewPagerAdapter extends FragmentPagerAdapter {
|
||||
private class ViewPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private final List<Fragment> fragments = new ArrayList<>();
|
||||
private final List<BaseOsmAndFragment> fragments = Arrays.asList(exploreTabFragment, savedArticlesTabFragment);
|
||||
|
||||
ViewPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
fragments.addAll(Arrays.asList(new ExploreTabFragment(), new SavedArticlesTabFragment()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.explore;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.Gravity;
|
||||
|
@ -31,6 +32,10 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
|
||||
public final static String TAG = "WikivoyageOptionsBottomSheetDialogFragment";
|
||||
|
||||
public static final int REQUEST_CODE = 0;
|
||||
public static final int DOWNLOAD_IMAGES_CHANGED = 1;
|
||||
public static final int CACHE_CLEARED = 2;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
|
@ -65,7 +70,6 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END);
|
||||
for (final WikivoyageShowImages showImages : WikivoyageShowImages.values()) {
|
||||
MenuItem item = popup.getMenu().add(getString(showImages.name));
|
||||
|
@ -73,12 +77,12 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
showImagesPref.set(showImages);
|
||||
sendResult(DOWNLOAD_IMAGES_CHANGED);
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
popup.show();
|
||||
}
|
||||
})
|
||||
|
@ -95,6 +99,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
public void onClick(View v) {
|
||||
new WebView(getContext()).clearCache(true);
|
||||
PicassoUtils.clearAllPicassoCache();
|
||||
sendResult(CACHE_CLEARED);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
|
@ -119,7 +124,14 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
items.add(clearHistoryItem);
|
||||
}
|
||||
|
||||
protected void selectTravelBookDialog() {
|
||||
private void sendResult(int resultCode) {
|
||||
Fragment fragment = getTargetFragment();
|
||||
if (fragment != null) {
|
||||
fragment.onActivityResult(getTargetRequestCode(), resultCode, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectTravelBookDialog() {
|
||||
final TravelDbHelper dbHelper = getMyApplication().getTravelDbHelper();
|
||||
final List<File> list = dbHelper.getExistingTravelBooks();
|
||||
String[] ls = new String[list.size()];
|
||||
|
|
Loading…
Reference in a new issue