@@ -105,7 +105,7 @@ class MainActivity : SimpleActivity() {
105105 main_tabs_holder.setSelectedTabIndicatorColor(adjustedPrimaryColor)
106106 main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(adjustedPrimaryColor)
107107
108- if (main_view_pager.adapter == null ) {
108+ if (main_view_pager.adapter == null && mWasProtectionHandled ) {
109109 initFragments()
110110 }
111111 }
@@ -130,7 +130,7 @@ class MainActivity : SimpleActivity() {
130130
131131 override fun onPrepareOptionsMenu (menu : Menu ? ): Boolean {
132132 val favorites = config.favorites
133- val currentFragment = getCurrentFragment()
133+ val currentFragment = getCurrentFragment() ? : return true
134134
135135 menu!! .apply {
136136 findItem(R .id.search).isVisible = currentFragment is ItemsFragment
@@ -155,6 +155,10 @@ class MainActivity : SimpleActivity() {
155155 }
156156
157157 override fun onOptionsItemSelected (item : MenuItem ): Boolean {
158+ if (getCurrentFragment() == null ) {
159+ return true
160+ }
161+
158162 when (item.itemId) {
159163 R .id.go_home -> goHome()
160164 R .id.go_to_favorite -> goToFavorite()
@@ -224,7 +228,7 @@ class MainActivity : SimpleActivity() {
224228
225229 override fun onQueryTextChange (newText : String ): Boolean {
226230 if (isSearchOpen) {
227- getCurrentFragment().searchQueryChanged(newText)
231+ getCurrentFragment()? .searchQueryChanged(newText)
228232 }
229233 return true
230234 }
@@ -394,23 +398,23 @@ class MainActivity : SimpleActivity() {
394398 }
395399
396400 private fun goHome () {
397- if (config.homeFolder != getCurrentFragment().currentPath) {
401+ if (config.homeFolder != getCurrentFragment()? .currentPath) {
398402 openPath(config.homeFolder)
399403 }
400404 }
401405
402406 private fun showSortingDialog () {
403- ChangeSortingDialog (this , getCurrentFragment().currentPath) {
407+ ChangeSortingDialog (this , getCurrentFragment()!! .currentPath) {
404408 (getCurrentFragment() as ? ItemsFragment )?.refreshItems()
405409 }
406410 }
407411
408412 private fun addFavorite () {
409- config.addFavorite(getCurrentFragment().currentPath)
413+ config.addFavorite(getCurrentFragment()!! .currentPath)
410414 }
411415
412416 private fun removeFavorite () {
413- config.removeFavorite(getCurrentFragment().currentPath)
417+ config.removeFavorite(getCurrentFragment()!! .currentPath)
414418 }
415419
416420 private fun toggleFilenameVisibility () {
@@ -440,7 +444,7 @@ class MainActivity : SimpleActivity() {
440444 favorites.forEachIndexed { index, path ->
441445 val visiblePath = humanizePath(path).replace(" /" , " / " )
442446 items.add(RadioItem (index, visiblePath, path))
443- if (path == getCurrentFragment().currentPath) {
447+ if (path == getCurrentFragment()!! .currentPath) {
444448 currFavoriteIndex = index
445449 }
446450 }
@@ -451,12 +455,12 @@ class MainActivity : SimpleActivity() {
451455 }
452456
453457 private fun setAsHome () {
454- config.homeFolder = getCurrentFragment().currentPath
458+ config.homeFolder = getCurrentFragment()!! .currentPath
455459 toast(R .string.home_folder_updated)
456460 }
457461
458462 private fun changeViewType () {
459- ChangeViewTypeDialog (this , getCurrentFragment().currentPath, getCurrentFragment() is ItemsFragment ) {
463+ ChangeViewTypeDialog (this , getCurrentFragment()!! .currentPath, getCurrentFragment() is ItemsFragment ) {
460464 getAllFragments().forEach {
461465 it?.refreshItems()
462466 }
@@ -501,7 +505,7 @@ class MainActivity : SimpleActivity() {
501505 return
502506 }
503507
504- if (getCurrentFragment().breadcrumbs.childCount ? : 2 <= 1 ) {
508+ if (getCurrentFragment()!! .breadcrumbs.childCount <= 1 ) {
505509 if (! wasBackJustPressed && config.pressBackTwice) {
506510 wasBackJustPressed = true
507511 toast(R .string.press_back_again)
@@ -512,8 +516,8 @@ class MainActivity : SimpleActivity() {
512516 finish()
513517 }
514518 } else {
515- getCurrentFragment().breadcrumbs.removeBreadcrumb()
516- openPath(getCurrentFragment().breadcrumbs.getLastItem().path)
519+ getCurrentFragment()!! .breadcrumbs.removeBreadcrumb()
520+ openPath(getCurrentFragment()!! .breadcrumbs.getLastItem().path)
517521 }
518522 }
519523
@@ -586,7 +590,7 @@ class MainActivity : SimpleActivity() {
586590
587591 private fun getAllFragments (): ArrayList <MyViewPagerFragment ?> = arrayListOf (items_fragment, recents_fragment)
588592
589- private fun getCurrentFragment (): MyViewPagerFragment = when (main_view_pager.currentItem) {
593+ private fun getCurrentFragment (): MyViewPagerFragment ? = when (main_view_pager.currentItem) {
590594 TAB_FILES -> items_fragment
591595 else -> recents_fragment
592596 }
0 commit comments