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