mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
improve code structure
This commit is contained in:
parent
206b560eb4
commit
f65d84727c
@ -85,7 +85,6 @@ class PlaylistsAdapter(
|
||||
}
|
||||
|
||||
private fun deletePlaylist(id: String, position: Int) {
|
||||
fun run() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val response = try {
|
||||
RetrofitInstance.authApi.deletePlaylist(
|
||||
@ -110,8 +109,6 @@ class PlaylistsAdapter(
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
||||
class PlaylistsViewHolder(val binding: PlaylistsRowBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
@ -44,7 +44,6 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun fetchPlaylists() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.authApi.playlists(token)
|
||||
@ -88,8 +87,6 @@ class AddToPlaylistDialog : DialogFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun addToPlaylist(playlistId: String) {
|
||||
fun run() {
|
||||
|
@ -50,7 +50,6 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun createPlaylist(name: String) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.authApi.createPlaylist(token, Playlists(name = name))
|
||||
@ -80,6 +79,4 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ class DeleteAccountDialog : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun deleteAccount(password: String) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val token = PreferenceHelper.getToken()
|
||||
|
||||
@ -58,8 +57,6 @@ class DeleteAccountDialog : DialogFragment() {
|
||||
restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name)
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun logout() {
|
||||
PreferenceHelper.setToken("")
|
||||
|
@ -55,7 +55,6 @@ class LoginDialog : DialogFragment() {
|
||||
}
|
||||
|
||||
private fun login(login: Login) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.authApi.login(login)
|
||||
@ -83,8 +82,6 @@ class LoginDialog : DialogFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun register(login: Login) {
|
||||
fun run() {
|
||||
|
@ -101,6 +101,14 @@ class PlaylistOptionsDialog(
|
||||
.setTitle(R.string.renamePlaylist)
|
||||
.setView(binding.root)
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
if (binding.input.text.toString() == "") {
|
||||
Toast.makeText(
|
||||
context,
|
||||
R.string.emptyPlaylistName,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@setPositiveButton
|
||||
}
|
||||
renamePlaylist(playlistId, binding.input.text.toString())
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
@ -112,7 +120,6 @@ class PlaylistOptionsDialog(
|
||||
}
|
||||
|
||||
private fun importPlaylist(token: String, playlistId: String) {
|
||||
fun run() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val response = try {
|
||||
RetrofitInstance.authApi.importPlaylist(token, PlaylistId(playlistId))
|
||||
@ -125,8 +132,6 @@ class PlaylistOptionsDialog(
|
||||
Log.e(TAG(), response.toString())
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun renamePlaylist(id: String, newName: String) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
@ -83,7 +83,6 @@ class ChannelFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
private fun fetchChannel() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
if (channelId != null) {
|
||||
@ -163,8 +162,6 @@ class ChannelFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun fetchChannelNextPage() {
|
||||
fun run() {
|
||||
|
@ -62,7 +62,6 @@ class HomeFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
private fun fetchTrending() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getTrending(region)
|
||||
@ -106,6 +105,4 @@ class HomeFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,6 @@ class LibraryFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
fun fetchPlaylists() {
|
||||
fun run() {
|
||||
binding.playlistRefresh.isRefreshing = true
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
@ -140,6 +139,4 @@ class LibraryFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
}
|
||||
|
@ -1332,7 +1332,6 @@ class PlayerFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
private fun isSubscribed() {
|
||||
fun run() {
|
||||
val channelId = streams.uploaderUrl!!.toID()
|
||||
lifecycleScope.launchWhenCreated {
|
||||
isSubscribed = SubscriptionHelper.isSubscribed(channelId)
|
||||
@ -1357,8 +1356,6 @@ class PlayerFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun fetchComments() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
|
@ -58,7 +58,6 @@ class PlaylistFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
private fun fetchPlaylist() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
// load locally stored playlists with the auth api
|
||||
@ -159,8 +158,6 @@ class PlaylistFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun fetchNextPage() {
|
||||
fun run() {
|
||||
|
@ -69,7 +69,6 @@ class SearchFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
private fun fetchSuggestions(query: String) {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getSuggestions(query)
|
||||
@ -94,8 +93,6 @@ class SearchFragment : BaseFragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
private fun showHistory() {
|
||||
var historyList = listOf<String>()
|
||||
|
Loading…
x
Reference in New Issue
Block a user