mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
cleanup
This commit is contained in:
parent
6da00f912e
commit
7eb83716c5
@ -89,77 +89,79 @@ class MainActivity : BaseActivity() {
|
|||||||
if (!ConnectionHelper.isNetworkAvailable(this)) {
|
if (!ConnectionHelper.isNetworkAvailable(this)) {
|
||||||
val noInternetIntent = Intent(this, NoInternetActivity::class.java)
|
val noInternetIntent = Intent(this, NoInternetActivity::class.java)
|
||||||
startActivity(noInternetIntent)
|
startActivity(noInternetIntent)
|
||||||
} else {
|
finish()
|
||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
return
|
||||||
setContentView(binding.root)
|
|
||||||
|
|
||||||
// set the action bar for the activity
|
|
||||||
setSupportActionBar(binding.toolbar)
|
|
||||||
|
|
||||||
navController = findNavController(R.id.fragment)
|
|
||||||
binding.bottomNav.setupWithNavController(navController)
|
|
||||||
|
|
||||||
// gets the surface color of the bottom navigation view
|
|
||||||
val color = SurfaceColors.getColorForElevation(this, 10F)
|
|
||||||
|
|
||||||
// sets the navigation bar color to the previously calculated color
|
|
||||||
window.navigationBarColor = color
|
|
||||||
|
|
||||||
// hide the trending page if enabled
|
|
||||||
val hideTrendingPage =
|
|
||||||
PreferenceHelper.getBoolean(PreferenceKeys.HIDE_TRENDING_PAGE, false)
|
|
||||||
if (hideTrendingPage) binding.bottomNav.menu.findItem(R.id.homeFragment).isVisible =
|
|
||||||
false
|
|
||||||
|
|
||||||
// save start tab fragment id
|
|
||||||
startFragmentId =
|
|
||||||
when (PreferenceHelper.getString(PreferenceKeys.DEFAULT_TAB, "home")) {
|
|
||||||
"home" -> R.id.homeFragment
|
|
||||||
"subscriptions" -> R.id.subscriptionsFragment
|
|
||||||
"library" -> R.id.libraryFragment
|
|
||||||
else -> R.id.homeFragment
|
|
||||||
}
|
|
||||||
|
|
||||||
// set default tab as start fragment
|
|
||||||
navController.graph.setStartDestination(startFragmentId)
|
|
||||||
|
|
||||||
// navigate to the default fragment
|
|
||||||
navController.navigate(startFragmentId)
|
|
||||||
|
|
||||||
val labelVisibilityMode = when (
|
|
||||||
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "always")
|
|
||||||
) {
|
|
||||||
"always" -> NavigationBarView.LABEL_VISIBILITY_LABELED
|
|
||||||
"selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED
|
|
||||||
"never" -> NavigationBarView.LABEL_VISIBILITY_UNLABELED
|
|
||||||
else -> NavigationBarView.LABEL_VISIBILITY_AUTO
|
|
||||||
}
|
|
||||||
binding.bottomNav.labelVisibilityMode = labelVisibilityMode
|
|
||||||
|
|
||||||
binding.bottomNav.setOnApplyWindowInsetsListener(null)
|
|
||||||
|
|
||||||
binding.bottomNav.setOnItemSelectedListener {
|
|
||||||
// clear backstack if it's the start fragment
|
|
||||||
if (startFragmentId == it.itemId) navController.backQueue.clear()
|
|
||||||
// set menu item on click listeners
|
|
||||||
removeSearchFocus()
|
|
||||||
when (it.itemId) {
|
|
||||||
R.id.homeFragment -> {
|
|
||||||
navController.navigate(R.id.homeFragment)
|
|
||||||
}
|
|
||||||
R.id.subscriptionsFragment -> {
|
|
||||||
navController.navigate(R.id.subscriptionsFragment)
|
|
||||||
}
|
|
||||||
R.id.libraryFragment -> {
|
|
||||||
navController.navigate(R.id.libraryFragment)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.toolbar.title = ThemeHelper.getStyledAppName(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
// set the action bar for the activity
|
||||||
|
setSupportActionBar(binding.toolbar)
|
||||||
|
|
||||||
|
navController = findNavController(R.id.fragment)
|
||||||
|
binding.bottomNav.setupWithNavController(navController)
|
||||||
|
|
||||||
|
// gets the surface color of the bottom navigation view
|
||||||
|
val color = SurfaceColors.getColorForElevation(this, 10F)
|
||||||
|
|
||||||
|
// sets the navigation bar color to the previously calculated color
|
||||||
|
window.navigationBarColor = color
|
||||||
|
|
||||||
|
// hide the trending page if enabled
|
||||||
|
val hideTrendingPage =
|
||||||
|
PreferenceHelper.getBoolean(PreferenceKeys.HIDE_TRENDING_PAGE, false)
|
||||||
|
if (hideTrendingPage) binding.bottomNav.menu.findItem(R.id.homeFragment).isVisible =
|
||||||
|
false
|
||||||
|
|
||||||
|
// save start tab fragment id
|
||||||
|
startFragmentId =
|
||||||
|
when (PreferenceHelper.getString(PreferenceKeys.DEFAULT_TAB, "home")) {
|
||||||
|
"home" -> R.id.homeFragment
|
||||||
|
"subscriptions" -> R.id.subscriptionsFragment
|
||||||
|
"library" -> R.id.libraryFragment
|
||||||
|
else -> R.id.homeFragment
|
||||||
|
}
|
||||||
|
|
||||||
|
// set default tab as start fragment
|
||||||
|
navController.graph.setStartDestination(startFragmentId)
|
||||||
|
|
||||||
|
// navigate to the default fragment
|
||||||
|
navController.navigate(startFragmentId)
|
||||||
|
|
||||||
|
val labelVisibilityMode = when (
|
||||||
|
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "always")
|
||||||
|
) {
|
||||||
|
"always" -> NavigationBarView.LABEL_VISIBILITY_LABELED
|
||||||
|
"selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED
|
||||||
|
"never" -> NavigationBarView.LABEL_VISIBILITY_UNLABELED
|
||||||
|
else -> NavigationBarView.LABEL_VISIBILITY_AUTO
|
||||||
|
}
|
||||||
|
binding.bottomNav.labelVisibilityMode = labelVisibilityMode
|
||||||
|
|
||||||
|
binding.bottomNav.setOnApplyWindowInsetsListener(null)
|
||||||
|
|
||||||
|
binding.bottomNav.setOnItemSelectedListener {
|
||||||
|
// clear backstack if it's the start fragment
|
||||||
|
if (startFragmentId == it.itemId) navController.backQueue.clear()
|
||||||
|
// set menu item on click listeners
|
||||||
|
removeSearchFocus()
|
||||||
|
when (it.itemId) {
|
||||||
|
R.id.homeFragment -> {
|
||||||
|
navController.navigate(R.id.homeFragment)
|
||||||
|
}
|
||||||
|
R.id.subscriptionsFragment -> {
|
||||||
|
navController.navigate(R.id.subscriptionsFragment)
|
||||||
|
}
|
||||||
|
R.id.libraryFragment -> {
|
||||||
|
navController.navigate(R.id.libraryFragment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.toolbar.title = ThemeHelper.getStyledAppName(this)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handle error logs
|
* handle error logs
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,8 @@ package com.github.libretube.database
|
|||||||
import com.github.libretube.obj.Streams
|
import com.github.libretube.obj.Streams
|
||||||
import com.github.libretube.obj.WatchHistoryItem
|
import com.github.libretube.obj.WatchHistoryItem
|
||||||
import com.github.libretube.obj.WatchPosition
|
import com.github.libretube.obj.WatchPosition
|
||||||
|
import com.github.libretube.preferences.PreferenceHelper
|
||||||
|
import com.github.libretube.preferences.PreferenceKeys
|
||||||
import com.github.libretube.util.toID
|
import com.github.libretube.util.toID
|
||||||
|
|
||||||
object DatabaseHelper {
|
object DatabaseHelper {
|
||||||
@ -19,6 +21,15 @@ object DatabaseHelper {
|
|||||||
)
|
)
|
||||||
Thread {
|
Thread {
|
||||||
DatabaseHolder.database.watchHistoryDao().insertAll(watchHistoryItem)
|
DatabaseHolder.database.watchHistoryDao().insertAll(watchHistoryItem)
|
||||||
|
val maxHistorySize = PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "unlimited")
|
||||||
|
if (maxHistorySize == "unlimited") return@Thread
|
||||||
|
|
||||||
|
// delete the first watch history entry if the limit is reached
|
||||||
|
val watchHistory = DatabaseHolder.database.watchHistoryDao().getAll()
|
||||||
|
if (watchHistory.size > maxHistorySize.toInt()) {
|
||||||
|
DatabaseHolder.database.watchHistoryDao()
|
||||||
|
.delete(watchHistory.first())
|
||||||
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user