From 57b3053b5895fcc9dd4050b291f208a807107d2b Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 8 Aug 2022 11:38:50 +0200 Subject: [PATCH 1/4] use better tags --- .../java/com/github/libretube/adapters/ChannelAdapter.kt | 2 +- .../java/com/github/libretube/adapters/PlaylistAdapter.kt | 2 +- .../com/github/libretube/adapters/PlaylistsAdapter.kt | 1 - .../java/com/github/libretube/adapters/SearchAdapter.kt | 4 ++-- .../java/com/github/libretube/adapters/TrendingAdapter.kt | 2 +- .../com/github/libretube/adapters/WatchHistoryAdapter.kt | 2 +- .../com/github/libretube/dialogs/DeleteAccountDialog.kt | 2 +- .../com/github/libretube/dialogs/PlaylistOptionsDialog.kt | 2 +- .../com/github/libretube/dialogs/VideoOptionsDialog.kt | 4 ++-- .../java/com/github/libretube/extensions/BaseActivity.kt | 6 ++++++ .../com/github/libretube/fragments/LibraryFragment.kt | 2 +- .../java/com/github/libretube/fragments/PlayerFragment.kt | 6 +++--- .../com/github/libretube/fragments/PlaylistFragment.kt | 2 +- .../github/libretube/preferences/AppearanceSettings.kt | 8 ++++---- .../com/github/libretube/preferences/GeneralSettings.kt | 6 +++--- .../com/github/libretube/preferences/InstanceSettings.kt | 8 ++++---- .../java/com/github/libretube/preferences/MainSettings.kt | 2 +- .../java/com/github/libretube/services/BackgroundMode.kt | 1 - 18 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/extensions/BaseActivity.kt diff --git a/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt b/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt index 895929166..3574d9117 100644 --- a/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt @@ -52,7 +52,7 @@ class ChannelAdapter( val videoId = trending.url.toID() root.setOnLongClickListener { VideoOptionsDialog(videoId) - .show(childFragmentManager, "VideoOptionsDialog") + .show(childFragmentManager, VideoOptionsDialog::class.java.name) true } watchProgress.setWatchProgressLength(videoId, trending.duration!!) diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt index baa0031f4..c6f90c022 100644 --- a/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/PlaylistAdapter.kt @@ -61,7 +61,7 @@ class PlaylistAdapter( val videoId = streamItem.url.toID() root.setOnLongClickListener { VideoOptionsDialog(videoId) - .show(childFragmentManager, "VideoOptionsDialog") + .show(childFragmentManager, VideoOptionsDialog::class.java.name) true } diff --git a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt index 1e53cbaf6..931e7ba0f 100644 --- a/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/PlaylistsAdapter.kt @@ -48,7 +48,6 @@ class PlaylistsAdapter( val playlist = playlists[position] holder.binding.apply { // set imageview drawable as empty playlist if imageview empty - Log.e(TAG, playlist.thumbnail.toString()) if (playlist.thumbnail!!.split("/").size <= 4) { playlistThumbnail.setImageResource(R.drawable.ic_empty_playlist) playlistThumbnail.setBackgroundColor(R.attr.colorSurface) diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index 4c2709281..dad2e931f 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -103,7 +103,7 @@ class SearchAdapter( val videoId = item.url.toID() root.setOnLongClickListener { VideoOptionsDialog(videoId) - .show(childFragmentManager, "VideoOptionsDialog") + .show(childFragmentManager, VideoOptionsDialog::class.java.name) true } channelImage.setOnClickListener { @@ -176,7 +176,7 @@ class SearchAdapter( root.setOnLongClickListener { val playlistId = item.url!!.toID() PlaylistOptionsDialog(playlistId, false) - .show(childFragmentManager, "PlaylistOptionsDialog") + .show(childFragmentManager, PlaylistOptionsDialog::class.java.name) true } } diff --git a/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt b/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt index 28ecce85b..1d9aba5b5 100644 --- a/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt @@ -66,7 +66,7 @@ class TrendingAdapter( val videoId = trending.url!!.toID() root.setOnLongClickListener { VideoOptionsDialog(videoId) - .show(childFragmentManager, "VideoOptionsDialog") + .show(childFragmentManager, VideoOptionsDialog::class.java.name) true } watchProgress.setWatchProgressLength(videoId, trending.duration!!) diff --git a/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt index 27bc9b694..b3a8f1b5b 100644 --- a/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt @@ -51,7 +51,7 @@ class WatchHistoryAdapter( } root.setOnLongClickListener { VideoOptionsDialog(video.videoId!!) - .show(childFragmentManager, "VideoOptionsDialog") + .show(childFragmentManager, VideoOptionsDialog::class.java.name) true } diff --git a/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt index f1bff5b6f..6accb54a4 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DeleteAccountDialog.kt @@ -57,7 +57,7 @@ class DeleteAccountDialog : DialogFragment() { Toast.makeText(context, R.string.success, Toast.LENGTH_SHORT).show() logout() val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) } } run() diff --git a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt index 566d64774..e3c0ba8b5 100644 --- a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt @@ -81,7 +81,7 @@ class PlaylistOptionsDialog( context?.getString(R.string.share) -> { val shareDialog = ShareDialog(playlistId, true) // using parentFragmentManager, childFragmentManager doesn't work here - shareDialog.show(parentFragmentManager, "ShareDialog") + shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) } context?.getString(R.string.deletePlaylist) -> { val token = PreferenceHelper.getToken() diff --git a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt index 63adf531e..cf95eb04c 100644 --- a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt @@ -55,7 +55,7 @@ class VideoOptionsDialog( val bundle = Bundle() bundle.putString("videoId", videoId) newFragment.arguments = bundle - newFragment.show(parentFragmentManager, "AddToPlaylist") + newFragment.show(parentFragmentManager, AddToPlaylistDialog::class.java.name) } else { Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show() } @@ -63,7 +63,7 @@ class VideoOptionsDialog( context?.getString(R.string.share) -> { val shareDialog = ShareDialog(videoId, false) // using parentFragmentManager is important here - shareDialog.show(parentFragmentManager, "ShareDialog") + shareDialog.show(parentFragmentManager, ShareDialog::class.java.name) } } } diff --git a/app/src/main/java/com/github/libretube/extensions/BaseActivity.kt b/app/src/main/java/com/github/libretube/extensions/BaseActivity.kt new file mode 100644 index 000000000..1136a6bb3 --- /dev/null +++ b/app/src/main/java/com/github/libretube/extensions/BaseActivity.kt @@ -0,0 +1,6 @@ +package com.github.libretube.extensions + +import androidx.appcompat.app.AppCompatActivity + +class BaseActivity: AppCompatActivity() { +} \ No newline at end of file diff --git a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt index b1cc76c99..36d87e5a2 100644 --- a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt @@ -68,7 +68,7 @@ class LibraryFragment : Fragment() { } binding.createPlaylist.setOnClickListener { val newFragment = CreatePlaylistDialog() - newFragment.show(childFragmentManager, "Create Playlist") + newFragment.show(childFragmentManager, CreatePlaylistDialog::class.java.name) } } else { binding.playlistRefresh.isEnabled = false diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index a2cbf2544..52061e0ca 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -523,7 +523,7 @@ class PlayerFragment : Fragment() { // share button binding.relPlayerShare.setOnClickListener { val shareDialog = ShareDialog(videoId!!, false, exoPlayer.currentPosition) - shareDialog.show(childFragmentManager, "ShareDialog") + shareDialog.show(childFragmentManager, ShareDialog::class.java.name) } binding.relPlayerBackground.setOnClickListener { @@ -979,7 +979,7 @@ class PlayerFragment : Fragment() { val bundle = Bundle() bundle.putString("video_id", videoId) newFragment.arguments = bundle - newFragment.show(childFragmentManager, "DownloadDialog") + newFragment.show(childFragmentManager, DownloadDialog::class.java.name) } else { Toast.makeText(context, R.string.dlisinprogress, Toast.LENGTH_SHORT) .show() @@ -1045,7 +1045,7 @@ class PlayerFragment : Fragment() { val bundle = Bundle() bundle.putString("videoId", videoId) newFragment.arguments = bundle - newFragment.show(childFragmentManager, "AddToPlaylist") + newFragment.show(childFragmentManager, AddToPlaylistDialog::class.java.name) } } else { binding.relPlayerSave.setOnClickListener { diff --git a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt index a11098bd5..61fbe1ee9 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt @@ -87,7 +87,7 @@ class PlaylistFragment : Fragment() { binding.optionsMenu.setOnClickListener { val optionsDialog = PlaylistOptionsDialog(playlistId!!, isOwner) - optionsDialog.show(childFragmentManager, "PlaylistOptionsDialog") + optionsDialog.show(childFragmentManager, PlaylistOptionsDialog::class.java.name) } playlistAdapter = PlaylistAdapter( diff --git a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt index 827613604..7c5ce8f5d 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -26,14 +26,14 @@ class AppearanceSettings : MaterialPreferenceFragment() { val themeToggle = findPreference(PreferenceKeys.THEME_MODE) themeToggle?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) true } val pureTheme = findPreference(PreferenceKeys.PURE_THEME) pureTheme?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) true } @@ -41,7 +41,7 @@ class AppearanceSettings : MaterialPreferenceFragment() { updateAccentColorValues(accentColor!!) accentColor.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) true } @@ -54,7 +54,7 @@ class AppearanceSettings : MaterialPreferenceFragment() { val labelVisibilityMode = findPreference(PreferenceKeys.LABEL_VISIBILITY) labelVisibilityMode?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) true } diff --git a/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt b/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt index bf5e39ce0..f9d15e56d 100644 --- a/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/GeneralSettings.kt @@ -20,21 +20,21 @@ class GeneralSettings : MaterialPreferenceFragment() { val language = findPreference("language") language?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) true } val autoRotation = findPreference(PreferenceKeys.AUTO_ROTATION) autoRotation?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) true } val hideTrending = findPreference(PreferenceKeys.HIDE_TRENDING_PAGE) hideTrending?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() - restartDialog.show(childFragmentManager, "RequireRestartDialog") + restartDialog.show(childFragmentManager, RequireRestartDialog::class.java.name) true } } diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index 06c50c185..4b233d57d 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -99,7 +99,7 @@ class InstanceSettings : MaterialPreferenceFragment() { val customInstance = findPreference(PreferenceKeys.CUSTOM_INSTANCE) customInstance?.setOnPreferenceClickListener { val newFragment = CustomInstanceDialog() - newFragment.show(childFragmentManager, "CustomInstanceDialog") + newFragment.show(childFragmentManager, CustomInstanceDialog::class.java.name) true } @@ -117,10 +117,10 @@ class InstanceSettings : MaterialPreferenceFragment() { login?.setOnPreferenceClickListener { if (token == "") { val newFragment = LoginDialog() - newFragment.show(childFragmentManager, "Login") + newFragment.show(childFragmentManager, LoginDialog::class.java.name) } else { val newFragment = LogoutDialog() - newFragment.show(childFragmentManager, "Logout") + newFragment.show(childFragmentManager, LogoutDialog::class.java.name) } true @@ -131,7 +131,7 @@ class InstanceSettings : MaterialPreferenceFragment() { val token = PreferenceHelper.getToken() if (token != "") { val newFragment = DeleteAccountDialog() - newFragment.show(childFragmentManager, "DeleteAccountDialog") + newFragment.show(childFragmentManager, DeleteAccountDialog::class.java.name) } else { Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt index 413c94cb0..dbad3d703 100644 --- a/app/src/main/java/com/github/libretube/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/MainSettings.kt @@ -101,7 +101,7 @@ class MainSettings : MaterialPreferenceFragment() { } else if (BuildConfig.VERSION_NAME != updateInfo.name) { // show the UpdateAvailableDialog if there's an update available val updateAvailableDialog = UpdateDialog(updateInfo) - updateAvailableDialog.show(childFragmentManager, "UpdateAvailableDialog") + updateAvailableDialog.show(childFragmentManager, UpdateDialog::class.java.name) } else { // otherwise show the no update available snackBar val settingsActivity = activity as SettingsActivity diff --git a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt index 6c0e9dc17..0a70a285e 100644 --- a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt @@ -205,7 +205,6 @@ class BackgroundMode : Service() { nextStreamId = streams?.relatedStreams!![0].url.toID() } - return if (playlistId == null) return if (!this::autoPlayHelper.isInitialized) autoPlayHelper = AutoPlayHelper(playlistId!!) // search for the next videoId in the playlist From 5f498e2e3973d749e2404ca22d713cbd8e92b741 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 8 Aug 2022 11:43:54 +0200 Subject: [PATCH 2/4] extend activity --- .../github/libretube/activities/AboutActivity.kt | 4 ++-- .../libretube/activities/CommunityActivity.kt | 4 ++-- .../github/libretube/activities/MainActivity.kt | 7 ++----- .../libretube/activities/NoInternetActivity.kt | 5 ++--- .../github/libretube/activities/RouterActivity.kt | 4 ++-- .../libretube/activities/SettingsActivity.kt | 15 ++------------- .../github/libretube/extensions/BaseActivity.kt | 12 ++++++++++-- 7 files changed, 22 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/github/libretube/activities/AboutActivity.kt b/app/src/main/java/com/github/libretube/activities/AboutActivity.kt index c564cf8e3..a6a23a862 100644 --- a/app/src/main/java/com/github/libretube/activities/AboutActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/AboutActivity.kt @@ -5,7 +5,6 @@ import android.net.Uri import android.os.Build import android.os.Bundle import android.text.Html -import androidx.appcompat.app.AppCompatActivity import com.github.libretube.DONATE_URL import com.github.libretube.GITHUB_URL import com.github.libretube.PIPED_GITHUB_URL @@ -13,10 +12,11 @@ import com.github.libretube.R import com.github.libretube.WEBLATE_URL import com.github.libretube.WEBSITE_URL import com.github.libretube.databinding.ActivityAboutBinding +import com.github.libretube.extensions.BaseActivity import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar -class AboutActivity : AppCompatActivity() { +class AboutActivity : BaseActivity() { private lateinit var binding: ActivityAboutBinding override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/github/libretube/activities/CommunityActivity.kt b/app/src/main/java/com/github/libretube/activities/CommunityActivity.kt index d28db2fa8..7fe9f2211 100644 --- a/app/src/main/java/com/github/libretube/activities/CommunityActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/CommunityActivity.kt @@ -3,15 +3,15 @@ package com.github.libretube.activities import android.content.Intent import android.net.Uri import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import com.github.libretube.DISCORD_URL import com.github.libretube.MATRIX_URL import com.github.libretube.REDDIT_URL import com.github.libretube.TELEGRAM_URL import com.github.libretube.TWITTER_URL import com.github.libretube.databinding.ActivityCommunityBinding +import com.github.libretube.extensions.BaseActivity -class CommunityActivity : AppCompatActivity() { +class CommunityActivity : BaseActivity() { private lateinit var binding: ActivityCommunityBinding override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 58317079f..697a9df76 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -16,7 +16,6 @@ import android.view.WindowInsets import android.view.WindowInsetsController import android.view.WindowManager import android.widget.LinearLayout -import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.constraintlayout.motion.widget.MotionLayout import androidx.constraintlayout.widget.ConstraintLayout @@ -30,6 +29,7 @@ import com.github.libretube.Globals import com.github.libretube.R import com.github.libretube.databinding.ActivityMainBinding import com.github.libretube.dialogs.ErrorDialog +import com.github.libretube.extensions.BaseActivity import com.github.libretube.fragments.PlayerFragment import com.github.libretube.models.SearchViewModel import com.github.libretube.preferences.PreferenceHelper @@ -42,7 +42,7 @@ import com.github.libretube.util.ThemeHelper import com.google.android.material.elevation.SurfaceColors import com.google.android.material.navigation.NavigationBarView -class MainActivity : AppCompatActivity() { +class MainActivity : BaseActivity() { val TAG = "MainActivity" lateinit var binding: ActivityMainBinding @@ -54,9 +54,6 @@ class MainActivity : AppCompatActivity() { lateinit var searchView: SearchView override fun onCreate(savedInstanceState: Bundle?) { - // set the app theme (e.g. Material You) - ThemeHelper.updateTheme(this) - // set the language LocaleHelper.updateLanguage(this) diff --git a/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt b/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt index 53f08a650..e60ae1ee4 100644 --- a/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/NoInternetActivity.kt @@ -2,18 +2,17 @@ package com.github.libretube.activities import android.content.Intent import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import com.github.libretube.R import com.github.libretube.databinding.ActivityNointernetBinding +import com.github.libretube.extensions.BaseActivity import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.ThemeHelper import com.google.android.material.snackbar.Snackbar -class NoInternetActivity : AppCompatActivity() { +class NoInternetActivity : BaseActivity() { private lateinit var binding: ActivityNointernetBinding override fun onCreate(savedInstanceState: Bundle?) { - ThemeHelper.updateTheme(this) super.onCreate(savedInstanceState) binding = ActivityNointernetBinding.inflate(layoutInflater) diff --git a/app/src/main/java/com/github/libretube/activities/RouterActivity.kt b/app/src/main/java/com/github/libretube/activities/RouterActivity.kt index a90e218da..b9e981b50 100644 --- a/app/src/main/java/com/github/libretube/activities/RouterActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/RouterActivity.kt @@ -5,11 +5,11 @@ import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.util.Log -import androidx.appcompat.app.AppCompatActivity import com.github.libretube.R +import com.github.libretube.extensions.BaseActivity import com.github.libretube.util.ThemeHelper -class RouterActivity : AppCompatActivity() { +class RouterActivity : BaseActivity() { val TAG = "RouterActivity" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt b/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt index 12cb149a4..e33b0019f 100644 --- a/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/SettingsActivity.kt @@ -1,31 +1,20 @@ package com.github.libretube.activities -import android.os.Build import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity import com.github.libretube.R import com.github.libretube.databinding.ActivitySettingsBinding +import com.github.libretube.extensions.BaseActivity import com.github.libretube.preferences.MainSettings -import com.github.libretube.util.ThemeHelper -class SettingsActivity : AppCompatActivity() { +class SettingsActivity : BaseActivity() { val TAG = "SettingsActivity" lateinit var binding: ActivitySettingsBinding override fun onCreate(savedInstanceState: Bundle?) { - ThemeHelper.updateTheme(this) - super.onCreate(savedInstanceState) binding = ActivitySettingsBinding.inflate(layoutInflater) - // animate the layout transition - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - overridePendingTransition(50, 50) - } - binding.root.alpha = 0F - binding.root.animate().alpha(1F).duration = 300 - setContentView(binding.root) binding.backImageButton.setOnClickListener { diff --git a/app/src/main/java/com/github/libretube/extensions/BaseActivity.kt b/app/src/main/java/com/github/libretube/extensions/BaseActivity.kt index 1136a6bb3..cae26114a 100644 --- a/app/src/main/java/com/github/libretube/extensions/BaseActivity.kt +++ b/app/src/main/java/com/github/libretube/extensions/BaseActivity.kt @@ -1,6 +1,14 @@ package com.github.libretube.extensions +import android.os.Bundle import androidx.appcompat.app.AppCompatActivity +import com.github.libretube.util.ThemeHelper -class BaseActivity: AppCompatActivity() { -} \ No newline at end of file +open class BaseActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + // set the app theme (e.g. Material You) + ThemeHelper.updateTheme(this) + + super.onCreate(savedInstanceState) + } +} From 1cb0c8f7b5a93a09ef81e7a407ed841577dc0587 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 8 Aug 2022 11:49:19 +0200 Subject: [PATCH 3/4] extend fragment --- .../libretube/dialogs/PlaylistOptionsDialog.kt | 5 +++-- .../libretube/dialogs/VideoOptionsDialog.kt | 5 ++++- .../github/libretube/extensions/BaseFragment.kt | 10 ++++++++++ .../github/libretube/fragments/ChannelFragment.kt | 10 ++-------- .../github/libretube/fragments/HomeFragment.kt | 10 ++-------- .../github/libretube/fragments/LibraryFragment.kt | 10 ++-------- .../github/libretube/fragments/PlayerFragment.kt | 12 +++--------- .../libretube/fragments/PlaylistFragment.kt | 15 ++++++--------- .../github/libretube/fragments/SearchFragment.kt | 10 ++-------- .../libretube/fragments/SearchResultFragment.kt | 10 ++-------- .../libretube/fragments/SubscriptionsFragment.kt | 10 ++-------- .../libretube/fragments/WatchHistoryFragment.kt | 4 ++-- .../com/github/libretube/util/AutoPlayHelper.kt | 5 ++++- .../com/github/libretube/util/ResettableLazy.kt | 2 +- 14 files changed, 45 insertions(+), 73 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/extensions/BaseFragment.kt diff --git a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt index e3c0ba8b5..eb3750487 100644 --- a/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/PlaylistOptionsDialog.kt @@ -55,8 +55,9 @@ class PlaylistOptionsDialog( // play the playlist in the background context?.getString(R.string.playOnBackground) -> { runBlocking { - val playlist = if (isOwner) RetrofitInstance.authApi.getPlaylist(playlistId) - else RetrofitInstance.api.getPlaylist(playlistId) + val playlist = + if (isOwner) RetrofitInstance.authApi.getPlaylist(playlistId) + else RetrofitInstance.api.getPlaylist(playlistId) BackgroundHelper.playOnBackground( context = requireContext(), videoId = playlist.relatedStreams!![0].url.toID(), diff --git a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt index cf95eb04c..a90e270cf 100644 --- a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt @@ -55,7 +55,10 @@ class VideoOptionsDialog( val bundle = Bundle() bundle.putString("videoId", videoId) newFragment.arguments = bundle - newFragment.show(parentFragmentManager, AddToPlaylistDialog::class.java.name) + newFragment.show( + parentFragmentManager, + AddToPlaylistDialog::class.java.name + ) } else { Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/java/com/github/libretube/extensions/BaseFragment.kt b/app/src/main/java/com/github/libretube/extensions/BaseFragment.kt new file mode 100644 index 000000000..ded091322 --- /dev/null +++ b/app/src/main/java/com/github/libretube/extensions/BaseFragment.kt @@ -0,0 +1,10 @@ +package com.github.libretube.extensions + +import androidx.fragment.app.Fragment + +open class BaseFragment : Fragment() { + fun runOnUiThread(action: () -> Unit) { + if (!isAdded) return // Fragment not attached to an Activity + activity?.runOnUiThread(action) + } +} diff --git a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt index 9861963ed..5399e75dc 100644 --- a/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/ChannelFragment.kt @@ -5,12 +5,12 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.R import com.github.libretube.adapters.ChannelAdapter import com.github.libretube.databinding.FragmentChannelBinding +import com.github.libretube.extensions.BaseFragment import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.SubscriptionHelper @@ -19,7 +19,7 @@ import com.github.libretube.util.toID import retrofit2.HttpException import java.io.IOException -class ChannelFragment : Fragment() { +class ChannelFragment : BaseFragment() { private val TAG = "ChannelFragment" private lateinit var binding: FragmentChannelBinding @@ -184,10 +184,4 @@ class ChannelFragment : Fragment() { } run() } - - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } } diff --git a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt index a65364b8c..2a1312e55 100644 --- a/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/HomeFragment.kt @@ -6,12 +6,12 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import com.github.libretube.R import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.databinding.FragmentHomeBinding +import com.github.libretube.extensions.BaseFragment import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.LocaleHelper @@ -19,7 +19,7 @@ import com.github.libretube.util.RetrofitInstance import retrofit2.HttpException import java.io.IOException -class HomeFragment : Fragment() { +class HomeFragment : BaseFragment() { private val TAG = "HomeFragment" private lateinit var binding: FragmentHomeBinding private lateinit var region: String @@ -88,10 +88,4 @@ class HomeFragment : Fragment() { } run() } - - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } } diff --git a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt index 36d87e5a2..ac09a945b 100644 --- a/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/LibraryFragment.kt @@ -6,7 +6,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager @@ -15,13 +14,14 @@ import com.github.libretube.R import com.github.libretube.adapters.PlaylistsAdapter import com.github.libretube.databinding.FragmentLibraryBinding import com.github.libretube.dialogs.CreatePlaylistDialog +import com.github.libretube.extensions.BaseFragment import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.RetrofitInstance import retrofit2.HttpException import java.io.IOException -class LibraryFragment : Fragment() { +class LibraryFragment : BaseFragment() { private val TAG = "LibraryFragment" lateinit var token: String @@ -129,10 +129,4 @@ class LibraryFragment : Fragment() { } run() } - - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } } diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 52061e0ca..b6f4b282e 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -28,7 +28,6 @@ import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.net.toUri import androidx.core.os.bundleOf import androidx.core.view.isVisible -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager @@ -45,6 +44,7 @@ import com.github.libretube.databinding.FragmentPlayerBinding import com.github.libretube.dialogs.AddToPlaylistDialog import com.github.libretube.dialogs.DownloadDialog import com.github.libretube.dialogs.ShareDialog +import com.github.libretube.extensions.BaseFragment import com.github.libretube.obj.ChapterSegment import com.github.libretube.obj.Segment import com.github.libretube.obj.Segments @@ -88,6 +88,7 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource import com.google.android.exoplayer2.util.RepeatModeUtil import com.google.android.exoplayer2.video.VideoSize import com.google.android.material.dialog.MaterialAlertDialogBuilder +import kotlin.math.abs import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -95,9 +96,8 @@ import org.chromium.net.CronetEngine import retrofit2.HttpException import java.io.IOException import java.util.concurrent.Executors -import kotlin.math.abs -class PlayerFragment : Fragment() { +class PlayerFragment : BaseFragment() { private val TAG = "PlayerFragment" private lateinit var binding: FragmentPlayerBinding @@ -1509,12 +1509,6 @@ class PlayerFragment : Fragment() { run() } - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } - private fun fetchComments() { lifecycleScope.launchWhenCreated { val commentsResponse = try { diff --git a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt index 61fbe1ee9..059a5fa21 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlaylistFragment.kt @@ -5,7 +5,6 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -14,13 +13,14 @@ import com.github.libretube.R import com.github.libretube.adapters.PlaylistAdapter import com.github.libretube.databinding.FragmentPlaylistBinding import com.github.libretube.dialogs.PlaylistOptionsDialog +import com.github.libretube.extensions.BaseFragment import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.toID import retrofit2.HttpException import java.io.IOException -class PlaylistFragment : Fragment() { +class PlaylistFragment : BaseFragment() { private val TAG = "PlaylistFragment" private lateinit var binding: FragmentPlaylistBinding @@ -87,7 +87,10 @@ class PlaylistFragment : Fragment() { binding.optionsMenu.setOnClickListener { val optionsDialog = PlaylistOptionsDialog(playlistId!!, isOwner) - optionsDialog.show(childFragmentManager, PlaylistOptionsDialog::class.java.name) + optionsDialog.show( + childFragmentManager, + PlaylistOptionsDialog::class.java.name + ) } playlistAdapter = PlaylistAdapter( @@ -171,10 +174,4 @@ class PlaylistFragment : Fragment() { } run() } - - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } } diff --git a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt index 47487e725..ca133d4e2 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt @@ -5,7 +5,6 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager @@ -13,13 +12,14 @@ import com.github.libretube.activities.MainActivity import com.github.libretube.adapters.SearchHistoryAdapter import com.github.libretube.adapters.SearchSuggestionsAdapter import com.github.libretube.databinding.FragmentSearchBinding +import com.github.libretube.extensions.BaseFragment import com.github.libretube.models.SearchViewModel import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.util.RetrofitInstance import retrofit2.HttpException import java.io.IOException -class SearchFragment() : Fragment() { +class SearchFragment() : BaseFragment() { private val TAG = "SearchFragment" private lateinit var binding: FragmentSearchBinding private val viewModel: SearchViewModel by activityViewModels() @@ -101,10 +101,4 @@ class SearchFragment() : Fragment() { binding.historyEmpty.visibility = View.VISIBLE } } - - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } } diff --git a/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt index 4a6ea764f..76ca8506f 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchResultFragment.kt @@ -5,12 +5,12 @@ import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.R import com.github.libretube.adapters.SearchAdapter import com.github.libretube.databinding.FragmentSearchResultBinding +import com.github.libretube.extensions.BaseFragment import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.RetrofitInstance @@ -18,7 +18,7 @@ import com.github.libretube.util.hideKeyboard import retrofit2.HttpException import java.io.IOException -class SearchResultFragment : Fragment() { +class SearchResultFragment : BaseFragment() { private val TAG = "SearchResultFragment" private lateinit var binding: FragmentSearchResultBinding @@ -135,10 +135,4 @@ class SearchResultFragment : Fragment() { PreferenceHelper.saveToSearchHistory(query) } } - - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } } diff --git a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt index 4d1400cbc..ded749700 100644 --- a/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SubscriptionsFragment.kt @@ -7,7 +7,6 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.core.view.isVisible -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager @@ -15,6 +14,7 @@ import com.github.libretube.R import com.github.libretube.adapters.SubscriptionChannelAdapter import com.github.libretube.adapters.TrendingAdapter import com.github.libretube.databinding.FragmentSubscriptionsBinding +import com.github.libretube.extensions.BaseFragment import com.github.libretube.obj.StreamItem import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceKeys @@ -25,7 +25,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import retrofit2.HttpException import java.io.IOException -class SubscriptionsFragment : Fragment() { +class SubscriptionsFragment : BaseFragment() { val TAG = "SubFragment" private lateinit var binding: FragmentSubscriptionsBinding @@ -199,10 +199,4 @@ class SubscriptionsFragment : Fragment() { } run() } - - private fun Fragment?.runOnUiThread(action: () -> Unit) { - this ?: return - if (!isAdded) return // Fragment not attached to an Activity - activity?.runOnUiThread(action) - } } diff --git a/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt index 43c5e3a4d..df8fec274 100644 --- a/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/WatchHistoryFragment.kt @@ -4,13 +4,13 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.adapters.WatchHistoryAdapter import com.github.libretube.databinding.FragmentWatchHistoryBinding +import com.github.libretube.extensions.BaseFragment import com.github.libretube.preferences.PreferenceHelper -class WatchHistoryFragment : Fragment() { +class WatchHistoryFragment : BaseFragment() { private val TAG = "WatchHistoryFragment" private lateinit var binding: FragmentWatchHistoryBinding diff --git a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt index 7ade16f67..ca48fd1d2 100644 --- a/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt +++ b/app/src/main/java/com/github/libretube/util/AutoPlayHelper.kt @@ -25,7 +25,10 @@ class AutoPlayHelper( // fetch the playlists or its nextPage's videos val playlist = if (playlistNextPage == null) RetrofitInstance.authApi.getPlaylist(playlistId) - else RetrofitInstance.authApi.getPlaylistNextPage(playlistId, playlistNextPage!!) + else RetrofitInstance.authApi.getPlaylistNextPage( + playlistId, + playlistNextPage!! + ) // save the playlist urls to the list playlistStreamIds += playlist.relatedStreams!!.map { it.url.toID() } // save playlistNextPage for usage if video is not contained diff --git a/app/src/main/java/com/github/libretube/util/ResettableLazy.kt b/app/src/main/java/com/github/libretube/util/ResettableLazy.kt index 129e27de6..432dff009 100644 --- a/app/src/main/java/com/github/libretube/util/ResettableLazy.kt +++ b/app/src/main/java/com/github/libretube/util/ResettableLazy.kt @@ -1,7 +1,7 @@ package com.github.libretube.util -import java.util.* import kotlin.reflect.KProperty +import java.util.* class ResettableLazyManager { // we synchronize to make sure the timing of a reset() call and new inits do not collide From a39b03e77838d4eefe8b00c25cdcc989596416ea Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 8 Aug 2022 12:01:25 +0200 Subject: [PATCH 4/4] fix crash --- .../com/github/libretube/dialogs/DownloadDialog.kt | 3 +-- .../com/github/libretube/dialogs/UpdateDialog.kt | 3 +-- .../github/libretube/fragments/PlayerFragment.kt | 2 +- .../libretube/preferences/InstanceSettings.kt | 5 ++--- .../com/github/libretube/services/BackgroundMode.kt | 13 +++++++++++++ .../com/github/libretube/services/UpdateService.kt | 11 ++++++++++- .../com/github/libretube/util/PermissionHelper.kt | 6 +++--- .../com/github/libretube/util/ResettableLazy.kt | 2 +- .../java/com/github/libretube/util/ThemeHelper.kt | 2 +- app/src/main/res/values/strings.xml | 2 +- 10 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt index 5dbf63ea7..4f2ed94a1 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt @@ -7,7 +7,6 @@ import android.util.Log import android.view.View import android.widget.ArrayAdapter import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity import androidx.core.view.size import androidx.fragment.app.DialogFragment import androidx.lifecycle.lifecycleScope @@ -38,7 +37,7 @@ class DownloadDialog : DialogFragment() { fetchAvailableSources() - PermissionHelper.requestReadWrite(activity as AppCompatActivity) + PermissionHelper.requestReadWrite(requireActivity()) binding.title.text = ThemeHelper.getStyledAppName(requireContext()) diff --git a/app/src/main/java/com/github/libretube/dialogs/UpdateDialog.kt b/app/src/main/java/com/github/libretube/dialogs/UpdateDialog.kt index 4ddeceea7..715400bdd 100644 --- a/app/src/main/java/com/github/libretube/dialogs/UpdateDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/UpdateDialog.kt @@ -6,7 +6,6 @@ import android.net.Uri import android.os.Build import android.os.Bundle import android.util.Log -import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.DialogFragment import com.github.libretube.R import com.github.libretube.services.UpdateService @@ -28,7 +27,7 @@ class UpdateDialog( val downloadUrl = getDownloadUrl(updateInfo) Log.i("downloadUrl", downloadUrl.toString()) if (downloadUrl != null) { - PermissionHelper.requestReadWrite(activity as AppCompatActivity) + PermissionHelper.requestReadWrite(requireActivity()) val intent = Intent(context, UpdateService::class.java) intent.putExtra("downloadUrl", downloadUrl) context?.startService(intent) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index b6f4b282e..908073fa7 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -88,7 +88,6 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource import com.google.android.exoplayer2.util.RepeatModeUtil import com.google.android.exoplayer2.video.VideoSize import com.google.android.material.dialog.MaterialAlertDialogBuilder -import kotlin.math.abs import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -96,6 +95,7 @@ import org.chromium.net.CronetEngine import retrofit2.HttpException import java.io.IOException import java.util.concurrent.Executors +import kotlin.math.abs class PlayerFragment : BaseFragment() { diff --git a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt index 4b233d57d..12c2a9381 100644 --- a/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/InstanceSettings.kt @@ -6,7 +6,6 @@ import android.os.Bundle import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.preference.ListPreference @@ -142,11 +141,11 @@ class InstanceSettings : MaterialPreferenceFragment() { importSubscriptions?.setOnPreferenceClickListener { // check StorageAccess val accessGranted = - PermissionHelper.isStoragePermissionGranted(activity as AppCompatActivity) + PermissionHelper.isStoragePermissionGranted(requireActivity()) // import subscriptions if (accessGranted) getContent.launch("*/*") // request permissions if not granted - else PermissionHelper.requestReadWrite(activity as AppCompatActivity) + else PermissionHelper.requestReadWrite(requireActivity()) true } diff --git a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt index 0a70a285e..c22a889e1 100644 --- a/app/src/main/java/com/github/libretube/services/BackgroundMode.kt +++ b/app/src/main/java/com/github/libretube/services/BackgroundMode.kt @@ -9,6 +9,7 @@ import android.os.Build import android.os.Handler import android.os.IBinder import android.os.Looper +import android.widget.Toast import com.fasterxml.jackson.databind.ObjectMapper import com.github.libretube.BACKGROUND_CHANNEL_ID import com.github.libretube.PLAYER_NOTIFICATION_ID @@ -269,6 +270,18 @@ class BackgroundMode : Service() { val segmentEnd = (segment.segment[1] * 1000f).toLong() val currentPosition = player?.currentPosition if (currentPosition in segmentStart until segmentEnd) { + if (PreferenceHelper.getBoolean( + "sb_notifications_key", + true + ) + ) { + try { + Toast.makeText(this, R.string.segment_skipped, Toast.LENGTH_SHORT) + .show() + } catch (e: Exception) { + // Do nothing. + } + } player?.seekTo(segmentEnd) } } diff --git a/app/src/main/java/com/github/libretube/services/UpdateService.kt b/app/src/main/java/com/github/libretube/services/UpdateService.kt index 47d3c3888..5c34cf38b 100644 --- a/app/src/main/java/com/github/libretube/services/UpdateService.kt +++ b/app/src/main/java/com/github/libretube/services/UpdateService.kt @@ -9,6 +9,7 @@ import android.content.IntentFilter import android.net.Uri import android.os.Environment import android.os.IBinder +import android.widget.Toast import com.github.libretube.R import java.io.File @@ -64,7 +65,15 @@ class UpdateService : Service() { Uri.fromFile(file), downloadManager.getMimeTypeForDownloadedFile(downloadId) ) - startActivity(installIntent) + try { + startActivity(installIntent) + } catch (e: Exception) { + Toast.makeText( + context, + R.string.downloadsucceeded, + Toast.LENGTH_SHORT + ).show() + } } } } diff --git a/app/src/main/java/com/github/libretube/util/PermissionHelper.kt b/app/src/main/java/com/github/libretube/util/PermissionHelper.kt index 562423377..3670a2d81 100644 --- a/app/src/main/java/com/github/libretube/util/PermissionHelper.kt +++ b/app/src/main/java/com/github/libretube/util/PermissionHelper.kt @@ -1,14 +1,14 @@ package com.github.libretube.util import android.Manifest +import android.app.Activity import android.content.pm.PackageManager import android.os.Build import android.os.Environment -import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat object PermissionHelper { - fun requestReadWrite(activity: AppCompatActivity): Boolean { + fun requestReadWrite(activity: Activity): Boolean { // request storage permissions if not granted yet if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (!Environment.isExternalStorageManager()) { @@ -46,7 +46,7 @@ object PermissionHelper { return true } - fun isStoragePermissionGranted(activity: AppCompatActivity): Boolean { + fun isStoragePermissionGranted(activity: Activity): Boolean { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED diff --git a/app/src/main/java/com/github/libretube/util/ResettableLazy.kt b/app/src/main/java/com/github/libretube/util/ResettableLazy.kt index 432dff009..129e27de6 100644 --- a/app/src/main/java/com/github/libretube/util/ResettableLazy.kt +++ b/app/src/main/java/com/github/libretube/util/ResettableLazy.kt @@ -1,7 +1,7 @@ package com.github.libretube.util -import kotlin.reflect.KProperty import java.util.* +import kotlin.reflect.KProperty class ResettableLazyManager { // we synchronize to make sure the timing of a reset() call and new inits do not collide diff --git a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt index 4637f57ea..f3e48bba4 100644 --- a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt @@ -100,7 +100,7 @@ object ThemeHelper { fun restartMainActivity(context: Context) { // kill player notification val nManager = context - .getSystemService(AppCompatActivity.NOTIFICATION_SERVICE) as NotificationManager + .getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager nManager.cancelAll() // start a new Intent of the app val pm: PackageManager = context.packageManager diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6bfb73e3..f89599e88 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -289,7 +289,7 @@ No results. Error Copied - Downloaded + Download succeeded Share with start time Export Subscriptions