Skip to content

Commit

Permalink
Fixed issue where coin overrides weren't getting set, causing certain…
Browse files Browse the repository at this point in the history
… coin/exchange combinations to fail.

Improved the slider for decimal places on settings screen.
Dependency upgrades.
  • Loading branch information
hwki committed Nov 3, 2023
1 parent a87dd1c commit bf3b00e
Showing 16 changed files with 134 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

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.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

25 changes: 13 additions & 12 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ plugins {
id 'kotlin-android'
id 'com.google.devtools.ksp'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.10'
}

android {
@@ -13,13 +13,14 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 34
versionCode 319
versionName "8.4.0"
versionCode 320
versionName "8.4.1"

}

buildFeatures {
compose true
buildConfig true
}

buildTypes {
@@ -61,28 +62,28 @@ ksp {
}

dependencies {
implementation platform('androidx.compose:compose-bom:2023.08.00')
implementation platform('androidx.compose:compose-bom:2023.10.01')

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0"
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.work:work-runtime-ktx:2.8.1'
implementation 'androidx.activity:activity-ktx:1.8.0-alpha07'
implementation 'androidx.activity:activity-compose:1.7.2'
implementation 'androidx.activity:activity-ktx:1.8.0'
implementation 'androidx.activity:activity-compose:1.8.0'
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation 'androidx.compose.material:material'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
implementation 'androidx.navigation:navigation-compose:2.7.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2'
implementation 'androidx.navigation:navigation-compose:2.7.5'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'io.coil-kt:coil-compose:2.4.0'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'io.coil-kt:coil-compose:2.5.0'
implementation 'androidx.core:core-ktx:1.12.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.jayway.jsonpath:json-path:2.8.0'
debugImplementation "androidx.compose.ui:ui-tooling"

def room_version = "2.5.2"
def room_version = '2.6.0'

ksp "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-runtime:$room_version"
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ object DataMigration {

private fun fixRemovedExchanges(db: SupportSQLiteDatabase) {
val cursor = db.query("SELECT id, exchange FROM Widget ORDER BY id")
val allExchanges = Exchange.values().map { it.name }
val allExchanges = Exchange.entries.map { it.name }
val errored = mutableListOf<Int>()
while (cursor.moveToNext()) {
val exchange = cursor.getString(1)
Original file line number Diff line number Diff line change
@@ -18,30 +18,30 @@ abstract class WidgetDatabase : RoomDatabase() {
companion object {

private val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE Widget ADD COLUMN widgetType TEXT NOT NULL DEFAULT 'PRICE'")
database.execSQL("ALTER TABLE Widget ADD COLUMN showAmountLabel INTEGER NOT NULL DEFAULT 0")
database.execSQL("ALTER TABLE Widget ADD COLUMN amountHeld REAL")
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE Widget ADD COLUMN widgetType TEXT NOT NULL DEFAULT 'PRICE'")
db.execSQL("ALTER TABLE Widget ADD COLUMN showAmountLabel INTEGER NOT NULL DEFAULT 0")
db.execSQL("ALTER TABLE Widget ADD COLUMN amountHeld REAL")
}
}

private val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE Widget ADD COLUMN useInverse INTEGER NOT NULL DEFAULT 0")
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE Widget ADD COLUMN useInverse INTEGER NOT NULL DEFAULT 0")
}
}

private val MIGRATION_3_4 = object : Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
override fun migrate(db: SupportSQLiteDatabase) {
// not all devices support rename column yet
database.execSQL("""
db.execSQL("""
CREATE TABLE `Widget_New` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `widgetId` INTEGER NOT NULL, `widgetType` TEXT NOT NULL, `exchange` TEXT NOT NULL,
`coin` TEXT NOT NULL, `currency` TEXT NOT NULL, `coinCustomId` TEXT, `coinCustomName` TEXT, `currencyCustomName` TEXT, `showExchangeLabel` INTEGER NOT NULL,
`showCoinLabel` INTEGER NOT NULL, `showIcon` INTEGER NOT NULL, `numDecimals` INTEGER NOT NULL, `currencySymbol` TEXT, `theme` TEXT NOT NULL,
`nightMode` TEXT NOT NULL, `coinUnit` TEXT, `currencyUnit` TEXT, `customIcon` TEXT, `portraitTextSize` INTEGER, `landscapeTextSize` INTEGER, `lastValue` TEXT,
`amountHeld` REAL, `showAmountLabel` INTEGER NOT NULL, `useInverse` INTEGER NOT NULL, `lastUpdated` INTEGER NOT NULL, `state` TEXT NOT NULL)
""")
database.execSQL("""
db.execSQL("""
INSERT INTO Widget_New (id, widgetId, widgetType, exchange, coin, currency, coinCustomId, coinCustomName, currencyCustomName,
showExchangeLabel, showCoinLabel, showIcon, numDecimals, currencySymbol, theme, nightMode, coinUnit, currencyUnit,
customIcon, portraitTextSize, landscapeTextSize, lastValue, amountHeld, showAmountLabel, useInverse, lastUpdated, state)
@@ -50,15 +50,15 @@ abstract class WidgetDatabase : RoomDatabase() {
customIcon, portraitTextSize, landscapeTextSize, lastValue, amountHeld, showAmountLabel, useInverse, lastUpdated, state
FROM Widget
""")
database.execSQL("DROP TABLE Widget")
database.execSQL("ALTER TABLE Widget_New RENAME TO Widget")
database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_Widget_widgetId` ON `Widget` (`widgetId`)")
db.execSQL("DROP TABLE Widget")
db.execSQL("ALTER TABLE Widget_New RENAME TO Widget")
db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS `index_Widget_widgetId` ON `Widget` (`widgetId`)")
}
}

private val MIGRATION_4_5 = object : Migration(4, 5) {
override fun migrate(database: SupportSQLiteDatabase) {
val cursor = database.query("SELECT coinCustomId, customIcon FROM Widget ORDER BY id")
override fun migrate(db: SupportSQLiteDatabase) {
val cursor = db.query("SELECT coinCustomId, customIcon FROM Widget ORDER BY id")
while (cursor.moveToNext()) {
val coinCustomId = cursor.getString(0)
val customIcon = cursor.getString(1)
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ import kotlin.time.Duration.Companion.milliseconds

class CoinSelectionViewModel : ViewModel() {

private var allCoins = Coin.values().filterNot { it == Coin.CUSTOM }.associateBy { it.coinGeckoId }
private var allCoins = Coin.entries.filterNot { it == Coin.CUSTOM }.associateBy { it.coinGeckoId }

private val json = Json { ignoreUnknownKeys = true }
val coins = MutableStateFlow<SearchResponse?>(null)
Original file line number Diff line number Diff line change
@@ -2,17 +2,48 @@ package com.brentpanther.bitcoinwidget.ui.settings

import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.material.Card
import androidx.compose.material.ContentAlpha
import androidx.compose.material.Divider
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.ProvideTextStyle
import androidx.compose.material.RadioButton
import androidx.compose.material.Slider
import androidx.compose.material.SliderDefaults
import androidx.compose.material.Surface
import androidx.compose.material.Switch
import androidx.compose.material.SwitchDefaults
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -24,7 +55,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.brentpanther.bitcoinwidget.ui.theme.HighlightRippleTheme
import java.lang.Integer.max
import java.util.*
import java.util.Locale

@Composable
fun Setting(
@@ -157,24 +188,23 @@ fun SettingsEditText(
dialogVisible = false
}
) {
Surface(
shape = MaterialTheme.shapes.medium,
modifier = Modifier.padding(vertical = 8.dp)
Card(
modifier = Modifier
.wrapContentSize()
.safeContentPadding()
.padding(vertical = 36.dp, horizontal = 20.dp),
shape = RoundedCornerShape(16.dp),
) {
Column(
Modifier.padding(start = 20.dp, top = 20.dp)
Modifier.padding(16.dp)
)
{
Row(
Modifier.padding(bottom = 12.dp)
) {
Row {
ProvideTextStyle(value = MaterialTheme.typography.h6) {
title()
}
}
Row(
Modifier.padding(bottom = 8.dp)
) {
Row(Modifier.padding(vertical=8.dp)) {
dialogText?.invoke()
}
OutlinedTextField(
@@ -190,12 +220,12 @@ fun SettingsEditText(
singleLine = true,
onValueChange = {
tempValue = it
}
},
modifier = Modifier.padding(vertical=8.dp)
)
Row(
Modifier
.fillMaxWidth()
.padding(8.dp),
.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) {
TextButton(
@@ -205,7 +235,7 @@ fun SettingsEditText(
}
) {
Text(
stringResource(android.R.string.ok).uppercase(Locale.getDefault())
stringResource(android.R.string.ok).uppercase((Locale.getDefault()))
)
}
TextButton(
@@ -254,14 +284,17 @@ fun SettingsList(
dialogVisible = false
}
) {
Surface(
shape = MaterialTheme.shapes.medium,
modifier = Modifier.padding(vertical = 8.dp)
Card(
modifier = Modifier
.wrapContentSize()
.safeContentPadding()
.padding(vertical = 36.dp, horizontal = 20.dp),
shape = RoundedCornerShape(16.dp),
) {
Column {
Row(
Modifier.padding(start = 20.dp, top = 20.dp, bottom = 12.dp)
) {
Column (
Modifier.padding(16.dp)
){
Row {
ProvideTextStyle(value = MaterialTheme.typography.h6) {
title()
}
@@ -280,9 +313,7 @@ fun SettingsList(
}
}
Row(
Modifier
.fillMaxWidth()
.padding(8.dp),
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End
) {
TextButton(
@@ -322,8 +353,8 @@ fun SettingsSlider(
title: @Composable () -> Unit,
subtitle: (@Composable () -> Unit)? = null,
range: IntRange,
value: Int,
onChange: (Int) -> Unit
value: Float,
onChange: (Float) -> Unit
) {
Column {
Setting(
@@ -332,11 +363,12 @@ fun SettingsSlider(
subtitle = subtitle
)
Slider(
value.toFloat(),
value,
onValueChange = {
onChange(it.toInt())
onChange(it)
},
valueRange = range.first.toFloat()..range.last.toFloat(),
steps = range.last - range.first,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
Original file line number Diff line number Diff line change
@@ -24,6 +24,9 @@ import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
@@ -54,6 +57,7 @@ import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.text.ParseException
import java.util.Locale
import kotlin.math.roundToInt

@Composable
fun SettingsScreen(
@@ -83,7 +87,7 @@ fun BaseSettingsScreen(
ConfigurationWithSizes(15, false, 0, 0)
)
val context = LocalContext.current
val navEntries by navController.currentBackStack.collectAsState()
val navEntries by navController.visibleEntries.collectAsState()
val fromHome = navEntries.any { it.destination.route == "home" }
Scaffold(
topBar = {
@@ -423,6 +427,7 @@ private fun DisplaySection(
widget: Widget
) {
SettingsHeader(title = R.string.title_display)
var numDecimals by remember { mutableFloatStateOf(widget.numDecimals.toFloat()) }
SettingsSlider(
icon = {
Icon(painterResource(R.drawable.ic_decimal), null)
@@ -438,10 +443,11 @@ private fun DisplaySection(
}
Text(value)
},
value = widget.numDecimals,
value = numDecimals,
range = -1..10,
onChange = {
settingsViewModel.setNumDecimals(it)
numDecimals = it
settingsViewModel.setNumDecimals(it.roundToInt())
}
)
SettingsSwitch(
Loading

0 comments on commit bf3b00e

Please sign in to comment.