From 54b865342dc3cb4c3506c7d2501e116c6147497a Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Thu, 15 Oct 2015 15:12:30 +0300 Subject: [PATCH] Updates logic finished. --- OsmAnd/res/layout/update_index_frament.xml | 29 +++++++++++++ OsmAnd/res/values/strings.xml | 1 + .../plus/download/BaseDownloadActivity.java | 3 ++ .../plus/download/DownloadIndexesThread.java | 10 +++++ .../net/osmand/plus/download/IndexItem.java | 28 ++++++------- .../plus/download/UpdatesIndexFragment.java | 42 +++++++++++++------ 6 files changed, 87 insertions(+), 26 deletions(-) create mode 100644 OsmAnd/res/layout/update_index_frament.xml diff --git a/OsmAnd/res/layout/update_index_frament.xml b/OsmAnd/res/layout/update_index_frament.xml new file mode 100644 index 0000000000..157a8add1b --- /dev/null +++ b/OsmAnd/res/layout/update_index_frament.xml @@ -0,0 +1,29 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 423f6c346a..22a3897c8a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2018,4 +2018,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Are you sure you want to download map of roads, even though you have full map? %1$.1f from %2$.1f MB %.1f MB + Update all(%1$s Mb) diff --git a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java index 72ddee3953..9065433731 100644 --- a/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/BaseDownloadActivity.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.widget.Toast; @@ -76,10 +77,12 @@ public class BaseDownloadActivity extends ActionBarProgressActivity { } + @UiThread public void updateDownloadList(List list) { } + @UiThread public void updateProgress(boolean updateOnlyProgress, Object tag) { } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 865d530735..50ad54e5e3 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -11,6 +11,7 @@ import android.os.AsyncTask; import android.os.AsyncTask.Status; import android.os.Build; import android.os.StatFs; +import android.support.annotation.UiThread; import android.view.View; import android.widget.Toast; @@ -553,6 +554,7 @@ public class DownloadIndexesThread { } protected void onPostExecute(IndexFileList result) { + notifyFilesToUpdateChanged(); indexFiles = result; if (indexFiles != null && uiActivity != null) { boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); @@ -679,6 +681,7 @@ public class DownloadIndexesThread { @Override protected void onPostExecute(List filtered) { prepareFilesToUpdate(); + notifyFilesToUpdateChanged(); currentRunningTask.remove(this); if (uiActivity != null) { uiActivity.categorizationFinished(filtered, cats); @@ -709,6 +712,13 @@ public class DownloadIndexesThread { itemsToUpdate.add(item); } } + } + } + + @UiThread + private void notifyFilesToUpdateChanged() { + List filtered = getCachedIndexFiles(); + if (filtered != null) { if (uiActivity != null) { uiActivity.updateDownloadList(itemsToUpdate); } diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index b9dab4e113..0045a8ba2d 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -165,20 +165,20 @@ public class IndexItem implements Comparable, HasName, Parcelable { this.initializedName = initializedName; } - @Override - public String toString() { - return "IndexItem{" + - "description='" + description + '\'' + - ", fileName='" + fileName + '\'' + - ", simplifiedFileName='" + simplifiedFileName + '\'' + - ", size='" + size + '\'' + - ", timestamp=" + timestamp + - ", contentSize=" + contentSize + - ", containerSize=" + containerSize + - ", type=" + type.getTag() + - ", extra=" + extra + - '}'; - } +// @Override +// public String toString() { +// return "IndexItem{" + +// "description='" + description + '\'' + +// ", fileName='" + fileName + '\'' + +// ", simplifiedFileName='" + simplifiedFileName + '\'' + +// ", size='" + size + '\'' + +// ", timestamp=" + timestamp + +// ", contentSize=" + contentSize + +// ", containerSize=" + containerSize + +// ", type=" + type.getTag() + +// ", extra=" + extra + +// '}'; +// } @Override public int describeContents() { diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index fce4b934a6..2e4c5b47a5 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -19,12 +19,15 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import net.osmand.PlatformUtil; import net.osmand.access.AccessibleToast; import net.osmand.map.OsmandRegions; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.OsmAndListFragment; +import org.apache.commons.logging.Log; + import java.text.MessageFormat; import java.text.ParseException; import java.util.ArrayList; @@ -33,11 +36,8 @@ import java.util.Date; import java.util.List; import java.util.Map; -/** - * Created by Denis - * on 09.09.2014. - */ public class UpdatesIndexFragment extends OsmAndListFragment { + private static final Log LOG = PlatformUtil.getLog(UpdateIndexAdapter.class); private UpdateIndexAdapter listAdapter; List indexItems = new ArrayList<>(); @@ -45,7 +45,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (BaseDownloadActivity.downloadListIndexThread != null) { - indexItems = new ArrayList(DownloadActivity.downloadListIndexThread.getItemsToUpdate()); + indexItems = new ArrayList<>(DownloadActivity.downloadListIndexThread.getItemsToUpdate()); } createListView(); setHasOptionsMenu(true); @@ -53,11 +53,11 @@ public class UpdatesIndexFragment extends OsmAndListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.update_index, container, false); + return inflater.inflate(R.layout.update_index_frament, container, false); } private void createListView() { - updateHeader(); + updateUpdateAllButton(); if (indexItems.size() == 0) { if (DownloadActivity.downloadListIndexThread.isDownloadedFromInternet()) { indexItems.add(new IndexItem(getString(R.string.everything_up_to_date), "", 0, "", 0, 0, null)); @@ -77,14 +77,32 @@ public class UpdatesIndexFragment extends OsmAndListFragment { setListAdapter(listAdapter); } - private void updateHeader() { + private void updateUpdateAllButton() { View view = getView(); if (getView() == null) { return; } - String header = getActivity().getString(R.string.download_tab_updates) + " - " + indexItems.size(); - ((TextView) view.findViewById(R.id.header)). - setText(header); + final TextView updateAllButton = (TextView) view.findViewById(R.id.updateAllButton); + if (indexItems.size() == 0 || indexItems.get(0).getType() == null) { + updateAllButton.setVisibility(View.GONE); + } else { + updateAllButton.setVisibility(View.VISIBLE); + long downloadsSize = 0; + for (IndexItem indexItem : indexItems) { + downloadsSize += indexItem.getSize(); + } + String updateAllText = getActivity().getString(R.string.update_all, downloadsSize >> 20); + updateAllButton.setText(updateAllText); + updateAllButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + for (IndexItem indexItem : indexItems) { + getMyActivity().addToDownload(indexItem); + } + getMyActivity().downloadFilesCheckFreeVersion(); + } + }); + } } @Override @@ -112,7 +130,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - updateHeader(); + updateUpdateAllButton(); ActionBar actionBar = getMyActivity().getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);