Skip to content

Commit

Permalink
70% SettingScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Dec 7, 2024
1 parent 6bfee80 commit 1c53a63
Show file tree
Hide file tree
Showing 11 changed files with 1,927 additions and 1,116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import java.time.LocalDateTime
class LocalDataSource(
private val databaseDao: DatabaseDao,
) {
fun checkpoint() = databaseDao.checkpoint()

suspend fun getAllRecentData() = databaseDao.getAllRecentData()

suspend fun getAllDownloadedPlaylist() = databaseDao.getAllDownloadedPlaylist()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.maxrave.simpmusic.common.QUALITY
import com.maxrave.simpmusic.common.VIDEO_QUALITY
import com.maxrave.simpmusic.data.dataStore.DataStoreManager
import com.maxrave.simpmusic.data.db.LocalDataSource
import com.maxrave.simpmusic.data.db.MusicDatabase
import com.maxrave.simpmusic.data.db.entities.AlbumEntity
import com.maxrave.simpmusic.data.db.entities.ArtistEntity
import com.maxrave.simpmusic.data.db.entities.FollowedArtistSingleAndAlbum
Expand Down Expand Up @@ -107,9 +108,20 @@ import kotlin.math.abs
class MainRepository(
private val localDataSource: LocalDataSource,
private val dataStoreManager: DataStoreManager,
private val database: MusicDatabase,
private val context: Context,
) {
// Database
fun closeDatabase() {
if (database.isOpen) {
database.close()
}
}

fun getDatabasePath() = database.openHelper.writableDatabase.path

fun databaseDaoCheckpoint() = localDataSource.checkpoint()

fun getSearchHistory(): Flow<List<SearchHistory>> =
flow {
emit(localDataSource.getSearchHistory())
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/maxrave/simpmusic/di/DatabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ val databaseModule =
object : Migration(5, 6) {
override fun migrate(db: SupportSQLiteDatabase) {
val playlistSongMaps = mutableListOf<PairSongLocalPlaylist>()
db
db.query("SELECT * FROM local_playlist".toSQLiteQuery()).use { cursor ->
while (cursor.moveToNext()) {
val input = cursor.getString(8)
Expand Down Expand Up @@ -176,7 +175,7 @@ val databaseModule =
}
// MainRepository
single(createdAtStart = true) {
MainRepository(get<LocalDataSource>(), get<DataStoreManager>(), androidContext())
MainRepository(get<LocalDataSource>(), get<DataStoreManager>(), get<MusicDatabase>(), androidContext())
}
// List of managers

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/maxrave/simpmusic/di/ViewModelModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.maxrave.simpmusic.viewModel.AlbumViewModel
import com.maxrave.simpmusic.viewModel.LibraryDynamicPlaylistViewModel
import com.maxrave.simpmusic.viewModel.LibraryViewModel
import com.maxrave.simpmusic.viewModel.NowPlayingBottomSheetViewModel
import com.maxrave.simpmusic.viewModel.SettingsViewModel
import org.koin.android.ext.koin.androidApplication
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module
Expand All @@ -31,4 +32,9 @@ val viewModelModule = module {
application = androidApplication()
)
}
viewModel {
SettingsViewModel(
application = androidApplication()
)
}
}
20 changes: 19 additions & 1 deletion app/src/main/java/com/maxrave/simpmusic/extension/AllExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,22 @@ fun String.toSQLiteQuery(): SimpleSQLiteQuery = SimpleSQLiteQuery(this)

fun InputStream.zipInputStream(): ZipInputStream = ZipInputStream(this)

fun OutputStream.zipOutputStream(): ZipOutputStream = ZipOutputStream(this)
fun OutputStream.zipOutputStream(): ZipOutputStream = ZipOutputStream(this)

fun Long?.bytesToMB(): Long {
val mbInBytes = 1024 * 1024
return this?.div(mbInBytes) ?: 0L
}

fun getSizeOfFile(dir: File): Long {
var dirSize: Long = 0
if (!dir.listFiles().isNullOrEmpty()) {
for (f in dir.listFiles()!!) {
dirSize += f.length()
if (f.isDirectory) {
dirSize += getSizeOfFile(f)
}
}
}
return dirSize
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.maxrave.simpmusic.ui.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.maxrave.simpmusic.extension.greyScale
import com.maxrave.simpmusic.ui.theme.typo

@Composable
fun SettingItem(
title: String = "Title",
subtitle: String = "Subtitle",
smallSubtitle: Boolean = false,
isEnable: Boolean = true,
onClick: (() -> Unit)? = null,
switch: Pair<Boolean, ((Boolean) -> Unit)>? = null,
otherView: @Composable (() -> Unit)? = null
) {
Box(
Modifier
.then(
if (onClick != null && isEnable) Modifier.clickable { onClick.invoke() }
else Modifier
)
.then(
if (!isEnable) Modifier.greyScale()
else Modifier
)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(
vertical = 8.dp,
horizontal = 24.dp
),
verticalAlignment = Alignment.CenterVertically,
) {
Column(
modifier = Modifier.weight(1f),
horizontalAlignment = Alignment.Start
) {
Text(text = title, style = typo.labelMedium)
Spacer(Modifier.height(4.dp))
Text(text = subtitle, style = if (smallSubtitle) typo.bodySmall else typo.bodyMedium, maxLines = 2)

otherView?.let {
Spacer(Modifier.height(16.dp))
it.invoke()
}
}
if (switch != null) {
Spacer(Modifier.width(10.dp))
Switch(
modifier = Modifier.wrapContentWidth(),
checked = switch.first,
onCheckedChange = {
switch.second.invoke(it)
}
)
}
}
}
}
Loading

0 comments on commit 1c53a63

Please sign in to comment.