Create simple test UI for search
This commit is contained in:
parent
ae700b3eae
commit
b8f50b78d8
5 changed files with 316 additions and 0 deletions
103
OsmAnd/res/layout/fragment_wikivoyage_explore_dialog.xml
Normal file
103
OsmAnd/res/layout/fragment_wikivoyage_explore_dialog.xml
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dashboard_map_toolbar"
|
||||
osmand:contentInsetEnd="0dp"
|
||||
osmand:contentInsetLeft="4dp"
|
||||
osmand:contentInsetRight="0dp"
|
||||
osmand:contentInsetStart="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/back_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:contentDescription="@string/shared_string_back"
|
||||
tools:src="@drawable/ic_arrow_back"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/toolbar_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:text="@string/shared_string_travel"
|
||||
android:textSize="@dimen/dialog_header_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:textColor="@color/color_white"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/options_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:text="@string/shared_string_options"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/dashboard_blue"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="?attr/bg_color"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/search_edit_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="@string/search_poi_category_hint"
|
||||
android:imeOptions="actionSearch"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:textColor="?attr/searchbar_text"
|
||||
android:textColorHint="?attr/searchbar_text_hint"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/search_button"
|
||||
style="@style/Widget.AppCompat.ActionButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:contentDescription="@string/shared_string_search"
|
||||
tools:src="@drawable/ic_action_search_dark"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
72
OsmAnd/res/layout/wikivoyage_search_list_item.xml
Normal file
72
OsmAnd/res/layout/wikivoyage_search_list_item.xml
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="search_term: "/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/search_term"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="city_id: "/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/city_id"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="article_title: "/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/article_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="lang: "/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lang"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="25dp"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -9,6 +9,7 @@
|
|||
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
|
||||
-->
|
||||
<string name="shared_string_travel">Travel</string>
|
||||
<string name="nothing_found_in_radius">Nothing found within the radius:</string>
|
||||
<string name="select_waypoints_category_description">You can add all of the track\'s waypoints, or select separate categories.</string>
|
||||
<string name="shared_string_total">Total</string>
|
||||
|
|
|
@ -62,6 +62,7 @@ import net.osmand.plus.views.BaseMapLayer;
|
|||
import net.osmand.plus.views.MapControlsLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageExploreDialogFragment;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -774,6 +775,17 @@ public class MapActivityActions implements DialogProvider {
|
|||
}
|
||||
}).createItem());
|
||||
|
||||
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.shared_string_travel, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_track_16)
|
||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
|
||||
MapActivity.clearPrevActivityIntent();
|
||||
WikivoyageExploreDialogFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||
return true;
|
||||
}
|
||||
}).createItem());
|
||||
|
||||
optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.layer_map_appearance, mapActivity)
|
||||
.setIcon(R.drawable.ic_configure_screen_dark)
|
||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
package net.osmand.plus.wikivoyage;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper.SearchResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WikivoyageExploreDialogFragment extends BaseOsmAndDialogFragment {
|
||||
|
||||
public static final String TAG = "WikivoyageExploreDialogFragment";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_explore_dialog, container);
|
||||
|
||||
final EditText searchEt = (EditText) mainView.findViewById(R.id.search_edit_text);
|
||||
|
||||
final SearchListAdapter adapter = new SearchListAdapter();
|
||||
RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
|
||||
rv.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
rv.setAdapter(adapter);
|
||||
|
||||
ImageButton backBtn = (ImageButton) mainView.findViewById(R.id.back_button);
|
||||
backBtn.setImageDrawable(getContentIcon(R.drawable.ic_arrow_back));
|
||||
backBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
ImageButton searchBtn = (ImageButton) mainView.findViewById(R.id.search_button);
|
||||
searchBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_search_dark));
|
||||
searchBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
adapter.setItems(getMyApplication().getWikivoyageDbHelper().search((searchEt).getText().toString()));
|
||||
}
|
||||
});
|
||||
|
||||
searchEt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
adapter.setItems(getMyApplication().getWikivoyageDbHelper().search((searchEt).getText().toString()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fm) {
|
||||
try {
|
||||
WikivoyageExploreDialogFragment fragment = new WikivoyageExploreDialogFragment();
|
||||
fragment.show(fm, TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SearchListAdapter extends RecyclerView.Adapter<SearchListAdapter.ViewHolder> {
|
||||
|
||||
private List<SearchResult> items = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View itemView = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.wikivoyage_search_list_item, viewGroup, false);
|
||||
return new ViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder viewHolder, int i) {
|
||||
SearchResult item = items.get(i);
|
||||
viewHolder.searchTerm.setText(item.getSearchTerm());
|
||||
viewHolder.cityId.setText(String.valueOf(item.getCityId()));
|
||||
viewHolder.articleTitle.setText(item.getArticleTitle());
|
||||
viewHolder.lang.setText(item.getLang());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
public void setItems(List<SearchResult> items) {
|
||||
this.items = items;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
final TextView searchTerm;
|
||||
final TextView cityId;
|
||||
final TextView articleTitle;
|
||||
final TextView lang;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
searchTerm = (TextView) itemView.findViewById(R.id.search_term);
|
||||
cityId = (TextView) itemView.findViewById(R.id.city_id);
|
||||
articleTitle = (TextView) itemView.findViewById(R.id.article_title);
|
||||
lang = (TextView) itemView.findViewById(R.id.lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue