From 742eb0a64a49b6fb10d0e2485785394e2dbbe533 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 25 Nov 2014 18:23:37 +0200 Subject: [PATCH] Added view for map updates --- OsmAnd/res/layout/dash_updates_fragment.xml | 10 +++++-- OsmAnd/res/layout/dash_updates_item.xml | 5 ++++ .../plus/dashboard/DashUpdatesFragment.java | 29 ++++++++++++++++-- .../plus/dashboard/DashboardActivity.java | 30 +++++++++---------- .../plus/download/BaseDownloadActivity.java | 25 ++++++++++++++++ .../plus/download/DownloadActivity.java | 17 ++--------- .../plus/download/UpdatesIndexFragment.java | 2 +- 7 files changed, 83 insertions(+), 35 deletions(-) diff --git a/OsmAnd/res/layout/dash_updates_fragment.xml b/OsmAnd/res/layout/dash_updates_fragment.xml index bd0eae9de4..8e4d96408c 100644 --- a/OsmAnd/res/layout/dash_updates_fragment.xml +++ b/OsmAnd/res/layout/dash_updates_fragment.xml @@ -10,12 +10,18 @@ + android:layout_height="40dp"> + android:layout_height="fill_parent" + android:paddingTop="2dp" + android:gravity="center_vertical" + android:layout_marginLeft="15dp" + android:textSize="14sp" + android:textColor="@color/dashboard_black"/> + list) { View mainView = getView(); + //it may be null because download index thread is async if (mainView == null) { return; } @@ -41,6 +60,9 @@ public class DashUpdatesFragment extends DashBaseFragment { mainView.setVisibility(View.GONE); return; } + + ((TextView)mainView.findViewById(R.id.update_count)).setText(String.valueOf(list.size())); + LinearLayout updates = (LinearLayout) mainView.findViewById(R.id.updates_items); updates.removeAllViews(); @@ -51,9 +73,9 @@ public class DashUpdatesFragment extends DashBaseFragment { } LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dash_updates_item, null, false); - String eName = item.getVisibleDescription(getMyApplication()) + "\n" - + item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions()); - String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + "\n" + item.getSizeDescription(getMyApplication()); + String name = item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions()); + String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", " + item.getSizeDescription(getMyApplication()); + String eName = name.replace("\n", " "); ((TextView) view.findViewById(R.id.map_name)).setText(eName); ((TextView) view.findViewById(R.id.map_descr)).setText(d); (view.findViewById(R.id.btn_download)).setOnClickListener(new View.OnClickListener() { @@ -63,6 +85,7 @@ public class DashUpdatesFragment extends DashBaseFragment { getDownloadActivity().getEntriesToDownload().put(item, download); } }); + updates.addView(view); } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardActivity.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardActivity.java index 1b2f8a6c17..e51536dcc3 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardActivity.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardActivity.java @@ -7,6 +7,7 @@ import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; +import android.support.v4.app.Fragment; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; @@ -22,11 +23,10 @@ import net.osmand.plus.activities.MainMenuActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TipsAndTricksActivity; import net.osmand.plus.base.FavoriteImageDrawable; -import net.osmand.plus.download.BaseDownloadActivity; -import net.osmand.plus.download.DownloadActivityType; -import net.osmand.plus.download.DownloadIndexesThread; +import net.osmand.plus.download.*; import net.osmand.util.MapUtils; +import java.lang.ref.WeakReference; import java.util.*; /** @@ -35,8 +35,6 @@ import java.util.*; public class DashboardActivity extends BaseDownloadActivity { public static final boolean TIPS_AND_TRICKS = false; - public static DownloadIndexesThread downloadListIndexThread; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -46,16 +44,6 @@ public class DashboardActivity extends BaseDownloadActivity { getSupportActionBar().setBackgroundDrawable(color); getSupportActionBar().setIcon(android.R.color.transparent); - if(downloadListIndexThread == null) { - downloadListIndexThread = new DownloadIndexesThread(this); - } - if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) { - downloadListIndexThread.runCategorization(DownloadActivityType.NORMAL_FILE); - } else { - downloadListIndexThread.runReloadIndexFiles(); - } - downloadListIndexThread.setUiActivity(this); - android.support.v4.app.FragmentManager manager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = manager.beginTransaction(); @@ -107,6 +95,18 @@ public class DashboardActivity extends BaseDownloadActivity { return true; } + @Override + public void updateDownloadList(List list){ + for(WeakReference ref : fragList) { + Fragment f = ref.get(); + if(f instanceof DashUpdatesFragment) { + if(!f.isDetached()) { + ((DashUpdatesFragment) f).updatedDownloadsList(list); + } + } + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { return true; diff --git a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java index 584dba9511..f1b7dad636 100644 --- a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java @@ -2,13 +2,17 @@ package net.osmand.plus.download; import android.app.AlertDialog; import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.Fragment; import com.actionbarsherlock.app.SherlockFragmentActivity; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; +import java.lang.ref.WeakReference; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -20,9 +24,24 @@ public class BaseDownloadActivity extends SherlockFragmentActivity { protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE; protected OsmandSettings settings; public static DownloadIndexesThread downloadListIndexThread; + protected List> fragList = new ArrayList>(); public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if(downloadListIndexThread == null) { + downloadListIndexThread = new DownloadIndexesThread(this); + } + if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) { + downloadListIndexThread.runCategorization(type); + } else { + downloadListIndexThread.runReloadIndexFiles(); + } + downloadListIndexThread.setUiActivity(this); + } + public void updateDownloadList(List list){ } @@ -129,5 +148,11 @@ public class BaseDownloadActivity extends SherlockFragmentActivity { downloadFilesPreCheckSpace(); } } + + @Override + public void onAttachFragment(Fragment fragment) { + fragList.add(new WeakReference(fragment)); + } + } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index 7c5d98020b..732fa7e9dc 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -47,7 +47,6 @@ public class DownloadActivity extends BaseDownloadActivity { private TextView progressPercent; private ImageView cancel; private List localIndexInfos = new ArrayList(); - List> fragList = new ArrayList>(); private String initialFilter = ""; @@ -56,6 +55,7 @@ public class DownloadActivity extends BaseDownloadActivity { public static final String TAB_TO_OPEN = "Tab_to_open"; public static final String DOWNLOAD_TAB = "download"; + public static final String UPDATES_TAB = "updates"; @Override @@ -66,15 +66,6 @@ public class DownloadActivity extends BaseDownloadActivity { setProgressBarIndeterminateVisibility(false); setContentView(R.layout.tab_content); - if(downloadListIndexThread == null) { - downloadListIndexThread = new DownloadIndexesThread(this); - } - if (downloadListIndexThread.getCachedIndexFiles() != null && downloadListIndexThread.isDownloadedFromInternet()) { - downloadListIndexThread.runCategorization(type); - } else { - downloadListIndexThread.runReloadIndexFiles(); - } - downloadListIndexThread.setUiActivity(this); settings = ((OsmandApplication) getApplication()).getSettings(); tabHost = (TabHost) findViewById(android.R.id.tabhost); @@ -145,6 +136,8 @@ public class DownloadActivity extends BaseDownloadActivity { if (tab != null) { if (tab.equals(DOWNLOAD_TAB)){ tabHost.setCurrentTab(1); + } else if (tab.equals(UPDATES_TAB)){ + tabHost.setCurrentTab(2); } } } @@ -439,10 +432,6 @@ public class DownloadActivity extends BaseDownloadActivity { return ((OsmandApplication) getApplication()).getSettings().isLightActionBar(); } - @Override - public void onAttachFragment(Fragment fragment) { - fragList.add(new WeakReference(fragment)); - } private void copyFilesForAndroid19(final String newLoc) { SettingsGeneralActivity.MoveFilesToDifferentDirectory task = diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index 3a123d86af..b6f8b3f0f9 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -42,7 +42,7 @@ public class UpdatesIndexFragment extends SherlockListFragment { updateColor = getResources().getColor(R.color.color_update); osmandRegions = getMyApplication().getResourceManager().getOsmandRegions(); List indexItems = new ArrayList(); - if (DownloadActivity.downloadListIndexThread != null) { + if (BaseDownloadActivity.downloadListIndexThread != null) { indexItems = DownloadActivity.downloadListIndexThread.getItemsToUpdate(); } listAdapter = new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, indexItems);