Add wikivoyage search history UI
This commit is contained in:
parent
21f2406dcc
commit
d9b641c420
5 changed files with 91 additions and 18 deletions
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="oval">
|
||||||
|
<solid android:color="@color/color_transparent"/>
|
||||||
|
<size
|
||||||
|
android:width="28dp"
|
||||||
|
android:height="28dp"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
android:id="@+id/placeholder_icon"
|
||||||
|
android:bottom="2dp"
|
||||||
|
android:left="2dp"
|
||||||
|
android:right="2dp"
|
||||||
|
android:top="2dp">
|
||||||
|
|
||||||
|
<bitmap
|
||||||
|
android:gravity="center"
|
||||||
|
android:src="@drawable/ic_action_history"
|
||||||
|
android:tint="@color/icon_color"/>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
|
@ -1,6 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
>
|
|
||||||
<item>
|
<item>
|
||||||
<shape android:shape="oval">
|
<shape android:shape="oval">
|
||||||
<solid android:color="@color/color_transparent"/>
|
<solid android:color="@color/color_transparent"/>
|
||||||
|
|
|
@ -22,6 +22,7 @@ import net.osmand.AndroidUtils;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||||
|
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -146,6 +147,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WikivoyageLocalDataHelper.getInstance(getMyApplication()).addToHistory(article);
|
||||||
|
|
||||||
contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null);
|
contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,9 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.widgets.tools.CropCircleTransformation;
|
import net.osmand.plus.widgets.tools.CropCircleTransformation;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
|
||||||
|
import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -29,7 +31,9 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
private static final int ITEM_TYPE = 1;
|
private static final int ITEM_TYPE = 1;
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
|
||||||
private LayerDrawable placeholder;
|
private LayerDrawable placeholder;
|
||||||
|
private LayerDrawable historyPlaceholder;
|
||||||
|
|
||||||
private List<Object> items = new ArrayList<>();
|
private List<Object> items = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -41,11 +45,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
|
|
||||||
SearchRecyclerViewAdapter(OsmandApplication app) {
|
SearchRecyclerViewAdapter(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
placeholder = (LayerDrawable) ContextCompat.getDrawable(app, R.drawable.wikivoyage_search_placeholder);
|
placeholder = getPlaceholder(false);
|
||||||
if (Build.VERSION.SDK_INT < 21 && placeholder != null) {
|
historyPlaceholder = getPlaceholder(true);
|
||||||
placeholder.setDrawableByLayerId(R.id.placeholder_icon,
|
|
||||||
app.getIconsCache().getIcon(R.drawable.ic_action_placeholder_city, R.color.icon_color));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -69,15 +70,24 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
ItemVH holder = (ItemVH) viewHolder;
|
ItemVH holder = (ItemVH) viewHolder;
|
||||||
boolean lastItem = pos == getItemCount() - 1;
|
boolean lastItem = pos == getItemCount() - 1;
|
||||||
|
|
||||||
WikivoyageSearchResult item = (WikivoyageSearchResult) getItem(pos);
|
Object item = getItem(pos);
|
||||||
Picasso.get()
|
if (item instanceof WikivoyageSearchResult) {
|
||||||
.load(WikivoyageArticle.getThumbImageUrl(item.getImageTitle()))
|
WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
|
||||||
.transform(new CropCircleTransformation())
|
Picasso.get()
|
||||||
.placeholder(placeholder)
|
.load(WikivoyageArticle.getThumbImageUrl(searchRes.getImageTitle()))
|
||||||
.into(holder.icon);
|
.transform(new CropCircleTransformation())
|
||||||
holder.title.setText(item.getArticleTitles().get(0));
|
.placeholder(placeholder)
|
||||||
holder.leftDescr.setText(item.getIsPartOf());
|
.into(holder.icon);
|
||||||
holder.rightDescr.setText(item.getFirstLangsString());
|
holder.title.setText(searchRes.getArticleTitles().get(0));
|
||||||
|
holder.leftDescr.setText(searchRes.getIsPartOf());
|
||||||
|
holder.rightDescr.setText(searchRes.getFirstLangsString());
|
||||||
|
} else {
|
||||||
|
WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item;
|
||||||
|
holder.icon.setImageDrawable(historyPlaceholder);
|
||||||
|
holder.title.setText(historyItem.getArticleTitle());
|
||||||
|
holder.leftDescr.setText(historyItem.getIsPartOf());
|
||||||
|
holder.rightDescr.setText(Algorithms.capitalizeFirstLetter(historyItem.getLang()));
|
||||||
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -101,6 +111,15 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
return items.get(pos);
|
return items.get(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHistoryItems(@Nullable List<WikivoyageSearchHistoryItem> historyItems) {
|
||||||
|
this.items.clear();
|
||||||
|
if (historyItems != null && !historyItems.isEmpty()) {
|
||||||
|
this.items.add(app.getString(R.string.shared_string_history));
|
||||||
|
this.items.addAll(historyItems);
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public void setItems(@Nullable List<WikivoyageSearchResult> items) {
|
public void setItems(@Nullable List<WikivoyageSearchResult> items) {
|
||||||
this.items.clear();
|
this.items.clear();
|
||||||
if (items != null && !items.isEmpty()) {
|
if (items != null && !items.isEmpty()) {
|
||||||
|
@ -110,6 +129,21 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LayerDrawable getPlaceholder(boolean history) {
|
||||||
|
LayerDrawable res = (LayerDrawable) ContextCompat.getDrawable(
|
||||||
|
app, history
|
||||||
|
? R.drawable.wikivoyage_search_history_placeholder
|
||||||
|
: R.drawable.wikivoyage_search_placeholder
|
||||||
|
);
|
||||||
|
if (Build.VERSION.SDK_INT < 21 && res != null) {
|
||||||
|
res.setDrawableByLayerId(R.id.placeholder_icon, app.getIconsCache().getIcon(
|
||||||
|
history ? R.drawable.ic_action_history : R.drawable.ic_action_placeholder_city,
|
||||||
|
R.color.icon_color
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
static class HeaderVH extends RecyclerView.ViewHolder {
|
static class HeaderVH extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
final TextView title;
|
final TextView title;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -20,6 +21,7 @@ import net.osmand.ResultMatcher;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
|
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
||||||
|
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -71,7 +73,7 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
||||||
searchQuery = newQuery;
|
searchQuery = newQuery;
|
||||||
if (searchQuery.isEmpty()) {
|
if (searchQuery.isEmpty()) {
|
||||||
cancelSearch();
|
cancelSearch();
|
||||||
adapter.setItems(null);
|
setAdapterItems(null);
|
||||||
} else {
|
} else {
|
||||||
runSearch();
|
runSearch();
|
||||||
}
|
}
|
||||||
|
@ -117,6 +119,9 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
||||||
super.onResume();
|
super.onResume();
|
||||||
paused = false;
|
paused = false;
|
||||||
searchEt.requestFocus();
|
searchEt.requestFocus();
|
||||||
|
if (TextUtils.isEmpty(searchQuery)) {
|
||||||
|
setAdapterItems(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -132,6 +137,15 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setAdapterItems(@Nullable List<WikivoyageSearchResult> items) {
|
||||||
|
if (items == null || items.isEmpty()) {
|
||||||
|
adapter.setHistoryItems(WikivoyageLocalDataHelper
|
||||||
|
.getInstance(getMyApplication()).getAllHistory());
|
||||||
|
} else {
|
||||||
|
adapter.setItems(items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void runSearch() {
|
private void runSearch() {
|
||||||
switchProgressBarVisibility(true);
|
switchProgressBarVisibility(true);
|
||||||
cancelled = false;
|
cancelled = false;
|
||||||
|
@ -141,7 +155,7 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
||||||
getMyApplication().runInUIThread(new Runnable() {
|
getMyApplication().runInUIThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!isCancelled()) {
|
if (!isCancelled()) {
|
||||||
adapter.setItems(results);
|
setAdapterItems(results);
|
||||||
switchProgressBarVisibility(false);
|
switchProgressBarVisibility(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue