• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.wallpaper.picker.individual;
17 
18 import static com.android.wallpaper.picker.WallpaperPickerDelegate.PREVIEW_LIVE_WALLPAPER_REQUEST_CODE;
19 import static com.android.wallpaper.picker.WallpaperPickerDelegate.PREVIEW_WALLPAPER_REQUEST_CODE;
20 
21 import android.app.Activity;
22 import android.util.Log;
23 import android.view.View;
24 
25 import com.android.wallpaper.model.LiveWallpaperInfo;
26 import com.android.wallpaper.model.WallpaperInfo;
27 import com.android.wallpaper.module.InjectorProvider;
28 import com.android.wallpaper.module.WallpaperPersister;
29 import com.android.wallpaper.picker.category.ui.viewmodel.CategoriesViewModel;
30 
31 /**
32  * IndividualHolder subclass for a wallpaper tile in the RecyclerView for which a click should
33  * show a full-screen preview of the wallpaper.
34  */
35 class PreviewIndividualHolder extends IndividualHolder implements View.OnClickListener {
36     private static final String TAG = "PreviewIndividualHolder";
37 
38     private WallpaperPersister mWallpaperPersister;
39     CategoriesViewModel.CategoryType mCategoryType;
40 
PreviewIndividualHolder( Activity hostActivity, int tileHeightPx, View itemView, CategoriesViewModel.CategoryType categoryType)41     public PreviewIndividualHolder(
42             Activity hostActivity, int tileHeightPx, View itemView,
43             CategoriesViewModel.CategoryType categoryType) {
44         super(hostActivity, tileHeightPx, tileHeightPx, itemView);
45         mTileLayout.setOnClickListener(this);
46         mCategoryType = categoryType;
47         mWallpaperPersister = InjectorProvider.getInjector().getWallpaperPersister(hostActivity);
48     }
49 
50     @Override
onClick(View view)51     public void onClick(View view) {
52         if (mActivity.isFinishing()) {
53             Log.w(TAG, "onClick received on VH on finishing Activity");
54             return;
55         }
56         showPreview(mWallpaper);
57     }
58 
59     /**
60      * Shows the preview activity for the given wallpaper.
61      */
showPreview(WallpaperInfo wallpaperInfo)62     private void showPreview(WallpaperInfo wallpaperInfo) {
63         mWallpaperPersister.setWallpaperInfoInPreview(wallpaperInfo);
64 
65         wallpaperInfo.showPreview(mActivity,
66                 InjectorProvider.getInjector().getPreviewActivityIntentFactory(),
67                 wallpaperInfo instanceof LiveWallpaperInfo ? PREVIEW_LIVE_WALLPAPER_REQUEST_CODE
68                         : PREVIEW_WALLPAPER_REQUEST_CODE, true,
69                 (mCategoryType == CategoriesViewModel.CategoryType.CreativeCategories));
70     }
71 
72 }
73