Skip to content

Commit

Permalink
fix: Android 12 support changes.
Browse files Browse the repository at this point in the history
- PendingIntent flags turned IMMUTABLE
- Added setExpedited while called work manager (ImageUploading & QuoteFetch hWorker).
- compile SDK changed
- gradle upgraded t0 7.0.3
- compiler changed to Java 11
- compose migration started
  • Loading branch information
bosankus committed Nov 13, 2021
1 parent 7deb04b commit 9f8e940
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 30 deletions.
10 changes: 7 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}

composeOptions {
kotlinCompilerExtensionVersion '1.0.5'
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = JavaVersion.VERSION_11.toString()
}

packagingOptions {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
</service>

<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
android:exported="false"
tools:node="remove" />
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove">
</provider>

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class TodoApplication : Application(), Configuration.Provider {
.build()

val quoteFetchWorker = PeriodicWorkRequestBuilder<QuoteFetchWorker>(24, TimeUnit.HOURS)
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.setConstraints(constraints)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class TaskCreateViewModel @Inject constructor(

val taskImageUploadWorker =
OneTimeWorkRequestBuilder<TaskImageUploadWorker>()
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.setConstraints(constraints)
.setInputData(inputData)
.addTag(IMAGE_UPLOAD_WORKER_TAG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ class QuoteFetchWorker @AssistedInject constructor(
@Assisted context: Context,
@Assisted workerParameters: WorkerParameters,
private val preferences: SharedPreferences,
private val repository: QuoteRepository
private val repository: QuoteRepository,
private val notify: Notify
) :
CoroutineWorker(context, workerParameters) {

@Inject
lateinit var notify: Notify
private val context = applicationContext

override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
showNotification()
val response = repository.fetchQuote()
if (response.text?.isNotEmpty() == true) {
preferences.edit {
Expand All @@ -58,19 +56,11 @@ class QuoteFetchWorker @AssistedInject constructor(
Result.failure()
}

private fun showNotification() {
notify.showNotification(context) {
notificationId = QUOTE_WORKER_ID
notificationTitle = "Syncing..."
notificationBody = "Managing your tasks on your behalf"
}
}

private fun showErrorNotification() {
notify.showNotification(context) {
notificationId = QUOTE_WORKER_ID
notificationTitle = "Syncing Failed"
notificationBody = "Ehh! something stopped the process."
notificationTitle = "Ehh! Syncing Failed"
notificationBody = "Something stopped the process."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ import kotlin.coroutines.suspendCoroutine
@HiltWorker
class TaskImageUploadWorker @AssistedInject constructor(
@Assisted context: Context,
@Assisted workerParameters: WorkerParameters
@Assisted workerParameters: WorkerParameters,
private val notify: Notify
) :
CoroutineWorker(context, workerParameters) {

@Inject
lateinit var notify: Notify
private val context = applicationContext
private val repository = TodoRepository()
private val taskBody: String = checkNotNull(inputData.getString(TASK_BODY))
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.gradle_version = '4.2.0'
ext.kotlin_version = "1.5.10"
ext.gradle_version = '7.0.3'
ext.kotlin_version = "1.5.31"
ext.google_services = "4.3.4"
ext.lifecycle_version = "2.2.0"
ext.viewpager_version = "1.0.0"
Expand All @@ -21,7 +21,7 @@ buildscript {
ext.glide_version = "4.12.0"
ext.coroutine_version = "1.4.1"
ext.coroutine_play_version = "1.1.1"
ext.crashlytics_version = "2.4.1"
ext.crashlytics_version = '2.5.2'
ext.firebase_bom_version = "26.2.0"
ext.circular_indicator_version = "2.1.4"
repositories {
Expand All @@ -30,7 +30,7 @@ buildscript {
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:${gradle_version}"
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "com.google.gms:google-services:$google_services"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue May 11 13:15:50 IST 2021
#Sat Nov 13 17:51:15 IST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 9f8e940

Please sign in to comment.