mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
commit
2713935438
@ -106,20 +106,15 @@ class MainActivity : BaseActivity() {
|
||||
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 -> {
|
||||
binding.bottomNav.removeBadge(R.id.subscriptionsFragment)
|
||||
navController.navigate(R.id.subscriptionsFragment)
|
||||
}
|
||||
R.id.libraryFragment -> {
|
||||
navController.navigate(R.id.libraryFragment)
|
||||
}
|
||||
|
||||
if (it.itemId == R.id.subscriptionsFragment) {
|
||||
binding.bottomNav.removeBadge(R.id.subscriptionsFragment)
|
||||
}
|
||||
|
||||
removeSearchFocus()
|
||||
|
||||
// navigate to the selected fragment
|
||||
navController.navigate(it.itemId)
|
||||
false
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ import com.github.libretube.R
|
||||
import com.github.libretube.databinding.ActivityNointernetBinding
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.ui.fragments.DownloadsFragment
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
import com.github.libretube.util.NetworkHelper
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
|
||||
class NoInternetActivity : BaseActivity() {
|
||||
@ -21,7 +21,7 @@ class NoInternetActivity : BaseActivity() {
|
||||
// retry button
|
||||
binding.retryButton.setOnClickListener {
|
||||
if (NetworkHelper.isNetworkAvailable(this)) {
|
||||
ThemeHelper.restartMainActivity(this)
|
||||
NavigationHelper.restartMainActivity(this)
|
||||
} else {
|
||||
Snackbar.make(binding.root, R.string.turnInternetOn, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
|
||||
class RouterActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -23,7 +23,7 @@ class RouterActivity : BaseActivity() {
|
||||
handleSendText(uri!!)
|
||||
} else {
|
||||
// start app as normal if URI not in host list
|
||||
ThemeHelper.restartMainActivity(this)
|
||||
NavigationHelper.restartMainActivity(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class RequireRestartDialog : DialogFragment() {
|
||||
@ -15,7 +15,7 @@ class RequireRestartDialog : DialogFragment() {
|
||||
.setMessage(R.string.require_restart_message)
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
activity?.recreate()
|
||||
ThemeHelper.restartMainActivity(requireContext())
|
||||
NavigationHelper.restartMainActivity(requireContext())
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
|
@ -12,6 +12,7 @@ import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.ui.activities.SettingsActivity
|
||||
import com.github.libretube.ui.base.BasePreferenceFragment
|
||||
import com.github.libretube.ui.dialogs.NavBarOptionsDialog
|
||||
import com.github.libretube.ui.dialogs.RequireRestartDialog
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
@ -59,6 +60,15 @@ class AppearanceSettings : BasePreferenceFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
val navBarOptions = findPreference<Preference>(PreferenceKeys.NAVBAR_ITEMS)
|
||||
navBarOptions?.setOnPreferenceClickListener {
|
||||
NavBarOptionsDialog().show(
|
||||
childFragmentManager,
|
||||
null
|
||||
)
|
||||
true
|
||||
}
|
||||
|
||||
val systemCaptionStyle =
|
||||
findPreference<SwitchPreferenceCompat>(PreferenceKeys.SYSTEM_CAPTION_STYLE)
|
||||
val captionSettings = findPreference<Preference>(PreferenceKeys.CAPTION_SETTINGS)
|
||||
|
@ -39,15 +39,6 @@ class GeneralSettings : BasePreferenceFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
val navBarOptions = findPreference<Preference>(PreferenceKeys.NAVBAR_ITEMS)
|
||||
navBarOptions?.setOnPreferenceClickListener {
|
||||
NavBarOptionsDialog().show(
|
||||
childFragmentManager,
|
||||
null
|
||||
)
|
||||
true
|
||||
}
|
||||
|
||||
val breakReminder =
|
||||
findPreference<SwitchPreferenceCompat>(PreferenceKeys.BREAK_REMINDER_TOGGLE)
|
||||
val breakReminderTime = findPreference<EditTextPreference>(PreferenceKeys.BREAK_REMINDER)
|
||||
|
@ -37,7 +37,8 @@ object NavBarHelper {
|
||||
defaultNavBarItems.add(
|
||||
NavBarItem(
|
||||
it.itemId,
|
||||
it.title.toString()
|
||||
it.title.toString(),
|
||||
it.isEnabled
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -90,6 +91,6 @@ object NavBarHelper {
|
||||
).icon = menuItem.icon
|
||||
}
|
||||
}
|
||||
return navBarItems[0].id
|
||||
return navBarItems.filter { it.isEnabled }[0].id
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.os.bundleOf
|
||||
@ -66,4 +69,21 @@ object NavigationHelper {
|
||||
activity.navController.navigate(R.id.playlistFragment, bundle)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Needed due to different MainActivity Aliases because of the app icons
|
||||
*/
|
||||
fun restartMainActivity(context: Context) {
|
||||
// kill player notification
|
||||
val nManager = context
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
nManager.cancelAll()
|
||||
// start a new Intent of the app
|
||||
val pm: PackageManager = context.packageManager
|
||||
val intent = pm.getLaunchIntentForPackage(context.packageName)
|
||||
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
context.startActivity(intent)
|
||||
// kill the old application
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.NotificationManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.text.Spanned
|
||||
import android.util.TypedValue
|
||||
@ -128,23 +126,6 @@ object ThemeHelper {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Needed due to different MainActivity Aliases because of the app icons
|
||||
*/
|
||||
fun restartMainActivity(context: Context) {
|
||||
// kill player notification
|
||||
val nManager = context
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
nManager.cancelAll()
|
||||
// start a new Intent of the app
|
||||
val pm: PackageManager = context.packageManager
|
||||
val intent = pm.getLaunchIntentForPackage(context.packageName)
|
||||
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
context.startActivity(intent)
|
||||
// kill the old application
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a color by a resource code
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp">
|
||||
android:paddingTop="20dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/options_recycler"
|
||||
|
@ -5,13 +5,27 @@
|
||||
android:id="@+id/homeFragment"
|
||||
android:icon="@drawable/ic_home"
|
||||
android:title="@string/startpage" />
|
||||
|
||||
<item
|
||||
android:id="@+id/subscriptionsFragment"
|
||||
android:icon="@drawable/ic_subscriptions"
|
||||
android:title="@string/subscriptions" />
|
||||
|
||||
<item
|
||||
android:id="@+id/libraryFragment"
|
||||
android:icon="@drawable/ic_library"
|
||||
android:title="@string/library" />
|
||||
|
||||
<item
|
||||
android:id="@+id/downloadsFragment"
|
||||
android:icon="@drawable/ic_download_filled"
|
||||
android:title="@string/downloads"
|
||||
android:enabled="false" />
|
||||
|
||||
<item
|
||||
android:id="@+id/watchHistoryFragment"
|
||||
android:icon="@drawable/ic_history_filled"
|
||||
android:title="@string/history"
|
||||
android:enabled="false" />
|
||||
|
||||
</menu>
|
@ -38,6 +38,12 @@
|
||||
app:title="@string/app_icon"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_home"
|
||||
app:key="nav_bar_items"
|
||||
app:title="@string/navigation_bar" />
|
||||
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/app_behavior">
|
||||
|
@ -38,15 +38,6 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/behavior">
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_home"
|
||||
app:key="nav_bar_items"
|
||||
app:title="@string/navigation_bar" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory app:title="@string/misc">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
|
Loading…
x
Reference in New Issue
Block a user