From 49f404ec485a5bb32cbf641a931f0f3ae8a8ae1b Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Tue, 20 Oct 2015 14:25:05 +0300 Subject: [PATCH] Rows selection for necessary fragments --- .../audionotes/AudioVideoNotesPlugin.java | 5 +--- .../DashAudioVideoNotesFragment.java | 28 ++++++++++--------- .../plus/dashboard/DashFavoritesFragment.java | 12 ++++---- .../plus/dashboard/DashRecentsFragment.java | 9 ++++-- .../osmand/plus/dashboard/DashboardOnMap.java | 20 +++++++++---- .../dashboard/tools/TransactionBuilder.java | 2 +- .../plus/download/DownloadActivity.java | 1 + .../plus/monitoring/DashTrackFragment.java | 9 ++++++ .../monitoring/OsmandMonitoringPlugin.java | 3 +- .../plus/osmedit/DashOsmEditsFragment.java | 9 ++++++ .../osmand/plus/osmedit/OsmEditingPlugin.java | 3 +- 11 files changed, 64 insertions(+), 37 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 4b32291f3d..99391f32b1 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -56,7 +56,6 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.TabActivity.TabItem; -import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.FavoritesActivity; @@ -1311,8 +1310,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override public DashFragmentData getCardFragment() { - return new DashFragmentData(DashAudioVideoNotesFragment.TAG, - DashAudioVideoNotesFragment.class, DashAudioVideoNotesFragment.TITLE_ID, - new DashboardOnMap.DefaultShouldShow(), 100, null); + return DashAudioVideoNotesFragment.FRAGMENT_DATA; } } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java index d555b166e6..ff7980def7 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java @@ -16,6 +16,8 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashBaseFragment; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.dashboard.tools.DashFragmentData; import java.util.ArrayList; import java.util.List; @@ -28,6 +30,10 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { public static final String TAG = "DASH_NOTES_FRAGMENT"; public static final int TITLE_ID = R.string.map_widget_av_notes; + private static final String ROW_NUMBER_TAG = TAG + "_row_number"; + static final DashFragmentData FRAGMENT_DATA = + new DashFragmentData(TAG, DashAudioVideoNotesFragment.class, TITLE_ID, + new DashboardOnMap.DefaultShouldShow(), 100, ROW_NUMBER_TAG); AudioVideoNotesPlugin plugin; @@ -45,24 +51,24 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { }); return view; } - + @Override public void onOpenDash() { if (plugin == null) { plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); } - setupNotes(); + setupNotes(); } - + public void setupNotes() { View mainView = getView(); - if (plugin == null){ + if (plugin == null) { mainView.setVisibility(View.GONE); return; } List notes = new ArrayList(plugin.getAllRecordings()); - if (notes.size() == 0){ + if (notes.size() == 0) { mainView.setVisibility(View.GONE); return; } else { @@ -71,11 +77,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { LinearLayout notesLayout = (LinearLayout) mainView.findViewById(R.id.items); notesLayout.removeAllViews(); - if (notes.size() > 3){ - while (notes.size() != 3){ - notes.remove(3); - } - } + DashboardOnMap.handleNumberOfRows(notes, getMyApplication().getSettings(), ROW_NUMBER_TAG); for (final AudioVideoNotesPlugin.Recording recording : notes) { LayoutInflater inflater = getActivity().getLayoutInflater(); @@ -105,9 +107,9 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { notesLayout.addView(view); } } - + public static Drawable getNoteView(final AudioVideoNotesPlugin.Recording recording, View view, - final OsmandApplication ctx) { + final OsmandApplication ctx) { String name = recording.getName(ctx); TextView nameText = ((TextView) view.findViewById(R.id.name)); nameText.setText(name); @@ -115,7 +117,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { ImageView icon = (ImageView) view.findViewById(R.id.icon); Drawable iconDrawable; - + if (recording.isAudio()) { iconDrawable = ctx.getIconsCache().getIcon(R.drawable.ic_type_audio, R.color.color_distance); } else if (recording.isVideo()) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index b63def2a9a..3ebd3bee62 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -17,6 +17,7 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.util.MapUtils; @@ -36,6 +37,9 @@ public class DashFavoritesFragment extends DashLocationFragment { List points = new ArrayList(); public static final String ROW_NUMBER_TAG = TAG + "_row_number"; + public static final DashFragmentData FRAGMENT_DATA = + new DashFragmentData(TAG, DashFavoritesFragment.class, TITLE_ID, + new DashboardOnMap.DefaultShouldShow(), 90, ROW_NUMBER_TAG); @Override public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -81,13 +85,7 @@ public class DashFavoritesFragment extends DashLocationFragment { } LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items); favorites.removeAllViews(); - int numberOfRows = - getMyApplication().getSettings().registerIntPreference(ROW_NUMBER_TAG, 3).get(); - if (points.size() > numberOfRows) { - while (points.size() != numberOfRows) { - points.remove(numberOfRows); - } - } + DashboardOnMap.handleNumberOfRows(points, getMyApplication().getSettings(), ROW_NUMBER_TAG); List distances = new ArrayList(); for (final FavouritePoint point : points) { LayoutInflater inflater = getActivity().getLayoutInflater(); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java index 97e614c540..6d381f5470 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java @@ -18,6 +18,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.activities.search.SearchHistoryFragment; +import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; @@ -34,6 +35,10 @@ public class DashRecentsFragment extends DashLocationFragment { private List arrows = new ArrayList(); List points = new ArrayList(); + private static final String ROW_NUMBER_TAG = TAG + "_row_number"; + static final DashFragmentData FRAGMENT_DATA = + new DashFragmentData(TAG, DashRecentsFragment.class, TITLE_ID, + new DashboardOnMap.DefaultShouldShow(), 100, ROW_NUMBER_TAG); @Override public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -76,9 +81,7 @@ public class DashRecentsFragment extends DashLocationFragment { LinearLayout recents = (LinearLayout) mainView.findViewById(R.id.items); recents.removeAllViews(); - if (points.size() > 3) { - points = points.subList(0, 3); - } + DashboardOnMap.handleNumberOfRows(points, getMyApplication().getSettings(), ROW_NUMBER_TAG); LatLon loc = getDefaultLocation(); List distances = new ArrayList(); for (final HistoryEntry historyEntry : points) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 95d3bca1dc..bb00964780 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -33,6 +33,7 @@ import com.github.ksoichiro.android.observablescrollview.ScrollState; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; +import net.osmand.osm.edit.OSMSettings; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; @@ -92,11 +93,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { DashWaypointsFragment.TITLE_ID, defaultShouldShow, 60, null), new DashFragmentData(DashSearchFragment.TAG, DashSearchFragment.class, DashSearchFragment.TITLE_ID, defaultShouldShow, 70, null), - new DashFragmentData(DashRecentsFragment.TAG, DashRecentsFragment.class, - DashRecentsFragment.TITLE_ID, defaultShouldShow, 80, null), - new DashFragmentData(DashFavoritesFragment.TAG, DashFavoritesFragment.class, - DashFavoritesFragment.TITLE_ID, defaultShouldShow, 90, - DashFavoritesFragment.ROW_NUMBER_TAG), + DashRecentsFragment.FRAGMENT_DATA, + DashFavoritesFragment.FRAGMENT_DATA, new DashFragmentData(DashPluginsFragment.TAG, DashPluginsFragment.class, DashPluginsFragment.TITLE_ID, defaultShouldShow, 140, null) }; @@ -922,6 +920,18 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { return dashboardView; } + public static List handleNumberOfRows(List list, OsmandSettings settings, + String rowNumberTag) { + int numberOfRows = settings.registerIntPreference(rowNumberTag, 3) + .makeGlobal().get(); + if (list.size() > numberOfRows) { + while (list.size() != numberOfRows) { + list.remove(numberOfRows); + } + } + return list; + } + public static class SettingsShouldShow implements DashFragmentData.ShouldShowFunction { @Override public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/tools/TransactionBuilder.java b/OsmAnd/src/net/osmand/plus/dashboard/tools/TransactionBuilder.java index e5dab45f04..552da73b7a 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/tools/TransactionBuilder.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/tools/TransactionBuilder.java @@ -1,5 +1,6 @@ package net.osmand.plus.dashboard.tools; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.util.Log; @@ -49,7 +50,6 @@ public final class TransactionBuilder { } public FragmentTransaction getFragmentTransaction() { - Log.v(TAG, "getFragmentTransaction(" + ")"); FragmentTransaction fragmentTransaction = manager.beginTransaction(); Collections.sort(fragments); for (DashFragmentData dashFragmentData : fragments) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index f51d545fec..b5edd23f71 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -59,6 +59,7 @@ public class DownloadActivity extends BaseDownloadActivity { DownloadResources indexes = getDownloadThread().getIndexes(); if (!indexes.isDownloadedFromInternet) { getDownloadThread().runReloadIndexFiles(); + } setContentView(R.layout.download); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java index b1f93b4838..f3b867e3a8 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java @@ -25,6 +25,8 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashBaseFragment; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.myplaces.AvailableGPXFragment; import net.osmand.plus.myplaces.FavoritesActivity; @@ -42,6 +44,11 @@ public class DashTrackFragment extends DashBaseFragment { public static final String TAG = "DASH_TRACK_FRAGMENT"; public static final int TITLE_ID = R.string.shared_string_my_tracks; + private static final String ROW_NUMBER_TAG = TAG + "_row_number"; + static final DashFragmentData FRAGMENT_DATA = + new DashFragmentData(TAG, DashTrackFragment.class, TITLE_ID, + new DashboardOnMap.DefaultShouldShow(), 110, ROW_NUMBER_TAG); + private boolean updateEnable; @Override @@ -116,6 +123,8 @@ public class DashTrackFragment extends DashBaseFragment { return; } else { (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE); + DashboardOnMap.handleNumberOfRows(list, + getMyApplication().getSettings(), ROW_NUMBER_TAG); } LinearLayout tracks = (LinearLayout) mainView.findViewById(R.id.items); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index ea29e3b7e2..f3321d2a7a 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -469,8 +469,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { @Override public DashFragmentData getCardFragment() { - return new DashFragmentData(DashTrackFragment.TAG, DashTrackFragment.class, - DashTrackFragment.TITLE_ID, new DashboardOnMap.DefaultShouldShow(), 110, null); + return DashTrackFragment.FRAGMENT_DATA; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java index 1402f93350..a4815c9648 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java @@ -18,6 +18,8 @@ import net.osmand.plus.ProgressImplementation; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashBaseFragment; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment; import java.util.ArrayList; @@ -33,6 +35,11 @@ public class DashOsmEditsFragment extends DashBaseFragment public static final String TAG = "DASH_OSM_EDITS_FRAGMENT"; public static final int TITLE_ID = R.string.osm_settings; + private static final String ROW_NUMBER_TAG = TAG + "_row_number"; + static final DashFragmentData FRAGMENT_DATA = + new DashFragmentData(TAG, DashOsmEditsFragment.class, TITLE_ID, + new DashboardOnMap.DefaultShouldShow(), 130, ROW_NUMBER_TAG); + OsmEditingPlugin plugin; @Override @@ -78,6 +85,8 @@ public class DashOsmEditsFragment extends DashBaseFragment return; } else { mainView.setVisibility(View.VISIBLE); + DashboardOnMap.handleNumberOfRows(dataPoints, + getMyApplication().getSettings(), ROW_NUMBER_TAG); } LinearLayout osmLayout = (LinearLayout) mainView.findViewById(R.id.items); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 6f38cb157b..54c94651d1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -349,7 +349,6 @@ public class OsmEditingPlugin extends OsmandPlugin { @Override public DashFragmentData getCardFragment() { - return new DashFragmentData(DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, - DashOsmEditsFragment.TITLE_ID, new DashboardOnMap.DefaultShouldShow(), 130, null); + return DashOsmEditsFragment.FRAGMENT_DATA; } }