[android] Updated UI.

This commit is contained in:
Dmitry Yunitsky 2015-07-31 18:06:23 +03:00 committed by Alex Zolotarev
parent 3f84362a84
commit 80d37ebc46
4 changed files with 59 additions and 41 deletions

View file

@ -0,0 +1,12 @@
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:gravity="center_vertical"
android:minHeight="@dimen/height_item_oneline"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Body1"
tools:text="/storage/mnt/"/>

View file

@ -0,0 +1,11 @@
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/height_item_oneline"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:textAppearance="@style/MwmTextAppearance.Body1"
tools:text="/storage/mnt/"/>

View file

@ -1,6 +1,7 @@
package com.mapswithme.maps.settings;
import android.app.Activity;
import android.support.annotation.LayoutRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -10,7 +11,6 @@ import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.util.Constants;
import com.mapswithme.util.Utils;
import java.util.ArrayList;
import java.util.List;
@ -25,10 +25,9 @@ class StoragePathAdapter extends BaseAdapter
private StoragePathManager mStoragePathManager;
private final LayoutInflater mInflater;
private final Activity mContext;
private final int mListItemHeight;
private List<StorageItem> mItems;
private int mCurrent = -1;
private int mCurrentStorageIndex = -1;
private long mSizeNeeded;
public StoragePathAdapter(StoragePathManager storagePathManager, Activity context)
@ -36,8 +35,6 @@ class StoragePathAdapter extends BaseAdapter
mStoragePathManager = storagePathManager;
mContext = context;
mInflater = mContext.getLayoutInflater();
mListItemHeight = (int) Utils.getAttributeDimension(context, android.R.attr.listPreferredItemHeight);
}
@Override
@ -61,7 +58,7 @@ class StoragePathAdapter extends BaseAdapter
@Override
public StorageItem getItem(int position)
{
return (position == 0 ? null : mItems.get(getIndexFromPos(position)));
return (getItemViewType(position) == TYPE_HEADER ? null : mItems.get(getStorageIndex(position)));
}
@Override
@ -70,50 +67,53 @@ class StoragePathAdapter extends BaseAdapter
return position;
}
@Override
public boolean isEnabled(int position)
{
return getItemViewType(position) == TYPE_ITEM;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// 1. It's a strange thing, but when I tried to use setClickable,
// all the views become nonclickable.
// 2. I call setMinimumHeight(listPreferredItemHeight)
// because standard item's height is unknown.
int viewType = getItemViewType(position);
if (convertView == null)
convertView = mInflater.inflate(getLayoutForType(viewType), parent, false);
switch (getItemViewType(position))
{
case TYPE_HEADER:
if (convertView == null)
{
convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
convertView.setMinimumHeight(mListItemHeight);
}
final TextView v = (TextView) convertView;
v.setText(mContext.getString(R.string.maps) + ": " + getSizeString(mSizeNeeded));
TextView view = (TextView) convertView;
view.setText(mContext.getString(R.string.maps) + ": " + getSizeString(mSizeNeeded));
break;
case TYPE_ITEM:
final int index = getIndexFromPos(position);
final StorageItem item = mItems.get(index);
int storageIndex = getStorageIndex(position);
StorageItem item = mItems.get(storageIndex);
if (convertView == null)
{
convertView = mInflater.inflate(android.R.layout.simple_list_item_single_choice, parent, false);
convertView.setMinimumHeight(mListItemHeight);
}
convertView = mInflater.inflate(R.layout.item_storage, parent, false);
final CheckedTextView ctv = (CheckedTextView) convertView;
ctv.setText(item.mPath + ": " + getSizeString(item.mSize));
ctv.setChecked(index == mCurrent);
ctv.setEnabled((index == mCurrent) || isAvailable(index));
CheckedTextView checkedView = (CheckedTextView) convertView;
checkedView.setText(item.mPath + ": " + getSizeString(item.mSize));
checkedView.setChecked(storageIndex == mCurrentStorageIndex);
checkedView.setEnabled(storageIndex == mCurrentStorageIndex || isStorageBigEnough(storageIndex));
break;
}
return convertView;
}
private
@LayoutRes
int getLayoutForType(int viewType)
{
return viewType == 0 ? R.layout.item_storage_title : R.layout.item_storage;
}
public void onItemClick(int position)
{
final int index = getIndexFromPos(position);
if (isAvailable(index))
final int index = getStorageIndex(position);
if (isStorageBigEnough(index) && index != mCurrentStorageIndex)
mStoragePathManager.onStorageItemClick(index);
}
@ -121,7 +121,7 @@ class StoragePathAdapter extends BaseAdapter
{
mSizeNeeded = dirSize;
mItems = items;
mCurrent = currentItemIndex;
mCurrentStorageIndex = currentItemIndex;
notifyDataSetChanged();
}
@ -145,17 +145,14 @@ class StoragePathAdapter extends BaseAdapter
return String.format("%.1f %s", (double) size / (double) current, arrS[i]);
}
private boolean isAvailable(int index)
private boolean isStorageBigEnough(int index)
{
assert (index >= 0 && index < mItems.size());
return ((mCurrent != index) && (mItems.get(index).mSize >= mSizeNeeded));
return mItems.get(index).mSize >= mSizeNeeded;
}
private int getIndexFromPos(int position)
private int getStorageIndex(int position)
{
final int index = position - HEADERS_COUNT;
assert (index >= 0 && index < mItems.size());
return index;
return position - HEADERS_COUNT;
}
public static class StorageItem

View file

@ -22,9 +22,7 @@ public class StoragePathFragment extends BaseMwmListFragment implements StorageP
@Override
public void onListItemClick(final ListView l, View v, final int position, long id)
{
// Do not process clicks on header items.
if (position != 0)
getAdapter().onItemClick(position);
getAdapter().onItemClick(position);
}
@Override