Add to bookmarks, build gpx track
This commit is contained in:
parent
a914efaa28
commit
fea90fd37e
5 changed files with 198 additions and 34 deletions
|
@ -1,6 +1,12 @@
|
||||||
package net.osmand.plus.wikivoyage.data;
|
package net.osmand.plus.wikivoyage.data;
|
||||||
|
|
||||||
public class TravelGpx extends TravelArticle {
|
public class TravelGpx extends TravelArticle {
|
||||||
|
|
||||||
|
public static final String DISTANCE = "distance";
|
||||||
|
public static final String DIFF_ELE_UP = "diff_ele_up";
|
||||||
|
public static final String DIFF_ELE_DOWN = "diff_ele_down";
|
||||||
|
public static final String USER = "user";
|
||||||
|
|
||||||
public String user;
|
public String user;
|
||||||
public float totalDistance = 0;
|
public float totalDistance = 0;
|
||||||
public double diffElevationUp = 0;
|
public double diffElevationUp = 0;
|
||||||
|
|
|
@ -143,6 +143,9 @@ public class TravelLocalDataHelper {
|
||||||
@Nullable
|
@Nullable
|
||||||
private TravelArticle getArticle(String title, String lang) {
|
private TravelArticle getArticle(String title, String lang) {
|
||||||
for (TravelArticle article : savedArticles) {
|
for (TravelArticle article : savedArticles) {
|
||||||
|
if (article.lang == null && lang == null && article.title != null && article.title.equals(title)) {
|
||||||
|
return article;
|
||||||
|
}
|
||||||
if (article.title != null && article.title.equals(title) && article.lang != null && article.lang.equals(lang)) {
|
if (article.title != null && article.title.equals(title) && article.lang != null && article.lang.equals(lang)) {
|
||||||
return article;
|
return article;
|
||||||
}
|
}
|
||||||
|
@ -477,12 +480,23 @@ public class TravelLocalDataHelper {
|
||||||
SQLiteConnection conn = openConnection(false);
|
SQLiteConnection conn = openConnection(false);
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
try {
|
try {
|
||||||
conn.execSQL("DELETE FROM " + BOOKMARKS_TABLE_NAME +
|
String query;
|
||||||
" WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" +
|
Object[] parameters;
|
||||||
" AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" +
|
if (article.lang == null) {
|
||||||
" AND " + BOOKMARKS_COL_LANG + " = ?" +
|
query = "DELETE FROM " + BOOKMARKS_TABLE_NAME +
|
||||||
" AND " + BOOKMARKS_COL_TRAVEL_BOOK + " = ?",
|
" WHERE " + BOOKMARKS_COL_ARTICLE_TITLE + " = ?" +
|
||||||
new Object[]{article.title, article.routeId, article.lang, travelBook});
|
" AND " + BOOKMARKS_COL_ROUTE_ID + " = ?" +
|
||||||
|
" 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();
|
||||||
}
|
}
|
||||||
|
@ -537,7 +551,12 @@ public class TravelLocalDataHelper {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private TravelArticle readSavedArticle(SQLiteCursor cursor) {
|
private TravelArticle readSavedArticle(SQLiteCursor cursor) {
|
||||||
TravelArticle res = new TravelArticle();
|
TravelArticle res;
|
||||||
|
if (cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_LANG)) == null) {
|
||||||
|
res = new TravelGpx();
|
||||||
|
} else {
|
||||||
|
res = new TravelArticle();
|
||||||
|
}
|
||||||
res.title = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_ARTICLE_TITLE));
|
res.title = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_ARTICLE_TITLE));
|
||||||
res.lang = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_LANG));
|
res.lang = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_LANG));
|
||||||
res.aggregatedPartOf = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_IS_PART_OF));
|
res.aggregatedPartOf = cursor.getString(cursor.getColumnIndex(BOOKMARKS_COL_IS_PART_OF));
|
||||||
|
|
|
@ -8,11 +8,13 @@ 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;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
|
import net.osmand.binary.BinaryMapDataObject;
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
|
@ -48,6 +50,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
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;
|
||||||
|
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_DOWN;
|
||||||
|
import static net.osmand.plus.wikivoyage.data.TravelGpx.DIFF_ELE_UP;
|
||||||
|
import static net.osmand.plus.wikivoyage.data.TravelGpx.DISTANCE;
|
||||||
|
import static net.osmand.plus.wikivoyage.data.TravelGpx.USER;
|
||||||
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
||||||
|
|
||||||
public class TravelObfHelper implements TravelHelper {
|
public class TravelObfHelper implements TravelHelper {
|
||||||
|
@ -168,25 +174,26 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
private Map<String, TravelArticle> readRoutePoint(File file, Amenity amenity) {
|
private Map<String, TravelArticle> readRoutePoint(File file, Amenity amenity) {
|
||||||
Map<String, TravelArticle> articles = new HashMap<>();
|
Map<String, TravelArticle> articles = new HashMap<>();
|
||||||
TravelGpx res = new TravelGpx();
|
TravelGpx res = new TravelGpx();
|
||||||
|
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 = capitalizeFirstLetter(getGpxTitle(Algorithms.isEmpty(title) ? amenity.getName() : title));
|
||||||
res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID));
|
res.routeId = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.ROUTE_ID));
|
||||||
try {
|
try {
|
||||||
res.totalDistance = Float.parseFloat(Algorithms.emptyIfNull(amenity.getTagContent("distance")));
|
res.totalDistance = Float.parseFloat(Algorithms.emptyIfNull(amenity.getTagContent(DISTANCE)));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
LOG.debug(e.getMessage(), e);
|
LOG.debug(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
res.diffElevationUp = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent("diff_ele_up")));
|
res.diffElevationUp = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(DIFF_ELE_UP)));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
LOG.debug(e.getMessage(), e);
|
LOG.debug(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
res.diffElevationDown = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent("diff_ele_down")));
|
res.diffElevationDown = Double.parseDouble(Algorithms.emptyIfNull(amenity.getTagContent(DIFF_ELE_DOWN)));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
LOG.debug(e.getMessage(), e);
|
LOG.debug(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
res.user = Algorithms.emptyIfNull(amenity.getTagContent("user"));
|
res.user = Algorithms.emptyIfNull(amenity.getTagContent(USER));
|
||||||
articles.put("en", res);
|
articles.put("en", res);
|
||||||
return articles;
|
return articles;
|
||||||
}
|
}
|
||||||
|
@ -255,6 +262,66 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
return gpxFile;
|
return gpxFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private GPXFile buildTravelGpxFile(@NonNull final TravelGpx article) {
|
||||||
|
String routeId = article.getRouteId();
|
||||||
|
final String ref = routeId.substring(routeId.length() - 3);
|
||||||
|
final List<BinaryMapDataObject> segmentList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (BinaryMapIndexReader reader : getReaders()) {
|
||||||
|
try {
|
||||||
|
if (article.file != null && !article.file.equals(reader.getFile())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BinaryMapIndexReader.SearchRequest<BinaryMapDataObject> sr = BinaryMapIndexReader.buildSearchRequest(
|
||||||
|
0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, 15, null,
|
||||||
|
new ResultMatcher<BinaryMapDataObject>() {
|
||||||
|
@Override
|
||||||
|
public boolean publish(BinaryMapDataObject object) {
|
||||||
|
if (object.getPointsLength() > 1) {
|
||||||
|
if (object.getObjectNames().get(2).equals(ref)
|
||||||
|
&& capitalizeFirstLetter(getGpxTitle(object.getObjectNames().get(1))).equals(article.title)) {
|
||||||
|
segmentList.add(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
reader.searchMapIndex(sr);
|
||||||
|
if (!Algorithms.isEmpty(segmentList)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GPXFile gpxFile = null;
|
||||||
|
if (!segmentList.isEmpty()) {
|
||||||
|
GPXUtilities.Track track = new GPXUtilities.Track();
|
||||||
|
for (BinaryMapDataObject segment : segmentList) {
|
||||||
|
List<WptPt> pointList = new ArrayList<>();
|
||||||
|
GPXUtilities.TrkSegment trkSegment = new GPXUtilities.TrkSegment();
|
||||||
|
for (int i = 0; i < segment.getPointsLength(); i++) {
|
||||||
|
WptPt point = new WptPt();
|
||||||
|
point.lat = MapUtils.get31LatitudeY(segment.getPoint31YTile(i));
|
||||||
|
point.lon = MapUtils.get31LongitudeX(segment.getPoint31XTile(i));
|
||||||
|
pointList.add(point);
|
||||||
|
}
|
||||||
|
trkSegment.points = pointList;
|
||||||
|
track.segments.add(trkSegment);
|
||||||
|
}
|
||||||
|
gpxFile = new GPXFile(article.getTitle(), article.getLang(), "");
|
||||||
|
gpxFile.tracks = new ArrayList<>();
|
||||||
|
gpxFile.tracks.add(track);
|
||||||
|
}
|
||||||
|
return gpxFile;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private List<Amenity> getPointList(@NonNull final TravelArticle article) {
|
private List<Amenity> getPointList(@NonNull final TravelArticle article) {
|
||||||
final List<Amenity> pointList = new ArrayList<>();
|
final List<Amenity> pointList = new ArrayList<>();
|
||||||
|
@ -744,7 +811,12 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public File createGpxFile(@NonNull final TravelArticle article) {
|
public File createGpxFile(@NonNull final TravelArticle article) {
|
||||||
final GPXFile gpx = article.getGpxFile();
|
final GPXFile gpx;
|
||||||
|
if (article instanceof TravelGpx) {
|
||||||
|
gpx = buildTravelGpxFile((TravelGpx) article);
|
||||||
|
} else {
|
||||||
|
gpx = article.getGpxFile();
|
||||||
|
}
|
||||||
File file = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + getGPXName(article));
|
File file = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + getGPXName(article));
|
||||||
writeGpxFile(file, gpx);
|
writeGpxFile(file, gpx);
|
||||||
return file;
|
return file;
|
||||||
|
|
|
@ -7,6 +7,8 @@ import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes;
|
||||||
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
@ -16,16 +18,20 @@ import com.squareup.picasso.Callback;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
import com.squareup.picasso.RequestCreator;
|
import com.squareup.picasso.RequestCreator;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.PicassoUtils;
|
import net.osmand.PicassoUtils;
|
||||||
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
|
||||||
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.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;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||||
|
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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -33,7 +39,8 @@ import java.util.List;
|
||||||
public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private static final int HEADER_TYPE = 0;
|
private static final int HEADER_TYPE = 0;
|
||||||
private static final int ITEM_TYPE = 1;
|
private static final int ARTICLE_TYPE = 1;
|
||||||
|
private static final int GPX_TYPE = 2;
|
||||||
|
|
||||||
private final OsmandApplication app;
|
private final OsmandApplication app;
|
||||||
private final OsmandSettings settings;
|
private final OsmandSettings settings;
|
||||||
|
@ -45,6 +52,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
private final Drawable readIcon;
|
private final Drawable readIcon;
|
||||||
private final Drawable deleteIcon;
|
private final Drawable deleteIcon;
|
||||||
private PicassoUtils picasso;
|
private PicassoUtils picasso;
|
||||||
|
boolean nightMode;
|
||||||
|
|
||||||
public void setListener(Listener listener) {
|
public void setListener(Listener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
@ -54,21 +62,34 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.settings = app.getSettings();
|
this.settings = app.getSettings();
|
||||||
picasso = PicassoUtils.getPicasso(app);
|
picasso = PicassoUtils.getPicasso(app);
|
||||||
|
nightMode = !app.getSettings().isLightContent();
|
||||||
|
readIcon = getActiveIcon(R.drawable.ic_action_read_article);
|
||||||
|
deleteIcon = getActiveIcon(R.drawable.ic_action_read_later_fill);
|
||||||
|
}
|
||||||
|
|
||||||
int colorId = settings.isLightContent()
|
private Drawable getActiveIcon(@DrawableRes int iconId) {
|
||||||
? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark;
|
int colorId = nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light;
|
||||||
UiUtilities ic = app.getUIUtilities();
|
return app.getUIUtilities().getIcon(iconId, colorId);
|
||||||
readIcon = ic.getIcon(R.drawable.ic_action_read_article, colorId);
|
|
||||||
deleteIcon = ic.getIcon(R.drawable.ic_action_read_later_fill, colorId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
boolean header = viewType == HEADER_TYPE;
|
switch (viewType) {
|
||||||
int layoutId = header ? R.layout.wikivoyage_list_header : R.layout.wikivoyage_article_card;
|
case HEADER_TYPE:
|
||||||
View itemView = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
|
return new HeaderVH(inflate(parent, R.layout.wikivoyage_list_header));
|
||||||
return header ? new HeaderVH(itemView) : new ItemVH(itemView);
|
case ARTICLE_TYPE:
|
||||||
|
return new ItemVH(inflate(parent, R.layout.wikivoyage_article_card));
|
||||||
|
case GPX_TYPE:
|
||||||
|
return new TravelGpxCard.TravelGpxVH(inflate(parent, R.layout.wikivoyage_travel_gpx_card));
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unsupported view type: " + viewType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private View inflate(@NonNull ViewGroup parent, @LayoutRes int layoutId) {
|
||||||
|
return LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,7 +98,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
final HeaderVH holder = (HeaderVH) viewHolder;
|
final HeaderVH holder = (HeaderVH) viewHolder;
|
||||||
holder.title.setText((String) getItem(position));
|
holder.title.setText((String) getItem(position));
|
||||||
holder.description.setText(String.valueOf(items.size() - 1));
|
holder.description.setText(String.valueOf(items.size() - 1));
|
||||||
} else {
|
} else if (viewHolder instanceof ItemVH) {
|
||||||
final ItemVH holder = (ItemVH) viewHolder;
|
final ItemVH holder = (ItemVH) viewHolder;
|
||||||
TravelArticle article = (TravelArticle) getItem(position);
|
TravelArticle article = (TravelArticle) getItem(position);
|
||||||
final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
|
final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
|
||||||
|
@ -111,6 +132,50 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, deleteIcon, null);
|
holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, deleteIcon, null);
|
||||||
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
||||||
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
||||||
|
} else if (viewHolder instanceof TravelGpxCard.TravelGpxVH) {
|
||||||
|
final TravelGpx article = (TravelGpx) getItem(position);
|
||||||
|
final TravelGpxCard.TravelGpxVH holder = (TravelGpxCard.TravelGpxVH) viewHolder;
|
||||||
|
holder.title.setText(article.getTitle());
|
||||||
|
Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16);
|
||||||
|
holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||||
|
holder.user.setText(WikiArticleHelper.getPartialContent(article.user));
|
||||||
|
AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark);
|
||||||
|
holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
|
||||||
|
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
||||||
|
holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown, app));
|
||||||
|
holder.leftButton.setText(app.getString(R.string.shared_string_view));
|
||||||
|
View.OnClickListener readClickListener = new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
app.getTravelHelper().createGpxFile(article);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
holder.leftButton.setOnClickListener(readClickListener);
|
||||||
|
holder.itemView.setOnClickListener(readClickListener);
|
||||||
|
holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null);
|
||||||
|
updateSaveButton(holder, article);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSaveButton(final TravelGpxCard.TravelGpxVH holder, final TravelGpx article) {
|
||||||
|
if (article != null) {
|
||||||
|
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
|
||||||
|
final boolean saved = helper.isArticleSaved(article);
|
||||||
|
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
|
||||||
|
holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save);
|
||||||
|
holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
|
||||||
|
holder.rightButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (saved) {
|
||||||
|
helper.removeArticleFromSaved(article);
|
||||||
|
} else {
|
||||||
|
app.getTravelHelper().createGpxFile(article);
|
||||||
|
helper.addArticleToSaved(article);
|
||||||
|
}
|
||||||
|
updateSaveButton(holder, article);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +183,10 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
if (getItem(position) instanceof String) {
|
if (getItem(position) instanceof String) {
|
||||||
return HEADER_TYPE;
|
return HEADER_TYPE;
|
||||||
|
} else if (getItem(position) instanceof TravelGpx) {
|
||||||
|
return GPX_TYPE;
|
||||||
}
|
}
|
||||||
return ITEM_TYPE;
|
return ARTICLE_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -89,15 +89,15 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
|
|
||||||
public static class TravelGpxVH extends RecyclerView.ViewHolder {
|
public static class TravelGpxVH extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
final TextView title;
|
public final TextView title;
|
||||||
final TextView user;
|
public final TextView user;
|
||||||
final TextView distance;
|
public final TextView distance;
|
||||||
final TextView diffElevationUp;
|
public final TextView diffElevationUp;
|
||||||
final TextView diffElevationDown;
|
public final TextView diffElevationDown;
|
||||||
final TextView leftButton;
|
public final TextView leftButton;
|
||||||
final TextView rightButton;
|
public final TextView rightButton;
|
||||||
final View divider;
|
public final View divider;
|
||||||
final View shadow;
|
public final View shadow;
|
||||||
|
|
||||||
public TravelGpxVH(final View itemView) {
|
public TravelGpxVH(final View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
Loading…
Reference in a new issue