Skip to content

Commit

Permalink
Added sorting to EMI and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
suyash01 committed Jul 27, 2024
1 parent 40347e7 commit 2899f8a
Show file tree
Hide file tree
Showing 36 changed files with 361 additions and 229 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

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

3 changes: 2 additions & 1 deletion .idea/misc.xml

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

24 changes: 12 additions & 12 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
kotlin("plugin.serialization")
kotlin("plugin.compose")
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.dagger.hilt.android")
Expand All @@ -15,8 +16,8 @@ android {
applicationId = "com.suyash.creditmanager"
minSdk = 26
targetSdk = 35
versionCode = 23
versionName = "1.0.22"
versionCode = 24
versionName = "1.0.23"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -37,19 +38,16 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
buildFeatures {
buildConfig = true
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.2"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand All @@ -61,14 +59,15 @@ android {
}

dependencies {
val hiltVersion = "2.49"
val hiltVersion = "2.51.1"
val roomVersion = "2.6.1"
val navVersion = "2.7.7"
val workVersion = "2.9.0"
implementation("org.jetbrains.kotlin:kotlin-reflect:2.0.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.2")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.4")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.activity:activity-compose:1.9.0")
implementation("androidx.activity:activity-compose:1.9.1")
implementation(platform("androidx.compose:compose-bom:2024.06.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
Expand All @@ -81,7 +80,7 @@ dependencies {
implementation("androidx.navigation:navigation-compose:$navVersion")
implementation("androidx.hilt:hilt-navigation-compose:1.2.0")
implementation("androidx.datastore:datastore:1.1.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")
implementation("androidx.work:work-runtime-ktx:$workVersion")
implementation("androidx.hilt:hilt-work:1.2.0")
implementation("com.google.code.gson:gson:2.10.1")
Expand All @@ -93,6 +92,7 @@ dependencies {
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2024.06.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
androidTestImplementation("androidx.navigation:navigation-testing:$navVersion")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ data class EMI(
return min(emiPaid, months)
}

fun emisRemaining(): Int {
return months - emisPaid()
}

fun toEmiBackup() =
EmiBackup (
name = this.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.suyash.creditmanager.domain.use_case.credit_card

import com.suyash.creditmanager.domain.model.CreditCard
import com.suyash.creditmanager.domain.repository.CreditCardRepository
import com.suyash.creditmanager.domain.util.CreditCardOrder
import com.suyash.creditmanager.domain.util.OrderType
import com.suyash.creditmanager.domain.util.order.CreditCardOrder
import com.suyash.creditmanager.domain.util.order.OrderType
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.suyash.creditmanager.domain.use_case.emi

import com.suyash.creditmanager.domain.model.EMI
import com.suyash.creditmanager.domain.repository.EMIRepository
import com.suyash.creditmanager.domain.util.EMIOrder
import com.suyash.creditmanager.domain.util.OrderType
import com.suyash.creditmanager.domain.util.order.EMIOrder
import com.suyash.creditmanager.domain.util.order.OrderType
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

Expand All @@ -19,6 +19,7 @@ class GetEMIs(private val repository: EMIRepository) {
is EMIOrder.Months -> emis.sortedBy { it.months }
is EMIOrder.Date -> emis.sortedBy { it.date }
is EMIOrder.EMIsPaid -> emis.sortedBy { it.emisPaid() }
is EMIOrder.EMIsRemaining -> emis.sortedBy { it.emisRemaining() }
}
}
is OrderType.Descending -> {
Expand All @@ -29,6 +30,7 @@ class GetEMIs(private val repository: EMIRepository) {
is EMIOrder.Months -> emis.sortedByDescending { it.months }
is EMIOrder.Date -> emis.sortedByDescending { it.date }
is EMIOrder.EMIsPaid -> emis.sortedByDescending { it.emisPaid() }
is EMIOrder.EMIsRemaining -> emis.sortedByDescending { it.emisRemaining() }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.suyash.creditmanager.domain.use_case.transaction

import com.suyash.creditmanager.domain.model.Transaction
import com.suyash.creditmanager.domain.repository.TransactionRepository
import com.suyash.creditmanager.domain.util.OrderType
import com.suyash.creditmanager.domain.util.TransactionOrder
import com.suyash.creditmanager.domain.util.order.OrderType
import com.suyash.creditmanager.domain.util.order.TransactionOrder
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions app/src/main/java/com/suyash/creditmanager/domain/util/EMIOrder.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.suyash.creditmanager.domain.util.order

sealed class CreditCardOrder(
override val orderType: OrderType,
override val label: String
) : Order {
class Name(orderType: OrderType, label: String = "Name") : CreditCardOrder(orderType, label)
class Expiry(orderType: OrderType, label: String = "Expiry") : CreditCardOrder(orderType, label)
class Limit(orderType: OrderType, label: String = "Limit") : CreditCardOrder(orderType, label)
class DueDate(orderType: OrderType, label: String = "Due Date") :
CreditCardOrder(orderType, label)

class BillDate(orderType: OrderType, label: String = "Bill Date") :
CreditCardOrder(orderType, label)

companion object {
fun getOrderList(): List<CreditCardOrder> {
return listOf(
Name(OrderType.Ascending),
Expiry(OrderType.Ascending),
Limit(OrderType.Ascending),
DueDate(OrderType.Ascending),
BillDate(OrderType.Ascending)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.suyash.creditmanager.domain.util.order

sealed class EMIOrder(override val orderType: OrderType, override val label: String) : Order {
class Name(orderType: OrderType, label: String = "Name") : EMIOrder(orderType, label)
class Amount(orderType: OrderType, label: String = "Amount") : EMIOrder(orderType, label)
class Rate(orderType: OrderType, label: String = "Rate") : EMIOrder(orderType, label)
class Months(orderType: OrderType, label: String = "Months") : EMIOrder(orderType, label)
class Date(orderType: OrderType, label: String = "Date") : EMIOrder(orderType, label)
class EMIsPaid(orderType: OrderType, label: String = "EMIs Paid") : EMIOrder(orderType, label)
class EMIsRemaining(orderType: OrderType, label: String = "EMIs Remaining") : EMIOrder(orderType, label)

companion object {
fun getOrderList(): List<EMIOrder> {
return listOf(
Name(OrderType.Ascending),
Amount(OrderType.Ascending),
Rate(OrderType.Ascending),
Months(OrderType.Ascending),
Date(OrderType.Descending),
EMIsPaid(OrderType.Ascending),
EMIsRemaining(OrderType.Descending)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.suyash.creditmanager.domain.util.order

sealed interface Order {

val orderType: OrderType
val label: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.suyash.creditmanager.domain.util.order

sealed class OrderType {
data object Ascending: OrderType()
data object Descending: OrderType()

fun getReverse(): OrderType {
return when (this) {
is Ascending -> Descending
is Descending -> Ascending
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.suyash.creditmanager.domain.util
package com.suyash.creditmanager.domain.util.order

sealed class TransactionOrder(val orderType: OrderType) {
class Date(orderType: OrderType): TransactionOrder(orderType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import com.suyash.creditmanager.domain.model.EMI
import com.suyash.creditmanager.domain.use_case.CreditCardUseCases
import com.suyash.creditmanager.domain.use_case.EMIUseCases
import com.suyash.creditmanager.domain.util.CardType
import com.suyash.creditmanager.domain.util.CreditCardOrder
import com.suyash.creditmanager.domain.util.OrderType
import com.suyash.creditmanager.domain.util.order.CreditCardOrder
import com.suyash.creditmanager.domain.util.order.OrderType
import com.suyash.creditmanager.presentation.commons.TextInputState
import com.suyash.creditmanager.presentation.commons.validateInRange
import com.suyash.creditmanager.presentation.commons.validateMinMaxLength
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import com.suyash.creditmanager.domain.model.TxnCategory
import com.suyash.creditmanager.domain.use_case.CreditCardUseCases
import com.suyash.creditmanager.domain.use_case.TransactionUseCases
import com.suyash.creditmanager.domain.use_case.TxnCategoryUseCases
import com.suyash.creditmanager.domain.util.CreditCardOrder
import com.suyash.creditmanager.domain.util.OrderType
import com.suyash.creditmanager.domain.util.order.CreditCardOrder
import com.suyash.creditmanager.domain.util.order.OrderType
import com.suyash.creditmanager.domain.util.TransactionType
import com.suyash.creditmanager.presentation.commons.TextInputState
import com.suyash.creditmanager.presentation.commons.validateInRange
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.suyash.creditmanager.presentation.commons.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.suyash.creditmanager.presentation.commons.model.ItemAction

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CustomActionBottomSheet(
modifier: Modifier = Modifier,
onDismissRequest: () -> Unit,
actions: List<ItemAction>
) {
val bottomSheetState = rememberModalBottomSheetState()

ModalBottomSheet(
sheetState = bottomSheetState,
onDismissRequest = onDismissRequest
) {
Column(
modifier = modifier.padding(bottom = 16.dp)
) {
actions.forEach {
Row(
modifier = Modifier
.clickable {
onDismissRequest()
it.onClick()
}
.fillMaxWidth()
.padding(16.dp)
) {
Icon(it.icon, it.iconName)
Text(text = it.title, modifier = Modifier.padding(start = 16.dp))
}
}
}
}
}
Loading

0 comments on commit 2899f8a

Please sign in to comment.