mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #3350 from Isira-Seneviratne/Remove_runOnUiThread
Remove runOnUiThread().
This commit is contained in:
commit
f1da5d2151
@ -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,7 +65,6 @@ 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!!
|
||||
@ -78,7 +76,6 @@ class AddToPlaylistDialog(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun addToPlaylist(playlistId: String) {
|
||||
val appContext = context?.applicationContext ?: return
|
||||
@ -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,7 +154,6 @@ 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()
|
||||
@ -166,7 +165,6 @@ class InstanceSettings : BasePreferenceFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun logoutAndUpdateUI() {
|
||||
PreferenceHelper.setToken("")
|
||||
|
Loading…
Reference in New Issue
Block a user