Skip to content

Commit

Permalink
Updated the libraries and some under the hood logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai-Cristian Condrea committed Jun 17, 2024
1 parent 9ac3b7f commit 108e0b3
Show file tree
Hide file tree
Showing 35 changed files with 108 additions and 97 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import com.android.volley.NoConnectionError
import com.android.volley.TimeoutError
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.datastore.DataStore
import com.d4rk.cartcalculator.notifications.managers.AppUpdateNotificationsManager
import com.d4rk.cartcalculator.notifications.managers.AppUsageNotificationsManager
import com.d4rk.cartcalculator.ui.settings.display.theme.style.AppTheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import com.d4rk.cartcalculator.constants.ads.AdsConstants
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.datastore.DataStore
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package com.d4rk.cartcalculator.constants.ads

import com.d4rk.cartcalculator.BuildConfig

object AdsConstants {
const val BANNER_AD_UNIT_ID = "ca-app-pub-5294151573817700/8040893463"
const val BANNER_AD_UNIT_ID_TEST = "ca-app-pub-3940256099942544/6300978111"

const val APP_OPEN_UNIT_ID = "ca-app-pub-5294151573817700/9208287867"
const val APP_OPEN_UNIT_ID_TEST = "ca-app-pub-3940256099942544/9257395921"
val BANNER_AD_UNIT_ID: String
get() = if (BuildConfig.DEBUG) {
"ca-app-pub-3940256099942544/6300978111"
} else {
"ca-app-pub-5294151573817700/8040893463"
}

val APP_OPEN_UNIT_ID: String
get() = if (BuildConfig.DEBUG) {
"ca-app-pub-3940256099942544/9257395921"
} else {
"ca-app-pub-5294151573817700/9208287867"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import androidx.lifecycle.ProcessLifecycleOwner
import androidx.multidex.MultiDexApplication
import androidx.room.Room
import com.d4rk.cartcalculator.constants.ads.AdsConstants
import com.d4rk.cartcalculator.data.db.AppDatabase
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.database.AppDatabase
import com.d4rk.cartcalculator.data.datastore.DataStore
import com.d4rk.cartcalculator.notifications.managers.AppUsageNotificationsManager
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.d4rk.cartcalculator.data.db
package com.d4rk.cartcalculator.data.database

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.d4rk.cartcalculator.data.db.dao.NewCartDao
import com.d4rk.cartcalculator.data.db.dao.ShoppingCartItemsDao
import com.d4rk.cartcalculator.data.db.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.db.table.ShoppingCartTable
import com.d4rk.cartcalculator.data.database.dao.NewCartDao
import com.d4rk.cartcalculator.data.database.dao.ShoppingCartItemsDao
import com.d4rk.cartcalculator.data.database.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartTable
import com.d4rk.cartcalculator.data.repository.DateConverter

@Database(entities = [ShoppingCartTable::class, ShoppingCartItemsTable::class], version = 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.d4rk.cartcalculator.data.db.dao
package com.d4rk.cartcalculator.data.database.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import com.d4rk.cartcalculator.data.db.table.ShoppingCartTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartTable

@Dao
interface NewCartDao {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.d4rk.cartcalculator.data.db.dao
package com.d4rk.cartcalculator.data.database.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.d4rk.cartcalculator.data.db.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartItemsTable

@Dao
interface ShoppingCartItemsDao {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.data.db.table
package com.d4rk.cartcalculator.data.database.table

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.data.db.table
package com.d4rk.cartcalculator.data.database.table

import androidx.room.Entity
import androidx.room.PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.data.store
package com.d4rk.cartcalculator.data.datastore

import android.content.Context
import androidx.compose.runtime.mutableStateOf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.core.app.NotificationCompat
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.datastore.DataStore
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.ViewModelProvider
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.datastore.DataStore
import com.d4rk.cartcalculator.ui.settings.display.theme.style.AppTheme
import com.google.android.gms.ads.MobileAds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.ads.BannerAdsComposable
import com.d4rk.cartcalculator.data.db.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.dialogs.DeleteCartItemDialog
import com.d4rk.cartcalculator.dialogs.NewCartItemDialog
import com.d4rk.cartcalculator.data.database.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.datastore.DataStore
import com.d4rk.cartcalculator.ui.dialogs.DeleteCartItemDialog
import com.d4rk.cartcalculator.ui.dialogs.NewCartItemDialog
import java.util.Locale

@OptIn(ExperimentalMaterial3Api::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.d4rk.cartcalculator.data.core.AppCoreManager
import com.d4rk.cartcalculator.data.db.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.db.table.ShoppingCartTable
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.database.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartTable
import com.d4rk.cartcalculator.data.datastore.DataStore
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -76,17 +76,17 @@ class CartViewModel(private val cartId: Int, private val dataStore: DataStore) :
}

/**
* Loads the selected currency from the data store and updates the UI state.
* Loads the selected currency from the data datastore and updates the UI state.
*
* This function is called during the initialization of the ViewModel. It launches a coroutine in the ViewModel's scope.
* In the coroutine, it performs the following operations:
* 1. Fetches the selected currency from the data store.
* 1. Fetches the selected currency from the data datastore.
* 2. If a currency is found, it sets the `selectedCurrency` state to the fetched currency.
* 3. If no currency is found, it sets the `selectedCurrency` state to an empty string.
*
* Note: The data store operation is performed asynchronously to avoid blocking the main thread.
* Note: The data datastore operation is performed asynchronously to avoid blocking the main thread.
*
* @throws Exception If there is an error while fetching the selected currency from the data store.
* @throws Exception If there is an error while fetching the selected currency from the data datastore.
*/
private fun loadSelectedCurrency() {
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.d4rk.cartcalculator.ui.cart

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.datastore.DataStore

/**
* Factory class for creating instances of [CartViewModel].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.dialogs
package com.d4rk.cartcalculator.ui.dialogs

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -29,7 +29,7 @@ import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.datastore.DataStore
import kotlinx.coroutines.flow.firstOrNull

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.dialogs
package com.d4rk.cartcalculator.ui.dialogs

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -17,7 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.data.db.table.ShoppingCartTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartTable

@Composable
fun DeleteCartDialog(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.dialogs
package com.d4rk.cartcalculator.ui.dialogs

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -17,7 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.data.db.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartItemsTable

@Composable
fun DeleteCartItemDialog(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.dialogs
package com.d4rk.cartcalculator.ui.dialogs

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -29,7 +29,7 @@ import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.data.store.DataStore
import com.d4rk.cartcalculator.data.datastore.DataStore
import kotlinx.coroutines.flow.firstOrNull

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.dialogs
package com.d4rk.cartcalculator.ui.dialogs

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -23,7 +23,7 @@ import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.data.core.AppCoreManager
import com.d4rk.cartcalculator.data.db.table.ShoppingCartTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartTable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Date
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.dialogs
package com.d4rk.cartcalculator.ui.dialogs

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -22,7 +22,7 @@ import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.R
import com.d4rk.cartcalculator.data.db.table.ShoppingCartItemsTable
import com.d4rk.cartcalculator.data.database.table.ShoppingCartItemsTable

@Composable
fun NewCartItemDialog(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.d4rk.cartcalculator.dialogs
package com.d4rk.cartcalculator.ui.dialogs

import android.content.res.Resources
import android.graphics.Bitmap
Expand All @@ -21,71 +21,72 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.d4rk.cartcalculator.BuildConfig
import com.d4rk.cartcalculator.R

@Composable
fun VersionInfoDialog(onDismiss: () -> Unit) {
AlertDialog(onDismissRequest = onDismiss,
AlertDialog(
onDismissRequest = onDismiss,
text = { VersionInfoContent() },
confirmButton = {},
dismissButton = {})
)
}

@Composable
fun VersionInfoContent() {
val context = LocalContext.current
val appName = context.getString(R.string.app_name)
val version = String.format(context.getString(R.string.version), BuildConfig.VERSION_NAME)
val versionName = BuildConfig.VERSION_NAME
val versionString =
stringResource(R.string.version, versionName)
val copyright = context.getString(R.string.copyright)

val appIcon = context.packageManager.getApplicationIcon(context.packageName)
val bitmapDrawable = convertAdaptiveIconDrawableToBitmap(appIcon)
val bitmapDrawable = appIcon.toBitmapDrawable()

Row(
modifier = Modifier.fillMaxWidth()
modifier = Modifier
.fillMaxWidth()
) {
Image(
bitmap = bitmapDrawable.bitmap.asImageBitmap(),
contentDescription = null,
modifier = Modifier.size(48.dp)
)
Spacer(modifier = Modifier.width(24.dp))
Spacer(modifier = Modifier.width(16.dp))
Column {
Text(
text = appName,
style = MaterialTheme.typography.titleLarge,
style = MaterialTheme.typography.titleLarge
)
Text(
text = version, style = MaterialTheme.typography.bodyMedium
text = versionString,
style = MaterialTheme.typography.bodyMedium
)
Spacer(modifier = Modifier.height(24.dp))
Spacer(modifier = Modifier.height(16.dp))
Text(
text = copyright, style = MaterialTheme.typography.bodyMedium
text = copyright,
style = MaterialTheme.typography.bodyMedium
)
}
}
}

fun convertAdaptiveIconDrawableToBitmap(drawable: Drawable): BitmapDrawable {
return when (drawable) {
is BitmapDrawable -> {
drawable
}

fun Drawable.toBitmapDrawable(): BitmapDrawable {
return when (this) {
is BitmapDrawable -> this
is AdaptiveIconDrawable -> {
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888
)
val bitmap =
Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
setBounds(0, 0, canvas.width, canvas.height)
draw(canvas)
BitmapDrawable(Resources.getSystem(), bitmap)
}

else -> {
throw IllegalArgumentException("Unsupported drawable type")
}
else -> throw IllegalArgumentException("Unsupported drawable type: ${this::class.java.name}")
}
}
Loading

0 comments on commit 108e0b3

Please sign in to comment.