Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-11 11:40:52 +02:00
commit e5f6d89837
2 changed files with 31 additions and 6 deletions

View file

@ -9,7 +9,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
@ -29,9 +28,15 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
private final List<Object> items = new ArrayList<>();
private Listener listener;
private final Drawable readIcon;
private final Drawable deleteIcon;
public void setListener(Listener listener) {
this.listener = listener;
}
SavedArticlesRvAdapter(OsmandApplication app) {
this.app = app;
int colorId = app.getSettings().isLightContent()
@ -140,8 +145,9 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
public void onClick(View view) {
Object item = getItemByPosition();
if (item != null && item instanceof WikivoyageArticle) {
WikivoyageArticle article = (WikivoyageArticle) item;
Toast.makeText(app, "read: " + article.getTitle(), Toast.LENGTH_SHORT).show();
if (listener != null) {
listener.openArticle((WikivoyageArticle) item);
}
}
}
};
@ -169,4 +175,8 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter<RecyclerView.Vi
return null;
}
}
interface Listener {
void openArticle(WikivoyageArticle article);
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.explore;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -10,8 +11,10 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
@ -28,11 +31,22 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
dataHelper = WikivoyageLocalDataHelper.getInstance(getMyApplication());
adapter = new SavedArticlesRvAdapter(getMyApplication());
final OsmandApplication app = getMyApplication();
dataHelper = WikivoyageLocalDataHelper.getInstance(app);
final View mainView = inflater.inflate(R.layout.fragment_saved_articles_tab, container, false);
adapter = new SavedArticlesRvAdapter(app);
adapter.setListener(new SavedArticlesRvAdapter.Listener() {
@Override
public void openArticle(WikivoyageArticle article) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
WikivoyageArticleDialogFragment.showInstance(app, fm, article.getCityId(), article.getLang());
}
}
});
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setAdapter(adapter);
@ -58,8 +72,9 @@ public class SavedArticlesTabFragment extends BaseOsmAndFragment implements Wiki
public void savedArticlesUpdated() {
List<Object> newItems = getItems();
SavedArticlesDiffCallback diffCallback = new SavedArticlesDiffCallback(adapter.getItems(), newItems);
DiffUtil.DiffResult diffRes = DiffUtil.calculateDiff(diffCallback);
adapter.setItems(newItems);
DiffUtil.calculateDiff(diffCallback).dispatchUpdatesTo(adapter);
diffRes.dispatchUpdatesTo(adapter);
}
private List<Object> getItems() {