Format and refactor code
This commit is contained in:
parent
65535f0705
commit
8ec5b17599
6 changed files with 46 additions and 47 deletions
|
@ -61,18 +61,18 @@
|
|||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="match_parent"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:indeterminate="true"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/search_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/text_margin_small"
|
||||
android:layout_marginRight="@dimen/text_margin_small"
|
||||
android:background="@drawable/wikivoyage_search_card_bg">
|
||||
|
|
|
@ -46,5 +46,4 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -121,7 +121,7 @@ public class TravelDbHelper {
|
|||
selectedTravelBook = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void loadDataForSelectedTravelBook() {
|
||||
localDataHelper.refreshCachedData();
|
||||
loadPopularArticles();
|
||||
|
@ -212,7 +212,7 @@ public class TravelDbHelper {
|
|||
public List<TravelArticle> getPopularArticles() {
|
||||
return popularArticles;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public List<TravelArticle> loadPopularArticles() {
|
||||
List<TravelArticle> res = new ArrayList<>();
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package net.osmand.plus.wikivoyage.explore;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.download.DownloadIndexesThread;
|
||||
import net.osmand.plus.download.DownloadValidationManager;
|
||||
|
@ -28,7 +29,6 @@ import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
|||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -63,8 +63,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
return mainView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void populateData() {
|
||||
final List<BaseTravelCard> items = new ArrayList<>();
|
||||
final OsmandApplication app = getMyApplication();
|
||||
|
@ -74,18 +72,20 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
if (app.getTravelDbHelper().getSelectedTravelBook() != null) {
|
||||
items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations)));
|
||||
List<TravelArticle> popularArticles = app.getTravelDbHelper().getPopularArticles();
|
||||
for (TravelArticle article : popularArticles) {
|
||||
items.add(new ArticleTravelCard(getMyApplication(), nightMode, article,
|
||||
getActivity().getSupportFragmentManager()));
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
for (TravelArticle article : popularArticles) {
|
||||
items.add(new ArticleTravelCard(getMyApplication(), nightMode, article,
|
||||
activity.getSupportFragmentManager()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
items.add(startEditingTravelCard);
|
||||
adapter.setItems(items);
|
||||
|
||||
|
||||
checkToAddDownloadTravelCard();
|
||||
}
|
||||
|
||||
|
||||
private void checkToAddDownloadTravelCard() {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
|
@ -100,8 +100,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
addDownloadUpdateCard(loadingInProgress);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
|
@ -109,7 +107,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
downloadIndexesRequested = false;
|
||||
indexItem = getMyApplication().getDownloadThread().getIndexes()
|
||||
.getWikivoyageItem(getWikivoyageFileName());
|
||||
if(downloadUpdateCard == null) {
|
||||
if (downloadUpdateCard == null) {
|
||||
addDownloadUpdateCard(false);
|
||||
}
|
||||
}
|
||||
|
@ -131,13 +129,18 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
File targetFile = indexItem.getTargetFile(getMyApplication());
|
||||
final OsmandApplication app = getMyApplication();
|
||||
File targetFile = indexItem.getTargetFile(app);
|
||||
if (downloadUpdateCard != null && indexItem != null && targetFile.exists()) {
|
||||
downloadUpdateCard.setLoadingInProgress(false);
|
||||
removeDownloadUpdateCard();
|
||||
getMyApplication().getTravelDbHelper().initTravelBooks();
|
||||
getMyApplication().getTravelDbHelper().selectTravelBook(targetFile);
|
||||
((WikivoyageExploreDialogFragment)getParentFragment()).populateData();
|
||||
TravelDbHelper travelDbHelper = app.getTravelDbHelper();
|
||||
travelDbHelper.initTravelBooks();
|
||||
travelDbHelper.selectTravelBook(targetFile);
|
||||
Fragment parent = getParentFragment();
|
||||
if (parent != null && parent instanceof WikivoyageExploreDialogFragment) {
|
||||
((WikivoyageExploreDialogFragment) parent).populateData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,14 +191,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
|||
downloadUpdateCard = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void addOpenBetaTravelCard(List<BaseTravelCard> items, final boolean nightMode) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
if (!Version.isPaidVersion(app)) {
|
||||
items.add(new OpenBetaTravelCard(app, nightMode, getFragmentManager()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.PicassoUtils;
|
||||
import net.osmand.plus.LockableViewPager;
|
||||
|
@ -58,7 +59,6 @@ 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) {
|
||||
|
@ -136,37 +136,41 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
updateSearchVisibility();
|
||||
populateData();
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
||||
|
||||
protected void onDataLoaded() {
|
||||
mainView.findViewById(R.id.progress_bar).setVisibility(View.GONE);
|
||||
updateSearchVisibility();
|
||||
if(exploreTabFragment != null) {
|
||||
if (exploreTabFragment != null) {
|
||||
exploreTabFragment.populateData();
|
||||
}
|
||||
if(savedArticlesTabFragment != null) {
|
||||
if (savedArticlesTabFragment != null) {
|
||||
savedArticlesTabFragment.savedArticlesUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSearchVisibility() {
|
||||
mainView.findViewById(R.id.search_box).setVisibility(getMyApplication().getTravelDbHelper().getSelectedTravelBook() == null ? View.GONE : View.VISIBLE);
|
||||
mainView.findViewById(R.id.search_box).setVisibility(
|
||||
getMyApplication().getTravelDbHelper().getSelectedTravelBook() == null ? View.GONE : View.VISIBLE
|
||||
);
|
||||
}
|
||||
|
||||
public void populateData() {
|
||||
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
||||
new LoadWikivoyageData(this).execute();
|
||||
}
|
||||
|
||||
|
||||
private static class LoadWikivoyageData extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
|
||||
private WeakReference<WikivoyageExploreDialogFragment> weakReference;
|
||||
private TravelDbHelper travelDbHelper;
|
||||
|
||||
public LoadWikivoyageData(WikivoyageExploreDialogFragment fragment) {
|
||||
LoadWikivoyageData(WikivoyageExploreDialogFragment fragment) {
|
||||
travelDbHelper = fragment.getMyApplication().getTravelDbHelper();
|
||||
weakReference = new WeakReference<WikivoyageExploreDialogFragment>(fragment);
|
||||
}
|
||||
|
@ -176,15 +180,16 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
travelDbHelper.loadDataForSelectedTravelBook();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
WikivoyageExploreDialogFragment option = weakReference.get();
|
||||
if(option != null && option.isResumed()) {
|
||||
if (option != null && option.isResumed()) {
|
||||
option.onDataLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
@ -254,5 +259,4 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
return fragments.size();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.wikivoyage.explore.travelcards;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -16,7 +15,6 @@ public class HeaderTravelCard extends BaseTravelCard {
|
|||
private int articleItemCount;
|
||||
private String title;
|
||||
|
||||
|
||||
public HeaderTravelCard(OsmandApplication app, boolean nightMode, String title) {
|
||||
super(app, nightMode);
|
||||
this.title = title;
|
||||
|
@ -57,4 +55,3 @@ public class HeaderTravelCard extends BaseTravelCard {
|
|||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue