forked from organicmaps/organicmaps
[android] Added some biz fixes for bookmark categories
This commit is contained in:
parent
8b03f2d8de
commit
68d2ece342
8 changed files with 74 additions and 36 deletions
|
@ -4,7 +4,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/height_item_oneline"
|
||||
android:gravity="center"
|
||||
android:background="?clickableBackground">
|
||||
|
||||
<ImageView
|
||||
|
@ -17,28 +16,14 @@
|
|||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:layout_alignParentStart="true"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/more"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:minHeight="@dimen/height_item_edit_bookmark"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingLeft="@dimen/margin_double"
|
||||
android:paddingStart="@dimen/margin_double"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@drawable/ic_more"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:tint="?secondary"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:weightSum="2"
|
||||
android:orientation="vertical"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:layout_toRightOf="@id/iv__bookmark_color"
|
||||
android:layout_toEndOf="@id/iv__bookmark_color"
|
||||
android:layout_marginRight="@dimen/margin_base"
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:lines="3"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.view.ViewGroup;
|
|||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmFragment;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -35,17 +36,42 @@ public class BookmarkCategoriesPagerFragment extends BaseMwmFragment
|
|||
TabLayout tabLayout = root.findViewById(R.id.sliding_tabs_layout);
|
||||
|
||||
FragmentManager fm = getActivity().getSupportFragmentManager();
|
||||
BookmarksPagerAdapter adapter = new BookmarksPagerAdapter(getContext(),
|
||||
fm,
|
||||
prepareAdapterDataSet());
|
||||
List<BookmarksPageFactory> dataSet = getAdapterDataSet();
|
||||
BookmarksPagerAdapter adapter = new BookmarksPagerAdapter(getContext(), fm, dataSet);
|
||||
viewPager.setAdapter(adapter);
|
||||
|
||||
int lastVisibleScreen = SharedPropertiesUtils.getLastVisibleBookmarkCategoriesPage(getActivity());
|
||||
viewPager.setCurrentItem(lastVisibleScreen);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
viewPager.addOnPageChangeListener(new PageChangeListener());
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static List<BookmarksPageFactory> prepareAdapterDataSet()
|
||||
private static List<BookmarksPageFactory> getAdapterDataSet()
|
||||
{
|
||||
return Arrays.asList(BookmarksPageFactory.PRIVATE, BookmarksPageFactory.CATALOG);
|
||||
}
|
||||
|
||||
private class PageChangeListener implements ViewPager.OnPageChangeListener
|
||||
{
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position)
|
||||
{
|
||||
SharedPropertiesUtils.setLastVisibleBookmarkCategoriesPage(getActivity(), position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,14 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
|
|||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url)
|
||||
{
|
||||
return requestArchive(view, url);
|
||||
try
|
||||
{
|
||||
return requestArchive(view, url);
|
||||
}
|
||||
catch (BookmarksDownloadManager.UnprocessedUrlException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,7 +164,8 @@ public class BookmarksCatalogFragment extends BaseWebViewMwmFragment
|
|||
mError = null;
|
||||
}
|
||||
|
||||
private boolean requestArchive(@NonNull WebView view, @NonNull String url)
|
||||
private boolean requestArchive(@NonNull WebView view,
|
||||
@NonNull String url) throws BookmarksDownloadManager.UnprocessedUrlException
|
||||
{
|
||||
BookmarksDownloadManager dm = BookmarksDownloadManager.from(view.getContext());
|
||||
dm.enqueueRequest(url);
|
||||
|
|
|
@ -9,8 +9,6 @@ import android.util.Pair;
|
|||
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class BookmarksDownloadManager
|
||||
{
|
||||
private static final String QUERY_PARAM_ID_KEY = "id";
|
||||
|
@ -24,17 +22,19 @@ public class BookmarksDownloadManager
|
|||
mContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public long enqueueRequest(@NonNull String url)
|
||||
public long enqueueRequest(@NonNull String url) throws UnprocessedUrlException
|
||||
{
|
||||
Pair<Uri, Uri> uriPair = prepareUriPair(url);
|
||||
|
||||
DownloadManager downloadManager =
|
||||
(DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
|
||||
if (downloadManager == null)
|
||||
{
|
||||
throw new NullPointerException(
|
||||
"Download manager is null, failed to download url = " + url);
|
||||
}
|
||||
|
||||
Pair<Uri, Uri> uriPair = prepareUriPair(url);
|
||||
Uri srcUri = uriPair.first;
|
||||
Uri dstUri = uriPair.second;
|
||||
|
||||
|
@ -55,12 +55,12 @@ public class BookmarksDownloadManager
|
|||
}
|
||||
|
||||
@NonNull
|
||||
private static Pair<Uri, Uri> prepareUriPair(@NonNull String url)
|
||||
private static Pair<Uri, Uri> prepareUriPair(@NonNull String url) throws UnprocessedUrlException
|
||||
{
|
||||
Uri srcUri = Uri.parse(url);
|
||||
String fileId = srcUri.getQueryParameter(QUERY_PARAM_ID_KEY);
|
||||
if (TextUtils.isEmpty(fileId))
|
||||
throw new IllegalArgumentException("File id not found");
|
||||
throw new UnprocessedUrlException("File id not found");
|
||||
|
||||
String downloadUrl = BookmarkManager.INSTANCE.getCatalogDownloadUrl(fileId);
|
||||
Uri.Builder builder = Uri.parse(downloadUrl).buildUpon();
|
||||
|
@ -78,4 +78,12 @@ public class BookmarksDownloadManager
|
|||
{
|
||||
return new BookmarksDownloadManager(context);
|
||||
}
|
||||
|
||||
public static class UnprocessedUrlException extends Exception
|
||||
{
|
||||
UnprocessedUrlException(@NonNull String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
|
|||
|
||||
adapter.startLocationUpdate();
|
||||
adapter.setOnClickListener(this);
|
||||
adapter.setOnLongClickListener(this);
|
||||
adapter.setOnLongClickListener(isCatalogCategory() ? null : this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -315,8 +315,6 @@ public class Holders
|
|||
private final TextView mName;
|
||||
@NonNull
|
||||
private final TextView mDistance;
|
||||
@NonNull
|
||||
private final View mMore;
|
||||
|
||||
BookmarkViewHolder(@NonNull View itemView, @NonNull BookmarkCategory category)
|
||||
{
|
||||
|
@ -324,14 +322,12 @@ public class Holders
|
|||
mIcon = itemView.findViewById(R.id.iv__bookmark_color);
|
||||
mName = itemView.findViewById(R.id.tv__bookmark_name);
|
||||
mDistance = itemView.findViewById(R.id.tv__bookmark_distance);
|
||||
mMore = itemView.findViewById(R.id.more);
|
||||
}
|
||||
|
||||
@Override
|
||||
void setOnLongClickListener(@Nullable RecyclerLongClickListener listener)
|
||||
{
|
||||
super.setOnLongClickListener(listener);
|
||||
mMore.setOnClickListener(v -> onOpenActionMenu(v, listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -452,7 +448,7 @@ public class Holders
|
|||
private void onMoreBtnClicked(@NonNull View v)
|
||||
{
|
||||
int lineCount = calcLineCount(mDescText, mCategory.getDescription());
|
||||
mDescText.setLines(lineCount);
|
||||
mDescText.setMaxLines(lineCount);
|
||||
mDescText.setText(mCategory.getDescription());
|
||||
v.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public final class SharedPropertiesUtils
|
|||
private static final String PREFS_BACKUP_WIDGET_EXPANDED = "BackupWidgetExpanded";
|
||||
private static final String PREFS_WHATS_NEW_TITLE_CONCATENATION = "WhatsNewTitleConcatenation";
|
||||
private static final String PREFS_CATALOG_CATEGORIES_HEADER_CLOSED = "CatalogCategoriesHeaderClosed";
|
||||
private static final String PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE = "BookmarkCategoriesLastVisiblePage";
|
||||
private static final SharedPreferences PREFS
|
||||
= PreferenceManager.getDefaultSharedPreferences(MwmApplication.get());
|
||||
|
||||
|
@ -92,4 +93,18 @@ public final class SharedPropertiesUtils
|
|||
.putBoolean(PREFS_CATALOG_CATEGORIES_HEADER_CLOSED, value)
|
||||
.apply();
|
||||
}
|
||||
|
||||
public static int getLastVisibleBookmarkCategoriesPage(@NonNull Context context)
|
||||
{
|
||||
return MwmApplication.prefs(context)
|
||||
.getInt(PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE, 0);
|
||||
}
|
||||
|
||||
public static void setLastVisibleBookmarkCategoriesPage(@NonNull Context context, int lastVisibleScreenIndex)
|
||||
{
|
||||
MwmApplication.prefs(context)
|
||||
.edit()
|
||||
.putInt(PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE, lastVisibleScreenIndex)
|
||||
.apply();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue