Format and refactor code

This commit is contained in:
Alex Sytnyk 2018-04-28 19:16:58 +03:00
parent 65535f0705
commit 8ec5b17599
6 changed files with 46 additions and 47 deletions

View file

@ -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">

View file

@ -46,5 +46,4 @@
</LinearLayout>
</LinearLayout>

View file

@ -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,11 +72,13 @@ 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();
FragmentActivity activity = getActivity();
if (activity != null) {
for (TravelArticle article : popularArticles) {
items.add(new ArticleTravelCard(getMyApplication(), nightMode, article,
getActivity().getSupportFragmentManager()));
activity.getSupportFragmentManager()));
}
}
}
items.add(startEditingTravelCard);
adapter.setItems(items);
@ -101,8 +101,6 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
}
}
@Override
public void newDownloadIndexes() {
if (downloadIndexesRequested) {
@ -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()));
}
}
}

View file

@ -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,8 +136,10 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
return false;
}
});
updateSearchVisibility();
populateData();
return mainView;
}
@ -153,7 +155,9 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
}
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() {
@ -166,7 +170,7 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
private WeakReference<WikivoyageExploreDialogFragment> weakReference;
private TravelDbHelper travelDbHelper;
public LoadWikivoyageData(WikivoyageExploreDialogFragment fragment) {
LoadWikivoyageData(WikivoyageExploreDialogFragment fragment) {
travelDbHelper = fragment.getMyApplication().getTravelDbHelper();
weakReference = new WeakReference<WikivoyageExploreDialogFragment>(fragment);
}
@ -176,6 +180,7 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
travelDbHelper.loadDataForSelectedTravelBook();
return null;
}
@Override
protected void onPostExecute(Void result) {
WikivoyageExploreDialogFragment option = weakReference.get();
@ -184,7 +189,7 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
}
}
};
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
@ -254,5 +259,4 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
return fragments.size();
}
}
}

View file

@ -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;
}
}