Minor code cleanup

This commit is contained in:
Dima-1 2021-01-27 16:33:49 +02:00
parent 048f6035cb
commit bc5ad1a032
4 changed files with 22 additions and 31 deletions

View file

@ -480,23 +480,12 @@ public class TravelLocalDataHelper {
SQLiteConnection conn = openConnection(false); SQLiteConnection conn = openConnection(false);
if (conn != null) { if (conn != null) {
try { try {
String query; String query = "DELETE FROM " + BOOKMARKS_TABLE_NAME +
Object[] parameters; " WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" +
if (article.lang == null) { " AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" +
query = "DELETE FROM " + BOOKMARKS_TABLE_NAME + " AND " + BOOKMARKS_COL_LANG + ((article.lang != null) ? " = '" + article.lang + "'" : " IS NULL") +
" WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" + " AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?";
" AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" + conn.execSQL(query, new Object[]{article.title, article.routeId, travelBook});
" AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?";
parameters = new Object[]{article.title, article.routeId, travelBook};
} else {
query = "DELETE FROM " + BOOKMARKS_TABLE_NAME +
" WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" +
" AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" +
" AND " + BOOKMARKS_COL_LANG + " = ?" +
" AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?";
parameters = new Object[]{article.title, article.routeId, article.lang, travelBook};
}
conn.execSQL(query, parameters);
} finally { } finally {
conn.close(); conn.close();
} }

View file

@ -9,7 +9,6 @@ import androidx.annotation.Nullable;
import net.osmand.Collator; import net.osmand.Collator;
import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.OsmAndCollator; import net.osmand.OsmAndCollator;
@ -49,6 +48,8 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.GPXUtilities.Track;
import static net.osmand.GPXUtilities.TrkSegment;
import static net.osmand.GPXUtilities.WptPt; import static net.osmand.GPXUtilities.WptPt;
import static net.osmand.GPXUtilities.writeGpxFile; import static net.osmand.GPXUtilities.writeGpxFile;
import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle; import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle;
@ -69,6 +70,8 @@ public class TravelObfHelper implements TravelHelper {
public static final int ARTICLE_SEARCH_RADIUS = 50000; public static final int ARTICLE_SEARCH_RADIUS = 50000;
public static final int GPX_TRACKS_SEARCH_RADIUS = 10000; public static final int GPX_TRACKS_SEARCH_RADIUS = 10000;
public static final int MAX_POPULAR_ARTICLES_COUNT = 30; public static final int MAX_POPULAR_ARTICLES_COUNT = 30;
public static final int REF_KEY = 2;
public static final int NAME_KEY = 1;
private final OsmandApplication app; private final OsmandApplication app;
private final Collator collator; private final Collator collator;
@ -178,7 +181,7 @@ public class TravelObfHelper implements TravelHelper {
TravelGpx res = new TravelGpx(); TravelGpx res = new TravelGpx();
res.file = file; res.file = file;
String title = amenity.getName("en"); String title = amenity.getName("en");
res.title = capitalizeFirstLetter(getGpxTitle(Algorithms.isEmpty(title) ? amenity.getName() : title)); res.title = createTitle(Algorithms.isEmpty(title) ? amenity.getName() : title);
res.lat = amenity.getLocation().getLatitude(); res.lat = amenity.getLocation().getLatitude();
res.lon = amenity.getLocation().getLongitude(); res.lon = amenity.getLocation().getLongitude();
res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID)); res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID));
@ -265,8 +268,8 @@ public class TravelObfHelper implements TravelHelper {
@Override @Override
public boolean publish(BinaryMapDataObject object) { public boolean publish(BinaryMapDataObject object) {
if (object.getPointsLength() > 1) { if (object.getPointsLength() > 1) {
if (object.getObjectNames().get(2).equals(ref) if (object.getObjectNames().get(REF_KEY).equals(ref)
&& capitalizeFirstLetter(getGpxTitle(object.getObjectNames().get(1))).equals(article.title)) { && createTitle(object.getObjectNames().get(NAME_KEY)).equals(article.title)) {
segmentList.add(object); segmentList.add(object);
} }
} }
@ -288,17 +291,15 @@ public class TravelObfHelper implements TravelHelper {
} }
GPXFile gpxFile = null; GPXFile gpxFile = null;
if (!segmentList.isEmpty()) { if (!segmentList.isEmpty()) {
GPXUtilities.Track track = new GPXUtilities.Track(); Track track = new Track();
for (BinaryMapDataObject segment : segmentList) { for (BinaryMapDataObject segment : segmentList) {
List<WptPt> pointList = new ArrayList<>(); TrkSegment trkSegment = new TrkSegment();
GPXUtilities.TrkSegment trkSegment = new GPXUtilities.TrkSegment();
for (int i = 0; i < segment.getPointsLength(); i++) { for (int i = 0; i < segment.getPointsLength(); i++) {
WptPt point = new WptPt(); WptPt point = new WptPt();
point.lat = MapUtils.get31LatitudeY(segment.getPoint31YTile(i)); point.lat = MapUtils.get31LatitudeY(segment.getPoint31YTile(i));
point.lon = MapUtils.get31LongitudeX(segment.getPoint31XTile(i)); point.lon = MapUtils.get31LongitudeX(segment.getPoint31XTile(i));
pointList.add(point); trkSegment.points.add(point);
} }
trkSegment.points = pointList;
track.segments.add(trkSegment); track.segments.add(trkSegment);
} }
gpxFile = new GPXFile(article.getTitle(), article.getLang(), ""); gpxFile = new GPXFile(article.getTitle(), article.getLang(), "");
@ -309,6 +310,10 @@ public class TravelObfHelper implements TravelHelper {
return gpxFile; return gpxFile;
} }
private String createTitle(String name) {
return capitalizeFirstLetter(getGpxTitle(name));
}
@NonNull @NonNull
private synchronized List<Amenity> getPointList(@NonNull final TravelArticle article) { private synchronized List<Amenity> getPointList(@NonNull final TravelArticle article) {
final List<Amenity> pointList = new ArrayList<>(); final List<Amenity> pointList = new ArrayList<>();

View file

@ -11,7 +11,6 @@ import androidx.annotation.DrawableRes;
import androidx.annotation.LayoutRes; import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -26,7 +25,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.WikivoyageUtils;
@ -35,7 +33,6 @@ import net.osmand.plus.wikivoyage.data.TravelGpx;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -61,7 +58,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
this.listener = listener; this.listener = listener;
} }
SavedArticlesRvAdapter(OsmandApplication app, FragmentActivity activity) { SavedArticlesRvAdapter(OsmandApplication app) {
this.app = app; this.app = app;
this.settings = app.getSettings(); this.settings = app.getSettings();
picasso = PicassoUtils.getPicasso(app); picasso = PicassoUtils.getPicasso(app);

View file

@ -48,7 +48,7 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Trav
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);
adapter = new SavedArticlesRvAdapter(app, getActivity()); adapter = new SavedArticlesRvAdapter(app);
adapter.setListener(new SavedArticlesRvAdapter.Listener() { adapter.setListener(new SavedArticlesRvAdapter.Listener() {
@Override @Override
public void openArticle(TravelArticle article) { public void openArticle(TravelArticle article) {