Now loading of map categories happening after activity start. Fragment saves its state now.
This commit is contained in:
parent
07faee07c4
commit
1b7a75d72a
7 changed files with 94 additions and 55 deletions
|
@ -1,12 +1,12 @@
|
||||||
package net.osmand.plus.activities;
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Denis
|
* Created by Denis
|
||||||
* on 26.01.2015.
|
* on 26.01.2015.
|
||||||
|
@ -34,7 +34,7 @@ public class TabActivity extends ActionBarProgressActivity {
|
||||||
pager.setAdapter(new OsmandFragmentPagerAdapter(getSupportFragmentManager(), items));
|
pager.setAdapter(new OsmandFragmentPagerAdapter(getSupportFragmentManager(), items));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OsmandFragmentPagerAdapter extends FragmentPagerAdapter {
|
public static class OsmandFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||||||
|
|
||||||
private List<TabItem> mTabs;
|
private List<TabItem> mTabs;
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,11 @@ import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Denis
|
* Created by Denis
|
||||||
|
@ -33,7 +35,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
||||||
protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
|
protected DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
|
||||||
protected OsmandSettings settings;
|
protected OsmandSettings settings;
|
||||||
public static DownloadIndexesThread downloadListIndexThread;
|
public static DownloadIndexesThread downloadListIndexThread;
|
||||||
protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
|
protected Set<WeakReference<Fragment>> fragSet = new HashSet<>();
|
||||||
protected List<IndexItem> downloadQueue = new ArrayList<>();
|
protected List<IndexItem> downloadQueue = new ArrayList<>();
|
||||||
|
|
||||||
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
public static final int MAXIMUM_AVAILABLE_FREE_DOWNLOADS = 10;
|
||||||
|
@ -217,7 +219,7 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachFragment(Fragment fragment) {
|
public void onAttachFragment(Fragment fragment) {
|
||||||
fragList.add(new WeakReference<Fragment>(fragment));
|
fragSet.add(new WeakReference<Fragment>(fragment));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void makeSureUserCancelDownload() {
|
public void makeSureUserCancelDownload() {
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
public static final String UPDATES_TAB = "updates";
|
public static final String UPDATES_TAB = "updates";
|
||||||
public static final String SINGLE_TAB = "SINGLE_TAB";
|
public static final String SINGLE_TAB = "SINGLE_TAB";
|
||||||
private List<DownloadActivityType> downloadTypes = new ArrayList<DownloadActivityType>();
|
private List<DownloadActivityType> downloadTypes = new ArrayList<DownloadActivityType>();
|
||||||
|
private List<IndexItemCategoryWithSubcat> cats;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -164,13 +165,13 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
getEntriesToDownload().clear();
|
getEntriesToDownload().clear();
|
||||||
updateDownloadButton();
|
updateDownloadButton();
|
||||||
for (WeakReference<Fragment> ref : fragList) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (f instanceof OsmAndListFragment) {
|
if (f instanceof OsmAndListFragment) {
|
||||||
if (!f.isDetached() && ((OsmAndListFragment) f).getListAdapter() instanceof ArrayAdapter) {
|
if (f.isAdded() && ((OsmAndListFragment) f).getListAdapter() instanceof ArrayAdapter) {
|
||||||
((ArrayAdapter) ((OsmAndListFragment) f).getListAdapter()).notifyDataSetChanged();
|
((ArrayAdapter) ((OsmAndListFragment) f).getListAdapter()).notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
} else if (!f.isDetached() && f instanceof OsmandExpandableListFragment &&
|
} else if (f.isAdded() && f instanceof OsmandExpandableListFragment &&
|
||||||
((OsmandExpandableListFragment) f).getAdapter() instanceof BaseExpandableListAdapter) {
|
((OsmandExpandableListFragment) f).getAdapter() instanceof BaseExpandableListAdapter) {
|
||||||
((BaseExpandableListAdapter) ((OsmandExpandableListFragment) f).getAdapter()).notifyDataSetChanged();
|
((BaseExpandableListAdapter) ((OsmandExpandableListFragment) f).getAdapter()).notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
@ -283,10 +284,10 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDownloadList(List<IndexItem> list) {
|
public void updateDownloadList(List<IndexItem> list) {
|
||||||
for (WeakReference<Fragment> ref : fragList) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (f instanceof UpdatesIndexFragment) {
|
if (f instanceof UpdatesIndexFragment) {
|
||||||
if (!f.isDetached()) {
|
if (f.isAdded()) {
|
||||||
((UpdatesIndexFragment) f).updateItemsList(list);
|
((UpdatesIndexFragment) f).updateItemsList(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,10 +296,10 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
|
public void categorizationFinished(List<IndexItem> filtered, List<IndexItemCategory> cats) {
|
||||||
for (WeakReference<Fragment> ref : fragList) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (f instanceof DownloadIndexFragment) {
|
if (f instanceof DownloadIndexFragment) {
|
||||||
if (!f.isDetached()) {
|
if (f.isAdded()) {
|
||||||
((DownloadIndexFragment) f).categorizationFinished(filtered, cats);
|
((DownloadIndexFragment) f).categorizationFinished(filtered, cats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,22 +309,28 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onCategorizationFinished(List<IndexItem> filtered,
|
public void onCategorizationFinished(List<IndexItem> filtered,
|
||||||
List<IndexItemCategoryWithSubcat> cats) {
|
List<IndexItemCategoryWithSubcat> cats) {
|
||||||
for (WeakReference<Fragment> ref : fragList) {
|
boolean isPushed = false;
|
||||||
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (f instanceof NewLocalIndexesFragment) {
|
if (f instanceof NewLocalIndexesFragment) {
|
||||||
if (!f.isDetached()) {
|
if (f.isAdded()) {
|
||||||
|
isPushed = true;
|
||||||
((NewLocalIndexesFragment) f).onCategorizationFinished(filtered, cats);
|
((NewLocalIndexesFragment) f).onCategorizationFinished(filtered, cats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!isPushed) {
|
||||||
|
this.cats = cats;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadListUpdated() {
|
public void downloadListUpdated() {
|
||||||
for (WeakReference<Fragment> ref : fragList) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (f instanceof DownloadIndexFragment) {
|
if (f instanceof DownloadIndexFragment) {
|
||||||
if (!f.isDetached()) {
|
if (f.isAdded()) {
|
||||||
((DownloadIndexAdapter) ((DownloadIndexFragment) f).getExpandableListAdapter()).notifyDataSetInvalidated();
|
((DownloadIndexAdapter) ((DownloadIndexFragment) f).getExpandableListAdapter())
|
||||||
|
.notifyDataSetInvalidated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,15 +338,16 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadedIndexes() {
|
public void downloadedIndexes() {
|
||||||
for (WeakReference<Fragment> ref : fragList) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (f instanceof LocalIndexesFragment) {
|
if (f instanceof LocalIndexesFragment) {
|
||||||
if (!f.isDetached()) {
|
if (f.isAdded()) {
|
||||||
((LocalIndexesFragment) f).reloadData();
|
((LocalIndexesFragment) f).reloadData();
|
||||||
}
|
}
|
||||||
} else if (f instanceof DownloadIndexFragment) {
|
} else if (f instanceof DownloadIndexFragment) {
|
||||||
if (!f.isDetached()) {
|
if (f.isAdded()) {
|
||||||
DownloadIndexAdapter adapter = ((DownloadIndexAdapter) ((DownloadIndexFragment) f).getExpandableListAdapter());
|
DownloadIndexAdapter adapter = ((DownloadIndexAdapter)
|
||||||
|
((DownloadIndexFragment) f).getExpandableListAdapter());
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
adapter.setLoadedFiles(getIndexActivatedFileNames(), getIndexFileNames());
|
adapter.setLoadedFiles(getIndexActivatedFileNames(), getIndexFileNames());
|
||||||
|
|
||||||
|
@ -446,9 +454,10 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
findViewById(R.id.wikiButton).setVisibility(wikipediaItems.size() == 0 ? View.GONE : View.VISIBLE);
|
findViewById(R.id.wikiButton).setVisibility(wikipediaItems.size() == 0 ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WeakReference<Fragment> ref : fragList) {
|
for (WeakReference<Fragment> ref : fragSet) {
|
||||||
Fragment f = ref.get();
|
Fragment f = ref.get();
|
||||||
if (!f.isDetached()) {
|
if (f != null)
|
||||||
|
if (f.isAdded()) {
|
||||||
if (f instanceof OsmandExpandableListFragment) {
|
if (f instanceof OsmandExpandableListFragment) {
|
||||||
ExpandableListAdapter ad = ((OsmandExpandableListFragment) f).getExpandableListView()
|
ExpandableListAdapter ad = ((OsmandExpandableListFragment) f).getExpandableListView()
|
||||||
.getExpandableListAdapter();
|
.getExpandableListAdapter();
|
||||||
|
@ -533,6 +542,12 @@ public class DownloadActivity extends BaseDownloadActivity {
|
||||||
return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null;
|
return downloadListIndexThread != null ? downloadListIndexThread.getIndexFileNames() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<IndexItemCategoryWithSubcat> getCats() {
|
||||||
|
List<IndexItemCategoryWithSubcat> toReturn = cats;
|
||||||
|
cats = null;
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
public void showDialogToDownloadMaps(Collection<String> maps) {
|
public void showDialogToDownloadMaps(Collection<String> maps) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int sz = 0;
|
int sz = 0;
|
||||||
|
|
|
@ -1,17 +1,6 @@
|
||||||
package net.osmand.plus.download;
|
package net.osmand.plus.download;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.osmand.access.AccessibleToast;
|
|
||||||
import net.osmand.plus.R;
|
|
||||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
|
||||||
import net.osmand.plus.base.BasicProgressAsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
|
@ -31,6 +20,18 @@ import android.widget.ExpandableListAdapter;
|
||||||
import android.widget.ExpandableListView;
|
import android.widget.ExpandableListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.osmand.access.AccessibleToast;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||||
|
import net.osmand.plus.base.BasicProgressAsyncTask;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
public class DownloadIndexFragment extends OsmandExpandableListFragment {
|
||||||
|
|
||||||
|
|
|
@ -430,7 +430,7 @@ public class DownloadIndexesThread {
|
||||||
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download,
|
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download,
|
||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
if (uiActivity instanceof DownloadActivity) {
|
if (uiActivity instanceof DownloadActivity) {
|
||||||
((DownloadActivity) uiActivity).updateDownloadButton();
|
uiActivity.updateDownloadButton();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,14 @@ import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
public class NewLocalIndexesFragment extends OsmAndListFragment {
|
public class NewLocalIndexesFragment extends OsmAndListFragment {
|
||||||
private static final Log LOG = PlatformUtil.getLog(NewLocalIndexesFragment.class);
|
private static final Log LOG = PlatformUtil.getLog(NewLocalIndexesFragment.class);
|
||||||
|
public static final String CATEGORIES = "categories";
|
||||||
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
|
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
|
||||||
|
|
||||||
public static final int RELOAD_ID = 0;
|
public static final int RELOAD_ID = 0;
|
||||||
|
@ -55,6 +57,16 @@ public class NewLocalIndexesFragment extends OsmAndListFragment {
|
||||||
mAdapter = new CategoriesAdapter(getActivity(), getMyApplication());
|
mAdapter = new CategoriesAdapter(getActivity(), getMyApplication());
|
||||||
listView.setAdapter(mAdapter);
|
listView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
List<IndexItemCategoryWithSubcat> cats = ((DownloadActivity) getActivity()).getCats();
|
||||||
|
if (cats != null) {
|
||||||
|
onCategorizationFinished(null, cats);
|
||||||
|
}
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
List<IndexItemCategoryWithSubcat> savedCats =
|
||||||
|
savedInstanceState.getParcelableArrayList(CATEGORIES);
|
||||||
|
onCategorizationFinished(null, savedCats);
|
||||||
|
}
|
||||||
|
|
||||||
View header = inflater.inflate(R.layout.local_index_fragment_header, listView, false);
|
View header = inflater.inflate(R.layout.local_index_fragment_header, listView, false);
|
||||||
initMemoryConsumedCard(header);
|
initMemoryConsumedCard(header);
|
||||||
DownloadsUiInitHelper.initFreeVersionBanner(header, getMyApplication().getSettings(),
|
DownloadsUiInitHelper.initFreeVersionBanner(header, getMyApplication().getSettings(),
|
||||||
|
@ -102,6 +114,17 @@ public class NewLocalIndexesFragment extends OsmAndListFragment {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
LOG.debug("onSaveInstanceState()");
|
||||||
|
ArrayList<IndexItemCategoryWithSubcat> items = new ArrayList<>(mAdapter.getCount());
|
||||||
|
for (int i = 0; i < mAdapter.getCount(); i++) {
|
||||||
|
items.add(mAdapter.getItem(i));
|
||||||
|
}
|
||||||
|
outState.putParcelableArrayList(CATEGORIES, items);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
|
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
|
||||||
|
@ -115,9 +138,11 @@ public class NewLocalIndexesFragment extends OsmAndListFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCategorizationFinished(List<IndexItem> filtered, List<IndexItemCategoryWithSubcat> cats) {
|
public void onCategorizationFinished(List<IndexItem> filtered, List<IndexItemCategoryWithSubcat> cats) {
|
||||||
|
if (mAdapter != null) {
|
||||||
mAdapter.clear();
|
mAdapter.clear();
|
||||||
mAdapter.addAll(cats);
|
mAdapter.addAll(cats);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class CategoriesAdapter extends ArrayAdapter<IndexItemCategoryWithSubcat> {
|
private static class CategoriesAdapter extends ArrayAdapter<IndexItemCategoryWithSubcat> {
|
||||||
private final OsmandApplication osmandApplication;
|
private final OsmandApplication osmandApplication;
|
||||||
|
|
|
@ -15,7 +15,6 @@ import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -24,10 +23,7 @@ import net.osmand.plus.download.DownloadActivityType;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
import net.osmand.plus.helpers.HasName;
|
import net.osmand.plus.helpers.HasName;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
|
|
||||||
public class SubcategoriesFragment extends Fragment {
|
public class SubcategoriesFragment extends Fragment {
|
||||||
private static final Log LOG = PlatformUtil.getLog(SubcategoriesFragment.class);
|
|
||||||
private static final String CATEGORY = "category";
|
private static final String CATEGORY = "category";
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
Loading…
Reference in a new issue