add sort for popular articles and improve design
This commit is contained in:
parent
ed0c8b0a31
commit
76e6d064c6
6 changed files with 39 additions and 16 deletions
|
@ -5,7 +5,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/list_content_padding"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:layout_marginLeft="@dimen/text_margin_small"
|
||||
android:layout_marginRight="@dimen/text_margin_small"
|
||||
android:background="@drawable/travel_card_bg"
|
||||
|
@ -62,9 +62,9 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_title_height"
|
||||
android:layout_gravity="center"
|
||||
android:paddingBottom="@dimen/abp__shadow_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingTop="@dimen/wikivoyage_travel_card_button_padding"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/list_content_padding"
|
||||
android:layout_marginTop="@dimen/content_padding_small"
|
||||
android:layout_marginLeft="@dimen/text_margin_small"
|
||||
android:layout_marginRight="@dimen/text_margin_small"
|
||||
android:background="@drawable/travel_card_bg">
|
||||
|
@ -69,7 +69,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_title_height"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingTop="@dimen/wikivoyage_travel_card_button_padding"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
|
|
|
@ -208,4 +208,6 @@
|
|||
<dimen name="wikivoyage_search_icon_margin_right">33dp</dimen>
|
||||
<dimen name="wikivoyage_search_divider_margin_start">82dp</dimen>
|
||||
<dimen name="wikivoyage_explore_card_image_height">216dp</dimen>
|
||||
<dimen name="wikivoyage_travel_card_button_padding">22dp</dimen>
|
||||
|
||||
</resources>
|
|
@ -291,6 +291,7 @@
|
|||
<dimen name="wikivoyage_search_icon_margin_left">14dp</dimen>
|
||||
<dimen name="wikivoyage_search_icon_margin_right">22dp</dimen>
|
||||
<dimen name="wikivoyage_search_divider_margin_start">64dp</dimen>
|
||||
<dimen name="wikivoyage_travel_card_button_padding">15dp</dimen>
|
||||
|
||||
<dimen name="wikivoyage_explore_card_image_height">144dp</dimen>
|
||||
|
||||
|
|
|
@ -221,6 +221,9 @@ public class TravelDbHelper {
|
|||
}
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
sortPopularArticles(res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -244,6 +247,27 @@ public class TravelDbHelper {
|
|||
});
|
||||
}
|
||||
|
||||
private void sortPopularArticles(List<TravelArticle> list) {
|
||||
Location location = application.getLocationProvider().getLastKnownLocation();
|
||||
if (location != null) {
|
||||
final LatLon loc = new LatLon(location.getLatitude(), location.getLongitude());
|
||||
Collections.sort(list, new Comparator<TravelArticle>() {
|
||||
@Override
|
||||
public int compare(TravelArticle article1, TravelArticle article2) {
|
||||
int d1 = (int) MapUtils.getDistance(loc, article1.getLat(), article1.getLon());
|
||||
int d2 = (int) MapUtils.getDistance(loc, article2.getLat(), article2.getLon());
|
||||
if (d1 > d2) {
|
||||
return 1;
|
||||
} else if (d1 == d2) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private Collection<WikivoyageSearchResult> groupSearchResultsByCityId(List<WikivoyageSearchResult> res) {
|
||||
String baseLng = application.getLanguage();
|
||||
TLongObjectHashMap<WikivoyageSearchResult> wikivoyage = new TLongObjectHashMap<>();
|
||||
|
|
|
@ -9,12 +9,10 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.LocalIndexHelper;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
|
@ -63,15 +61,11 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
|
||||
addDownloadUpdateCard();
|
||||
startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
|
||||
items.add(new OpenBetaTravelCard(app, nightMode, getFragmentManager()));
|
||||
items.add(startEditingTravelCard);
|
||||
addPopularDestinations(app);
|
||||
addDownloadUpdateCard(nightMode);
|
||||
addOpenBetaTravelCard(items, nightMode);
|
||||
startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
|
||||
items.add(startEditingTravelCard);
|
||||
items.add(getString(R.string.popular_destinations));
|
||||
addPopularDestinations(app, nightMode);
|
||||
addPopularDestinations(app);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
@ -92,10 +86,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
|
||||
private void addPopularDestinations(OsmandApplication app) {
|
||||
PopularDestinationsSearchTask popularDestinationsSearchTask = new PopularDestinationsSearchTask(
|
||||
app.getTravelDbHelper(), getMyActivity(), adapter, nightMode, startEditingTravelCard, progressBar
|
||||
);
|
||||
app.getTravelDbHelper(), getMyActivity(), adapter, nightMode, startEditingTravelCard);
|
||||
popularDestinationsSearchTask.execute();
|
||||
}
|
||||
|
||||
private void addOpenBetaTravelCard(List<Object> items, final boolean nightMode) {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
if ((Version.isFreeVersion(app) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
|
||||
|
@ -103,6 +97,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
items.add(new OpenBetaTravelCard(app, nightMode, getFragmentManager()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class CheckWorldWikivoyageTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
@ -151,7 +146,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
private boolean nightMode;
|
||||
|
||||
PopularDestinationsSearchTask(TravelDbHelper travelDbHelper,
|
||||
OsmandActionBarActivity context, ExploreRvAdapter adapter, boolean nightMode, StartEditingTravelCard startEditingTravelCard, View progressBar) {
|
||||
OsmandActionBarActivity context, ExploreRvAdapter adapter, boolean nightMode, StartEditingTravelCard startEditingTravelCard) {
|
||||
this.travelDbHelper = travelDbHelper;
|
||||
weakContext = new WeakReference<>(context);
|
||||
weakAdapter = new WeakReference<>(adapter);
|
||||
|
|
Loading…
Reference in a new issue