all: reformat

This commit is contained in:
Alexander Capehart
2025-06-16 07:55:03 -06:00
parent 5465ad3733
commit 3979b8e688
8 changed files with 37 additions and 27 deletions
@@ -160,7 +160,8 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext private val cont
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") } joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
private fun String.toOpenedLocations(): List<Location.Opened> = private fun String.toOpenedLocations(): List<Location.Opened> =
splitEscaped { it == ';' }.mapNotNull { Location.Unopened.from(context, it.toUri())?.open(context) } splitEscaped { it == ';' }
.mapNotNull { Location.Unopened.from(context, it.toUri())?.open(context) }
private fun List<Location>.stringifyLocations(): String = private fun List<Location>.stringifyLocations(): String =
joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") } joinToString(separator = ";") { it.uri.toString().replace(";", "\\;") }
@@ -29,7 +29,8 @@ import org.oxycblt.musikr.fs.Location
* @param listener A [LocationAdapter.Listener] to bind interactions to. * @param listener A [LocationAdapter.Listener] to bind interactions to.
* @author Alexander Capehart (OxygenCobalt) * @author Alexander Capehart (OxygenCobalt)
*/ */
class ExcludedLocationAdapter(listener: LocationAdapter.Listener<Location.Unopened>) : LocationAdapter<Location.Unopened>(listener) { class ExcludedLocationAdapter(listener: LocationAdapter.Listener<Location.Unopened>) :
LocationAdapter<Location.Unopened>(listener) {
override fun createViewHolder(parent: ViewGroup): LocationViewHolder<Location.Unopened> = override fun createViewHolder(parent: ViewGroup): LocationViewHolder<Location.Unopened> =
ExcludedLocationViewHolder.from(parent) ExcludedLocationViewHolder.from(parent)
} }
@@ -50,6 +51,7 @@ class ExcludedLocationViewHolder private constructor(binding: ItemMusicLocationB
* @return A new instance. * @return A new instance.
*/ */
fun from(parent: ViewGroup) = fun from(parent: ViewGroup) =
ExcludedLocationViewHolder(ItemMusicLocationBinding.inflate(parent.context.inflater, parent, false)) ExcludedLocationViewHolder(
ItemMusicLocationBinding.inflate(parent.context.inflater, parent, false))
} }
} }
@@ -21,11 +21,11 @@ package org.oxycblt.auxio.music.locations
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.BuildConfig import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.MusicSettings import org.oxycblt.auxio.music.MusicSettings
import org.oxycblt.musikr.fs.Location import org.oxycblt.musikr.fs.Location
import javax.inject.Inject
/** /**
* Dialog that manages the excluded locations setting. * Dialog that manages the excluded locations setting.
@@ -36,8 +36,7 @@ import javax.inject.Inject
class ExcludedLocationsDialog : LocationsDialog<Location.Unopened>() { class ExcludedLocationsDialog : LocationsDialog<Location.Unopened>() {
override val locationAdapter = ExcludedLocationAdapter(this) override val locationAdapter = ExcludedLocationAdapter(this)
@Inject @Inject override lateinit var musicSettings: MusicSettings
override lateinit var musicSettings: MusicSettings
override fun getDialogTitle(): Int = R.string.set_excluded_locations override fun getDialogTitle(): Int = R.string.set_excluded_locations
@@ -58,6 +57,7 @@ class ExcludedLocationsDialog : LocationsDialog<Location.Unopened>() {
} }
private companion object { private companion object {
const val KEY_PENDING_EXCLUDED_LOCATIONS = BuildConfig.APPLICATION_ID + ".key.PENDING_EXCLUDED_LOCATIONS" const val KEY_PENDING_EXCLUDED_LOCATIONS =
BuildConfig.APPLICATION_ID + ".key.PENDING_EXCLUDED_LOCATIONS"
} }
} }
@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2024 Auxio Project * Copyright (c) 2024 Auxio Project
* BaseLocationAdapter.kt is part of Auxio. * LocationAdapter.kt is part of Auxio.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -26,14 +26,14 @@ import org.oxycblt.auxio.util.context
import org.oxycblt.musikr.fs.Location import org.oxycblt.musikr.fs.Location
import timber.log.Timber as L import timber.log.Timber as L
abstract class LocationAdapter<T : Location>(private val listener: Listener<T>) : RecyclerView.Adapter<LocationViewHolder<T>>() { abstract class LocationAdapter<T : Location>(private val listener: Listener<T>) :
RecyclerView.Adapter<LocationViewHolder<T>>() {
private val _locations = mutableListOf<T>() private val _locations = mutableListOf<T>()
val locations: List<T> = _locations val locations: List<T> = _locations
override fun getItemCount() = locations.size override fun getItemCount() = locations.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(parent)
createViewHolder(parent)
override fun onBindViewHolder(holder: LocationViewHolder<T>, position: Int) = override fun onBindViewHolder(holder: LocationViewHolder<T>, position: Int) =
holder.bind(locations[position], listener) holder.bind(locations[position], listener)
@@ -73,4 +73,4 @@ abstract class LocationViewHolder<T : Location>(protected val binding: ItemMusic
binding.locationPath.text = location.path.resolve(binding.context) binding.locationPath.text = location.path.resolve(binding.context)
binding.locationDelete.setOnClickListener { listener.onRemoveLocation(location) } binding.locationDelete.setOnClickListener { listener.onRemoveLocation(location) }
} }
} }
@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2024 Auxio Project * Copyright (c) 2024 Auxio Project
* BaseLocationsDialog.kt is part of Auxio. * LocationsDialog.kt is part of Auxio.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -81,7 +81,8 @@ abstract class LocationsDialog<T : Location> :
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
outState.putStringArrayList( outState.putStringArrayList(
getPendingLocationsKey(), ArrayList(locationAdapter.locations.map { it.uri.toString() })) getPendingLocationsKey(),
ArrayList(locationAdapter.locations.map { it.uri.toString() }))
} }
override fun onDestroyBinding(binding: DialogMusicLocationsBinding) { override fun onDestroyBinding(binding: DialogMusicLocationsBinding) {
@@ -122,9 +123,14 @@ abstract class LocationsDialog<T : Location> :
} }
protected abstract fun getDialogTitle(): Int protected abstract fun getDialogTitle(): Int
protected abstract fun getCurrentLocations(): List<T> protected abstract fun getCurrentLocations(): List<T>
protected abstract fun saveLocations(locations: List<T>) protected abstract fun saveLocations(locations: List<T>)
protected abstract fun getPendingLocationsKey(): String protected abstract fun getPendingLocationsKey(): String
protected abstract fun convertUriToLocation(uri: Uri): T? protected abstract fun convertUriToLocation(uri: Uri): T?
protected abstract fun createLocationFromUri(context: android.content.Context, uri: Uri): T? protected abstract fun createLocationFromUri(context: android.content.Context, uri: Uri): T?
} }
@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2021 Auxio Project * Copyright (c) 2021 Auxio Project
* LocationAdapter.kt is part of Auxio. * MusicLocationAdapter.kt is part of Auxio.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -29,7 +29,8 @@ import org.oxycblt.musikr.fs.Location
* @param listener A [LocationAdapter.Listener] to bind interactions to. * @param listener A [LocationAdapter.Listener] to bind interactions to.
* @author Alexander Capehart (OxygenCobalt) * @author Alexander Capehart (OxygenCobalt)
*/ */
class MusicLocationAdapter(listener: LocationAdapter.Listener<Location.Opened>) : LocationAdapter<Location.Opened>(listener) { class MusicLocationAdapter(listener: LocationAdapter.Listener<Location.Opened>) :
LocationAdapter<Location.Opened>(listener) {
override fun createViewHolder(parent: ViewGroup): LocationViewHolder<Location.Opened> = override fun createViewHolder(parent: ViewGroup): LocationViewHolder<Location.Opened> =
MusicLocationViewHolder.from(parent) MusicLocationViewHolder.from(parent)
} }
@@ -50,6 +51,7 @@ class MusicLocationViewHolder private constructor(binding: ItemMusicLocationBind
* @return A new instance. * @return A new instance.
*/ */
fun from(parent: ViewGroup) = fun from(parent: ViewGroup) =
MusicLocationViewHolder(ItemMusicLocationBinding.inflate(parent.context.inflater, parent, false)) MusicLocationViewHolder(
ItemMusicLocationBinding.inflate(parent.context.inflater, parent, false))
} }
} }
@@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2021 Auxio Project * Copyright (c) 2021 Auxio Project
* MusicSourcesDialog.kt is part of Auxio. * MusicLocationsDialog.kt is part of Auxio.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -21,11 +21,11 @@ package org.oxycblt.auxio.music.locations
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.BuildConfig import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.MusicSettings import org.oxycblt.auxio.music.MusicSettings
import org.oxycblt.musikr.fs.Location import org.oxycblt.musikr.fs.Location
import javax.inject.Inject
/** /**
* Dialog that manages the music locations setting. * Dialog that manages the music locations setting.
@@ -36,8 +36,7 @@ import javax.inject.Inject
class MusicLocationsDialog : LocationsDialog<Location.Opened>() { class MusicLocationsDialog : LocationsDialog<Location.Opened>() {
override val locationAdapter = MusicLocationAdapter(this) override val locationAdapter = MusicLocationAdapter(this)
@Inject @Inject override lateinit var musicSettings: MusicSettings
override lateinit var musicSettings: MusicSettings
override fun getDialogTitle(): Int = R.string.set_locations override fun getDialogTitle(): Int = R.string.set_locations
@@ -38,7 +38,8 @@ sealed class Location(val uri: Uri, val path: Path) {
try { try {
context.contentResolverSafe.takePersistableUriPermission( context.contentResolverSafe.takePersistableUriPermission(
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
} catch (e: Exception) { } catch (e: Exception) {
// Not fully sure what happens if I'm disallowed to take the permission, // Not fully sure what happens if I'm disallowed to take the permission,
// check for both circumstances (error or no-op) // check for both circumstances (error or no-op)
@@ -68,8 +69,7 @@ sealed class Location(val uri: Uri, val path: Path) {
} }
class Opened internal constructor(uri: Uri, path: Path) : Location(uri, path) { class Opened internal constructor(uri: Uri, path: Path) : Location(uri, path) {
override fun equals(other: Any?) = override fun equals(other: Any?) = other is Opened && uri == other.uri && path == other.path
other is Opened && uri == other.uri && path == other.path
override fun hashCode() = 31 * uri.hashCode() + path.hashCode() override fun hashCode() = 31 * uri.hashCode() + path.hashCode()
} }