Merge branch 'dontClearPlaylist' into 'develop'

Dont clear playlist

See merge request ultrasonic/ultrasonic!796
This commit is contained in:
Nite 2022-08-01 15:00:39 +00:00
commit d32cd66ce4
15 changed files with 45 additions and 67 deletions

View File

@ -23,8 +23,6 @@ import org.moire.ultrasonic.util.ServerColor
/**
* Row Adapter to be used in the Server List
* Converts a Server Setting into a displayable Row, and sets up the Row's context menu
* @param manageMode: set to True if the default action by clicking the row is to edit the server
* In Manage Mode the "Offline" setting is not visible, and the servers can be edited by
* clicking the row.
*/
internal class ServerRowAdapter(
@ -32,9 +30,8 @@ internal class ServerRowAdapter(
passedData: Array<ServerSetting>,
private val model: ServerSettingsModel,
private val activeServerProvider: ActiveServerProvider,
private val manageMode: Boolean,
private val serverDeletedCallback: ((Int) -> Unit),
private val serverEditRequestedCallback: ((Int) -> Unit)
private val serverDeletedCallback: (Int) -> Unit,
private val serverEditRequestedCallback: (Int) -> Unit
) : BaseAdapter() {
private var data: MutableList<ServerSetting> = mutableListOf()
@ -56,10 +53,8 @@ internal class ServerRowAdapter(
fun setData(data: Array<ServerSetting>) {
this.data.clear()
// In read mode show the offline server as well
if (!manageMode) {
this.data.add(ActiveServerProvider.OFFLINE_DB)
}
// Show the offline server as well
this.data.add(ActiveServerProvider.OFFLINE_DB)
this.data.addAll(data)
notifyDataSetChanged()
@ -82,10 +77,6 @@ internal class ServerRowAdapter(
*/
@Suppress("LongMethod")
override fun getView(pos: Int, convertView: View?, parent: ViewGroup?): View? {
var position = pos
// Skip "Offline" in manage mode
if (manageMode) position++
var vi: View? = convertView
if (vi == null) vi = inflater.inflate(R.layout.server_row, parent, false)
@ -95,7 +86,7 @@ internal class ServerRowAdapter(
val layout = vi?.findViewById<ConstraintLayout>(R.id.server_layout)
val image = vi?.findViewById<ImageView>(R.id.server_image)
val serverMenu = vi?.findViewById<ImageButton>(R.id.server_menu)
val setting = data.singleOrNull { t -> t.index == position }
val setting = data.singleOrNull { t -> t.index == pos }
text?.text = setting?.name ?: ""
description?.text = setting?.url ?: ""
@ -122,7 +113,7 @@ internal class ServerRowAdapter(
image?.background = background
// Highlight the Active Server's row by changing its background
if (position == activeServerProvider.getActiveServer().index) {
if (pos == activeServerProvider.getActiveServer().index) {
layout?.background = ContextCompat.getDrawable(context, R.drawable.select_ripple)
} else {
layout?.background = ContextCompat.getDrawable(context, R.drawable.default_ripple)
@ -134,7 +125,7 @@ internal class ServerRowAdapter(
R.drawable.select_ripple_circle
)
serverMenu?.setOnClickListener { view -> serverMenuClick(view, position) }
serverMenu?.setOnClickListener { view -> serverMenuClick(view, pos) }
return vi
}
@ -145,18 +136,14 @@ internal class ServerRowAdapter(
private fun serverMenuClick(view: View, position: Int) {
val menu = PopupMenu(context, view)
val firstServer = 1
var lastServer = count - 1
val lastServer = count - 1
if (!manageMode) {
menu.menu.add(
Menu.NONE,
MENU_ID_EDIT,
Menu.NONE,
context.getString(R.string.server_menu_edit)
)
} else {
lastServer++
}
menu.menu.add(
Menu.NONE,
MENU_ID_EDIT,
Menu.NONE,
context.getString(R.string.server_menu_edit)
)
menu.menu.add(
Menu.NONE,

View File

@ -14,6 +14,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import org.moire.ultrasonic.R
import org.moire.ultrasonic.adapters.ServerRowAdapter
import org.moire.ultrasonic.data.ActiveServerProvider
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.OFFLINE_DB_ID
import org.moire.ultrasonic.data.ServerSetting
import org.moire.ultrasonic.fragment.EditServerFragment.Companion.EDIT_SERVER_INTENT_INDEX
import org.moire.ultrasonic.model.ServerSettingsModel
@ -28,9 +29,6 @@ import timber.log.Timber
* TODO: Manage mode is unused. Remove it...
*/
class ServerSelectorFragment : Fragment() {
companion object {
const val SERVER_SELECTOR_MANAGE_MODE = "manageMode"
}
private var listView: ListView? = null
private val serverSettingsModel: ServerSettingsModel by viewModel()
@ -55,16 +53,7 @@ class ServerSelectorFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val manageMode = arguments?.getBoolean(
SERVER_SELECTOR_MANAGE_MODE,
false
) ?: false
if (manageMode) {
FragmentTitle.setTitle(this, R.string.settings_server_manage_servers)
} else {
FragmentTitle.setTitle(this, R.string.server_selector_label)
}
FragmentTitle.setTitle(this, R.string.server_selector_label)
listView = view.findViewById(R.id.server_list)
serverRowAdapter = ServerRowAdapter(
@ -72,7 +61,6 @@ class ServerSelectorFragment : Fragment() {
arrayOf(),
serverSettingsModel,
activeServerProvider,
manageMode,
::deleteServerById,
::editServerByIndex
)
@ -82,12 +70,8 @@ class ServerSelectorFragment : Fragment() {
listView?.onItemClickListener = AdapterView.OnItemClickListener { parent, _, position, _ ->
val server = parent.getItemAtPosition(position) as ServerSetting
if (manageMode) {
editServerByIndex(position + 1)
} else {
setActiveServerById(server.id)
findNavController().popBackStack(R.id.mainFragment, false)
}
setActiveServerById(server.id)
findNavController().popBackStack(R.id.mainFragment, false)
}
val fab = view.findViewById<FloatingActionButton>(R.id.server_add_fab)
@ -110,12 +94,20 @@ class ServerSelectorFragment : Fragment() {
* Sets the active server when a list item is clicked
*/
private fun setActiveServerById(id: Int) {
val oldId = activeServerProvider.getActiveServer().id
controller.clearIncomplete()
// Check if there is a change
if (oldId == id)
return
if (activeServerProvider.getActiveServer().id != id) {
ActiveServerProvider.setActiveServerById(id)
// Remove incomplete tracks if we are going offline, or changing between servers.
// If we are coming from offline there is no need to clear downloads etc.
if (oldId != OFFLINE_DB_ID) {
controller.removeIncompleteTracksFromPlaylist()
controller.clearDownloads()
}
ActiveServerProvider.setActiveServerById(id)
}
/**
@ -132,7 +124,7 @@ class ServerSelectorFragment : Fragment() {
val activeServerId = ActiveServerProvider.getActiveServerId()
// If the currently active server is deleted, go offline
if (id == activeServerId) setActiveServerById(ActiveServerProvider.OFFLINE_DB_ID)
if (id == activeServerId) setActiveServerById(OFFLINE_DB_ID)
serverSettingsModel.deleteItemById(id)

View File

@ -468,13 +468,24 @@ class MediaPlayerController(
}
@Synchronized
fun clearIncomplete() {
reset()
fun clearDownloads() {
downloader.clearActiveDownloads()
downloader.clearBackground()
}
jukeboxMediaPlayer.updatePlaylist()
@Synchronized
fun removeIncompleteTracksFromPlaylist() {
val list = playlist.toList()
var removed = 0
for ((index, item) in list.withIndex()) {
val state = downloader.getDownloadState(item.toTrack())
// The track is not downloaded, remove it
if (state != DownloadStatus.DONE && state != DownloadStatus.PINNED) {
removeFromPlaylist(index - removed)
removed++
}
}
}
@Synchronized

View File

@ -239,7 +239,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Historie hledání vyčištěna</string>
<string name="settings.search_title">Nastavení vyhledávání</string>
<string name="settings.server_manage_servers">Spravovat servery</string>
<string name="settings.server_address">Adresa serveru</string>
<string name="settings.server_name">Název</string>
<string name="settings.server_password">Heslo</string>

View File

@ -279,7 +279,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Suchhistorie gelöscht</string>
<string name="settings.search_title">Sucheinstellungen</string>
<string name="settings.server_manage_servers">Server verwalten</string>
<string name="settings.server_address">Server Adresse</string>
<string name="settings.server_name">Name</string>
<string name="settings.server_password">Kennwort</string>

View File

@ -279,7 +279,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Se ha limpiado el historial de búsqueda</string>
<string name="settings.search_title">Configuración de la búsqueda</string>
<string name="settings.server_manage_servers">Administrar servidores</string>
<string name="settings.server_address">Dirección del servidor</string>
<string name="settings.server_name">Nombre</string>
<string name="settings.server_password">Contraseña</string>

View File

@ -259,7 +259,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Historique des recherches effacé</string>
<string name="settings.search_title">Paramètres de recherche</string>
<string name="settings.server_manage_servers">Gérer les serveurs</string>
<string name="settings.server_address">Adresse du serveur</string>
<string name="settings.server_name">Nom</string>
<string name="settings.server_password">Mot de passe</string>

View File

@ -247,7 +247,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Keresési előzmények törölve.</string>
<string name="settings.search_title">Keresés beállításai</string>
<string name="settings.server_manage_servers">Kiszolgálók kezelése</string>
<string name="settings.server_address">Kiszolgáló címe</string>
<string name="settings.server_name">Név</string>
<string name="settings.server_password">Jelszó</string>

View File

@ -279,7 +279,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Zoekgeschiedenis gewist</string>
<string name="settings.search_title">Zoekinstellingen</string>
<string name="settings.server_manage_servers">Manage Servers</string>
<string name="settings.server_address">Serveradres</string>
<string name="settings.server_name">Naam</string>
<string name="settings.server_password">Wachtwoord</string>

View File

@ -239,7 +239,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Wyczyść historię wyszukiwania</string>
<string name="settings.search_title">Ustawienia wyszukiwania</string>
<string name="settings.server_manage_servers">Manage Servers</string>
<string name="settings.server_address">Adres serwera</string>
<string name="settings.server_name">Nazwa</string>
<string name="settings.server_password">Hasło</string>

View File

@ -254,7 +254,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Histórico de pesquisas apagado</string>
<string name="settings.search_title">Configurações de Pesquisa</string>
<string name="settings.server_manage_servers">Gerenciar Servidores</string>
<string name="settings.server_address">Endereço do Servidor</string>
<string name="settings.server_name">Nome</string>
<string name="settings.server_password">Senha</string>

View File

@ -239,7 +239,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Histórico de pesquisas apagado</string>
<string name="settings.search_title">Configurações de Pesquisa</string>
<string name="settings.server_manage_servers">Manage Servers</string>
<string name="settings.server_address">Endereço do Servidor</string>
<string name="settings.server_name">Nome</string>
<string name="settings.server_password">Senha</string>

View File

@ -265,7 +265,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">История поиска очищена</string>
<string name="settings.search_title">Настройки поиска</string>
<string name="settings.server_manage_servers">Управление серверами</string>
<string name="settings.server_address">Адрес сервера</string>
<string name="settings.server_name">Имя</string>
<string name="settings.server_password">Пароль</string>

View File

@ -259,7 +259,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">搜索记录已清除</string>
<string name="settings.search_title">搜索设置</string>
<string name="settings.server_manage_servers">管理服务器</string>
<string name="settings.server_address">服务器地址</string>
<string name="settings.server_name">名称</string>
<string name="settings.server_password">密码</string>

View File

@ -290,7 +290,6 @@
<string name="settings.search_75">75</string>
<string name="settings.search_history_cleared">Search history cleared</string>
<string name="settings.search_title">Search Settings</string>
<string name="settings.server_manage_servers">Manage Servers</string>
<string name="settings.server_address">Server Address</string>
<string name="settings.server_name">Name</string>
<string name="settings.server_password">Password</string>