Skip to content

Commit

Permalink
Update to latest commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliano101 committed Dec 9, 2024
2 parents 4241cf4 + a1b6758 commit 7685dd1
Show file tree
Hide file tree
Showing 17 changed files with 2,402 additions and 1,640 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ dependencies {
implementation(libs.ssp.android)

implementation(libs.aboutlibraries)
implementation(libs.aboutlibraries.compose.m3)

implementation(libs.flexbox)
implementation(libs.balloon)
Expand Down
49 changes: 48 additions & 1 deletion app/src/main/java/com/maxrave/simpmusic/common/Config.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.maxrave.simpmusic.common

import android.content.Context
import android.util.Log
import com.maxrave.simpmusic.R
import java.time.LocalDateTime
import java.time.Month
Expand All @@ -25,7 +27,7 @@ object Config {
const val CANVAS_CACHE = "canvasCache"
const val SERVICE_SCOPE = "serviceScope"

val REMOVED_SONG_DATE_TIME = LocalDateTime.of(2003, Month.AUGUST, 26, 3, 0)
val REMOVED_SONG_DATE_TIME: LocalDateTime = LocalDateTime.of(2003, Month.AUGUST, 26, 3, 0)

val listOfHomeChip =
listOf(
Expand Down Expand Up @@ -217,6 +219,24 @@ object SUPPORTED_LANGUAGE {
"hi-IN",
"th-TH"
)
fun getLanguageFromCode(code: String?): String {
val index = codes.indexOf(code)
Log.d("Config", "getLanguageFromCode: $index")
if (index == -1) {
return "English"
}
Log.w("Config", "getLanguageFromCode: ${items.get(index)}")
return (items.getOrNull(index) ?: "English").toString()
}
fun getCodeFromLanguage(language: String?): String {
val index = items.indexOf(language ?: "English")
Log.d("Config", "getCodeFromLanguage: $index")
if (index == -1) {
return "en-US"
}
Log.w("Config", "getCodeFromLanguage: ${codes.getOrNull(index)}")
return (codes.getOrNull(index) ?: "en-US").toString()
}
}

object QUALITY {
Expand All @@ -236,6 +256,15 @@ object LYRICS_PROVIDER {
object LIMIT_CACHE_SIZE {
val items: Array<CharSequence> = arrayOf("100MB", "250MB", "500MB", "1GB", "2GB", "5GB", "8GB", "")
val data: Array<Int> = arrayOf(100, 250, 500, 1000, 2000, 5000, 8000, -1)

fun getDataFromItem(item: CharSequence?): Int {
val index = items.indexOf(item)
return data.getOrNull(index) ?: -1
}
fun getItemFromData(input: Int?): CharSequence {
val index = data.indexOf(input)
return items.getOrNull(index) ?: ""
}
}

object SPONSOR_BLOCK {
Expand All @@ -253,6 +282,24 @@ object SPONSOR_BLOCK {
R.string.poi_highlight,
R.string.filter,
)
fun fromDbToName(context: Context, list: List<CharSequence>): List<String> {
val result = mutableListOf<String>()
for (item in list) {
val index = list.indexOf(item)
result.add(context.getString(listName[index]))
}
return result
}
fun fromNameToDb(context: Context, input: List<String>): List<CharSequence> {
val allString = fromDbToName(context, list.toList())
val listIndex = allString.map {
allString.indexOf(it)
}
val result = listIndex.mapNotNull {
list.getOrNull(it)
}
return result
}
}

object CHART_SUPPORTED_COUNTRY {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ class DataStoreManager(private val settingsDataStore: DataStore<Preferences>) {
settings[stringPreferencesKey(category)] = TRUE
}
}
SPONSOR_BLOCK.list.filter { !categories.contains(it) }.forEach { category ->
settingsDataStore.edit { settings ->
settings[stringPreferencesKey(category.toString())] = FALSE
}
}
}
}

Expand Down
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 7685dd1

Please sign in to comment.