[android] Added pageIndex selection for bookmarks catalog, optimized code

This commit is contained in:
Dmitry Donskoy 2018-08-06 13:41:58 +03:00 committed by Vlad Mihaylenko
parent 713d97ace2
commit 8e1fb8203f
5 changed files with 59 additions and 45 deletions

View file

@ -415,7 +415,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
private void showBookmarks()
{
BookmarkCategoriesActivity.startForResult(this, BookmarksPageFactory.PRIVATE.ordinal());
BookmarkCategoriesActivity.startForResult(this);
}
private void showTabletSearch(@Nullable Intent data, @NonNull String query)
@ -1055,10 +1055,14 @@ public class MwmActivity extends BaseMwmFragmentActivity
if (category == null)
throw new IllegalArgumentException("Category not found in bundle");
addTask((MapTask) target -> {
Framework.nativeShowBookmarkCategory(category.getId());
return true;
});
MapTask mapTask = target -> showBookmarkCategory(category);
addTask(mapTask);
}
private boolean showBookmarkCategory(BookmarkCategory category)
{
Framework.nativeShowBookmarkCategory(category.getId());
return true;
}
private void handleDiscoveryResult(@NonNull Intent data)

View file

@ -12,22 +12,13 @@ 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.SharedPropertiesUtils;
import com.mapswithme.util.ThemeUtils;
public class BookmarkCategoriesActivity extends BaseToolbarActivity
{
public static final int REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY = 102;
public static void startForResult(@NonNull Activity context, int initialPage)
{
Intent intent = new Intent(context, BookmarkCategoriesActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle args = new Bundle();
args.putInt(BookmarkCategoriesPagerFragment.ARG_CATEGORIES_PAGE, initialPage);
intent.putExtras(args);
context.startActivityForResult(intent, REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY);
}
public static void start(@NonNull Context context, int initialPage)
{
context.startActivity(new Intent(context, BookmarkCategoriesActivity.class));
@ -73,4 +64,19 @@ public class BookmarkCategoriesActivity extends BaseToolbarActivity
{
return R.layout.bookmarks_activity;
}
public static void startForResult(@NonNull Activity context, int initialPage)
{
Bundle args = new Bundle();
args.putInt(BookmarkCategoriesPagerFragment.ARG_CATEGORIES_PAGE, initialPage);
Intent intent = new Intent(context, BookmarkCategoriesActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtras(args);
context.startActivityForResult(intent, REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY);
}
public static void startForResult(@NonNull Activity context)
{
int initialPage = SharedPropertiesUtils.getLastVisibleBookmarkCategoriesPage(context);
startForResult(context, initialPage);
}
}

View file

@ -142,33 +142,7 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
@Override
BookmarkManager.BookmarksCatalogListener createCatalogListener()
{
return new BookmarkManager.BookmarksCatalogListener()
{
@Override
public void onImportStarted(@NonNull String serverId)
{
UiUtils.show(mProgressContainer);
UiUtils.hide(mEmptyViewContainer, mPayloadContainer);
}
@Override
public void onImportFinished(@NonNull String serverId, long catId, boolean successful)
{
if (successful)
{
UiUtils.show(mPayloadContainer);
UiUtils.hide(mProgressContainer, mEmptyViewContainer);
getAdapter().notifyDataSetChanged();
}
else
{
boolean isEmptyAdapter = getAdapter().getItemCount() == 0;
UiUtils.hide(mProgressContainer);
UiUtils.showIf(isEmptyAdapter, mEmptyViewContainer);
UiUtils.hideIf(isEmptyAdapter, mPayloadContainer);
}
}
};
return new BookmarkCategoriesCatalogListener();
}
@Override
@ -197,4 +171,32 @@ public class CachedBookmarkCategoriesFragment extends BaseBookmarkCategoriesFrag
openBookmarksCatalogScreen();
}
}
private class BookmarkCategoriesCatalogListener implements BookmarkManager.BookmarksCatalogListener
{
@Override
public void onImportStarted(@NonNull String serverId)
{
UiUtils.show(mProgressContainer);
UiUtils.hide(mEmptyViewContainer, mPayloadContainer);
}
@Override
public void onImportFinished(@NonNull String serverId, long catId, boolean successful)
{
if (successful)
{
UiUtils.show(mPayloadContainer);
UiUtils.hide(mProgressContainer, mEmptyViewContainer);
getAdapter().notifyDataSetChanged();
}
else
{
boolean isEmptyAdapter = getAdapter().getItemCount() == 0;
UiUtils.hide(mProgressContainer);
UiUtils.showIf(isEmptyAdapter, mEmptyViewContainer);
UiUtils.hideIf(isEmptyAdapter, mPayloadContainer);
}
}
}
}

View file

@ -28,10 +28,10 @@ public class ShowOnMapCatalogCategoryFragment extends DialogFragment
{
super.onCreate(savedInstanceState);
Bundle args = getArguments();
mCategory = getArgsOrThrow(args);
mCategory = getCategoryOrThrow(args);
}
private BookmarkCategory getArgsOrThrow(@Nullable Bundle args)
private BookmarkCategory getCategoryOrThrow(@Nullable Bundle args)
{
BookmarkCategory category;
if (args == null || ((category = args.getParcelable(ARGS_CATEGORY)) == null))

View file

@ -8,6 +8,7 @@ import android.support.annotation.Nullable;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.BookmarksPageFactory;
import static com.mapswithme.util.Config.KEY_PREF_STATISTICS;
@ -97,7 +98,8 @@ public final class SharedPropertiesUtils
public static int getLastVisibleBookmarkCategoriesPage(@NonNull Context context)
{
return MwmApplication.prefs(context)
.getInt(PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE, 0);
.getInt(PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE,
BookmarksPageFactory.PRIVATE.ordinal());
}
public static void setLastVisibleBookmarkCategoriesPage(@NonNull Context context, int pageIndex)