Fix wikivoyage crash
This commit is contained in:
parent
64e415a894
commit
ceea1d1646
4 changed files with 255 additions and 141 deletions
|
@ -8,7 +8,10 @@ import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.ColorRes;
|
import android.support.annotation.ColorRes;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
|
@ -33,35 +36,37 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
int colorId = getStatusBarColorId();
|
if (activity != null) {
|
||||||
if (colorId != -1) {
|
int colorId = getStatusBarColorId();
|
||||||
if (activity instanceof MapActivity) {
|
if (colorId != -1) {
|
||||||
((MapActivity) activity).updateStatusBarColor();
|
if (activity instanceof MapActivity) {
|
||||||
} else {
|
((MapActivity) activity).updateStatusBarColor();
|
||||||
statusBarColor = activity.getWindow().getStatusBarColor();
|
} else {
|
||||||
activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, colorId));
|
statusBarColor = activity.getWindow().getStatusBarColor();
|
||||||
|
activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, colorId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!isFullScreenAllowed() && activity instanceof MapActivity) {
|
||||||
if (!isFullScreenAllowed() && activity instanceof MapActivity) {
|
View view = getView();
|
||||||
View view = getView();
|
if (view != null) {
|
||||||
if (view != null) {
|
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
|
|
||||||
View view = getView();
|
View view = getView();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||||
obs.removeOnGlobalLayoutListener(this);
|
obs.removeOnGlobalLayoutListener(this);
|
||||||
view.requestLayout();
|
view.requestLayout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
((MapActivity) activity).exitFromFullScreen();
|
||||||
}
|
}
|
||||||
((MapActivity) activity).exitFromFullScreen();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,11 +76,13 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (!(activity instanceof MapActivity) && statusBarColor != -1) {
|
if (activity != null) {
|
||||||
activity.getWindow().setStatusBarColor(statusBarColor);
|
if (!(activity instanceof MapActivity) && statusBarColor != -1) {
|
||||||
}
|
activity.getWindow().setStatusBarColor(statusBarColor);
|
||||||
if (!isFullScreenAllowed() && activity instanceof MapActivity) {
|
}
|
||||||
((MapActivity) activity).enterToFullScreen();
|
if (!isFullScreenAllowed() && activity instanceof MapActivity) {
|
||||||
|
((MapActivity) activity).enterToFullScreen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,14 +128,33 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected OsmandApplication getMyApplication() {
|
protected OsmandApplication getMyApplication() {
|
||||||
return (OsmandApplication) getActivity().getApplication();
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
return (OsmandApplication) activity.getApplication();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected OsmandApplication requireMyApplication() {
|
||||||
|
FragmentActivity activity = requireActivity();
|
||||||
|
return (OsmandApplication) activity.getApplication();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected OsmandActionBarActivity getMyActivity() {
|
protected OsmandActionBarActivity getMyActivity() {
|
||||||
return (OsmandActionBarActivity) getActivity();
|
return (OsmandActionBarActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected OsmandActionBarActivity requireMyActivity() {
|
||||||
|
return (OsmandActionBarActivity) requireActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected OsmandInAppPurchaseActivity getInAppPurchaseActivity() {
|
protected OsmandInAppPurchaseActivity getInAppPurchaseActivity() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity instanceof OsmandInAppPurchaseActivity) {
|
if (activity instanceof OsmandInAppPurchaseActivity) {
|
||||||
|
@ -138,23 +164,28 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected IconsCache getIconsCache() {
|
protected IconsCache getIconsCache() {
|
||||||
if (iconsCache == null) {
|
OsmandApplication app = getMyApplication();
|
||||||
iconsCache = getMyApplication().getIconsCache();
|
if (iconsCache == null && app != null) {
|
||||||
|
iconsCache = app.getIconsCache();
|
||||||
}
|
}
|
||||||
return iconsCache;
|
return iconsCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color) {
|
protected Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color) {
|
||||||
return getIconsCache().getPaintedIcon(id, color);
|
IconsCache cache = getIconsCache();
|
||||||
|
return cache != null ? cache.getPaintedIcon(id, color) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) {
|
protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) {
|
||||||
return getIconsCache().getIcon(id, colorId);
|
IconsCache cache = getIconsCache();
|
||||||
|
return cache != null ? cache.getIcon(id, colorId) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Drawable getContentIcon(@DrawableRes int id) {
|
protected Drawable getContentIcon(@DrawableRes int id) {
|
||||||
return getIconsCache().getThemedIcon(id);
|
IconsCache cache = getIconsCache();
|
||||||
|
return cache != null ? cache.getThemedIcon(id) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setThemedDrawable(View parent, @IdRes int viewId, @DrawableRes int iconId) {
|
protected void setThemedDrawable(View parent, @IdRes int viewId, @DrawableRes int iconId) {
|
||||||
|
@ -165,7 +196,19 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
|
||||||
((ImageView) view).setImageDrawable(getContentIcon(iconId));
|
((ImageView) view).setImageDrawable(getContentIcon(iconId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected OsmandSettings getSettings() {
|
protected OsmandSettings getSettings() {
|
||||||
return getMyApplication().getSettings();
|
OsmandApplication app = getMyApplication();
|
||||||
|
if (app != null) {
|
||||||
|
return app.getSettings();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected OsmandSettings requireSettings() {
|
||||||
|
OsmandApplication app = requireMyApplication();
|
||||||
|
return app.getSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,15 +46,22 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
|
|
||||||
private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite";
|
private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite";
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private ExploreRvAdapter adapter = new ExploreRvAdapter();
|
private ExploreRvAdapter adapter = new ExploreRvAdapter();
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TravelDownloadUpdateCard downloadUpdateCard;
|
private TravelDownloadUpdateCard downloadUpdateCard;
|
||||||
|
@Nullable
|
||||||
private TravelNeededMapsCard neededMapsCard;
|
private TravelNeededMapsCard neededMapsCard;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private DownloadValidationManager downloadManager;
|
private DownloadValidationManager downloadManager;
|
||||||
|
@Nullable
|
||||||
private IndexItem currentDownloadingIndexItem;
|
private IndexItem currentDownloadingIndexItem;
|
||||||
|
@Nullable
|
||||||
private IndexItem mainIndexItem;
|
private IndexItem mainIndexItem;
|
||||||
|
|
||||||
private List<IndexItem> neededIndexItems = new ArrayList<>();
|
private List<IndexItem> neededIndexItems = new ArrayList<>();
|
||||||
private boolean waitForIndexes;
|
private boolean waitForIndexes;
|
||||||
|
|
||||||
|
@ -62,8 +69,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
downloadManager = new DownloadValidationManager(getMyApplication());
|
OsmandApplication app = requireMyApplication();
|
||||||
nightMode = !getMyApplication().getSettings().isLightContent();
|
downloadManager = new DownloadValidationManager(app);
|
||||||
|
nightMode = !app.getSettings().isLightContent();
|
||||||
|
|
||||||
final View mainView = inflater.inflate(R.layout.fragment_explore_tab, container, false);
|
final View mainView = inflater.inflate(R.layout.fragment_explore_tab, container, false);
|
||||||
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
|
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
|
||||||
|
@ -74,6 +82,15 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
return mainView;
|
return mainView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
||||||
|
if (exploreActivity != null) {
|
||||||
|
exploreActivity.onTabFragmentResume(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newDownloadIndexes() {
|
public void newDownloadIndexes() {
|
||||||
if (waitForIndexes) {
|
if (waitForIndexes) {
|
||||||
|
@ -84,26 +101,32 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadInProgress() {
|
public void downloadInProgress() {
|
||||||
IndexItem current = getMyApplication().getDownloadThread().getCurrentDownloadingItem();
|
OsmandApplication app = getMyApplication();
|
||||||
if (current != null && current != currentDownloadingIndexItem) {
|
if (app != null && adapter != null) {
|
||||||
currentDownloadingIndexItem = current;
|
IndexItem current = app.getDownloadThread().getCurrentDownloadingItem();
|
||||||
removeRedundantCards();
|
if (current != null && current != currentDownloadingIndexItem) {
|
||||||
|
currentDownloadingIndexItem = current;
|
||||||
|
removeRedundantCards();
|
||||||
|
}
|
||||||
|
adapter.updateDownloadUpdateCard(true);
|
||||||
|
adapter.updateNeededMapsCard(true);
|
||||||
}
|
}
|
||||||
adapter.updateDownloadUpdateCard(true);
|
|
||||||
adapter.updateNeededMapsCard(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadHasFinished() {
|
public void downloadHasFinished() {
|
||||||
TravelDbHelper travelDbHelper = getMyApplication().getTravelDbHelper();
|
OsmandApplication app = getMyApplication();
|
||||||
if (travelDbHelper.getSelectedTravelBook() == null) {
|
if (app != null) {
|
||||||
getMyApplication().getTravelDbHelper().initTravelBooks();
|
TravelDbHelper travelDbHelper = app.getTravelDbHelper();
|
||||||
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
if (travelDbHelper.getSelectedTravelBook() == null) {
|
||||||
if (exploreActivity != null) {
|
app.getTravelDbHelper().initTravelBooks();
|
||||||
exploreActivity.populateData();
|
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
||||||
|
if (exploreActivity != null) {
|
||||||
|
exploreActivity.populateData();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
removeRedundantCards();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
removeRedundantCards();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,29 +149,32 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
public void populateData() {
|
public void populateData() {
|
||||||
final List<BaseTravelCard> items = new ArrayList<>();
|
final List<BaseTravelCard> items = new ArrayList<>();
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
FragmentManager fm = getFragmentManager();
|
if (app != null) {
|
||||||
if (fm != null) {
|
if (adapter != null) {
|
||||||
if (!Version.isPaidVersion(app)) {
|
FragmentManager fm = getFragmentManager();
|
||||||
items.add(new OpenBetaTravelCard(app, nightMode, fm));
|
if (fm != null) {
|
||||||
}
|
if (!Version.isPaidVersion(app)) {
|
||||||
if (app.getTravelDbHelper().getSelectedTravelBook() != null) {
|
items.add(new OpenBetaTravelCard(app, nightMode, fm));
|
||||||
items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations)));
|
}
|
||||||
|
if (app.getTravelDbHelper().getSelectedTravelBook() != null) {
|
||||||
|
items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations)));
|
||||||
|
|
||||||
List<TravelArticle> popularArticles = app.getTravelDbHelper().getPopularArticles();
|
List<TravelArticle> popularArticles = app.getTravelDbHelper().getPopularArticles();
|
||||||
for (TravelArticle article : popularArticles) {
|
for (TravelArticle article : popularArticles) {
|
||||||
items.add(new ArticleTravelCard(app, nightMode, article, fm));
|
items.add(new ArticleTravelCard(app, nightMode, article, fm));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
items.add(new StartEditingTravelCard(app, getMyActivity(), nightMode));
|
||||||
|
adapter.setItems(items);
|
||||||
|
}
|
||||||
|
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||||
|
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
|
||||||
|
waitForIndexes = true;
|
||||||
|
downloadThread.runReloadIndexFilesSilent();
|
||||||
|
} else {
|
||||||
|
checkDownloadIndexes();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
items.add(new StartEditingTravelCard(app, getMyActivity(), nightMode));
|
|
||||||
adapter.setItems(items);
|
|
||||||
|
|
||||||
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
|
||||||
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
|
|
||||||
waitForIndexes = true;
|
|
||||||
downloadThread.runReloadIndexFilesSilent();
|
|
||||||
} else {
|
|
||||||
checkDownloadIndexes();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,69 +208,74 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
|
|
||||||
private void addDownloadUpdateCard() {
|
private void addDownloadUpdateCard() {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
if (app != null && adapter != null) {
|
||||||
|
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||||
|
|
||||||
boolean outdated = mainIndexItem != null && mainIndexItem.isOutdated();
|
boolean outdated = mainIndexItem != null && mainIndexItem.isOutdated();
|
||||||
File selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
|
File selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
|
||||||
|
|
||||||
if (selectedTravelBook == null || outdated) {
|
if (selectedTravelBook == null || outdated) {
|
||||||
boolean showOtherMaps = false;
|
boolean showOtherMaps = false;
|
||||||
if (selectedTravelBook == null) {
|
if (selectedTravelBook == null) {
|
||||||
List<IndexItem> items = downloadThread.getIndexes().getWikivoyageItems();
|
List<IndexItem> items = downloadThread.getIndexes().getWikivoyageItems();
|
||||||
showOtherMaps = items != null && items.size() > 1;
|
showOtherMaps = items != null && items.size() > 1;
|
||||||
}
|
|
||||||
|
|
||||||
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated);
|
|
||||||
downloadUpdateCard.setShowOtherMapsBtn(showOtherMaps);
|
|
||||||
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onPrimaryButtonClick() {
|
|
||||||
if (mainIndexItem != null) {
|
|
||||||
downloadManager.startDownload(getMyActivity(), mainIndexItem);
|
|
||||||
adapter.updateDownloadUpdateCard(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated);
|
||||||
public void onSecondaryButtonClick() {
|
downloadUpdateCard.setShowOtherMapsBtn(showOtherMaps);
|
||||||
if (downloadUpdateCard.isLoading()) {
|
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() {
|
||||||
downloadThread.cancelDownload(mainIndexItem);
|
@Override
|
||||||
adapter.updateDownloadUpdateCard(false);
|
public void onPrimaryButtonClick() {
|
||||||
} else if (!downloadUpdateCard.isDownload()) {
|
if (mainIndexItem != null && downloadManager != null && adapter != null) {
|
||||||
removeDownloadUpdateCard();
|
downloadManager.startDownload(getMyActivity(), mainIndexItem);
|
||||||
} else if (downloadUpdateCard.isShowOtherMapsBtn()) {
|
adapter.updateDownloadUpdateCard(false);
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null) {
|
|
||||||
Intent newIntent = new Intent(activity,
|
|
||||||
getMyApplication().getAppCustomization().getDownloadActivity());
|
|
||||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
||||||
activity.startActivity(newIntent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
@Override
|
||||||
downloadUpdateCard.setIndexItem(mainIndexItem);
|
public void onSecondaryButtonClick() {
|
||||||
adapter.addDownloadUpdateCard(downloadUpdateCard);
|
if (downloadUpdateCard.isLoading() && adapter != null) {
|
||||||
|
downloadThread.cancelDownload(mainIndexItem);
|
||||||
|
adapter.updateDownloadUpdateCard(false);
|
||||||
|
} else if (!downloadUpdateCard.isDownload()) {
|
||||||
|
removeDownloadUpdateCard();
|
||||||
|
} else if (downloadUpdateCard.isShowOtherMapsBtn()) {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
Intent newIntent = new Intent(activity,
|
||||||
|
getMyApplication().getAppCustomization().getDownloadActivity());
|
||||||
|
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||||
|
activity.startActivity(newIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
downloadUpdateCard.setIndexItem(mainIndexItem);
|
||||||
|
adapter.addDownloadUpdateCard(downloadUpdateCard);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNeededMapsCard() {
|
private void addNeededMapsCard() {
|
||||||
if (!neededIndexItems.isEmpty()) {
|
final OsmandApplication app = getMyApplication();
|
||||||
final OsmandApplication app = getMyApplication();
|
if (app != null && !neededIndexItems.isEmpty() && adapter != null) {
|
||||||
|
|
||||||
neededMapsCard = new TravelNeededMapsCard(app, nightMode, neededIndexItems);
|
neededMapsCard = new TravelNeededMapsCard(app, nightMode, neededIndexItems);
|
||||||
neededMapsCard.setListener(new TravelNeededMapsCard.CardListener() {
|
neededMapsCard.setListener(new TravelNeededMapsCard.CardListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryButtonClick() {
|
public void onPrimaryButtonClick() {
|
||||||
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload());
|
if (adapter != null && downloadManager != null) {
|
||||||
adapter.updateNeededMapsCard(false);
|
downloadManager.startDownload(getMyActivity(), getAllItemsForDownload());
|
||||||
|
adapter.updateNeededMapsCard(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSecondaryButtonClick() {
|
public void onSecondaryButtonClick() {
|
||||||
if (neededMapsCard.isDownloading()) {
|
if (neededMapsCard.isDownloading()) {
|
||||||
app.getDownloadThread().cancelDownload(neededIndexItems);
|
if (adapter != null) {
|
||||||
adapter.updateNeededMapsCard(false);
|
app.getDownloadThread().cancelDownload(neededIndexItems);
|
||||||
|
adapter.updateNeededMapsCard(false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
removeNeededMapsCard();
|
removeNeededMapsCard();
|
||||||
}
|
}
|
||||||
|
@ -261,10 +292,12 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||||
if (downloadThread.isDownloading(item)) {
|
if (downloadThread.isDownloading(item)) {
|
||||||
downloadThread.cancelDownload(item);
|
downloadThread.cancelDownload(item);
|
||||||
} else if (!item.isDownloaded()) {
|
} else if (!item.isDownloaded() && downloadManager != null) {
|
||||||
downloadManager.startDownload(getMyActivity(), item);
|
downloadManager.startDownload(getMyActivity(), item);
|
||||||
}
|
}
|
||||||
adapter.updateNeededMapsCard(false);
|
if (adapter != null) {
|
||||||
|
adapter.updateNeededMapsCard(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -285,17 +318,22 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String getWikivoyageFileName() {
|
private String getWikivoyageFileName() {
|
||||||
File selectedTravelBook = getMyApplication().getTravelDbHelper().getSelectedTravelBook();
|
OsmandApplication app = getMyApplication();
|
||||||
|
File selectedTravelBook = app != null ? app.getTravelDbHelper().getSelectedTravelBook() : null;
|
||||||
return selectedTravelBook == null ? WORLD_WIKIVOYAGE_FILE_NAME : selectedTravelBook.getName();
|
return selectedTravelBook == null ? WORLD_WIKIVOYAGE_FILE_NAME : selectedTravelBook.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeDownloadUpdateCard() {
|
private void removeDownloadUpdateCard() {
|
||||||
adapter.removeDownloadUpdateCard();
|
if (adapter != null) {
|
||||||
|
adapter.removeDownloadUpdateCard();
|
||||||
|
}
|
||||||
downloadUpdateCard = null;
|
downloadUpdateCard = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeNeededMapsCard() {
|
private void removeNeededMapsCard() {
|
||||||
adapter.removeNeededMapsCard();
|
if (adapter != null) {
|
||||||
|
adapter.removeNeededMapsCard();
|
||||||
|
}
|
||||||
neededMapsCard = null;
|
neededMapsCard = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.wikivoyage.explore;
|
package net.osmand.plus.wikivoyage.explore;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
@ -29,14 +30,15 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
||||||
|
|
||||||
protected static final Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
|
protected static final Log LOG = PlatformUtil.getLog(SavedArticlesTabFragment.class);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TravelLocalDataHelper dataHelper;
|
private TravelLocalDataHelper dataHelper;
|
||||||
|
@Nullable
|
||||||
private SavedArticlesRvAdapter adapter;
|
private SavedArticlesRvAdapter adapter;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = requireMyApplication();
|
||||||
dataHelper = app.getTravelDbHelper().getLocalDataHelper();
|
dataHelper = app.getTravelDbHelper().getLocalDataHelper();
|
||||||
|
|
||||||
final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false);
|
final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false);
|
||||||
|
@ -62,22 +64,42 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
dataHelper.setListener(this);
|
if (dataHelper != null) {
|
||||||
|
dataHelper.setListener(this);
|
||||||
|
}
|
||||||
|
WikivoyageExploreActivity exploreActivity = getExploreActivity();
|
||||||
|
if (exploreActivity != null) {
|
||||||
|
exploreActivity.onTabFragmentResume(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
dataHelper.setListener(null);
|
if (dataHelper != null) {
|
||||||
|
dataHelper.setListener(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void savedArticlesUpdated() {
|
public void savedArticlesUpdated() {
|
||||||
List<Object> newItems = getItems();
|
if (adapter != null) {
|
||||||
SavedArticlesDiffCallback diffCallback = new SavedArticlesDiffCallback(adapter.getItems(), newItems);
|
List<Object> newItems = getItems();
|
||||||
DiffUtil.DiffResult diffRes = DiffUtil.calculateDiff(diffCallback);
|
SavedArticlesDiffCallback diffCallback = new SavedArticlesDiffCallback(adapter.getItems(), newItems);
|
||||||
adapter.setItems(newItems);
|
DiffUtil.DiffResult diffRes = DiffUtil.calculateDiff(diffCallback);
|
||||||
diffRes.dispatchUpdatesTo(adapter);
|
adapter.setItems(newItems);
|
||||||
|
diffRes.dispatchUpdatesTo(adapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private WikivoyageExploreActivity getExploreActivity() {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity != null && activity instanceof WikivoyageExploreActivity) {
|
||||||
|
return (WikivoyageExploreActivity) activity;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidateAdapter() {
|
public void invalidateAdapter() {
|
||||||
|
@ -88,11 +110,13 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
|
||||||
|
|
||||||
private List<Object> getItems() {
|
private List<Object> getItems() {
|
||||||
List<Object> items = new ArrayList<>();
|
List<Object> items = new ArrayList<>();
|
||||||
List<TravelArticle> savedArticles = dataHelper.getSavedArticles();
|
if (dataHelper != null) {
|
||||||
if (!savedArticles.isEmpty()) {
|
List<TravelArticle> savedArticles = dataHelper.getSavedArticles();
|
||||||
Collections.reverse(savedArticles);
|
if (!savedArticles.isEmpty()) {
|
||||||
items.add(getString(R.string.saved_articles));
|
Collections.reverse(savedArticles);
|
||||||
items.addAll(savedArticles);
|
items.add(getString(R.string.saved_articles));
|
||||||
|
items.addAll(savedArticles);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class WikivoyageExploreActivity extends TabActivity implements DownloadEvents, OnDialogFragmentResultListener {
|
public class WikivoyageExploreActivity extends TabActivity implements DownloadEvents, OnDialogFragmentResultListener {
|
||||||
|
|
||||||
public static final String INTENT_KEY_PARENT_WIKIVOYAGE_EXPLORE_ACTIVITY = "intent_key_parent_wikivoyage_explore_activity";
|
|
||||||
|
|
||||||
private static final String TAB_SELECTED = "tab_selected";
|
private static final String TAB_SELECTED = "tab_selected";
|
||||||
private static final String CITY_ID_KEY = "city_id_key";
|
private static final String CITY_ID_KEY = "city_id_key";
|
||||||
private static final String SELECTED_LANG_KEY = "selected_lang_key";
|
private static final String SELECTED_LANG_KEY = "selected_lang_key";
|
||||||
|
@ -56,6 +54,7 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
|
||||||
protected List<WeakReference<Fragment>> fragments = new ArrayList<>();
|
protected List<WeakReference<Fragment>> fragments = new ArrayList<>();
|
||||||
|
|
||||||
private LockableViewPager viewPager;
|
private LockableViewPager viewPager;
|
||||||
|
private boolean updateNeeded;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -293,14 +292,18 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
|
||||||
private void onDataLoaded() {
|
private void onDataLoaded() {
|
||||||
switchProgressBarVisibility(false);
|
switchProgressBarVisibility(false);
|
||||||
updateSearchBarVisibility();
|
updateSearchBarVisibility();
|
||||||
|
updateFragments();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFragments() {
|
||||||
ExploreTabFragment exploreTabFragment = getExploreTabFragment();
|
ExploreTabFragment exploreTabFragment = getExploreTabFragment();
|
||||||
if (exploreTabFragment != null) {
|
|
||||||
exploreTabFragment.populateData();
|
|
||||||
}
|
|
||||||
SavedArticlesTabFragment savedArticlesTabFragment = getSavedArticlesTabFragment();
|
SavedArticlesTabFragment savedArticlesTabFragment = getSavedArticlesTabFragment();
|
||||||
if (savedArticlesTabFragment != null) {
|
if (exploreTabFragment != null && savedArticlesTabFragment != null) {
|
||||||
|
exploreTabFragment.populateData();
|
||||||
savedArticlesTabFragment.savedArticlesUpdated();
|
savedArticlesTabFragment.savedArticlesUpdated();
|
||||||
|
updateNeeded = false;
|
||||||
|
} else {
|
||||||
|
updateNeeded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,6 +327,12 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onTabFragmentResume(Fragment fragment) {
|
||||||
|
if (updateNeeded) {
|
||||||
|
updateFragments();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class LoadWikivoyageData extends AsyncTask<Void, Void, Void> {
|
private static class LoadWikivoyageData extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
private WeakReference<WikivoyageExploreActivity> activityRef;
|
private WeakReference<WikivoyageExploreActivity> activityRef;
|
||||||
|
|
Loading…
Reference in a new issue