Merge pull request #3350 from Isira-Seneviratne/Remove_runOnUiThread

Remove runOnUiThread().
This commit is contained in:
Bnyro 2023-03-23 19:39:25 +01:00 committed by GitHub
commit f1da5d2151
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 33 deletions

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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
}
}
}
}