This commit is contained in:
Alexey Kulish 2017-04-11 09:52:40 +03:00
parent 926ce6cfcc
commit 6e3d4eedad
5 changed files with 157 additions and 32 deletions

View file

@ -4,23 +4,96 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:orientation="horizontal"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp">
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
<LinearLayout
android:id="@+id/empty_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_sub_text_size"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"
tools:text="Amsterdam"/>
android:layout_height="wrap_content"
android:paddingTop="24dp"
android:paddingBottom="24dp"
android:orientation="horizontal"
android:visibility="visible">
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_empty_state_search"
android:tint="#ec572e"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
android:text="@string/nothing_found"/>
<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
android:text="@string/nothing_found_descr"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"/>
</LinearLayout>
<View
android:id="@+id/more_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"
android:visibility="gone"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:orientation="horizontal"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_sub_text_size"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/increase_search_radius"/>
</LinearLayout>
</LinearLayout>

View file

@ -9,6 +9,10 @@
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="restart_search">Restart search</string>
<string name="increase_search_radius">Increase search radius</string>
<string name="nothing_found">Nothing found :(</string>
<string name="nothing_found_descr">Try to change search query or increase radius of search</string>
<string name="quick_action_showhide_osmbugs_title">Show/hide OSM Notes</string>
<string name="quick_action_osmbugs_show">Show OSM Notes</string>
<string name="quick_action_osmbugs_hide">Hide OSM Notes</string>

View file

@ -749,8 +749,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
paused = false;
hidden = false;
if (interruptedSearch) {
interruptedSearch = false;
addMoreButton();
interruptedSearch = false;
}
}
@ -1004,6 +1004,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
return searchHelper.getResultCollection();
}
public boolean isResultEmpty() {
SearchResultCollection res = getResultCollection();
return res == null || res.getCurrentSearchResults().size() == 0;
}
public void onSearchListFragmentResume(QuickSearchListFragment searchListFragment) {
switch (searchListFragment.getType()) {
case HISTORY:
@ -1675,19 +1680,20 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
private void addMoreButton() {
QuickSearchMoreListItem moreListItem =
new QuickSearchMoreListItem(app, app.getString(R.string.search_POI_level_btn).toUpperCase(), new OnClickListener() {
@Override
public void onClick(View v) {
if (!interruptedSearch) {
SearchSettings settings = searchUICore.getSearchSettings();
searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
}
runCoreSearch(searchQuery, false, true);
}
});
if (!paused && !cancelPrev && mainSearchFragment != null) {
QuickSearchMoreListItem moreListItem =
new QuickSearchMoreListItem(app, null, new OnClickListener() {
@Override
public void onClick(View v) {
if (!interruptedSearch) {
SearchSettings settings = searchUICore.getSearchSettings();
searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
}
runCoreSearch(searchQuery, false, true);
}
});
moreListItem.setInterruptedSearch(interruptedSearch);
moreListItem.setEmptySearch(isResultEmpty());
mainSearchFragment.addListItem(moreListItem);
}
}

View file

@ -22,7 +22,6 @@ import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.search.listitems.QuickSearchButtonListItem;
import net.osmand.plus.search.listitems.QuickSearchHeaderListItem;
import net.osmand.plus.search.listitems.QuickSearchListItem;
import net.osmand.plus.search.listitems.QuickSearchListItemType;
@ -225,6 +224,14 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
} else {
((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
}
QuickSearchMoreListItem searchMoreListItem = (QuickSearchMoreListItem) listItem;
if (searchMoreListItem.isEmptySearch() && !searchMoreListItem.isInterruptedSearch()) {
view.findViewById(R.id.empty_search).setVisibility(View.VISIBLE);
view.findViewById(R.id.more_divider).setVisibility(View.VISIBLE);
} else {
view.findViewById(R.id.empty_search).setVisibility(View.GONE);
view.findViewById(R.id.more_divider).setVisibility(View.GONE);
}
} else if (type == QuickSearchListItemType.BUTTON) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) app

View file

@ -3,16 +3,25 @@ package net.osmand.plus.search.listitems;
import android.view.View.OnClickListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public class QuickSearchMoreListItem extends QuickSearchListItem {
private String name;
private OnClickListener onClickListener;
private boolean emptySearch;
private boolean interruptedSearch;
private String findMore;
private String restartSearch;
private String increaseRadius;
public QuickSearchMoreListItem(OsmandApplication app, String name, OnClickListener onClickListener) {
super(app, null);
this.name = name;
this.onClickListener = onClickListener;
findMore = app.getString(R.string.search_POI_level_btn).toUpperCase();
restartSearch = app.getString(R.string.restart_search).toUpperCase();
increaseRadius = app.getString(R.string.increase_search_radius).toUpperCase();
}
public QuickSearchListItemType getType() {
@ -21,7 +30,33 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
@Override
public String getName() {
return name;
if (name != null) {
return name;
} else if (interruptedSearch) {
if (emptySearch) {
return restartSearch;
} else {
return findMore;
}
} else {
return increaseRadius;
}
}
public boolean isInterruptedSearch() {
return interruptedSearch;
}
public void setInterruptedSearch(boolean interruptedSearch) {
this.interruptedSearch = interruptedSearch;
}
public boolean isEmptySearch() {
return emptySearch;
}
public void setEmptySearch(boolean emptySearch) {
this.emptySearch = emptySearch;
}
public OnClickListener getOnClickListener() {