forked from organicmaps/organicmaps
Merge pull request #375 from trashkalmar/settings-ui-fixes
[android] fix: Settings UI fixes.
This commit is contained in:
commit
2c8ca21e05
18 changed files with 238 additions and 148 deletions
|
@ -208,17 +208,6 @@
|
|||
android:value="com.mapswithme.maps.MwmActivity"/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.mapswithme.maps.settings.StoragePathActivity"
|
||||
android:configChanges="orientation|screenLayout|screenSize"
|
||||
android:label="@string/maps_storage"
|
||||
android:parentActivityName="com.mapswithme.maps.MwmActivity">
|
||||
<!-- The meta-data element is needed for versions lower than 4.1 -->
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.mapswithme.maps.MwmActivity"/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity"
|
||||
android:configChanges="orientation|screenLayout|screenSize"
|
||||
|
|
14
android/res/layout/fragment_prefs_storage.xml
Normal file
14
android/res/layout/fragment_prefs_storage.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView android:id="@+id/header"
|
||||
style="@style/MwmWidget.TextView.Item"
|
||||
tools:text="/storage/mnt/"/>
|
||||
|
||||
<ListView android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
|
@ -2,5 +2,8 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
style="@style/MwmWidget.TextView.Item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/height_item_oneline"
|
||||
android:checkMark="?android:attr/listChoiceIndicatorSingle"
|
||||
tools:text="/storage/mnt/"/>
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<TextView xmlns:tools="http://schemas.android.com/tools"
|
||||
style="@style/MwmWidget.TextView.Item"
|
||||
tools:text="/storage/mnt/"/>
|
|
@ -15,7 +15,9 @@
|
|||
<SwitchPreference android:key="@string/pref_show_zoom_buttons"
|
||||
android:title="@string/pref_zoom_title"
|
||||
android:summary="@string/pref_zoom_summary"
|
||||
android:order="3"/>
|
||||
android:order="3"
|
||||
android:switchTextOn=""
|
||||
android:switchTextOff=""/>
|
||||
|
||||
<ListPreference android:key="@string/pref_map_style"
|
||||
android:title="@string/pref_map_style_title"
|
||||
|
|
|
@ -2,10 +2,14 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<SwitchPreference android:key="@string/pref_send_statistics"
|
||||
android:title="@string/allow_statistics"
|
||||
android:summary="@string/allow_statistics_hint"/>
|
||||
android:summary="@string/allow_statistics_hint"
|
||||
android:switchTextOn=""
|
||||
android:switchTextOff=""/>
|
||||
|
||||
<SwitchPreference android:key="@string/pref_play_services"
|
||||
android:title="Google Play Services"
|
||||
android:summary="@string/pref_use_google_play"
|
||||
android:defaultValue="true"/>
|
||||
android:defaultValue="true"
|
||||
android:switchTextOn=""
|
||||
android:switchTextOff=""/>
|
||||
</PreferenceScreen>
|
|
@ -40,18 +40,19 @@ public abstract class BaseMwmListFragment extends ListFragment
|
|||
return mToolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
org.alohalytics.Statistics.logEvent("$onResume", this.getClass().getSimpleName()
|
||||
+ ":" + com.mapswithme.util.UiUtils.deviceOrientationAsString(getActivity()));
|
||||
org.alohalytics.Statistics.logEvent("$onResume", getClass().getSimpleName() + ":" +
|
||||
UiUtils.deviceOrientationAsString(getActivity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
org.alohalytics.Statistics.logEvent("$onPause", this.getClass().getSimpleName());
|
||||
org.alohalytics.Statistics.logEvent("$onPause", getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public void navigateUpToParent()
|
||||
|
|
|
@ -34,7 +34,7 @@ public class AboutFragment extends BaseSettingsFragment
|
|||
@Override
|
||||
protected BaseShadowController createShadowController()
|
||||
{
|
||||
((View)mFrame.getParent()).setPadding(0, 0, 0, 0);
|
||||
clearPaddings();
|
||||
return new ScrollViewShadowController((ObservableScrollView)mFrame.findViewById(R.id.content_frame));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.settings;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.annotation.LayoutRes;
|
||||
|
@ -17,9 +18,27 @@ abstract class BaseSettingsFragment extends Fragment
|
|||
protected View mFrame;
|
||||
private BaseShadowController mShadowController;
|
||||
|
||||
private final Rect mSavedPaddings = new Rect();
|
||||
|
||||
protected abstract @LayoutRes int getLayoutRes();
|
||||
protected abstract BaseShadowController createShadowController();
|
||||
|
||||
private void savePaddings()
|
||||
{
|
||||
View parent = (View)mFrame.getParent();
|
||||
mSavedPaddings.set(parent.getPaddingLeft(), parent.getPaddingTop(), parent.getPaddingRight(), parent.getPaddingBottom());
|
||||
}
|
||||
|
||||
protected void clearPaddings()
|
||||
{
|
||||
((View)mFrame.getParent()).setPadding(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
protected void restorePaddings()
|
||||
{
|
||||
((View)mFrame.getParent()).setPadding(mSavedPaddings.left, mSavedPaddings.top, mSavedPaddings.right, mSavedPaddings.bottom);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
|
@ -33,8 +52,13 @@ abstract class BaseSettingsFragment extends Fragment
|
|||
{
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
savePaddings();
|
||||
if (((PreferenceActivity)getActivity()).onIsMultiPane())
|
||||
mShadowController = createShadowController().attach();
|
||||
{
|
||||
mShadowController = createShadowController();
|
||||
if (mShadowController != null)
|
||||
mShadowController.attach();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,10 +66,27 @@ abstract class BaseSettingsFragment extends Fragment
|
|||
{
|
||||
super.onDestroyView();
|
||||
|
||||
restorePaddings();
|
||||
if (mShadowController != null)
|
||||
mShadowController.detach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
org.alohalytics.Statistics.logEvent("$onResume", getClass().getSimpleName() + ":" +
|
||||
UiUtils.deviceOrientationAsString(getActivity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
org.alohalytics.Statistics.logEvent("$onPause", getClass().getSimpleName() + ":" +
|
||||
UiUtils.deviceOrientationAsString(getActivity()));
|
||||
}
|
||||
|
||||
protected static void adjustMargins(View view)
|
||||
{
|
||||
int margin = UiUtils.dimen(R.dimen.margin_half);
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.mapswithme.maps.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.annotation.XmlRes;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
abstract class BaseXmlSettingsFragment extends PreferenceFragment
|
||||
{
|
||||
protected abstract @XmlRes int getXmlResources();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(getXmlResources());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
org.alohalytics.Statistics.logEvent("$onResume", getClass().getSimpleName() + ":" +
|
||||
UiUtils.deviceOrientationAsString(getActivity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
org.alohalytics.Statistics.logEvent("$onPause", getClass().getSimpleName() + ":" +
|
||||
UiUtils.deviceOrientationAsString(getActivity()));
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ public class CopyrightFragment extends BaseSettingsFragment
|
|||
@Override
|
||||
protected BaseShadowController createShadowController()
|
||||
{
|
||||
clearPaddings();
|
||||
adjustMargins(mDelegate.getWebView());
|
||||
return new WebViewShadowController((ObservableWebView)mDelegate.getWebView());
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class HelpFragment extends BaseSettingsFragment
|
|||
@Override
|
||||
protected BaseShadowController createShadowController()
|
||||
{
|
||||
((View)mFrame.getParent()).setPadding(0, 0, 0, 0);
|
||||
clearPaddings();
|
||||
adjustMargins(mDelegate.getWebView());
|
||||
return new WebViewShadowController((ObservableWebView)mDelegate.getWebView())
|
||||
.addBottomShadow();
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.mapswithme.util.statistics.AlohaHelper;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class MapPrefsFragment extends PreferenceFragment
|
||||
public class MapPrefsFragment extends BaseXmlSettingsFragment
|
||||
{
|
||||
private final StoragePathManager mPathManager = new StoragePathManager();
|
||||
private Preference mStoragePref;
|
||||
|
@ -41,11 +41,16 @@ public class MapPrefsFragment extends PreferenceFragment
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getXmlResources()
|
||||
{
|
||||
return R.xml.prefs_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.prefs_map);
|
||||
|
||||
mStoragePref = findPreference(getString(R.string.pref_storage));
|
||||
updateStoragePrefs();
|
||||
|
@ -62,7 +67,7 @@ public class MapPrefsFragment extends PreferenceFragment
|
|||
.setPositiveButton(getString(R.string.ok), null)
|
||||
.show();
|
||||
else
|
||||
startActivity(new Intent(getActivity(), StoragePathActivity.class));
|
||||
((SettingsActivity)getActivity()).switchToFragment(StoragePathFragment.class, R.string.maps_storage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.mapswithme.maps.settings;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.SwitchPreference;
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
|
@ -11,13 +10,18 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.util.Config;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
public class MiscPrefsFragment extends PreferenceFragment
|
||||
public class MiscPrefsFragment extends BaseXmlSettingsFragment
|
||||
{
|
||||
@Override
|
||||
protected int getXmlResources()
|
||||
{
|
||||
return R.xml.prefs_misc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.prefs_misc);
|
||||
|
||||
Preference pref = findPreference(getString(R.string.pref_send_statistics));
|
||||
((SwitchPreference)pref).setChecked(Config.isStatisticsEnabled());
|
||||
|
|
|
@ -22,13 +22,16 @@ import com.mapswithme.util.ViewServer;
|
|||
import com.mapswithme.util.statistics.AlohaHelper;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SettingsActivity extends PreferenceActivity
|
||||
{
|
||||
private final FragmentListHelper mFragmentListHelper = new FragmentListHelper();
|
||||
private AppCompatDelegate mDelegate;
|
||||
private CharSequence mNextBreadcrumb;
|
||||
private final Map<Long, Header> mHeaders = new HashMap<>();
|
||||
|
||||
private AppCompatDelegate getDelegate()
|
||||
{
|
||||
|
@ -48,6 +51,10 @@ public class SettingsActivity extends PreferenceActivity
|
|||
public void onBuildHeaders(List<Header> target)
|
||||
{
|
||||
loadHeadersFromResource(R.xml.prefs_headers, target);
|
||||
|
||||
mHeaders.clear();
|
||||
for (Header h : target)
|
||||
mHeaders.put(h.id, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,7 +189,7 @@ public class SettingsActivity extends PreferenceActivity
|
|||
{
|
||||
super.onResume();
|
||||
|
||||
org.alohalytics.Statistics.logEvent("$onResume", this.getClass().getSimpleName());
|
||||
org.alohalytics.Statistics.logEvent("$onResume", getClass().getSimpleName());
|
||||
ViewServer.get(this).setFocusedWindow(this);
|
||||
}
|
||||
|
||||
|
@ -198,7 +205,7 @@ public class SettingsActivity extends PreferenceActivity
|
|||
{
|
||||
super.onPause();
|
||||
|
||||
org.alohalytics.Statistics.logEvent("$onPause", this.getClass().getSimpleName());
|
||||
org.alohalytics.Statistics.logEvent("$onPause", getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -235,7 +242,14 @@ public class SettingsActivity extends PreferenceActivity
|
|||
super.showBreadCrumbs(title, shortTitle);
|
||||
}
|
||||
|
||||
public void switchToFragment(Class<? extends Fragment> fragmentClass, @StringRes int breadcrumb)
|
||||
public void switchToHeader(long id)
|
||||
{
|
||||
Header h = mHeaders.get(id);
|
||||
if (h != null)
|
||||
switchToHeader(h);
|
||||
}
|
||||
|
||||
public void switchToFragment(Class<? extends BaseSettingsFragment> fragmentClass, @StringRes int breadcrumb)
|
||||
{
|
||||
mNextBreadcrumb = getString(breadcrumb);
|
||||
switchToHeader(fragmentClass.getName(), null);
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package com.mapswithme.maps.settings;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
|
||||
public class StoragePathActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
@Override
|
||||
protected Class<? extends Fragment> getFragmentClass()
|
||||
{
|
||||
return StoragePathFragment.class;
|
||||
}
|
||||
}
|
|
@ -1,28 +1,19 @@
|
|||
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;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.TextView;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.Constants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class StoragePathAdapter extends BaseAdapter
|
||||
{
|
||||
private static final int TYPE_HEADER = 0;
|
||||
private static final int TYPE_ITEM = 1;
|
||||
private static final int HEADERS_COUNT = 1;
|
||||
private static final int TYPES_COUNT = 2;
|
||||
|
||||
private StoragePathManager mStoragePathManager;
|
||||
private final LayoutInflater mInflater;
|
||||
private final Activity mContext;
|
||||
|
||||
private List<StorageItem> mItems;
|
||||
private int mCurrentStorageIndex = -1;
|
||||
|
@ -31,32 +22,19 @@ class StoragePathAdapter extends BaseAdapter
|
|||
public StoragePathAdapter(StoragePathManager storagePathManager, Activity context)
|
||||
{
|
||||
mStoragePathManager = storagePathManager;
|
||||
mContext = context;
|
||||
mInflater = mContext.getLayoutInflater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
return (position == 0 ? TYPE_HEADER : TYPE_ITEM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount()
|
||||
{
|
||||
return TYPES_COUNT;
|
||||
mInflater = context.getLayoutInflater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return (mItems != null ? mItems.size() + HEADERS_COUNT : HEADERS_COUNT);
|
||||
return (mItems == null ? 0 : mItems.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageItem getItem(int position)
|
||||
{
|
||||
return (getItemViewType(position) == TYPE_HEADER ? null : mItems.get(getStorageIndex(position)));
|
||||
return mItems.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,57 +43,28 @@ 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)
|
||||
{
|
||||
int viewType = getItemViewType(position);
|
||||
if (convertView == null)
|
||||
convertView = mInflater.inflate(getLayoutForType(viewType), parent, false);
|
||||
convertView = mInflater.inflate(R.layout.item_storage, parent, false);
|
||||
|
||||
switch (getItemViewType(position))
|
||||
{
|
||||
case TYPE_HEADER:
|
||||
TextView view = (TextView) convertView;
|
||||
view.setText(mContext.getString(R.string.maps) + ": " + getSizeString(mSizeNeeded));
|
||||
break;
|
||||
case TYPE_ITEM:
|
||||
int storageIndex = getStorageIndex(position);
|
||||
StorageItem item = mItems.get(storageIndex);
|
||||
|
||||
if (convertView == null)
|
||||
convertView = mInflater.inflate(R.layout.item_storage, parent, false);
|
||||
|
||||
CheckedTextView checkedView = (CheckedTextView) convertView;
|
||||
checkedView.setText(item.mPath + ": " + getSizeString(item.mFreeSize));
|
||||
checkedView.setChecked(storageIndex == mCurrentStorageIndex);
|
||||
checkedView.setEnabled(storageIndex == mCurrentStorageIndex || isStorageBigEnough(storageIndex));
|
||||
break;
|
||||
}
|
||||
StorageItem item = mItems.get(position);
|
||||
CheckedTextView checkedView = (CheckedTextView) convertView;
|
||||
checkedView.setText(item.mPath + ": " + StoragePathFragment.getSizeString(item.mFreeSize));
|
||||
checkedView.setChecked(position == mCurrentStorageIndex);
|
||||
checkedView.setEnabled(position == mCurrentStorageIndex || isStorageBigEnough(position));
|
||||
|
||||
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 = getStorageIndex(position);
|
||||
if (isStorageBigEnough(index) && index != mCurrentStorageIndex)
|
||||
mStoragePathManager.changeStorage(index);
|
||||
if (isStorageBigEnough(position) && position != mCurrentStorageIndex)
|
||||
mStoragePathManager.changeStorage(position);
|
||||
}
|
||||
|
||||
public void updateList(List<StorageItem> items, int currentItemIndex, long dirSize)
|
||||
public void update(List<StorageItem> items, int currentItemIndex, long dirSize)
|
||||
{
|
||||
mSizeNeeded = dirSize;
|
||||
mItems = items;
|
||||
|
@ -124,33 +73,8 @@ class StoragePathAdapter extends BaseAdapter
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private String getSizeString(long size)
|
||||
{
|
||||
final String arrS[] = {"Kb", "Mb", "Gb"};
|
||||
|
||||
long current = Constants.KB;
|
||||
int i = 0;
|
||||
for (; i < arrS.length; ++i)
|
||||
{
|
||||
final long bound = Constants.KB * current;
|
||||
if (size < bound)
|
||||
break;
|
||||
else
|
||||
current = bound;
|
||||
}
|
||||
|
||||
// left 1 digit after the comma and add postfix string
|
||||
return String.format("%.1f %s", (double) size / (double) current, arrS[i]);
|
||||
}
|
||||
|
||||
private boolean isStorageBigEnough(int index)
|
||||
{
|
||||
return mItems.get(index).mFreeSize >= mSizeNeeded;
|
||||
}
|
||||
|
||||
private int getStorageIndex(int position)
|
||||
{
|
||||
return position - HEADERS_COUNT;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,30 +2,61 @@ package com.mapswithme.maps.settings;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmListFragment;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.maps.widget.BaseShadowController;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StoragePathFragment extends BaseMwmListFragment
|
||||
implements StoragePathManager.MoveFilesListener
|
||||
public class StoragePathFragment extends BaseSettingsFragment
|
||||
implements StoragePathManager.MoveFilesListener,
|
||||
OnBackPressListener
|
||||
{
|
||||
private StoragePathManager mPathManager = new StoragePathManager();
|
||||
private StoragePathAdapter mAdapter;
|
||||
private TextView mHeader;
|
||||
private ListView mList;
|
||||
|
||||
private StoragePathAdapter getAdapter()
|
||||
private StoragePathAdapter mAdapter;
|
||||
private StoragePathManager mPathManager = new StoragePathManager();
|
||||
|
||||
@Override
|
||||
protected int getLayoutRes()
|
||||
{
|
||||
return (StoragePathAdapter) getListView().getAdapter();
|
||||
return R.layout.fragment_prefs_storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(final ListView l, View v, final int position, long id)
|
||||
protected BaseShadowController createShadowController()
|
||||
{
|
||||
getAdapter().onItemClick(position);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
mHeader = (TextView) mFrame.findViewById(R.id.header);
|
||||
mList = (ListView) mFrame.findViewById(R.id.list);
|
||||
mList.setOnItemClickListener(new AdapterView.OnItemClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
mAdapter.onItemClick(position);
|
||||
}
|
||||
});
|
||||
|
||||
return mFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,16 +68,15 @@ public class StoragePathFragment extends BaseMwmListFragment
|
|||
@Override
|
||||
public void onStorageListChanged(List<StorageItem> storageItems, int currentStorageIndex)
|
||||
{
|
||||
if (mAdapter != null)
|
||||
mAdapter.updateList(storageItems, currentStorageIndex, StorageUtils.getWritableDirSize());
|
||||
updateList();
|
||||
}
|
||||
}, this);
|
||||
|
||||
if (mAdapter == null)
|
||||
mAdapter = new StoragePathAdapter(mPathManager, getActivity());
|
||||
|
||||
mAdapter.updateList(mPathManager.getStorageItems(), mPathManager.getCurrentStorageIndex(), StorageUtils.getWritableDirSize());
|
||||
setListAdapter(mAdapter);
|
||||
updateList();
|
||||
mList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,10 +86,19 @@ public class StoragePathFragment extends BaseMwmListFragment
|
|||
mPathManager.stopExternalStorageWatching();
|
||||
}
|
||||
|
||||
private void updateList()
|
||||
{
|
||||
long dirSize = StorageUtils.getWritableDirSize();
|
||||
mHeader.setText(getString(R.string.maps) + ": " + getSizeString(dirSize));
|
||||
|
||||
if (mAdapter != null)
|
||||
mAdapter.update(mPathManager.getStorageItems(), mPathManager.getCurrentStorageIndex(), dirSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveFilesFinished(String newPath)
|
||||
{
|
||||
mAdapter.updateList(mPathManager.getStorageItems(), mPathManager.getCurrentStorageIndex(), StorageUtils.getWritableDirSize());
|
||||
updateList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,4 +123,36 @@ public class StoragePathFragment extends BaseMwmListFragment
|
|||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
static String getSizeString(long size)
|
||||
{
|
||||
final String units[] = { "Kb", "Mb", "Gb" };
|
||||
|
||||
long current = Constants.KB;
|
||||
int i = 0;
|
||||
for (; i < units.length; ++i)
|
||||
{
|
||||
final long bound = Constants.KB * current;
|
||||
if (size < bound)
|
||||
break;
|
||||
|
||||
current = bound;
|
||||
}
|
||||
|
||||
// left 1 digit after the comma and add postfix string
|
||||
return String.format("%.1f %s", (double) size / current, units[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed()
|
||||
{
|
||||
SettingsActivity activity = (SettingsActivity)getActivity();
|
||||
if (activity.onIsMultiPane())
|
||||
{
|
||||
activity.switchToHeader(R.id.group_map);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue