fix warnings

This commit is contained in:
Bnyro 2022-08-27 15:13:24 +02:00
parent 19cef57b8c
commit 771dee9b2e
39 changed files with 72 additions and 58 deletions

View File

@ -3,17 +3,16 @@ import java.time.Instant
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}
android {
compileSdk 31
compileSdk 33
defaultConfig {
applicationId 'com.github.libretube'
minSdk 21
targetSdk 31
targetSdk 33
versionCode 17
versionName '0.5.0'
multiDexEnabled true

View File

@ -123,6 +123,7 @@ class AboutActivity : BaseActivity() {
it?.readText()
}
@Suppress("DEPRECATION")
val licenseHtml = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(licenseString.toString(), 1)
} else {

View File

@ -205,7 +205,7 @@ class MainActivity : BaseActivity() {
/**
* Remove the focus of the search view in the toolbar
*/
fun removeSearchFocus() {
private fun removeSearchFocus() {
searchView.setQuery("", false)
searchView.clearFocus()
searchView.onActionViewCollapsed()
@ -250,13 +250,14 @@ class MainActivity : BaseActivity() {
searchItem.setOnActionExpandListener(
object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(p0: MenuItem?): Boolean {
override fun onMenuItemActionExpand(p0: MenuItem): Boolean {
return true
}
override fun onMenuItemActionCollapse(p0: MenuItem?): Boolean {
override fun onMenuItemActionCollapse(p0: MenuItem): Boolean {
val currentFragmentId = navController.currentDestination?.id
if (currentFragmentId == R.id.searchFragment || currentFragmentId == R.id.searchResultFragment) {
@Suppress("DEPRECATION")
onBackPressed()
}
return true
@ -443,6 +444,7 @@ class MainActivity : BaseActivity() {
}
}
} else if (navController.currentDestination?.id == startFragmentId) {
@Suppress("DEPRECATION")
super.onBackPressed()
} else {
navController.popBackStack()
@ -494,7 +496,7 @@ class MainActivity : BaseActivity() {
hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
} else {
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_FULLSCREEN
@ -528,7 +530,7 @@ class MainActivity : BaseActivity() {
show(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
systemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
} else {
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_VISIBLE or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
@ -554,7 +556,7 @@ class MainActivity : BaseActivity() {
/**
* show the status bar
*/
fun showSystemBars() {
private fun showSystemBars() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.show(WindowInsets.Type.statusBars())
} else {

View File

@ -31,6 +31,7 @@ class SettingsActivity : BaseActivity() {
override fun onBackPressed() {
when (supportFragmentManager.findFragmentById(R.id.settings)) {
is MainSettings -> {
@Suppress("DEPRECATION")
super.onBackPressed()
finishAndRemoveTask()
}

View File

@ -10,9 +10,9 @@ import com.github.libretube.dialogs.VideoOptionsDialog
import com.github.libretube.obj.StreamItem
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.formatShort
import com.github.libretube.util.setWatchProgressLength
import com.github.libretube.util.toID
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
class ChannelAdapter(
private val videoFeed: MutableList<StreamItem>,

View File

@ -15,7 +15,7 @@ import com.github.libretube.obj.Comment
import com.github.libretube.obj.CommentsPage
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.formatShort
import com.github.libretube.extensions.formatShort
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View File

@ -7,7 +7,7 @@ import com.github.libretube.databinding.LegacySubscriptionChannelBinding
import com.github.libretube.obj.Subscription
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.toID
import com.github.libretube.extensions.toID
class LegacySubscriptionAdapter(
private val subscriptions: List<Subscription>

View File

@ -17,8 +17,8 @@ import com.github.libretube.obj.StreamItem
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.setWatchProgressLength
import com.github.libretube.util.toID
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View File

@ -8,7 +8,7 @@ import com.github.libretube.databinding.RepliesRowBinding
import com.github.libretube.obj.Comment
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.formatShort
import com.github.libretube.extensions.formatShort
class RepliesAdapter(
private val replies: MutableList<Comment>

View File

@ -16,9 +16,9 @@ import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.obj.SearchItem
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.formatShort
import com.github.libretube.util.setWatchProgressLength
import com.github.libretube.util.toID
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View File

@ -9,7 +9,7 @@ import com.github.libretube.databinding.ChannelSubscriptionRowBinding
import com.github.libretube.obj.Subscription
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.toID
import com.github.libretube.extensions.toID
class SubscriptionChannelAdapter(private val subscriptions: MutableList<Subscription>) :
RecyclerView.Adapter<SubscriptionChannelViewHolder>() {

View File

@ -11,9 +11,9 @@ import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.obj.StreamItem
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.formatShort
import com.github.libretube.util.setWatchProgressLength
import com.github.libretube.util.toID
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.setWatchProgressLength
import com.github.libretube.extensions.toID
class TrendingAdapter(
private val streamItems: List<StreamItem>,

View File

@ -11,7 +11,7 @@ import com.github.libretube.dialogs.VideoOptionsDialog
import com.github.libretube.extensions.setFormattedDuration
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.setWatchProgressLength
import com.github.libretube.extensions.setWatchProgressLength
class WatchHistoryAdapter(
private val watchHistory: MutableList<WatchHistoryItem>,

View File

@ -1,4 +1,4 @@
package com.github.libretube.util
package com.github.libretube.api
import java.util.*
import kotlin.reflect.KProperty
@ -47,7 +47,7 @@ class ResettableLazy<PROPTYPE>(val manager: ResettableLazyManager, val init: ()
}
fun <PROPTYPE> resettableLazy(manager: ResettableLazyManager, init: () -> PROPTYPE):
ResettableLazy<PROPTYPE> {
ResettableLazy<PROPTYPE> {
return ResettableLazy(manager, init)
}

View File

@ -1,7 +1,5 @@
package com.github.libretube.api
import com.github.libretube.util.resettableLazy
import com.github.libretube.util.resettableManager
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory

View File

@ -6,7 +6,7 @@ import com.github.libretube.db.obj.WatchPosition
import com.github.libretube.obj.Streams
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.toID
import com.github.libretube.extensions.toID
object DatabaseHelper {
fun addToWatchHistory(videoId: String, streams: Streams) {

View File

@ -12,7 +12,7 @@ import com.github.libretube.extensions.TAG
import com.github.libretube.obj.PlaylistId
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.util.BackgroundHelper
import com.github.libretube.util.toID
import com.github.libretube.extensions.toID
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers

View File

@ -1,4 +1,4 @@
package com.github.libretube.util
package com.github.libretube.extensions
import java.math.BigDecimal
import java.math.RoundingMode

View File

@ -1,4 +1,4 @@
package com.github.libretube.util
package com.github.libretube.extensions
import android.app.Activity
import android.content.Context

View File

@ -1,4 +1,4 @@
package com.github.libretube.util
package com.github.libretube.extensions
import android.view.View
import android.view.ViewTreeObserver

View File

@ -1,4 +1,4 @@
package com.github.libretube.util
package com.github.libretube.extensions
/**
* format a Piped route to an ID

View File

@ -15,8 +15,8 @@ import com.github.libretube.databinding.FragmentChannelBinding
import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.formatShort
import com.github.libretube.util.toID
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID
import retrofit2.HttpException
import java.io.IOException

View File

@ -46,7 +46,7 @@ class HomeFragment : BaseFragment() {
resources.getInteger(R.integer.grid_items).toString()
)
val regionPref = PreferenceHelper.getString(PreferenceKeys.REGION, "sys")!!
val regionPref = PreferenceHelper.getString(PreferenceKeys.REGION, "sys")
// get the system default country if auto region selected
region = if (regionPref == "sys") {

View File

@ -72,9 +72,9 @@ import com.github.libretube.util.BackgroundHelper
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NowPlayingNotification
import com.github.libretube.util.PlayerHelper
import com.github.libretube.util.formatShort
import com.github.libretube.util.hideKeyboard
import com.github.libretube.util.toID
import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.hideKeyboard
import com.github.libretube.extensions.toID
import com.github.libretube.views.PlayerOptionsBottomSheet
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.DefaultLoadControl

View File

@ -16,7 +16,7 @@ import com.github.libretube.databinding.FragmentPlaylistBinding
import com.github.libretube.dialogs.PlaylistOptionsDialog
import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG
import com.github.libretube.util.toID
import com.github.libretube.extensions.toID
import retrofit2.HttpException
import java.io.IOException

View File

@ -20,11 +20,10 @@ import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.await
import com.github.libretube.models.SearchViewModel
import kotlinx.android.synthetic.main.activity_main.toolbar
import retrofit2.HttpException
import java.io.IOException
class SearchFragment() : BaseFragment() {
class SearchFragment : BaseFragment() {
private lateinit var binding: FragmentSearchBinding
private val viewModel: SearchViewModel by activityViewModels()
@ -117,7 +116,7 @@ class SearchFragment() : BaseFragment() {
if (findNavController().currentDestination?.id != R.id.searchResultFragment) {
// remove the search focus
(activity as MainActivity)
.toolbar.menu
.binding.toolbar.menu
.findItem(R.id.action_search).collapseActionView()
}
super.onStop()

View File

@ -17,10 +17,9 @@ import com.github.libretube.db.DatabaseHelper
import com.github.libretube.db.obj.SearchHistoryItem
import com.github.libretube.extensions.BaseFragment
import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.hideKeyboard
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.hideKeyboard
import kotlinx.android.synthetic.main.activity_main.toolbar
import retrofit2.HttpException
import java.io.IOException
@ -149,7 +148,7 @@ class SearchResultFragment : BaseFragment() {
if (findNavController().currentDestination?.id != R.id.searchFragment) {
// remove the search focus
(activity as MainActivity)
.toolbar.menu
.binding.toolbar.menu
.findItem(R.id.action_search).collapseActionView()
}
super.onStop()

View File

@ -9,7 +9,7 @@ import com.github.libretube.extensions.TAG
import com.github.libretube.obj.StreamItem
import com.github.libretube.obj.Subscription
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.util.toID
import com.github.libretube.extensions.toID
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View File

@ -4,6 +4,7 @@ import android.net.Uri
import android.os.Bundle
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument
import androidx.preference.ListPreference
import androidx.preference.Preference
import com.github.libretube.R
@ -29,7 +30,7 @@ class AdvancedSettings : MaterialPreferenceFragment() {
BackupHelper(requireContext()).restoreSharedPreferences(uri)
}
createFile = registerForActivityResult(
ActivityResultContracts.CreateDocument()
CreateDocument("application/json")
) { uri: Uri? ->
BackupHelper(requireContext()).backupSharedPreferences(uri)
}

View File

@ -5,6 +5,7 @@ import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.preference.ListPreference
@ -40,7 +41,7 @@ class InstanceSettings : MaterialPreferenceFragment() {
ImportHelper(requireActivity()).importSubscriptions(uri)
}
createFile = registerForActivityResult(
ActivityResultContracts.CreateDocument()
CreateDocument("application/json")
) { uri: Uri? ->
ImportHelper(requireActivity()).exportSubscriptions(uri)
}

View File

@ -16,6 +16,7 @@ import com.github.libretube.Globals
import com.github.libretube.PLAYER_NOTIFICATION_ID
import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.extensions.toID
import com.github.libretube.obj.Segment
import com.github.libretube.obj.Segments
import com.github.libretube.obj.Streams
@ -24,7 +25,6 @@ import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.AutoPlayHelper
import com.github.libretube.util.NowPlayingNotification
import com.github.libretube.util.PlayerHelper
import com.github.libretube.util.toID
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
@ -130,8 +130,7 @@ class BackgroundMode : Service() {
// play the audio in the background
playAudio(videoId, position)
} catch (e: Exception) {
stopForeground(true)
stopSelf()
onDestroy()
}
return super.onStartCommand(intent, flags, startId)
}
@ -209,6 +208,8 @@ class BackgroundMode : Service() {
Player.STATE_IDLE -> {
onDestroy()
}
Player.STATE_BUFFERING -> {}
Player.STATE_READY -> {}
}
}
})
@ -309,7 +310,12 @@ class BackgroundMode : Service() {
override fun onDestroy() {
// called when the user pressed stop in the notification
// stop the service from being in the foreground and remove the notification
stopForeground(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
stopForeground(STOP_FOREGROUND_REMOVE)
} else {
@Suppress("DEPRECATION")
stopForeground(true)
}
// destroy the service
stopSelf()
if (this::nowPlayingNotification.isInitialized) nowPlayingNotification.destroy()

View File

@ -2,6 +2,7 @@ package com.github.libretube.util
import com.github.libretube.Globals
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.extensions.toID
import com.github.libretube.obj.StreamItem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

View File

@ -13,7 +13,7 @@ object LocaleHelper {
val languageName = PreferenceHelper.getString(PreferenceKeys.LANGUAGE, "sys")
if (languageName == "sys") {
updateLocaleConf(context, Locale.getDefault())
} else if (languageName?.contains("-") == true) {
} else if (languageName.contains("-") == true) {
val languageParts = languageName.split("-")
val locale = Locale(
languageParts[0],

View File

@ -7,6 +7,7 @@ import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.os.bundleOf
import com.github.libretube.R
import com.github.libretube.activities.MainActivity
import com.github.libretube.extensions.toID
import com.github.libretube.fragments.PlayerFragment
object NavigationHelper {

View File

@ -17,6 +17,7 @@ import com.github.libretube.R
import com.github.libretube.activities.MainActivity
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.extensions.toID
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import kotlinx.coroutines.async

View File

@ -26,6 +26,6 @@ class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) :
}
init {
mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
mTouchSlop = ViewConfiguration.get(this.context).scaledTouchSlop
}
}

View File

@ -1,5 +1,6 @@
package com.github.libretube.views
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
@ -89,13 +90,14 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS
private val gestureDetector = GestureDetector(
context,
object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
transitionToEnd()
return false
}
}
)
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
// gestureDetector.onTouchEvent(event)
when (event.actionMasked) {

View File

@ -2,5 +2,6 @@
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
<!--suppress AndroidElementNotAllowed -->
<monochrome android:drawable="@drawable/ic_launcher_monochrome" />
</adaptive-icon>

View File

@ -2,5 +2,6 @@
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background" />
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
<!--suppress AndroidElementNotAllowed -->
<monochrome android:drawable="@drawable/ic_launcher_monochrome" />
</adaptive-icon>