Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Zatsepin <az@mapswithme.com>2018-04-26 13:51:40 +0300
committerRoman Kuznetsov <r.kuznetsow@gmail.com>2018-04-26 14:43:08 +0300
commit017bcdff9c0005bf507d228e24c9ecf94ee2e728 (patch)
tree4d308b46c31eab41384d4c1a8483fbadca2ccec2 /android/src
parent0d509db02865dde1d6dcb3dd83a9344b4789fbd5 (diff)
[android] Review fixes
Diffstat (limited to 'android/src')
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java29
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java17
-rw-r--r--android/src/com/mapswithme/maps/bookmarks/Holders.java35
3 files changed, 49 insertions, 32 deletions
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java
index 1d588adfba..658840bbf1 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java
@@ -17,7 +17,10 @@ import com.mapswithme.maps.widget.recycler.RecyclerLongClickListener;
import static com.mapswithme.maps.bookmarks.Holders.BaseBookmarkHolder.SECTION_BMKS;
import static com.mapswithme.maps.bookmarks.Holders.BaseBookmarkHolder.SECTION_TRACKS;
+import static com.mapswithme.maps.bookmarks.Holders.BaseBookmarkHolder.getBookmarksSectionPosition;
import static com.mapswithme.maps.bookmarks.Holders.BaseBookmarkHolder.getTracksSectionPosition;
+import static com.mapswithme.maps.bookmarks.Holders.BaseBookmarkHolder.isSectionEmpty;
+import static com.mapswithme.maps.bookmarks.Holders.BookmarkViewHolder.calculateBookmarkPosition;
public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookmarkHolder>
{
@@ -77,16 +80,16 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
switch (viewType)
{
case TYPE_TRACK:
- holder = new Holders.TrackViewHolder(inflater.inflate(R.layout.item_track,
- parent, false), mCategoryId);
+ holder = new Holders.TrackViewHolder(inflater.inflate(R.layout.item_track, parent,
+ false), mCategoryId);
break;
case TYPE_BOOKMARK:
- holder = new Holders.BookmarkViewHolder(inflater.inflate(R.layout.item_bookmark,
- parent,false), mCategoryId);
+ holder = new Holders.BookmarkViewHolder(inflater.inflate(R.layout.item_bookmark, parent,
+ false), mCategoryId);
break;
case TYPE_SECTION:
- holder = new Holders.SectionViewHolder((TextView) inflater.inflate(R.layout.item_category_title,
- parent, false), mCategoryId);
+ TextView tv = (TextView) inflater.inflate(R.layout.item_category_title, parent, false);
+ holder = new Holders.SectionViewHolder(tv, mCategoryId);
break;
}
@@ -107,15 +110,15 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
@Override
public int getItemViewType(int position)
{
- final int bmkPos = Holders.BaseBookmarkHolder.getBookmarksSectionPosition(mCategoryId);
+ final int bmkPos = getBookmarksSectionPosition(mCategoryId);
final int trackPos = getTracksSectionPosition(mCategoryId);
if (position == bmkPos || position == trackPos)
return TYPE_SECTION;
- if (position > bmkPos && !Holders.BaseBookmarkHolder.isSectionEmpty(mCategoryId, SECTION_BMKS))
+ if (position > bmkPos && !isSectionEmpty(mCategoryId, SECTION_BMKS))
return TYPE_BOOKMARK;
- else if (position > trackPos && !Holders.BaseBookmarkHolder.isSectionEmpty(mCategoryId, SECTION_TRACKS))
+ else if (position > trackPos && !isSectionEmpty(mCategoryId, SECTION_TRACKS))
return TYPE_TRACK;
throw new IllegalArgumentException("Position not found: " + position);
@@ -131,8 +134,8 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
public int getItemCount()
{
return BookmarkManager.INSTANCE.getCategorySize(mCategoryId)
- + (Holders.BaseBookmarkHolder.isSectionEmpty(mCategoryId, SECTION_TRACKS) ? 0 : 1)
- + (Holders.BaseBookmarkHolder.isSectionEmpty(mCategoryId, SECTION_BMKS) ? 0 : 1);
+ + (isSectionEmpty(mCategoryId, SECTION_TRACKS) ? 0 : 1)
+ + (isSectionEmpty(mCategoryId, SECTION_BMKS) ? 0 : 1);
}
// FIXME: remove this heavy method and use BoomarkInfo class instead.
@@ -145,9 +148,7 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
}
else
{
- final int pos = position - 1
- - (Holders.BaseBookmarkHolder.isSectionEmpty(mCategoryId, SECTION_TRACKS)
- ? 0 : BookmarkManager.INSTANCE.getTracksCount(mCategoryId) + 1);
+ final int pos = calculateBookmarkPosition(mCategoryId, position);
final long bookmarkId = BookmarkManager.INSTANCE.getBookmarkIdByPosition(mCategoryId, pos);
return BookmarkManager.INSTANCE.getBookmark(bookmarkId);
}
diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java b/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java
index c53001150d..717bf94dc0 100644
--- a/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java
+++ b/android/src/com/mapswithme/maps/bookmarks/BookmarksListFragment.java
@@ -67,7 +67,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
- initList();
+ configureAdapter();
setHasOptionsMenu(true);
ActionBar bar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (bar != null)
@@ -110,15 +110,15 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
BookmarkManager.INSTANCE.removeSharingListener(this);
}
- private void initList()
+ private void configureAdapter()
{
BookmarkListAdapter adapter = (BookmarkListAdapter) getAdapter();
- if (adapter != null)
- {
- adapter.startLocationUpdate();
- adapter.setOnClickListener(this);
- adapter.setOnLongClickListener(this);
- }
+ if (adapter == null)
+ return;
+
+ adapter.startLocationUpdate();
+ adapter.setOnClickListener(this);
+ adapter.setOnLongClickListener(this);
}
@Override
@@ -198,7 +198,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment
}
}
-
@Override
public void onPreparedFileForSharing(@NonNull BookmarkSharingResult result)
{
diff --git a/android/src/com/mapswithme/maps/bookmarks/Holders.java b/android/src/com/mapswithme/maps/bookmarks/Holders.java
index d4ea71aded..4f61ca4482 100644
--- a/android/src/com/mapswithme/maps/bookmarks/Holders.java
+++ b/android/src/com/mapswithme/maps/bookmarks/Holders.java
@@ -2,6 +2,7 @@ package com.mapswithme.maps.bookmarks;
import android.graphics.drawable.Drawable;
import android.location.Location;
+import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
@@ -21,6 +22,8 @@ import com.mapswithme.maps.widget.recycler.RecyclerLongClickListener;
import com.mapswithme.util.Graphics;
import com.mapswithme.util.UiUtils;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
@@ -123,6 +126,10 @@ 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 {}
+
final long mCategoryId;
@NonNull
private final View mView;
@@ -136,14 +143,17 @@ public class Holders
abstract void bind(int position);
- static boolean isSectionEmpty(long categoryId, int section)
+ static boolean isSectionEmpty(long categoryId, @Section int section)
{
- if (section == SECTION_TRACKS)
- return BookmarkManager.INSTANCE.getTracksCount(categoryId) == 0;
- if (section == SECTION_BMKS)
- return BookmarkManager.INSTANCE.getBookmarksCount(categoryId) == 0;
-
- throw new IllegalArgumentException("There is no section with index " + section);
+ switch (section)
+ {
+ case SECTION_TRACKS:
+ return BookmarkManager.INSTANCE.getTracksCount(categoryId) == 0;
+ case SECTION_BMKS:
+ return BookmarkManager.INSTANCE.getBookmarksCount(categoryId) == 0;
+ default:
+ throw new IllegalArgumentException("There is no section with index " + section);
+ }
}
static int getSectionForPosition(long categoryId, int position)
@@ -211,8 +221,7 @@ public class Holders
@Override
void bind(int position)
{
- int pos = position - 1 - (isSectionEmpty(mCategoryId, SECTION_TRACKS)
- ? 0 : BookmarkManager.INSTANCE.getTracksCount(mCategoryId) + 1);
+ int pos = calculateBookmarkPosition(mCategoryId, position);
final long bookmarkId = BookmarkManager.INSTANCE.getBookmarkIdByPosition(mCategoryId, pos);
BookmarkInfo bookmark = new BookmarkInfo(mCategoryId, bookmarkId);
mName.setText(bookmark.getTitle());
@@ -227,6 +236,14 @@ public class Holders
mDistance.setText(null);
mIcon.setImageResource(bookmark.getIcon().getSelectedResId());
}
+
+ static int calculateBookmarkPosition(long categoryId, int position)
+ {
+ // Since bookmarks are always below tracks and header we should take it into account
+ // during the bookmark's position calculation.
+ return position - 1 - (isSectionEmpty(categoryId, SECTION_TRACKS)
+ ? 0 : BookmarkManager.INSTANCE.getTracksCount(categoryId) + 1);
+ }
}
static class TrackViewHolder extends BaseBookmarkHolder