diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/AboutDialogFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/AboutDialogFragment.kt index 4958ffc3..dceb984c 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/AboutDialogFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/AboutDialogFragment.kt @@ -11,6 +11,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.transport.backup.PackageService @@ -41,12 +42,11 @@ class AboutDialogFragment : Fragment() { contributorsView.movementMethod = linkMovementMethod orgsView.movementMethod = linkMovementMethod + v.requireViewById(R.id.toolbar).setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + return v } - override fun onStart() { - super.onStart() - activity?.setTitle(R.string.about_title) - } - } diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt index 25c5aad1..dc91cb96 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/AppStatusFragment.kt @@ -7,14 +7,13 @@ package com.stevesoltys.seedvault.settings import android.os.Bundle import android.view.LayoutInflater -import android.view.Menu -import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.View.INVISIBLE import android.view.View.VISIBLE import android.view.ViewGroup import android.widget.ProgressBar +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -32,7 +31,6 @@ class AppStatusFragment : Fragment(), AppStatusToggleListener { private val layoutManager = LinearLayoutManager(context) private val adapter = AppStatusAdapter(this) - private lateinit var appEditMenuItem: MenuItem private lateinit var list: RecyclerView private lateinit var progressBar: ProgressBar @@ -41,7 +39,6 @@ class AppStatusFragment : Fragment(), AppStatusToggleListener { container: ViewGroup?, savedInstanceState: Bundle?, ): View { - setHasOptionsMenu(true) val v: View = inflater.inflate(R.layout.fragment_app_status, container, false) progressBar = v.requireViewById(R.id.progressBar) @@ -53,7 +50,17 @@ class AppStatusFragment : Fragment(), AppStatusToggleListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - activity?.setTitle(R.string.settings_backup_status_title) + val toolbar = view.requireViewById(R.id.toolbar).apply { + setOnMenuItemClickListener(::onMenuItemSelected) + setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } + + viewModel.appEditMode.observe(viewLifecycleOwner) { enabled -> + toolbar.menu.findItem(R.id.edit_app_blacklist)?.isChecked = enabled + adapter.setEditMode(enabled) + } list.apply { layoutManager = this@AppStatusFragment.layoutManager @@ -67,24 +74,12 @@ class AppStatusFragment : Fragment(), AppStatusToggleListener { } } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.app_status_menu, menu) - appEditMenuItem = menu.findItem(R.id.edit_app_blacklist) - - // observe edit mode changes here where we are sure to have the MenuItem - viewModel.appEditMode.observe(viewLifecycleOwner) { enabled -> - appEditMenuItem.isChecked = enabled - adapter.setEditMode(enabled) - } - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { + private fun onMenuItemSelected(item: MenuItem): Boolean = when (item.itemId) { R.id.edit_app_blacklist -> { viewModel.setEditMode(!item.isChecked) true } - else -> super.onOptionsItemSelected(item) + else -> false } override fun onAppStatusToggled(status: AppStatus) { diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt index 0d1097ba..8a3f1de7 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/ExpertSettingsFragment.kt @@ -7,7 +7,9 @@ package com.stevesoltys.seedvault.settings import android.app.backup.IBackupManager import android.os.Bundle +import android.view.View import androidx.activity.result.contract.ActivityResultContracts.CreateDocument +import androidx.appcompat.widget.Toolbar import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceChangeListener import androidx.preference.PreferenceFragmentCompat @@ -66,9 +68,19 @@ class ExpertSettingsFragment : PreferenceFragmentCompat() { } } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + view.requireViewById(R.id.toolbar).apply { + title = getString(R.string.settings_expert_title) + setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } + } + override fun onStart() { super.onStart() - activity?.setTitle(R.string.settings_expert_title) apkBackup.isEnabled = backupManager.isBackupEnabled } } diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt index d36f3522..e30556e6 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SchedulingFragment.kt @@ -8,6 +8,7 @@ package com.stevesoltys.seedvault.settings import android.content.SharedPreferences import android.os.Bundle import android.view.View +import androidx.appcompat.widget.Toolbar import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceCategory @@ -39,6 +40,13 @@ class SchedulingFragment : PreferenceFragmentCompat(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + view.requireViewById(R.id.toolbar).apply { + title = getString(R.string.settings_backup_scheduling_title) + setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } + val storage = backendManager.backendProperties if (storage?.isUsb == true) { findPreference("scheduling_category_conditions")?.isEnabled = false @@ -60,12 +68,6 @@ class SchedulingFragment : PreferenceFragmentCompat(), } } - override fun onStart() { - super.onStart() - - activity?.setTitle(R.string.settings_backup_scheduling_title) - } - override fun onResume() { super.onResume() settingsManager.registerOnSharedPreferenceChangeListener(this) diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt index 976cb364..9bd00319 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt @@ -30,9 +30,6 @@ class SettingsActivity : RequireProvisioningActivity(), OnPreferenceStartFragmen setContentView(R.layout.activity_fragment_container) - setSupportActionBar(requireViewById(R.id.toolbar)) - supportActionBar!!.setDisplayHomeAsUpEnabled(true) - if (savedInstanceState == null && viewModel.isFirstStart) { // let user choose whether to restore on first start FirstRunFragment().show(supportFragmentManager, null) diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt index 3d85f58e..c33a47d3 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt @@ -11,12 +11,11 @@ import android.os.Bundle import android.os.PowerManager import android.os.RemoteException import android.util.Log -import android.view.Menu -import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.widget.Toast import android.widget.Toast.LENGTH_LONG +import androidx.appcompat.widget.Toolbar import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceChangeListener import androidx.preference.PreferenceFragmentCompat @@ -53,9 +52,6 @@ class SettingsFragment : PreferenceFragmentCompat() { private lateinit var backupStorage: TwoStatePreference private lateinit var backupRecoveryCode: Preference - private var menuBackupNow: MenuItem? = null - private var menuRestore: MenuItem? = null - private val backendProperties: BackendProperties<*>? get() = backendManager.backendProperties @@ -63,7 +59,6 @@ class SettingsFragment : PreferenceFragmentCompat() { permitDiskReads { setPreferencesFromResource(R.xml.settings, rootKey) } - setHasOptionsMenu(true) backup = findPreference("backup")!! backup.onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue -> @@ -141,6 +136,20 @@ class SettingsFragment : PreferenceFragmentCompat() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val toolbar = view.requireViewById(R.id.toolbar).apply { + title = getString(R.string.backup) + inflateMenu(R.menu.settings_menu) + setOnMenuItemClickListener(::onMenuItemSelected) + setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } + + viewModel.backupPossible.observe(viewLifecycleOwner) { possible -> + toolbar.menu.findItem(R.id.action_backup)?.isEnabled = possible + toolbar.menu.findItem(R.id.action_restore)?.isEnabled = possible + } + viewModel.lastBackupTime.observe(viewLifecycleOwner) { time -> setAppBackupStatusSummary(time) } @@ -157,9 +166,6 @@ class SettingsFragment : PreferenceFragmentCompat() { override fun onStart() { super.onStart() - // we need to re-set the title when returning to this fragment - activity?.setTitle(R.string.backup) - setBackupEnabledState() setBackupLocationSummary() setAutoRestoreState() @@ -185,18 +191,7 @@ class SettingsFragment : PreferenceFragmentCompat() { } } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.settings_menu, menu) - menuBackupNow = menu.findItem(R.id.action_backup) - menuRestore = menu.findItem(R.id.action_restore) - viewModel.backupPossible.observe(viewLifecycleOwner) { possible -> - menuBackupNow?.isEnabled = possible - menuRestore?.isEnabled = possible - } - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { + private fun onMenuItemSelected(item: MenuItem): Boolean = when (item.itemId) { R.id.action_backup -> { viewModel.backupNow() true @@ -219,7 +214,7 @@ class SettingsFragment : PreferenceFragmentCompat() { .commit() true } - else -> super.onOptionsItemSelected(item) + else -> false } private fun trySetBackupEnabled(enabled: Boolean): Boolean { diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/BackupActivity.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/BackupActivity.kt index 286c1167..af347d35 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/BackupActivity.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/BackupActivity.kt @@ -6,8 +6,6 @@ package com.stevesoltys.seedvault.ui import android.os.Bundle -import android.view.MenuItem -import androidx.annotation.CallSuper import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import com.stevesoltys.seedvault.R @@ -19,15 +17,6 @@ abstract class BackupActivity : AppCompatActivity() { super.onCreate(savedInstanceState) } - @CallSuper - override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { - android.R.id.home -> { - onBackPressed() - true - } - else -> super.onOptionsItemSelected(item) - } - protected fun showFragment(f: Fragment, addToBackStack: Boolean = false, tag: String? = null) { supportFragmentManager.beginTransaction().apply { replace(R.id.fragment, f, tag) diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/files/FileSelectionFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/files/FileSelectionFragment.kt index 3934cdde..1a659b58 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/files/FileSelectionFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/files/FileSelectionFragment.kt @@ -6,9 +6,8 @@ package com.stevesoltys.seedvault.ui.files import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.settings.SettingsViewModel import org.calyxos.backup.storage.ui.backup.BackupContentFragment @@ -20,13 +19,15 @@ class FileSelectionFragment : BackupContentFragment() { override val viewModel by viewModel() private val settingsViewModel by sharedViewModel() - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - requireActivity().setTitle(R.string.settings_backup_files_title) - return super.onCreateView(inflater, container, savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + view.requireViewById(R.id.toolbar).apply { + title = getString(R.string.settings_backup_files_title) + setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } } override fun onDestroy() { diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeActivity.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeActivity.kt index c4f34435..de15f257 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeActivity.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeActivity.kt @@ -6,7 +6,6 @@ package com.stevesoltys.seedvault.ui.recoverycode import android.os.Bundle -import android.view.MenuItem import android.view.WindowManager.LayoutParams.FLAG_SECURE import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.isDebugBuild @@ -42,16 +41,6 @@ class RecoveryCodeActivity : BackupActivity() { } } - override fun onOptionsItemSelected(item: MenuItem): Boolean { - return when (item.itemId) { - android.R.id.home -> { - onBackPressed() - true - } - else -> super.onOptionsItemSelected(item) - } - } - private fun showOutput() { supportFragmentManager.beginTransaction() .add(R.id.fragment, RecoveryCodeOutputFragment(), "Code") diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeInputFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeInputFragment.kt index 6cd76ba5..bfa8db60 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeInputFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeInputFragment.kt @@ -26,6 +26,7 @@ import android.widget.TextView import android.widget.Toast import android.widget.Toast.LENGTH_LONG import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult +import androidx.appcompat.widget.Toolbar import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat.getMainExecutor import androidx.fragment.app.Fragment @@ -105,7 +106,11 @@ class RecoveryCodeInputFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - activity?.setTitle(R.string.recovery_code_title) + view.requireViewById(R.id.toolbar).apply { + setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } if (viewModel.isRestore) { introText.setText(R.string.recovery_code_input_intro) diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeOutputFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeOutputFragment.kt index a17b3582..9c8263ce 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeOutputFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/recoverycode/RecoveryCodeOutputFragment.kt @@ -12,6 +12,7 @@ import android.view.View import android.view.ViewGroup import android.view.WindowManager.LayoutParams.FLAG_SECURE import android.widget.Button +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -44,6 +45,12 @@ class RecoveryCodeOutputFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + view.requireViewById(R.id.toolbar).apply { + setNavigationOnClickListener { + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } + setGridParameters(wordList) wordList.adapter = RecoveryCodeAdapter(viewModel.wordList) diff --git a/app/src/main/res/layout/activity_fragment_container.xml b/app/src/main/res/layout/activity_fragment_container.xml index a688348d..69068728 100644 --- a/app/src/main/res/layout/activity_fragment_container.xml +++ b/app/src/main/res/layout/activity_fragment_container.xml @@ -8,13 +8,6 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - + android:layout_height="match_parent" + android:orientation="vertical"> - + android:layout_height="wrap_content" + android:minHeight="?attr/actionBarSize" + android:theme="?attr/actionBarTheme" + app:navigationIcon="?attr/homeAsUpIndicator" + app:title="@string/about_title" /> - + - + - + - + - + - + - + - + - + - - + + + + + + + diff --git a/app/src/main/res/layout/fragment_app_status.xml b/app/src/main/res/layout/fragment_app_status.xml index adc968ea..35ff3011 100644 --- a/app/src/main/res/layout/fragment_app_status.xml +++ b/app/src/main/res/layout/fragment_app_status.xml @@ -8,6 +8,18 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + app:layout_constraintTop_toBottomOf="@id/toolbar" /> - + android:orientation="vertical"> - + android:minHeight="?attr/actionBarSize" + android:theme="?attr/actionBarTheme" + app:navigationIcon="?attr/homeAsUpIndicator" + app:title="@string/recovery_code_title" /> - - - - - + + tools:context=".ui.recoverycode.RecoveryCodeInputFragment"> - + + + + + + + + + + + + +