diff --git a/app/src/main/java/com/topjohnwu/magisk/arch/BaseFragment.kt b/app/src/main/java/com/topjohnwu/magisk/arch/BaseFragment.kt index 9a6b6a59d..7a8ff6cae 100644 --- a/app/src/main/java/com/topjohnwu/magisk/arch/BaseFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/arch/BaseFragment.kt @@ -15,11 +15,11 @@ import com.topjohnwu.magisk.ktx.startAnimations abstract class BaseFragment : Fragment(), ViewModelHolder { - val activity get() = requireActivity() as NavigationActivity<*> + val activity get() = getActivity() as? NavigationActivity<*> protected lateinit var binding: Binding protected abstract val layoutRes: Int - private val navigation get() = activity.navigation + private val navigation get() = activity?.navigation open val snackbarAnchorView: View? get() = null override fun onCreate(savedInstanceState: Bundle?) { @@ -41,12 +41,12 @@ abstract class BaseFragment : Fragment(), ViewModelHo override fun onStart() { super.onStart() - activity.supportActionBar?.subtitle = null + activity?.supportActionBar?.subtitle = null } override fun onEventDispatched(event: ViewEvent) = when(event) { is ContextExecutor -> event(requireContext()) - is ActivityExecutor -> event(activity) + is ActivityExecutor -> activity?.let { event(it) } ?: Unit is FragmentExecutor -> event(this) else -> Unit } diff --git a/app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt b/app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt index 22f227d78..247c644e2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/ViewEvents.kt @@ -83,7 +83,7 @@ class SelectModuleEvent : ViewEvent(), FragmentExecutor { override fun invoke(fragment: BaseFragment<*>) { try { fragment.apply { - activity.getContent("application/zip") { + activity?.getContent("application/zip") { MainDirections.actionFlashFragment(Const.Value.FLASH_ZIP, it).navigate() } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListFragment.kt index 1b9698242..69099ce2a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/deny/DenyListFragment.kt @@ -26,7 +26,7 @@ class DenyListFragment : BaseFragment() { override fun onAttach(context: Context) { super.onAttach(context) - activity.setTitle(R.string.denylist) + activity?.setTitle(R.string.denylist) setHasOptionsMenu(true) } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt index 793e1fb02..f6e57822f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt @@ -31,10 +31,10 @@ class FlashFragment : BaseFragment() { override fun onStart() { super.onStart() setHasOptionsMenu(true) - activity.setTitle(R.string.flash_screen_title) + activity?.setTitle(R.string.flash_screen_title) viewModel.subtitle.observe(this) { - activity.supportActionBar?.setSubtitle(it) + activity?.supportActionBar?.setSubtitle(it) } } @@ -49,15 +49,15 @@ class FlashFragment : BaseFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - defaultOrientation = activity.requestedOrientation - activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR + defaultOrientation = activity?.requestedOrientation ?: -1 + activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR viewModel.startFlashing() } @SuppressLint("WrongConstant") override fun onDestroyView() { if (defaultOrientation != -1) { - activity.requestedOrientation = defaultOrientation + activity?.requestedOrientation = defaultOrientation } super.onDestroyView() } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt index 8fc5fc22f..21e8ff130 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeFragment.kt @@ -19,7 +19,7 @@ class HomeFragment : BaseFragment() { override fun onStart() { super.onStart() - activity.title = resources.getString(R.string.section_home) + activity?.title = resources.getString(R.string.section_home) setHasOptionsMenu(true) DownloadService.observeProgress(this, viewModel::onProgressUpdate) } @@ -64,7 +64,7 @@ class HomeFragment : BaseFragment() { when (item.itemId) { R.id.action_settings -> HomeFragmentDirections.actionHomeFragmentToSettingsFragment().navigate() - R.id.action_reboot -> RebootEvent.inflateMenu(activity).show() + R.id.action_reboot -> activity?.let { RebootEvent.inflateMenu(it).show() } else -> return super.onOptionsItemSelected(item) } return true diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt index bb9fe37d2..4cd2467ef 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/log/LogFragment.kt @@ -38,7 +38,7 @@ class LogFragment : BaseFragment() { override fun onStart() { super.onStart() setHasOptionsMenu(true) - activity.title = resources.getString(R.string.logs) + activity?.title = resources.getString(R.string.logs) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt index 8d4d06807..6da0d7b4e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleFragment.kt @@ -19,7 +19,7 @@ class ModuleFragment : BaseFragment() { override fun onStart() { super.onStart() setHasOptionsMenu(true) - activity.title = resources.getString(R.string.modules) + activity?.title = resources.getString(R.string.modules) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt index 8912f17b3..0bc9b6295 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.kt @@ -18,7 +18,7 @@ class SettingsFragment : BaseFragment() { override fun onStart() { super.onStart() - activity.title = resources.getString(R.string.settings) + activity?.title = resources.getString(R.string.settings) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt index 04bb3849a..6fbfbc01e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserFragment.kt @@ -17,7 +17,7 @@ class SuperuserFragment : BaseFragment() { override fun onStart() { super.onStart() - activity.title = resources.getString(R.string.superuser) + activity?.title = resources.getString(R.string.superuser) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt index 802035b44..ac892c194 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/theme/ThemeFragment.kt @@ -61,7 +61,7 @@ class ThemeFragment : BaseFragment() { override fun onStart() { super.onStart() - activity.title = getString(R.string.section_theme) + activity?.title = getString(R.string.section_theme) } }