aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-10-20 14:32:06 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-10-20 14:32:06 +0200
commiteb1e528c635888baab7f42b456dd12e57170c4e5 (patch)
tree8d1f8fa94ce70a6b9959d84a62b550606885fa27
parentddaa662b5f2d7bf6cbe8dae5b8854097ce4f1cce (diff)
downloadcgeo-eb1e528c635888baab7f42b456dd12e57170c4e5.zip
cgeo-eb1e528c635888baab7f42b456dd12e57170c4e5.tar.gz
cgeo-eb1e528c635888baab7f42b456dd12e57170c4e5.tar.bz2
refactoring: convert waypoints to real list
-rw-r--r--main/res/layout/cachedetail_waypoints_footer.xml9
-rw-r--r--main/res/layout/cachedetail_waypoints_page.xml36
-rw-r--r--main/res/layout/waypoint_item.xml11
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java234
-rw-r--r--main/src/cgeo/geocaching/WaypointViewHolder.java22
5 files changed, 171 insertions, 141 deletions
diff --git a/main/res/layout/cachedetail_waypoints_footer.xml b/main/res/layout/cachedetail_waypoints_footer.xml
new file mode 100644
index 0000000..58187c1
--- /dev/null
+++ b/main/res/layout/cachedetail_waypoints_footer.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Button xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/add_waypoint"
+ style="@style/button_full"
+ android:layout_margin="10dip"
+ android:padding="10dip"
+ android:clickable="true"
+ android:text="@string/cache_waypoints_add" />
+
diff --git a/main/res/layout/cachedetail_waypoints_page.xml b/main/res/layout/cachedetail_waypoints_page.xml
index 8a24aa8..a3e43df 100644
--- a/main/res/layout/cachedetail_waypoints_page.xml
+++ b/main/res/layout/cachedetail_waypoints_page.xml
@@ -1,26 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
-
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:padding="4dip" >
-
- <LinearLayout
- android:id="@+id/waypoints"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
-
- <Button
- android:id="@+id/add_waypoint"
- style="@style/button_full"
- android:layout_marginTop="9dp"
- android:text="@string/cache_waypoints_add" />
- </LinearLayout>
-
-</ScrollView> \ No newline at end of file
+ android:layout_height="fill_parent"
+ android:cacheColorHint="?background_color"
+ android:divider="?background_color"
+ android:fastScrollEnabled="true"
+ android:focusable="false"
+ android:footerDividersEnabled="false"
+ android:headerDividersEnabled="false"
+ android:clickable="true"
+ android:listSelector="?background_color" >
+
+</ListView> \ No newline at end of file
diff --git a/main/res/layout/waypoint_item.xml b/main/res/layout/waypoint_item.xml
index 17690ff..4fe3576 100644
--- a/main/res/layout/waypoint_item.xml
+++ b/main/res/layout/waypoint_item.xml
@@ -1,25 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/waypoint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:clickable="true"
+ android:descendantFocusability="blocksDescendants"
+ android:longClickable="true"
android:orientation="vertical"
android:paddingTop="9dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
+ android:descendantFocusability="blocksDescendants"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
+ android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
+ android:focusable="false"
android:textColor="?text_color"
android:textSize="18sp" />
@@ -30,6 +37,7 @@
android:layout_gravity="left"
android:layout_marginLeft="12dp"
android:ellipsize="marquee"
+ android:focusable="false"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
@@ -44,6 +52,7 @@
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:clickable="true"
+ android:focusable="false"
android:longClickable="true"
android:src="?actionbar_compass" />
</RelativeLayout>
@@ -55,6 +64,7 @@
android:layout_gravity="left"
android:layout_marginLeft="12dp"
android:ellipsize="marquee"
+ android:focusable="false"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
@@ -67,6 +77,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
+ android:focusable="false"
android:textColor="?text_color"
android:textSize="14sp"
android:visibility="gone" />
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 8597abd..4eddba4 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -378,37 +378,21 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
clickedItemText = ((TextView) view).getText();
buildDetailsContextMenu(menu, res.getString(R.string.cache_logs), false);
break;
- case -1:
- if (null != cache.getWaypoints()) {
- try {
- final ViewGroup parent = ((ViewGroup) view.getParent());
- for (int i = 0; i < parent.getChildCount(); i++) {
- if (parent.getChildAt(i) == view) {
- final List<Waypoint> sortedWaypoints = new ArrayList<Waypoint>(cache.getWaypoints());
- Collections.sort(sortedWaypoints);
- selectedWaypoint = sortedWaypoints.get(i);
-
- menu.setHeaderTitle(res.getString(R.string.waypoint));
- getMenuInflater().inflate(R.menu.waypoint_options, menu);
- final boolean isOriginalWaypoint = selectedWaypoint.getWaypointType().equals(WaypointType.ORIGINAL);
- menu.findItem(R.id.menu_waypoint_reset_cache_coords).setVisible(isOriginalWaypoint);
- menu.findItem(R.id.menu_waypoint_edit).setVisible(!isOriginalWaypoint);
- menu.findItem(R.id.menu_waypoint_duplicate).setVisible(!isOriginalWaypoint);
- final boolean userDefined = selectedWaypoint.isUserDefined() && !selectedWaypoint.getWaypointType().equals(WaypointType.ORIGINAL);
- menu.findItem(R.id.menu_waypoint_delete).setVisible(userDefined);
- final boolean hasCoords = selectedWaypoint.getCoords() != null;
- final MenuItem defaultNavigationMenu = menu.findItem(R.id.menu_waypoint_navigate_default);
- defaultNavigationMenu.setVisible(hasCoords);
- defaultNavigationMenu.setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName());
- menu.findItem(R.id.menu_waypoint_navigate).setVisible(hasCoords);
- menu.findItem(R.id.menu_waypoint_caches_around).setVisible(hasCoords);
-
- break;
- }
- }
- } catch (final RuntimeException e) {
- }
- }
+ case R.id.waypoint:
+ menu.setHeaderTitle(res.getString(R.string.waypoint));
+ getMenuInflater().inflate(R.menu.waypoint_options, menu);
+ final boolean isOriginalWaypoint = selectedWaypoint.getWaypointType().equals(WaypointType.ORIGINAL);
+ menu.findItem(R.id.menu_waypoint_reset_cache_coords).setVisible(isOriginalWaypoint);
+ menu.findItem(R.id.menu_waypoint_edit).setVisible(!isOriginalWaypoint);
+ menu.findItem(R.id.menu_waypoint_duplicate).setVisible(!isOriginalWaypoint);
+ final boolean userDefined = selectedWaypoint.isUserDefined() && !selectedWaypoint.getWaypointType().equals(WaypointType.ORIGINAL);
+ menu.findItem(R.id.menu_waypoint_delete).setVisible(userDefined);
+ final boolean hasCoords = selectedWaypoint.getCoords() != null;
+ final MenuItem defaultNavigationMenu = menu.findItem(R.id.menu_waypoint_navigate_default);
+ defaultNavigationMenu.setVisible(hasCoords);
+ defaultNavigationMenu.setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName());
+ menu.findItem(R.id.menu_waypoint_navigate).setVisible(hasCoords);
+ menu.findItem(R.id.menu_waypoint_caches_around).setVisible(hasCoords);
break;
default:
if (imagesList != null) {
@@ -1795,122 +1779,138 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
}
- private class WaypointsViewCreator extends AbstractCachingPageViewCreator<ScrollView> {
+ private class WaypointsViewCreator extends AbstractCachingPageViewCreator<ListView> {
@Override
- public ScrollView getDispatchedView() {
+ public ListView getDispatchedView() {
if (cache == null) {
// something is really wrong
return null;
}
- view = (ScrollView) getLayoutInflater().inflate(R.layout.cachedetail_waypoints_page, null);
-
- final LinearLayout waypoints = (LinearLayout) view.findViewById(R.id.waypoints);
-
// sort waypoints: PP, Sx, FI, OWN
final List<Waypoint> sortedWaypoints = new ArrayList<Waypoint>(cache.getWaypoints());
Collections.sort(sortedWaypoints);
- for (final Waypoint wpt : sortedWaypoints) {
- final LinearLayout waypointView = (LinearLayout) getLayoutInflater().inflate(R.layout.waypoint_item, null);
+ view = (ListView) getLayoutInflater().inflate(R.layout.cachedetail_waypoints_page, null);
+ view.setClickable(true);
+ View addWaypointButton = getLayoutInflater().inflate(R.layout.cachedetail_waypoints_footer, null);
+ view.addFooterView(addWaypointButton);
+ addWaypointButton.setOnClickListener(new View.OnClickListener() {
- // coordinates
- if (null != wpt.getCoords()) {
- final TextView coordinatesView = (TextView) waypointView.findViewById(R.id.coordinates);
- coordinatesView.setOnClickListener(new CoordinatesFormatSwitcher(wpt.getCoords()));
- coordinatesView.setText(wpt.getCoords().toString());
- coordinatesView.setVisibility(View.VISIBLE);
+ @Override
+ public void onClick(View v) {
+ EditWaypointActivity.startActivityAddWaypoint(CacheDetailActivity.this, cache);
+ refreshOnResume = true;
}
+ });
- // info
- final String waypointInfo = Formatter.formatWaypointInfo(wpt);
- if (StringUtils.isNotBlank(waypointInfo)) {
- final TextView infoView = (TextView) waypointView.findViewById(R.id.info);
- infoView.setText(waypointInfo);
- infoView.setVisibility(View.VISIBLE);
- }
+ view.setAdapter(new ArrayAdapter<Waypoint>(CacheDetailActivity.this, R.layout.waypoint_item, sortedWaypoints) {
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View rowView = convertView;
+ if (null == rowView) {
+ rowView = getLayoutInflater().inflate(R.layout.waypoint_item, null);
+ rowView.setClickable(true);
+ rowView.setLongClickable(true);
+ }
+ WaypointViewHolder holder = (WaypointViewHolder) rowView.getTag();
+ if (null == holder) {
+ holder = new WaypointViewHolder(rowView);
+ }
- // title
- final TextView nameView = (TextView) waypointView.findViewById(R.id.name);
- if (StringUtils.isNotBlank(wpt.getName())) {
- nameView.setText(StringEscapeUtils.unescapeHtml4(wpt.getName()));
- } else if (null != wpt.getCoords()) {
- nameView.setText(wpt.getCoords().toString());
- } else {
- nameView.setText(res.getString(R.string.waypoint));
+ final Waypoint waypoint = getItem(position);
+ fillViewHolder(rowView, holder, waypoint);
+ return rowView;
}
- wpt.setIcon(res, nameView);
+ });
- // visited
- if (wpt.isVisited()) {
- final TypedValue a = new TypedValue();
- getTheme().resolveAttribute(R.attr.text_color_grey, a, true);
- if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
- // really should be just a color!
- nameView.setTextColor(a.data);
- }
- }
+ return view;
+ }
- // note
- if (StringUtils.isNotBlank(wpt.getNote())) {
- final TextView noteView = (TextView) waypointView.findViewById(R.id.note);
- noteView.setVisibility(View.VISIBLE);
- if (TextUtils.containsHtml(wpt.getNote())) {
- noteView.setText(Html.fromHtml(wpt.getNote()), TextView.BufferType.SPANNABLE);
- }
- else {
- noteView.setText(wpt.getNote());
- }
- }
+ protected void fillViewHolder(View rowView, final WaypointViewHolder holder, final Waypoint wpt) {
+ // coordinates
+ if (null != wpt.getCoords()) {
+ final TextView coordinatesView = holder.coordinatesView;
+ coordinatesView.setOnClickListener(new CoordinatesFormatSwitcher(wpt.getCoords()));
+ coordinatesView.setText(wpt.getCoords().toString());
+ coordinatesView.setVisibility(View.VISIBLE);
+ }
- final View wpNavView = waypointView.findViewById(R.id.wpDefaultNavigation);
- wpNavView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- NavigationAppFactory.startDefaultNavigationApplication(1, CacheDetailActivity.this, wpt);
- }
- });
- wpNavView.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- NavigationAppFactory.startDefaultNavigationApplication(2, CacheDetailActivity.this, wpt);
- return true;
- }
- });
+ // info
+ final String waypointInfo = Formatter.formatWaypointInfo(wpt);
+ if (StringUtils.isNotBlank(waypointInfo)) {
+ final TextView infoView = holder.infoView;
+ infoView.setText(waypointInfo);
+ infoView.setVisibility(View.VISIBLE);
+ }
- registerForContextMenu(waypointView);
- waypointView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- openContextMenu(v);
- }
- });
+ // title
+ final TextView nameView = holder.nameView;
+ if (StringUtils.isNotBlank(wpt.getName())) {
+ nameView.setText(StringEscapeUtils.unescapeHtml4(wpt.getName()));
+ } else if (null != wpt.getCoords()) {
+ nameView.setText(wpt.getCoords().toString());
+ } else {
+ nameView.setText(res.getString(R.string.waypoint));
+ }
+ wpt.setIcon(res, nameView);
- waypointView.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- EditWaypointActivity.startActivityEditWaypoint(CacheDetailActivity.this, cache, wpt.getId());
- refreshOnResume = true;
- return true;
- }
- });
+ // visited
+ if (wpt.isVisited()) {
+ final TypedValue a = new TypedValue();
+ getTheme().resolveAttribute(R.attr.text_color_grey, a, true);
+ if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
+ // really should be just a color!
+ nameView.setTextColor(a.data);
+ }
+ }
- waypoints.addView(waypointView);
+ // note
+ if (StringUtils.isNotBlank(wpt.getNote())) {
+ final TextView noteView = holder.noteView;
+ noteView.setVisibility(View.VISIBLE);
+ if (TextUtils.containsHtml(wpt.getNote())) {
+ noteView.setText(Html.fromHtml(wpt.getNote()), TextView.BufferType.SPANNABLE);
+ }
+ else {
+ noteView.setText(wpt.getNote());
+ }
}
- final Button addWaypoint = (Button) view.findViewById(R.id.add_waypoint);
- addWaypoint.setClickable(true);
- addWaypoint.setOnClickListener(new View.OnClickListener() {
+ final View wpNavView = holder.wpNavView;
+ wpNavView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ NavigationAppFactory.startDefaultNavigationApplication(1, CacheDetailActivity.this, wpt);
+ }
+ });
+ wpNavView.setOnLongClickListener(new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ NavigationAppFactory.startDefaultNavigationApplication(2, CacheDetailActivity.this, wpt);
+ return true;
+ }
+ });
+ registerForContextMenu(rowView);
+ rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- EditWaypointActivity.startActivityAddWaypoint(CacheDetailActivity.this, cache);
- refreshOnResume = true;
+ selectedWaypoint = wpt;
+ openContextMenu(v);
}
});
- return view;
+ rowView.setOnLongClickListener(new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ selectedWaypoint = wpt;
+ EditWaypointActivity.startActivityEditWaypoint(CacheDetailActivity.this, cache, wpt.getId());
+ refreshOnResume = true;
+ return true;
+ }
+ });
}
}
diff --git a/main/src/cgeo/geocaching/WaypointViewHolder.java b/main/src/cgeo/geocaching/WaypointViewHolder.java
new file mode 100644
index 0000000..bf2bf01
--- /dev/null
+++ b/main/src/cgeo/geocaching/WaypointViewHolder.java
@@ -0,0 +1,22 @@
+package cgeo.geocaching;
+
+import butterknife.InjectView;
+
+import cgeo.geocaching.ui.AbstractViewHolder;
+
+import android.view.View;
+import android.widget.TextView;
+
+public class WaypointViewHolder extends AbstractViewHolder {
+
+ @InjectView(R.id.coordinates) protected TextView coordinatesView;
+ @InjectView(R.id.info) protected TextView infoView;
+ @InjectView(R.id.name) protected TextView nameView;
+ @InjectView(R.id.note) protected TextView noteView;
+ @InjectView(R.id.wpDefaultNavigation) protected View wpNavView;
+
+ public WaypointViewHolder(View rowView) {
+ super(rowView);
+ }
+
+}