Add the ability to undo deletion from saved articles list

This commit is contained in:
Alex Sytnyk 2018-04-11 14:30:50 +03:00
parent cecb6a7ee0
commit f85a67beec
4 changed files with 33 additions and 5 deletions

View file

@ -103,10 +103,17 @@
</FrameLayout> </FrameLayout>
<net.osmand.plus.LockableViewPager <!-- Coordinator layout is needed in order to display the snackbar above the bottom navigation -->
android:id="@+id/view_pager" <android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="wrap_content">
<net.osmand.plus.LockableViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout> </LinearLayout>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="article_removed">Article removed</string>
<string name="wikivoyage_search_hint">Search: Country, City, Province</string> <string name="wikivoyage_search_hint">Search: Country, City, Province</string>
<string name="shared_string_read">Read</string> <string name="shared_string_read">Read</string>
<string name="saved_articles">Saved articles</string> <string name="saved_articles">Saved articles</string>

View file

@ -109,6 +109,14 @@ public class WikivoyageLocalDataHelper {
} }
} }
public void restoreSavedArticle(@NonNull WikivoyageArticle article) {
if (!isArticleSaved(article)) {
savedArticles.add(article);
dbHelper.addSavedArticle(article);
notifySavedUpdated();
}
}
public void removeArticleFromSaved(@NonNull WikivoyageArticle article) { public void removeArticleFromSaved(@NonNull WikivoyageArticle article) {
WikivoyageArticle savedArticle = getArticle(article.cityId, article.lang); WikivoyageArticle savedArticle = getArticle(article.cityId, article.lang);
if (savedArticle != null) { if (savedArticle != null) {

View file

@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.explore;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -10,6 +11,7 @@ import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -129,7 +131,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
final View divider; final View divider;
final View shadow; final View shadow;
ItemVH(View itemView) { ItemVH(final View itemView) {
super(itemView); super(itemView);
title = (TextView) itemView.findViewById(R.id.title); title = (TextView) itemView.findViewById(R.id.title);
content = (TextView) itemView.findViewById(R.id.content); content = (TextView) itemView.findViewById(R.id.content);
@ -160,7 +162,17 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
public void onClick(View view) { public void onClick(View view) {
Object item = getItemByPosition(); Object item = getItemByPosition();
if (item != null && item instanceof WikivoyageArticle) { if (item != null && item instanceof WikivoyageArticle) {
WikivoyageLocalDataHelper.getInstance(app).removeArticleFromSaved((WikivoyageArticle) item); final WikivoyageArticle article = (WikivoyageArticle) item;
WikivoyageLocalDataHelper.getInstance(app).removeArticleFromSaved(article);
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) {
WikivoyageLocalDataHelper.getInstance(app).restoreSavedArticle(article);
}
});
AndroidUtils.setSnackbarTextColor(snackbar, R.color.wikivoyage_active_dark);
snackbar.show();
} }
} }
}); });