commit
a92e002db3
8 changed files with 119 additions and 108 deletions
|
@ -246,24 +246,17 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
|
|||
|
||||
private void updateSaveButton() {
|
||||
if (article != null) {
|
||||
final TravelLocalDataHelper helper = getMyApplication().getTravelHelper().getBookmarksHelper();
|
||||
final boolean saved = helper.isArticleSaved(article);
|
||||
final TravelHelper helper = getMyApplication().getTravelHelper();
|
||||
final boolean saved = helper.getBookmarksHelper().isArticleSaved(article);
|
||||
Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later);
|
||||
saveBtn.setText(getString(saved ? R.string.shared_string_remove : R.string.shared_string_bookmark));
|
||||
saveBtn.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
|
||||
saveBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (article != null) {
|
||||
if (saved) {
|
||||
helper.removeArticleFromSaved(article);
|
||||
} else {
|
||||
getMyApplication().getTravelHelper().createGpxFile(article);
|
||||
helper.addArticleToSaved(article);
|
||||
}
|
||||
helper.saveOrRemoveArticle(article, !saved);
|
||||
updateSaveButton();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,6 +193,15 @@ public class TravelDbHelper implements TravelHelper {
|
|||
return WORLD_WIKIVOYAGE_FILE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save) {
|
||||
if (save) {
|
||||
localDataHelper.addArticleToSaved(article);
|
||||
} else {
|
||||
localDataHelper.removeArticleFromSaved(article);
|
||||
}
|
||||
}
|
||||
|
||||
public List<File> getExistingTravelBooks() {
|
||||
return existingTravelBooks;
|
||||
}
|
||||
|
|
|
@ -70,4 +70,6 @@ public interface TravelHelper {
|
|||
String getSelectedTravelBookName();
|
||||
|
||||
String getWikivoyageFileName();
|
||||
|
||||
void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save);
|
||||
}
|
||||
|
|
|
@ -4,11 +4,13 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.plus.wikivoyage.data.TravelHelper.GpxReadCallback;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -124,14 +126,6 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void restoreSavedArticle(@NonNull TravelArticle article) {
|
||||
if (!isArticleSaved(article)) {
|
||||
savedArticles.add(article);
|
||||
dbHelper.addSavedArticle(article);
|
||||
notifySavedUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeArticleFromSaved(@NonNull TravelArticle article) {
|
||||
TravelArticle savedArticle = getArticle(article.title, article.lang);
|
||||
if (savedArticle != null) {
|
||||
|
@ -480,15 +474,19 @@ public class TravelLocalDataHelper {
|
|||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
context.getTravelHelper().getArticleById(article.generateIdentifier(), article.lang, true,
|
||||
new TravelHelper.GpxReadCallback() {
|
||||
final TravelHelper travelHelper = context.getTravelHelper();
|
||||
travelHelper.getArticleById(article.generateIdentifier(), article.lang, true, new GpxReadCallback() {
|
||||
@Override
|
||||
public void onGpxFileReading() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGpxFileRead(@Nullable GPXUtilities.GPXFile gpxFile) {
|
||||
public void onGpxFileRead(@Nullable GPXFile gpxFile) {
|
||||
if (gpxFile != null) {
|
||||
travelHelper.createGpxFile(article);
|
||||
}
|
||||
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
|
@ -519,11 +517,26 @@ public class TravelLocalDataHelper {
|
|||
});
|
||||
}
|
||||
|
||||
void removeSavedArticle(@NonNull TravelArticle article) {
|
||||
String travelBook = article.getTravelBook(context);
|
||||
void removeSavedArticle(@NonNull final TravelArticle article) {
|
||||
final String travelBook = article.getTravelBook(context);
|
||||
if (travelBook == null) {
|
||||
return;
|
||||
}
|
||||
final TravelHelper travelHelper = context.getTravelHelper();
|
||||
travelHelper.getArticleById(article.generateIdentifier(), article.lang, true, new GpxReadCallback() {
|
||||
@Override
|
||||
public void onGpxFileReading() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGpxFileRead(@Nullable GPXFile gpxFile) {
|
||||
if (gpxFile != null) {
|
||||
String name = travelHelper.getGPXName(article);
|
||||
gpxFile.path = context.getAppPath(IndexConstants.GPX_TRAVEL_DIR + name).getAbsolutePath();
|
||||
context.getSelectedGpxHelper().selectGpxFile(gpxFile, false, true);
|
||||
}
|
||||
|
||||
SQLiteConnection conn = openConnection(false);
|
||||
if (conn != null) {
|
||||
try {
|
||||
|
@ -538,6 +551,8 @@ public class TravelLocalDataHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void updateSavedArticle(@NonNull TravelArticle odlArticle, @NonNull TravelArticle newArticle) {
|
||||
String travelBook = odlArticle.getTravelBook(context);
|
||||
|
|
|
@ -56,10 +56,10 @@ import static net.osmand.GPXUtilities.WptPt;
|
|||
import static net.osmand.GPXUtilities.writeGpxFile;
|
||||
import static net.osmand.plus.helpers.GpxUiHelper.getGpxTitle;
|
||||
import static net.osmand.plus.wikivoyage.data.PopularArticles.ARTICLES_PER_PAGE;
|
||||
import static net.osmand.plus.wikivoyage.data.TravelGpx.ACTIVITY_TYPE;
|
||||
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.ACTIVITY_TYPE;
|
||||
import static net.osmand.plus.wikivoyage.data.TravelGpx.USER;
|
||||
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
||||
|
||||
|
@ -1029,6 +1029,15 @@ public class TravelObfHelper implements TravelHelper {
|
|||
return WORLD_WIKIVOYAGE_FILE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save) {
|
||||
if (save) {
|
||||
localDataHelper.addArticleToSaved(article);
|
||||
} else {
|
||||
localDataHelper.removeArticleFromSaved(article);
|
||||
}
|
||||
}
|
||||
|
||||
private class GpxFileReader extends AsyncTask<Void, Void, GPXFile> {
|
||||
|
||||
private final TravelArticle article;
|
||||
|
|
|
@ -31,13 +31,13 @@ import net.osmand.plus.wikipedia.WikiArticleHelper;
|
|||
import net.osmand.plus.wikivoyage.WikivoyageUtils;
|
||||
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.TravelHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.*;
|
||||
import static net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH;
|
||||
import static net.osmand.util.Algorithms.capitalizeFirstLetterAndLowercase;
|
||||
|
||||
public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
@ -182,20 +182,15 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
|||
|
||||
private void updateSaveButton(final TravelGpxVH holder, final TravelGpx article) {
|
||||
if (article != null) {
|
||||
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
|
||||
final boolean saved = helper.isArticleSaved(article);
|
||||
final TravelHelper helper = app.getTravelHelper();
|
||||
final boolean saved = helper.getBookmarksHelper().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);
|
||||
}
|
||||
helper.saveOrRemoveArticle(article, !saved);
|
||||
updateSaveButton(holder, article);
|
||||
}
|
||||
});
|
||||
|
@ -286,13 +281,13 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
|||
Object item = getItemByPosition();
|
||||
if (item instanceof TravelArticle) {
|
||||
final TravelArticle article = (TravelArticle) item;
|
||||
final TravelLocalDataHelper ldh = app.getTravelHelper().getBookmarksHelper();
|
||||
ldh.removeArticleFromSaved(article);
|
||||
final TravelHelper helper = app.getTravelHelper();
|
||||
helper.saveOrRemoveArticle(article, false);
|
||||
Snackbar snackbar = Snackbar.make(itemView, R.string.article_removed, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ldh.restoreSavedArticle(article);
|
||||
helper.saveOrRemoveArticle(article, true);
|
||||
}
|
||||
});
|
||||
boolean nightMode = !settings.isLightContent();
|
||||
|
|
|
@ -100,16 +100,9 @@ public class ArticleTravelCard extends BaseTravelCard {
|
|||
holder.rightButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (article != null) {
|
||||
if (saved) {
|
||||
helper.removeArticleFromSaved(article);
|
||||
} else {
|
||||
app.getTravelHelper().createGpxFile(article);
|
||||
helper.addArticleToSaved(article);
|
||||
}
|
||||
app.getTravelHelper().saveOrRemoveArticle(article, !saved);
|
||||
updateSaveButton(holder);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.track.TrackMenuFragment;
|
||||
import net.osmand.plus.wikivoyage.data.TravelGpx;
|
||||
import net.osmand.plus.wikivoyage.data.TravelHelper;
|
||||
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -104,19 +103,15 @@ public class TravelGpxCard extends BaseTravelCard {
|
|||
|
||||
private void updateSaveButton(final TravelGpxVH holder) {
|
||||
if (article != null) {
|
||||
final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper();
|
||||
final boolean saved = helper.isArticleSaved(article);
|
||||
final TravelHelper helper = app.getTravelHelper();
|
||||
final boolean saved = helper.getBookmarksHelper().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 {
|
||||
helper.addArticleToSaved(article);
|
||||
}
|
||||
helper.saveOrRemoveArticle(article, !saved);
|
||||
updateSaveButton(holder);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue