Skip to content

Commit

Permalink
Upgrade Compose, AS, and Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
mtotschnig committed Aug 23, 2023
1 parent 838e40e commit b04c0e0
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 37 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_compiler_version = '1.4.8'
kotlin_version = '1.8.22'
agp_version = '8.1.0'
compose_compiler_version = '1.5.1'
kotlin_version = '1.9.0'
agp_version = '8.1.1'
}
}
plugins {
Expand All @@ -19,7 +19,7 @@ plugins {
ext {
versionCode = 639
versionName = '3.6.2'
compileSdkVersion = 33
compileSdkVersion = 34
minSdkVersion = 21
targetSdkVersion = 33
espressoVersion = "3.5.1"
Expand Down Expand Up @@ -58,7 +58,7 @@ ext {
androidxSqlite = "2.3.1"
barista = "4.3.0"
googleHttp = "1.43.1"
composeBom = "androidx.compose:compose-bom:2023.05.01"
composeBom = "androidx.compose:compose-bom:2023.08.00"
}

allprojects {
Expand Down
1 change: 1 addition & 0 deletions fints/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation "androidx.compose.ui:ui"
implementation("androidx.compose.material3:material3")
implementation "androidx.compose.ui:ui-tooling-preview"
debugImplementation "androidx.compose.ui:ui-tooling"
implementation 'androidx.activity:activity-compose:1.7.2'
implementation "androidx.compose.material:material-icons-extended"
implementation "androidx.compose.runtime:runtime-livedata"
Expand Down
6 changes: 2 additions & 4 deletions fints/src/main/java/org/totschnig/fints/Banking.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ class Banking : ProtectedFragmentActivity() {
}

AlertDialog(
//https://issuetracker.google.com/issues/221643630
properties = DialogProperties(
dismissOnClickOutside = false,
usePlatformDefaultWidth = false
dismissOnClickOutside = false
),
onDismissRequest = {
dialogShown.value = null
Expand Down Expand Up @@ -272,7 +270,7 @@ class Banking : ProtectedFragmentActivity() {
}
},
text = {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
Column(modifier = Modifier.width(IntrinsicSize.Min).verticalScroll(rememberScrollState())) {
when (workState.value) {
is Loading -> {
Loading((workState.value as Loading).message)
Expand Down
7 changes: 4 additions & 3 deletions fints/src/main/java/org/totschnig/fints/Composables.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ fun BankingCredentials(
bankingCredentials.value = credentials.copy(password = it.trim())
},
label = { Text(text = "PIN") },
singleLine = true,
supportingText = { Text(text = stringResource(id = R.string.pin_info)) }
singleLine = true
)
// Not using supportingText parameter of OutlinedTextField, because of
// https://issuetracker.google.com/issues/270523016
Text(text = stringResource(id = R.string.pin_info))
}
}

Expand Down Expand Up @@ -108,5 +110,4 @@ fun TanDialog(
}
)
}

}
2 changes: 1 addition & 1 deletion fints/src/main/res/values-de/values.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<string name="enter_pin">PIN eingegeben</string>
<string name="bankleitzahl">Bankleitzahl</string>
<string name="login_name">Anmeldename</string>
<string name="pin_info">Der PIN wird nicht auf dem Gerät gespeichert und bei jeder weiteren Verbindung mit der Bank erneut abgefragt.</string>
<string name="pin_info">Der PIN wird nicht auf dem Gerät gespeichert und bei jeder Verbindung mit der Bank erneut abgefragt.</string>
<string name="btn_load_accounts">Konten laden</string>
<string name="no_bank_added_yet">Noch wurde kein Bankzugang hinzugefügt.</string>
<string name="import_maximum">Maximal verfügbaren Buchungsverlauf importieren</string>
Expand Down
2 changes: 1 addition & 1 deletion fints/src/main/res/values/values.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<string name="bankleitzahl">Bank number</string>
<string name="login_name">Login name</string>
Der PIN wird nicht auf dem Gerät gespeichert und bei jeder weiteren Verbindung mit der Bank erneut abgefragt.
<string name="pin_info">The PIN is not stored on the device and is requested again for each subsequent connection to the bank.</string>
<string name="pin_info">The PIN is not stored on the device and is requested again for each connection to the bank.</string>
<string name="btn_load_accounts">Load accounts</string>
<string name="no_bank_added_yet">No bank added yet.</string>
<string name="import_maximum">Import maximum available transaction history</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.LocalTextStyle
Expand Down Expand Up @@ -53,7 +53,6 @@ import eltos.simpledialogfragment.list.MenuDialog
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import org.totschnig.myexpenses.MyApplication
import org.totschnig.myexpenses.R
import org.totschnig.myexpenses.activity.ExpenseEdit.Companion.KEY_OCR_RESULT
import org.totschnig.myexpenses.activity.FilterHandler.Companion.FILTER_COMMENT_DIALOG
Expand Down Expand Up @@ -114,8 +113,10 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene
private val accountData: List<FullAccount>
get() = viewModel.accountData.value?.getOrNull() ?: emptyList()

private val currentPage = mutableStateOf(0)

var selectedAccountId: Long
get() = viewModel.accountData.value?.getOrNull()?.getOrNull(pagerState.currentPage)?.id ?: 0
get() = currentAccount?.id ?: 0
set(value) {
deferredAccountId = if (value != 0L) {
value
Expand All @@ -131,15 +132,13 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene
?.maxBy { it.lastUsed }
}

lateinit var pagerState: PagerState

private var deferredAccountId: Long? = null

val currentFilter: FilterPersistence
get() = viewModel.filterPersistence.getValue(selectedAccountId)

val currentAccount: FullAccount?
get() = accountData.getOrNull(pagerState.currentPage)
get() = accountData.getOrNull(currentPage.value)

@Inject
lateinit var discoveryHelper: IDiscoveryHelper
Expand Down Expand Up @@ -399,7 +398,6 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene
initLocaleContext()
maybeRepairRequerySchema()
readAccountGroupingFromPref()
pagerState = PagerState(initialPage = savedInstanceState?.getInt(KEY_CURRENT_PAGE) ?: 0)
accountSort = readAccountSortFromPref()
viewModel = ViewModelProvider(this)[modelClass]
with(injector) {
Expand Down Expand Up @@ -524,11 +522,9 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene
AccountList(
accountData = data,
grouping = accountGrouping.value,
selectedAccount = selectedAccountId,
currentPage = currentPage.value,
onSelected = {
lifecycleScope.launch {
pagerState.scrollToPage(it)
}
currentPage.value = it
closeDrawer()
},
onEdit = {
Expand Down Expand Up @@ -643,7 +639,7 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt(KEY_CURRENT_PAGE, pagerState.currentPage)
outState.putInt(KEY_CURRENT_PAGE, currentPage.value)
}

private fun editAccount(accountId: Long) {
Expand All @@ -653,11 +649,11 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene

}

private suspend fun deferredLoad() {
private fun deferredLoad() {
deferredAccountId?.let {
viewModel.accountData.value!!.getOrThrow().indexOfFirst { it.id == deferredAccountId }
.takeIf { it != -1 }.let {
pagerState.scrollToPage(it ?: 0)
currentPage.value = it ?: 0
}
deferredAccountId = null
}
Expand All @@ -667,7 +663,7 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene
@Composable
private fun MainContent() {

LaunchedEffect(pagerState.currentPage) {
LaunchedEffect(currentAccount) {
setCurrentAccount()?.let { account ->
finishActionMode()
sumInfo = SumInfoUnknown
Expand Down Expand Up @@ -698,6 +694,17 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene
}
}
if (accountData.isNotEmpty()) {
val pagerState = rememberPagerState(initialPage = 0) {
accountData.count()
}
LaunchedEffect(currentPage.value) {
if (pagerState.currentPage != currentPage.value) {
pagerState.scrollToPage(currentPage.value)
}
}
LaunchedEffect(pagerState.currentPage) {
currentPage.value = pagerState.currentPage
}
HorizontalPager(
modifier = Modifier
.background(MaterialTheme.colorScheme.onSurface)
Expand All @@ -706,7 +713,6 @@ abstract class BaseMyExpenses : LaunchActivity(), OcrHost, OnDialogResultListene
collectionInfo = CollectionInfo(1, accountData.size)
},
verticalAlignment = Alignment.Top,
pageCount = accountData.count(),
state = pagerState,
pageSpacing = 10.dp,
key = { accountData[it].id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ class DistributionActivity : DistributionBaseActivity<DistributionViewModel>(),
mDetector = GestureDetector(this,
object : SimpleOnGestureListener() {
override fun onFling(
e1: MotionEvent, e2: MotionEvent,
e1: MotionEvent?, e2: MotionEvent,
velocityX: Float, velocityY: Float
): Boolean {
//if (e1 == null) return false
if (e1 == null) return false
if (abs(e1.y - e2.y) > maxOffPath) return false
if (e1.x - e2.x > minDistance
&& abs(velocityX) > thresholdVelocity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import kotlin.math.roundToInt
fun AccountList(
accountData: List<FullAccount>,
grouping: AccountGrouping,
selectedAccount: Long,
currentPage: Int,
onSelected: (Int) -> Unit,
onEdit: (Long) -> Unit,
onDelete: (FullAccount) -> Unit,
Expand Down Expand Up @@ -82,7 +82,7 @@ fun AccountList(
AccountCard(
account = account,
isCollapsed = collapsedAccountIds.contains(account.id.toString()),
isSelected = account.id == selectedAccount,
isSelected = index == currentPage,
onSelected = { onSelected(index) },
onEdit = onEdit,
onDelete = onDelete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ fun CategoryEdit(
}
if (showIconSelection) {
Dialog(
onDismissRequest = { },
properties = DialogProperties(usePlatformDefaultWidth = true)
onDismissRequest = { }
) {
Surface(
shape = MaterialTheme.shapes.medium,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object ImageOptimizer {

private fun compressAndSaveImage(
bitmap: Bitmap,
compressFormat: Bitmap.CompressFormat?,
compressFormat: Bitmap.CompressFormat,
quality: Int,
outputStream: OutputStream
) = try {
Expand Down

0 comments on commit b04c0e0

Please sign in to comment.