This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Suppress("BlockingMethodInNonBlockingContext") | |
class RemoteImageWorker( | |
private val context: Context, | |
workerParameters: WorkerParameters | |
) : CoroutineWorker( | |
context, | |
workerParameters | |
) { | |
override suspend fun doWork(): Result { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainScreenViewModel ( | |
application: Application | |
) : ViewModel() { | |
private val preferencesManager = PreferencesManager(application) | |
val imageCategoryIndex = preferencesManager.imageCategoryPref | |
private var workManager = WorkManager.getInstance(application) | |
init { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PreferencesManager( | |
private val application: Application, | |
) { | |
private companion object{ | |
val Context.pref: DataStore<Preferences> by preferencesDataStore( | |
name = "pref_settings" | |
) | |
} | |
val imageCategoryPref = application.applicationContext.pref.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface RemoteImageService { | |
/** | |
* returns a random image object from unsplash api | |
* @param clientId should be replaced with your client id | |
* which you can obtain it from unsplash api | |
*/ | |
@GET | |
suspend fun getRandomImageObject( | |
@Url unsplashBaseUrl: String = "https://api.unsplash.com/photos/random", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:layout_width="350dp" | |
android:layout_height="350dp" | |
android:scaleType="centerCrop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | |
android:description="@string/widget_description" | |
android:initialLayout="@layout/widget_initial_layout" | |
android:minWidth="500dp" | |
android:minHeight="500dp" | |
android:minResizeWidth="200dp" | |
android:minResizeHeight="200dp" | |
android:previewImage="@drawable/ic_image" | |
android:resizeMode="vertical|horizontal" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RemoteWidgetReceiver: GlanceAppWidgetReceiver() { | |
override val glanceAppWidget: GlanceAppWidget | |
get() = RemoteWidget() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.runtime.Composable | |
import androidx.glance.GlanceModifier | |
import androidx.glance.Image | |
import androidx.glance.ImageProvider | |
import androidx.glance.appwidget.GlanceAppWidget | |
import androidx.glance.layout.ContentScale | |
import androidx.glance.layout.fillMaxSize | |
import com.example.remotewidget.R | |
class RemoteWidget : GlanceAppWidget() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//other dependencies.... | |
..... | |
.... | |
//Glance | |
implementation "androidx.glance:glance-appwidget:1.0.0-alpha03" | |
//WorkManger | |
implementation "androidx.work:work-runtime-ktx:2.7.1" | |
//Retrofit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
ConstraintSets:{...}, | |
Transitions: { | |
default: { | |
from: 'start', | |
to: 'end', | |
pathMotionArc: 'startVertical', | |
// key here must be Key with capital K | |
KeyFrames: { | |
KeyAttributes: [ |