From a2339672c64e1c9103def27930f62a9dc3ddf0d0 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 20 May 2022 00:22:10 +0200 Subject: [PATCH] Lint --- .../libretube/ExampleInstrumentedTest.kt | 8 +- .../github/libretube/AddtoPlaylistDialog.kt | 52 ++++---- .../com/github/libretube/ChannelFragment.kt | 113 ++++++++-------- .../github/libretube/CreatePlaylistDialog.kt | 5 +- .../github/libretube/CustomExoPlayerView.kt | 9 +- .../github/libretube/CustomSwipeToRefresh.kt | 2 +- .../com/github/libretube/DownloadDialog.kt | 27 ++-- .../com/github/libretube/DownloadService.kt | 122 +++++++++--------- .../main/java/com/github/libretube/Home.kt | 41 +++--- .../main/java/com/github/libretube/Library.kt | 82 ++++++------ .../java/com/github/libretube/LoginDialog.kt | 114 ++++++++-------- .../java/com/github/libretube/PipedApi.kt | 38 ++++-- .../main/java/com/github/libretube/Player.kt | 13 -- .../com/github/libretube/PlayerFragment.kt | 105 +++++++-------- .../com/github/libretube/PlaylistFragment.kt | 56 ++++---- .../com/github/libretube/ResettableLazy.kt | 10 +- .../com/github/libretube/RetrofitInstance.kt | 3 +- .../com/github/libretube/SearchFragment.kt | 101 +++++++-------- .../com/github/libretube/SettingsActivity.kt | 6 +- .../SingleViewTouchableMotionLayout.kt | 26 ++-- .../github/libretube/SponsorBlockSettings.kt | 2 +- .../com/github/libretube/Subscriptions.kt | 70 +++++----- .../libretube/adapters/ChannelAdapter.kt | 16 +-- .../libretube/adapters/CommentsAdapter.kt | 13 +- .../libretube/adapters/PlaylistAdapter.kt | 44 ++++--- .../libretube/adapters/PlaylistsAdapter.kt | 41 +++--- .../libretube/adapters/SearchAdapter.kt | 35 +++-- .../adapters/SearchHistoryAdapter.kt | 12 +- .../libretube/adapters/SubscriptionAdapter.kt | 29 ++--- .../adapters/SubscriptionChannelAdapter.kt | 14 +- .../libretube/adapters/TrendingAdapter.kt | 24 ++-- .../main/java/com/github/libretube/myApp.kt | 4 +- .../github/libretube/obj/ChapterSegment.kt | 4 +- .../java/com/github/libretube/obj/Comment.kt | 5 +- .../com/github/libretube/obj/CommentsPage.kt | 10 +- .../com/github/libretube/obj/PipedStream.kt | 4 +- .../com/github/libretube/obj/SearchItem.kt | 8 +- .../com/github/libretube/obj/SearchResult.kt | 4 +- .../java/com/github/libretube/obj/Segment.kt | 4 +- .../java/com/github/libretube/obj/Segments.kt | 4 +- .../com/github/libretube/obj/StreamItem.kt | 4 +- .../java/com/github/libretube/obj/Streams.kt | 8 +- .../java/com/github/libretube/obj/Subtitle.kt | 4 +- .../com/github/libretube/ExampleUnitTest.kt | 5 +- 44 files changed, 624 insertions(+), 677 deletions(-) diff --git a/app/src/androidTest/java/com/github/libretube/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/github/libretube/ExampleInstrumentedTest.kt index 39c054e77..e89f1b40c 100644 --- a/app/src/androidTest/java/com/github/libretube/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/github/libretube/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.github.libretube -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * @@ -21,4 +19,4 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.github.libretube", appContext.packageName) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/AddtoPlaylistDialog.kt b/app/src/main/java/com/github/libretube/AddtoPlaylistDialog.kt index b852d979c..0ee8cb59c 100644 --- a/app/src/main/java/com/github/libretube/AddtoPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/AddtoPlaylistDialog.kt @@ -10,10 +10,9 @@ import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope -import com.github.libretube.adapters.PlaylistsAdapter import com.github.libretube.obj.PlaylistId -import retrofit2.HttpException import java.io.IOException +import retrofit2.HttpException class AddtoPlaylistDialog : DialogFragment() { private val TAG = "AddToPlaylistDialog" @@ -26,77 +25,74 @@ class AddtoPlaylistDialog : DialogFragment() { videoId = arguments?.getString("videoId")!! val builder = AlertDialog.Builder(it) // Get the layout inflater - val inflater = requireActivity().layoutInflater; + val inflater = requireActivity().layoutInflater val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) - token = sharedPref?.getString("token","")!! + token = sharedPref?.getString("token", "")!! var view: View = inflater.inflate(R.layout.dialog_addtoplaylist, null) spinner = view.findViewById(R.id.playlists_spinner) button = view.findViewById(R.id.addToPlaylist) - if(token!=""){ - fetchPlaylists() + if (token != "") { + fetchPlaylists() } builder.setView(view) builder.create() } ?: throw IllegalStateException("Activity cannot be null") } - private fun fetchPlaylists(){ + private fun fetchPlaylists() { fun run() { lifecycleScope.launchWhenCreated { val response = try { RetrofitInstance.api.playlists(token) - }catch(e: IOException) { + } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") - Toast.makeText(context,R.string.unknown_error, Toast.LENGTH_SHORT).show() + Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } catch (e: HttpException) { Log.e(TAG, "HttpException, unexpected response") - Toast.makeText(context,R.string.server_error, Toast.LENGTH_SHORT).show() + Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } - if (response.isNotEmpty()){ + if (response.isNotEmpty()) { var names = emptyList().toMutableList() - for(playlist in response){ + for (playlist in response) { names.add(playlist.name!!) } - val arrayAdapter = ArrayAdapter(requireContext(),android.R.layout.simple_spinner_item,names) - arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) - spinner.adapter = arrayAdapter + val arrayAdapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, names) + arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + spinner.adapter = arrayAdapter runOnUiThread { button.setOnClickListener { addToPlaylist(response[spinner.selectedItemPosition].id!!) } } - }else{ - + } else { } - } } run() } - private fun addToPlaylist(playlistId: String){ + private fun addToPlaylist(playlistId: String) { fun run() { lifecycleScope.launchWhenCreated { val response = try { RetrofitInstance.api.addToPlaylist(token, PlaylistId(playlistId, videoId)) - }catch(e: IOException) { + } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") - Toast.makeText(context,R.string.unknown_error, Toast.LENGTH_SHORT).show() + Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } catch (e: HttpException) { Log.e(TAG, "HttpException, unexpected response") - Toast.makeText(context,R.string.server_error, Toast.LENGTH_SHORT).show() + Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() return@launchWhenCreated } - if (response.message == "ok"){ - Toast.makeText(context,R.string.success, Toast.LENGTH_SHORT).show() + if (response.message == "ok") { + Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show() dialog?.dismiss() - }else{ - Toast.makeText(context,R.string.fail, Toast.LENGTH_SHORT).show() + } else { + Toast.makeText(context, R.string.fail, Toast.LENGTH_SHORT).show() } - } } run() @@ -106,4 +102,4 @@ class AddtoPlaylistDialog : DialogFragment() { if (!isAdded) return // Fragment not attached to an Activity activity?.runOnUiThread(action) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ChannelFragment.kt b/app/src/main/java/com/github/libretube/ChannelFragment.kt index e8a6d762c..d9af3e2d0 100644 --- a/app/src/main/java/com/github/libretube/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/ChannelFragment.kt @@ -1,13 +1,10 @@ package com.github.libretube - import android.annotation.SuppressLint -import android.app.Activity import android.content.Context import android.os.Bundle import android.text.TextUtils.substring import android.util.Log -import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -23,18 +20,17 @@ import com.github.libretube.adapters.ChannelAdapter import com.github.libretube.obj.Subscribe import com.google.android.material.button.MaterialButton import com.squareup.picasso.Picasso -import retrofit2.HttpException import java.io.IOException - +import retrofit2.HttpException class ChannelFragment : Fragment() { private var channel_id: String? = null private val TAG = "ChannelFragment" - var nextPage: String? =null + var nextPage: String? = null var channelAdapter: ChannelAdapter? = null var isLoading = true - var isSubscribed: Boolean =false + var isSubscribed: Boolean = false private var refreshLayout: SwipeRefreshLayout? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -45,20 +41,19 @@ class ChannelFragment : Fragment() { } override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, + inflater: LayoutInflater, + container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_channel, container, false) - - } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - channel_id = channel_id!!.replace("/channel/","") - view.findViewById(R.id.channel_name).text=channel_id + channel_id = channel_id!!.replace("/channel/", "") + view.findViewById(R.id.channel_name).text = channel_id val recyclerView = view.findViewById(R.id.channel_recView) recyclerView.layoutManager = LinearLayoutManager(context) refreshLayout = view.findViewById(R.id.channel_refresh) @@ -68,7 +63,7 @@ class ChannelFragment : Fragment() { fetchChannel(view) val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) val subButton = view.findViewById(R.id.channel_subscribe) - if (sharedPref?.getString("token","") != "") { + if (sharedPref?.getString("token", "") != "") { isSubscribed(subButton) } } @@ -81,28 +76,26 @@ class ChannelFragment : Fragment() { scrollView.viewTreeObserver .addOnScrollChangedListener { if (scrollView.getChildAt(0).bottom - == (scrollView.height + scrollView.scrollY)) { - //scroll view is at bottom - if(nextPage!=null && !isLoading){ - isLoading=true - refreshLayout?.isRefreshing = true; + == (scrollView.height + scrollView.scrollY) + ) { + // scroll view is at bottom + if (nextPage != null && !isLoading) { + isLoading = true + refreshLayout?.isRefreshing = true fetchNextPage() } - } } - - } - private fun isSubscribed(button: MaterialButton){ + private fun isSubscribed(button: MaterialButton) { @SuppressLint("ResourceAsColor") fun run() { lifecycleScope.launchWhenCreated { val response = try { val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) - RetrofitInstance.api.isSubscribed(channel_id!!,sharedPref?.getString("token","")!!) - } catch(e: IOException) { + RetrofitInstance.api.isSubscribed(channel_id!!, sharedPref?.getString("token", "")!!) + } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") return@launchWhenCreated @@ -112,33 +105,34 @@ class ChannelFragment : Fragment() { } runOnUiThread { - if (response.subscribed==true){ - isSubscribed=true - button.text=getString(R.string.unsubscribe) + if (response.subscribed == true) { + isSubscribed = true + button.text = getString(R.string.unsubscribe) } - if(response.subscribed!=null){ - button.setOnClickListener { - if(isSubscribed){ - unsubscribe() - button.text=getString(R.string.subscribe) - }else{ - subscribe() - button.text=getString(R.string.unsubscribe) + if (response.subscribed != null) { + button.setOnClickListener { + if (isSubscribed) { + unsubscribe() + button.text = getString(R.string.subscribe) + } else { + subscribe() + button.text = getString(R.string.unsubscribe) + } } - }} + } } } } run() } - private fun subscribe(){ + private fun subscribe() { fun run() { lifecycleScope.launchWhenCreated { val response = try { val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) - RetrofitInstance.api.subscribe(sharedPref?.getString("token","")!!, Subscribe(channel_id)) - }catch(e: IOException) { + RetrofitInstance.api.subscribe(sharedPref?.getString("token", "")!!, Subscribe(channel_id)) + } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") return@launchWhenCreated @@ -146,18 +140,18 @@ class ChannelFragment : Fragment() { Log.e(TAG, "HttpException, unexpected response$e") return@launchWhenCreated } - isSubscribed=true + isSubscribed = true } } run() } - private fun unsubscribe(){ + private fun unsubscribe() { fun run() { lifecycleScope.launchWhenCreated { val response = try { val sharedPref = context?.getSharedPreferences("token", Context.MODE_PRIVATE) - RetrofitInstance.api.unsubscribe(sharedPref?.getString("token","")!!, Subscribe(channel_id)) - }catch(e: IOException) { + RetrofitInstance.api.unsubscribe(sharedPref?.getString("token", "")!!, Subscribe(channel_id)) + } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") return@launchWhenCreated @@ -165,37 +159,37 @@ class ChannelFragment : Fragment() { Log.e(TAG, "HttpException, unexpected response") return@launchWhenCreated } - isSubscribed=false + isSubscribed = false } } run() } - private fun fetchChannel(view: View){ + private fun fetchChannel(view: View) { fun run() { lifecycleScope.launchWhenCreated { val response = try { RetrofitInstance.api.getChannel(channel_id!!) - }catch(e: IOException) { - refreshLayout?.isRefreshing = false; + } catch (e: IOException) { + refreshLayout?.isRefreshing = false println(e) Log.e(TAG, "IOException, you might not have internet connection") return@launchWhenCreated } catch (e: HttpException) { - refreshLayout?.isRefreshing = false; + refreshLayout?.isRefreshing = false Log.e(TAG, "HttpException, unexpected response") return@launchWhenCreated } nextPage = response.nextpage - isLoading=false - refreshLayout?.isRefreshing = false; + isLoading = false + refreshLayout?.isRefreshing = false runOnUiThread { view.findViewById(R.id.channel_scrollView).visibility = View.VISIBLE val channelName = view.findViewById(R.id.channel_name) - channelName.text = if (response.name?.length!! > 18) response.name.toString().substring(0,16) + "..." else response.name + channelName.text = if (response.name?.length!! > 18) response.name.toString().substring(0, 16) + "..." else response.name val channelVerified = view.findViewById(R.id.channel_verified) if (response.verified) channelVerified.visibility = View.VISIBLE - view.findViewById(R.id.channel_subs).text=resources.getString(R.string.subscribers, response.subscriberCount.formatShort()) + view.findViewById(R.id.channel_subs).text = resources.getString(R.string.subscribers, response.subscriberCount.formatShort()) val channelDescription = view.findViewById(R.id.channel_description) if (response.description?.trim() == "") channelDescription.visibility = View.GONE else channelDescription.text = response.description?.trim() val bannerImage = view.findViewById(R.id.channel_banner) @@ -204,18 +198,17 @@ class ChannelFragment : Fragment() { Picasso.get().load(response.avatarUrl).into(channelImage) channelAdapter = ChannelAdapter(response.relatedStreams!!.toMutableList()) view.findViewById(R.id.channel_recView).adapter = channelAdapter - } } } run() } - private fun fetchNextPage(){ + private fun fetchNextPage() { fun run() { lifecycleScope.launchWhenCreated { val response = try { - RetrofitInstance.api.getChannelNextPage(channel_id!!,nextPage!!) + RetrofitInstance.api.getChannelNextPage(channel_id!!, nextPage!!) } catch (e: IOException) { refreshLayout?.isRefreshing = false println(e) @@ -223,12 +216,12 @@ class ChannelFragment : Fragment() { return@launchWhenCreated } catch (e: HttpException) { refreshLayout?.isRefreshing = false - Log.e(TAG, "HttpException, unexpected response,"+e.response()) + Log.e(TAG, "HttpException, unexpected response," + e.response()) return@launchWhenCreated } nextPage = response.nextpage channelAdapter?.updateItems(response.relatedStreams!!) - isLoading=false + isLoading = false refreshLayout?.isRefreshing = false } } @@ -244,8 +237,8 @@ class ChannelFragment : Fragment() { val scrollView = view?.findViewById(R.id.channel_scrollView) scrollView?.viewTreeObserver?.removeOnScrollChangedListener { } - channelAdapter=null - view?.findViewById(R.id.channel_recView)?.adapter=null + channelAdapter = null + view?.findViewById(R.id.channel_recView)?.adapter = null super.onDestroyView() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/CreatePlaylistDialog.kt b/app/src/main/java/com/github/libretube/CreatePlaylistDialog.kt index 1bbcc9d32..9f287c045 100644 --- a/app/src/main/java/com/github/libretube/CreatePlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/CreatePlaylistDialog.kt @@ -27,11 +27,10 @@ class CreatePlaylistDialog : DialogFragment() { val createPlaylistBtn = rootView.findViewById