Updates now shows all type of maps, Click on item in updates now also caounts as selection

This commit is contained in:
Denis_Bars 2014-09-27 15:49:07 +03:00
parent b50b78842d
commit 9b0a02eacd
5 changed files with 213 additions and 119 deletions

View file

@ -12,7 +12,6 @@ import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.*;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Window;
import net.osmand.IndexConstants;
@ -26,6 +25,7 @@ import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.io.File;
import java.lang.ref.WeakReference;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@ -51,8 +51,8 @@ public class DownloadActivity extends SherlockFragmentActivity {
private TextView progressMessage;
private TextView progressPercent;
private ImageView cancel;
private UpdatesIndexFragment updatesIndexFragment;
private List<LocalIndexInfo> localIndexInfos = new ArrayList<LocalIndexInfo>();
List<WeakReference<Fragment>> fragList = new ArrayList<WeakReference<Fragment>>();
public static final String FILTER_KEY = "filter";
@ -94,6 +94,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
} else {
downloadListIndexThread.runReloadIndexFiles();
}
downloadListIndexThread.setUiActivity(this);
settings = ((OsmandApplication)getApplication()).getSettings();
@ -192,8 +193,8 @@ public class DownloadActivity extends SherlockFragmentActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
public void setUpdatesIndexFragment(UpdatesIndexFragment fragment){
this.updatesIndexFragment = fragment;
public Map<String, String> getIndexActivatedFileNames() {
return downloadListIndexThread != null ? downloadListIndexThread.getIndexActivatedFileNames() : null;
}
@Override
@ -223,7 +224,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
return localIndexInfos;
}
public DownloadActivityType getType() { return type;}
public DownloadActivityType getDownloadType() { return type;}
public void setType(DownloadActivityType type) { this.type = type;}
@ -394,10 +395,52 @@ public class DownloadActivity extends SherlockFragmentActivity {
}
public void updateDownloadList(List<IndexItem> list){
if(updatesIndexFragment == null){
return;
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof UpdatesIndexFragment) {
if(!f.isDetached()) {
((UpdatesIndexFragment) f).updateItemsList(list);
}
updatesIndexFragment.updateItemsList(list);
}
}
}
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats){
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof DownloadIndexFragment) {
if(!f.isDetached()) {
((DownloadIndexFragment) f).categorizationFinished(filtered, cats);
}
}
}
}
public void downloadListUpdated(){
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof DownloadIndexFragment) {
if(!f.isDetached()) {
((DownloadIndexAdapter)((DownloadIndexFragment) f).getExpandableListAdapter()).notifyDataSetInvalidated();
}
}
}
}
public void downloadedIndexes(){
for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if(f instanceof DownloadIndexFragment) {
if(!f.isDetached()) {
DownloadIndexAdapter adapter = ((DownloadIndexAdapter)((DownloadIndexFragment) f).getExpandableListAdapter());
if (adapter != null) {
adapter.setLoadedFiles(getIndexActivatedFileNames(), getIndexFileNames());
}
}
}
}
}
public void updateDownloadButton(boolean scroll) {
@ -427,7 +470,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
boolean excessLimit = left < 0;
if (left < 0)
left = 0;
if (DownloadActivityType.isCountedInDownloads(getType())) {
if (DownloadActivityType.isCountedInDownloads(getDownloadType())) {
text += " (" + (excessLimit ? "! " : "") + getString(R.string.files_limit, left).toLowerCase() + ")";
}
}
@ -455,6 +498,11 @@ public class DownloadActivity extends SherlockFragmentActivity {
return ((OsmandApplication) getApplication()).getSettings().isLightActionBar();
}
@Override
public void onAttachFragment(Fragment fragment) {
fragList.add(new WeakReference<Fragment>(fragment));
}
private void copyFilesForAndroid19(final String newLoc) {
SettingsGeneralActivity.MoveFilesToDifferentDirectory task =
new SettingsGeneralActivity.MoveFilesToDifferentDirectory(this,
@ -473,4 +521,8 @@ public class DownloadActivity extends SherlockFragmentActivity {
task.execute();
}
public Map<String,String> getIndexFileNames() {
return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null;
}
}

View file

@ -124,6 +124,8 @@ public class DownloadActivityType {
return IndexConstants.EXTRA_EXT;
} else if (indexItem.fileName.endsWith(IndexConstants.SQLITE_EXT)) {
return IndexConstants.SQLITE_EXT;
} else if (indexItem.fileName.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
return "";
}
} else if (ROADS_FILE == this) {
return "-roads" + BINARY_MAP_INDEX_EXT;

View file

@ -9,30 +9,24 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import android.content.ActivityNotFoundException;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.*;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.MenuInflater;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask.Status;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@ -100,8 +94,6 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
setHasOptionsMenu(true);
DownloadActivity.downloadListIndexThread.setUiFragment(this);
settings = getMyApplication().getSettings();
@ -257,7 +249,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
if (!getDownloadActivity().getEntriesToDownload().containsKey(es)) {
selected++;
getDownloadActivity().getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(),
getDownloadActivity().getType(), new ArrayList<DownloadEntry>(1)));
getDownloadActivity().getDownloadType(), new ArrayList<DownloadEntry>(1)));
}
}
}
@ -282,7 +274,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
return true;
}
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList<DownloadEntry>());
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getDownloadType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
// if(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
@ -338,7 +330,7 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
EditText filterText = (EditText) getView().findViewById(R.id.search_box);
filterText.removeTextChangedListener(textWatcher);
}
DownloadActivity.downloadListIndexThread.setUiFragment(null);
DownloadActivity.downloadListIndexThread.setUiActivity(null);
}
public List<String> toString(List<DownloadActivityType> t) {
@ -359,4 +351,39 @@ public class DownloadIndexFragment extends OsmandExpandableListFragment {
public void updateProgress(boolean b) {
getDownloadActivity().updateProgress(b);
}
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
Map<String, String> indexActivatedFileNames = getDownloadActivity().getIndexActivatedFileNames();
Map<String, String> indexFileNames = getDownloadActivity().getIndexFileNames();
DownloadActivityType type = getDownloadActivity().getDownloadType();
DownloadIndexAdapter a = ((DownloadIndexAdapter) getExpandableListAdapter());
if (a == null){
return;
}
a.setLoadedFiles(indexActivatedFileNames, indexFileNames);
a.setIndexFiles(filtered, cats);
a.notifyDataSetChanged();
a.getFilter().filter(getFilterText());
if ((type == DownloadActivityType.SRTM_COUNTRY_FILE || type == DownloadActivityType.HILLSHADE_FILE)
&& OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin
&& !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) {
AlertDialog.Builder msg = new AlertDialog.Builder(getDownloadActivity());
msg.setTitle(R.string.srtm_paid_version_title);
msg.setMessage(R.string.srtm_paid_version_msg);
msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:net.osmand.srtmPlugin.paid"));
try {
getDownloadActivity().startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
msg.setPositiveButton(R.string.default_buttons_ok, null);
msg.show();
}
}
}

View file

@ -19,20 +19,17 @@ import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
@ -46,7 +43,7 @@ import android.view.View;
import android.widget.Toast;
public class DownloadIndexesThread {
private DownloadIndexFragment uiFragment = null;
private DownloadActivity uiActivity = null;
private IndexFileList indexFiles = null;
private Map<IndexItem, List<DownloadEntry>> entriesToDownload = new ConcurrentHashMap<IndexItem, List<DownloadEntry>>();
private Set<DownloadEntry> currentDownloads = new HashSet<DownloadEntry>();
@ -72,8 +69,8 @@ public class DownloadIndexesThread {
indexFiles = null;
}
public void setUiFragment(DownloadIndexFragment uiFragment) {
this.uiFragment = uiFragment;
public void setUiActivity(DownloadActivity uiActivity) {
this.uiActivity = uiActivity;
}
public List<DownloadEntry> flattenDownloadEntries() {
@ -90,6 +87,14 @@ public class DownloadIndexesThread {
return indexFiles != null ? indexFiles.getIndexFiles() : null;
}
public Map<String, String> getIndexFileNames(){
return indexFileNames;
}
public Map<String, String> getIndexActivatedFileNames(){
return indexActivatedFileNames;
}
public void updateLoadedFiles() {
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
DownloadIndexFragment.listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT,
@ -137,15 +142,15 @@ public class DownloadIndexesThread {
protected void onProgressUpdate(Object... values) {
for (Object o : values) {
if (o instanceof DownloadEntry) {
if (uiFragment != null) {
((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
uiFragment.getDownloadActivity().updateDownloadButton(false);
if (uiActivity != null) {
uiActivity.downloadListUpdated();
uiActivity.updateDownloadButton(false);
}
} else if (o instanceof IndexItem) {
entriesToDownload.remove(o);
if (uiFragment != null) {
((DownloadIndexAdapter) uiFragment.getExpandableListAdapter()).notifyDataSetInvalidated();
uiFragment.getDownloadActivity().updateDownloadButton(false);
if (uiActivity != null) {
uiActivity.downloadListUpdated();
uiActivity.updateDownloadButton(false);
}
} else if (o instanceof String) {
AccessibleToast.makeText(ctx, (String) o, Toast.LENGTH_LONG).show();
@ -158,9 +163,9 @@ public class DownloadIndexesThread {
protected void onPreExecute() {
currentRunningTask.add( this);
super.onPreExecute();
if (uiFragment != null) {
if (uiActivity != null) {
downloadFileHelper.setInterruptDownloading(false);
View mainView = uiFragment.findViewById(R.id.MainLayout);
View mainView = uiActivity.findViewById(R.id.MainLayout);
if (mainView != null) {
mainView.setKeepScreenOn(true);
}
@ -174,21 +179,18 @@ public class DownloadIndexesThread {
AccessibleToast.makeText(ctx, result, Toast.LENGTH_LONG).show();
}
currentDownloads.clear();
if (uiFragment != null) {
View mainView = uiFragment.findViewById(R.id.MainLayout);
if (uiActivity != null) {
View mainView = uiActivity.findViewById(R.id.MainLayout);
if (mainView != null) {
mainView.setKeepScreenOn(false);
}
DownloadIndexAdapter adapter = ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter());
if (adapter != null) {
adapter.setLoadedFiles(indexActivatedFileNames, indexFileNames);
updateFilesToUpdate();
}
uiActivity.downloadedIndexes();
}
currentRunningTask.remove(this);
if(uiFragment != null) {
uiFragment.updateProgress(false);
if(uiActivity != null) {
uiActivity.updateProgress(false);
}
updateFilesToUpdate();
}
@ -326,8 +328,8 @@ public class DownloadIndexesThread {
boolean res = false;
if (de.isAsset) {
try {
if (uiFragment != null) {
ResourceManager.copyAssets(uiFragment.getDownloadActivity().getAssets(), de.assetName, de.targetFile);
if (uiActivity != null) {
ResourceManager.copyAssets(uiActivity.getAssets(), de.assetName, de.targetFile);
boolean changedDate = de.targetFile.setLastModified(de.dateModified);
if(!changedDate) {
log.error("Set last timestamp is not supported");
@ -348,8 +350,8 @@ public class DownloadIndexesThread {
@Override
protected void updateProgress(boolean updateOnlyProgress) {
if(uiFragment != null) {
uiFragment.updateProgress(updateOnlyProgress);
if(uiActivity != null) {
uiActivity.updateProgress(updateOnlyProgress);
}
}
}
@ -380,19 +382,20 @@ public class DownloadIndexesThread {
protected void onPostExecute(IndexFileList result) {
indexFiles = result;
if (indexFiles != null && uiFragment != null) {
boolean basemapExists = uiFragment.getMyApplication().getResourceManager().containsBasemap();
if (indexFiles != null && uiActivity != null) {
prepareFilesToUpdate();
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap();
if (basemap != null ) {
String dt = uiFragment.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName());
String dt = uiActivity.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName());
if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate(dateFormat))) {
List<DownloadEntry> downloadEntry = basemap
.createDownloadEntry(uiFragment.getMyApplication(), DownloadActivityType.NORMAL_FILE,
.createDownloadEntry(uiActivity.getMyApplication(), DownloadActivityType.NORMAL_FILE,
new ArrayList<DownloadEntry>());
uiFragment.getDownloadActivity().getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiFragment.getDownloadActivity(), R.string.basemap_was_selected_to_download,
uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download,
Toast.LENGTH_LONG).show();
uiFragment.getDownloadActivity().findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
uiActivity.findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE);
}
}
if (indexFiles.isIncreasedMapVersion()) {
@ -402,9 +405,9 @@ public class DownloadIndexesThread {
AccessibleToast.makeText(ctx, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
}
currentRunningTask.remove(this);
if (uiFragment != null) {
uiFragment.updateProgress(false);
runCategorization(uiFragment.getDownloadActivity().getType());
if (uiActivity != null) {
uiActivity.updateProgress(false);
runCategorization(uiActivity.getDownloadType());
}
}
@ -433,8 +436,8 @@ public class DownloadIndexesThread {
@Override
protected void updateProgress(boolean updateOnlyProgress) {
if (uiFragment != null) {
uiFragment.updateProgress(updateOnlyProgress);
if (uiActivity != null) {
uiActivity.updateProgress(updateOnlyProgress);
}
};
@ -473,8 +476,8 @@ public class DownloadIndexesThread {
super.onPreExecute();
currentRunningTask.add(this);
this.message = ctx.getString(R.string.downloading_list_indexes);
if(uiFragment != null) {
uiFragment.updateProgress(false);
if(uiActivity != null) {
uiActivity.updateProgress(false);
}
}
@ -502,43 +505,18 @@ public class DownloadIndexesThread {
@Override
protected void onPostExecute(List<IndexItem> filtered) {
if (uiFragment != null) {
DownloadIndexAdapter a = ((DownloadIndexAdapter) uiFragment.getExpandableListAdapter());
a.setLoadedFiles(indexActivatedFileNames, indexFileNames);
a.setIndexFiles(filtered, cats);
prepareFilesToUpdate(filtered);
a.notifyDataSetChanged();
a.getFilter().filter(uiFragment.getFilterText());
if ((type == DownloadActivityType.SRTM_COUNTRY_FILE || type == DownloadActivityType.HILLSHADE_FILE)
&& OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) instanceof SRTMPlugin
&& !OsmandPlugin.getEnabledPlugin(SRTMPlugin.class).isPaid()) {
Builder msg = new AlertDialog.Builder(uiFragment.getDownloadActivity());
msg.setTitle(R.string.srtm_paid_version_title);
msg.setMessage(R.string.srtm_paid_version_msg);
msg.setNegativeButton(R.string.button_upgrade_osmandplus, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:net.osmand.srtmPlugin.paid"));
try {
ctx.startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
msg.setPositiveButton(R.string.default_buttons_ok, null);
msg.show();
}
}
prepareFilesToUpdate();
currentRunningTask.remove(this);
if(uiFragment != null) {
uiFragment.updateProgress(false);
if(uiActivity != null) {
uiActivity.categorizationFinished(filtered, cats);
uiActivity.updateProgress(false);
}
}
@Override
protected void updateProgress(boolean updateOnlyProgress) {
if(uiFragment != null) {
uiFragment.updateProgress(updateOnlyProgress);
if(uiActivity != null) {
uiActivity.updateProgress(updateOnlyProgress);
}
};
@ -547,11 +525,12 @@ public class DownloadIndexesThread {
execute(inst, new Void[0]);
}
private void prepareFilesToUpdate(List<IndexItem> filtered) {
private void prepareFilesToUpdate() {
List<IndexItem> filtered = getCachedIndexFiles();
itemsToUpdate.clear();
for (IndexItem item : filtered) {
String sfName = item.getTargetFileName();
java.text.DateFormat format = uiFragment.getDownloadActivity().getMyApplication().getResourceManager().getDateFormat();
java.text.DateFormat format = uiActivity.getMyApplication().getResourceManager().getDateFormat();
String date = item.getDate(format);
String indexactivateddate = indexActivatedFileNames.get(sfName);
String indexfilesdate = indexFileNames.get(sfName);
@ -562,14 +541,16 @@ public class DownloadIndexesThread {
itemsToUpdate.add(item);
}
}
uiFragment.getDownloadActivity().updateDownloadList(itemsToUpdate);
if (uiActivity != null){
uiActivity.updateDownloadList(itemsToUpdate);
}
}
private void updateFilesToUpdate(){
List<IndexItem> stillUpdate = new ArrayList<IndexItem>();
for (IndexItem item : itemsToUpdate) {
String sfName = item.getTargetFileName();
java.text.DateFormat format = uiFragment.getDownloadActivity().getMyApplication().getResourceManager().getDateFormat();
java.text.DateFormat format = uiActivity.getMyApplication().getResourceManager().getDateFormat();
String date = item.getDate(format);
String indexactivateddate = indexActivatedFileNames.get(sfName);
String indexfilesdate = indexFileNames.get(sfName);
@ -581,7 +562,9 @@ public class DownloadIndexesThread {
}
}
itemsToUpdate = stillUpdate;
uiFragment.getDownloadActivity().updateDownloadList(itemsToUpdate);
if (uiActivity != null){
uiActivity.updateDownloadList(itemsToUpdate);
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.download;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -16,7 +17,6 @@ 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.OsmandExpandableListFragment;
import java.text.MessageFormat;
import java.util.ArrayList;
@ -48,7 +48,6 @@ public class UpdatesIndexFragment extends SherlockListFragment {
});
setListAdapter(listAdapter);
setHasOptionsMenu(true);
getDownloadActivity().setUpdatesIndexFragment(this);
}
@Override
@ -66,7 +65,25 @@ public class UpdatesIndexFragment extends SherlockListFragment {
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
onItemSelected(ch, position);
}
private void onItemSelected(CheckBox ch, int position){
final IndexItem e = (IndexItem) getListAdapter().getItem(position);
if (ch.isChecked()) {
ch.setChecked(!ch.isChecked());
getDownloadActivity().getEntriesToDownload().remove(e);
getDownloadActivity().updateDownloadButton(true);
return;
}
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getDownloadType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true);
ch.setChecked(!ch.isChecked());
}
}
public DownloadActivity getDownloadActivity() {
@ -124,7 +141,7 @@ public class UpdatesIndexFragment extends SherlockListFragment {
if (!getDownloadActivity().getEntriesToDownload().containsKey(es)) {
selected++;
getDownloadActivity().getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(),
getDownloadActivity().getType(), new ArrayList<DownloadEntry>(1)));
getDownloadActivity().getDownloadType(), new ArrayList<DownloadEntry>(1)));
}
}
@ -179,7 +196,7 @@ public class UpdatesIndexFragment extends SherlockListFragment {
TextView name = (TextView) v.findViewById(R.id.download_item);
TextView description = (TextView) v.findViewById(R.id.download_descr);
IndexItem e = items.get(position);
String eName = e.getVisibleName(getMyApplication(), osmandRegions);
String eName = e.getVisibleDescription(getMyApplication()) + "\n" + e.getVisibleName(getMyApplication(), osmandRegions);
name.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate(format) + "\n" + e.getSizeDescription(getMyApplication());
description.setText(d);
@ -190,24 +207,37 @@ public class UpdatesIndexFragment extends SherlockListFragment {
@Override
public void onClick(View v) {
ch.setChecked(!ch.isChecked());
final IndexItem e = (IndexItem) getListAdapter().getItem(position);
if (ch.isChecked()) {
ch.setChecked(!ch.isChecked());
getDownloadActivity().getEntriesToDownload().remove(e);
getDownloadActivity().updateDownloadButton(true);
return;
}
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true);
ch.setChecked(!ch.isChecked());
}
onItemSelected(ch, position);
}
});
if (e.getDate(format) != null) {
Map<String, String> indexActivatedFileNames = getDownloadActivity().getIndexActivatedFileNames();
Map<String, String> indexFileNames = getDownloadActivity().getIndexFileNames();
if (indexActivatedFileNames != null && indexFileNames != null){
String sfName = e.getTargetFileName();
if (e.getDate(format).equals(indexActivatedFileNames.get(sfName))) {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
name.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else if (e.getDate(format).equals(indexFileNames.get(sfName))) {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
name.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else if (indexActivatedFileNames.containsKey(sfName)) {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
name.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
name.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
}
}
}
return v;
}