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 
30 /**
31  * IndividualHolder subclass for a wallpaper tile in the RecyclerView for which a click should
32  * show a full-screen preview of the wallpaper.
33  */
34 class PreviewIndividualHolder extends IndividualHolder implements View.OnClickListener {
35     private static final String TAG = "PreviewIndividualHolder";
36 
37     private WallpaperPersister mWallpaperPersister;
38 
PreviewIndividualHolder( Activity hostActivity, int tileHeightPx, View itemView)39     public PreviewIndividualHolder(
40             Activity hostActivity, int tileHeightPx, View itemView) {
41         super(hostActivity, tileHeightPx, tileHeightPx, itemView);
42         mTileLayout.setOnClickListener(this);
43 
44         mWallpaperPersister = InjectorProvider.getInjector().getWallpaperPersister(hostActivity);
45     }
46 
47     @Override
onClick(View view)48     public void onClick(View view) {
49         if (mActivity.isFinishing()) {
50             Log.w(TAG, "onClick received on VH on finishing Activity");
51             return;
52         }
53         showPreview(mWallpaper);
54     }
55 
56     /**
57      * Shows the preview activity for the given wallpaper.
58      */
showPreview(WallpaperInfo wallpaperInfo)59     private void showPreview(WallpaperInfo wallpaperInfo) {
60         mWallpaperPersister.setWallpaperInfoInPreview(wallpaperInfo);
61         wallpaperInfo.showPreview(mActivity,
62                 InjectorProvider.getInjector().getPreviewActivityIntentFactory(),
63                 wallpaperInfo instanceof LiveWallpaperInfo ? PREVIEW_LIVE_WALLPAPER_REQUEST_CODE
64                         : PREVIEW_WALLPAPER_REQUEST_CODE, true);
65     }
66 
67 }
68