Fix compare by distance

This commit is contained in:
Dima-1 2021-02-08 21:57:12 +02:00
parent 08b5e9fdf9
commit 27ee57339b
5 changed files with 23 additions and 22 deletions

View file

@ -174,9 +174,9 @@ public class TravelDbHelper implements TravelHelper {
}
@Override
public void initializeDataToDisplay(boolean showMore) {
public void initializeDataToDisplay() {
localDataHelper.refreshCachedData();
loadPopularArticles(showMore);
loadPopularArticles();
}
@ -283,7 +283,7 @@ public class TravelDbHelper implements TravelHelper {
}
@NonNull
public List<TravelArticle> loadPopularArticles(boolean showMore) {
public List<TravelArticle> loadPopularArticles() {
String language = application.getLanguage();
SQLiteConnection conn = openConnection();
if (conn == null) {

View file

@ -17,6 +17,7 @@ public interface TravelHelper {
interface GpxReadCallback {
void onGpxFileReading();
void onGpxFileRead(@Nullable GPXFile gpxFile);
}
@ -24,7 +25,7 @@ public interface TravelHelper {
void initializeDataOnAppStartup();
void initializeDataToDisplay(boolean showMore);
void initializeDataToDisplay();
boolean isAnyTravelBookPresent();
@ -35,7 +36,7 @@ public interface TravelHelper {
List<TravelArticle> getPopularArticles();
@NonNull
List<TravelArticle> loadPopularArticles(boolean showMore);
List<TravelArticle> loadPopularArticles();
@NonNull
Map<WikivoyageSearchResult, List<WikivoyageSearchResult>> getNavigationMap(@NonNull TravelArticle article);

View file

@ -100,13 +100,13 @@ public class TravelObfHelper implements TravelHelper {
}
@Override
public void initializeDataToDisplay(boolean showMore) {
public void initializeDataToDisplay() {
localDataHelper.refreshCachedData();
loadPopularArticles(showMore);
loadPopularArticles();
}
@NonNull
public synchronized List<TravelArticle> loadPopularArticles(boolean showMore) {
public synchronized List<TravelArticle> loadPopularArticles() {
String lang = app.getLanguage();
List<TravelArticle> popularArticles = new ArrayList<>();
if (amenities.size() - count < MAX_POPULAR_ARTICLES_COUNT) {
@ -123,9 +123,13 @@ public class TravelObfHelper implements TravelHelper {
Collections.sort(amenities, new Comparator<Pair<File, Amenity>>() {
@Override
public int compare(Pair article1, Pair article2) {
int d1 = (int) (MapUtils.getDistance(((Amenity) article1.second).getLocation(), location));
int d2 = (int) (MapUtils.getDistance(((Amenity) article2.second).getLocation(), location));
return d1 < d2 ? -1 : (d1 == d2 ? 0 : 1);
Amenity amenity1 = (Amenity) article1.second;
double d1 = MapUtils.getDistance(amenity1.getLocation(), location)
/ (ROUTE_ARTICLE.equals(amenity1.getSubType()) ? 5 : 1);
Amenity amenity2 = (Amenity) article2.second;
double d2 = MapUtils.getDistance(amenity2.getLocation(), location)
/ (ROUTE_ARTICLE.equals(amenity2.getSubType()) ? 5 : 1);
return Double.compare(d1, d2);
}
});
}

View file

@ -191,7 +191,9 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv
travelButtonCard.setListener(new TravelNeededMapsCard.CardListener() {
@Override
public void onPrimaryButtonClick() {
new LoadWikivoyageData(ExploreTabFragment.this.getExploreActivity(), true).execute();
if (activity instanceof WikivoyageExploreActivity) {
new LoadWikivoyageData((WikivoyageExploreActivity) activity).execute();
}
}
@Override

View file

@ -314,10 +314,6 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
}
public void populateData() {
populateData(false);
}
public void populateData(final boolean showMore) {
switchProgressBarVisibility(true);
if (app.isApplicationInitializing()) {
final WeakReference<WikivoyageExploreActivity> activityRef = new WeakReference<>(this);
@ -330,12 +326,12 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
public void onFinish(AppInitializer init) {
WikivoyageExploreActivity activity = activityRef.get();
if (AndroidUtils.isActivityNotDestroyed(activity)) {
new LoadWikivoyageData(activity, showMore).execute();
new LoadWikivoyageData(activity).execute();
}
}
});
} else {
new LoadWikivoyageData(this, showMore).execute();
new LoadWikivoyageData(this).execute();
}
}
@ -388,17 +384,15 @@ public class WikivoyageExploreActivity extends TabActivity implements DownloadEv
private final WeakReference<WikivoyageExploreActivity> activityRef;
private final TravelHelper travelHelper;
private final boolean showMore;
LoadWikivoyageData(WikivoyageExploreActivity activity, boolean showMore) {
LoadWikivoyageData(WikivoyageExploreActivity activity) {
travelHelper = activity.getMyApplication().getTravelHelper();
activityRef = new WeakReference<>(activity);
this.showMore = showMore;
}
@Override
protected Void doInBackground(Void... params) {
travelHelper.initializeDataToDisplay(showMore);
travelHelper.initializeDataToDisplay();
return null;
}