Skip to content

Commit

Permalink
Done SettingScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Dec 15, 2024
1 parent 99ddbd1 commit b3489cc
Show file tree
Hide file tree
Showing 44 changed files with 749 additions and 444 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ dependencies {
implementation(libs.compose.material.ripple)
implementation(libs.compose.material.icons.core)
implementation(libs.compose.material.icons.extended)
implementation(libs.compose.ui.viewbinding)
implementation(libs.constraintlayout.compose)

// Android Studio Preview support
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
android:localeConfig="@xml/locale_config"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/Theme.SimpMusic">
android:theme="@style/Theme.SimpMusic"
android:enableOnBackInvokedCallback="true"
tools:targetApi="tiramisu">
<receiver
android:name=".ui.widget.BasicWidget"
android:exported="false">
Expand All @@ -66,6 +68,7 @@
android:name=".ui.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:enableOnBackInvokedCallback="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -191,7 +194,7 @@
</service>
<service
android:name=".service.test.download.MusicDownloadService"
android:exported="false"
android:exported="true"
android:foregroundServiceType="dataSync">
<intent-filter>
<action android:name="androidx.media3.exoplayer.downloadService.action.RESTART" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,66 @@ class DataStoreManager(
}
}

val usingProxy =
settingsDataStore.data.map { preferences ->
preferences[USING_PROXY] ?: FALSE
}
suspend fun setUsingProxy(usingProxy: Boolean) {
withContext(Dispatchers.IO) {
if (usingProxy) {
settingsDataStore.edit { settings ->
settings[USING_PROXY] = TRUE
}
} else {
settingsDataStore.edit { settings ->
settings[USING_PROXY] = FALSE
}
}
}
}
val proxyType =
settingsDataStore.data.map { preferences ->
preferences[PROXY_TYPE]
}.map {
when (it) {
PROXY_TYPE_HTTP -> ProxyType.PROXY_TYPE_HTTP
PROXY_TYPE_SOCKS -> ProxyType.PROXY_TYPE_SOCKS
else -> ProxyType.PROXY_TYPE_HTTP
}
}
suspend fun setProxyType(proxyType: ProxyType) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[PROXY_TYPE] = when (proxyType) {
ProxyType.PROXY_TYPE_HTTP -> PROXY_TYPE_HTTP
ProxyType.PROXY_TYPE_SOCKS -> PROXY_TYPE_SOCKS
}
}
}
}
val proxyHost =
settingsDataStore.data.map { preferences ->
preferences[PROXY_HOST] ?: ""
}
suspend fun setProxyHost(proxyHost: String) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[PROXY_HOST] = proxyHost
}
}
}
val proxyPort =
settingsDataStore.data.map { preferences ->
preferences[PROXY_PORT] ?: 8000
}
suspend fun setProxyPort(proxyPort: Int) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[PROXY_PORT] = proxyPort
}
}
}

companion object Settings {
val COOKIE = stringPreferencesKey("cookie")
val LOGGED_IN = stringPreferencesKey("logged_in")
Expand Down Expand Up @@ -592,10 +652,21 @@ class DataStoreManager(
val HOME_LIMIT = intPreferencesKey("home_limit")
val CHART_KEY = stringPreferencesKey("chart_key")
val TRANSLUCENT_BOTTOM_BAR = stringPreferencesKey("translucent_bottom_bar")
val USING_PROXY = stringPreferencesKey("using_proxy")
val PROXY_TYPE = stringPreferencesKey("proxy_type")
val PROXY_HOST = stringPreferencesKey("proxy_host")
val PROXY_PORT = intPreferencesKey("proxy_port")
const val REPEAT_MODE_OFF = "REPEAT_MODE_OFF"
const val REPEAT_ONE = "REPEAT_ONE"
const val REPEAT_ALL = "REPEAT_ALL"
const val TRUE = "TRUE"
const val FALSE = "FALSE"
const val PROXY_TYPE_HTTP = "http"
const val PROXY_TYPE_SOCKS = "socks"
// Proxy type
enum class ProxyType {
PROXY_TYPE_HTTP,
PROXY_TYPE_SOCKS
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import java.time.LocalDateTime

class LocalPlaylistManager(
context: Context,
private val youTube: YouTube
) : BaseManager(context) {
override val tag: String = this.javaClass.simpleName

Expand Down Expand Up @@ -134,7 +135,7 @@ class LocalPlaylistManager(
emit(LocalResource.Success(getString(R.string.updated)))
val localPlaylist = localDataSource.getLocalPlaylist(id)
if (localPlaylist.youtubePlaylistId != null) {
YouTube
youTube
.editPlaylist(localPlaylist.youtubePlaylistId, newTitle)
.onSuccess {
emit(LocalResource.Success(getString(R.string.updated_to_youtube_playlist)))
Expand Down Expand Up @@ -198,7 +199,7 @@ class LocalPlaylistManager(
}
val ytPlaylistId = playlist.id
val id = ytPlaylistId.verifyYouTubePlaylistId()
YouTube
youTube
.customQuery(browseId = id, setLogin = true)
.onSuccess { res ->
val listContent: ArrayList<MusicShelfRenderer.Content> = arrayListOf()
Expand All @@ -222,7 +223,7 @@ class LocalPlaylistManager(
?.nextContinuationData
?.continuation
while (continueParam != null) {
YouTube
youTube
.customQuery(
"",
continuation = continueParam,
Expand Down Expand Up @@ -280,15 +281,15 @@ class LocalPlaylistManager(
emit(LocalResource.Loading())
val playlist = localDataSource.getLocalPlaylist(playlistId)
val res =
YouTube.createPlaylist(
youTube.createPlaylist(
playlist.title,
playlist.tracks,
)
val value = res.getOrNull()
if (res.isSuccess && value != null) {
val ytId = value.playlistId
Log.d(tag, "syncLocalPlaylistToYouTubePlaylist: $ytId")
YouTube
youTube
.getYouTubePlaylistFullTracksWithSetVideoId(ytId)
.onSuccess { list ->
Log.d(tag, "syncLocalPlaylistToYouTubePlaylist: onSuccess song ${list.map { it.first.title }}")
Expand Down Expand Up @@ -350,7 +351,7 @@ class LocalPlaylistManager(
val currentTracks = tracks.toMutableList()
localPlaylist.youtubePlaylistId?.let { ytId ->
Log.d(tag, "updateListTrackSynced: $ytId")
YouTube
youTube
.getYouTubePlaylistFullTracksWithSetVideoId(ytId)
.onSuccess { list ->
Log.d(tag, "updateListTrackSynced: onSuccess ${list.map { it.first.title }}")
Expand Down Expand Up @@ -427,7 +428,7 @@ class LocalPlaylistManager(

// Add to YouTube playlist
if (localPlaylist.youtubePlaylistId != null) {
YouTube
youTube
.addPlaylistItem(localPlaylist.youtubePlaylistId, song.videoId)
.onSuccess {
val data = it.playlistEditResults
Expand Down Expand Up @@ -465,7 +466,7 @@ class LocalPlaylistManager(
if (localPlaylist.youtubePlaylistId != null) {
val setVideoId = localDataSource.getSetVideoId(song.videoId)
if (setVideoId?.setVideoId != null) {
YouTube
youTube
.removeItemYouTubePlaylist(localPlaylist.youtubePlaylistId, song.videoId, setVideoId.setVideoId)
.onSuccess {
emit(LocalResource.Success(getString(R.string.removed_from_YouTube_playlist)))
Expand All @@ -483,7 +484,7 @@ class LocalPlaylistManager(
val localPlaylist = localDataSource.getLocalPlaylist(id)
val ytPlaylistId = localPlaylist.youtubePlaylistId ?: return@flow

YouTube
youTube
.getSuggestionsTrackForPlaylist(ytPlaylistId)
.onSuccess { data ->
val listSongItem = data?.second?.map { it.toTrack() }
Expand Down
Loading

0 comments on commit b3489cc

Please sign in to comment.