Fixed bug with "failed" countries.

This commit is contained in:
Dmitry Yunitsky 2014-10-13 19:25:07 +03:00 committed by Alex Zolotarev
parent 3d1f43fffd
commit 3bbc70e58d
4 changed files with 19 additions and 39 deletions

View file

@ -75,7 +75,7 @@ abstract class BaseDownloadAdapter extends BaseAdapter
return;
if (adapter.mActiveAnimationsCount == 0)
adapter.fillList();
adapter.notifyDataSetChanged();
else
adapter.mHandler.postDelayed(this, ANIMATION_LENGTH);
}
@ -105,8 +105,6 @@ abstract class BaseDownloadAdapter extends BaseAdapter
mStatusNotDownloaded = mActivity.getString(R.string.download).toUpperCase();
}
protected abstract void fillList();
public abstract void onItemClick(int position, View view);
protected abstract void expandGroup(int position);
@ -391,7 +389,7 @@ abstract class BaseDownloadAdapter extends BaseAdapter
bindCarRoutingIcon(holder, item);
sizes = getItemSizes(position, StorageOptions.MAP_OPTION_MAP_AND_CAR_ROUTING);
if(item.getOptions() == StorageOptions.MAP_OPTION_MAP_ONLY)
if (item.getOptions() == StorageOptions.MAP_OPTION_MAP_ONLY)
setHolderSizeString(holder, 0, sizes[0]);
else
setHolderSizeString(holder, 0, sizes[1]);
@ -611,6 +609,9 @@ abstract class BaseDownloadAdapter extends BaseAdapter
{
// use this hard reset, because of caching different ViewHolders according to item's type
mHandler.postDelayed(mDatasetChangedRunnable, ANIMATION_LENGTH);
if (item.getStatus() == MapStorage.DOWNLOAD_FAILED)
UiUtils.checkConnectionAndShowAlert(mActivity, String.format(mActivity.getString(R.string.download_country_failed), item.getName()));
}
}
@ -733,9 +734,9 @@ abstract class BaseDownloadAdapter extends BaseAdapter
if (status == MapStorage.ON_DISK && options == StorageOptions.MAP_OPTION_MAP_ONLY)
{
String titleShow = mActivity.getString(R.string.downloader_download_routing);
// TODO add size
menu.add(0, MENU_DOWNLOAD_ROUTING, MENU_DOWNLOAD_ROUTING, titleShow).setOnMenuItemClickListener(menuItemClickListener);
String titleShow = mActivity.getString(R.string.downloader_download_routing);
// TODO add size
menu.add(0, MENU_DOWNLOAD_ROUTING, MENU_DOWNLOAD_ROUTING, titleShow).setOnMenuItemClickListener(menuItemClickListener);
}
if (status == MapStorage.ON_DISK_OUT_OF_DATE)

View file

@ -106,4 +106,10 @@ public class CountryItem
return DownloadAdapter.TYPE_COUNTRY_IN_PROCESS;
}
}
@Override
public String toString()
{
return "Name : " + mName + "; options : " + mOptions + "; status : " + mStatus + "; has children : " + mHasChildren;
}
}

View file

@ -7,32 +7,10 @@ import com.mapswithme.maps.guides.GuideInfo;
class DownloadAdapter extends BaseDownloadAdapter implements CountryTree.CountryTreeListener
{
protected CountryItem[] mItems;
public DownloadAdapter(Activity activity)
{
super(activity);
CountryTree.setDefaultRoot();
fillList();
}
/**
* Get items from native and notify dataset changes.
*/
protected void fillList()
{
final int count = CountryTree.getChildCount();
if (count > 0)
{
mItems = new CountryItem[count];
for (int i = 0; i < count; ++i)
{
mItems[i] = new CountryItem(CountryTree.getChildName(i), CountryTree.getLeafStatus(i),
CountryTree.getLeafOptions(i), !CountryTree.isLeaf(i));
}
}
notifyDataSetChanged();
}
@Override
@ -54,13 +32,14 @@ class DownloadAdapter extends BaseDownloadAdapter implements CountryTree.Country
@Override
public int getCount()
{
return (mItems != null ? mItems.length : 0);
return CountryTree.getChildCount();
}
@Override
public CountryItem getItem(int position)
{
return mItems[position];
return new CountryItem(CountryTree.getChildName(position), CountryTree.getLeafStatus(position),
CountryTree.getLeafOptions(position), !CountryTree.isLeaf(position));
}
@Override
@ -74,7 +53,7 @@ class DownloadAdapter extends BaseDownloadAdapter implements CountryTree.Country
protected void expandGroup(int position)
{
CountryTree.setChildAsRoot(position);
fillList();
notifyDataSetChanged();
}
@Override
@ -84,7 +63,7 @@ class DownloadAdapter extends BaseDownloadAdapter implements CountryTree.Country
return false;
CountryTree.setParentAsRoot();
fillList();
notifyDataSetChanged();
return true;
}

View file

@ -149,12 +149,6 @@ public class DownloadedAdapter extends BaseDownloadAdapter implements ActiveCoun
return mInProgressCount != 0;
}
@Override
protected void fillList()
{
notifyDataSetChanged();
}
private int getGroupByAbsPosition(int position)
{
final int newGroupEnd = mInProgressCount;