Merge branch 'develop' into ready/removeMergeAdapter

This commit is contained in:
Nite 2021-12-20 08:56:31 +01:00 committed by GitHub
commit 941fbd907f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 76 additions and 158 deletions

View File

@ -152,6 +152,12 @@ class NavigationActivity : AppCompatActivity() {
var showWelcomeScreen = Util.isFirstRun()
val areServersMigrated: Boolean = serverSettingsModel.migrateFromPreferences()
// Migrate Feature storage if needed
// TODO: Remove in December 2022
if (!Settings.hasKey(Constants.PREFERENCES_KEY_USE_FIVE_STAR_RATING)) {
Settings.migrateFeatureStorage()
}
// If there are any servers in the DB, do not show the welcome screen
showWelcomeScreen = showWelcomeScreen and !areServersMigrated

View File

@ -13,12 +13,9 @@ import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.RecyclerView
import io.reactivex.rxjava3.disposables.Disposable
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.moire.ultrasonic.R
import org.moire.ultrasonic.data.ActiveServerProvider
import org.moire.ultrasonic.domain.MusicDirectory
import org.moire.ultrasonic.featureflags.Feature
import org.moire.ultrasonic.featureflags.FeatureStorage
import org.moire.ultrasonic.service.DownloadFile
import org.moire.ultrasonic.service.DownloadStatus
import org.moire.ultrasonic.service.MusicServiceFactory
@ -61,11 +58,6 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable
var observableChecked = MutableLiveData(false)
private val useFiveStarRating: Boolean by lazy {
val features: FeatureStorage = get()
features.isFeatureEnabled(Feature.FIVE_STAR_RATING)
}
lateinit var imageHelper: Utils.ImageHelper
fun setSong(
@ -74,6 +66,7 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable
draggable: Boolean,
isSelected: Boolean = false
) {
val useFiveStarRating = Settings.useFiveStarRating
val song = file.song
downloadFile = file
entry = song
@ -98,7 +91,7 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable
star.isVisible = false
rating.isVisible = false
} else {
setupStarButtons(song)
setupStarButtons(song, useFiveStarRating)
}
updateProgress(downloadFile!!.progress.value!!)
@ -138,7 +131,7 @@ class TrackViewHolder(val view: View) : RecyclerView.ViewHolder(view), Checkable
}
}
private fun setupStarButtons(song: MusicDirectory.Entry) {
private fun setupStarButtons(song: MusicDirectory.Entry, useFiveStarRating: Boolean) {
if (useFiveStarRating) {
// Hide single star
star.isVisible = false

View File

@ -9,7 +9,6 @@ import org.moire.ultrasonic.BuildConfig
import org.moire.ultrasonic.di.appPermanentStorage
import org.moire.ultrasonic.di.applicationModule
import org.moire.ultrasonic.di.baseNetworkModule
import org.moire.ultrasonic.di.featureFlagsModule
import org.moire.ultrasonic.di.mediaPlayerModule
import org.moire.ultrasonic.di.musicServiceModule
import org.moire.ultrasonic.log.FileLoggerTree
@ -47,7 +46,6 @@ class UApp : MultiDexApplication() {
applicationModule,
appPermanentStorage,
baseNetworkModule,
featureFlagsModule,
musicServiceModule,
mediaPlayerModule
)

View File

@ -1,12 +0,0 @@
package org.moire.ultrasonic.di
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module
import org.moire.ultrasonic.featureflags.FeatureStorage
/**
* This Koin module contains the registration for the Feature Flags
*/
val featureFlagsModule = module {
factory { FeatureStorage(androidContext()) }
}

View File

@ -1,18 +0,0 @@
package org.moire.ultrasonic.featureflags
/**
* Contains a list of new features/implementations that are not yet finished,
* but possible to try it out.
*/
enum class Feature(
val defaultValue: Boolean
) {
/**
* Enables new image downloader implementation.
*/
NEW_IMAGE_DOWNLOADER(false),
/**
* Enables five star rating system.
*/
FIVE_STAR_RATING(false)
}

View File

@ -1,31 +0,0 @@
package org.moire.ultrasonic.featureflags
import android.content.Context
private const val SP_NAME = "feature_flags"
/**
* Provides storage for current feature flag state.
*/
class FeatureStorage(
context: Context
) {
private val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
/**
* Get [feature] current enabled state.
*/
fun isFeatureEnabled(feature: Feature): Boolean {
return sp.getBoolean(feature.name, feature.defaultValue)
}
/**
* Update [feature] enabled state to [isEnabled].
*/
fun changeFeatureFlag(
feature: Feature,
isEnabled: Boolean
) {
sp.edit().putBoolean(feature.name, isEnabled).apply()
}
}

View File

@ -70,8 +70,6 @@ import org.moire.ultrasonic.domain.Identifiable
import org.moire.ultrasonic.domain.MusicDirectory
import org.moire.ultrasonic.domain.PlayerState
import org.moire.ultrasonic.domain.RepeatMode
import org.moire.ultrasonic.featureflags.Feature
import org.moire.ultrasonic.featureflags.FeatureStorage
import org.moire.ultrasonic.fragment.FragmentTitle.Companion.setTitle
import org.moire.ultrasonic.service.DownloadFile
import org.moire.ultrasonic.service.LocalMediaPlayer
@ -210,7 +208,7 @@ class PlayerFragment :
val width = size.x
val height = size.y
setHasOptionsMenu(true)
useFiveStarRating = get<FeatureStorage>().isFeatureEnabled(Feature.FIVE_STAR_RATING)
useFiveStarRating = Settings.useFiveStarRating
swipeDistance = (width + height) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100
swipeVelocity = swipeDistance
gestureScanner = GestureDetector(context, this)

View File

@ -23,12 +23,9 @@ import androidx.preference.PreferenceFragmentCompat
import java.io.File
import kotlin.math.ceil
import org.koin.core.component.KoinComponent
import org.koin.java.KoinJavaComponent.get
import org.koin.java.KoinJavaComponent.inject
import org.moire.ultrasonic.R
import org.moire.ultrasonic.app.UApp
import org.moire.ultrasonic.featureflags.Feature
import org.moire.ultrasonic.featureflags.FeatureStorage
import org.moire.ultrasonic.fragment.FragmentTitle.Companion.setTitle
import org.moire.ultrasonic.log.FileLoggerTree
import org.moire.ultrasonic.log.FileLoggerTree.Companion.deleteLogFiles
@ -142,7 +139,6 @@ class SettingsFragment :
sharingDefaultGreeting!!.text = shareGreeting
setupClearSearchPreference()
setupFeatureFlagsPreferences()
setupCacheLocationPreference()
setupBluetoothDevicePreferences()
@ -371,21 +367,6 @@ class SettingsFragment :
}
}
private fun setupFeatureFlagsPreferences() {
val featureStorage = get<FeatureStorage>(FeatureStorage::class.java)
val useFiveStarRating = findPreference<Preference>(
Constants.PREFERENCES_KEY_USE_FIVE_STAR_RATING
) as CheckBoxPreference?
if (useFiveStarRating != null) {
useFiveStarRating.isChecked = featureStorage.isFeatureEnabled(Feature.FIVE_STAR_RATING)
useFiveStarRating.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference?, o: Any? ->
featureStorage.changeFeatureFlag(Feature.FIVE_STAR_RATING, (o as Boolean?)!!)
true
}
}
}
private fun update() {
theme!!.summary = theme!!.entry
maxBitrateWifi!!.summary = maxBitrateWifi!!.entry

View File

@ -8,15 +8,12 @@ package org.moire.ultrasonic.service
import android.content.Intent
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import org.koin.core.component.inject
import org.moire.ultrasonic.app.UApp
import org.moire.ultrasonic.data.ActiveServerProvider
import org.moire.ultrasonic.domain.MusicDirectory
import org.moire.ultrasonic.domain.PlayerState
import org.moire.ultrasonic.domain.RepeatMode
import org.moire.ultrasonic.featureflags.Feature
import org.moire.ultrasonic.featureflags.FeatureStorage
import org.moire.ultrasonic.service.MediaPlayerService.Companion.executeOnStartedMediaPlayerService
import org.moire.ultrasonic.service.MediaPlayerService.Companion.getInstance
import org.moire.ultrasonic.service.MediaPlayerService.Companion.runningInstance
@ -473,8 +470,7 @@ class MediaPlayerController(
@Suppress("TooGenericExceptionCaught") // The interface throws only generic exceptions
fun setSongRating(rating: Int) {
val features: FeatureStorage = get()
if (!features.isFeatureEnabled(Feature.FIVE_STAR_RATING)) return
if (!Settings.useFiveStarRating) return
if (localMediaPlayer.currentPlaying == null) return
val song = localMediaPlayer.currentPlaying!!.song
song.userRating = rating

View File

@ -297,11 +297,6 @@ object Settings {
return 0
}
var shouldShowAllSongsByArtist by BooleanSetting(
Constants.PREFERENCES_KEY_SHOW_ALL_SONGS_BY_ARTIST,
false
)
@JvmStatic
var resumeOnBluetoothDevice by IntSetting(
Constants.PREFERENCES_KEY_RESUME_ON_BLUETOOTH_DEVICE,
@ -320,6 +315,18 @@ object Settings {
val preferences: SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(Util.appContext())
var useFiveStarRating by BooleanSetting(Constants.PREFERENCES_KEY_USE_FIVE_STAR_RATING, false)
// TODO: Remove in December 2022
fun migrateFeatureStorage() {
val sp = appContext.getSharedPreferences("feature_flags", Context.MODE_PRIVATE)
useFiveStarRating = sp.getBoolean("FIVE_STAR_RATING", false)
}
fun hasKey(key: String): Boolean {
return preferences.contains(key)
}
private val appContext: Context
get() {
return UApp.applicationContext()

View File

@ -428,10 +428,10 @@
<string name="api.subsonic.upgrade_client">Nekompatibilní verze. Aktualizujte prosím Ultrasonic Android aplikaci.</string>
<string name="api.subsonic.upgrade_server">Nekompatibilní verze. Aktualizujte prosím Subsonic server.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Příznaky funkcí</string>
<string name="feature_flags_five_star_rating_title">Používat pět hvězdiček pro hodnocení skladeb</string>
<string name="feature_flags_five_star_rating_description">Používat pět hvězdiček pro hodnocení skladeb
<!-- Subsonic features -->
<string name="settings.features_title">Příznaky funkcí</string>
<string name="settings.five_star_rating_title">Používat pět hvězdiček pro hodnocení skladeb</string>
<string name="settings.five_star_rating_description">Používat pět hvězdiček pro hodnocení skladeb
namísto jednoduchého jednohvězdičkového hodnocení.
</string>

View File

@ -360,10 +360,10 @@
<string name="api.subsonic.upgrade_client">Inkompatible Versionen. Bitte die Ultrasonic App aktualisieren.</string>
<string name="api.subsonic.upgrade_server">Inkompatible Versionen. Bitte den subsonic Server aktualisieren.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Funktionseinstellungem</string>
<string name="feature_flags_five_star_rating_title">Verwenden Sie Fünf-Sterne-Bewertung für Songs</string>
<string name="feature_flags_five_star_rating_description">Verwenden Sie Fünf-Sterne-Bewertungssystem für Songs
<!-- Subsonic features -->
<string name="settings.features_title">Funktionseinstellungem</string>
<string name="settings.five_star_rating_title">Verwenden Sie Fünf-Sterne-Bewertung für Songs</string>
<string name="settings.five_star_rating_description">Verwenden Sie Fünf-Sterne-Bewertungssystem für Songs
         anstatt einfach Elemente zu markieren / zu entfernen.
</string>

View File

@ -450,10 +450,10 @@
<string name="api.subsonic.upgrade_client">Versiones incompatibles. Por favor actualiza la aplicación de Android Ultrasonic.</string>
<string name="api.subsonic.upgrade_server">Versiones incompatibles. Por favor actualiza el servidor de Subsonic.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Funciones experimentales</string>
<string name="feature_flags_five_star_rating_title">Use cinco estrellas para las canciones</string>
<string name="feature_flags_five_star_rating_description">Utilice el sistema de calificación de cinco estrellas para canciones
<!-- Subsonic features -->
<string name="settings.features_title">Funciones experimentales</string>
<string name="settings.five_star_rating_title">Use cinco estrellas para las canciones</string>
<string name="settings.five_star_rating_description">Utilice el sistema de calificación de cinco estrellas para canciones
en lugar de simplemente destacar / desestimar elementos.
</string>

View File

@ -439,10 +439,10 @@
<string name="api.subsonic.upgrade_client">Versions incompatibles. Veuillez mette à jour l\'application Android Ultrasonic.</string>
<string name="api.subsonic.upgrade_server">Versions incompatibles. Veuillez mette à jour le serveur Subsonic.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Drapeaux des fonctionnalités</string>
<string name="feature_flags_five_star_rating_title">Utiliser les étoiles pour noter les morceaux</string>
<string name="feature_flags_five_star_rating_description">Utiliser un système de notation à base d\'étoiles pour les morceaux
<!-- Subsonic features -->
<string name="settings.features_title">Drapeaux des fonctionnalités</string>
<string name="settings.five_star_rating_title">Utiliser les étoiles pour noter les morceaux</string>
<string name="settings.five_star_rating_description">Utiliser un système de notation à base d\'étoiles pour les morceaux
au lieu de simplement mettre en avant les morceaux.
</string>

View File

@ -434,10 +434,10 @@
<string name="api.subsonic.upgrade_client">Nem kompatibilis verzió. Kérjük, frissítse az Ultrasonic Android alkalmazást!</string>
<string name="api.subsonic.upgrade_server">Nem kompatibilis verzió. Kérjük, frissítse a Subsonic kiszolgálót!</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Jellemzők Zászlók</string>
<string name="feature_flags_five_star_rating_title">Öt csillagos értékelés használata a dalokhoz</string>
<string name="feature_flags_five_star_rating_description">Öt csillag használata az értékeléshez az egyszerű
<!-- Subsonic features -->
<string name="settings.features_title">Jellemzők Zászlók</string>
<string name="settings.five_star_rating_title">Öt csillagos értékelés használata a dalokhoz</string>
<string name="settings.five_star_rating_description">Öt csillag használata az értékeléshez az egyszerű
csillaggal jelölés helyett.
</string>

View File

@ -450,10 +450,10 @@
<string name="api.subsonic.upgrade_client">Incompatibele versies. Werk de Ultrasonic Android-app bij.</string>
<string name="api.subsonic.upgrade_server">Incompatibele versies. Werk je Subsonic-server bij.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Experimentele functies</string>
<string name="feature_flags_five_star_rating_title">Gebruik vijf sterren voor nummers</string>
<string name="feature_flags_five_star_rating_description">Gebruik vijf sterren ratingsysteem voor liedjes
<!-- Subsonic features -->
<string name="settings.features_title">Experimentele functies</string>
<string name="settings.five_star_rating_title">Gebruik vijf sterren voor nummers</string>
<string name="settings.five_star_rating_description">Gebruik vijf sterren ratingsysteem voor liedjes
in plaats van items simpelweg in de hoofdrol te zetten / niet te verwijderen.
</string>

View File

@ -404,10 +404,10 @@ ponieważ api Subsonic nie wspiera nowego sposobu autoryzacji dla użytkowników
<string name="api.subsonic.upgrade_client">Brak zgodności wersji. Uaktualnij aplikację Ultrasonic na Androida.</string>
<string name="api.subsonic.upgrade_server">Brak zgodności wersji. Uaktualnij serwer Subsonic.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Flagi funkcji</string>
<string name="feature_flags_five_star_rating_title">Użyj pięciu gwiazdek dla utworów</string>
<string name="feature_flags_five_star_rating_description">W przypadku utworów użyj systemu pięciu gwiazdek
<!-- Subsonic features -->
<string name="settings.features_title">Flagi funkcji</string>
<string name="settings.five_star_rating_title">Użyj pięciu gwiazdek dla utworów</string>
<string name="settings.five_star_rating_description">W przypadku utworów użyj systemu pięciu gwiazdek
zamiast po prostu grać gwiazdkami / bez gwiazd.
</string>

View File

@ -443,10 +443,10 @@
<string name="api.subsonic.upgrade_client">Versões incompativeis. Atualize o aplicativo Ultrasonic para Android.</string>
<string name="api.subsonic.upgrade_server">Versões incompativeis. Atualize o servidor Ultrasonic.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Sinalização de Recursos</string>
<string name="feature_flags_five_star_rating_title">Usar Classif. 5 Estrelas para Músicas</string>
<string name="feature_flags_five_star_rating_description">Usar o sistema de classificação de 5 estrelas para músicas
<!-- Subsonic features -->
<string name="settings.features_title">Sinalização de Recursos</string>
<string name="settings.five_star_rating_title">Usar Classif. 5 Estrelas para Músicas</string>
<string name="settings.five_star_rating_description">Usar o sistema de classificação de 5 estrelas para músicas
em vez de simplesmente estrelar/não estrelar itens
</string>

View File

@ -389,10 +389,10 @@
<string name="api.subsonic.upgrade_client">Versões incompativeis. Atualize o aplicativo Ultrasonic para Android.</string>
<string name="api.subsonic.upgrade_server">Versões incompativeis. Atualize o servidor Ultrasonic.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Bandeiras de recursos</string>
<string name="feature_flags_five_star_rating_title">Use classificação de cinco estrelas para músicas</string>
<string name="feature_flags_five_star_rating_description">Use o sistema de classificação de cinco estrelas para músicas
<!-- Subsonic features -->
<string name="settings.features_title">Bandeiras de recursos</string>
<string name="settings.five_star_rating_title">Use classificação de cinco estrelas para músicas</string>
<string name="settings.five_star_rating_description">Use o sistema de classificação de cinco estrelas para músicas
em vez de simplesmente estrelar / não estrelar itens.
</string>

View File

@ -453,10 +453,10 @@
<string name="api.subsonic.upgrade_client">Несовместимые версии. Пожалуйста, обновите приложение Ultrasonic для Android.</string>
<string name="api.subsonic.upgrade_server">Несовместимые версии. Пожалуйста, обновите Subsonic сервер.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Флаги</string>
<string name="feature_flags_five_star_rating_title">Использовать пятизвездочный рейтинг для песен</string>
<string name="feature_flags_five_star_rating_description">Использовать пятизвездочную систему рейтинга для песен
<!-- Subsonic features -->
<string name="settings.features_title">Флаги</string>
<string name="settings.five_star_rating_title">Использовать пятизвездочный рейтинг для песен</string>
<string name="settings.five_star_rating_description">Использовать пятизвездочную систему рейтинга для песен
вместо того, чтобы просто ставить/не ставить звезды.</string>
</resources>

View File

@ -432,10 +432,10 @@
<string name="api.subsonic.upgrade_client">版本不兼容,请升级 Ultrasonic 应用。</string>
<string name="api.subsonic.upgrade_server">不兼容的版本。请升级Subsonic 服务。</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">特性标志</string>
<string name="feature_flags_five_star_rating_title">为歌曲使用五星评分</string>
<string name="feature_flags_five_star_rating_description">对歌曲使用五星级评级系统
<!-- Subsonic features -->
<string name="settings.features_title">特性标志</string>
<string name="settings.five_star_rating_title">为歌曲使用五星评分</string>
<string name="settings.five_star_rating_description">对歌曲使用五星级评级系统
而不是简单地为项目加星标/取消星标。</string>
</resources>

View File

@ -461,10 +461,10 @@
<string name="api.subsonic.upgrade_client">Incompatible versions. Please upgrade Ultrasonic Android app.</string>
<string name="api.subsonic.upgrade_server">Incompatible versions. Please upgrade Subsonic server.</string>
<!-- Subsonic feature flags -->
<string name="feature_flags_category_title">Feature Flags</string>
<string name="feature_flags_five_star_rating_title">Use five star rating for songs</string>
<string name="feature_flags_five_star_rating_description">Use five star rating system for songs
<!-- Subsonic features -->
<string name="settings.features_title">Features</string>
<string name="settings.five_star_rating_title">Use five star rating for songs</string>
<string name="settings.five_star_rating_description">Use five star rating system for songs
instead of simply starring/unstarring items.
</string>

View File

@ -345,14 +345,14 @@
app:iconSpaceReserved="false"/>
</PreferenceCategory>
<PreferenceCategory
a:title="@string/feature_flags_category_title"
a:title="@string/settings.features_title"
app:iconSpaceReserved="false">
<CheckBoxPreference
a:defaultValue="false"
a:key="use_five_star_rating"
a:persistent="false"
a:title="@string/feature_flags_five_star_rating_title"
a:summary="@string/feature_flags_five_star_rating_description"
app:iconSpaceReserved="false"/>
a:summary="@string/settings.five_star_rating_description"
a:title="@string/settings.five_star_rating_title"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
a:title="@string/settings.debug.title"