From c71c207319dad56ba96475eafecc9f131b8d694b Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 17 Sep 2014 12:03:28 +0300 Subject: [PATCH 1/4] Updates view checkbox & textbox -> center vertical --- OsmAnd/res/layout/update_index_list_item.xml | 31 +++++++++++++++++++ .../plus/download/UpdatesIndexFragment.java | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 OsmAnd/res/layout/update_index_list_item.xml diff --git a/OsmAnd/res/layout/update_index_list_item.xml b/OsmAnd/res/layout/update_index_list_item.xml new file mode 100644 index 0000000000..6d7ad49bcf --- /dev/null +++ b/OsmAnd/res/layout/update_index_list_item.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index 41e92bd3d3..b268db46f2 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -170,7 +170,7 @@ public class UpdatesIndexFragment extends SherlockListFragment { if (v == null) { LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - v = inflater.inflate(R.layout.download_index_list_item, null); + v = inflater.inflate(R.layout.update_index_list_item, null); } TextView name = (TextView) v.findViewById(R.id.download_item); From 872c6200a1bfbe36bcc0b091f96f905371278e13 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 17 Sep 2014 14:19:15 +0300 Subject: [PATCH 2/4] Updates list now will be updated after successfull download --- .../plus/download/DownloadActivity.java | 13 ++++++-- .../plus/download/DownloadIndexesThread.java | 31 ++++++++++++------- .../plus/download/UpdatesIndexFragment.java | 17 +++++----- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index a017574055..5106250936 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -44,6 +44,8 @@ public class DownloadActivity extends SherlockFragmentActivity { private TextView progressMessage; private TextView progressPercent; private ImageView cancel; + private UpdatesIndexFragment updatesIndexFragment; + public static final String FILTER_KEY = "filter"; public static final String FILTER_CAT = "filter_cat"; @@ -129,6 +131,10 @@ public class DownloadActivity extends SherlockFragmentActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } + public void setUpdatesIndexFragment(UpdatesIndexFragment fragment){ + this.updatesIndexFragment = fragment; + } + @Override protected void onResume() { super.onResume(); @@ -320,9 +326,10 @@ public class DownloadActivity extends SherlockFragmentActivity { } public void updateDownloadList(List list){ - Fragment fragment = mTabsAdapter.getItem(2); - //will fall if change tab order - ((UpdatesIndexFragment) fragment).updateItemsList(list); + if(updatesIndexFragment == null){ + return; + } + updatesIndexFragment.updateItemsList(list); } public void updateDownloadButton(boolean scroll) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 449e43d2a4..7c92e38080 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -182,6 +182,7 @@ public class DownloadIndexesThread { DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()); if (adapter != null) { adapter.setLoadedFiles(indexActivatedFileNames, indexFileNames); + updateFilesToUpdate(); } } currentRunningTask.remove(this); @@ -546,16 +547,6 @@ public class DownloadIndexesThread { execute(inst, new Void[0]); } - private void updateFilesToDownload(){ - for (IndexItem item : itemsToUpdate){ - for (String key : indexFileNames.keySet()){ - if (item.getFileName().equals(indexFileNames.get(key))){ - itemsToUpdate.remove(item); - } - } - } - } - private void prepareFilesToUpdate(List filtered) { itemsToUpdate.clear(); for (IndexItem item : filtered) { @@ -571,7 +562,25 @@ public class DownloadIndexesThread { itemsToUpdate.add(item); } } - itemsToUpdate.size(); + uiFragment.getDownloadActivity().updateDownloadList(itemsToUpdate); + } + + private void updateFilesToUpdate(){ + List stillUpdate = new ArrayList(); + for (IndexItem item : itemsToUpdate) { + String sfName = item.getTargetFileName(); + java.text.DateFormat format = uiFragment.getDownloadActivity().getMyApplication().getResourceManager().getDateFormat(); + String date = item.getDate(format); + String indexactivateddate = indexActivatedFileNames.get(sfName); + String indexfilesdate = indexFileNames.get(sfName); + if (date != null && + !date.equals(indexactivateddate) && + !date.equals(indexfilesdate) && + indexActivatedFileNames.containsKey(sfName)) { + stillUpdate.add(item); + } + } + itemsToUpdate = stillUpdate; uiFragment.getDownloadActivity().updateDownloadList(itemsToUpdate); } diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index b268db46f2..2b6d466e06 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -32,6 +32,7 @@ public class UpdatesIndexFragment extends SherlockListFragment { private java.text.DateFormat format; private UpdateIndexAdapter listAdapter; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -40,6 +41,7 @@ public class UpdatesIndexFragment extends SherlockListFragment { listAdapter = new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, DownloadActivity.downloadListIndexThread.getItemsToUpdate()); setListAdapter(listAdapter); setHasOptionsMenu(true); + getDownloadActivity().setUpdatesIndexFragment(this); } @Override @@ -51,14 +53,10 @@ public class UpdatesIndexFragment extends SherlockListFragment { } public void updateItemsList(List items) { - UpdateIndexAdapter adapter = (UpdateIndexAdapter) getListAdapter(); - if (adapter == null) { + if(listAdapter == null){ return; } - adapter.clear(); - for (IndexItem item : items) { - adapter.add(item); - } + listAdapter.setIndexFiles(items); } @Override @@ -209,9 +207,10 @@ public class UpdatesIndexFragment extends SherlockListFragment { } public void setIndexFiles(List filtered) { - this.items.clear(); - this.items.addAll(filtered); - notifyDataSetChanged(); + clear(); + for (IndexItem item : filtered){ + add(item); + } } } From 1f10bf88bc8e26e90a00989188bc334f2db07a4b Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 17 Sep 2014 15:05:54 +0300 Subject: [PATCH 3/4] Sorted items in updateindexfragment --- .../plus/download/UpdatesIndexFragment.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java index 2b6d466e06..f0813a0cf9 100644 --- a/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/UpdatesIndexFragment.java @@ -20,6 +20,7 @@ import net.osmand.plus.activities.OsmandExpandableListFragment; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -39,6 +40,12 @@ public class UpdatesIndexFragment extends SherlockListFragment { format = getMyApplication().getResourceManager().getDateFormat(); osmandRegions = getMyApplication().getResourceManager().getOsmandRegions(); listAdapter = new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, DownloadActivity.downloadListIndexThread.getItemsToUpdate()); + listAdapter.sort(new Comparator() { + @Override + public int compare(IndexItem indexItem, IndexItem indexItem2) { + return indexItem.getVisibleName(getMyApplication(), osmandRegions).compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions)); + } + }); setListAdapter(listAdapter); setHasOptionsMenu(true); getDownloadActivity().setUpdatesIndexFragment(this); @@ -47,9 +54,6 @@ public class UpdatesIndexFragment extends SherlockListFragment { @Override public void onResume() { super.onResume(); - - Map> map = getDownloadActivity().getEntriesToDownload(); - } public void updateItemsList(List items) { @@ -211,6 +215,12 @@ public class UpdatesIndexFragment extends SherlockListFragment { for (IndexItem item : filtered){ add(item); } + sort(new Comparator() { + @Override + public int compare(IndexItem indexItem, IndexItem indexItem2) { + return indexItem.getVisibleName(getMyApplication(), osmandRegions).compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions)); + } + }); } } From 4c0d1a793df41568d24b81eb1b34c05d0c5a41d1 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 17 Sep 2014 15:25:59 +0300 Subject: [PATCH 4/4] Fixed all download intents --- OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java | 3 ++- .../net/osmand/plus/activities/SettingsGeneralActivity.java | 2 +- .../src/net/osmand/plus/download/LocalIndexesFragment.java | 5 +---- OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java | 3 ++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index 4b777361de..ea3afea27f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -11,6 +11,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.search.SearchActivity; +import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexFragment; import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.sherpafy.TourViewActivity; @@ -376,7 +377,7 @@ public class MainMenuActivity extends Activity { @Override public void onClick(DialogInterface dialog, int which) { - startActivity(new Intent(MainMenuActivity.this, DownloadIndexFragment.class)); + startActivity(new Intent(MainMenuActivity.this, DownloadActivity.class)); } }); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 35a5a7ef08..ffc787aaf1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -374,7 +374,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { if (id.equals(settings.VOICE_PROVIDER.getId())) { if (MORE_VALUE.equals(newValue)) { // listPref.set(oldValue); // revert the change.. - final Intent intent = new Intent(this, DownloadIndexFragment.class); + final Intent intent = new Intent(this, DownloadActivity.class); intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag()); startActivity(intent); } else { diff --git a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java index bb88f4a03f..9befb659b1 100644 --- a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java @@ -640,10 +640,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment { } public void localOptionsMenu(final int itemId) { - if (itemId == R.string.local_index_download) { - asyncLoader.setResult(null); - startActivity(new Intent(getDownloadActivity(), DownloadIndexFragment.class)); - } else if (itemId == R.string.local_index_mi_reload) { + if (itemId == R.string.local_index_mi_reload) { reloadIndexes(); } else if (itemId == R.string.local_index_mi_delete) { openSelectionMode(itemId, R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_light, diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java index 04f1549bae..e2cb2d4f63 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/TourViewActivity.java @@ -5,6 +5,7 @@ import java.util.WeakHashMap; import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexFragment; import net.osmand.plus.sherpafy.TourInformation.StageFavorite; import net.osmand.plus.sherpafy.TourInformation.StageInformation; @@ -376,7 +377,7 @@ public class TourViewActivity extends SherlockFragmentActivity { public void startDownloadActivity() { - final Intent download = new Intent(this, DownloadIndexFragment.class); + final Intent download = new Intent(this, DownloadActivity.class); download.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); refreshListAfterDownload = true; startActivity(download);