Skip to content

Commit 3d71d11

Browse files
committed
Refine history retention and release build setup
1 parent a85847a commit 3d71d11

10 files changed

Lines changed: 52 additions & 24 deletions

File tree

app/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ android {
4242
release {
4343
signingConfig = signingConfigs.getByName("debug")
4444
isMinifyEnabled = true
45+
isShrinkResources = true
4546
proguardFiles(
4647
getDefaultProguardFile("proguard-android-optimize.txt"),
4748
"proguard-rules.pro"
@@ -106,8 +107,8 @@ dependencies {
106107
implementation(libs.retrofit)
107108
implementation(libs.retrofit.converter.gson)
108109
implementation(libs.okhttp)
109-
implementation(libs.okhttp.logging)
110110
implementation(libs.gson)
111+
debugImplementation(libs.okhttp.logging)
111112

112113
// DataStore
113114
implementation(libs.datastore.preferences)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.sasayaki.di
2+
3+
import okhttp3.OkHttpClient
4+
import okhttp3.logging.HttpLoggingInterceptor
5+
6+
internal fun OkHttpClient.Builder.applyDebugLogging(): OkHttpClient.Builder {
7+
return addInterceptor(
8+
HttpLoggingInterceptor().apply {
9+
level = HttpLoggingInterceptor.Level.BASIC
10+
}
11+
)
12+
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
package com.sasayaki
22

33
import android.app.Application
4+
import com.sasayaki.data.preferences.PreferencesDataStore
45
import dagger.hilt.android.HiltAndroidApp
6+
import kotlinx.coroutines.CoroutineScope
7+
import kotlinx.coroutines.Dispatchers
8+
import kotlinx.coroutines.SupervisorJob
9+
import kotlinx.coroutines.launch
10+
import javax.inject.Inject
511

612
@HiltAndroidApp
7-
class SasayakiApp : Application()
13+
class SasayakiApp : Application() {
14+
@Inject lateinit var preferencesDataStore: PreferencesDataStore
15+
16+
private val startupScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
17+
18+
override fun onCreate() {
19+
super.onCreate()
20+
startupScope.launch {
21+
preferencesDataStore.runStartupMigrations()
22+
}
23+
}
24+
}

app/src/main/java/com/sasayaki/data/db/dao/DictationDao.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ interface DictationDao {
1919
suspend fun getRawText(id: Long): String?
2020

2121
@Query("UPDATE dictations SET text = '', rawText = '', sourceApp = NULL, historyVisible = 0 WHERE id = :id")
22-
suspend fun delete(id: Long)
22+
suspend fun removeFromHistory(id: Long)
2323

2424
@Query("UPDATE dictations SET text = '', rawText = '', sourceApp = NULL, historyVisible = 0 WHERE historyVisible = 1")
25-
suspend fun clearHistory()
25+
suspend fun removeAllFromHistory()
2626

2727
@Query("DELETE FROM dictations WHERE id NOT IN (SELECT id FROM dictations ORDER BY timestamp DESC LIMIT :keep)")
2828
suspend fun pruneOldEntries(keep: Int)

app/src/main/java/com/sasayaki/data/preferences/PreferencesDataStore.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.Flow
1616
import kotlinx.coroutines.flow.catch
1717
import kotlinx.coroutines.flow.distinctUntilChanged
1818
import kotlinx.coroutines.flow.flowOn
19+
import kotlinx.coroutines.flow.first
1920
import kotlinx.coroutines.flow.map
2021
import java.io.IOException
2122
import javax.inject.Inject
@@ -56,8 +57,6 @@ class PreferencesDataStore @Inject constructor(
5657
}
5758
}
5859
.map { prefs ->
59-
migrateLegacySecretsIfNeeded(prefs)
60-
6160
UserPreferences(
6261
asrBaseUrl = prefs[Keys.ASR_BASE_URL] ?: "",
6362
asrApiKey = securePreferencesStore.getAsrApiKey(),
@@ -142,6 +141,10 @@ class PreferencesDataStore @Inject constructor(
142141
}
143142
}
144143

144+
suspend fun runStartupMigrations() {
145+
migrateLegacySecretsIfNeeded(context.dataStore.data.first())
146+
}
147+
145148
private fun resolveActiveLanguage(prefs: Preferences): String? {
146149
val preferred = parsePreferredLanguages(prefs)
147150
val active = prefs[Keys.ACTIVE_LANGUAGE]

app/src/main/java/com/sasayaki/di/NetworkModule.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.sasayaki.di
22

3-
import com.sasayaki.BuildConfig
43
import com.sasayaki.data.api.ApiClientFactory
54
import dagger.Module
65
import dagger.Provides
76
import dagger.hilt.InstallIn
87
import dagger.hilt.components.SingletonComponent
98
import okhttp3.OkHttpClient
10-
import okhttp3.logging.HttpLoggingInterceptor
119
import java.util.concurrent.TimeUnit
1210
import javax.inject.Singleton
1311

@@ -21,15 +19,7 @@ object NetworkModule {
2119
.connectTimeout(30, TimeUnit.SECONDS)
2220
.readTimeout(60, TimeUnit.SECONDS)
2321
.writeTimeout(60, TimeUnit.SECONDS)
24-
.apply {
25-
if (BuildConfig.DEBUG) {
26-
addInterceptor(
27-
HttpLoggingInterceptor().apply {
28-
level = HttpLoggingInterceptor.Level.BASIC
29-
}
30-
)
31-
}
32-
}
22+
.applyDebugLogging()
3323
.build()
3424
}
3525

app/src/main/java/com/sasayaki/service/FanMenuController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class FanMenuController(
113113
active = prefs.llmEnabled
114114
),
115115
FanMenuItem(
116-
label = "HIST",
116+
label = "SAVE",
117117
active = prefs.historyEnabled
118118
)
119119
)

app/src/main/java/com/sasayaki/ui/history/HistoryScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fun HistoryScreen(
105105
HistoryCard(
106106
dictation = dictation,
107107
onCopy = { copyToClipboard(context, dictation.text) },
108-
onDelete = { viewModel.delete(dictation.id) },
108+
onDelete = { viewModel.removeFromHistory(dictation.id) },
109109
onLoadRawText = { viewModel.getRawText(dictation.id) }
110110
)
111111
}
@@ -122,7 +122,7 @@ fun HistoryScreen(
122122
confirmButton = {
123123
TextButton(
124124
onClick = {
125-
viewModel.clearHistory()
125+
viewModel.removeAllFromHistory()
126126
showClearHistoryDialog = false
127127
}
128128
) {

app/src/main/java/com/sasayaki/ui/history/HistoryViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ class HistoryViewModel @Inject constructor(
4848
}
4949
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
5050

51-
fun delete(id: Long) {
51+
fun removeFromHistory(id: Long) {
5252
viewModelScope.launch {
53-
dictationDao.delete(id)
53+
dictationDao.removeFromHistory(id)
5454
}
5555
}
5656

57-
fun clearHistory() {
57+
fun removeAllFromHistory() {
5858
viewModelScope.launch {
59-
dictationDao.clearHistory()
59+
dictationDao.removeAllFromHistory()
6060
}
6161
}
6262

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.sasayaki.di
2+
3+
import okhttp3.OkHttpClient
4+
5+
internal fun OkHttpClient.Builder.applyDebugLogging(): OkHttpClient.Builder = this

0 commit comments

Comments
 (0)