Skip to content

Commit

Permalink
refactor: remove parcelize
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyMuse committed Jan 17, 2024
1 parent b38417f commit 11b8498
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 58 deletions.
2 changes: 1 addition & 1 deletion accessibility/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
implementation "androidx.core:core-ktx:$coreKTX"
implementation libs.androidx.core.ktx
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
@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
)
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ allprojects {
}

tasks.register('clean', Delete) {
delete rootProject.buildDir
delete rootProject.layout.getBuildDirectory()
}

subprojects {
Expand All @@ -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'])
Expand All @@ -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)
Expand Down
18 changes: 8 additions & 10 deletions common/src/main/java/com/crazylegend/common/BatteryStatusModel.kt
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
72 changes: 51 additions & 21 deletions customviews/src/main/java/com/crazylegend/customviews/AppRater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
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
)
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ include ':toaster'
include ':saf'
include ':intent'
include ':receivers'
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

0 comments on commit 11b8498

Please sign in to comment.