From 11b84988494cd8d46437d9e777ddb53f135a94ad Mon Sep 17 00:00:00 2001 From: FunkyMuse Date: Wed, 17 Jan 2024 17:49:54 +0100 Subject: [PATCH] refactor: remove parcelize --- accessibility/build.gradle | 2 +- .../adapter/TestModel.kt | 23 +++--- build.gradle | 4 +- .../crazylegend/common/BatteryStatusModel.kt | 18 +++-- .../com/crazylegend/customviews/AppRater.kt | 72 +++++++++++++------ .../location/ObtainedLocationModel.kt | 18 +++-- settings.gradle | 1 + 7 files changed, 80 insertions(+), 58 deletions(-) diff --git a/accessibility/build.gradle b/accessibility/build.gradle index 67ca25d88..5d0a33595 100644 --- a/accessibility/build.gradle +++ b/accessibility/build.gradle @@ -1,5 +1,5 @@ dependencies { - implementation "androidx.core:core-ktx:$coreKTX" + implementation libs.androidx.core.ktx } android { diff --git a/app/src/main/java/com/crazylegend/setofusefulkotlinextensions/adapter/TestModel.kt b/app/src/main/java/com/crazylegend/setofusefulkotlinextensions/adapter/TestModel.kt index 3245b2c31..eac228e41 100644 --- a/app/src/main/java/com/crazylegend/setofusefulkotlinextensions/adapter/TestModel.kt +++ b/app/src/main/java/com/crazylegend/setofusefulkotlinextensions/adapter/TestModel.kt @@ -1,24 +1,21 @@ package com.crazylegend.setofusefulkotlinextensions.adapter -import android.os.Parcelable import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey import com.squareup.moshi.JsonClass -import kotlinx.parcelize.Parcelize -@Parcelize @Entity(tableName = "tests") @JsonClass(generateAdapter = true) data class TestModel( - @ColumnInfo(name = "body") - val body: String, - @ColumnInfo(name = "id") - @PrimaryKey - val id: Int, - @ColumnInfo(name = "title") - val title: String, - @ColumnInfo(name = "userId") - val userId: Int -) : Parcelable \ No newline at end of file + @ColumnInfo(name = "body") + val body: String, + @ColumnInfo(name = "id") + @PrimaryKey + val id: Int, + @ColumnInfo(name = "title") + val title: String, + @ColumnInfo(name = "userId") + val userId: Int +) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 37ffeca38..d4408b074 100644 --- a/build.gradle +++ b/build.gradle @@ -80,7 +80,7 @@ allprojects { } tasks.register('clean', Delete) { - delete rootProject.buildDir + delete rootProject.layout.getBuildDirectory() } subprojects { @@ -89,7 +89,6 @@ subprojects { apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' - apply plugin: 'kotlin-parcelize' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) @@ -110,7 +109,6 @@ subprojects { apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'maven-publish' - apply plugin: 'kotlin-parcelize' apply plugin: 'org.jetbrains.dokka' applyAndroid(it, false) diff --git a/common/src/main/java/com/crazylegend/common/BatteryStatusModel.kt b/common/src/main/java/com/crazylegend/common/BatteryStatusModel.kt index 31e6dfff1..5245581fa 100644 --- a/common/src/main/java/com/crazylegend/common/BatteryStatusModel.kt +++ b/common/src/main/java/com/crazylegend/common/BatteryStatusModel.kt @@ -1,18 +1,16 @@ package com.crazylegend.common -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - /** * Created by funkymuse on 5/26/21 to long live and prosper ! */ -@Parcelize -data class BatteryStatusModel(val isCharging: Boolean, - val isUsbCharging: Boolean, - val wirelessCharge: Boolean, - val isACCharging: Boolean, - val batteryCapacity: Float, - val batteryScale: Float) : Parcelable { +data class BatteryStatusModel( + val isCharging: Boolean, + val isUsbCharging: Boolean, + val wirelessCharge: Boolean, + val isACCharging: Boolean, + val batteryCapacity: Float, + val batteryScale: Float +) { val batteryPercentage get() = (batteryCapacity * batteryScale).toInt() diff --git a/customviews/src/main/java/com/crazylegend/customviews/AppRater.kt b/customviews/src/main/java/com/crazylegend/customviews/AppRater.kt index 59a52dc96..434b17c5a 100644 --- a/customviews/src/main/java/com/crazylegend/customviews/AppRater.kt +++ b/customviews/src/main/java/com/crazylegend/customviews/AppRater.kt @@ -5,14 +5,14 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle -import android.os.Parcelable import android.view.View import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager +import com.crazylegend.customviews.AppRater.AppRaterModelSetup.Companion.DEFAULT_APP_TITLE +import com.crazylegend.customviews.AppRater.AppRaterModelSetup.Companion.DEFAULT_CONTENT import com.crazylegend.customviews.databinding.DialogAppRaterBinding import com.crazylegend.viewbinding.viewBinding -import kotlinx.parcelize.Parcelize /** @@ -31,15 +31,20 @@ buttonsBGColor = getCompatColor(R.color.colorAccent) */ object AppRater { - + private const val appRaterModelSetupKey = "AppRaterModelSetupKey" private const val prefKey = "appRater" private const val doNotShowAgainPref = "doNotShowAgain" private const val launchCountPref = "launchCount" private const val dateFirstLaunchPref = "dateFirLaunched" private lateinit var appRaterDialog: AppRaterDialog - fun appLaunched(context: Context, fragmentManager: FragmentManager, DAYS_UNTIL_PROMPT: Int, LAUNCHES_UNTIL_PROMPT: Int, - appRaterModelSetup: AppRaterModelSetup.() -> Unit = {}) { + fun appLaunched( + context: Context, + fragmentManager: FragmentManager, + DAYS_UNTIL_PROMPT: Int, + LAUNCHES_UNTIL_PROMPT: Int, + appRaterModelSetup: AppRaterModelSetup.() -> Unit = {} + ) { val modelToModify = AppRaterModelSetup() appRaterModelSetup.invoke(modelToModify) @@ -82,18 +87,24 @@ object AppRater { appRaterDialog.show(fragmentManager, DIALOG_TAG) } - @Parcelize class AppRaterModelSetup( - var appTitle: String = "Rate my app", - var content: String = "If you're enjoying using this application, please take a moment to rate it.\nThanks for your support !", - var buttonsCornerRadius: Int? = null, - var contentTextSize: Float? = null, - var rateMeButtonText: String? = null, - var doNotShowAgainButtonText: String? = null, - var remindMeLaterButtonText: String? = null, - var backgroundButtonsResource: Int? = null, //use 0 to remove background and also removes the button too - var buttonsBGColor: Int? = null) : Parcelable { + var appTitle: String = "Rate my app", + var content: String = "If you're enjoying using this application, please take a moment to rate it.\nThanks for your support !", + var buttonsCornerRadius: Int? = null, + var contentTextSize: Float? = null, + var rateMeButtonText: String? = null, + var doNotShowAgainButtonText: String? = null, + var remindMeLaterButtonText: String? = null, + var backgroundButtonsResource: Int? = null, //use 0 to remove background and also removes the button too + var buttonsBGColor: Int? = null + ) { + companion object { + const val DEFAULT_APP_TITLE = "Rate my app" + const val DEFAULT_CONTENT = + "If you're enjoying using this application, please take a moment to rate it.\nThanks for your support !", + + } operator fun invoke(callback: AppRaterModelSetup.() -> Unit = {}) { callback.invoke(this) @@ -111,9 +122,25 @@ object AppRater { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - - val argumentModel: AppRaterModelSetup? = arguments?.getParcelable(argumentModel) - argumentModel ?: return + val argumentModel = arguments?.run { + AppRaterModelSetup( + appTitle = getString(appRaterModelSetupKey + "appTitle", DEFAULT_APP_TITLE), + content = getString(appRaterModelSetupKey + "content", DEFAULT_CONTENT), + buttonsCornerRadius = runCatching { getInt(appRaterModelSetupKey + "buttonsCornerRadius") }.getOrNull(), + buttonsBGColor = runCatching { getInt(appRaterModelSetupKey + "buttonsBGColor") }.getOrNull(), + backgroundButtonsResource = runCatching { getInt(appRaterModelSetupKey + "backgroundButtonsResource") }.getOrNull(), + contentTextSize = runCatching { getFloat(appRaterModelSetupKey + "contentTextSize") }.getOrNull(), + rateMeButtonText = getString(appRaterModelSetupKey + "rateMeButtonText", null), + doNotShowAgainButtonText = getString( + appRaterModelSetupKey + "doNotShowAgainButtonText", + null + ), + remindMeLaterButtonText = getString( + appRaterModelSetupKey + "remindMeLaterButtonText", + null + ), + ) + } ?: return binding.content.text = (argumentModel.content) binding.title.text = (argumentModel.appTitle) @@ -130,9 +157,9 @@ object AppRater { binding.rate.text = argumentModel.rateMeButtonText ?: "Rate" binding.doNotShowAgain.text = argumentModel.doNotShowAgainButtonText - ?: "Don't show again" + ?: "Don't show again" binding.remindMeLater.text = argumentModel.remindMeLaterButtonText - ?: "Remind me later" + ?: "Remind me later" argumentModel.backgroundButtonsResource?.apply { binding.rate.setBackgroundResource(this) @@ -147,7 +174,10 @@ object AppRater { } binding.rate.setOnClickListener { - val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${requireContext().packageName}")) + val intent = Intent( + Intent.ACTION_VIEW, + Uri.parse("market://details?id=${requireContext().packageName}") + ) if (intent.resolveActivity(requireContext().packageManager) != null) { requireContext().startActivity(intent) diff --git a/kotlinextensions/src/main/java/com/crazylegend/kotlinextensions/location/ObtainedLocationModel.kt b/kotlinextensions/src/main/java/com/crazylegend/kotlinextensions/location/ObtainedLocationModel.kt index c877c82f9..1ab41c969 100644 --- a/kotlinextensions/src/main/java/com/crazylegend/kotlinextensions/location/ObtainedLocationModel.kt +++ b/kotlinextensions/src/main/java/com/crazylegend/kotlinextensions/location/ObtainedLocationModel.kt @@ -1,17 +1,15 @@ package com.crazylegend.kotlinextensions.location -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - /** * Created by crazy on 3/30/19 to long live and prosper ! */ -@Parcelize -data class ObtainedLocationModel(var address: String = "", - var city: String = "", - var state: String = "", - var country: String = "", - var postalCode: String = "", - var knownName: String = "") : Parcelable \ No newline at end of file +data class ObtainedLocationModel( + var address: String? = null, + var city: String? = null, + var state: String? = null, + var country: String? = null, + var postalCode: String? = null, + var knownName: String? = null +) \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 498d936d1..0b5789e5d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -50,3 +50,4 @@ include ':toaster' include ':saf' include ':intent' include ':receivers' +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")