[bookmarks][android] Review fixes.

This commit is contained in:
Daria Volvenkova 2019-08-28 15:06:02 +03:00 committed by Aleksey Belousov
parent 9842f590e8
commit bc7ae6fddb
8 changed files with 50 additions and 38 deletions

View file

@ -51,23 +51,33 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
{
static final int INVALID_POSITION = -1;
public final int sectionIndex;
public final int itemIndex;
private final int mSectionIndex;
private final int mItemIndex;
SectionPosition(int sectionInd, int itemInd)
{
sectionIndex = sectionInd;
itemIndex = itemInd;
mSectionIndex = sectionInd;
mItemIndex = itemInd;
}
int getSectionIndex()
{
return mSectionIndex;
}
int getItemIndex()
{
return mItemIndex;
}
boolean isTitlePosition()
{
return sectionIndex != INVALID_POSITION && itemIndex == INVALID_POSITION;
return mSectionIndex != INVALID_POSITION && mItemIndex == INVALID_POSITION;
}
boolean isItemPosition()
{
return sectionIndex != INVALID_POSITION && itemIndex != INVALID_POSITION;
return mSectionIndex != INVALID_POSITION && mItemIndex != INVALID_POSITION;
}
}
@ -184,13 +194,15 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
@Override
public long getBookmarkId(@NonNull SectionPosition pos)
{
return BookmarkManager.INSTANCE.getBookmarkIdByPosition(getCategory().getId(), pos.itemIndex);
return BookmarkManager.INSTANCE.getBookmarkIdByPosition(getCategory().getId(),
pos.getItemIndex());
}
@Override
public long getTrackId(@NonNull SectionPosition pos)
{
return BookmarkManager.INSTANCE.getTrackIdByPosition(getCategory().getId(), pos.itemIndex);
return BookmarkManager.INSTANCE.getTrackIdByPosition(getCategory().getId(),
pos.getItemIndex());
}
}
@ -225,10 +237,16 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
public int getItemsType(int sectionIndex) { return TYPE_BOOKMARK; }
@Override
public void onDelete(@NonNull SectionPosition pos) { mSearchResults.remove(pos.itemIndex); }
public void onDelete(@NonNull SectionPosition pos)
{
mSearchResults.remove(pos.getItemIndex());
}
@Override
public long getBookmarkId(@NonNull SectionPosition pos) { return mSearchResults.get(pos.itemIndex); }
public long getBookmarkId(@NonNull SectionPosition pos)
{
return mSearchResults.get(pos.getItemIndex());
}
@Override
public long getTrackId(@NonNull SectionPosition pos)
@ -310,32 +328,32 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
@Override
public void onDelete(@NonNull SectionPosition pos)
{
if (isDescriptionSection(pos.sectionIndex))
if (isDescriptionSection(pos.getSectionIndex()))
throw new IllegalArgumentException("Delete failed. Invalid section index.");
int blockIndex = pos.sectionIndex - (hasDescription() ? 1 : 0);
int blockIndex = pos.getSectionIndex() - (hasDescription() ? 1 : 0);
SortedBlock block = mSortedBlocks.get(blockIndex);
if (block.isBookmarksBlock())
{
block.getBookmarkIds().remove(pos.itemIndex);
block.getBookmarkIds().remove(pos.getItemIndex());
if (block.getBookmarkIds().isEmpty())
mSortedBlocks.remove(blockIndex);
return;
}
block.getTrackIds().remove(pos.itemIndex);
block.getTrackIds().remove(pos.getItemIndex());
if (block.getTrackIds().isEmpty())
mSortedBlocks.remove(blockIndex);
}
public long getBookmarkId(@NonNull SectionPosition pos)
{
return getSortedBlock(pos.sectionIndex).getBookmarkIds().get(pos.itemIndex);
return getSortedBlock(pos.getSectionIndex()).getBookmarkIds().get(pos.getItemIndex());
}
public long getTrackId(@NonNull SectionPosition pos)
{
return getSortedBlock(pos.sectionIndex).getTrackIds().get(pos.itemIndex);
return getSortedBlock(pos.getSectionIndex()).getTrackIds().get(pos.getItemIndex());
}
}
@ -466,7 +484,7 @@ public class BookmarkListAdapter extends RecyclerView.Adapter<Holders.BaseBookma
if (sp.isTitlePosition())
return TYPE_SECTION;
if (sp.isItemPosition())
return mSectionsDataSource.getItemsType(sp.sectionIndex);
return mSectionsDataSource.getItemsType(sp.getSectionIndex());
throw new IllegalArgumentException("Position not found: " + position);
}

View file

@ -450,9 +450,9 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
{
int currentType = getLastSortingType();
@BookmarkManager.SortingType int[] types = getAvailableSortingTypes();
for (int i = 0; i < types.length; ++i)
for (@BookmarkManager.SortingType int type : types)
{
if (types[i] == currentType)
if (type == currentType)
return currentType;
}
return -1;

View file

@ -93,8 +93,8 @@ public class ChooseBookmarksSortingTypeFragment extends BaseMwmDialogFragment
@BookmarkManager.SortingType
int[] availableSortingTypes = args.getIntArray(EXTRA_SORTING_TYPES);
for (int i = 0; i < availableSortingTypes.length; ++i)
UiUtils.show(view.findViewById(getViewId(availableSortingTypes[i])));
for (@BookmarkManager.SortingType int type : availableSortingTypes)
UiUtils.show(view.findViewById(getViewId(type)));
int currentType = args.getInt(EXTRA_CURRENT_SORT_TYPE);

View file

@ -3,7 +3,6 @@ package com.mapswithme.maps.bookmarks;
import android.content.Context;
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.annotation.PluralsRes;
@ -29,11 +28,6 @@ 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;
public class Holders
{
static class GeneralViewHolder extends RecyclerView.ViewHolder
@ -279,7 +273,7 @@ public class Holders
UiUtils.hideIf(TextUtils.isEmpty(subtitleValue), mDistance);
mIcon.setImageResource(bookmark.getIcon().getResId());
UiUtils.hideIf(!sectionsDataSource.isEditable(position.sectionIndex), mMore);
UiUtils.hideIf(!sectionsDataSource.isEditable(position.getSectionIndex()), mMore);
Drawable circle = Graphics.drawCircleAndImage(bookmark.getIcon().argb(),
R.dimen.track_circle_size,
bookmark.getIcon().getResId(),
@ -347,7 +341,7 @@ public class Holders
void bind(@NonNull BookmarkListAdapter.SectionPosition position,
@NonNull BookmarkListAdapter.SectionsDataSource sectionsDataSource)
{
mView.setText(sectionsDataSource.getTitle(position.sectionIndex, mView.getResources()));
mView.setText(sectionsDataSource.getTitle(position.getSectionIndex(), mView.getResources()));
}
}

View file

@ -930,8 +930,8 @@ public enum BookmarkManager
private native int[] nativeGetAvailableSortingTypes(long catId, boolean hasMyPosition);
private native boolean nativeGetSortedBookmarks(long catId, @SortingType int sortingType,
boolean hasMyPosition, double lat, double lon,
long timestamp);
boolean hasMyPosition, double lat, double lon,
long timestamp);
public interface BookmarksLoadingListener
{

View file

@ -3,7 +3,6 @@ package com.mapswithme.maps.bookmarks.data;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;

View file

@ -1,7 +1,6 @@
package com.mapswithme.maps.bookmarks.data;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
@ -28,8 +27,12 @@ public class SortedBlock
public boolean isTracksBlock() { return !mTrackIds.isEmpty(); }
@NonNull
public String getName() { return mName; }
@SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
@NonNull
public List<Long> getBookmarkIds() { return mBookmarkIds; }
@SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
@NonNull
public List<Long> getTrackIds() { return mTrackIds; }
}

View file

@ -831,7 +831,7 @@ public class Factory
public static class ShowCountryTask implements MapTask
{
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 256630934543189768L;
private final String mCountryId;
public ShowCountryTask(String countryId)
@ -849,8 +849,7 @@ public class Factory
public static class ShowBookmarkCategoryTask implements MapTask
{
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 8285565041410550281L;
final long mCategoryId;
public ShowBookmarkCategoryTask(long categoryId)
@ -867,8 +866,7 @@ public class Factory
static abstract class BaseUserMarkTask implements MapTask
{
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = -3348320422813422144L;
final long mCategoryId;
final long mId;