summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Etchebehere <santie@google.com>2019-08-12 14:50:40 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-08-12 14:50:40 -0700
commit9f185433f6e97802ab0e2e012440ce5229077ac9 (patch)
tree7005e77ffc95e61ab9d75b4ae628fbfed11670c9
parentbbc27b7b5dbccbe564d0d65c1b534998c3a1e84e (diff)
parent8648bb81e74b8d68072524d0d2faa9b23dd90725 (diff)
downloadandroid_packages_apps_WallpaperPicker2-9f185433f6e97802ab0e2e012440ce5229077ac9.tar.gz
android_packages_apps_WallpaperPicker2-9f185433f6e97802ab0e2e012440ce5229077ac9.tar.bz2
android_packages_apps_WallpaperPicker2-9f185433f6e97802ab0e2e012440ce5229077ac9.zip
Ensure category is loaded in individual picker
am: 8648bb81e7 Change-Id: Iddbfb85b37f3c82f13813fe5fb55cc03ed395039
-rwxr-xr-xsrc/com/android/wallpaper/picker/individual/IndividualPickerActivity.java44
-rwxr-xr-xsrc/com/android/wallpaper/picker/individual/IndividualPickerFragment.java59
2 files changed, 73 insertions, 30 deletions
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java b/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java
index 3ed5bf3..367181a 100755
--- a/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java
+++ b/src/com/android/wallpaper/picker/individual/IndividualPickerActivity.java
@@ -22,9 +22,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.graphics.Insets;
-import android.graphics.PorterDuff.Mode;
-import android.graphics.drawable.Drawable;
-import android.os.Build.VERSION;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
@@ -33,13 +30,14 @@ import android.view.WindowInsets;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
-import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.android.wallpaper.R;
import com.android.wallpaper.compat.BuildCompat;
import com.android.wallpaper.model.Category;
+import com.android.wallpaper.model.CategoryProvider;
+import com.android.wallpaper.model.CategoryReceiver;
import com.android.wallpaper.model.InlinePreviewIntentFactory;
import com.android.wallpaper.model.LiveWallpaperInfo;
import com.android.wallpaper.model.PickerIntentFactory;
@@ -93,18 +91,29 @@ public class IndividualPickerActivity extends BaseActivity {
mCategoryCollectionId = (savedInstanceState == null)
? getIntent().getStringExtra(EXTRA_CATEGORY_COLLECTION_ID)
: savedInstanceState.getString(KEY_CATEGORY_COLLECTION_ID);
- mCategory = injector.getCategoryProvider(this).getCategory(mCategoryCollectionId);
- if (mCategory == null) {
- DiskBasedLogger.e(TAG, "Failed to find the category: " + mCategoryCollectionId, this);
- // We either were called with an invalid collection Id, or we're restarting with no
- // saved state, or with a collection id that doesn't exist anymore.
- // In those cases, we cannot continue, so let's just go back.
- finish();
- return;
- }
+ CategoryProvider categoryProvider = injector.getCategoryProvider(this);
+ categoryProvider.fetchCategories(new CategoryReceiver() {
+ @Override
+ public void onCategoryReceived(Category category) {
+ // Do nothing.
+ }
+
+ @Override
+ public void doneFetchingCategories() {
+ mCategory = categoryProvider.getCategory(mCategoryCollectionId);
+ if (mCategory == null) {
+ DiskBasedLogger.e(TAG, "Failed to find the category: " + mCategoryCollectionId,
+ IndividualPickerActivity.this);
+ // We either were called with an invalid collection Id, or we're restarting with
+ // no saved state, or with a collection id that doesn't exist anymore.
+ // In those cases, we cannot continue, so let's just go back.
+ finish();
+ return;
+ }
+ onCategoryLoaded();
+ }
+ }, false);
- setTitle(mCategory.getTitle());
- getSupportActionBar().setTitle(mCategory.getTitle());
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.getNavigationIcon().setTint(getColor(R.color.toolbar_icon_color));
@@ -142,6 +151,11 @@ public class IndividualPickerActivity extends BaseActivity {
}
}
+ private void onCategoryLoaded() {
+ setTitle(mCategory.getTitle());
+ getSupportActionBar().setTitle(mCategory.getTitle());
+ }
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
index a33bf97..8f1d380 100755
--- a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
+++ b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
@@ -48,6 +48,9 @@ import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.asset.Asset.DrawableLoadedListener;
import com.android.wallpaper.config.Flags;
+import com.android.wallpaper.model.Category;
+import com.android.wallpaper.model.CategoryProvider;
+import com.android.wallpaper.model.CategoryReceiver;
import com.android.wallpaper.model.WallpaperCategory;
import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.model.WallpaperReceiver;
@@ -257,27 +260,38 @@ public class IndividualPickerFragment extends Fragment
mRandom = new Random();
mHandler = new Handler();
- String collectionId = getArguments().getString(ARG_CATEGORY_COLLECTION_ID);
- mCategory = (WallpaperCategory) injector.getCategoryProvider(appContext).getCategory(
- collectionId);
- if (mCategory == null) {
- DiskBasedLogger.e(TAG, "Failed to find the category.", appContext);
-
- // The absence of this category in the CategoryProvider indicates a broken state, probably due
- // to a relaunch into this activity/fragment following a crash immediately prior; see
- // b//38030129. Hence, finish the activity and return.
- getActivity().finish();
- return;
- }
-
- mWallpaperRotationInitializer = mCategory.getWallpaperRotationInitializer();
-
// Clear Glide's cache if night-mode changed to ensure thumbnails are reloaded
if (savedInstanceState != null && (savedInstanceState.getInt(KEY_NIGHT_MODE)
!= (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK))) {
Glide.get(getContext()).clearMemory();
}
+ CategoryProvider categoryProvider = injector.getCategoryProvider(appContext);
+ categoryProvider.fetchCategories(new CategoryReceiver() {
+ @Override
+ public void onCategoryReceived(Category category) {
+ // Do nothing.
+ }
+
+ @Override
+ public void doneFetchingCategories() {
+ mCategory = (WallpaperCategory) categoryProvider.getCategory(
+ getArguments().getString(ARG_CATEGORY_COLLECTION_ID));
+ if (mCategory == null) {
+ DiskBasedLogger.e(TAG, "Failed to find the category.", getContext());
+
+ // The absence of this category in the CategoryProvider indicates a broken
+ // state, see b/38030129. Hence, finish the activity and return.
+ getActivity().finish();
+ return;
+ }
+ onCategoryLoaded();
+ }
+ }, false);
+ }
+
+ protected void onCategoryLoaded() {
+ mWallpaperRotationInitializer = mCategory.getWallpaperRotationInitializer();
fetchWallpapers(false);
if (mCategory.supportsThirdParty()) {
@@ -290,6 +304,8 @@ public class IndividualPickerFragment extends Fragment
mPackageStatusNotifier.addListener(mAppStatusListener,
WallpaperService.SERVICE_INTERFACE);
}
+
+ setUpImageGrid();
}
void fetchWallpapers(boolean forceReload) {
@@ -347,6 +363,7 @@ public class IndividualPickerFragment extends Fragment
GridMarginDecoration.applyTo(mImageGrid);
setUpImageGrid();
+
setUpBottomSheet();
return view;
@@ -370,6 +387,18 @@ public class IndividualPickerFragment extends Fragment
}
void setUpImageGrid() {
+ // Skip if mImageGrid been initialized yet
+ if (mImageGrid == null) {
+ return;
+ }
+ // Skip if category hasn't loaded yet
+ if (mCategory == null) {
+ return;
+ }
+ // Skip if the adapter was already created
+ if (mAdapter != null) {
+ return;
+ }
mAdapter = new IndividualAdapter(mWallpapers);
mImageGrid.setAdapter(mAdapter);
mImageGrid.setLayoutManager(new GridLayoutManager(getActivity(), getNumColumns()));