-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Animated bottom navigation fix key 0 was used nav replaced with compose-destinations; bump kotlin, compose version minor fix Fix change currency for existing conditions, fix ratio input Check pair alerts every 8 hours refactoring condition item minor fix
- Loading branch information
Showing
32 changed files
with
985 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
app/src/main/java/space/taran/arkrate/data/db/PairAlertConditionRepo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package space.taran.arkrate.data.db | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Entity | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.PrimaryKey | ||
import androidx.room.Query | ||
import space.taran.arkrate.domain.PairAlertCondition | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Entity | ||
data class RoomPairAlertCondition( | ||
@PrimaryKey(autoGenerate = true) | ||
val id: Long, | ||
val numeratorCode: String, | ||
val denominatorCode: String, | ||
val ratio: Float, | ||
val moreNotLess: Boolean | ||
) | ||
|
||
@Dao | ||
interface PairAlertConditionDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(pairAlert: RoomPairAlertCondition): Long | ||
|
||
@Query("SELECT * FROM RoomPairAlertCondition") | ||
suspend fun getAll(): List<RoomPairAlertCondition> | ||
|
||
@Query("DELETE FROM RoomPairAlertCondition where id = :id") | ||
suspend fun delete(id: Long) | ||
} | ||
|
||
private fun PairAlertCondition.toRoom() = RoomPairAlertCondition( | ||
id, numeratorCode, denominatorCode, ratio, moreNotLess | ||
) | ||
|
||
private fun RoomPairAlertCondition.toCondition() = PairAlertCondition( | ||
id, numeratorCode, denominatorCode, ratio, moreNotLess | ||
) | ||
|
||
@Singleton | ||
class PairAlertConditionRepo @Inject constructor( | ||
private val dao: PairAlertConditionDao | ||
) { | ||
suspend fun insert(pairAlertCondition: PairAlertCondition) = | ||
dao.insert(pairAlertCondition.toRoom()) | ||
|
||
suspend fun getAll() = dao.getAll().map { it.toCondition() } | ||
|
||
suspend fun delete(id: Long) = dao.delete(id) | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/space/taran/arkrate/data/worker/CurrencyMonitorWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package space.taran.arkrate.data.worker | ||
|
||
import android.content.Context | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.WorkerParameters | ||
import space.taran.arkrate.data.CurrencyRate | ||
import space.taran.arkrate.data.GeneralCurrencyRepo | ||
import space.taran.arkrate.data.db.PairAlertConditionRepo | ||
import space.taran.arkrate.di.DIManager | ||
import space.taran.arkrate.domain.PairAlertCondition | ||
import space.taran.arkrate.presentation.utils.NotificationUtils | ||
import javax.inject.Inject | ||
|
||
class CurrencyMonitorWorker(val context: Context, params: WorkerParameters) : | ||
CoroutineWorker(context, params) { | ||
|
||
@Inject | ||
lateinit var currencyRepo: GeneralCurrencyRepo | ||
|
||
@Inject | ||
lateinit var pairAlertRepo: PairAlertConditionRepo | ||
|
||
override suspend fun doWork(): Result { | ||
DIManager.component.inject(this) | ||
val rates = currencyRepo.getCurrencyRate() | ||
pairAlertRepo.getAll().forEach { pairAlert -> | ||
val curRatio = curRatio(pairAlert, rates) | ||
if (pairAlert.isConditionMet(curRatio)) { | ||
notifyPair(pairAlert, curRatio) | ||
} | ||
} | ||
|
||
return Result.success() | ||
} | ||
|
||
private fun curRatio( | ||
pairAlertCondition: PairAlertCondition, | ||
rates: List<CurrencyRate> | ||
): Float { | ||
val numeratorRate = | ||
rates.find { it.code == pairAlertCondition.numeratorCode }!!.rate | ||
val denominatorRate = | ||
rates.find { it.code == pairAlertCondition.denominatorCode }!!.rate | ||
return (numeratorRate / denominatorRate).toFloat() | ||
} | ||
|
||
|
||
private fun notifyPair(pairAlertCondition: PairAlertCondition, curRatio: Float) { | ||
NotificationUtils.showPairAlert(pairAlertCondition, curRatio, context) | ||
} | ||
|
||
companion object { | ||
const val name = "CurrencyMonitorWorker" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/src/main/java/space/taran/arkrate/di/NavDepContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package space.taran.arkrate.di | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import space.taran.arkrate.presentation.MainActivity | ||
import space.taran.arkrate.presentation.shared.SharedViewModel | ||
|
||
class NavDepContainer( | ||
val activity: MainActivity | ||
) { | ||
@Suppress("UNCHECKED_CAST") | ||
fun <T> createViewModel(modelClass: Class<T>, handle: SavedStateHandle): T { | ||
return when (modelClass) { | ||
SharedViewModel::class.java -> DIManager.component.sharedVMFactory().create(modelClass) | ||
else -> throw RuntimeException("Unknown view model $modelClass") | ||
} as T | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package space.taran.arkrate.domain | ||
|
||
typealias CurrencyCode = String |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/space/taran/arkrate/domain/PairAlertCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package space.taran.arkrate.domain | ||
|
||
data class PairAlertCondition( | ||
val id: Long, | ||
val numeratorCode: String, | ||
val denominatorCode: String, | ||
val ratio: Float, | ||
var moreNotLess: Boolean | ||
) { | ||
fun isConditionMet(currentRatio: Float) = | ||
if (moreNotLess) | ||
currentRatio >= ratio | ||
else | ||
currentRatio <= ratio | ||
|
||
fun isCompleted() = | ||
numeratorCode.isNotEmpty() && | ||
denominatorCode.isNotEmpty() | ||
|
||
companion object { | ||
fun defaultInstance() = PairAlertCondition( | ||
id = 0, | ||
numeratorCode = "", | ||
denominatorCode = "", | ||
ratio = 1f, | ||
moreNotLess = true | ||
) | ||
} | ||
} |
Oops, something went wrong.