summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-08-24 23:03:48 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-08-24 23:03:48 +0000
commitba8e5584aacceb392a59afa40a542554f618b0d8 (patch)
tree9cc1fe9c89dfa219ca48bfd17816dbc50e648e07
parente7c32b620fac07b6c696a40a2bb4f6461380c38e (diff)
parent1ff5eb1b5bd6532e6f6899e6e4905ed2df6e48e3 (diff)
downloadandroid_packages_apps_WallpaperPicker2-ba8e5584aacceb392a59afa40a542554f618b0d8.tar.gz
android_packages_apps_WallpaperPicker2-ba8e5584aacceb392a59afa40a542554f618b0d8.tar.bz2
android_packages_apps_WallpaperPicker2-ba8e5584aacceb392a59afa40a542554f618b0d8.zip
Snap for 5828070 from 1ff5eb1b5bd6532e6f6899e6e4905ed2df6e48e3 to qt-qpr1-release
Change-Id: I83531f1f94181dfbed02cb4c31101f5c320d412c
-rw-r--r--src/com/android/wallpaper/model/EmptyCategory.java47
-rwxr-xr-xsrc/com/android/wallpaper/picker/CategoryFragment.java1
-rwxr-xr-xsrc/com/android/wallpaper/picker/individual/IndividualPickerActivity.java44
-rwxr-xr-xsrc/com/android/wallpaper/picker/individual/IndividualPickerFragment.java69
4 files changed, 130 insertions, 31 deletions
diff --git a/src/com/android/wallpaper/model/EmptyCategory.java b/src/com/android/wallpaper/model/EmptyCategory.java
new file mode 100644
index 0000000..d37da90
--- /dev/null
+++ b/src/com/android/wallpaper/model/EmptyCategory.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.wallpaper.model;
+
+import android.app.Activity;
+import android.content.Context;
+
+import com.android.wallpaper.asset.Asset;
+
+/**
+ * A placeholder {@link Category} with only id and title (and no content).
+ * Typically used to display partially loaded categories.
+ */
+public class EmptyCategory extends Category {
+
+ /**
+ * Constructs an EmptyCategory object.
+ *
+ * @see Category#Category(String, String, int)
+ */
+ public EmptyCategory(String title, String collectionId, int priority) {
+ super(title, collectionId, priority);
+ }
+
+ @Override
+ public void show(Activity srcActivity, PickerIntentFactory factory, int requestCode) {
+
+ }
+
+ @Override
+ public Asset getThumbnail(Context context) {
+ return null;
+ }
+}
diff --git a/src/com/android/wallpaper/picker/CategoryFragment.java b/src/com/android/wallpaper/picker/CategoryFragment.java
index cbfcabb..f460a39 100755
--- a/src/com/android/wallpaper/picker/CategoryFragment.java
+++ b/src/com/android/wallpaper/picker/CategoryFragment.java
@@ -220,6 +220,7 @@ public class CategoryFragment extends ToolbarFragment {
}
// Not add existing category to category list
if (mCategories.indexOf(category) >= 0) {
+ updateCategory(category);
return;
}
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..db21da3 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);
}
+
+ maybeSetUpImageGrid();
}
void fetchWallpapers(boolean forceReload) {
@@ -346,7 +362,8 @@ public class IndividualPickerFragment extends Fragment
}
GridMarginDecoration.applyTo(mImageGrid);
- setUpImageGrid();
+ maybeSetUpImageGrid();
+
setUpBottomSheet();
return view;
@@ -369,6 +386,26 @@ public class IndividualPickerFragment extends Fragment
gridPaddingPx, gridPaddingPx, 0, paddingBottomPx);
}
+ private void maybeSetUpImageGrid() {
+ // 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;
+ }
+ setUpImageGrid();
+ }
+
+ /**
+ * Create the adapter and assign it to mImageGrid.
+ * Both mImageGrid and mCategory are guaranteed to not be null when this method is called.
+ */
void setUpImageGrid() {
mAdapter = new IndividualAdapter(mWallpapers);
mImageGrid.setAdapter(mAdapter);