forked from organicmaps/organicmaps-tmp
[bookmarks][android] Choose sorting type.
This commit is contained in:
parent
5926dacf2f
commit
94e1aff644
5 changed files with 246 additions and 8 deletions
67
android/res/layout/dialog_sorting_types.xml
Normal file
67
android/res/layout/dialog_sorting_types.xml
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/margin_double_and_half"
|
||||
android:padding="@dimen/margin_base_plus"
|
||||
android:minWidth="@dimen/dialog_min_width"
|
||||
android:minHeight="@dimen/dialog_min_height">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/margin_quarter"
|
||||
android:textAppearance="@android:style/TextAppearance.DialogWindowTitle"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:text="Sort_bookmarks"/>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/sorting_types"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_base">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/sort_by_default"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.Theme"
|
||||
android:padding="@dimen/margin_half_plus"
|
||||
android:checked="true"
|
||||
android:text="by_default"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/sort_by_type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.Theme"
|
||||
android:padding="@dimen/margin_half_plus"
|
||||
android:checked="false"
|
||||
android:text="by_type"
|
||||
tools:visibility="gone"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/sort_by_distance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.Theme"
|
||||
android:padding="@dimen/margin_half_plus"
|
||||
android:checked="false"
|
||||
android:text="by_distance"
|
||||
tools:visibility="gone"/>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/sort_by_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.Theme"
|
||||
android:padding="@dimen/margin_half_plus"
|
||||
android:checked="false"
|
||||
android:text="by_time"
|
||||
tools:visibility="gone"/>
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
|
@ -35,6 +35,7 @@
|
|||
<dimen name="primary_button_min_height">36dp</dimen>
|
||||
<dimen name="primary_button_min_width">64dp</dimen>
|
||||
<dimen name="dialog_min_width">288dp</dimen>
|
||||
<dimen name="dialog_min_height">100dp</dimen>
|
||||
<dimen name="default_elevation">2dp</dimen>
|
||||
|
||||
<dimen name="dialog_max_height">320dp</dimen>
|
||||
|
|
|
@ -380,13 +380,13 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
|
|||
return new SectionPosition(SectionPosition.INVALID_POSITION, SectionPosition.INVALID_POSITION);
|
||||
}
|
||||
|
||||
public void setSearchResults(List<Long> searchResults)
|
||||
public void setSearchResults(@Nullable List<Long> searchResults)
|
||||
{
|
||||
mSearchResults = searchResults;
|
||||
refreshSections();
|
||||
}
|
||||
|
||||
public void setSortedResults(List<SortedBlock> sortedResults)
|
||||
public void setSortedResults(@Nullable List<SortedBlock> sortedResults)
|
||||
{
|
||||
mSortedResults = sortedResults;
|
||||
refreshSections();
|
||||
|
|
|
@ -56,7 +56,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
MenuItem.OnMenuItemClickListener,
|
||||
BookmarkManager.BookmarksSharingListener,
|
||||
BookmarkManager.BookmarksSortingListener,
|
||||
NativeBookmarkSearchListener
|
||||
NativeBookmarkSearchListener,
|
||||
ChooseBookmarksSortingTypeFragment.ChooseSortingTypeListener
|
||||
{
|
||||
public static final String TAG = BookmarksListFragment.class.getSimpleName();
|
||||
public static final String EXTRA_CATEGORY = "bookmark_category";
|
||||
|
@ -388,16 +389,42 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
SharingHelper.INSTANCE.onPreparedFileForSharing(getActivity(), result);
|
||||
}
|
||||
|
||||
public void onResetSorting()
|
||||
{
|
||||
mLastSortTimestamp = 0;
|
||||
long catId = getCategoryOrThrow().getId();
|
||||
BookmarkManager.INSTANCE.resetLastSortingType(catId);
|
||||
|
||||
BookmarkListAdapter adapter = getAdapter();
|
||||
adapter.setSortedResults(null);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void onSort(@BookmarkManager.SortingType int sortingType)
|
||||
{
|
||||
mLastSortTimestamp = System.nanoTime();
|
||||
long catId = getCategoryOrThrow().getId();
|
||||
BookmarkManager.INSTANCE.setLastSortingType(catId, sortingType);
|
||||
BookmarkManager.INSTANCE.getSortedBookmarks(catId, sortingType,
|
||||
false, 0, 0, mLastSortTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem menuItem)
|
||||
{
|
||||
switch (menuItem.getItemId())
|
||||
{
|
||||
case R.id.sort:
|
||||
mLastSortTimestamp = System.nanoTime();
|
||||
BookmarkManager.INSTANCE.getSortedBookmarks(
|
||||
getCategoryOrThrow().getId(), BookmarkManager.SORT_BY_TYPE,
|
||||
false, 0, 0, mLastSortTimestamp);
|
||||
long catId = getCategoryOrThrow().getId();
|
||||
@BookmarkManager.SortingType int[] types =
|
||||
BookmarkManager.INSTANCE.getAvailableSortingTypes(catId, false);
|
||||
int currentType = -1;
|
||||
if (BookmarkManager.INSTANCE.hasLastSortingType(catId))
|
||||
currentType = (int)BookmarkManager.INSTANCE.getLastSortingType(catId);
|
||||
|
||||
ChooseBookmarksSortingTypeFragment.chooseSortingType(types, currentType, this,
|
||||
getActivity(),
|
||||
getChildFragmentManager());
|
||||
return false;
|
||||
case R.id.sharing_options:
|
||||
return false;
|
||||
|
@ -452,7 +479,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
public void onPrepareOptionsMenu(Menu menu)
|
||||
{
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
//menu.setGroupVisible(0, false);
|
||||
final boolean visible = !isSearchMode();
|
||||
MenuItem itemSearch = menu.findItem(R.id.bookmarks_search);
|
||||
itemSearch.setVisible(visible);
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class ChooseBookmarksSortingTypeFragment extends BaseMwmDialogFragment
|
||||
implements RadioGroup.OnCheckedChangeListener
|
||||
{
|
||||
private static final String EXTRA_SORTING_TYPES = "sorting_types";
|
||||
private static final String EXTRA_CURRENT_SORT_TYPE = "current_sort_type";
|
||||
|
||||
@Nullable
|
||||
ChooseSortingTypeListener mListener;
|
||||
|
||||
public interface ChooseSortingTypeListener
|
||||
{
|
||||
void onResetSorting();
|
||||
void onSort(@BookmarkManager.SortingType int sortingType);
|
||||
}
|
||||
|
||||
public void setChooseSortingTypeListener(@Nullable ChooseSortingTypeListener listener)
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public static void chooseSortingType(@NonNull @BookmarkManager.SortingType int[] availableTypes,
|
||||
int currentType, @NonNull ChooseSortingTypeListener listener,
|
||||
@NonNull Context context,
|
||||
@NonNull FragmentManager manager)
|
||||
{
|
||||
Bundle args = new Bundle();
|
||||
args.putIntArray(EXTRA_SORTING_TYPES, availableTypes);
|
||||
args.putInt(EXTRA_CURRENT_SORT_TYPE, currentType);
|
||||
String name = ChooseBookmarksSortingTypeFragment.class.getName();
|
||||
final ChooseBookmarksSortingTypeFragment fragment =
|
||||
(ChooseBookmarksSortingTypeFragment) Fragment.instantiate(context, name, args);
|
||||
fragment.setArguments(args);
|
||||
fragment.setChooseSortingTypeListener(listener);
|
||||
fragment.show(manager, name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.dialog_sorting_types, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getStyle()
|
||||
{
|
||||
return STYLE_NO_TITLE;
|
||||
}
|
||||
|
||||
private int getViewId(int sortingType)
|
||||
{
|
||||
if (sortingType >= 0)
|
||||
{
|
||||
switch (sortingType)
|
||||
{
|
||||
case BookmarkManager.SORT_BY_TYPE:
|
||||
return R.id.sort_by_type;
|
||||
case BookmarkManager.SORT_BY_DISTANCE:
|
||||
return R.id.sort_by_distance;
|
||||
case BookmarkManager.SORT_BY_TIME:
|
||||
return R.id.sort_by_time;
|
||||
}
|
||||
}
|
||||
return R.id.sort_by_default;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
final Bundle args = getArguments();
|
||||
|
||||
UiUtils.hide(view.findViewById(R.id.sort_by_type));
|
||||
UiUtils.hide(view.findViewById(R.id.sort_by_distance));
|
||||
UiUtils.hide(view.findViewById(R.id.sort_by_time));
|
||||
|
||||
@BookmarkManager.SortingType
|
||||
int[] availableSortingTypes = args.getIntArray(EXTRA_SORTING_TYPES);
|
||||
for (int i = 0; i < availableSortingTypes.length; ++i)
|
||||
UiUtils.show(view.findViewById(getViewId(availableSortingTypes[i])));
|
||||
|
||||
int currentType = args.getInt(EXTRA_CURRENT_SORT_TYPE);
|
||||
|
||||
RadioGroup radioGroup = view.findViewById(R.id.sorting_types);
|
||||
radioGroup.clearCheck();
|
||||
radioGroup.check(getViewId(currentType));
|
||||
radioGroup.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
||||
private void resetSorting()
|
||||
{
|
||||
if (mListener != null)
|
||||
mListener.onResetSorting();
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private void setSortingType(@BookmarkManager.SortingType int sortingType)
|
||||
{
|
||||
if (mListener != null)
|
||||
mListener.onSort(sortingType);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case R.id.sort_by_default:
|
||||
resetSorting();
|
||||
break;
|
||||
case R.id.sort_by_type:
|
||||
setSortingType(BookmarkManager.SORT_BY_TYPE);
|
||||
break;
|
||||
case R.id.sort_by_distance:
|
||||
setSortingType(BookmarkManager.SORT_BY_DISTANCE);
|
||||
break;
|
||||
case R.id.sort_by_time:
|
||||
setSortingType(BookmarkManager.SORT_BY_TIME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue