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

View File

@ -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("")