[android] Added catalog fragment and adapter , modified bottom menu on main screen [non compiled]
|
@ -1 +1 @@
|
|||
Subproject commit 28653c5fe6cefd7d83502140f9e14a8b60c34f81
|
||||
Subproject commit ef8e5ad5ba7854c4bada9815716f7bb0b59240bf
|
|
@ -106,6 +106,7 @@ dependencies {
|
|||
exclude group: 'com.android.support'
|
||||
exclude group: 'com.google.android.gms'
|
||||
}
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
|
||||
}
|
||||
|
||||
def getDate() {
|
||||
|
|
BIN
android/res/drawable-hdpi/bookmark_disabled.png
Normal file
After Width: | Height: | Size: 411 B |
BIN
android/res/drawable-hdpi/ic_clear.png
Executable file
After Width: | Height: | Size: 324 B |
BIN
android/res/drawable-hdpi/img_empty_bookmarks.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
android/res/drawable-mdpi/bookmark_disabled.png
Normal file
After Width: | Height: | Size: 307 B |
BIN
android/res/drawable-mdpi/ic_clear.png
Executable file
After Width: | Height: | Size: 232 B |
BIN
android/res/drawable-mdpi/img_empty_bookmarks.png
Normal file
After Width: | Height: | Size: 9.3 KiB |
BIN
android/res/drawable-xhdpi/bookmark_disabled.png
Normal file
After Width: | Height: | Size: 530 B |
BIN
android/res/drawable-xhdpi/ic_clear.png
Executable file
After Width: | Height: | Size: 397 B |
BIN
android/res/drawable-xhdpi/img_empty_bookmarks.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
android/res/drawable-xxhdpi/bookmark_disabled.png
Normal file
After Width: | Height: | Size: 768 B |
BIN
android/res/drawable-xxhdpi/ic_clear.png
Executable file
After Width: | Height: | Size: 570 B |
BIN
android/res/drawable-xxhdpi/img_empty_bookmarks.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
android/res/drawable-xxxhdpi/bookmark_disabled.png
Normal file
After Width: | Height: | Size: 1,000 B |
BIN
android/res/drawable-xxxhdpi/ic_clear.png
Executable file
After Width: | Height: | Size: 767 B |
BIN
android/res/drawable-xxxhdpi/img_empty_bookmarks.png
Normal file
After Width: | Height: | Size: 29 KiB |
14
android/res/layout/bookmarks_activity.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
layout="@layout/non_elevated_toolbar"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
112
android/res/layout/fragment_catalog_bookmark_categories.xml
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:mapsme="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:fillViewport="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<RelativeLayout
|
||||
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">
|
||||
<LinearLayout
|
||||
android:id="@+id/cached_bookmarks_payload_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:id="@+id/header"
|
||||
android:background="?cardBackground"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingBottom="@dimen/margin_half_plus"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/header_title"
|
||||
android:text="@string/cached_bookmarks_placeholder_title"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingTop="@dimen/margin_half_plus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
mapsme:layout_constraintLeft_toLeftOf="parent"/>
|
||||
<TextView
|
||||
android:id="@+id/header_description"
|
||||
android:text="@string/cached_bookmarks_placeholder_subtitle"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:paddingTop="@dimen/margin_half_plus"
|
||||
android:paddingBottom="@dimen/margin_half_plus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
mapsme:layout_constraintTop_toBottomOf="@id/header_title"/>
|
||||
<ImageView
|
||||
android:id="@+id/header_close"
|
||||
android:baselineAlignBottom="true"
|
||||
mapsme:layout_constraintRight_toRightOf="parent"
|
||||
mapsme:layout_constraintBottom_toTopOf="@id/header_description"
|
||||
mapsme:layout_constraintBaseline_toBaselineOf="@id/header_title"
|
||||
android:src="@drawable/ic_clear"
|
||||
android:tint="@color/icon_tint"
|
||||
android:layout_width="@dimen/margin_half_double_plus"
|
||||
android:layout_height="@dimen/margin_half_double_plus"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
<include
|
||||
layout="@layout/recycler_default"
|
||||
android:id="@+id/recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/bookmark_recycler_view_bottom_margin"/>
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/placeholder_container">
|
||||
<com.mapswithme.maps.widget.PlaceholderView
|
||||
android:id="@+id/placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/margin_double_and_half"
|
||||
android:paddingRight="@dimen/margin_double_and_half"
|
||||
android:paddingTop="@dimen/placeholder_margin_top"
|
||||
mapsme:imgSrcDefault="@drawable/img_empty_bookmarks"
|
||||
mapsme:titleDefault="@string/cached_bookmarks_placeholder_title"
|
||||
mapsme:subTitleDefault="@string/cached_bookmarks_placeholder_subtitle"/>
|
||||
<Button
|
||||
android:id="@+id/download_routers_btn"
|
||||
style="@style/MwmWidget.Button.Accent"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:text="@string/downloader_download_routers"
|
||||
mapsme:layout_constraintLeft_toLeftOf="parent"
|
||||
mapsme:layout_constraintRight_toRightOf="parent"
|
||||
mapsme:layout_constraintTop_toBottomOf="@id/placeholder"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Light"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/placeholder_loading"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
<ProgressBar
|
||||
style="@style/Widget.AppCompat.ProgressBar"
|
||||
android:background="@null"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/margin_half"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:text="@string/load_kmz_title"/>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
|
@ -2,6 +2,7 @@
|
|||
<RelativeLayout
|
||||
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:background="?clickableBackground"
|
||||
|
@ -20,7 +21,7 @@
|
|||
android:id="@+id/name"
|
||||
android:layout_toEndOf="@id/checkbox"
|
||||
android:layout_toRightOf="@id/checkbox"
|
||||
android:layout_toStartOf="@+id/more"
|
||||
android:layout_toStartOf="@id/more"
|
||||
android:layout_toLeftOf="@id/more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -36,11 +37,24 @@
|
|||
android:layout_below="@id/name"
|
||||
android:layout_alignLeft="@id/name"
|
||||
android:layout_alignStart="@id/name"
|
||||
android:layout_marginBottom="@dimen/margin_half_plus"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
tools:text="42000000"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/author_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/name"
|
||||
android:layout_toRightOf="@id/size"
|
||||
android:layout_toEndOf="@id/size"
|
||||
android:layout_marginBottom="@dimen/margin_half_plus"
|
||||
android:layout_alignEnd="@id/name"
|
||||
android:layout_alignRight="@id/name"
|
||||
android:layout_toStartOf="@+id/more"
|
||||
android:layout_toStartOf="@id/more"
|
||||
android:layout_toLeftOf="@id/more"
|
||||
android:layout_marginBottom="@dimen/margin_half_plus"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
|
@ -57,6 +71,6 @@
|
|||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:src="@drawable/ic_more"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:tint="?secondary"/>
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -13,11 +13,13 @@
|
|||
android:paddingBottom="@dimen/margin_half_plus"
|
||||
android:paddingTop="@dimen/margin_half_plus">
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_checkbox_add"
|
||||
android:tint="?colorAccent"/>
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/margin_half"
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:background="?windowBackgroundForced">
|
||||
<TextView
|
||||
android:id="@+id/text_message"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
15
android/res/menu/menu_catalog_bookmark_categories.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/show_on_map"
|
||||
android:title="@string/search_show_on_map"/>
|
||||
<item
|
||||
android:id="@+id/share_list"
|
||||
android:title="@string/share"
|
||||
android:icon="@drawable/ic_share"/>
|
||||
<item
|
||||
android:id="@+id/delete_list"
|
||||
android:title="@string/delete"
|
||||
android:icon="@drawable/ic_delete"/>
|
||||
</menu>
|
|
@ -75,4 +75,10 @@
|
|||
|
||||
<bool name="isTablet">false</bool>
|
||||
<bool name="tabletLayout">false</bool>
|
||||
|
||||
<declare-styleable name="PlaceholderView">
|
||||
<attr name="imgSrcDefault" format="reference"/>
|
||||
<attr name="titleDefault" format="reference"/>
|
||||
<attr name="subTitleDefault" format="reference"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<attr name="panel" format="color"/>
|
||||
<attr name="sidePanel" format="color"/>
|
||||
<attr name="iconTint" format="color"/>
|
||||
<attr name="iconTintDisabled" format="color"/>
|
||||
<attr name="iconTintLight" format="color"/>
|
||||
<attr name="counterTextColor" format="color"/>
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
<item name="panel">@color/bg_panel</item>
|
||||
<item name="sidePanel">@color/bg_side_panel</item>
|
||||
<item name="iconTint">@color/icon_tint</item>
|
||||
<item name="iconTintDisabled">@color/black_38</item>
|
||||
<item name="iconTintLight">@color/icon_tint_light</item>
|
||||
<item name="counterTextColor">?android:textColorPrimaryInverse</item>
|
||||
|
||||
|
@ -156,6 +157,7 @@
|
|||
<item name="panel">@color/bg_panel_night</item>
|
||||
<item name="sidePanel">@color/bg_side_panel_night</item>
|
||||
<item name="iconTint">@color/icon_tint_night</item>
|
||||
<item name="iconTintDisabled">@color/white_38</item>
|
||||
<item name="iconTintLight">@color/icon_tint_light_night</item>
|
||||
<item name="counterTextColor">?android:textColorPrimary</item>
|
||||
|
||||
|
|
|
@ -979,7 +979,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
return;
|
||||
}
|
||||
|
||||
BottomSheetHelper.free();
|
||||
SearchEngine.INSTANCE.removeListener(this);
|
||||
|
||||
super.onDestroy();
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
||||
public interface AdapterResourceProvider
|
||||
{
|
||||
@StringRes
|
||||
int getHeaderText();
|
||||
|
||||
@StringRes
|
||||
int getFooterText();
|
||||
|
||||
@DrawableRes
|
||||
int getFooterImage();
|
||||
|
||||
@NonNull
|
||||
Button getHeaderBtn();
|
||||
|
||||
class Default implements AdapterResourceProvider
|
||||
{
|
||||
@NonNull
|
||||
private final Button mBtn;
|
||||
|
||||
public Default(@NonNull Button btn)
|
||||
{
|
||||
mBtn = btn;
|
||||
}
|
||||
|
||||
public Default()
|
||||
{
|
||||
this(new Button());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeaderText()
|
||||
{
|
||||
return R.string.bookmarks_groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFooterText()
|
||||
{
|
||||
return R.string.bookmarks_create_new_group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFooterImage()
|
||||
{
|
||||
return R.drawable.ic_checkbox_add;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Button getHeaderBtn()
|
||||
{
|
||||
return mBtn;
|
||||
}
|
||||
}
|
||||
|
||||
class Catalog extends Default
|
||||
{
|
||||
@Override
|
||||
public int getHeaderText()
|
||||
{
|
||||
return R.string.bookmarks_groups_cached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFooterImage()
|
||||
{
|
||||
return R.drawable.ic_download;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFooterText()
|
||||
{
|
||||
return R.string.downloader_download_routers;
|
||||
}
|
||||
}
|
||||
|
||||
class Button
|
||||
{
|
||||
@StringRes
|
||||
public int getSelectModeText()
|
||||
{
|
||||
return R.string.bookmarks_groups_show_all;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
public int getUnSelectModeText()
|
||||
{
|
||||
return R.string.bookmarks_groups_hide_all;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,429 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.MenuRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
import com.mapswithme.maps.widget.PlaceholderView;
|
||||
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.sharing.SharingHelper;
|
||||
|
||||
public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
||||
implements EditTextDialogFragment.EditTextDialogInterface,
|
||||
MenuItem.OnMenuItemClickListener,
|
||||
BookmarkManager.BookmarksLoadingListener,
|
||||
BookmarkManager.BookmarksSharingListener,
|
||||
CategoryListCallback,
|
||||
KmlImportController.ImportKmlCallback,
|
||||
OnItemClickListener<BookmarkCategory>,
|
||||
OnItemLongClickListener<BookmarkCategory>
|
||||
|
||||
{
|
||||
private static final int MAX_CATEGORY_NAME_LENGTH = 60;
|
||||
@NonNull
|
||||
private BookmarkCategory mSelectedCategory;
|
||||
@Nullable
|
||||
private CategoryEditor mCategoryEditor;
|
||||
@Nullable
|
||||
private KmlImportController mKmlImportController;
|
||||
@NonNull
|
||||
private Runnable mImportKmlTask = new ImportKmlTask();
|
||||
|
||||
@Override
|
||||
@LayoutRes
|
||||
protected int getLayoutRes()
|
||||
{
|
||||
return R.layout.fragment_bookmark_categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.Adapter createAdapter()
|
||||
{
|
||||
return new BookmarkCategoriesAdapter(getActivity());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected BookmarkCategoriesAdapter getAdapter()
|
||||
{
|
||||
RecyclerView.Adapter adapter = super.getAdapter();
|
||||
return adapter != null ? (BookmarkCategoriesAdapter) adapter : null;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
onPrepareControllers(view);
|
||||
if (getAdapter() != null)
|
||||
{
|
||||
getAdapter().setOnClickListener(this);
|
||||
getAdapter().setOnLongClickListener(this);
|
||||
getAdapter().setCategoryListCallback(this);
|
||||
}
|
||||
|
||||
RecyclerView rw = getRecyclerView();
|
||||
if (rw == null) return;
|
||||
|
||||
rw.setNestedScrollingEnabled(false);
|
||||
RecyclerView.ItemDecoration decor = ItemDecoratorFactory
|
||||
.createVerticalDefaultDecorator(getContext());
|
||||
rw.addItemDecoration(decor);
|
||||
}
|
||||
|
||||
protected void onPrepareControllers(@NonNull View view)
|
||||
{
|
||||
mKmlImportController = new KmlImportController(getActivity(), this);
|
||||
}
|
||||
|
||||
protected void updateLoadingPlaceholder()
|
||||
{
|
||||
View root = getView();
|
||||
if (root == null)
|
||||
throw new AssertionError("Fragment view must be non-null at this point!");
|
||||
|
||||
View loadingPlaceholder = root.findViewById(R.id.placeholder_loading);
|
||||
boolean showLoadingPlaceholder = BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress();
|
||||
UiUtils.showIf(showLoadingPlaceholder, loadingPlaceholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
BookmarkManager.INSTANCE.addLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.addSharingListener(this);
|
||||
if (mKmlImportController != null)
|
||||
mKmlImportController.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
BookmarkManager.INSTANCE.removeLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.removeSharingListener(this);
|
||||
if (mKmlImportController != null)
|
||||
mKmlImportController.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
updateLoadingPlaceholder();
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
if (!BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress())
|
||||
mImportKmlTask.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item)
|
||||
{
|
||||
MenuItemClickProcessorWrapper processor = MenuItemClickProcessorWrapper
|
||||
.getInstance(item.getItemId());
|
||||
processor
|
||||
.mInternalProcessor
|
||||
.process(this, mSelectedCategory);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected final void showBottomMenu(@NonNull BookmarkCategory item)
|
||||
{
|
||||
mSelectedCategory = item;
|
||||
showBottomMenuInternal(item);
|
||||
}
|
||||
|
||||
protected void showBottomMenuInternal(@NonNull BookmarkCategory item)
|
||||
{
|
||||
BottomSheetHelper.Builder bs = BottomSheetHelper.create(getActivity(), item.getName())
|
||||
.sheet(getCategoryMenuResId())
|
||||
.listener(this);
|
||||
|
||||
bs.getItemByIndex(0)
|
||||
.setIcon(item.isVisible() ? R.drawable.ic_hide : R.drawable.ic_show)
|
||||
.setTitle(item.isVisible() ? R.string.hide : R.string.show);
|
||||
|
||||
final boolean deleteIsPossible = getAdapter().getBookmarkCategories().size() > 1;
|
||||
bs.getItemById(getDeleteMenuItemResId())
|
||||
.setVisible(deleteIsPossible)
|
||||
.setEnabled(deleteIsPossible);
|
||||
|
||||
bs.tint().show();
|
||||
}
|
||||
|
||||
@MenuRes
|
||||
protected int getCategoryMenuResId()
|
||||
{
|
||||
return R.menu.menu_bookmark_categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoreOperationClick(@NonNull BookmarkCategory item)
|
||||
{
|
||||
showBottomMenu(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupPlaceholder(@Nullable PlaceholderView placeholder)
|
||||
{
|
||||
// A placeholder is no needed on this screen.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarksLoadingStarted()
|
||||
{
|
||||
updateLoadingPlaceholder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarksLoadingFinished()
|
||||
{
|
||||
updateLoadingPlaceholder();
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
mImportKmlTask.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarksFileLoaded(boolean success)
|
||||
{
|
||||
// Do nothing here.
|
||||
}
|
||||
|
||||
private void importKml()
|
||||
{
|
||||
if (mKmlImportController != null) mKmlImportController.importKml();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreparedFileForSharing(@NonNull BookmarkSharingResult result)
|
||||
{
|
||||
SharingHelper.INSTANCE.onPreparedFileForSharing(getActivity(), result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFooterClick()
|
||||
{
|
||||
mCategoryEditor = BookmarkManager.INSTANCE::createCategory;
|
||||
|
||||
EditTextDialogFragment.show(getString(R.string.bookmarks_create_new_group),
|
||||
getString(R.string.bookmarks_new_list_hint),
|
||||
getString(R.string.bookmark_set_name),
|
||||
getString(R.string.create), getString(R.string.cancel),
|
||||
MAX_CATEGORY_NAME_LENGTH, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishKmlImport()
|
||||
{
|
||||
if (getAdapter() != null) getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public EditTextDialogFragment.OnTextSaveListener getSaveTextListener()
|
||||
{
|
||||
return text -> {
|
||||
if (mCategoryEditor != null)
|
||||
mCategoryEditor.commit(text);
|
||||
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
};
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public EditTextDialogFragment.Validator getValidator()
|
||||
{
|
||||
return new CategoryValidator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(View v, BookmarkCategory category)
|
||||
{
|
||||
startActivity(new Intent(getActivity(), BookmarkListActivity.class)
|
||||
.putExtra(BookmarksListFragment.EXTRA_CATEGORY, category));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemLongClick(View v, BookmarkCategory category)
|
||||
{
|
||||
showBottomMenu(category);
|
||||
}
|
||||
|
||||
@IdRes
|
||||
protected int getDeleteMenuItemResId()
|
||||
{
|
||||
return R.id.set_delete;
|
||||
}
|
||||
|
||||
interface CategoryEditor
|
||||
{
|
||||
void commit(@NonNull String newName);
|
||||
}
|
||||
|
||||
private class ImportKmlTask implements Runnable
|
||||
{
|
||||
private boolean alreadyDone;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (alreadyDone)
|
||||
return;
|
||||
|
||||
importKml();
|
||||
alreadyDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected enum MenuItemClickProcessorWrapper
|
||||
{
|
||||
SET_SHOW(R.id.set_show, setShow()),
|
||||
SET_SHARE(R.id.set_share, setShare()),
|
||||
SET_DELETE(R.id.set_delete, setDelete()),
|
||||
SET_EDIT(R.id.set_edit, setEdit()),
|
||||
SHOW_ON_MAP(R.id.show_on_map, setShow()),
|
||||
SHARE_LIST(R.id.share_list, setShare()),
|
||||
DELETE_LIST(R.id.delete_list, setDelete());
|
||||
|
||||
@NonNull
|
||||
private static MenuClickProcessorBase.SetEdit setEdit()
|
||||
{
|
||||
return new MenuClickProcessorBase.SetEdit();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static MenuClickProcessorBase.SetDelete setDelete()
|
||||
{
|
||||
return new MenuClickProcessorBase.SetDelete();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static MenuClickProcessorBase.SetShare setShare()
|
||||
{
|
||||
return new MenuClickProcessorBase.SetShare();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static MenuClickProcessorBase.SetShow setShow()
|
||||
{
|
||||
return new MenuClickProcessorBase.SetShow();
|
||||
}
|
||||
|
||||
@IdRes
|
||||
private final int mId;
|
||||
@NonNull
|
||||
private MenuClickProcessorBase mInternalProcessor;
|
||||
|
||||
MenuItemClickProcessorWrapper(int id, @NonNull MenuClickProcessorBase processorBase)
|
||||
{
|
||||
mId = id;
|
||||
mInternalProcessor = processorBase;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public static MenuItemClickProcessorWrapper getInstance(@IdRes int resId)
|
||||
{
|
||||
for (MenuItemClickProcessorWrapper each : values())
|
||||
{
|
||||
if (each.mId == resId)
|
||||
{
|
||||
return each;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("enum value for res id = " + resId + " not found");
|
||||
}
|
||||
}
|
||||
|
||||
protected static abstract class MenuClickProcessorBase
|
||||
{
|
||||
public abstract void process(@NonNull BaseBookmarkCategoriesFragment frag,
|
||||
@NonNull BookmarkCategory category);
|
||||
|
||||
protected static class SetShow extends MenuClickProcessorBase
|
||||
{
|
||||
@Override
|
||||
public void process(@NonNull BaseBookmarkCategoriesFragment frag,
|
||||
@NonNull BookmarkCategory category)
|
||||
{
|
||||
BookmarkManager.INSTANCE.toggleCategoryVisibility(category.getId());
|
||||
if (frag.getAdapter() != null)
|
||||
frag.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected static class SetShare extends MenuClickProcessorBase
|
||||
{
|
||||
@Override
|
||||
public void process(@NonNull BaseBookmarkCategoriesFragment frag,
|
||||
@NonNull BookmarkCategory category)
|
||||
{
|
||||
SharingHelper.INSTANCE.prepareBookmarkCategoryForSharing(frag.getActivity(),
|
||||
category.getId());
|
||||
}
|
||||
}
|
||||
|
||||
protected static class SetDelete extends MenuClickProcessorBase
|
||||
{
|
||||
@Override
|
||||
public void process(@NonNull BaseBookmarkCategoriesFragment frag,
|
||||
@NonNull BookmarkCategory category)
|
||||
{
|
||||
BookmarkManager.INSTANCE.deleteCategory(category.getId());
|
||||
if (frag.getAdapter() != null)
|
||||
{
|
||||
frag.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static class SetEdit extends MenuClickProcessorBase
|
||||
{
|
||||
@Override
|
||||
public void process(@NonNull BaseBookmarkCategoriesFragment frag,
|
||||
@NonNull BookmarkCategory category)
|
||||
{
|
||||
frag.mCategoryEditor = newName ->
|
||||
{
|
||||
BookmarkManager.INSTANCE.setCategoryName(category.getId(), newName);
|
||||
};
|
||||
EditTextDialogFragment.show(frag.getString(R.string.bookmark_set_name),
|
||||
category.getName(),
|
||||
frag.getString(R.string.rename),
|
||||
frag.getString(R.string.cancel),
|
||||
MAX_CATEGORY_NAME_LENGTH,
|
||||
frag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,13 @@ import android.content.Context;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
public abstract class BaseBookmarkCategoryAdapter<V extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<V>
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseBookmarkCategoryAdapter<V extends RecyclerView.ViewHolder>
|
||||
extends RecyclerView.Adapter<V>
|
||||
{
|
||||
@NonNull
|
||||
private final Context mContext;
|
||||
|
@ -22,14 +26,24 @@ public abstract class BaseBookmarkCategoryAdapter<V extends RecyclerView.ViewHol
|
|||
return mContext;
|
||||
}
|
||||
|
||||
public List<BookmarkCategory> getBookmarkCategories()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getOwnedCategoriesSnapshot().items();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCategoriesCount();
|
||||
return getBookmarkCategories().size();
|
||||
}
|
||||
|
||||
public long getCategoryIdByPosition(int position)
|
||||
public BookmarkCategory getCategoryByPosition(int position)
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCategoryIdByPosition(position);
|
||||
List<BookmarkCategory> categories = getBookmarkCategories();
|
||||
if (position < 0 || position > categories.size() - 1){
|
||||
throw new ArrayIndexOutOfBoundsException(position);
|
||||
}
|
||||
return categories.get(position);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseToolbarActivity;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.util.ThemeUtils;
|
||||
|
@ -43,6 +44,12 @@ public class BookmarkCategoriesActivity extends BaseToolbarActivity
|
|||
@Override
|
||||
protected Class<? extends Fragment> getFragmentClass()
|
||||
{
|
||||
return BookmarkCategoriesFragment.class;
|
||||
return BookmarkCategoriesPagerFragment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentLayoutResId()
|
||||
{
|
||||
return R.layout.bookmarks_activity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,8 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.widget.recycler.RecyclerClickListener;
|
||||
import com.mapswithme.maps.widget.recycler.RecyclerLongClickListener;
|
||||
|
||||
import static com.mapswithme.maps.bookmarks.Holders.CategoryViewHolder;
|
||||
import static com.mapswithme.maps.bookmarks.Holders.HeaderViewHolder;
|
||||
|
@ -19,74 +18,70 @@ import static com.mapswithme.maps.bookmarks.Holders.HeaderViewHolder;
|
|||
public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<RecyclerView.ViewHolder>
|
||||
{
|
||||
private final static int TYPE_CATEGORY_ITEM = 0;
|
||||
private final static int TYPE_ACTION_CREATE_GROUP = 1;
|
||||
private final static int TYPE_ACTION_FOOTER = 1;
|
||||
private final static int TYPE_ACTION_HEADER = 2;
|
||||
private final static int HEADER_POSITION = 0;
|
||||
@NonNull
|
||||
private final AdapterResourceProvider mResProvider;
|
||||
@Nullable
|
||||
private RecyclerLongClickListener mLongClickListener;
|
||||
private OnItemLongClickListener<BookmarkCategory> mLongClickListener;
|
||||
@Nullable
|
||||
private RecyclerClickListener mClickListener;
|
||||
private OnItemClickListener<BookmarkCategory> mClickListener;
|
||||
@Nullable
|
||||
private CategoryListInterface mCategoryListInterface;
|
||||
private CategoryListCallback mCategoryListCallback;
|
||||
@NonNull
|
||||
private final MassOperationAction mMassOperationAction = new MassOperationAction();
|
||||
@NonNull
|
||||
private final BookmarkCategory.Type mType;
|
||||
|
||||
BookmarkCategoriesAdapter(@NonNull Context context, @NonNull BookmarkCategory.Type type)
|
||||
{
|
||||
super(context.getApplicationContext());
|
||||
mType = type;
|
||||
mResProvider = type.getFactory().getResProvider();
|
||||
}
|
||||
|
||||
BookmarkCategoriesAdapter(@NonNull Context context)
|
||||
{
|
||||
super(context);
|
||||
this(context, BookmarkCategory.Type.PRIVATE);
|
||||
}
|
||||
|
||||
public void setOnClickListener(@Nullable RecyclerClickListener listener)
|
||||
public void setOnClickListener(@Nullable OnItemClickListener<BookmarkCategory> listener)
|
||||
{
|
||||
mClickListener = listener;
|
||||
}
|
||||
|
||||
void setOnLongClickListener(@Nullable RecyclerLongClickListener listener)
|
||||
void setOnLongClickListener(@Nullable OnItemLongClickListener<BookmarkCategory> listener)
|
||||
{
|
||||
mLongClickListener = listener;
|
||||
}
|
||||
|
||||
void setCategoryListInterface(@Nullable CategoryListInterface listener)
|
||||
void setCategoryListCallback(@Nullable CategoryListCallback listener)
|
||||
{
|
||||
mCategoryListInterface = listener;
|
||||
mCategoryListCallback = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
|
||||
{
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
if (viewType == TYPE_ACTION_HEADER)
|
||||
{
|
||||
View header = inflater.inflate(R.layout.item_bookmark_group_list_header, parent, false);
|
||||
return new Holders.HeaderViewHolder(header);
|
||||
}
|
||||
|
||||
if (viewType == TYPE_ACTION_CREATE_GROUP)
|
||||
if (viewType == TYPE_ACTION_FOOTER)
|
||||
{
|
||||
View createListView = inflater.inflate(R.layout.item_bookmark_create_group, parent, false);
|
||||
createListView.setOnClickListener
|
||||
(v ->
|
||||
{
|
||||
if (mCategoryListInterface != null)
|
||||
mCategoryListInterface.onAddCategory();
|
||||
});
|
||||
return new Holders.GeneralViewHolder(createListView);
|
||||
View item = inflater.inflate(R.layout.item_bookmark_create_group, parent, false);
|
||||
item.setOnClickListener(new FooterClickListener());
|
||||
return new Holders.GeneralViewHolder(item);
|
||||
}
|
||||
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_bookmark_category,
|
||||
parent, false);
|
||||
View view = inflater.inflate(R.layout.item_bookmark_category, parent,false);
|
||||
final CategoryViewHolder holder = new CategoryViewHolder(view);
|
||||
view.setOnClickListener(
|
||||
v ->
|
||||
{
|
||||
if (mClickListener != null)
|
||||
mClickListener.onItemClick(v, toCategoryPosition(holder.getAdapterPosition()));
|
||||
});
|
||||
view.setOnLongClickListener(
|
||||
v ->
|
||||
{
|
||||
if (mLongClickListener != null)
|
||||
mLongClickListener.onLongItemClick(v, toCategoryPosition(holder.getAdapterPosition()));
|
||||
return true;
|
||||
});
|
||||
view.setOnClickListener(new CategoryItemClickListener(holder));
|
||||
view.setOnLongClickListener(new LongClickListener(holder));
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
@ -95,56 +90,77 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Recyc
|
|||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position)
|
||||
{
|
||||
int type = getItemViewType(position);
|
||||
if (type == TYPE_ACTION_CREATE_GROUP)
|
||||
return;
|
||||
|
||||
if (type == TYPE_ACTION_HEADER)
|
||||
if (type == TYPE_ACTION_FOOTER)
|
||||
{
|
||||
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
|
||||
headerHolder.setAction(new HeaderViewHolder.HeaderAction()
|
||||
{
|
||||
@Override
|
||||
public void onHideAll()
|
||||
{
|
||||
BookmarkManager.INSTANCE.setAllCategoriesVisibility(false);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowAll()
|
||||
{
|
||||
BookmarkManager.INSTANCE.setAllCategoriesVisibility(true);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}, BookmarkManager.INSTANCE.areAllCategoriesInvisible());
|
||||
bindFooterHolder(holder);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == TYPE_ACTION_HEADER)
|
||||
{
|
||||
bindHeaderHolder(holder);
|
||||
return;
|
||||
}
|
||||
|
||||
bindCategoryHolder(holder, position);
|
||||
}
|
||||
|
||||
private void bindFooterHolder(@NonNull RecyclerView.ViewHolder holder)
|
||||
{
|
||||
Holders.GeneralViewHolder generalViewHolder = (Holders.GeneralViewHolder) holder;
|
||||
generalViewHolder.getImage().setImageResource(mResProvider.getFooterImage());
|
||||
generalViewHolder.getText().setText(mResProvider.getFooterText());
|
||||
}
|
||||
|
||||
private void bindHeaderHolder(@NonNull RecyclerView.ViewHolder holder)
|
||||
{
|
||||
HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder;
|
||||
headerViewHolder.setAction(mMassOperationAction,
|
||||
mResProvider,
|
||||
BookmarkManager.INSTANCE.areAllCategoriesInvisible(mType));
|
||||
headerViewHolder.getText().setText(mResProvider.getHeaderText());
|
||||
}
|
||||
|
||||
private void bindCategoryHolder(@NonNull RecyclerView.ViewHolder holder, int position)
|
||||
{
|
||||
final BookmarkCategory category = getCategoryByPosition(toCategoryPosition(position));
|
||||
CategoryViewHolder categoryHolder = (CategoryViewHolder) holder;
|
||||
final BookmarkManager bmManager = BookmarkManager.INSTANCE;
|
||||
final long catId = getCategoryIdByPosition(toCategoryPosition(position));
|
||||
categoryHolder.setName(bmManager.getCategoryName(catId));
|
||||
categoryHolder.setSize(bmManager.getCategorySize(catId));
|
||||
categoryHolder.setVisibilityState(bmManager.isVisible(catId));
|
||||
categoryHolder.setVisibilityListener(
|
||||
v ->
|
||||
{
|
||||
BookmarkManager.INSTANCE.toggleCategoryVisibility(catId);
|
||||
categoryHolder.setVisibilityState(bmManager.isVisible(catId));
|
||||
notifyItemChanged(HEADER_POSITION);
|
||||
});
|
||||
categoryHolder.setCategory(category);
|
||||
categoryHolder.setName(category.getName());
|
||||
bindSize(categoryHolder, category);
|
||||
bindAuthor(categoryHolder, category);
|
||||
categoryHolder.setVisibilityState(category.isVisible());
|
||||
ToggleVisibilityClickListener listener = new ToggleVisibilityClickListener(categoryHolder);
|
||||
categoryHolder.setVisibilityListener(listener);
|
||||
categoryHolder.setMoreListener(v -> {
|
||||
if (mCategoryListInterface != null)
|
||||
mCategoryListInterface.onMoreOperationClick(toCategoryPosition(position));
|
||||
if (mCategoryListCallback != null)
|
||||
mCategoryListCallback.onMoreOperationClick(category);
|
||||
});
|
||||
}
|
||||
|
||||
private void bindSize(@NonNull CategoryViewHolder categoryHolder,
|
||||
@NonNull BookmarkCategory category)
|
||||
{
|
||||
categoryHolder.setSize(category.getPluralsCountTemplate(), category.getPluralsCount());
|
||||
}
|
||||
|
||||
private void bindAuthor(@NonNull CategoryViewHolder categoryHolder,
|
||||
@NonNull BookmarkCategory category)
|
||||
{
|
||||
CharSequence authorName = category.getAuthor() == null
|
||||
? null
|
||||
: BookmarkCategory
|
||||
.Author
|
||||
.getRepresentation(getContext(), category.getAuthor());
|
||||
categoryHolder.getAuthorName().setText(authorName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position)
|
||||
{
|
||||
if (position == 0)
|
||||
return TYPE_ACTION_HEADER;
|
||||
return (position == getItemCount() - 1) ? TYPE_ACTION_CREATE_GROUP : TYPE_CATEGORY_ITEM;
|
||||
return (position == getItemCount() - 1) ? TYPE_ACTION_FOOTER : TYPE_CATEGORY_ITEM;
|
||||
}
|
||||
|
||||
private int toCategoryPosition(int adapterPosition)
|
||||
|
@ -165,9 +181,92 @@ public class BookmarkCategoriesAdapter extends BaseBookmarkCategoryAdapter<Recyc
|
|||
return count > 0 ? count + 2 /* header + add category btn */ : 0;
|
||||
}
|
||||
|
||||
interface CategoryListInterface
|
||||
private class LongClickListener implements View.OnLongClickListener
|
||||
{
|
||||
void onAddCategory();
|
||||
void onMoreOperationClick(int position);
|
||||
@NonNull
|
||||
private final CategoryViewHolder mHolder;
|
||||
|
||||
LongClickListener(@NonNull CategoryViewHolder holder)
|
||||
{
|
||||
mHolder = holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view)
|
||||
{
|
||||
if (mLongClickListener != null)
|
||||
{
|
||||
mLongClickListener.onItemLongClick(view, mHolder.getEntity());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private class MassOperationAction implements HeaderViewHolder.HeaderAction
|
||||
{
|
||||
@Override
|
||||
public void onHideAll()
|
||||
{
|
||||
BookmarkManager.INSTANCE.setAllCategoriesVisibility(false);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowAll()
|
||||
{
|
||||
BookmarkManager.INSTANCE.setAllCategoriesVisibility(true);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private class CategoryItemClickListener implements View.OnClickListener
|
||||
{
|
||||
@NonNull
|
||||
private final CategoryViewHolder mHolder;
|
||||
|
||||
CategoryItemClickListener(@NonNull CategoryViewHolder holder)
|
||||
{
|
||||
mHolder = holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (mClickListener != null)
|
||||
{
|
||||
mClickListener.onItemClick(v, mHolder.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FooterClickListener implements View.OnClickListener
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (mCategoryListCallback != null)
|
||||
{
|
||||
mCategoryListCallback.onFooterClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ToggleVisibilityClickListener implements View.OnClickListener
|
||||
{
|
||||
@NonNull
|
||||
private final CategoryViewHolder mHolder;
|
||||
|
||||
ToggleVisibilityClickListener(@NonNull CategoryViewHolder holder)
|
||||
{
|
||||
mHolder = holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
BookmarkManager.INSTANCE.toggleCategoryVisibility(mHolder.getEntity().getId());
|
||||
notifyItemChanged(mHolder.getAdapterPosition());
|
||||
notifyItemChanged(HEADER_POSITION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -15,17 +10,10 @@ import com.mapswithme.maps.auth.Authorizer;
|
|||
import com.mapswithme.maps.auth.TargetFragmentCallback;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
import com.mapswithme.maps.widget.PlaceholderView;
|
||||
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
|
||||
import com.mapswithme.maps.widget.recycler.RecyclerClickListener;
|
||||
import com.mapswithme.maps.widget.recycler.RecyclerLongClickListener;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.maps.widget.BookmarkBackupView;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.sharing.SharingHelper;
|
||||
|
||||
public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
||||
/*public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
||||
implements EditTextDialogFragment.EditTextDialogInterface,
|
||||
MenuItem.OnMenuItemClickListener,
|
||||
RecyclerClickListener,
|
||||
|
@ -33,285 +21,45 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
BookmarkManager.BookmarksLoadingListener,
|
||||
BookmarkManager.BookmarksSharingListener,
|
||||
BookmarkCategoriesAdapter.CategoryListInterface,
|
||||
KmlImportController.ImportKmlCallback, TargetFragmentCallback
|
||||
{
|
||||
private static final int MAX_CATEGORY_NAME_LENGTH = 60;
|
||||
private long mSelectedCatId;
|
||||
@Nullable
|
||||
private CategoryEditor mCategoryEditor;
|
||||
KmlImportController.ImportKmlCallback,*/
|
||||
|
||||
public class BookmarkCategoriesFragment extends BaseBookmarkCategoriesFragment
|
||||
implements Authorizer.SocialAuthCallback, TargetFragmentCallback
|
||||
{
|
||||
@Nullable
|
||||
private BookmarkBackupController mBackupController;
|
||||
@Nullable
|
||||
private KmlImportController mKmlImportController;
|
||||
@NonNull
|
||||
private Runnable mImportKmlTask = new Runnable()
|
||||
{
|
||||
private boolean alreadyDone = false;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (alreadyDone)
|
||||
return;
|
||||
|
||||
importKml();
|
||||
alreadyDone = true;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected @LayoutRes int getLayoutRes()
|
||||
protected void onPrepareControllers(@NonNull View view)
|
||||
{
|
||||
return R.layout.fragment_bookmark_categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.Adapter createAdapter()
|
||||
{
|
||||
return new BookmarkCategoriesAdapter(getActivity());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected BookmarkCategoriesAdapter getAdapter()
|
||||
{
|
||||
RecyclerView.Adapter adapter = super.getAdapter();
|
||||
return adapter != null ? (BookmarkCategoriesAdapter) adapter : null;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mBackupController = new BookmarkBackupController(getActivity(), view.findViewById(R.id.backup),
|
||||
new Authorizer(this));
|
||||
mKmlImportController = new KmlImportController(getActivity(), this);
|
||||
if (getAdapter() != null)
|
||||
{
|
||||
getAdapter().setOnClickListener(this);
|
||||
getAdapter().setOnLongClickListener(this);
|
||||
getAdapter().setCategoryListInterface(this);
|
||||
}
|
||||
|
||||
RecyclerView rw = getRecyclerView();
|
||||
if (rw == null)
|
||||
return;
|
||||
|
||||
rw.setNestedScrollingEnabled(false);
|
||||
rw.addItemDecoration(ItemDecoratorFactory.createVerticalDefaultDecorator(getContext()));
|
||||
}
|
||||
|
||||
private void updateLoadingPlaceholder()
|
||||
{
|
||||
View root = getView();
|
||||
if (root == null)
|
||||
throw new AssertionError("Fragment view must be non-null at this point!");
|
||||
|
||||
View loadingPlaceholder = root.findViewById(R.id.placeholder_loading);
|
||||
boolean showLoadingPlaceholder = BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress();
|
||||
UiUtils.showIf(showLoadingPlaceholder, loadingPlaceholder);
|
||||
UiUtils.showIf(!showLoadingPlaceholder, getView(), R.id.backup, R.id.recycler);
|
||||
super.onPrepareControllers(view);
|
||||
Authorizer authorizer = new Authorizer(this);
|
||||
BookmarkBackupView backupView = view.findViewById(R.id.backup);
|
||||
mBackupController = new BookmarkBackupController(getActivity(), backupView, authorizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
BookmarkManager.INSTANCE.addLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.addSharingListener(this);
|
||||
if (mBackupController != null)
|
||||
mBackupController.onStart();
|
||||
if (mKmlImportController != null)
|
||||
mKmlImportController.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateLoadingPlaceholder()
|
||||
{
|
||||
super.updateLoadingPlaceholder();
|
||||
boolean isLoading = BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress();
|
||||
UiUtils.showIf(!isLoading, getView(), R.id.backup, R.id.recycler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
BookmarkManager.INSTANCE.removeLoadingListener(this);
|
||||
BookmarkManager.INSTANCE.removeSharingListener(this);
|
||||
if (mBackupController != null)
|
||||
mBackupController.onStop();
|
||||
if (mKmlImportController != null)
|
||||
mKmlImportController.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
updateLoadingPlaceholder();
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
if (!BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress())
|
||||
mImportKmlTask.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause()
|
||||
{
|
||||
super.onPause();
|
||||
BottomSheetHelper.free();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item)
|
||||
{
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.set_show:
|
||||
BookmarkManager.INSTANCE.toggleCategoryVisibility(mSelectedCatId);
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
break;
|
||||
|
||||
case R.id.set_share:
|
||||
SharingHelper.INSTANCE.prepareBookmarkCategoryForSharing(getActivity(), mSelectedCatId);
|
||||
break;
|
||||
|
||||
case R.id.set_delete:
|
||||
BookmarkManager.INSTANCE.deleteCategory(mSelectedCatId);
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
break;
|
||||
|
||||
case R.id.set_edit:
|
||||
mCategoryEditor = newName ->
|
||||
{
|
||||
BookmarkManager.INSTANCE.setCategoryName(mSelectedCatId, newName);
|
||||
};
|
||||
EditTextDialogFragment.show(getString(R.string.bookmark_set_name),
|
||||
BookmarkManager.INSTANCE.getCategoryName(mSelectedCatId),
|
||||
getString(R.string.rename), getString(R.string.cancel),
|
||||
MAX_CATEGORY_NAME_LENGTH, this);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongItemClick(View v, int position)
|
||||
{
|
||||
showBottomMenu(position);
|
||||
}
|
||||
|
||||
private void showBottomMenu(int position)
|
||||
{
|
||||
final BookmarkManager bmManager = BookmarkManager.INSTANCE;
|
||||
mSelectedCatId = bmManager.getCategoryIdByPosition(position);
|
||||
|
||||
final String name = bmManager.getCategoryName(mSelectedCatId);
|
||||
BottomSheetHelper.Builder bs = BottomSheetHelper.create(getActivity(), name)
|
||||
.sheet(R.menu.menu_bookmark_categories)
|
||||
.listener(this);
|
||||
|
||||
final boolean isVisible = bmManager.isVisible(mSelectedCatId);
|
||||
bs.getItemByIndex(0)
|
||||
.setIcon(isVisible ? R.drawable.ic_hide : R.drawable.ic_show)
|
||||
.setTitle(isVisible ? R.string.hide : R.string.show);
|
||||
|
||||
final boolean deleteIsPossible = bmManager.getCategoriesCount() > 1;
|
||||
bs.getItemById(R.id.set_delete)
|
||||
.setVisible(deleteIsPossible)
|
||||
.setEnabled(deleteIsPossible);
|
||||
|
||||
bs.tint().show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoreOperationClick(int position)
|
||||
{
|
||||
showBottomMenu(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(View v, int position)
|
||||
{
|
||||
startActivity(new Intent(getActivity(), BookmarkListActivity.class)
|
||||
.putExtra(ChooseBookmarkCategoryFragment.CATEGORY_POSITION, position));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupPlaceholder(@Nullable PlaceholderView placeholder)
|
||||
{
|
||||
// A placeholder is no needed on this screen.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarksLoadingStarted()
|
||||
{
|
||||
updateLoadingPlaceholder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarksLoadingFinished()
|
||||
{
|
||||
updateLoadingPlaceholder();
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
mImportKmlTask.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarksFileLoaded(boolean success)
|
||||
{
|
||||
// Do nothing here.
|
||||
}
|
||||
|
||||
private void importKml()
|
||||
{
|
||||
if (mKmlImportController != null)
|
||||
mKmlImportController.importKml();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreparedFileForSharing(@NonNull BookmarkSharingResult result)
|
||||
{
|
||||
SharingHelper.INSTANCE.onPreparedFileForSharing(getActivity(), result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddCategory()
|
||||
{
|
||||
mCategoryEditor = BookmarkManager.INSTANCE::createCategory;
|
||||
|
||||
EditTextDialogFragment.show(getString(R.string.bookmarks_create_new_group),
|
||||
getString(R.string.bookmarks_new_list_hint),
|
||||
getString(R.string.bookmark_set_name),
|
||||
getString(R.string.create), getString(R.string.cancel),
|
||||
MAX_CATEGORY_NAME_LENGTH, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinishKmlImport()
|
||||
{
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public EditTextDialogFragment.OnTextSaveListener getSaveTextListener()
|
||||
{
|
||||
return text -> {
|
||||
if (mCategoryEditor != null)
|
||||
mCategoryEditor.commit(text);
|
||||
|
||||
if (getAdapter() != null)
|
||||
getAdapter().notifyDataSetChanged();
|
||||
};
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public EditTextDialogFragment.Validator getValidator()
|
||||
{
|
||||
return new CategoryValidator();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -326,9 +74,4 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
{
|
||||
return isAdded();
|
||||
}
|
||||
|
||||
interface CategoryEditor
|
||||
{
|
||||
void commit(@NonNull String newName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.mapswithme.maps.MwmActivity;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.maps.bookmarks.data.Track;
|
||||
|
@ -36,9 +37,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
|
|||
BookmarkManager.BookmarksSharingListener
|
||||
{
|
||||
public static final String TAG = BookmarksListFragment.class.getSimpleName();
|
||||
public static final String EXTRA_CATEGORY = "bookmark_category";
|
||||
|
||||
private int mCategoryPosition;
|
||||
private long mCategoryId;
|
||||
private BookmarkCategory mCategory;
|
||||
private int mSelectedPosition;
|
||||
|
||||
@CallSuper
|
||||
|
@ -46,14 +47,13 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
|
|||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
mCategoryPosition = getArguments().getInt(ChooseBookmarkCategoryFragment.CATEGORY_POSITION, 0);
|
||||
mCategoryId = BookmarkManager.INSTANCE.getCategoryIdByPosition(mCategoryPosition);
|
||||
mCategory = getArguments().getParcelable(EXTRA_CATEGORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.Adapter createAdapter()
|
||||
{
|
||||
return new BookmarkListAdapter(getActivity(), mCategoryId);
|
||||
return new BookmarkListAdapter(getActivity(), mCategory.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,7 +71,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
|
|||
setHasOptionsMenu(true);
|
||||
ActionBar bar = ((AppCompatActivity) getActivity()).getSupportActionBar();
|
||||
if (bar != null)
|
||||
bar.setTitle(BookmarkManager.INSTANCE.getCategoryName(mCategoryId));
|
||||
bar.setTitle(mCategory.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -258,7 +258,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
|
|||
{
|
||||
if (item.getItemId() == R.id.set_share)
|
||||
{
|
||||
SharingHelper.INSTANCE.prepareBookmarkCategoryForSharing(getActivity(), mCategoryId);
|
||||
SharingHelper.INSTANCE.prepareBookmarkCategoryForSharing(getActivity(), mCategory.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class CachedBookmarksFragment extends BaseBookmarkCategoriesFragment implements
|
||||
BookmarkManager.BookmarksCatalogListener
|
||||
|
||||
{
|
||||
@NonNull
|
||||
private ViewGroup mEmptyViewContainer;
|
||||
@NonNull
|
||||
private View mPayloadContainer;
|
||||
@NonNull
|
||||
private View mProgressContainer;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||
mProgressContainer = root.findViewById(R.id.placeholder_loading);
|
||||
mEmptyViewContainer = root.findViewById(R.id.placeholder_container);
|
||||
mPayloadContainer = root.findViewById(R.id.cached_bookmarks_payload_container);
|
||||
View downloadBtn = mEmptyViewContainer.findViewById(R.id.download_routers_btn);
|
||||
downloadBtn.setOnClickListener(new DownloadRoutesClickListener());
|
||||
View closeHeaderBtn = root.findViewById(R.id.header_close);
|
||||
closeHeaderBtn.setOnClickListener(new CloseHeaderClickListener());
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutRes()
|
||||
{
|
||||
return R.layout.fragment_catalog_bookmark_categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.Adapter createAdapter()
|
||||
{
|
||||
return new CatalogBookmarkCategoriesAdapter(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFooterClick()
|
||||
{
|
||||
openBookmarksCatalogScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDeleteMenuItemResId()
|
||||
{
|
||||
return R.id.delete_list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateLoadingPlaceholder()
|
||||
{
|
||||
super.updateLoadingPlaceholder();
|
||||
boolean showLoadingPlaceholder = BookmarkManager.INSTANCE.isAsyncBookmarksLoadingInProgress();
|
||||
if (showLoadingPlaceholder){
|
||||
mProgressContainer.setVisibility(View.VISIBLE);
|
||||
mPayloadContainer.setVisibility(View.GONE);
|
||||
mEmptyViewContainer.setVisibility(View.GONE);
|
||||
} else {
|
||||
mProgressContainer.setVisibility(View.GONE);
|
||||
boolean isEmptyAdapter = getAdapter().getItemCount() == 0;
|
||||
mEmptyViewContainer.setVisibility(isEmptyAdapter ? View.VISIBLE : View.GONE);
|
||||
mPayloadContainer.setVisibility(isEmptyAdapter ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
BookmarkManager.INSTANCE.addCatalogListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
super.onStop();
|
||||
BookmarkManager.INSTANCE.removeCatalogListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCategoryMenuResId()
|
||||
{
|
||||
return R.menu.menu_catalog_bookmark_categories;
|
||||
}
|
||||
|
||||
private void openBookmarksCatalogScreen()
|
||||
{
|
||||
Intent intent = new Intent(getActivity(), BookmarksCatalogActivity.class)
|
||||
.putExtra(BookmarksCatalogFragment.EXTRA_BOOKMARKS_CATALOG_URL,
|
||||
getCatalogUrl());
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getCatalogUrl()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCatalogFrontendUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoreOperationClick(@NonNull BookmarkCategory item)
|
||||
{
|
||||
showBottomMenu(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImportStarted(@NonNull String serverId)
|
||||
{
|
||||
mProgressContainer.setVisibility(View.VISIBLE);
|
||||
mEmptyViewContainer.setVisibility(View.GONE);
|
||||
mPayloadContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onImportFinished(@NonNull String serverId, boolean successful)
|
||||
{
|
||||
if (successful){
|
||||
mPayloadContainer.setVisibility(View.VISIBLE);
|
||||
mProgressContainer.setVisibility(View.GONE);
|
||||
mEmptyViewContainer.setVisibility(View.GONE);
|
||||
getAdapter().notifyDataSetChanged();
|
||||
} else {
|
||||
boolean isEmptyAdapter = getAdapter().getItemCount() == 0;
|
||||
mProgressContainer.setVisibility(View.GONE);
|
||||
UiUtils.showIf(isEmptyAdapter, mEmptyViewContainer);
|
||||
UiUtils.showIf(!isEmptyAdapter,mPayloadContainer);
|
||||
}
|
||||
}
|
||||
|
||||
private class CloseHeaderClickListener implements View.OnClickListener
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
View header = mPayloadContainer.findViewById(R.id.header);
|
||||
header.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private class DownloadRoutesClickListener implements View.OnClickListener
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
openBookmarksCatalogScreen();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CatalogBookmarkCategoriesAdapter extends BookmarkCategoriesAdapter
|
||||
{
|
||||
CatalogBookmarkCategoriesAdapter(@NonNull Context context)
|
||||
{
|
||||
super(context, BookmarkCategory.Type.CATALOG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BookmarkCategory> getBookmarkCategories()
|
||||
{
|
||||
return BookmarkManager.INSTANCE.getCatalogCategoriesSnapshot().items();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
|
||||
interface CategoryListCallback
|
||||
{
|
||||
void onFooterClick();
|
||||
|
||||
void onMoreOperationClick(BookmarkCategory item);
|
||||
}
|
|
@ -9,7 +9,7 @@ import android.widget.RadioButton;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
|
||||
public class ChooseBookmarkCategoryAdapter extends BaseBookmarkCategoryAdapter<ChooseBookmarkCategoryAdapter.SingleChoiceHolder>
|
||||
{
|
||||
|
@ -73,7 +73,8 @@ public class ChooseBookmarkCategoryAdapter extends BaseBookmarkCategoryAdapter<C
|
|||
{
|
||||
if (holder.getItemViewType() == VIEW_TYPE_CATEGORY)
|
||||
{
|
||||
holder.name.setText(BookmarkManager.INSTANCE.getCategoryName(getCategoryIdByPosition(position)));
|
||||
BookmarkCategory category = getCategoryByPosition(position);
|
||||
holder.name.setText(category.getName());
|
||||
holder.checked.setChecked(mCheckedPosition == position);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,13 @@ import android.view.ViewGroup;
|
|||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.dialog.EditTextDialogFragment;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChooseBookmarkCategoryFragment extends BaseMwmDialogFragment
|
||||
implements EditTextDialogFragment.EditTextDialogInterface,
|
||||
ChooseBookmarkCategoryAdapter.CategoryListener
|
||||
|
@ -27,7 +30,7 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmDialogFragment
|
|||
|
||||
public interface Listener
|
||||
{
|
||||
void onCategoryChanged(long newCategoryId);
|
||||
void onCategoryChanged(BookmarkCategory newCategory);
|
||||
}
|
||||
private Listener mListener;
|
||||
|
||||
|
@ -89,14 +92,22 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmDialogFragment
|
|||
}
|
||||
|
||||
|
||||
/*FIXME*/
|
||||
private void createCategory(@NonNull String name)
|
||||
{
|
||||
final long categoryId = BookmarkManager.INSTANCE.createCategory(name);
|
||||
final int categoryPosition = BookmarkManager.INSTANCE.getCategoriesCount() - 1;
|
||||
|
||||
List<BookmarkCategory> bookmarkCategories = mAdapter.getBookmarkCategories();
|
||||
|
||||
final int categoryPosition = bookmarkCategories.size() - 1;
|
||||
|
||||
mAdapter.chooseItem(categoryPosition);
|
||||
|
||||
if (mListener != null)
|
||||
mListener.onCategoryChanged(categoryId);
|
||||
{
|
||||
BookmarkCategory newCategory = bookmarkCategories.get(categoryPosition);
|
||||
mListener.onCategoryChanged(newCategory);
|
||||
}
|
||||
dismiss();
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.BM_GROUP_CREATED);
|
||||
}
|
||||
|
@ -107,8 +118,8 @@ public class ChooseBookmarkCategoryFragment extends BaseMwmDialogFragment
|
|||
mAdapter.chooseItem(categoryPosition);
|
||||
if (mListener != null)
|
||||
{
|
||||
final long categoryId = BookmarkManager.INSTANCE.getCategoryIdByPosition(categoryPosition);
|
||||
mListener.onCategoryChanged(categoryId);
|
||||
final BookmarkCategory category = mAdapter.getBookmarkCategories().get(categoryPosition);
|
||||
mListener.onCategoryChanged(category);
|
||||
}
|
||||
dismiss();
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.BM_GROUP_CHANGED);
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.location.Location;
|
|||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.PluralsRes;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
|
@ -12,6 +13,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkInfo;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
|
||||
|
@ -32,9 +34,28 @@ public class Holders
|
|||
static class GeneralViewHolder extends RecyclerView.ViewHolder
|
||||
{
|
||||
|
||||
@NonNull
|
||||
private final TextView mText;
|
||||
@NonNull
|
||||
private final ImageView mImage;
|
||||
|
||||
GeneralViewHolder(@NonNull View itemView)
|
||||
{
|
||||
super(itemView);
|
||||
mImage = itemView.findViewById(R.id.image);
|
||||
mText = itemView.findViewById(R.id.text);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TextView getText()
|
||||
{
|
||||
return mText;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ImageView getImage()
|
||||
{
|
||||
return mImage;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,28 +63,38 @@ public class Holders
|
|||
{
|
||||
@NonNull
|
||||
private TextView mButton;
|
||||
@NonNull
|
||||
private TextView mText;
|
||||
|
||||
|
||||
HeaderViewHolder(@NonNull View itemView)
|
||||
{
|
||||
super(itemView);
|
||||
mButton = itemView.findViewById(R.id.button);
|
||||
mText = itemView.findViewById(R.id.text_message);
|
||||
}
|
||||
|
||||
void setAction(@Nullable HeaderAction action, final boolean showAll)
|
||||
@NonNull
|
||||
public TextView getText()
|
||||
{
|
||||
mButton.setText(showAll ? R.string.bookmarks_groups_show_all :
|
||||
R.string.bookmarks_groups_hide_all);
|
||||
mButton.setOnClickListener
|
||||
(v ->
|
||||
{
|
||||
if (action == null)
|
||||
return;
|
||||
return mText;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TextView getButton()
|
||||
{
|
||||
return mButton;
|
||||
}
|
||||
|
||||
void setAction(@NonNull HeaderAction action,
|
||||
@NonNull AdapterResourceProvider resProvider,
|
||||
final boolean showAll)
|
||||
{
|
||||
mButton.setText(showAll
|
||||
? resProvider.getHeaderBtn().getSelectModeText()
|
||||
: resProvider.getHeaderBtn().getUnSelectModeText());
|
||||
mButton.setOnClickListener(new ToggleShowAllClickListener(action, showAll));
|
||||
|
||||
if (showAll)
|
||||
action.onShowAll();
|
||||
else
|
||||
action.onHideAll();
|
||||
});
|
||||
}
|
||||
|
||||
public interface HeaderAction
|
||||
|
@ -71,6 +102,27 @@ public class Holders
|
|||
void onHideAll();
|
||||
void onShowAll();
|
||||
}
|
||||
|
||||
private static class ToggleShowAllClickListener implements View.OnClickListener
|
||||
{
|
||||
private final HeaderAction mAction;
|
||||
private final boolean mShowAll;
|
||||
|
||||
ToggleShowAllClickListener(@NonNull HeaderAction action, boolean showAll)
|
||||
{
|
||||
mAction = action;
|
||||
mShowAll = showAll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if (mShowAll)
|
||||
mAction.onShowAll();
|
||||
else
|
||||
mAction.onHideAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class CategoryViewHolder extends RecyclerView.ViewHolder
|
||||
|
@ -83,6 +135,10 @@ public class Holders
|
|||
TextView mSize;
|
||||
@NonNull
|
||||
View mMore;
|
||||
@NonNull
|
||||
TextView mAuthorName;
|
||||
@NonNull
|
||||
private BookmarkCategory mEntity;
|
||||
|
||||
CategoryViewHolder(@NonNull View root)
|
||||
{
|
||||
|
@ -94,6 +150,7 @@ public class Holders
|
|||
UiUtils.expandTouchAreaForView(mVisibilityMarker, 0, left, 0, right);
|
||||
mSize = root.findViewById(R.id.size);
|
||||
mMore = root.findViewById(R.id.more);
|
||||
mAuthorName = root.findViewById(R.id.author_name);
|
||||
}
|
||||
|
||||
void setVisibilityState(boolean visible)
|
||||
|
@ -116,9 +173,26 @@ public class Holders
|
|||
mName.setText(name);
|
||||
}
|
||||
|
||||
void setSize(int size)
|
||||
void setSize(@PluralsRes int phrase, int size)
|
||||
{
|
||||
mSize.setText(mSize.getResources().getQuantityString(R.plurals.bookmarks_places, size, size));
|
||||
mSize.setText(mSize.getResources().getQuantityString(phrase, size, size));
|
||||
}
|
||||
|
||||
void setCategory(@NonNull BookmarkCategory entity)
|
||||
{
|
||||
mEntity = entity;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public BookmarkCategory getEntity()
|
||||
{
|
||||
return mEntity;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TextView getAuthorName()
|
||||
{
|
||||
return mAuthorName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,6 +200,7 @@ public class Holders
|
|||
{
|
||||
static final int SECTION_TRACKS = 0;
|
||||
static final int SECTION_BMKS = 1;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({ SECTION_TRACKS, SECTION_BMKS })
|
||||
public @interface Section {}
|
||||
|
@ -270,8 +345,11 @@ public class Holders
|
|||
position - 1);
|
||||
Track track = BookmarkManager.INSTANCE.getTrack(trackId);
|
||||
mName.setText(track.getName());
|
||||
mDistance.setText(mDistance.getContext().getString(R.string.length)
|
||||
+ " " + track.getLengthString());
|
||||
mDistance.setText(new StringBuilder().append(mDistance.getContext()
|
||||
.getString(R.string.length))
|
||||
.append(" ")
|
||||
.append(track.getLengthString())
|
||||
.toString());
|
||||
Drawable circle = Graphics.drawCircle(track.getColor(), R.dimen.track_circle_size,
|
||||
mIcon.getContext().getResources());
|
||||
mIcon.setImageDrawable(circle);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public interface OnItemClickListener<T>
|
||||
{
|
||||
void onItemClick(View v, T item);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.mapswithme.maps.bookmarks;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public interface OnItemLongClickListener<T>
|
||||
{
|
||||
void onItemLongClick(View v, T item);
|
||||
}
|
|
@ -4,6 +4,8 @@ import android.annotation.TargetApi;
|
|||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -23,6 +25,7 @@ import com.mapswithme.util.UiUtils;
|
|||
|
||||
public class PlaceholderView extends FrameLayout
|
||||
{
|
||||
public static final int STUB_VALUE_RES_ID = -1;
|
||||
@Nullable
|
||||
private ImageView mImage;
|
||||
@Nullable
|
||||
|
@ -38,6 +41,12 @@ public class PlaceholderView extends FrameLayout
|
|||
private float mScreenWidth;
|
||||
|
||||
private int mOrientation;
|
||||
@DrawableRes
|
||||
private int mImgSrcDefault;
|
||||
@StringRes
|
||||
private int mTitleResIdDefault;
|
||||
@StringRes
|
||||
private int mSubtitleResIdDefault;
|
||||
|
||||
public PlaceholderView(Context context)
|
||||
{
|
||||
|
@ -53,7 +62,7 @@ public class PlaceholderView extends FrameLayout
|
|||
{
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
init(context);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
|
@ -61,11 +70,10 @@ public class PlaceholderView extends FrameLayout
|
|||
int defStyleRes)
|
||||
{
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
|
||||
init(context);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context)
|
||||
private void init(Context context, AttributeSet attrs)
|
||||
{
|
||||
Resources res = getResources();
|
||||
mImageSizeFull = res.getDimension(R.dimen.placeholder_size);
|
||||
|
@ -75,6 +83,27 @@ public class PlaceholderView extends FrameLayout
|
|||
mScreenHeight = res.getDisplayMetrics().heightPixels;
|
||||
mScreenWidth = res.getDisplayMetrics().widthPixels;
|
||||
LayoutInflater.from(context).inflate(R.layout.placeholder, this, true);
|
||||
|
||||
initDefaultValues(context, attrs);
|
||||
}
|
||||
|
||||
private void initDefaultValues(Context context, AttributeSet attrs)
|
||||
{
|
||||
TypedArray attrsArray = null;
|
||||
try
|
||||
{
|
||||
attrsArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PlaceholderView, 0, 0);
|
||||
mImgSrcDefault = attrsArray.getResourceId(R.styleable.PlaceholderView_imgSrcDefault, STUB_VALUE_RES_ID);
|
||||
mTitleResIdDefault = attrsArray.getResourceId(R.styleable.PlaceholderView_titleDefault, STUB_VALUE_RES_ID);
|
||||
mSubtitleResIdDefault = attrsArray.getResourceId(R.styleable.PlaceholderView_subTitleDefault, STUB_VALUE_RES_ID);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (attrsArray != null)
|
||||
{
|
||||
attrsArray.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,21 +115,29 @@ public class PlaceholderView extends FrameLayout
|
|||
mTitle = (TextView) findViewById(R.id.title);
|
||||
mSubtitle = (TextView) findViewById(R.id.subtitle);
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener()
|
||||
setupDefaultContent();
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this, new ApplyWindowInsetsListener());
|
||||
}
|
||||
|
||||
private void setupDefaultContent()
|
||||
{
|
||||
if (isDefaultValueAllowed(mImage, mImgSrcDefault))
|
||||
{
|
||||
@Override
|
||||
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets)
|
||||
{
|
||||
int height = (int) (mOrientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
? mScreenWidth : mScreenHeight);
|
||||
int[] location = new int[2];
|
||||
getLocationOnScreen(location);
|
||||
ViewGroup.LayoutParams lp = getLayoutParams();
|
||||
lp.height = height - insets.getSystemWindowInsetBottom() - location[1];
|
||||
setLayoutParams(lp);
|
||||
return insets;
|
||||
}
|
||||
});
|
||||
mImage.setImageResource(mImgSrcDefault);
|
||||
}
|
||||
if (isDefaultValueAllowed(mTitle, mTitleResIdDefault))
|
||||
{
|
||||
|
||||
mTitle.setText(mTitleResIdDefault);
|
||||
}
|
||||
if (isDefaultValueAllowed(mSubtitle, mSubtitleResIdDefault))
|
||||
{
|
||||
mSubtitle.setText(mSubtitleResIdDefault);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDefaultValueAllowed(View view, int resId){
|
||||
return view != null && resId != STUB_VALUE_RES_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -161,4 +198,20 @@ public class PlaceholderView extends FrameLayout
|
|||
if (mSubtitle != null)
|
||||
mSubtitle.setText(subtitleRes);
|
||||
}
|
||||
|
||||
private class ApplyWindowInsetsListener implements android.support.v4.view.OnApplyWindowInsetsListener
|
||||
{
|
||||
@Override
|
||||
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets)
|
||||
{
|
||||
int height = (int) (mOrientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
? mScreenWidth : mScreenHeight);
|
||||
int[] location = new int[2];
|
||||
getLocationOnScreen(location);
|
||||
ViewGroup.LayoutParams lp = getLayoutParams();
|
||||
lp.height = height - insets.getSystemWindowInsetBottom() - location[1];
|
||||
setLayoutParams(lp);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,11 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.base.BaseMwmDialogFragment;
|
||||
import com.mapswithme.maps.bookmarks.ChooseBookmarkCategoryFragment;
|
||||
import com.mapswithme.maps.bookmarks.ChooseBookmarkCategoryFragment.Listener;
|
||||
import com.mapswithme.maps.bookmarks.data.AbstractCategoriesSnapshot;
|
||||
import com.mapswithme.maps.bookmarks.data.Bookmark;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.FilterStrategy;
|
||||
import com.mapswithme.maps.bookmarks.data.Icon;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
@ -35,8 +38,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||
private EditText mEtName;
|
||||
private TextView mTvBookmarkGroup;
|
||||
private ImageView mIvColor;
|
||||
private int mCategoryPosition;
|
||||
private long mCategoryId;
|
||||
private BookmarkCategory mBookmarkCategory;
|
||||
@Nullable
|
||||
private Icon mIcon;
|
||||
@Nullable
|
||||
|
@ -82,8 +84,8 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||
public void onViewCreated(@NonNull View view, Bundle savedInstanceState)
|
||||
{
|
||||
final Bundle args = getArguments();
|
||||
mCategoryId = args.getLong(EXTRA_CATEGORY_ID);
|
||||
mCategoryPosition = BookmarkManager.INSTANCE.getCategoryPositionById(mCategoryId);
|
||||
long categoryId = args.getLong(EXTRA_CATEGORY_ID);
|
||||
mBookmarkCategory = BookmarkManager.INSTANCE.getCategoryById(categoryId);
|
||||
long bookmarkId = args.getLong(EXTRA_BOOKMARK_ID);
|
||||
mBookmark = BookmarkManager.INSTANCE.getBookmark(bookmarkId);
|
||||
mIcon = mBookmark.getIcon();
|
||||
|
@ -129,9 +131,9 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||
dismiss();
|
||||
return;
|
||||
}
|
||||
if (mBookmark.getCategoryId() != mCategoryId)
|
||||
if (mBookmark.getCategoryId() != mBookmarkCategory.getId())
|
||||
{
|
||||
mBookmark.setCategoryId(mCategoryId);
|
||||
mBookmark.setCategoryId(mBookmarkCategory.getId());
|
||||
Framework.nativeOnBookmarkCategoryChanged(mBookmark.getCategoryId(), mBookmark.getBookmarkId());
|
||||
}
|
||||
mBookmark.setParams(mEtName.getText().toString(), mIcon, mEtDescription.getText().toString());
|
||||
|
@ -161,9 +163,19 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||
return;
|
||||
|
||||
final Bundle args = new Bundle();
|
||||
args.putInt(ChooseBookmarkCategoryFragment.CATEGORY_POSITION, mCategoryPosition);
|
||||
final ChooseBookmarkCategoryFragment fragment = (ChooseBookmarkCategoryFragment) Fragment.instantiate(getActivity(), ChooseBookmarkCategoryFragment.class.getName(), args);
|
||||
fragment.show(getChildFragmentManager(), null);
|
||||
FilterStrategy strategy = mBookmarkCategory.getType()
|
||||
.getFilterStrategy();
|
||||
AbstractCategoriesSnapshot.Default snapshot = BookmarkManager
|
||||
.INSTANCE
|
||||
.getCategoriesSnapshot(strategy);
|
||||
final int index = snapshot.indexOfOrThrow(mBookmarkCategory);
|
||||
args.putInt(ChooseBookmarkCategoryFragment.CATEGORY_POSITION, index);
|
||||
String className = ChooseBookmarkCategoryFragment.class.getName();
|
||||
ChooseBookmarkCategoryFragment frag = (ChooseBookmarkCategoryFragment) Fragment.instantiate(
|
||||
getActivity(),
|
||||
className,
|
||||
args);
|
||||
frag.show(getChildFragmentManager(), null);
|
||||
}
|
||||
|
||||
private void selectBookmarkColor()
|
||||
|
@ -204,7 +216,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||
|
||||
private void refreshCategory()
|
||||
{
|
||||
mTvBookmarkGroup.setText(BookmarkManager.INSTANCE.getCategoryName(mCategoryId));
|
||||
mTvBookmarkGroup.setText(mBookmarkCategory.getName());
|
||||
}
|
||||
|
||||
private void refreshBookmark()
|
||||
|
@ -222,9 +234,9 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCategoryChanged(long newCategoryId)
|
||||
public void onCategoryChanged(BookmarkCategory newCategory)
|
||||
{
|
||||
mCategoryId = newCategoryId;
|
||||
mBookmarkCategory = newCategory;
|
||||
refreshCategory();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,9 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class PlacePageButtons
|
||||
import static com.mapswithme.maps.widget.placepage.PlacePageButtons.PARTNERS_ITEMS;
|
||||
|
||||
public final class PlacePageButtons
|
||||
{
|
||||
private static final Map<Integer, PartnerItem> PARTNERS_ITEMS = new HashMap<Integer, PartnerItem>()
|
||||
{{
|
||||
|
@ -51,21 +53,74 @@ final class PlacePageButtons
|
|||
private final ViewGroup mFrame;
|
||||
private final ItemListener mItemListener;
|
||||
|
||||
private List<ButtonInterface> mPrevItems;
|
||||
private List<PlacePageButton> mPrevItems;
|
||||
|
||||
interface ButtonInterface
|
||||
interface PlacePageButton
|
||||
{
|
||||
@StringRes
|
||||
int getTitle();
|
||||
|
||||
@DrawableRes
|
||||
int getIcon();
|
||||
ImageResources getIcon();
|
||||
|
||||
@NonNull
|
||||
ButtonType getType();
|
||||
|
||||
@DrawableRes
|
||||
int getBackgroundResource();
|
||||
|
||||
class ImageResources
|
||||
{
|
||||
@DrawableRes
|
||||
private final int mEnabledStateResId;
|
||||
@DrawableRes
|
||||
private final int mDisabledStateResId;
|
||||
|
||||
public ImageResources(int enabledStateResId,
|
||||
int disabledStateResId)
|
||||
{
|
||||
mEnabledStateResId = enabledStateResId;
|
||||
mDisabledStateResId = disabledStateResId;
|
||||
}
|
||||
|
||||
public ImageResources(int enabledStateResId)
|
||||
{
|
||||
this(enabledStateResId, enabledStateResId);
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getDisabledStateResId()
|
||||
{
|
||||
return mDisabledStateResId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getEnabledStateResId()
|
||||
{
|
||||
return mEnabledStateResId;
|
||||
}
|
||||
|
||||
public static class Stub extends ImageResources
|
||||
{
|
||||
private static final int STUB_RES_ID = -1;
|
||||
|
||||
public Stub()
|
||||
{
|
||||
super(STUB_RES_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDisabledStateResId()
|
||||
{
|
||||
throw new UnsupportedOperationException("not supported here");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnabledStateResId()
|
||||
{
|
||||
throw new UnsupportedOperationException("not supported here");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ButtonType
|
||||
|
@ -77,54 +132,119 @@ final class PlacePageButtons
|
|||
ROUTE_FROM, ROUTE_TO, ROUTE_ADD, ROUTE_REMOVE, SHARE, MORE, CALL
|
||||
}
|
||||
|
||||
private enum PartnerItem implements ButtonInterface
|
||||
{
|
||||
PARTNER1(1, R.string.sponsored_partner1_action,
|
||||
R.drawable.ic_24px_logo_partner1, R.drawable.button_partner1, ButtonType.PARTNER1),
|
||||
PARTNER3(3, R.string.sponsored_partner3_action,
|
||||
R.drawable.ic_24px_logo_partner3, R.drawable.button_partner3, ButtonType.PARTNER3),
|
||||
PARTNER4(4, R.string.sponsored_partner4_action,
|
||||
R.drawable.ic_24px_logo_partner4, R.drawable.button_partner4, ButtonType.PARTNER4),
|
||||
PARTNER5(5, R.string.sponsored_partner5_action,
|
||||
R.drawable.ic_24px_logo_partner5, R.drawable.button_partner5, ButtonType.PARTNER5),
|
||||
PARTNER6(6, R.string.sponsored_partner6_action,
|
||||
R.drawable.ic_24px_logo_partner6, R.drawable.button_partner6, ButtonType.PARTNER6),
|
||||
PARTNER7(7, R.string.sponsored_partner7_action,
|
||||
R.drawable.ic_24px_logo_partner7, R.drawable.button_partner7, ButtonType.PARTNER7),
|
||||
PARTNER8(8, R.string.sponsored_partner8_action,
|
||||
R.drawable.ic_24px_logo_partner8, R.drawable.button_partner8, ButtonType.PARTNER8),
|
||||
PARTNER9(9, R.string.sponsored_partner9_action,
|
||||
R.drawable.ic_24px_logo_partner9, R.drawable.button_partner9, ButtonType.PARTNER9),
|
||||
PARTNER10(10, R.string.sponsored_partner10_action,
|
||||
R.drawable.ic_24px_logo_partner10, R.drawable.button_partner10, ButtonType.PARTNER10),
|
||||
PARTNER11(11, R.string.sponsored_partner11_action,
|
||||
R.drawable.ic_24px_logo_partner11, R.drawable.button_partner11, ButtonType.PARTNER11),
|
||||
PARTNER12(12, R.string.sponsored_partner12_action,
|
||||
R.drawable.ic_24px_logo_partner12, R.drawable.button_partner12, ButtonType.PARTNER12),
|
||||
PARTNER13(13, R.string.sponsored_partner13_action,
|
||||
R.drawable.ic_24px_logo_partner13, R.drawable.button_partner13, ButtonType.PARTNER13),
|
||||
PARTNER14(14, R.string.sponsored_partner14_action,
|
||||
R.drawable.ic_24px_logo_partner14, R.drawable.button_partner14, ButtonType.PARTNER14),
|
||||
PARTNER15(15, R.string.sponsored_partner15_action,
|
||||
R.drawable.ic_24px_logo_partner15, R.drawable.button_partner15, ButtonType.PARTNER15),
|
||||
PARTNER16(16, R.string.sponsored_partner16_action,
|
||||
R.drawable.ic_24px_logo_partner16, R.drawable.button_partner16, ButtonType.PARTNER16),
|
||||
PARTNER17(17, R.string.sponsored_partner17_action,
|
||||
R.drawable.ic_24px_logo_partner17, R.drawable.button_partner17, ButtonType.PARTNER17);
|
||||
enum PartnerItem implements PlacePageButtons.PlacePageButton {
|
||||
PARTNER1(
|
||||
1,
|
||||
R.string.sponsored_partner1_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner1),
|
||||
R.drawable.button_partner1,
|
||||
ButtonType.PARTNER1),
|
||||
PARTNER3(
|
||||
3,
|
||||
R.string.sponsored_partner3_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner3),
|
||||
R.drawable.button_partner3,
|
||||
ButtonType.PARTNER3),
|
||||
PARTNER4(
|
||||
4,
|
||||
R.string.sponsored_partner4_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner4),
|
||||
R.drawable.button_partner4,
|
||||
ButtonType.PARTNER4),
|
||||
PARTNER5(
|
||||
5,
|
||||
R.string.sponsored_partner5_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner5),
|
||||
R.drawable.button_partner5,
|
||||
ButtonType.PARTNER5),
|
||||
PARTNER6(
|
||||
6,
|
||||
R.string.sponsored_partner6_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner6),
|
||||
R.drawable.button_partner6,
|
||||
ButtonType.PARTNER6),
|
||||
PARTNER7(
|
||||
7,
|
||||
R.string.sponsored_partner7_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner7),
|
||||
R.drawable.button_partner7,
|
||||
ButtonType.PARTNER7),
|
||||
PARTNER8(
|
||||
8,
|
||||
R.string.sponsored_partner8_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner8),
|
||||
R.drawable.button_partner8,
|
||||
ButtonType.PARTNER8),
|
||||
PARTNER9(
|
||||
9,
|
||||
R.string.sponsored_partner9_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner9),
|
||||
R.drawable.button_partner9,
|
||||
ButtonType.PARTNER9),
|
||||
PARTNER10(
|
||||
10,
|
||||
R.string.sponsored_partner10_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner10),
|
||||
R.drawable.button_partner10,
|
||||
ButtonType.PARTNER10),
|
||||
PARTNER11(
|
||||
11,
|
||||
R.string.sponsored_partner11_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner11),
|
||||
R.drawable.button_partner11,
|
||||
ButtonType.PARTNER11),
|
||||
PARTNER12(
|
||||
12,
|
||||
R.string.sponsored_partner12_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner12),
|
||||
R.drawable.button_partner12,
|
||||
ButtonType.PARTNER12),
|
||||
PARTNER13(
|
||||
13,
|
||||
R.string.sponsored_partner13_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner13),
|
||||
R.drawable.button_partner13,
|
||||
ButtonType.PARTNER13),
|
||||
PARTNER14(
|
||||
14,
|
||||
R.string.sponsored_partner14_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner14),
|
||||
R.drawable.button_partner14,
|
||||
ButtonType.PARTNER14),
|
||||
PARTNER15(
|
||||
15,
|
||||
R.string.sponsored_partner15_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner15),
|
||||
R.drawable.button_partner15,
|
||||
ButtonType.PARTNER15),
|
||||
PARTNER16(
|
||||
16,
|
||||
R.string.sponsored_partner16_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner16),
|
||||
R.drawable.button_partner16,
|
||||
ButtonType.PARTNER16),
|
||||
PARTNER17(
|
||||
17,
|
||||
R.string.sponsored_partner17_action,
|
||||
new ImageResources(R.drawable.ic_24px_logo_partner17),
|
||||
R.drawable.button_partner17,
|
||||
ButtonType.PARTNER17);
|
||||
|
||||
private final int mIndex;
|
||||
@StringRes
|
||||
private final int mTitleId;
|
||||
@DrawableRes
|
||||
private final int mIconId;
|
||||
private final ImageResources mIconId;
|
||||
@DrawableRes
|
||||
private final int mBackgroundId;
|
||||
@NonNull
|
||||
private final ButtonType mButtonType;
|
||||
|
||||
PartnerItem(int index, @StringRes int titleId, @DrawableRes int iconId,
|
||||
@DrawableRes int backgroundId, @NonNull ButtonType buttonType)
|
||||
{
|
||||
PartnerItem(
|
||||
int index,
|
||||
@StringRes int titleId,
|
||||
@NonNull ImageResources iconId,
|
||||
@DrawableRes int backgroundId,
|
||||
@NonNull ButtonType buttonType) {
|
||||
mIndex = index;
|
||||
mTitleId = titleId;
|
||||
mIconId = iconId;
|
||||
|
@ -132,104 +252,115 @@ final class PlacePageButtons
|
|||
mButtonType = buttonType;
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
public int getIndex() {
|
||||
return mIndex;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
@Override
|
||||
public int getTitle()
|
||||
{
|
||||
public int getTitle() {
|
||||
return mTitleId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
@NonNull
|
||||
@Override
|
||||
public int getIcon()
|
||||
{
|
||||
public ImageResources getIcon() {
|
||||
return mIconId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ButtonType getType()
|
||||
{
|
||||
public ButtonType getType() {
|
||||
return mButtonType;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
@Override
|
||||
public int getBackgroundResource()
|
||||
{
|
||||
public int getBackgroundResource() {
|
||||
return mBackgroundId;
|
||||
}
|
||||
}
|
||||
|
||||
enum Item implements ButtonInterface
|
||||
{
|
||||
BOOKING(R.string.book_button, R.drawable.ic_booking, ButtonType.BOOKING)
|
||||
{
|
||||
enum Item implements PlacePageButtons.PlacePageButton {
|
||||
BOOKING(R.string.book_button, new ImageResources(R.drawable.ic_booking), ButtonType.BOOKING) {
|
||||
@DrawableRes
|
||||
@Override
|
||||
public int getBackgroundResource()
|
||||
{
|
||||
public int getBackgroundResource() {
|
||||
return R.drawable.button_booking;
|
||||
}
|
||||
},
|
||||
|
||||
BOOKING_SEARCH(R.string.booking_search, R.drawable.ic_menu_search, ButtonType.BOOKING_SEARCH)
|
||||
{
|
||||
BOOKING_SEARCH(
|
||||
R.string.booking_search,
|
||||
new ImageResources(R.drawable.ic_menu_search),
|
||||
ButtonType.BOOKING_SEARCH) {
|
||||
@DrawableRes
|
||||
@Override
|
||||
public int getBackgroundResource()
|
||||
{
|
||||
public int getBackgroundResource() {
|
||||
return R.drawable.button_booking;
|
||||
}
|
||||
},
|
||||
|
||||
OPENTABLE(R.string.book_button, R.drawable.ic_opentable, ButtonType.OPENTABLE)
|
||||
{
|
||||
OPENTABLE(
|
||||
R.string.book_button, new ImageResources(R.drawable.ic_opentable), ButtonType.OPENTABLE) {
|
||||
@DrawableRes
|
||||
@Override
|
||||
public int getBackgroundResource()
|
||||
{
|
||||
public int getBackgroundResource() {
|
||||
return R.drawable.button_opentable;
|
||||
}
|
||||
},
|
||||
|
||||
BACK(R.string.back, ThemeUtils.getResource(MwmApplication.get(),
|
||||
android.R.attr.homeAsUpIndicator), ButtonType.BACK),
|
||||
BACK(
|
||||
R.string.back,
|
||||
/*FIXME*/
|
||||
new ImageResources.Stub() {
|
||||
@Override
|
||||
public int getEnabledStateResId() {
|
||||
return ThemeUtils.getResource(MwmApplication.get(), android.R.attr.homeAsUpIndicator);
|
||||
}
|
||||
} /**/,
|
||||
ButtonType.BACK),
|
||||
|
||||
BOOKMARK(R.string.bookmark, R.drawable.ic_bookmarks_off, ButtonType.BOOKMARK),
|
||||
BOOKMARK(
|
||||
R.string.bookmark, new ImageResources(R.drawable.ic_bookmarks_off), ButtonType.BOOKMARK),
|
||||
|
||||
ROUTE_FROM(R.string.p2p_from_here, R.drawable.ic_route_from, ButtonType.ROUTE_FROM),
|
||||
ROUTE_FROM(
|
||||
R.string.p2p_from_here,
|
||||
new ImageResources(R.drawable.ic_route_from),
|
||||
ButtonType.ROUTE_FROM),
|
||||
|
||||
ROUTE_TO(R.string.p2p_to_here, R.drawable.ic_route_to, ButtonType.ROUTE_TO),
|
||||
ROUTE_TO(R.string.p2p_to_here, new ImageResources(R.drawable.ic_route_to), ButtonType.ROUTE_TO),
|
||||
|
||||
ROUTE_ADD(R.string.placepage_add_stop, R.drawable.ic_route_via, ButtonType.ROUTE_ADD),
|
||||
ROUTE_ADD(
|
||||
R.string.placepage_add_stop,
|
||||
new ImageResources(R.drawable.ic_route_via),
|
||||
ButtonType.ROUTE_ADD),
|
||||
|
||||
ROUTE_REMOVE(R.string.placepage_remove_stop, R.drawable.ic_route_remove,
|
||||
ROUTE_REMOVE(
|
||||
R.string.placepage_remove_stop,
|
||||
new ImageResources(R.drawable.ic_route_remove),
|
||||
ButtonType.ROUTE_REMOVE),
|
||||
|
||||
SHARE(R.string.share, R.drawable.ic_share, ButtonType.SHARE),
|
||||
SHARE(R.string.share, new ImageResources(R.drawable.ic_share), ButtonType.SHARE),
|
||||
|
||||
// Must not be used outside
|
||||
MORE(R.string.placepage_more_button, R.drawable.bs_ic_more, ButtonType.MORE),
|
||||
MORE(
|
||||
R.string.placepage_more_button, new ImageResources(R.drawable.bs_ic_more), ButtonType.MORE),
|
||||
|
||||
CALL(R.string.placepage_call_button, R.drawable.ic_place_page_phone, ButtonType.CALL);
|
||||
CALL(
|
||||
R.string.placepage_call_button,
|
||||
new ImageResources(R.drawable.ic_place_page_phone),
|
||||
ButtonType.CALL);
|
||||
|
||||
@StringRes
|
||||
private final int mTitleId;
|
||||
@StringRes private final int mTitleId;
|
||||
|
||||
@DrawableRes
|
||||
private final int mIconId;
|
||||
@NonNull private final ImageResources mIconId;
|
||||
|
||||
@NonNull
|
||||
private final ButtonType mButtonType;
|
||||
@NonNull private final ButtonType mButtonType;
|
||||
|
||||
Item(@StringRes int titleId, @DrawableRes int iconId, @NonNull ButtonType buttonType)
|
||||
{
|
||||
Item(@StringRes int titleId,
|
||||
@NonNull ImageResources iconId,
|
||||
@NonNull ButtonType buttonType) {
|
||||
mTitleId = titleId;
|
||||
mIconId = iconId;
|
||||
mButtonType = buttonType;
|
||||
|
@ -237,37 +368,33 @@ final class PlacePageButtons
|
|||
|
||||
@StringRes
|
||||
@Override
|
||||
public int getTitle()
|
||||
{
|
||||
public int getTitle() {
|
||||
return mTitleId;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
@NonNull
|
||||
@Override
|
||||
public int getIcon()
|
||||
{
|
||||
public ImageResources getIcon() {
|
||||
return mIconId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ButtonType getType()
|
||||
{
|
||||
public ButtonType getType() {
|
||||
return mButtonType;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
@Override
|
||||
public int getBackgroundResource()
|
||||
{
|
||||
public int getBackgroundResource() {
|
||||
throw new UnsupportedOperationException("Not supported!");
|
||||
}
|
||||
}
|
||||
|
||||
interface ItemListener
|
||||
{
|
||||
void onPrepareVisibleView(ButtonInterface item, View frame, ImageView icon, TextView title);
|
||||
void onItemClick(ButtonInterface item);
|
||||
void onPrepareVisibleView(PlacePageButtons.PlacePageButton item, View frame, ImageView icon, TextView title);
|
||||
void onItemClick(PlacePageButtons.PlacePageButton item);
|
||||
}
|
||||
|
||||
PlacePageButtons(PlacePageView placePage, ViewGroup frame, ItemListener itemListener)
|
||||
|
@ -280,17 +407,17 @@ final class PlacePageButtons
|
|||
}
|
||||
|
||||
@NonNull
|
||||
static ButtonInterface getPartnerItem(int partnerIndex)
|
||||
static PlacePageButtons.PlacePageButton getPartnerItem(int partnerIndex)
|
||||
{
|
||||
ButtonInterface item = PARTNERS_ITEMS.get(partnerIndex);
|
||||
PlacePageButtons.PlacePageButton item = PARTNERS_ITEMS.get(partnerIndex);
|
||||
if (item == null)
|
||||
throw new AssertionError("Wrong partner index: " + partnerIndex);
|
||||
return item;
|
||||
}
|
||||
|
||||
private @NonNull List<ButtonInterface> collectButtons(List<ButtonInterface> items)
|
||||
private @NonNull List<PlacePageButtons.PlacePageButton> collectButtons(List<PlacePageButtons.PlacePageButton> items)
|
||||
{
|
||||
List<ButtonInterface> res = new ArrayList<>(items);
|
||||
List<PlacePageButtons.PlacePageButton> res = new ArrayList<>(items);
|
||||
if (res.size() > mMaxButtons)
|
||||
res.add(mMaxButtons - 1, Item.MORE);
|
||||
|
||||
|
@ -322,7 +449,7 @@ final class PlacePageButtons
|
|||
return res;
|
||||
}
|
||||
|
||||
private void preserveRoutingButtons(@NonNull List<ButtonInterface> items, @NonNull Item itemToShift)
|
||||
private void preserveRoutingButtons(@NonNull List<PlacePageButton> items, @NonNull Item itemToShift)
|
||||
{
|
||||
if (!RoutingController.get().isNavigating() && !RoutingController.get().isPlanning())
|
||||
return;
|
||||
|
@ -348,13 +475,14 @@ final class PlacePageButtons
|
|||
}
|
||||
}
|
||||
|
||||
private void showPopup(final List<ButtonInterface> buttons)
|
||||
private void showPopup(final List<PlacePageButton> buttons)
|
||||
{
|
||||
BottomSheetHelper.Builder bs = new BottomSheetHelper.Builder(mPlacePage.getActivity());
|
||||
for (int i = mMaxButtons; i < buttons.size(); i++)
|
||||
{
|
||||
ButtonInterface bsItem = buttons.get(i);
|
||||
bs.sheet(i, bsItem.getIcon(), bsItem.getTitle());
|
||||
PlacePageButton bsItem = buttons.get(i);
|
||||
int iconRes = bsItem.getIcon().getEnabledStateResId();
|
||||
bs.sheet(i, iconRes, bsItem.getTitle());
|
||||
}
|
||||
|
||||
bs.listener(new MenuItem.OnMenuItemClickListener()
|
||||
|
@ -370,36 +498,24 @@ final class PlacePageButtons
|
|||
bs.tint().show();
|
||||
}
|
||||
|
||||
private View createButton(final List<ButtonInterface> items, final ButtonInterface current)
|
||||
private View createButton(final List<PlacePageButton> items, final PlacePageButton current)
|
||||
{
|
||||
View res = LayoutInflater.from(mPlacePage.getContext()).inflate(R.layout.place_page_button, mFrame, false);
|
||||
LayoutInflater inflater = LayoutInflater.from(mPlacePage.getContext());
|
||||
View parent = inflater.inflate(R.layout.place_page_button, mFrame, false);
|
||||
|
||||
ImageView icon = (ImageView) res.findViewById(R.id.icon);
|
||||
TextView title = (TextView) res.findViewById(R.id.title);
|
||||
ImageView icon = (ImageView) parent.findViewById(R.id.icon);
|
||||
TextView title = (TextView) parent.findViewById(R.id.title);
|
||||
|
||||
icon.setImageResource(current.getIcon());
|
||||
title.setText(current.getTitle());
|
||||
mItemListener.onPrepareVisibleView(current, res, icon, title);
|
||||
|
||||
res.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (current == Item.MORE)
|
||||
showPopup(items);
|
||||
else
|
||||
mItemListener.onItemClick(current);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return res;
|
||||
icon.setImageResource(current.getIcon().getEnabledStateResId());
|
||||
mItemListener.onPrepareVisibleView(current, parent, icon, title);
|
||||
parent.setOnClickListener(new ShowPopupClickListener(current, items));
|
||||
return parent;
|
||||
}
|
||||
|
||||
void setItems(List<ButtonInterface> items)
|
||||
void setItems(List<PlacePageButton> items)
|
||||
{
|
||||
final List<ButtonInterface> buttons = collectButtons(items);
|
||||
final List<PlacePageButton> buttons = collectButtons(items);
|
||||
if (buttons.equals(mPrevItems))
|
||||
return;
|
||||
|
||||
|
@ -410,4 +526,25 @@ final class PlacePageButtons
|
|||
|
||||
mPrevItems = buttons;
|
||||
}
|
||||
|
||||
private class ShowPopupClickListener implements View.OnClickListener
|
||||
{
|
||||
private final PlacePageButton mCurrent;
|
||||
private final List<PlacePageButton> mItems;
|
||||
|
||||
public ShowPopupClickListener(PlacePageButton current, List<PlacePageButton> items)
|
||||
{
|
||||
mCurrent = current;
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (mCurrent == Item.MORE)
|
||||
showPopup(mItems);
|
||||
else
|
||||
mItemListener.onItemClick(mCurrent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,6 +276,8 @@ public class PlacePageView extends RelativeLayout
|
|||
detachCountry();
|
||||
}
|
||||
};
|
||||
@NonNull
|
||||
private final EditBookmarkClickListener mEditBookmarkClickListener = new EditBookmarkClickListener();
|
||||
|
||||
public enum State
|
||||
{
|
||||
|
@ -419,7 +421,7 @@ public class PlacePageView extends RelativeLayout
|
|||
mWvBookmarkNote = (WebView) mBookmarkFrame.findViewById(R.id.wv__bookmark_notes);
|
||||
mWvBookmarkNote.getSettings().setJavaScriptEnabled(false);
|
||||
mTvBookmarkNote = (TextView) mBookmarkFrame.findViewById(R.id.tv__bookmark_notes);
|
||||
mBookmarkFrame.findViewById(R.id.tv__bookmark_edit).setOnClickListener(this);
|
||||
initEditMapObjectBtn();
|
||||
|
||||
ViewGroup ppButtons = (ViewGroup) findViewById(R.id.pp__buttons).findViewById(R.id.container);
|
||||
|
||||
|
@ -449,7 +451,7 @@ public class PlacePageView extends RelativeLayout
|
|||
mButtons = new PlacePageButtons(this, ppButtons, new PlacePageButtons.ItemListener()
|
||||
{
|
||||
@Override
|
||||
public void onPrepareVisibleView(PlacePageButtons.ButtonInterface item, View frame, ImageView icon, TextView title)
|
||||
public void onPrepareVisibleView(PlacePageButtons.PlacePageButton item, View frame, ImageView icon, TextView title)
|
||||
{
|
||||
int color;
|
||||
|
||||
|
@ -480,7 +482,8 @@ public class PlacePageView extends RelativeLayout
|
|||
|
||||
case BOOKMARK:
|
||||
mBookmarkButtonIcon = icon;
|
||||
updateBookmarkButton();
|
||||
updateBookmarkBtn();
|
||||
frame.setEnabled(isEditableMapObject());
|
||||
color = ThemeUtils.getColor(getContext(), R.attr.iconTint);
|
||||
break;
|
||||
|
||||
|
@ -494,7 +497,7 @@ public class PlacePageView extends RelativeLayout
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(PlacePageButtons.ButtonInterface item)
|
||||
public void onItemClick(PlacePageButtons.PlacePageButton item)
|
||||
{
|
||||
switch (item.getType())
|
||||
{
|
||||
|
@ -663,6 +666,34 @@ public class PlacePageView extends RelativeLayout
|
|||
Viator.setViatorListener(this);
|
||||
}
|
||||
|
||||
private void updateCatalogBookmarkBtn()
|
||||
{
|
||||
if (isEditableMapObject() || mBookmarkButtonIcon == null)
|
||||
return;
|
||||
final int resId = PlacePageButtons.Item.BOOKMARK.getIcon().getDisabledStateResId();
|
||||
Drawable drawable = Graphics.tint(getContext(), resId, R.attr.iconTintDisabled);
|
||||
mBookmarkButtonIcon.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
private void initEditMapObjectBtn()
|
||||
{
|
||||
boolean isEditSupported = isEditableMapObject();
|
||||
View editBookmarkBtn = mBookmarkFrame.findViewById(R.id.tv__bookmark_edit);
|
||||
UiUtils.showIf(isEditSupported, editBookmarkBtn);
|
||||
editBookmarkBtn.setOnClickListener(isEditSupported ? mEditBookmarkClickListener : null);
|
||||
}
|
||||
|
||||
public boolean isEditableMapObject()
|
||||
{
|
||||
boolean isBookmark = MapObject.isOfType(MapObject.BOOKMARK, mMapObject);
|
||||
return isBookmark
|
||||
&& BookmarkManager
|
||||
.INSTANCE
|
||||
.isEditableBookmark(Utils
|
||||
.<Bookmark>castTo(mMapObject)
|
||||
.getBookmarkId());
|
||||
}
|
||||
|
||||
private void initHotelRatingView()
|
||||
{
|
||||
mHotelReview = findViewById(R.id.ll__place_hotel_rating);
|
||||
|
@ -1202,6 +1233,7 @@ public class PlacePageView extends RelativeLayout
|
|||
clearSponsoredGalleryViews();
|
||||
clearUGCViews();
|
||||
processSponsored(policy);
|
||||
initEditMapObjectBtn();
|
||||
if (mUgcController != null)
|
||||
mUgcController.getUGC(mMapObject);
|
||||
|
||||
|
@ -1296,7 +1328,7 @@ public class PlacePageView extends RelativeLayout
|
|||
case MapObject.BOOKMARK:
|
||||
refreshDistanceToObject(mapObject, loc);
|
||||
showBookmarkDetails(mapObject);
|
||||
updateBookmarkButton();
|
||||
updateBookmarkBtn();
|
||||
setButtons(mapObject, false, true);
|
||||
break;
|
||||
case MapObject.POI:
|
||||
|
@ -1556,7 +1588,7 @@ public class PlacePageView extends RelativeLayout
|
|||
mTodayOpeningHours.setTextColor(color);
|
||||
}
|
||||
|
||||
private void updateBookmarkButton()
|
||||
private void updateBookmarkBtn()
|
||||
{
|
||||
if (mBookmarkButtonIcon == null)
|
||||
return;
|
||||
|
@ -1565,13 +1597,14 @@ public class PlacePageView extends RelativeLayout
|
|||
mBookmarkButtonIcon.setImageResource(R.drawable.ic_bookmarks_on);
|
||||
else
|
||||
mBookmarkButtonIcon.setImageDrawable(Graphics.tint(getContext(), R.drawable.ic_bookmarks_off, R.attr.iconTint));
|
||||
updateCatalogBookmarkBtn();
|
||||
}
|
||||
|
||||
private void hideBookmarkDetails()
|
||||
{
|
||||
mBookmarkSet = false;
|
||||
UiUtils.hide(mBookmarkFrame);
|
||||
updateBookmarkButton();
|
||||
updateBookmarkBtn();
|
||||
}
|
||||
|
||||
private void showBookmarkDetails(@NonNull MapObject mapObject)
|
||||
|
@ -1604,7 +1637,7 @@ public class PlacePageView extends RelativeLayout
|
|||
|
||||
private void setButtons(@NonNull MapObject mapObject, boolean showBackButton, boolean showRoutingButton)
|
||||
{
|
||||
List<PlacePageButtons.ButtonInterface> buttons = new ArrayList<>();
|
||||
List<PlacePageButtons.PlacePageButton> buttons = new ArrayList<>();
|
||||
if (RoutingController.get().isRoutePoint(mapObject))
|
||||
{
|
||||
buttons.add(PlacePageButtons.Item.ROUTE_REMOVE);
|
||||
|
@ -1848,17 +1881,6 @@ public class PlacePageView extends RelativeLayout
|
|||
case R.id.ll__place_email:
|
||||
Utils.sendTo(getContext(), mTvEmail.getText().toString());
|
||||
break;
|
||||
case R.id.tv__bookmark_edit:
|
||||
if (mMapObject == null)
|
||||
{
|
||||
LOGGER.e(TAG, "A bookmark cannot be edited, mMapObject is null!", new Throwable());
|
||||
return;
|
||||
}
|
||||
Bookmark bookmark = (Bookmark) mMapObject;
|
||||
EditBookmarkFragment.editBookmark(bookmark.getCategoryId(), bookmark.getBookmarkId(),
|
||||
getActivity(), getActivity().getSupportFragmentManager(),
|
||||
this);
|
||||
break;
|
||||
case R.id.tv__place_hotel_more:
|
||||
UiUtils.hide(mHotelMoreDescription);
|
||||
mTvHotelDescription.setMaxLines(Integer.MAX_VALUE);
|
||||
|
@ -2186,4 +2208,24 @@ public class PlacePageView extends RelativeLayout
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
private class EditBookmarkClickListener implements OnClickListener
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if (mMapObject == null)
|
||||
{
|
||||
LOGGER.e(TAG, "A bookmark cannot be edited, mMapObject is null!", new Throwable());
|
||||
return;
|
||||
}
|
||||
Bookmark bookmark = (Bookmark) mMapObject;
|
||||
EditBookmarkFragment.editBookmark(bookmark.getCategoryId(),
|
||||
bookmark.getBookmarkId(),
|
||||
getActivity(),
|
||||
getActivity().getSupportFragmentManager(),
|
||||
PlacePageView.this);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,10 +72,7 @@ public final class BottomSheetHelper
|
|||
@Override
|
||||
public BottomSheet build()
|
||||
{
|
||||
free();
|
||||
|
||||
BottomSheet res = super.build();
|
||||
sRef = new WeakReference<>(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -88,7 +85,6 @@ public final class BottomSheetHelper
|
|||
@Override
|
||||
public void onDismiss(DialogInterface dialog)
|
||||
{
|
||||
free();
|
||||
if (listener != null)
|
||||
listener.onDismiss(dialog);
|
||||
}
|
||||
|
@ -182,46 +178,11 @@ public final class BottomSheetHelper
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private static WeakReference<BottomSheet> sRef;
|
||||
|
||||
|
||||
private BottomSheetHelper()
|
||||
{}
|
||||
|
||||
public static BottomSheet getReference()
|
||||
{
|
||||
if (sRef == null)
|
||||
return null;
|
||||
|
||||
return sRef.get();
|
||||
}
|
||||
|
||||
public static boolean isShowing()
|
||||
{
|
||||
BottomSheet bs = getReference();
|
||||
return (bs != null && bs.isShowing());
|
||||
}
|
||||
|
||||
public static void free()
|
||||
{
|
||||
BottomSheet ref = getReference();
|
||||
if (ref != null)
|
||||
{
|
||||
if (ref.isShowing())
|
||||
{
|
||||
Activity activity = (Activity)((ContextWrapper)ref.getContext()).getBaseContext();
|
||||
if (!activity.isFinishing())
|
||||
ref.dismiss();
|
||||
}
|
||||
|
||||
sRef = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder create(Activity context)
|
||||
{
|
||||
free();
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
|
|