Updated search history view

This commit is contained in:
Denis 2015-02-23 16:51:24 +02:00
parent ca6ebeac3b
commit 1fdc3cb31c
8 changed files with 81 additions and 40 deletions

View file

@ -15,8 +15,7 @@
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="@dimen/local_index_check_right_margin"
android:layout_marginTop="@dimen/favorites_icon_top_margin"
/>
android:layout_marginTop="@dimen/favorites_icon_top_margin"/>
<ImageView
android:id="@+id/icon"

View file

@ -10,28 +10,66 @@
android:paddingRight="@dimen/list_content_padding"
android:paddingTop="5dp">
<TextView
android:id="@+id/label"
style="@style/ListText"
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
android:layout_marginTop="@dimen/favorites_icon_top_margin"
android:focusable="false"
android:src="@drawable/ic_sdcard"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary"
tools:text="@string/lorem_ipsum"/>
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/dashFavNameTextSize"
tools:text="@string/lorem_ipsum"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/direction"
android:layout_width="@dimen/dashFavDirectionSize"
android:layout_height="@dimen/dashFavDirectionSize"
android:layout_gravity="center_vertical"
android:visibility="gone"/>
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/showAllButtonTextSize"
tools:text="100500 km"/>
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/options"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"
android:layout_gravity="center_vertical"
android:background="?attr/reset_image"
android:contentDescription="@string/default_buttons_delete"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="2dp"/>
android:background="?attr/options_button_background"
android:focusable="false"
android:src="?attr/list_settings_icon"/>
</LinearLayout>

View file

@ -21,7 +21,6 @@ import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.content.Intent;
@ -156,7 +155,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
}
public FavouritesAdapter(Activity activity, List<FavouritePoint> list) {
super(activity, R.layout.favourites_list_item, list);
super(activity, R.layout.favorites_list_item, list);
this.activity = activity;
this.app = ((OsmandApplication) activity.getApplication());
boolean light = app.getSettings().isLightContent();
@ -178,7 +177,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
View row = convertView;
if (row == null) {
LayoutInflater inflater = activity.getLayoutInflater();
row = inflater.inflate(R.layout.favourites_list_item, parent, false);
row = inflater.inflate(R.layout.favorites_list_item, parent, false);
}
TextView name = (TextView) row.findViewById(R.id.favourite_label);

View file

@ -204,7 +204,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
private boolean editPoint(final FavouritePoint point) {
Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.favourites_context_menu_edit);
final View v = getActivity().getLayoutInflater().inflate(R.layout.favourite_edit_dialog,
final View v = getActivity().getLayoutInflater().inflate(R.layout.favorite_edit_dialog,
getExpandableListView(), false);
final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
final EditText editText = (EditText) v.findViewById(R.id.Name);
@ -762,7 +762,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
View row = convertView;
if (row == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
row = inflater.inflate(R.layout.favourites_list_item, parent, false);
row = inflater.inflate(R.layout.favorites_list_item, parent, false);
}
TextView name = (TextView) row.findViewById(R.id.favourite_label);

View file

@ -10,11 +10,16 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.util.MapUtils;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
@ -24,6 +29,7 @@ import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@ -95,7 +101,9 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
location = ((OsmandApplication) activity.getApplication()).getSettings().getLastKnownMapLocation();
}
historyAdapter.clear();
historyAdapter.addAll(helper.getHistoryEntries());
for(HistoryEntry entry : helper.getHistoryEntries()){
historyAdapter.add(entry);
}
locationUpdate(location);
clearButton.setVisibility(historyAdapter.isEmpty() ? View.GONE : View.VISIBLE);
@ -144,33 +152,26 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
LayoutInflater inflater = getActivity().getLayoutInflater();
row = inflater.inflate(R.layout.search_history_list_item, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.label);
TextView nameText = (TextView) row.findViewById(R.id.name);
TextView distanceText = (TextView) row.findViewById(R.id.distance);
String distance = "";
ImageButton icon = (ImageButton) row.findViewById(R.id.remove);
ImageButton options = (ImageButton) row.findViewById(R.id.options);
final HistoryEntry model = getItem(position);
if (location != null) {
int dist = (int) (MapUtils.getDistance(location, model.getLat(), model.getLon()));
distance = OsmAndFormatter.getFormattedDistance(dist, (OsmandApplication) getActivity().getApplication()) + " ";
}
String rnk = MessageFormat.format(" {0,number,#.##E00} ", ((float)model.getRank(System.currentTimeMillis())));
label.setText(distance + rnk + model.getName().getName(), BufferType.SPANNABLE);
((Spannable) label.getText()).setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_distance)), 0, distance.length(), 0);
icon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.remove(model);
historyAdapter.remove(model);
}
distanceText.setText(distance);
nameText.setText(model.getName().getName(), BufferType.SPANNABLE);
});
View.OnClickListener clickListener = new View.OnClickListener() {
options.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectModel(model, v);
}
};
label.setOnClickListener(clickListener);
});
return row;
}
}
@ -181,4 +182,8 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
((SearchActivity) getActivity()).getClearToolbar(false);
}
}
public OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
}

View file

@ -175,7 +175,7 @@ public class FavoriteDialogs {
public static Dialog createAddFavouriteDialog(final Activity activity, final Bundle args) {
Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.favourites_context_menu_edit);
final View v = activity.getLayoutInflater().inflate(R.layout.favourite_edit_dialog, null, false);
final View v = activity.getLayoutInflater().inflate(R.layout.favorite_edit_dialog, null, false);
final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
builder.setView(v);
final EditText editText = (EditText) v.findViewById(R.id.Name);