Skip to content

Commit

Permalink
improved playlist fetch and editing
Browse files Browse the repository at this point in the history
  • Loading branch information
icefields committed May 23, 2024
1 parent 00f1284 commit 0d3e2d9
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 281 deletions.
16 changes: 13 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ android {
val ampacheUser = properties.getProperty("AMPACHE_USER")
val ampachePass = properties.getProperty("AMPACHE_PASSWORD")
val ampacheUrl = properties.getProperty("AMPACHE_URL")
val ampacheUrlLocal = properties.getProperty("LOCAL_STABLE_URL")
val dogmazicPass = properties.getProperty("DOGMAZIC_PASSWORD")
val dogmazicUser = properties.getProperty("DOGMAZIC_USER")
val dogmazicEmail = properties.getProperty("DOGMAZIC_EMAIL")
val errorLogUrl = properties.getProperty("URL_ERROR_LOG")
val localDevUser = properties.getProperty("LOCAL_DEV_USER")
val localDevPass = properties.getProperty("LOCAL_DEV_PASSWORD")
val localDevUrl = properties.getProperty("LOCAL_DEVELOPMENT_URL")
val errorReportEmail = properties.getProperty("ERROR_REPORT_EMAIL")
val pastebinApiKey = properties.getProperty("PASTEBIN_API_KEY")
val localNextcloudUser = properties.getProperty("LOCAL_NEXTCLOUD_USER")
val localNextcloudPass = properties.getProperty("LOCAL_NEXTCLOUD_PASSWORD")
val localNextcloudUrl = properties.getProperty("LOCAL_NEXTCLOUD_URL")

defaultConfig {
applicationId = "luci.sixsixsix.powerampache2"
minSdk = 28
targetSdk = 34
versionCode = 55
versionName = "1.00-55"
val versionQuote = "This version is powered by the beginning of the music revolution (FDroid second release)"
versionCode = 56
versionName = "1.00-56"
val versionQuote = "This version is powered by financial debt"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand All @@ -65,6 +70,11 @@ android {

buildConfigField("String", "VERSION_QUOTE", "\"$versionQuote\"")
buildConfigField("String", "ERROR_REPORT_EMAIL", errorReportEmail)
buildConfigField("String", "LOCAL_NEXTCLOUD_USER", localNextcloudUser)
buildConfigField("String", "LOCAL_NEXTCLOUD_PASSWORD", localNextcloudPass)
buildConfigField("String", "LOCAL_NEXTCLOUD_URL", localNextcloudUrl)
buildConfigField("String", "DEBUG_LOCAL_STABLE_URL", ampacheUrlLocal)
buildConfigField("String", "DEBUG_LOCAL_DEVELOPMENT_URL", localDevUrl)
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ object Constants {
const val DATABASE_LIMIT_ELEMENTS = 66
const val QUICK_PLAY_MIN_SONGS = 50
const val USER_ACCESS_DEFAULT = 25
const val USER_EMAIL_DEFAULT = "" //""[email protected]"
const val USER_EMAIL_DEFAULT = ""
const val USER_FULL_NAME_PUBLIC_DEFAULT = 0
const val PLAYLIST_FETCH_LIMIT = 50
const val NETWORK_REQUEST_LIMIT_ARTISTS = 30
const val NETWORK_REQUEST_LIMIT_SONGS = 40
const val NETWORK_REQUEST_LIMIT_SONGS_SEARCH = 100
Expand All @@ -65,7 +64,6 @@ object Constants {
const val USER_ID_ERROR = ERROR_INT

// FLAGS
const val RESET_QUEUE_ON_NEW_SESSION = BuildConfig.RESET_QUEUE_ON_NEW_SESSION
const val CLEAR_TABLE_AFTER_FETCH = false
const val ALWAYS_FETCH_ALL_PLAYLISTS = true

Expand All @@ -92,4 +90,8 @@ object Constants {
const val DOGMAZIC_FAKE_USERNAME = "PowerAmpache"
const val DOGMAZIC_FAKE_STATE = "Ehime"
const val DOGMAZIC_FAKE_CITY = "Aoshima"

// fetch this from remote config or initialize locally
const val CONFIG_URL = "https://icefields.github.io/powerampache/config.json"
var config = Pa2Config()
}
39 changes: 0 additions & 39 deletions app/src/main/java/luci/sixsixsix/powerampache2/common/Event.kt

This file was deleted.

45 changes: 45 additions & 0 deletions app/src/main/java/luci/sixsixsix/powerampache2/common/Pa2Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (C) 2024 Antonio Tari
*
* This file is a part of Power Ampache 2
* Ampache Android client application
* @author Antonio Tari
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*
*/
package luci.sixsixsix.powerampache2.common

import luci.sixsixsix.powerampache2.BuildConfig

const val PLAYLIST_FETCH_LIMIT = 100
const val PLAYLIST_ADD_NEW_ENABLE = true
const val RESET_QUEUE_ON_NEW_SESSION = BuildConfig.RESET_QUEUE_ON_NEW_SESSION
const val DOGMAZIC_USER = BuildConfig.DOGMAZIC_USER

data class Pa2Config(
// use new fast method for adding albums and playlists to playlist
val playlistAddNewEnable: Boolean = PLAYLIST_ADD_NEW_ENABLE,

// reset queue on new session
val queueResetOnNewSession: Boolean = RESET_QUEUE_ON_NEW_SESSION,

val dogmazicDemoUser: String = DOGMAZIC_USER,

// limit of songs to fetch for playlists
// - bigger number results in faster fetching
// - smaller number will result in data becoming visible to the user faster, but it will
// take longer to completely fetch big playlists
val playlistSongsFetchLimit: Int = PLAYLIST_FETCH_LIMIT,
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ abstract class BaseAmpacheRepository(
private val errHandler: ErrorHandler
) {
protected val dao = db.dao
//protected var offlineModeEnabledLiveData = dao.offlineModeEnabled().distinctUntilChanged().map { it == true }

val settingsLiveData: LiveData<LocalSettings?>
get() = dao.settingsLiveData().distinctUntilChanged().map {
Expand Down Expand Up @@ -135,7 +134,6 @@ abstract class BaseAmpacheRepository(
}
}


protected suspend fun cacheSongs(songs: List<Song>) {
val credentials = getCurrentCredentials()
dao.insertSongs(songs.map { it.toSongEntity(username = credentials.username, serverUrl = credentials.serverUrl) })
Expand Down Expand Up @@ -176,7 +174,6 @@ abstract class BaseAmpacheRepository(
MainNetwork.Type.playlist -> dao.getAllPlaylists()
.firstOrNull { it.id == id}?.copy(flag = flag)?.let { dbPlaylist ->
dao.insertPlaylists(listOf(dbPlaylist))
L("like inserted")
}
}
if (!isOfflineModeEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import kotlinx.coroutines.launch
import luci.sixsixsix.mrlog.L
import luci.sixsixsix.powerampache2.BuildConfig
import luci.sixsixsix.powerampache2.common.Constants
import luci.sixsixsix.powerampache2.common.Pa2Config
import luci.sixsixsix.powerampache2.common.Resource
import luci.sixsixsix.powerampache2.common.sha256
import luci.sixsixsix.powerampache2.data.local.MusicDatabase
Expand All @@ -53,6 +54,7 @@ import luci.sixsixsix.powerampache2.data.local.multiuserDbKey
import luci.sixsixsix.powerampache2.data.remote.MainNetwork
import luci.sixsixsix.powerampache2.data.remote.dto.toError
import luci.sixsixsix.powerampache2.data.remote.dto.toGenre
import luci.sixsixsix.powerampache2.data.remote.dto.toPa2Config
import luci.sixsixsix.powerampache2.data.remote.dto.toServerInfo
import luci.sixsixsix.powerampache2.data.remote.dto.toSession
import luci.sixsixsix.powerampache2.domain.MusicRepository
Expand Down Expand Up @@ -84,6 +86,8 @@ class MusicRepositoryImpl @Inject constructor(
): BaseAmpacheRepository(api, db, errorHandler), MusicRepository {
private val _serverInfoStateFlow = MutableStateFlow(ServerInfo())
override val serverInfoStateFlow: StateFlow<ServerInfo> = _serverInfoStateFlow
val serverVersionStateFlow = serverInfoStateFlow.mapNotNull { it.version }.distinctUntilChanged()

override val sessionLiveData = dao.getSessionLiveData().map { it?.toSession() }
override val userLiveData: Flow<User?> = dao.getUserLiveData().map {
val cred = getCurrentCredentials()
Expand All @@ -94,6 +98,7 @@ class MusicRepositoryImpl @Inject constructor(
// used to check if a call to getUserNetwork() is necessary
private var currentAuthToken: String? = null
private var currentUser: User? = null

init {
// Things to do when we get new or different session
// user will itself emit a user object to observe
Expand All @@ -110,6 +115,18 @@ class MusicRepositoryImpl @Inject constructor(
}
}
}

GlobalScope.launch {
initialize()
}
}

private suspend fun initialize() {
Constants.config = try {
api.getConfig().toPa2Config()
} catch (e: Exception) {
Pa2Config()
}
}

private suspend fun setSession(se: Session) {
Expand Down Expand Up @@ -280,17 +297,17 @@ class MusicRepositoryImpl @Inject constructor(
return@flow
}

val auth = getSession()!!
val auth = authToken()
val serverVersion = try {
serverInfoStateFlow.value.version?.split(".")?.firstOrNull()?.let { version ->
if (version.isDigitsOnly()) version.toInt() else Int.MAX_VALUE
} ?: Int.MAX_VALUE
} catch (e: Exception) { Int.MAX_VALUE } // set to max value in case of errors to force the newest api

val response = if (serverVersion >= 5) {
api.getGenres(authKey = auth.auth).genres!!.map { it.toGenre() }
api.getGenres(authKey = auth).genres!!.map { it.toGenre() }
} else {
api.getTags(authKey = auth.auth).tags!!.map { it.toGenre() }
api.getTags(authKey = auth).tags!!.map { it.toGenre() }
}

if (Constants.CLEAR_TABLE_AFTER_FETCH) {
Expand Down
Loading

0 comments on commit 0d3e2d9

Please sign in to comment.