Merge pull request #958 from Bars107/r1.9

Huge fixes for downloads.
This commit is contained in:
vshcherb 2014-11-17 16:47:10 +01:00
commit 3b3d8017a7
3 changed files with 37 additions and 21 deletions

View file

@ -100,7 +100,6 @@ public class DownloadActivity extends SherlockFragmentActivity {
tabHost.setCurrentTab(0); tabHost.setCurrentTab(0);
settings = ((OsmandApplication)getApplication()).getSettings(); settings = ((OsmandApplication)getApplication()).getSettings();
indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar); indeterminateProgressBar = (ProgressBar) findViewById(R.id.IndeterminateProgressBar);
@ -448,7 +447,11 @@ public class DownloadActivity extends SherlockFragmentActivity {
public void downloadedIndexes(){ public void downloadedIndexes(){
for(WeakReference<Fragment> ref : fragList) { for(WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get(); Fragment f = ref.get();
if(f instanceof DownloadIndexFragment) { if(f instanceof LocalIndexesFragment){
if(!f.isDetached()){
((LocalIndexesFragment) f).reloadData();
}
} else if(f instanceof DownloadIndexFragment) {
if(!f.isDetached()) { if(!f.isDetached()) {
DownloadIndexAdapter adapter = ((DownloadIndexAdapter)((DownloadIndexFragment) f).getExpandableListAdapter()); DownloadIndexAdapter adapter = ((DownloadIndexAdapter)((DownloadIndexFragment) f).getExpandableListAdapter());
if (adapter != null) { if (adapter != null) {

View file

@ -114,8 +114,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (asyncLoader == null || asyncLoader.getResult() == null) { if (asyncLoader == null || asyncLoader.getResult() == null) {
asyncLoader = new LoadLocalIndexTask(); reloadData();
asyncLoader.execute(getActivity());
} }
getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@ -132,6 +131,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}); });
} }
public void reloadData() {
asyncLoader = new LoadLocalIndexTask();
asyncLoader.execute(getActivity());
}
private void showContextMenu(final LocalIndexInfo info) { private void showContextMenu(final LocalIndexInfo info) {
Builder builder = new AlertDialog.Builder(getActivity()); Builder builder = new AlertDialog.Builder(getActivity());
@ -241,6 +245,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true); getDownloadActivity().setSupportProgressBarIndeterminateVisibility(true);
listAdapter.clear();
} }
@Override @Override
@ -383,9 +388,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
protected void onPostExecute(String result) { protected void onPostExecute(String result) {
getDownloadActivity().setProgressBarIndeterminateVisibility(false); getDownloadActivity().setProgressBarIndeterminateVisibility(false);
AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(getDownloadActivity(), result, Toast.LENGTH_LONG).show();
if (operation == RESTORE_OPERATION){
listAdapter.clear(); listAdapter.clear();
reloadIndexes(); reloadIndexes();
}
} }
} }
@ -470,7 +476,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
for(LocalIndexInfo info : getDownloadActivity().getLocalIndexInfos()){ for(LocalIndexInfo info : getDownloadActivity().getLocalIndexInfos()){
listAdapter.addLocalIndexInfo(info); listAdapter.addLocalIndexInfo(info);
} }
listAdapter.notifyDataSetChanged(); listAdapter.sortData();
} }
ActionBar actionBar = getDownloadActivity().getSupportActionBar(); ActionBar actionBar = getDownloadActivity().getSupportActionBar();
//hide action bar from downloadindexfragment //hide action bar from downloadindexfragment
@ -773,10 +779,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
final Collator cl = Collator.getInstance(); final Collator cl = Collator.getInstance();
for(List<LocalIndexInfo> i : data.values()) { for(List<LocalIndexInfo> i : data.values()) {
Collections.sort(i, new Comparator<LocalIndexInfo>() { Collections.sort(i, new Comparator<LocalIndexInfo>() {
@Override @Override
public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) { public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) {
return cl.compare(lhs.getName(), rhs.getName()); return cl.compare(getNameToDisplay(lhs), getNameToDisplay(rhs));
} }
}); });
} }
@ -800,6 +805,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
LocalIndexInfo c = findCategory(i, i.isBackupedData()); LocalIndexInfo c = findCategory(i, i.isBackupedData());
if(c != null){ if(c != null){
data.get(c).remove(i); data.get(c).remove(i);
if (data.get(c).size() == 0){
data.remove(c);
category.remove(c);
}
} }
} }
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
@ -892,14 +901,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
} }
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name)); TextView viewName = ((TextView) v.findViewById(R.id.local_index_name));
String mapDescr = getMapDescription(child.getFileName()); viewName.setText(getNameToDisplay(child));
String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getDownloadActivity().getApplication()).getResourceManager().getOsmandRegions(), child.getFileName());
if (mapDescr.length() > 0){
viewName.setText(mapDescr + " - " + mapName);
} else {
viewName.setText(mapName);
}
if (child.isNotSupported()) { if (child.isNotSupported()) {
viewName.setTextColor(warningColor); viewName.setTextColor(warningColor);
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
@ -957,6 +959,17 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
return v; return v;
} }
private String getNameToDisplay(LocalIndexInfo child) {
String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getDownloadActivity().getApplication()).getResourceManager().getOsmandRegions(), child.getFileName());
if (mapDescr.length() > 0){
return mapDescr + " - " + mapName;
} else {
return mapName;
}
}
@Override @Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;

View file

@ -84,7 +84,7 @@ public class UpdatesIndexFragment extends SherlockListFragment {
return; return;
} }
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), getDownloadActivity().getDownloadType(), new ArrayList<DownloadEntry>()); List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), e.getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) { if (download.size() > 0) {
getDownloadActivity().getEntriesToDownload().put(e, download); getDownloadActivity().getEntriesToDownload().put(e, download);
getDownloadActivity().updateDownloadButton(true); getDownloadActivity().updateDownloadButton(true);