mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Remove runOnUiThread().
This commit is contained in:
parent
c008fa4282
commit
a927511d55
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.ui.base
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
@ -76,10 +75,4 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
|
||||
else -> super.onDisplayPreferenceDialog(preference)
|
||||
}
|
||||
}
|
||||
|
||||
fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||
this ?: return
|
||||
if (!isAdded) return // Fragment not attached to an Activity
|
||||
activity?.runOnUiThread(action)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import android.util.Log
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
@ -66,15 +65,13 @@ class AddToPlaylistDialog(
|
||||
response.indexOfFirst { it.id == id }.takeIf { it >= 0 } ?: 0
|
||||
)
|
||||
}
|
||||
runOnUiThread {
|
||||
binding.addToPlaylist.setOnClickListener {
|
||||
val index = binding.playlistsSpinner.selectedItemPosition
|
||||
viewModel.lastSelectedPlaylistId = response[index].id!!
|
||||
dialog?.hide()
|
||||
lifecycleScope.launch {
|
||||
addToPlaylist(response[index].id!!)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
binding.addToPlaylist.setOnClickListener {
|
||||
val index = binding.playlistsSpinner.selectedItemPosition
|
||||
viewModel.lastSelectedPlaylistId = response[index].id!!
|
||||
dialog?.hide()
|
||||
lifecycleScope.launch {
|
||||
addToPlaylist(response[index].id!!)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,10 +97,4 @@ class AddToPlaylistDialog(
|
||||
if (success) R.string.added_to_playlist else R.string.fail
|
||||
)
|
||||
}
|
||||
|
||||
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||
this ?: return
|
||||
if (!isAdded) return // Fragment not attached to an Activity
|
||||
activity?.runOnUiThread(action)
|
||||
}
|
||||
}
|
||||
|
@ -154,16 +154,14 @@ class InstanceSettings : BasePreferenceFragment() {
|
||||
|
||||
instances.addAll(customInstances.map { Instances(it.name, it.apiUrl) })
|
||||
|
||||
runOnUiThread {
|
||||
for (instancePref in instancePrefs) {
|
||||
// add custom instances to the list preference
|
||||
instancePref.entries = instances.map { it.name }.toTypedArray()
|
||||
instancePref.entryValues = instances.map { it.apiUrl }.toTypedArray()
|
||||
instancePref.summaryProvider =
|
||||
Preference.SummaryProvider<ListPreference> { preference ->
|
||||
preference.entry
|
||||
}
|
||||
}
|
||||
for (instancePref in instancePrefs) {
|
||||
// add custom instances to the list preference
|
||||
instancePref.entries = instances.map { it.name }.toTypedArray()
|
||||
instancePref.entryValues = instances.map { it.apiUrl }.toTypedArray()
|
||||
instancePref.summaryProvider =
|
||||
Preference.SummaryProvider<ListPreference> { preference ->
|
||||
preference.entry
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user