Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-10-16 11:11:07 +02:00
commit 8f54a2a358
11 changed files with 404 additions and 321 deletions

View file

@ -12,14 +12,10 @@ import android.os.StatFs;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -30,12 +26,11 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.ActiveDownloadsDialogFragment;
import net.osmand.plus.download.items.DialogDismissListener;
import net.osmand.plus.download.items.ProgressAdapter;
import net.osmand.plus.download.items.SearchDialogFragment;
import net.osmand.plus.download.items.WorldItemsFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin;
@ -73,7 +68,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
private List<DownloadActivityType> downloadTypes = new ArrayList<DownloadActivityType>();
private BannerAndDownloadFreeVersion visibleBanner;
private ActiveDownloadsDialogFragment.DownloadEntryAdapter progressAdapter;
private ProgressAdapter progressAdapter;
@Override
@ -365,17 +360,8 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
Fragment f = ref.get();
if (f != null)
if (f.isAdded()) {
if (f instanceof OsmandExpandableListFragment) {
ExpandableListAdapter ad = ((OsmandExpandableListFragment) f).getExpandableListView()
.getExpandableListAdapter();
if (ad instanceof OsmandBaseExpandableListAdapter) {
((OsmandBaseExpandableListAdapter) ad).notifyDataSetChanged();
}
} else if (f instanceof ListFragment) {
ListAdapter la = ((ListFragment) f).getListAdapter();
if (la instanceof BaseAdapter) {
((BaseAdapter) la).notifyDataSetChanged();
}
if (f instanceof DataSetChangedListener) {
((DataSetChangedListener) f).notifyDataSetChanged();
}
}
}
@ -505,7 +491,7 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
updateProgress(true, null);
}
public void registerUpdateListener(ActiveDownloadsDialogFragment.DownloadEntryAdapter adapter) {
public void registerUpdateListener(ProgressAdapter adapter) {
progressAdapter = adapter;
updateProgress(true, null);
}
@ -704,4 +690,8 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
descriptionText.setText(text);
descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
}
public interface DataSetChangedListener {
void notifyDataSetChanged();
}
}

View file

@ -1,17 +1,38 @@
package net.osmand.plus.download;
import java.io.File;
import java.text.Collator;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
@ -33,45 +54,23 @@ import net.osmand.plus.resources.IncrementalChangesManager;
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdate;
import net.osmand.plus.resources.IncrementalChangesManager.IncrementalUpdateList;
import net.osmand.util.Algorithms;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StatFs;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.text.method.LinkMovementMethod;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.text.Collator;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public class LocalIndexesFragment extends OsmandExpandableListFragment {
public class LocalIndexesFragment extends OsmandExpandableListFragment
implements DownloadActivity.DataSetChangedListener {
private LoadLocalIndexTask asyncLoader;
private LocalIndexesAdapter listAdapter;
@ -79,11 +78,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
private boolean selectionMode = false;
private Set<LocalIndexInfo> selectedItems = new LinkedHashSet<LocalIndexInfo>();
protected static int DELETE_OPERATION = 1;
protected static int BACKUP_OPERATION = 2;
protected static int RESTORE_OPERATION = 3;
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
private ContextMenuAdapter optionsMenuAdapter;
private ActionMode actionMode;
@ -98,17 +97,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
ExpandableListView listView = (ExpandableListView)view.findViewById(android.R.id.list);
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
listAdapter = new LocalIndexesAdapter(getActivity());
listView.setAdapter(listAdapter);
expandAllGroups();
setListView(listView);
setListView(listView);
((DownloadActivity) getActivity()).updateDescriptionTextWithSize(view);
colorDrawables();
return view;
}
@SuppressWarnings({"unchecked","deprecation"})
@SuppressWarnings({"unchecked", "deprecation"})
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -124,7 +123,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
setHasOptionsMenu(true);
}
private void colorDrawables(){
private void colorDrawables() {
boolean light = getMyApplication().getSettings().isLightContent();
backup = getActivity().getResources().getDrawable(R.drawable.ic_type_archive);
backup.mutate();
@ -183,7 +182,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
builder.show();
}
private void basicFileOperation(final LocalIndexInfo info, ContextMenuAdapter adapter) {
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
@ -191,16 +190,16 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
return performBasicOperation(resId, info);
}
};
if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA ||
info.getType() == LocalIndexType.WIKI_DATA){
if(!info.isBackupedData()){
adapter.item(R.string.local_index_mi_backup).listen(listener).position( 1).reg();
if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA ||
info.getType() == LocalIndexType.WIKI_DATA) {
if (!info.isBackupedData()) {
adapter.item(R.string.local_index_mi_backup).listen(listener).position(1).reg();
}
}
if(info.isBackupedData()){
if (info.isBackupedData()) {
adapter.item(R.string.local_index_mi_restore).listen(listener).position(2).reg();
}
if(info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA){
if (info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA) {
adapter.item(R.string.shared_string_rename).listen(listener).position(3).reg();
}
adapter.item(R.string.shared_string_delete).listen(listener).position(4).reg();
@ -209,7 +208,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
private boolean performBasicOperation(int resId, final LocalIndexInfo info) {
if (resId == R.string.shared_string_rename) {
renameFile(getActivity(), new File(info.getPathToData()), new Runnable() {
@Override
public void run() {
reloadIndexes();
@ -239,7 +238,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
public static void renameFile(final Activity a, final File f, final Runnable callback) {
Builder b = new AlertDialog.Builder(a);
if(f.exists()){
if (f.exists()) {
int xt = f.getName().lastIndexOf('.');
final String ext = xt == -1 ? "" : f.getName().substring(xt);
final String originalName = xt == -1 ? f.getName() : f.getName().substring(0, xt);
@ -247,7 +246,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
editText.setText(originalName);
b.setView(editText);
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String newName = editText.getText().toString() + ext;
@ -255,18 +254,18 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
if (dest.exists()) {
AccessibleToast.makeText(a, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
} else {
if(!dest.getParentFile().exists()) {
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
if(f.renameTo(dest)){
if(callback != null) {
if (f.renameTo(dest)) {
if (callback != null) {
callback.run();
}
} else {
AccessibleToast.makeText(a, R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
}
}
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
@ -274,6 +273,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
}
@Override
public void notifyDataSetChanged() {
listAdapter.notifyDataSetChanged();
((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
}
public class LoadLocalIndexTask extends AsyncTask<Activity, LocalIndexInfo, List<LocalIndexInfo>> {
private List<LocalIndexInfo> result;
@ -305,7 +310,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
public void setResult(List<LocalIndexInfo> result) {
this.result = result;
if(result == null){
if (result == null) {
listAdapter.clear();
} else {
for (LocalIndexInfo v : result) {
@ -321,7 +326,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
protected void onPostExecute(List<LocalIndexInfo> result) {
this.result = result;
listAdapter.sortData();
if (getDownloadActivity() != null){
if (getDownloadActivity() != null) {
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
getDownloadActivity().setLocalIndexInfos(result);
}
@ -333,105 +338,105 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
private File getFileToRestore(LocalIndexInfo i){
if(i.isBackupedData()){
private File getFileToRestore(LocalIndexInfo i) {
if (i.isBackupedData()) {
File parent = new File(i.getPathToData()).getParentFile();
if(i.getType() == LocalIndexType.SRTM_DATA){
if (i.getType() == LocalIndexType.SRTM_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR);
} else if(i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)){
} else if (i.getFileName().endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
parent = getMyApplication().getAppPath(IndexConstants.ROADS_INDEX_DIR);
} else if(i.getType() == LocalIndexType.WIKI_DATA){
} else if (i.getType() == LocalIndexType.WIKI_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR);
} else if(i.getType() == LocalIndexType.MAP_DATA){
} else if (i.getType() == LocalIndexType.MAP_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.MAPS_PATH);
} else if(i.getType() == LocalIndexType.TILES_DATA){
} else if (i.getType() == LocalIndexType.TILES_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.TILES_INDEX_DIR);
} else if(i.getType() == LocalIndexType.VOICE_DATA){
} else if (i.getType() == LocalIndexType.VOICE_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if(i.getType() == LocalIndexType.TTS_VOICE_DATA){
} else if (i.getType() == LocalIndexType.TTS_VOICE_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
}
return new File(parent, i.getFileName());
}
return new File(i.getPathToData());
}
private File getFileToBackup(LocalIndexInfo i) {
if(!i.isBackupedData()){
if (!i.isBackupedData()) {
return new File(getMyApplication().getAppPath(IndexConstants.BACKUP_INDEX_DIR), i.getFileName());
}
return new File(i.getPathToData());
}
private boolean move(File from, File to){
if(!to.getParentFile().exists()){
private boolean move(File from, File to) {
if (!to.getParentFile().exists()) {
to.getParentFile().mkdirs();
}
return from.renameTo(to);
}
public class LocalIndexOperationTask extends AsyncTask<LocalIndexInfo, LocalIndexInfo, String> {
private final int operation;
public LocalIndexOperationTask(int operation){
public LocalIndexOperationTask(int operation) {
this.operation = operation;
}
@Override
protected String doInBackground(LocalIndexInfo... params) {
int count = 0;
int total = 0;
for(LocalIndexInfo info : params) {
if(!isCancelled()){
for (LocalIndexInfo info : params) {
if (!isCancelled()) {
boolean successfull = false;
if(operation == DELETE_OPERATION){
if (operation == DELETE_OPERATION) {
File f = new File(info.getPathToData());
successfull = Algorithms.removeAllFiles(f);
} else if(operation == RESTORE_OPERATION){
} else if (operation == RESTORE_OPERATION) {
successfull = move(new File(info.getPathToData()), getFileToRestore(info));
if(successfull){
if (successfull) {
info.setBackupedData(false);
}
} else if(operation == BACKUP_OPERATION){
} else if (operation == BACKUP_OPERATION) {
successfull = move(new File(info.getPathToData()), getFileToBackup(info));
if(successfull){
if (successfull) {
info.setBackupedData(true);
getMyApplication().getResourceManager().closeFile(info.getFileName());
}
}
total ++;
if(successfull){
total++;
if (successfull) {
count++;
publishProgress(info);
}
}
}
if(operation == DELETE_OPERATION){
if (operation == DELETE_OPERATION) {
return getString(R.string.local_index_items_deleted, count, total);
} else if(operation == BACKUP_OPERATION){
} else if (operation == BACKUP_OPERATION) {
return getString(R.string.local_index_items_backuped, count, total);
} else if(operation == RESTORE_OPERATION){
} else if (operation == RESTORE_OPERATION) {
return getString(R.string.local_index_items_restored, count, total);
}
}
return "";
}
@Override
protected void onProgressUpdate(LocalIndexInfo... values) {
if(operation == DELETE_OPERATION){
if (operation == DELETE_OPERATION) {
listAdapter.delete(values);
} else if(operation == BACKUP_OPERATION){
} else if (operation == BACKUP_OPERATION) {
listAdapter.move(values, false);
} else if(operation == RESTORE_OPERATION){
} else if (operation == RESTORE_OPERATION) {
listAdapter.move(values, true);
}
}
@Override
protected void onPreExecute() {
getDownloadActivity().setProgressBarIndeterminateVisibility(true);
@ -441,20 +446,18 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
protected void onPostExecute(String result) {
getDownloadActivity().setProgressBarIndeterminateVisibility(false);
AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
if (operation == RESTORE_OPERATION || operation == BACKUP_OPERATION){
if (operation == RESTORE_OPERATION || operation == BACKUP_OPERATION) {
listAdapter.clear();
reloadIndexes();
}
}
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
LocalIndexInfo child = listAdapter.getChild(groupPosition, childPosition);
if (!selectionMode){
if (!selectionMode) {
openPopUpMenu(v, child);
return true;
}
@ -462,18 +465,16 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
listAdapter.notifyDataSetChanged();
return true;
}
public Set<LocalIndexInfo> getSelectedItems() {
return selectedItems;
}
@Override
public void onPause() {
super.onPause();
if(operationTask != null){
if (operationTask != null) {
operationTask.cancel(true);
}
}
@ -483,7 +484,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
super.onDestroy();
asyncLoader.cancel(true);
}
@SuppressWarnings("deprecation")
@Override
@ -495,7 +496,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
//fixes issue when local files not shown after switching tabs
//Next line throws NPE in some circumstances when called from dashboard and listAdpater=null is not checked for. (Checking !this.isAdded above is not sufficient!)
if (listAdapter != null && listAdapter.getGroupCount() == 0 && getDownloadActivity().getLocalIndexInfos().size() > 0) {
for(LocalIndexInfo info : getDownloadActivity().getLocalIndexInfos()) {
for (LocalIndexInfo info : getDownloadActivity().getLocalIndexInfos()) {
listAdapter.addLocalIndexInfo(info);
}
listAdapter.sortData();
@ -534,28 +535,28 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
split = menu.addSubMenu(0, 1, j + 1, R.string.shared_string_more_actions);
split.setIcon(R.drawable.ic_overflow_menu_white);
split.getItem();
MenuItemCompat.setShowAsAction(split.getItem(),MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
MenuItemCompat.setShowAsAction(split.getItem(), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
item = split.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS );
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} else {
item = menu.add(0, optionsMenuAdapter.getElementId(j), j + 1, optionsMenuAdapter.getItemName(j));
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS );
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
OsmandApplication app = getMyApplication();
if (optionsMenuAdapter.getImage(app, j, isLightActionBar()) != null) {
item.setIcon(optionsMenuAdapter.getImage(app, j, isLightActionBar()));
}
}
if(operationTask == null || operationTask.getStatus() == AsyncTask.Status.FINISHED){
if (operationTask == null || operationTask.getStatus() == AsyncTask.Status.FINISHED) {
menu.setGroupVisible(0, true);
} else {
menu.setGroupVisible(0, false);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
@ -567,40 +568,40 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
return super.onOptionsItemSelected(item);
}
public void doAction(int actionResId){
if(actionResId == R.string.local_index_mi_backup){
public void doAction(int actionResId) {
if (actionResId == R.string.local_index_mi_backup) {
operationTask = new LocalIndexOperationTask(BACKUP_OPERATION);
} else if(actionResId == R.string.shared_string_delete){
} else if (actionResId == R.string.shared_string_delete) {
operationTask = new LocalIndexOperationTask(DELETE_OPERATION);
} else if(actionResId == R.string.local_index_mi_restore){
} else if (actionResId == R.string.local_index_mi_restore) {
operationTask = new LocalIndexOperationTask(RESTORE_OPERATION);
} else {
operationTask = null;
}
if(operationTask != null){
if (operationTask != null) {
operationTask.execute(selectedItems.toArray(new LocalIndexInfo[selectedItems.size()]));
}
if(actionMode != null) {
if (actionMode != null) {
actionMode.finish();
}
}
private void expandAllGroups() {
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
getExpandableListView().expandGroup(i);
}
}
private void openSelectionMode(final int actionResId, final int actionIconId,
final DialogInterface.OnClickListener listener){
private void openSelectionMode(final int actionResId, final int actionIconId,
final DialogInterface.OnClickListener listener) {
String value = getString(actionResId);
if (value.endsWith("...")) {
value = value.substring(0, value.length() - 3);
}
final String actionButton = value;
if(listAdapter.getGroupCount() == 0){
if (listAdapter.getGroupCount() == 0) {
listAdapter.cancelFilter();
expandAllGroups();
listAdapter.notifyDataSetChanged();
@ -608,7 +609,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
return;
}
expandAllGroups();
selectionMode = true;
selectedItems.clear();
actionMode = getDownloadActivity().startSupportActionMode(new ActionMode.Callback() {
@ -693,9 +694,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
listAdapter.filterCategories(true);
}
}
public void openSelectionMode(int stringRes, int darkIcon, DialogInterface.OnClickListener listener, Boolean backup,
LocalIndexType filter) {
LocalIndexType filter) {
if (backup != null) {
listAdapter.filterCategories(backup);
}
@ -704,16 +705,28 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
openSelectionMode(stringRes, darkIcon, listener);
}
public void reloadIndexes() {
listAdapter.clear();
asyncLoader = new LoadLocalIndexTask();
AsyncTask<Void, String, List<String>> task = new AsyncTask<Void, String, List<String>>(){
AsyncTask<Void, String, List<String>> task = new AsyncTask<Void, String, List<String>>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
}
@Override
protected List<String> doInBackground(Void... params) {
return getMyApplication().getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS,
new ArrayList<String>()
);
}
@Override
protected void onPostExecute(List<String> warnings) {
if ( getDownloadActivity() == null) {
if (getDownloadActivity() == null) {
return;
}
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false);
@ -730,30 +743,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
AccessibleToast.makeText(getDownloadActivity(), b.toString(), Toast.LENGTH_LONG).show();
}
if(asyncLoader.getStatus() == Status.PENDING) {
if (asyncLoader.getStatus() == Status.PENDING) {
asyncLoader.execute(getDownloadActivity());
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
}
@Override
protected List<String> doInBackground(Void... params) {
return getMyApplication().getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS,
new ArrayList<String>()
);
}
};
task.execute();
}
protected class LocalIndexesAdapter extends OsmandBaseExpandableListAdapter {
Map<LocalIndexInfo, List<LocalIndexInfo>> data = new LinkedHashMap<LocalIndexInfo, List<LocalIndexInfo>>();
List<LocalIndexInfo> category = new ArrayList<LocalIndexInfo>();
List<LocalIndexInfo> filterCategory = null;
@ -770,17 +770,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
ta.recycle();
corruptedColor = ctx.getResources().getColor(R.color.color_invalid);
}
public void clear() {
data.clear();
category.clear();
filterCategory = null;
notifyDataSetChanged();
}
public void sortData() {
final Collator cl = Collator.getInstance();
for(List<LocalIndexInfo> i : data.values()) {
for (List<LocalIndexInfo> i : data.values()) {
Collections.sort(i, new Comparator<LocalIndexInfo>() {
@Override
public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) {
@ -790,10 +790,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
}
public LocalIndexInfo findCategory(LocalIndexInfo val, boolean backuped){
for(LocalIndexInfo i : category){
if(i.isBackupedData() == backuped && val.getType() == i.getType() &&
Algorithms.objectEquals(i.getSubfolder(), val.getSubfolder())){
public LocalIndexInfo findCategory(LocalIndexInfo val, boolean backuped) {
for (LocalIndexInfo i : category) {
if (i.isBackupedData() == backuped && val.getType() == i.getType() &&
Algorithms.objectEquals(i.getSubfolder(), val.getSubfolder())) {
return i;
}
}
@ -802,13 +802,13 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
data.put(newCat, new ArrayList<LocalIndexInfo>());
return newCat;
}
public void delete(LocalIndexInfo[] values) {
for(LocalIndexInfo i : values){
for (LocalIndexInfo i : values) {
LocalIndexInfo c = findCategory(i, i.isBackupedData());
if(c != null){
if (c != null) {
data.get(c).remove(i);
if (data.get(c).size() == 0){
if (data.get(c).size() == 0) {
data.remove(c);
category.remove(c);
}
@ -816,15 +816,15 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
listAdapter.notifyDataSetChanged();
}
public void move(LocalIndexInfo[] values, boolean oldBackupState) {
for(LocalIndexInfo i : values){
for (LocalIndexInfo i : values) {
LocalIndexInfo c = findCategory(i, oldBackupState);
if(c != null){
if (c != null) {
data.get(c).remove(i);
}
c = findCategory(i, !oldBackupState);
if(c != null){
if (c != null) {
data.get(c).add(i);
}
}
@ -832,11 +832,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
expandAllGroups();
}
public void cancelFilter(){
public void cancelFilter() {
filterCategory = null;
notifyDataSetChanged();
}
public void filterCategories(LocalIndexType... types) {
List<LocalIndexInfo> filter = new ArrayList<LocalIndexInfo>();
List<LocalIndexInfo> source = filterCategory == null ? category : filterCategory;
@ -850,7 +850,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
filterCategory = filter;
notifyDataSetChanged();
}
public void filterCategories(boolean backup) {
List<LocalIndexInfo> filter = new ArrayList<LocalIndexInfo>();
List<LocalIndexInfo> source = filterCategory == null ? category : filterCategory;
@ -900,7 +900,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View v = convertView;
final LocalIndexInfo child = getChild(groupPosition, childPosition);
if (v == null ) {
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
}
@ -938,7 +938,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
if (child.getSize() >= 0) {
String size;
if (child.getSize() > 100) {
size = formatMb.format(new Object[] { (float) child.getSize() / (1 << 10) });
size = formatMb.format(new Object[]{(float) child.getSize() / (1 << 10)});
} else {
size = child.getSize() + " kB";
}
@ -957,7 +957,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
final CheckBox checkbox = (CheckBox) v.findViewById(R.id.check_local_index);
checkbox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
if (selectionMode) {
@ -965,10 +964,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
options.setVisibility(View.GONE);
checkbox.setChecked(selectedItems.contains(child));
checkbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(checkbox.isChecked()){
if (checkbox.isChecked()) {
selectedItems.add(child);
} else {
selectedItems.remove(child);
@ -990,7 +989,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
return v;
}
private String getNameToDisplay(LocalIndexInfo child) {
String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx,
@ -1012,7 +1011,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
v = inflater.inflate(R.layout.local_index_list_category, parent, false);
}
StringBuilder name = new StringBuilder(group.getType().getHumanString(getDownloadActivity()));
if(group.getSubfolder() != null) {
if (group.getSubfolder() != null) {
name.append(" ").append(group.getSubfolder());
}
if (group.isBackupedData()) {
@ -1034,9 +1033,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
String sz = "";
if (size > 0) {
if (size > 1 << 20) {
sz = DownloadActivity.formatGb.format(new Object[] { (float) size / (1 << 20) });
sz = DownloadActivity.formatGb.format(new Object[]{(float) size / (1 << 20)});
} else {
sz = formatMb.format(new Object[] { (float) size / (1 << 10) });
sz = formatMb.format(new Object[]{(float) size / (1 << 10)});
}
}
@ -1060,12 +1059,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override
public LocalIndexInfo getGroup(int groupPosition) {
return filterCategory == null ? category.get(groupPosition) : filterCategory.get(groupPosition);
return filterCategory == null ? category.get(groupPosition) : filterCategory.get(groupPosition);
}
@Override
public int getGroupCount() {
return filterCategory == null ? category.size() : filterCategory.size();
return filterCategory == null ? category.size() : filterCategory.size();
}
@Override
@ -1084,15 +1083,14 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
private String getMapDescription(String fileName){
private String getMapDescription(String fileName) {
if (fileName.endsWith(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT)) {
return ctx.getString(R.string.download_roads_only_item);
}
return "";
}
}
private void openPopUpMenu(View v, final LocalIndexInfo info) {
IconsCache iconsCache = getMyApplication().getIconsCache();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
@ -1100,7 +1098,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
final boolean restore = info.isBackupedData();
MenuItem item;
if (info.getType() == LocalIndexType.MAP_DATA) {
item = optionsMenu.getMenu().add(restore? R.string.local_index_mi_restore : R.string.local_index_mi_backup)
item = optionsMenu.getMenu().add(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup)
.setIcon(backup);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
@ -1130,7 +1128,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
return true;
}
});
if(getMyApplication().getSettings().BETA_TESTING_LIVE_UPDATES.get()) {
if (getMyApplication().getSettings().BETA_TESTING_LIVE_UPDATES.get()) {
item = optionsMenu.getMenu().add("Live updates")
.setIcon(iconsCache.getContentIcon(R.drawable.ic_action_refresh_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@ -1141,10 +1139,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
});
}
optionsMenu.show();
}
private void runLiveUpdate(final LocalIndexInfo info) {
final String fnExt = Algorithms.getFileNameWithoutExtension(new File(info.getFileName()));
new AsyncTask<Object, Object, IncrementalUpdateList>() {
@ -1152,7 +1150,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
protected void onPreExecute() {
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
};
}
@Override
protected IncrementalUpdateList doInBackground(Object... params) {
@ -1166,7 +1164,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
Toast.makeText(getDownloadActivity(), result.errorMessage, Toast.LENGTH_SHORT).show();
} else {
List<IncrementalUpdate> ll = result.getItemsForUpdate();
if(ll.isEmpty()) {
if (ll.isEmpty()) {
Toast.makeText(getDownloadActivity(), R.string.no_updates_available, Toast.LENGTH_SHORT).show();
} else {
for (IncrementalUpdate iu : ll) {
@ -1178,9 +1176,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
}
};
}
}.execute(new Object[] { fnExt });
}.execute(new Object[]{fnExt});
}

View file

@ -25,6 +25,7 @@ import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.download.items.TwoLineWithImagesViewHolder;
import org.apache.commons.logging.Log;
@ -36,7 +37,8 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
public class UpdatesIndexFragment extends OsmAndListFragment {
public class UpdatesIndexFragment extends OsmAndListFragment
implements DownloadActivity.DataSetChangedListener {
private static final Log LOG = PlatformUtil.getLog(UpdateIndexAdapter.class);
private UpdateIndexAdapter listAdapter;
List<IndexItem> indexItems = new ArrayList<>();
@ -202,6 +204,11 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
listAdapter.notifyDataSetChanged();
}
@Override
public void notifyDataSetChanged() {
listAdapter.notifyDataSetChanged();
}
private class UpdateIndexAdapter extends ArrayAdapter<IndexItem> {
List<IndexItem> items;
@ -243,28 +250,12 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
}
}
// TODO: 10/13/15 Extract viewholder parent
private static class UpdateViewHolder {
private final TextView nameTextView;
private final TextView descrTextView;
private final ImageView leftImageView;
private final ImageView rightImageButton;
private final Button rightButton;
private final ProgressBar progressBar;
private final TextView mapDateTextView;
private final DownloadActivity context;
private static class UpdateViewHolder extends TwoLineWithImagesViewHolder {
private final java.text.DateFormat format;
private UpdateViewHolder(View convertView,
final DownloadActivity context) {
nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
rightButton = (Button) convertView.findViewById(R.id.rightButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
mapDateTextView = (TextView) convertView.findViewById(R.id.mapDateTextView);
this.context = context;
super(convertView, context);
format = context.getMyApplication().getResourceManager().getDateFormat();
}

View file

@ -51,7 +51,8 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
return builder.create();
}
public static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry> {
public static class DownloadEntryAdapter extends ArrayAdapter<DownloadEntry>
implements ProgressAdapter {
private final Drawable deleteDrawable;
private final DownloadActivity context;
private int itemInProgressPosition = -1;
@ -83,6 +84,7 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
return convertView;
}
@Override
public void setProgress(BasicProgressAsyncTask<?, ?, ?> task, Object tag) {
isFinished = task == null
|| task.getStatus() == AsyncTask.Status.FINISHED;
@ -96,6 +98,7 @@ public class ActiveDownloadsDialogFragment extends DialogFragment {
itemInProgressPosition = i;
downloadedItems.add(i);
}
break;
}
}
notifyDataSetChanged();

View file

@ -6,10 +6,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
@ -25,14 +21,7 @@ import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.text.DateFormat;
import java.util.Map;
public class ItemViewHolder {
private final TextView nameTextView;
private final TextView descrTextView;
private final ImageView leftImageView;
private final ImageView rightImageButton;
private final Button rightButton;
private final ProgressBar progressBar;
private final TextView mapDateTextView;
public class ItemViewHolder extends TwoLineWithImagesViewHolder {
private final Map<String, String> indexFileNames;
private final Map<String, String> indexActivatedFileNames;
@ -54,22 +43,17 @@ public class ItemViewHolder {
}
public ItemViewHolder(View convertView,
DownloadActivity context,
DateFormat dateFormat,
Map<String, String> indexFileNames,
Map<String, String> indexActivatedFileNames) {
super(convertView, context);
this.indexFileNames = indexFileNames;
this.indexActivatedFileNames = indexActivatedFileNames;
this.dateFormat = dateFormat;
nameTextView = (TextView) convertView.findViewById(R.id.name);
descrTextView = (TextView) convertView.findViewById(R.id.description);
leftImageView = (ImageView) convertView.findViewById(R.id.leftImageView);
rightImageButton = (ImageView) convertView.findViewById(R.id.rightImageButton);
rightButton = (Button) convertView.findViewById(R.id.rightButton);
progressBar = (ProgressBar) convertView.findViewById(R.id.progressBar);
mapDateTextView = (TextView) convertView.findViewById(R.id.mapDateTextView);
TypedValue typedValue = new TypedValue();
Resources.Theme theme = convertView.getContext().getTheme();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);
textColorPrimary = typedValue.data;
theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
@ -88,13 +72,20 @@ public class ItemViewHolder {
this.freeVersion = freeVersion;
}
public void bindIndexItem(final IndexItem indexItem, final DownloadActivity context,
boolean showTypeInTitle, boolean showTypeInDesc) {
public void bindIndexItem(final IndexItem indexItem,
boolean showTypeInTitle, boolean showTypeInDesc, int progress) {
boolean disabled = false;
String textButtonCaption = "GET";
rightButtonAction = RightButtonAction.UNKNOWN;
if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
rightImageButton.setClickable(false);
if (progress != -1) {
rightImageButton.setClickable(true);
rightImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context.makeSureUserCancelDownload();
}
});
} else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
nameTextView.setText(indexItem.getVisibleName(context,
context.getMyApplication().getRegions(), false));
} else {
@ -123,22 +114,60 @@ public class ItemViewHolder {
}
}
descrTextView.setVisibility(View.VISIBLE);
if (!showTypeInTitle && (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
descrTextView.setText(indexItem.getType().getString(context));
} else if (showTypeInDesc) {
descrTextView.setText(indexItem.getType().getString(context) + "" + indexItem.getSizeDescription(context));
if (progress == -1) {
descrTextView.setVisibility(View.VISIBLE);
if (!showTypeInTitle && (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE ||
indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) {
descrTextView.setText(indexItem.getType().getString(context));
} else if (showTypeInDesc) {
descrTextView.setText(indexItem.getType().getString(context) + "" + indexItem.getSizeDescription(context));
} else {
descrTextView.setText(indexItem.getSizeDescription(context));
}
rightImageButton.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import));
progressBar.setVisibility(View.GONE);
if (indexFileNames != null && indexItem.isAlreadyDownloaded(indexFileNames)) {
boolean outdated = false;
String date;
if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
date = indexItem.getDate(dateFormat);
} else {
String sfName = indexItem.getTargetFileName();
final boolean updatableResource = indexActivatedFileNames.containsKey(sfName);
date = updatableResource ? indexActivatedFileNames.get(sfName) : indexFileNames.get(sfName);
outdated = DownloadActivity.downloadListIndexThread.checkIfItemOutdated(indexItem);
}
String updateDescr = context.getResources().getString(R.string.local_index_installed) + ": "
+ date;
mapDateTextView.setText(updateDescr);
int colorId = outdated ? R.color.color_distance : R.color.color_ok;
final int color = context.getResources().getColor(colorId);
mapDateTextView.setTextColor(color);
leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource(), color));
nameTextView.setTextColor(textColorPrimary);
} else if (disabled) {
leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource(), textColorSecondary));
nameTextView.setTextColor(textColorSecondary);
} else {
leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource()));
nameTextView.setTextColor(textColorPrimary);
}
} else {
descrTextView.setText(indexItem.getSizeDescription(context));
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(progress);
rightImageButton.setImageDrawable(
getContentIcon(context, R.drawable.ic_action_remove_dark));
}
rightImageButton.setVisibility(View.VISIBLE);
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import));
progressBar.setVisibility(View.GONE);
if (rightButtonAction != RightButtonAction.UNKNOWN) {
rightButton.setText(textButtonCaption);
rightButton.setText(R.string.get_plugin);
rightButton.setVisibility(View.VISIBLE);
rightImageButton.setVisibility(View.GONE);
final RightButtonAction action = rightButtonAction;
@ -177,39 +206,14 @@ public class ItemViewHolder {
rightButton.setVisibility(View.GONE);
rightImageButton.setVisibility(View.VISIBLE);
}
if (indexFileNames != null && indexItem.isAlreadyDownloaded(indexFileNames)) {
boolean outdated = false;
String date;
if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
date = indexItem.getDate(dateFormat);
} else {
String sfName = indexItem.getTargetFileName();
final boolean updatableResource = indexActivatedFileNames.containsKey(sfName);
date = updatableResource ? indexActivatedFileNames.get(sfName) : indexFileNames.get(sfName);
outdated = DownloadActivity.downloadListIndexThread.checkIfItemOutdated(indexItem);
}
String updateDescr = context.getResources().getString(R.string.local_index_installed) + ": "
+ date;
mapDateTextView.setText(updateDescr);
int colorId = outdated ? R.color.color_distance : R.color.color_ok;
final int color = context.getResources().getColor(colorId);
mapDateTextView.setTextColor(color);
leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource(), color));
nameTextView.setTextColor(textColorPrimary);
} else if (disabled) {
leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource(), textColorSecondary));
nameTextView.setTextColor(textColorSecondary);
} else {
leftImageView.setImageDrawable(getContentIcon(context,
indexItem.getType().getIconResource()));
nameTextView.setTextColor(textColorPrimary);
}
}
public void bindRegion(WorldRegion region, DownloadActivity context) {
public void bindIndexItem(final IndexItem indexItem,
boolean showTypeInTitle, boolean showTypeInDesc) {
bindIndexItem(indexItem, showTypeInTitle, showTypeInDesc, -1);
}
public void bindRegion(WorldRegion region) {
nameTextView.setText(region.getName());
nameTextView.setTextColor(textColorPrimary);
if (region.getResourceTypes().size() > 0) {

View file

@ -0,0 +1,10 @@
package net.osmand.plus.download.items;
import net.osmand.plus.base.BasicProgressAsyncTask;
/**
* Created by GaidamakUA on 10/16/15.
*/
public interface ProgressAdapter {
void setProgress(BasicProgressAsyncTask<?, ?, ?> task, Object tag);
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.download.items;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
@ -22,8 +23,10 @@ import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadEntry;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
@ -80,6 +83,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
expandAllGroups();
}
}
getMyActivity().registerUpdateListener(listAdapter);
return view;
}
@ -168,7 +172,8 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
return fragment;
}
private class RegionsItemsAdapter extends OsmandBaseExpandableListAdapter {
private class RegionsItemsAdapter extends OsmandBaseExpandableListAdapter
implements ProgressAdapter {
private Map<String, List<Object>> data = new LinkedHashMap<>();
private List<String> sections = new LinkedList<>();
@ -176,6 +181,11 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private boolean nauticalPluginDisabled;
private boolean freeVersion;
private int groupInProgressPosition = -1;
private int childInProgressPosition = -1;
private int progress = -1;
private boolean isFinished;
public RegionsItemsAdapter() {
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
@ -217,7 +227,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView,
viewHolder = new ItemViewHolder(convertView, getMyActivity(),
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
@ -230,18 +240,16 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
viewHolder.setFreeVersion(freeVersion);
final Object child = getChild(groupPosition, childPosition);
if (child instanceof ItemsListBuilder.ResourceItem
&& groupPosition == regionMapsGroupPos) {
ItemsListBuilder.ResourceItem item = (ItemsListBuilder.ResourceItem) child;
viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), true, false);
} else if (child instanceof WorldRegion) {
viewHolder.bindRegion((WorldRegion) child, getDownloadActivity());
if (child instanceof WorldRegion) {
viewHolder.bindRegion((WorldRegion) child);
} else if (child instanceof ItemsListBuilder.ResourceItem) {
final int localProgress = groupPosition == groupInProgressPosition
&& childPosition == childInProgressPosition ? progress : -1;
viewHolder.bindIndexItem(((ItemsListBuilder.ResourceItem) child).getIndexItem(),
getDownloadActivity(), false, true);
false, true, localProgress);
} else {
throw new IllegalArgumentException("Item must be of type WorldRegion or " +
"IndexItem but is of type:" + child.getClass());
"ResourceItem but is of type:" + child.getClass());
}
return convertView;
@ -300,6 +308,39 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public void setProgress(BasicProgressAsyncTask<?, ?, ?> task, Object tag) {
LOG.debug("setProgress()");
isFinished = task == null
|| task.getStatus() == AsyncTask.Status.FINISHED;
groupInProgressPosition = -1;
childInProgressPosition = -1;
progress = -1;
if (isFinished) return;
if (tag instanceof DownloadEntry) {
progress = task.getProgressPercentage();
outer_loop:
for (int i = 0; i < getGroupCount(); i++) {
for (int j = 0; j < getChildrenCount(i); j++) {
final IndexItem child =
((ItemsListBuilder.ResourceItem) getChild(i, j)).getIndexItem();
LOG.debug("chield=" + child.getBasename());
LOG.debug("tag=" + ((DownloadEntry) tag).baseName);
if (child.getBasename().equals(((DownloadEntry) tag).baseName)) {
groupInProgressPosition = i;
childInProgressPosition = j;
notifyDataSetChanged();
LOG.debug("groupInProgressPosition=" + groupInProgressPosition
+ "; childInProgressPosition" + childInProgressPosition);
break outer_loop;
}
}
}
}
LOG.debug("groupInProgressPosition=" + groupInProgressPosition
+ "; childInProgressPosition" + childInProgressPosition);
}
}
public static class ConfirmDownloadUnneededMapDialogFragment extends DialogFragment {

View file

@ -218,6 +218,7 @@ public class SearchItemsFragment extends Fragment {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView,
getMyActivity(),
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
@ -230,9 +231,9 @@ public class SearchItemsFragment extends Fragment {
viewHolder.setFreeVersion(freeVersion);
if (item instanceof WorldRegion) {
viewHolder.bindRegion((WorldRegion) item, getDownloadActivity());
viewHolder.bindRegion((WorldRegion) item);
} else if (item instanceof IndexItem) {
viewHolder.bindIndexItem((IndexItem) item, getDownloadActivity(), false, true);
viewHolder.bindIndexItem((IndexItem) item, false, true);
} else {
throw new IllegalArgumentException("Item must be of type WorldRegion or " +
"IndexItem but is of type:" + item.getClass());

View file

@ -0,0 +1,36 @@
package net.osmand.plus.download.items;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
/**
* Created by GaidamakUA on 10/15/15.
*/
public class TwoLineWithImagesViewHolder {
protected final TextView nameTextView;
protected final TextView descrTextView;
protected final ImageView leftImageView;
protected final ImageView rightImageButton;
protected final Button rightButton;
protected final ProgressBar progressBar;
protected final TextView mapDateTextView;
protected final DownloadActivity context;
public TwoLineWithImagesViewHolder(View view, DownloadActivity context) {
this.context = context;
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
mapDateTextView = (TextView) view.findViewById(R.id.mapDateTextView);
rightButton = (Button) view.findViewById(R.id.rightButton);
leftImageView = (ImageView) view.findViewById(R.id.leftImageView);
descrTextView = (TextView) view.findViewById(R.id.description);
rightImageButton = (ImageView) view.findViewById(R.id.rightImageButton);
nameTextView = (TextView) view.findViewById(R.id.name);
}
}

View file

@ -185,6 +185,7 @@ public class VoiceItemsFragment extends OsmandExpandableListFragment {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView,
getMyActivity(),
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexFileNames(),
getMyActivity().getIndexActivatedFileNames());
@ -194,7 +195,7 @@ public class VoiceItemsFragment extends OsmandExpandableListFragment {
}
IndexItem item = (IndexItem) child;
viewHolder.bindIndexItem(item, getDownloadActivity(), true, false);
viewHolder.bindIndexItem(item, true, false);
return convertView;
}

View file

@ -39,7 +39,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class WorldItemsFragment extends OsmandExpandableListFragment {
public class WorldItemsFragment extends OsmandExpandableListFragment
implements DownloadActivity.DataSetChangedListener {
public static final String TAG = "WorldItemsFragment";
private static final Log LOG = PlatformUtil.getLog(WorldItemsFragment.class);
@ -199,6 +200,12 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
}
}
@Override
public void notifyDataSetChanged() {
listAdapter.notifyDataSetChanged();
((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
}
private class WorldItemsAdapter extends OsmandBaseExpandableListAdapter {
private Map<String, List<Object>> data = new LinkedHashMap<>();
@ -289,6 +296,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.two_line_with_images_list_item, parent, false);
viewHolder = new ItemViewHolder(convertView,
getMyActivity(),
getMyApplication().getResourceManager().getDateFormat(),
getMyActivity().getIndexActivatedFileNames(),
getMyActivity().getIndexFileNames());
@ -299,7 +307,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
viewHolder.setSrtmDisabled(srtmDisabled);
viewHolder.setNauticalPluginDisabled(nauticalPluginDisabled);
viewHolder.setFreeVersion(freeVersion);
viewHolder.bindIndexItem(item.getIndexItem(), getDownloadActivity(), false, false);
viewHolder.bindIndexItem(item.getIndexItem(), false, false);
} else if (groupPosition == voicePromptsIndex) {
String item = (String)child;
SimpleViewHolder viewHolder;