1 /* 2 * Copyright (C) 2023 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 17 package com.android.wallpaper.picker.preview.data.util 18 19 import android.app.Activity 20 import androidx.activity.result.ActivityResultLauncher 21 import androidx.activity.result.IntentSenderRequest 22 import com.android.wallpaper.picker.data.WallpaperModel 23 import com.android.wallpaper.picker.preview.shared.model.LiveWallpaperDownloadResultModel 24 25 /** 26 * Handles the download process of a downloadable wallpaper. This downloader should be aware of the 27 * Activity's lifecycle. 28 */ 29 interface LiveWallpaperDownloader { 30 31 /** 32 * Initializes the downloadable service. This needs to be called when [Activity.onCreate] and 33 * before calling [downloadWallpaper]. 34 */ initiateDownloadableServicenull35 fun initiateDownloadableService( 36 activity: Activity, 37 wallpaperData: WallpaperModel.StaticWallpaperModel, 38 intentSenderLauncher: ActivityResultLauncher<IntentSenderRequest>, 39 ) 40 41 /** 42 * Clean up the underlying downloadable service. This needs to be called when 43 * [Activity.onDestroy]. 44 */ 45 fun cleanup() 46 47 suspend fun downloadWallpaper(): LiveWallpaperDownloadResultModel? 48 49 50 /** 51 * @return True if there is a confirm cancel download dialog from the download service. 52 */ 53 fun cancelDownloadWallpaper(): Boolean 54 } 55