Skip to content

Commit 1c88783

Browse files
committed
bug fixes
1 parent 105c938 commit 1c88783

13 files changed

Lines changed: 110 additions & 73 deletions

File tree

app/src/main/java/com/songlib/core/utils/AppConstants.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ object PrefConstants {
2424
const val INITIAL_BOOKS = "initialBooks"
2525
const val SELECTED_BOOKS = "selectedBooks"
2626

27-
const val DATA_SELECTED = "dataSelected"
28-
const val DATA_LOADED = "dataLoaded"
29-
const val SELECT_AFRESH = "selectAfresh"
27+
const val IS_DATA_SELECTED = "dataSelected"
28+
const val IS_DATA_LOADED = "dataLoaded"
29+
const val SELECT_A_FRESH = "selectAfresh"
3030
const val IS_PRO_USER = "isProUser"
3131
const val INSTALL_DATE = "install_date"
3232
const val REVIEW_REQUESTED = "review_requested"

app/src/main/java/com/songlib/domain/repos/ListingRepo.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import javax.inject.*
1010

1111
@Singleton
1212
class ListingRepo @Inject constructor(context: Context) {
13-
private var listingDao: ListingDao?
13+
private var listingsDao: ListingDao?
1414

1515
init {
1616
val db = AppDatabase.getDatabase(context)
17-
listingDao = db?.listingDao()
17+
listingsDao = db?.listingsDao()
1818
}
1919

2020
suspend fun fetchListings(parent: Int): List<ListingUi> {
2121
return withContext(Dispatchers.IO) {
22-
val allListings = listingDao?.getAll(parent) ?: emptyList()
22+
val allListings = listingsDao?.getAll(parent) ?: emptyList()
2323

2424
allListings.map { listing ->
2525
ListingUi(
@@ -29,7 +29,7 @@ class ListingRepo @Inject constructor(context: Context) {
2929
song = listing.song,
3030
created = listing.created,
3131
modified = listing.modified,
32-
songCount = listingDao?.countSongs(listing.id) ?: 0,
32+
songCount = listingsDao?.countSongs(listing.id) ?: 0,
3333
updatedAgo = listing.modified.toLongOrNull()?.toTimeAgo() ?: ""
3434
)
3535
}
@@ -46,21 +46,21 @@ class ListingRepo @Inject constructor(context: Context) {
4646
created = currentTime,
4747
modified = currentTime
4848
)
49-
listingDao?.insert(newListing)
49+
listingsDao?.insert(newListing)
5050
}
5151
}
5252

5353
suspend fun saveListItem(parent: ListingUi, song: Int) {
5454
withContext(Dispatchers.IO) {
5555
val currentTime = System.currentTimeMillis().toString()
56-
listingDao?.insert(Listing(
56+
listingsDao?.insert(Listing(
5757
parent = parent.id,
5858
title = "",
5959
song = song,
6060
created = currentTime,
6161
modified = currentTime
6262
))
63-
listingDao?.update(Listing(
63+
listingsDao?.update(Listing(
6464
parent = parent.id,
6565
title = parent.title,
6666
song = song,
@@ -73,7 +73,7 @@ class ListingRepo @Inject constructor(context: Context) {
7373
suspend fun updateListing(listing: ListingUi) {
7474
val currentTime = System.currentTimeMillis().toString()
7575
withContext(Dispatchers.IO) {
76-
listingDao?.update(Listing(
76+
listingsDao?.update(Listing(
7777
parent = listing.id,
7878
title = listing.title,
7979
song = listing.song,
@@ -85,13 +85,13 @@ class ListingRepo @Inject constructor(context: Context) {
8585

8686
suspend fun deleteById(listId: Int) {
8787
withContext(Dispatchers.IO) {
88-
listingDao?.deleteById(listId)
88+
listingsDao?.deleteById(listId)
8989
}
9090
}
9191

9292
suspend fun deleteAllListings() {
9393
withContext(Dispatchers.IO) {
94-
listingDao?.deleteAll()
94+
listingsDao?.deleteAll()
9595
}
9696
}
9797

app/src/main/java/com/songlib/domain/repos/PrefsRepo.kt

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,48 @@ class PrefsRepo @Inject constructor(
2222
set(value) = prefs.edit { putString(PrefConstants.SELECTED_BOOKS, value) }
2323

2424
var isDataSelected: Boolean
25-
get() = prefs.getBoolean(PrefConstants.DATA_SELECTED, false)
26-
set(value) = prefs.edit { putBoolean(PrefConstants.DATA_SELECTED, value) }
25+
get() = {
26+
val value = prefs.getBoolean(PrefConstants.IS_DATA_SELECTED, false)
27+
value
28+
}()
29+
set(value) = {
30+
prefs.edit {
31+
putBoolean(PrefConstants.IS_DATA_SELECTED, value)
32+
}
33+
}()
2734

2835
var selectAfresh: Boolean
29-
get() = prefs.getBoolean(PrefConstants.SELECT_AFRESH, false)
30-
set(value) = prefs.edit { putBoolean(PrefConstants.SELECT_AFRESH, value) }
36+
get() = {
37+
val value = prefs.getBoolean(PrefConstants.SELECT_A_FRESH, false)
38+
value
39+
}()
40+
set(value) = {
41+
prefs.edit {
42+
putBoolean(PrefConstants.SELECT_A_FRESH, value)
43+
}
44+
}()
3145

3246
var isProUser: Boolean
33-
get() = prefs.getBoolean(PrefConstants.IS_PRO_USER, false)
34-
set(value) = prefs.edit { putBoolean(PrefConstants.IS_PRO_USER, value) }
47+
get() = {
48+
val value = prefs.getBoolean(PrefConstants.IS_PRO_USER, false)
49+
value
50+
}()
51+
set(value) = {
52+
prefs.edit {
53+
putBoolean(PrefConstants.IS_PRO_USER, value)
54+
}
55+
}()
3556

3657
var isDataLoaded: Boolean
37-
get() = prefs.getBoolean(PrefConstants.DATA_LOADED, false)
38-
set(value) = prefs.edit { putBoolean(PrefConstants.DATA_LOADED, value) }
58+
get() = {
59+
val value = prefs.getBoolean(PrefConstants.IS_DATA_LOADED, false)
60+
value
61+
}()
62+
set(value) = {
63+
prefs.edit {
64+
putBoolean(PrefConstants.IS_DATA_LOADED, value)
65+
}
66+
}()
3967

4068
var appThemeMode: ThemeMode
4169
get() = ThemeMode.valueOf(
@@ -45,8 +73,15 @@ class PrefsRepo @Inject constructor(
4573
set(value) = prefs.edit { putString(PrefConstants.THEME_MODE, value.name) }
4674

4775
var horizontalSlides: Boolean
48-
get() = prefs.getBoolean(PrefConstants.HORIZONTAL_SLIDES, false)
49-
set(value) = prefs.edit { putBoolean(PrefConstants.HORIZONTAL_SLIDES, value) }
76+
get() = {
77+
val value = prefs.getBoolean(PrefConstants.HORIZONTAL_SLIDES, false)
78+
value
79+
}()
80+
set(value) = {
81+
prefs.edit {
82+
putBoolean(PrefConstants.HORIZONTAL_SLIDES, value)
83+
}
84+
}()
5085

5186
var lastAppOpenTime: Long
5287
get() = prefs.getLong(PrefConstants.LAST_APP_OPEN_TIME, 0L)

app/src/main/java/com/songlib/domain/repos/TrackingRepo.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,70 @@ import javax.inject.*
1111
class TrackingRepo @Inject constructor(
1212
context: Context,
1313
) {
14-
private var historyDao: HistoryDao?
15-
private var searchDao: SearchDao?
14+
private var historiesDao: HistoryDao?
15+
private var searchesDao: SearchDao?
1616

1717
init {
1818
val db = AppDatabase.getDatabase(context)
19-
historyDao = db?.historyDao()
20-
searchDao = db?.searchDao()
19+
historiesDao = db?.historiesDao()
20+
searchesDao = db?.searchesDao()
2121
}
2222

2323
suspend fun saveHistory(history: History) {
2424
withContext(Dispatchers.IO) {
25-
historyDao?.insert(history)
25+
historiesDao?.insert(history)
2626
}
2727
}
2828

2929
suspend fun saveSearch(search: Search) {
3030
withContext(Dispatchers.IO) {
31-
searchDao?.insert(search)
31+
searchesDao?.insert(search)
3232
}
3333
}
3434

3535
suspend fun fetchHistories(): List<History> {
3636
var allHistories: List<History>
3737
withContext(Dispatchers.IO) {
38-
allHistories = historyDao?.getAll() ?: emptyList()
38+
allHistories = historiesDao?.getAll() ?: emptyList()
3939
}
4040
return allHistories
4141
}
4242

4343
suspend fun fetchSearches(): List<Search> {
4444
var allSearches: List<Search>
4545
withContext(Dispatchers.IO) {
46-
allSearches = searchDao?.getAll() ?: emptyList()
46+
allSearches = searchesDao?.getAll() ?: emptyList()
4747
}
4848
return allSearches
4949
}
5050

5151
suspend fun updateSearch(search: Search) {
5252
withContext(Dispatchers.IO) {
53-
searchDao?.update(search)
53+
searchesDao?.update(search)
5454
}
5555
}
5656

5757
suspend fun deleteHistoryById(id: Int) {
5858
withContext(Dispatchers.IO) {
59-
historyDao?.deleteById(id)
59+
historiesDao?.deleteById(id)
6060
}
6161
}
6262

6363
suspend fun deleteAllHistories() {
6464
withContext(Dispatchers.IO) {
65-
historyDao?.deleteAll()
65+
historiesDao?.deleteAll()
6666
}
6767
}
6868

6969
suspend fun deleteSearchById(id: Int) {
7070
withContext(Dispatchers.IO) {
71-
searchDao?.deleteById(id)
71+
searchesDao?.deleteById(id)
7272
}
7373
}
7474

7575
suspend fun deleteAllSearches() {
7676
withContext(Dispatchers.IO) {
77-
searchDao?.deleteAll()
77+
searchesDao?.deleteAll()
7878
}
7979
}
8080

app/src/main/java/com/songlib/presentation/components/listitems/SongBook.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ fun SongBook(
4747
) {
4848
Text(
4949
text = buildAnnotatedString {
50-
withStyle(style = SpanStyle(fontSize = 16.sp, color = txtColor)) {
50+
withStyle(style = SpanStyle(fontSize = 18.sp, color = txtColor)) {
5151
append(refineTitle(item.data.title))
5252
}
5353
append(" ")
54-
withStyle(style = SpanStyle(fontSize = 12.sp, color = txtColor.copy(alpha = 0.7f))) {
54+
withStyle(style = SpanStyle(fontSize = 14.sp, color = txtColor.copy(alpha = 0.7f))) {
5555
append("(${item.data.songs})")
5656
}
5757
},

app/src/main/java/com/songlib/presentation/home/components/HomeAppBar.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import androidx.compose.material.icons.Icons
44
import androidx.compose.material.icons.filled.*
55
import androidx.compose.material3.*
66
import androidx.compose.runtime.*
7-
import androidx.compose.ui.platform.LocalContext
87
import com.songlib.data.models.Song
9-
import com.songlib.domain.repos.PrefsRepo
108
import com.songlib.presentation.components.action.AppTopBar
119
import com.songlib.presentation.components.general.QuickFormDialog
1210
import com.songlib.presentation.home.HomeViewModel
@@ -21,8 +19,6 @@ fun HomeSearchAppBar(
2119
onShareClick: () -> Unit,
2220
onClearSelection: () -> Unit,
2321
) {
24-
val context = LocalContext.current
25-
val prefs = remember { PrefsRepo(context) }
2622
var showAddDialog by remember { mutableStateOf(false) }
2723
var showListingSheet by remember { mutableStateOf(false) }
2824
val isProUser by viewModel.isProUser.collectAsState()
@@ -63,8 +59,7 @@ fun HomeSearchAppBar(
6359
}
6460

6561
AppTopBar(
66-
// title = if (selectedSongs.isEmpty()) "SongLib" else "${selectedSongs.size} selected",
67-
title = if (prefs.isDataLoaded) "True" else "False",
62+
title = "SongLib",
6863
actions = {
6964
if (selectedSongs.isEmpty()) {
7065
IconButton(onClick = onSearchClick) {

app/src/main/java/com/songlib/presentation/navigation/AppNavHost.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import com.songlib.presentation.listing.view.ListingScreen
1515
import com.songlib.presentation.presenter.PresenterViewModel
1616
import com.songlib.presentation.presenter.view.PresenterScreen
1717
import com.songlib.presentation.selection.SelectionViewModel
18-
import com.songlib.presentation.selection.view.Step1Screen
19-
import com.songlib.presentation.selection.step2.Step2ViewModel
20-
import com.songlib.presentation.selection.step2.view.Step2Screen
18+
import com.songlib.presentation.selection.view.SelectionScreen
2119
import com.songlib.presentation.settings.SettingsViewModel
2220
import com.songlib.presentation.settings.view.SettingsScreen
2321
import com.songlib.presentation.splash.SplashViewModel
@@ -39,23 +37,15 @@ fun AppNavHost(
3937
SplashScreen(navController = navController, viewModel = viewModel)
4038
}
4139

42-
composable(Routes.STEP_1) {
40+
composable(Routes.SELECTION) {
4341
val viewModel: SelectionViewModel = hiltViewModel()
44-
Step1Screen(
42+
SelectionScreen(
4543
navController = navController,
4644
viewModel = viewModel,
4745
themeRepo = themeRepo,
4846
)
4947
}
5048

51-
composable(Routes.STEP_2) {
52-
val viewModel: Step2ViewModel = hiltViewModel()
53-
Step2Screen(
54-
navController = navController,
55-
viewModel = viewModel,
56-
)
57-
}
58-
5949
composable(Routes.HOME) {
6050
val viewModel: HomeViewModel = hiltViewModel()
6151
HomeScreen(

app/src/main/java/com/songlib/presentation/navigation/Routes.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package com.songlib.presentation.navigation
22

33
object Routes {
44
const val SPLASH = "splash"
5-
const val STEP_1 = "step1"
6-
const val STEP_2 = "step2"
5+
const val SELECTION = "selection"
76
const val HOME = "home"
87
const val PRESENTER = "presenter"
98
const val LISTING = "listing"

app/src/main/java/com/songlib/presentation/selection/SelectionViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ class SelectionViewModel @Inject constructor(
9898

9999
prefsRepo.selectedBooks = newIds.joinToString(",")
100100
} else {
101+
prefsRepo.isDataSelected = true
101102
songbkRepo.saveBooks(books)
102103
prefsRepo.selectedBooks = books.joinToString(",") { it.bookId.toString() }
103104
}
104105

105-
prefsRepo.isDataSelected = true
106106
fetchRemoteSongs(books.map { it.bookId })
107107
} catch (e: Exception) {
108108
Log.e("SaveBooks", "Failed to save books", e)
@@ -118,6 +118,7 @@ class SelectionViewModel @Inject constructor(
118118
songbkRepo.fetchAndSaveSongs(bookIds)
119119
}
120120

121+
prefsRepo.isDataLoaded = true
121122
Log.d("TAG", "Song fetch and save completed")
122123
_uiState.tryEmit(UiState.Saved)
123124

app/src/main/java/com/songlib/presentation/selection/view/SelectionContent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fun SelectionContent(
3636
SongBook(
3737
item = book,
3838
onClick = { onBookClick(book) },
39-
modifier = Modifier.height(60.dp)
39+
modifier = Modifier.height(90.dp)
4040
)
4141
}
4242
}

0 commit comments

Comments
 (0)