Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b62f503710
14 changed files with 274 additions and 93 deletions
|
@ -69,6 +69,7 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/action_bar_image_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/action_bar_image_height"
|
||||
android:background="?attr/actionModeBackground">
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="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:background="?attr/ctx_menu_info_view_bg"
|
||||
|
@ -22,34 +21,7 @@
|
|||
app:contentInsetLeft="54dp"
|
||||
app:contentInsetStart="54dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/search_edit_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="@null"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="@string/shared_string_search"
|
||||
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>
|
||||
<include layout="@layout/search_text_layout"/>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.graphics.PorterDuff;
|
|||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.FileProvider;
|
||||
|
@ -162,7 +163,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
View emptyView = view.findViewById(android.R.id.empty);
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_favorites_day : R.drawable.ic_empty_state_favorites_night);
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_favorites_day : R.drawable.ic_empty_state_favorites_night);
|
||||
} else {
|
||||
emptyImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
Button importButton = (Button) emptyView.findViewById(R.id.import_button);
|
||||
importButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -99,12 +99,17 @@ public class NotesFragment extends OsmAndListFragment {
|
|||
ViewStub emptyStub = (ViewStub) view.findViewById(R.id.empty_view_stub);
|
||||
emptyStub.setLayoutResource(R.layout.empty_state_av_notes);
|
||||
emptyView = emptyStub.inflate();
|
||||
int icRes = getMyApplication().getSettings().isLightContent()
|
||||
? R.drawable.ic_empty_state_av_notes_day : R.drawable.ic_empty_state_av_notes_night;
|
||||
((ImageView) emptyView.findViewById(R.id.empty_state_image_view)).setImageResource(icRes);
|
||||
emptyView.setBackgroundColor(getResources().getColor(getMyApplication().getSettings()
|
||||
.isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark));
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
int icRes = getMyApplication().getSettings().isLightContent()
|
||||
? R.drawable.ic_empty_state_av_notes_day : R.drawable.ic_empty_state_av_notes_night;
|
||||
emptyImageView.setImageResource(icRes);
|
||||
} else {
|
||||
emptyImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.res.ColorStateList;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -222,37 +223,41 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment
|
|||
}
|
||||
|
||||
private void updateHelpImage() {
|
||||
OsmandSettings settings = getSettings();
|
||||
int count = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
|
||||
LinkedList<Drawable> imgList = new LinkedList<>();
|
||||
imgList.add(getDeviceImg());
|
||||
if (settings.SHOW_LINES_TO_FIRST_MARKERS.get()) {
|
||||
imgList.add(getGuideLineOneImg());
|
||||
if (count == 2) {
|
||||
imgList.add(getGuideLineTwoImg());
|
||||
}
|
||||
}
|
||||
if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) {
|
||||
imgList.add(getArrowOneImg());
|
||||
if (count == 2) {
|
||||
imgList.add(getArrowTwoImg());
|
||||
}
|
||||
}
|
||||
if (settings.MARKERS_DISTANCE_INDICATION_ENABLED.get()) {
|
||||
if (settings.MAP_MARKERS_MODE.get().isWidgets()) {
|
||||
imgList.add(getWidget1Img());
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
OsmandSettings settings = getSettings();
|
||||
int count = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get();
|
||||
LinkedList<Drawable> imgList = new LinkedList<>();
|
||||
imgList.add(getDeviceImg());
|
||||
if (settings.SHOW_LINES_TO_FIRST_MARKERS.get()) {
|
||||
imgList.add(getGuideLineOneImg());
|
||||
if (count == 2) {
|
||||
imgList.add(getWidget2Img());
|
||||
}
|
||||
} else {
|
||||
imgList.add(getTopBar1Img());
|
||||
if (count == 2) {
|
||||
imgList.add(getTopBar2Img());
|
||||
imgList.add(getGuideLineTwoImg());
|
||||
}
|
||||
}
|
||||
if (settings.SHOW_ARROWS_TO_FIRST_MARKERS.get()) {
|
||||
imgList.add(getArrowOneImg());
|
||||
if (count == 2) {
|
||||
imgList.add(getArrowTwoImg());
|
||||
}
|
||||
}
|
||||
if (settings.MARKERS_DISTANCE_INDICATION_ENABLED.get()) {
|
||||
if (settings.MAP_MARKERS_MODE.get().isWidgets()) {
|
||||
imgList.add(getWidget1Img());
|
||||
if (count == 2) {
|
||||
imgList.add(getWidget2Img());
|
||||
}
|
||||
} else {
|
||||
imgList.add(getTopBar1Img());
|
||||
if (count == 2) {
|
||||
imgList.add(getTopBar2Img());
|
||||
}
|
||||
}
|
||||
}
|
||||
((ImageView) mainView.findViewById(R.id.action_bar_image))
|
||||
.setImageDrawable(new LayerDrawable(imgList.toArray(new Drawable[imgList.size()])));
|
||||
} else {
|
||||
mainView.findViewById(R.id.action_bar_image_container).setVisibility(View.GONE);
|
||||
}
|
||||
((ImageView) mainView.findViewById(R.id.action_bar_image))
|
||||
.setImageDrawable(new LayerDrawable(imgList.toArray(new Drawable[imgList.size()])));
|
||||
}
|
||||
|
||||
private Drawable getTopBar2Img() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
@ -126,7 +127,11 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
|
|||
|
||||
final View emptyView = mainView.findViewById(R.id.empty_view);
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
emptyImageView.setImageResource(mapActivity.getMyApplication().getSettings().isLightContent() ? R.drawable.ic_empty_state_marker_list_day : R.drawable.ic_empty_state_marker_list_night);
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
emptyImageView.setImageResource(mapActivity.getMyApplication().getSettings().isLightContent() ? R.drawable.ic_empty_state_marker_list_day : R.drawable.ic_empty_state_marker_list_night);
|
||||
} else {
|
||||
emptyImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
recyclerView.setEmptyView(emptyView);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.graphics.Paint;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
|
@ -304,7 +305,11 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
|||
}
|
||||
});
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_group_night : R.drawable.ic_empty_state_marker_group_day);
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_group_night : R.drawable.ic_empty_state_marker_group_day);
|
||||
} else {
|
||||
emptyImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
recyclerView.setEmptyView(emptyView);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.graphics.Paint;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
|
@ -203,7 +204,11 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
|||
});
|
||||
final View emptyView = mainView.findViewById(R.id.empty_view);
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_history_night : R.drawable.ic_empty_state_marker_history_day);
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_history_night : R.drawable.ic_empty_state_marker_history_day);
|
||||
} else {
|
||||
emptyImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
recyclerView.setEmptyView(emptyView);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
|||
|
||||
items.add(new DescriptionItem(getString(R.string.measurement_tool_save_as_new_track_descr)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
View imagesRow = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||
R.layout.fragment_save_as_new_track_images_row, null);
|
||||
|
|
|
@ -333,7 +333,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
listView.addFooterView(footerView);
|
||||
emptyView = v.findViewById(android.R.id.empty);
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_trip_day : R.drawable.ic_empty_state_trip_night);
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_trip_day : R.drawable.ic_empty_state_trip_night);
|
||||
} else {
|
||||
emptyImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
Button importButton = (Button) emptyView.findViewById(R.id.import_button);
|
||||
importButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -140,12 +141,16 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
|
|||
ViewStub emptyStub = (ViewStub) view.findViewById(R.id.empty_view_stub);
|
||||
emptyStub.setLayoutResource(R.layout.empty_state_osm_edits);
|
||||
emptyView = emptyStub.inflate();
|
||||
int icRes = getMyApplication().getSettings().isLightContent()
|
||||
? R.drawable.ic_empty_state_osm_edits_day : R.drawable.ic_empty_state_osm_edits_night;
|
||||
((ImageView) emptyView.findViewById(R.id.empty_state_image_view)).setImageResource(icRes);
|
||||
emptyView.setBackgroundColor(getResources().getColor(getMyApplication().getSettings()
|
||||
.isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark));
|
||||
|
||||
ImageView emptyImageView = emptyView.findViewById(R.id.empty_state_image_view);
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
int icRes = getMyApplication().getSettings().isLightContent()
|
||||
? R.drawable.ic_empty_state_osm_edits_day : R.drawable.ic_empty_state_osm_edits_night;
|
||||
emptyImageView.setImageResource(icRes);
|
||||
} else {
|
||||
emptyImageView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
FragmentManager fm = getChildFragmentManager();
|
||||
Fragment optionsFragment = fm.findFragmentByTag(OsmEditOptionsBottomSheetDialogFragment.TAG);
|
||||
if (optionsFragment != null) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.wikivoyage.search;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -48,8 +49,12 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
|
|||
return items.get(pos);
|
||||
}
|
||||
|
||||
public void setItems(List<SearchResult> items) {
|
||||
this.items = items;
|
||||
public void setItems(@Nullable List<SearchResult> items) {
|
||||
if (items == null) {
|
||||
this.items.clear();
|
||||
} else {
|
||||
this.items = items;
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
package net.osmand.plus.wikivoyage.search;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.wikivoyage.data.SearchResult;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class WikivoyageSearchCore {
|
||||
|
||||
private static final int TIMEOUT_BETWEEN_CHARS = 700;
|
||||
private static final int SLEEP_TIME = 50;
|
||||
|
||||
private LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();
|
||||
private ThreadPoolExecutor singleThreadExecutor =
|
||||
new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, workQueue);
|
||||
private AsyncTask<Void, Void, List<SearchResult>> currentTask;
|
||||
|
||||
private OsmandApplication application;
|
||||
private Set<SearchListener> listeners = new HashSet<>();
|
||||
|
||||
WikivoyageSearchCore(OsmandApplication application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public void registerListener(SearchListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void unregisterListener(SearchListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
public void cancelSearch() {
|
||||
workQueue.clear();
|
||||
if (currentTask != null) {
|
||||
currentTask.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void search(String query) {
|
||||
cancelSearch();
|
||||
currentTask = new SearchAsyncTask(query);
|
||||
currentTask.executeOnExecutor(singleThreadExecutor);
|
||||
}
|
||||
|
||||
public interface SearchListener {
|
||||
|
||||
void onSearchStarted();
|
||||
|
||||
void onSearchFinished(@Nullable List<SearchResult> results, boolean lastTask, boolean cancelled);
|
||||
}
|
||||
|
||||
private class SearchAsyncTask extends AsyncTask<Void, Void, List<SearchResult>> {
|
||||
|
||||
private String query;
|
||||
|
||||
SearchAsyncTask(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
for (SearchListener listener : listeners) {
|
||||
listener.onSearchStarted();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SearchResult> doInBackground(Void... voids) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - startTime <= TIMEOUT_BETWEEN_CHARS) {
|
||||
if (isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return application.getWikivoyageDbHelper().search(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<SearchResult> results) {
|
||||
super.onPostExecute(results);
|
||||
boolean cancelled = isCancelled();
|
||||
for (SearchListener listener : listeners) {
|
||||
listener.onSearchFinished(results, workQueue.isEmpty(), cancelled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,35 +6,47 @@ import android.support.v4.app.FragmentManager;
|
|||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.KeyEvent;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.ContextThemeWrapper;
|
||||
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 android.widget.ProgressBar;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.WikivoyageDbHelper;
|
||||
import net.osmand.plus.wikivoyage.data.SearchResult;
|
||||
|
||||
public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment {
|
||||
import java.util.List;
|
||||
|
||||
public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment implements WikivoyageSearchCore.SearchListener {
|
||||
|
||||
public static final String TAG = "WikivoyageSearchDialogFragment";
|
||||
|
||||
private WikivoyageDbHelper dbHelper;
|
||||
private WikivoyageSearchCore searchCore;
|
||||
private String searchQuery = "";
|
||||
|
||||
private SearchRecyclerViewAdapter adapter;
|
||||
|
||||
private EditText searchEt;
|
||||
private ImageButton clearIb;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
dbHelper = getMyApplication().getWikivoyageDbHelper();
|
||||
final OsmandApplication app = getMyApplication();
|
||||
searchCore = new WikivoyageSearchCore(app);
|
||||
final boolean nightMode = !app.getSettings().isLightContent();
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_search_dialog, container);
|
||||
final View mainView = LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
|
||||
.inflate(R.layout.fragment_wikivoyage_search_dialog, container, false);
|
||||
|
||||
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
|
||||
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
|
||||
|
@ -46,24 +58,40 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment {
|
|||
}
|
||||
});
|
||||
|
||||
searchEt = (EditText) toolbar.findViewById(R.id.search_edit_text);
|
||||
searchEt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
searchEt = (EditText) toolbar.findViewById(R.id.searchEditText);
|
||||
searchEt.setHint(R.string.shared_string_search);
|
||||
searchEt.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
runSearch();
|
||||
return true;
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
String newQuery = s.toString();
|
||||
if (newQuery.isEmpty()) {
|
||||
searchCore.cancelSearch();
|
||||
adapter.setItems(null);
|
||||
} else if (!searchQuery.equalsIgnoreCase(newQuery)) {
|
||||
searchQuery = newQuery;
|
||||
searchCore.search(searchQuery);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
ImageButton searchBtn = (ImageButton) mainView.findViewById(R.id.search_button);
|
||||
searchBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_search_dark));
|
||||
searchBtn.setOnClickListener(new View.OnClickListener() {
|
||||
progressBar = (ProgressBar) toolbar.findViewById(R.id.searchProgressBar);
|
||||
|
||||
clearIb = (ImageButton) toolbar.findViewById(R.id.clearButton);
|
||||
clearIb.setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark));
|
||||
clearIb.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
runSearch();
|
||||
public void onClick(View v) {
|
||||
searchEt.setText("");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -84,8 +112,41 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment {
|
|||
return mainView;
|
||||
}
|
||||
|
||||
private void runSearch() {
|
||||
adapter.setItems(dbHelper.search((searchEt).getText().toString()));
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (searchCore != null) {
|
||||
searchCore.registerListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (searchCore != null) {
|
||||
searchCore.unregisterListener(this);
|
||||
searchCore.cancelSearch();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchStarted() {
|
||||
switchProgressBarVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchFinished(@Nullable List<SearchResult> results, boolean lastTask, boolean cancelled) {
|
||||
if (!cancelled) {
|
||||
adapter.setItems(results);
|
||||
}
|
||||
if (lastTask) {
|
||||
switchProgressBarVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void switchProgressBarVisibility(boolean show) {
|
||||
progressBar.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
clearIb.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fm) {
|
||||
|
|
Loading…
Reference in a new issue