Request fixes.

This commit is contained in:
Dmitry Yunitsky 2014-09-29 14:04:14 +03:00 committed by Alex Zolotarev
parent 70ac990acd
commit 829212b811
7 changed files with 90 additions and 59 deletions

View file

@ -11,6 +11,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/margin_small"
android:textAppearance="@style/Holo.TextAppearance.Large.Light"/>
<ImageView

View file

@ -14,7 +14,6 @@ import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
@ -36,6 +35,8 @@ import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.view.ViewHelper;
import java.lang.ref.WeakReference;
abstract class BaseDownloadAdapter extends BaseAdapter
{
static final int TYPE_GROUP = 0;
@ -51,17 +52,34 @@ abstract class BaseDownloadAdapter extends BaseAdapter
public static final String PROPERTY_X = "x";
private static final long ANIMATION_LENGTH = 250;
private Handler mHandler = new Handler();
private Runnable mDatasetChangedRunnable = new Runnable()
private static class SafeAdapterRunnable implements Runnable
{
private WeakReference<BaseDownloadAdapter> mAdapterReference;
public SafeAdapterRunnable(BaseDownloadAdapter adapter)
{
mAdapterReference = new WeakReference<BaseDownloadAdapter>(adapter);
}
@Override
public void run()
{
if (mActiveAnimationsCount == 0)
notifyDataSetChanged();
if (mAdapterReference == null)
return;
final BaseDownloadAdapter adapter = mAdapterReference.get();
if (adapter == null)
return;
if (adapter.mActiveAnimationsCount == 0)
adapter.notifyDataSetChanged();
else
mHandler.postDelayed(this, ANIMATION_LENGTH);
adapter.mHandler.postDelayed(this, ANIMATION_LENGTH);
}
};
}
private SafeAdapterRunnable mDatasetChangedRunnable = new SafeAdapterRunnable(this);
protected final LayoutInflater mInflater;
protected final Activity mActivity;
@ -81,9 +99,8 @@ abstract class BaseDownloadAdapter extends BaseAdapter
mHasGoogleStore = Utils.hasAnyGoogleStoreInstalled();
mStatusDownloaded = mActivity.getString(R.string.downloader_downloaded).toUpperCase();
// FIXME
mStatusFailed = "failed";
mStatusOutdated = "outdated";
mStatusFailed = mActivity.getString(R.string.downloader_status_failed).toUpperCase();
mStatusOutdated = mActivity.getString(R.string.downloader_status_outdated).toUpperCase();
mStatusNotDownloaded = mActivity.getString(R.string.download).toUpperCase();
}
@ -95,6 +112,7 @@ abstract class BaseDownloadAdapter extends BaseAdapter
protected void showNotEnoughFreeSpaceDialog(String spaceNeeded, String countryName)
{
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.NO_FREE_SPACE);
final Dialog dlg = new AlertDialog.Builder(mActivity)
.setMessage(String.format(mActivity.getString(R.string.free_space_for_country), spaceNeeded, countryName))
.setNegativeButton(mActivity.getString(R.string.close), new DialogInterface.OnClickListener()
@ -213,7 +231,10 @@ abstract class BaseDownloadAdapter extends BaseAdapter
@Override
public int getItemViewType(int position)
{
return getItem(position).getType();
final CountryItem item = getItem(position);
if (item != null)
return item.getType();
return TYPE_GROUP;
}
@Override
@ -241,6 +262,8 @@ abstract class BaseDownloadAdapter extends BaseAdapter
private LinearLayout mInfoSlided;
private WheelProgressView mProgressSlided;
private Animator animator;
void initFromView(View v)
{
mName = (TextView) v.findViewById(R.id.title);
@ -261,29 +284,6 @@ abstract class BaseDownloadAdapter extends BaseAdapter
return mActivity.getString(strID, getSizeString(MapStorage.INSTANCE.countryRemoteSizeInBytes(index)));
}
protected void bindFlag(int position, ImageView v)
{
final String strID = getItem(position).mFlag;
int id;
try
{
// works faster than 'getIdentifier()'
id = R.drawable.class.getField(strID).getInt(null);
if (id > 0)
{
v.setImageResource(id);
v.setVisibility(View.VISIBLE);
}
else
v.setVisibility(View.GONE);
} catch (final Exception e)
{
v.setVisibility(View.GONE);
}
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
@ -300,6 +300,12 @@ abstract class BaseDownloadAdapter extends BaseAdapter
else
holder = (ViewHolder) convertView.getTag();
if (holder.animator != null)
{
holder.animator.end();
holder.animator = null;
}
switch (type)
{
case TYPE_GROUP:
@ -352,15 +358,18 @@ abstract class BaseDownloadAdapter extends BaseAdapter
return 0;
}
protected void bindCountry(int position, int type, BaseDownloadAdapter.ViewHolder holder)
protected void bindCountry(int position, int type, ViewHolder holder)
{
bindFlag(position, holder.mFlag);
bindSizeAndProgress(holder, type, position);
}
protected void bindSizeAndProgress(final BaseDownloadAdapter.ViewHolder holder, final int type, final int position)
protected void bindSizeAndProgress(final ViewHolder holder, final int type, final int position)
{
final CountryItem item = getItem(position);
if (item == null)
return;
if (holder.mSize != null)
setHolderSizeString(holder, MapStorage.INSTANCE.countryRemoteSizeInBytes(item.mCountryIdx));
@ -368,7 +377,7 @@ abstract class BaseDownloadAdapter extends BaseAdapter
ViewHelper.setTranslationX(holder.mInfo, 0);
ViewHelper.setTranslationX(holder.mProgress, 0);
ViewHelper.setTranslationX(holder.mProgressSlided, 0);
switch (getItem(position).getStatus())
switch (item.getStatus())
{
case MapStorage.DOWNLOADING:
holder.mProgress.setVisibility(View.GONE);
@ -498,6 +507,8 @@ abstract class BaseDownloadAdapter extends BaseAdapter
public void onAnimationEnd(Animator animation)
{
final CountryItem item = getItem(position);
if (item == null)
return;
if (item.getStatus() == MapStorage.ON_DISK_OUT_OF_DATE)
processOutOfDate(item.mCountryIdx, item.mName);
else
@ -511,6 +522,7 @@ abstract class BaseDownloadAdapter extends BaseAdapter
});
mActiveAnimationsCount++;
animatorSet.start();
holder.animator = animatorSet;
holder.mProgress.setVisibility(View.VISIBLE);
}
@ -532,16 +544,21 @@ abstract class BaseDownloadAdapter extends BaseAdapter
@Override
public void onAnimationEnd(Animator animation)
{
final CountryItem item = getItem(position);
if (item == null)
return;
holder.mInfo.setVisibility(View.VISIBLE);
holder.mInfoSlided.setVisibility(View.GONE);
holder.mProgressSlided.setVisibility(View.GONE);
holder.mProgress.setVisibility(View.GONE);
MapStorage.INSTANCE.deleteCountry(getItem(position).mCountryIdx);
MapStorage.INSTANCE.deleteCountry(item.mCountryIdx);
mActiveAnimationsCount--;
}
});
mActiveAnimationsCount++;
animatorSet.start();
holder.animator = animatorSet;
}
@Override
@ -574,6 +591,9 @@ abstract class BaseDownloadAdapter extends BaseAdapter
{
// set name and style
final CountryItem item = getItem(position);
if (item == null)
return;
holder.mName.setText(item.mName);
holder.mName.setTypeface(item.getTypeface());
holder.mName.setTextColor(item.getTextColor());
@ -588,13 +608,14 @@ abstract class BaseDownloadAdapter extends BaseAdapter
public int onCountryStatusChanged(Index idx)
{
final int position = getItemPosition(idx);
if (position != -1)
final CountryItem item = getItem(position);
if (position != -1 && item != null)
{
getItem(position).updateStatus();
item.updateStatus();
// use this hard reset, because of caching different ViewHolders according to item's type
mHandler.postDelayed(mDatasetChangedRunnable, ANIMATION_LENGTH);
return getItem(position).getStatus();
return item.getStatus();
}
return MapStorage.UNKNOWN;
}
@ -628,6 +649,9 @@ abstract class BaseDownloadAdapter extends BaseAdapter
protected void onCountryMenuClicked(final CountryItem countryItem, final View anchor)
{
if (countryItem == null)
return;
final int MENU_DELETE = 0;
final int MENU_UPDATE = 1;
final int MENU_DOWNLOAD = 2;

View file

@ -63,6 +63,7 @@ public class CountryItem
{
case MapStorage.NOT_DOWNLOADED:
case MapStorage.DOWNLOADING:
case MapStorage.IN_QUEUE:
case MapStorage.DOWNLOAD_FAILED:
return LIGHT;
default:

View file

@ -40,13 +40,16 @@ class DownloadAdapter extends BaseDownloadAdapter
if (position >= getCount())
return; // we have reports at GP that it crashes.
if (getItem(position).getStatus() < 0)
final CountryItem item = getItem(position);
if (item == null)
return;
if (item.getStatus() < 0)
{
// expand next level
expandGroup(position);
}
else
onCountryMenuClicked(getItem(position), view);
onCountryMenuClicked(item, view);
}
@Override

View file

@ -11,6 +11,8 @@ import com.mapswithme.maps.R;
public class DownloadedAdapter extends BaseDownloadAdapter
{
private static final int TYPE_HEADER = 5;
private static final int VIEW_TYPE_COUNT = 6;
private static final int INVALID_POSITION = -1;
private int mDownloadedCount;
private int mOutdatedCount;
@ -57,11 +59,10 @@ public class DownloadedAdapter extends BaseDownloadAdapter
view = convertView;
holder = (ViewHolder) view.getTag();
}
// TODO add strings
if (containsOutdated() && position == 0)
holder.mName.setText("OUT OF DATE");
holder.mName.setText(mActivity.getString(R.string.downloader_outdated_maps));
else
holder.mName.setText("UPDATED");
holder.mName.setText(mActivity.getString(R.string.downloader_uptodate_maps));
return view;
}
@ -69,7 +70,7 @@ public class DownloadedAdapter extends BaseDownloadAdapter
{
final View view = super.getView(position, convertView, parent);
final ViewHolder holder = (ViewHolder) view.getTag();
if (getOutdatedPosition(position) == -1)
if (getOutdatedPosition(position) == INVALID_POSITION)
holder.mPercent.setVisibility(View.GONE);
else
holder.mPercent.setVisibility(View.VISIBLE);
@ -92,7 +93,7 @@ public class DownloadedAdapter extends BaseDownloadAdapter
return null;
int correctedPosition = getOutdatedPosition(position);
if (correctedPosition != -1)
if (correctedPosition != INVALID_POSITION)
return new CountryItem(MapStorage.INSTANCE.getOutdatedCountry(correctedPosition));
correctedPosition = getDownloadedPosition(position);
@ -118,7 +119,7 @@ public class DownloadedAdapter extends BaseDownloadAdapter
@Override
public int getViewTypeCount()
{
return 6;
return VIEW_TYPE_COUNT;
}
@Override
@ -130,7 +131,7 @@ public class DownloadedAdapter extends BaseDownloadAdapter
@Override
protected int getItemPosition(MapStorage.Index idx)
{
return -1;
return INVALID_POSITION;
}
@Override
@ -148,24 +149,24 @@ public class DownloadedAdapter extends BaseDownloadAdapter
protected int getOutdatedPosition(int position)
{
if (!containsOutdated())
return -1;
return INVALID_POSITION;
if (position <= mOutdatedCount)
return position - 1;
return -1;
return INVALID_POSITION;
}
protected int getDownloadedPosition(int position)
{
if (!containsDownloaded())
return -1;
return INVALID_POSITION;
final int startNum = 1 + (containsOutdated() ? mOutdatedCount + 1 : 0);
if (position >= startNum && position < startNum + mDownloadedCount)
return position - 1 - (containsOutdated() ? mOutdatedCount + 1 : 0);
return -1;
return INVALID_POSITION;
}
protected boolean containsOutdated()

View file

@ -88,12 +88,12 @@ public class WheelProgressView extends View
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
int left = getPaddingLeft();
int top = getPaddingTop();
int right = w - getPaddingRight();
int bottom = h - getPaddingBottom();
int width = right - left;
int height = bottom - top;
final int left = getPaddingLeft();
final int top = getPaddingTop();
final int right = w - getPaddingRight();
final int bottom = h - getPaddingBottom();
final int width = right - left;
final int height = bottom - top;
mRadius = (Math.min(width, height) - mStrokeWidth) / 2;
mCenter = new PointF(left + width / 2, top + height / 2);

View file

@ -63,6 +63,7 @@ public enum Statistics
public static final String SEARCH_KEY_CLICKED = "Search key pressed.";
public static final String SEARCH_ON_MAP_CLICKED = "Search on map clicked.";
public static final String STATISTICS_STATUS_CHANGED = "Statistics status changed";
public static final String NO_FREE_SPACE = "Downloader. Not enough free space.";
}
public static class EventParam