diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index d8eb3df9..d634ef09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -20,15 +20,16 @@ import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release import com.simplemobiletools.filemanager.pro.BuildConfig import com.simplemobiletools.filemanager.pro.R +import com.simplemobiletools.filemanager.pro.adapters.ViewPagerAdapter import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent -import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT import com.simplemobiletools.filemanager.pro.helpers.RootHelpers import com.stericson.RootTools.RootTools import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.items_fragment.* import kotlinx.android.synthetic.main.items_fragment.view.* import java.io.File import java.util.* @@ -42,20 +43,12 @@ class MainActivity : SimpleActivity() { private var mWasProtectionHandled = false private var searchMenuItem: MenuItem? = null - private lateinit var fragment: ItemsFragment - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) appLaunched(BuildConfig.APPLICATION_ID) mIsPasswordProtectionPending = config.isAppPasswordProtectionOn - fragment = (fragment_holder as ItemsFragment).apply { - isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER - isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT - isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false) - } - if (savedInstanceState == null) { handleAppPasswordProtection { mWasProtectionHandled = it @@ -86,6 +79,8 @@ class MainActivity : SimpleActivity() { override fun onPrepareOptionsMenu(menu: Menu?): Boolean { val favorites = config.favorites + val fragment = getCurrentFragment() ?: return true + menu!!.apply { findItem(R.id.add_favorite).isVisible = !favorites.contains(fragment.currentPath) findItem(R.id.remove_favorite).isVisible = favorites.contains(fragment.currentPath) @@ -112,13 +107,13 @@ class MainActivity : SimpleActivity() { R.id.sort -> showSortingDialog() R.id.add_favorite -> addFavorite() R.id.remove_favorite -> removeFavorite() - R.id.toggle_filename -> fragment.toggleFilenameVisibility() + R.id.toggle_filename -> getCurrentFragment().toggleFilenameVisibility() R.id.set_as_home -> setAsHome() R.id.change_view_type -> changeViewType() R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden() R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden() - R.id.increase_column_count -> fragment.increaseColumnCount() - R.id.reduce_column_count -> fragment.reduceColumnCount() + R.id.increase_column_count -> getCurrentFragment().increaseColumnCount() + R.id.reduce_column_count -> getCurrentFragment().reduceColumnCount() R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java)) R.id.about -> launchAbout() else -> return super.onOptionsItemSelected(item) @@ -128,7 +123,7 @@ class MainActivity : SimpleActivity() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - outState.putString(PICKED_PATH, (fragment_holder as ItemsFragment).currentPath) + outState.putString(PICKED_PATH, getCurrentFragment().currentPath) outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled) } @@ -137,6 +132,17 @@ class MainActivity : SimpleActivity() { mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false) val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath + if (main_view_pager.adapter == null) { + main_view_pager.adapter = ViewPagerAdapter(this) + main_view_pager.onGlobalLayout { + restorePath(path) + } + } else { + restorePath(path) + } + } + + private fun restorePath(path: String) { if (!mWasProtectionHandled) { handleAppPasswordProtection { mWasProtectionHandled = it @@ -164,7 +170,7 @@ class MainActivity : SimpleActivity() { override fun onQueryTextChange(newText: String): Boolean { if (isSearchOpen) { - fragment.searchQueryChanged(newText) + getCurrentFragment().searchQueryChanged(newText) } return true } @@ -174,13 +180,13 @@ class MainActivity : SimpleActivity() { MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener { override fun onMenuItemActionExpand(item: MenuItem?): Boolean { isSearchOpen = true - fragment.searchOpened() + getCurrentFragment().searchOpened() return true } override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { isSearchOpen = false - fragment.searchClosed() + getCurrentFragment().searchClosed() return true } }) @@ -190,7 +196,13 @@ class MainActivity : SimpleActivity() { handlePermission(PERMISSION_WRITE_STORAGE) { checkOTGPath() if (it) { - initFileManager() + if (main_view_pager.adapter == null) { + main_view_pager.adapter = ViewPagerAdapter(this) + } + + main_view_pager.onGlobalLayout { + initFileManager() + } } else { toast(R.string.no_storage_permissions) finish() @@ -218,6 +230,12 @@ class MainActivity : SimpleActivity() { } else { openPath(config.homeFolder) } + + getCurrentFragment()?.apply { + isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER + isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT + isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false) + } } private fun checkOTGPath() { @@ -246,27 +264,27 @@ class MainActivity : SimpleActivity() { newPath = internalStoragePath } - (fragment_holder as ItemsFragment).openPath(newPath, forceRefresh) + getCurrentFragment()?.openPath(newPath, forceRefresh) } private fun goHome() { - if (config.homeFolder != fragment.currentPath) { + if (config.homeFolder != getCurrentFragment().currentPath) { openPath(config.homeFolder) } } private fun showSortingDialog() { - ChangeSortingDialog(this, fragment.currentPath) { - fragment.refreshItems() + ChangeSortingDialog(this, getCurrentFragment().currentPath) { + getCurrentFragment().refreshItems() } } private fun addFavorite() { - config.addFavorite(fragment.currentPath) + config.addFavorite(getCurrentFragment().currentPath) } private fun removeFavorite() { - config.removeFavorite(fragment.currentPath) + config.removeFavorite(getCurrentFragment().currentPath) } private fun goToFavorite() { @@ -277,7 +295,7 @@ class MainActivity : SimpleActivity() { favorites.forEachIndexed { index, path -> val visiblePath = humanizePath(path).replace("/", " / ") items.add(RadioItem(index, visiblePath, path)) - if (path == fragment.currentPath) { + if (path == getCurrentFragment().currentPath) { currFavoriteIndex = index } } @@ -288,13 +306,13 @@ class MainActivity : SimpleActivity() { } private fun setAsHome() { - config.homeFolder = fragment.currentPath + config.homeFolder = getCurrentFragment().currentPath toast(R.string.home_folder_updated) } private fun changeViewType() { - ChangeViewTypeDialog(this, fragment.currentPath) { - fragment.refreshItems() + ChangeViewTypeDialog(this, getCurrentFragment().currentPath) { + getCurrentFragment().refreshItems() } } @@ -310,7 +328,7 @@ class MainActivity : SimpleActivity() { private fun toggleTemporarilyShowHidden(show: Boolean) { config.temporarilyShowHidden = show - openPath(fragment.currentPath) + openPath(getCurrentFragment().currentPath) } private fun launchAbout() { @@ -329,7 +347,7 @@ class MainActivity : SimpleActivity() { } override fun onBackPressed() { - if (fragment.mView.breadcrumbs.childCount <= 1) { + if (getCurrentFragment().breadcrumbs.childCount <= 1) { if (!wasBackJustPressed && config.pressBackTwice) { wasBackJustPressed = true toast(R.string.press_back_again) @@ -340,8 +358,8 @@ class MainActivity : SimpleActivity() { finish() } } else { - fragment.mView.breadcrumbs.removeBreadcrumb() - openPath(fragment.mView.breadcrumbs.getLastItem().path) + getCurrentFragment().breadcrumbs.removeBreadcrumb() + openPath(getCurrentFragment().breadcrumbs.getLastItem().path) } } @@ -410,6 +428,8 @@ class MainActivity : SimpleActivity() { } } + private fun getCurrentFragment() = items_fragment + private fun checkWhatsNewDialog() { arrayListOf().apply { add(Release(26, R.string.release_26)) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt new file mode 100644 index 00000000..5115136b --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt @@ -0,0 +1,35 @@ +package com.simplemobiletools.filemanager.pro.adapters + +import android.view.View +import android.view.ViewGroup +import androidx.viewpager.widget.PagerAdapter +import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor +import com.simplemobiletools.filemanager.pro.R +import com.simplemobiletools.filemanager.pro.activities.SimpleActivity +import com.simplemobiletools.filemanager.pro.extensions.config +import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment + +class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val layout = getFragment(position) + val view = activity.layoutInflater.inflate(layout, container, false) + container.addView(view) + + (view as ItemsFragment).apply { + setupFragment(activity) + setupColors(activity.config.textColor, activity.getAdjustedPrimaryColor()) + } + + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, item: Any) { + container.removeView(item as View) + } + + override fun getCount() = 1 + + override fun isViewFromObject(view: View, item: Any) = view == item + + private fun getFragment(position: Int) = R.layout.items_fragment +} diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 5abad5db..b07b945e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -1,11 +1,9 @@ package com.simplemobiletools.filemanager.pro.fragments -import android.os.Bundle +import android.content.Context import android.os.Parcelable -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment +import android.util.AttributeSet +import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.recyclerview.widget.GridLayoutManager import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.StoragePickerDialog @@ -24,7 +22,6 @@ import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT -import com.simplemobiletools.filemanager.pro.helpers.PATH import com.simplemobiletools.filemanager.pro.helpers.RootHelpers import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.models.ListItem @@ -33,12 +30,13 @@ import java.io.File import java.util.* import kotlin.collections.ArrayList -class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { +class ItemsFragment(context: Context, attributeSet: AttributeSet) : CoordinatorLayout(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { var currentPath = "" var isGetContentIntent = false var isGetRingtonePicker = false var isPickMultipleIntent = false + private var activity: SimpleActivity? = null private var isFirstResume = true private var showHidden = false private var skipItemUpdating = false @@ -49,68 +47,51 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb private var zoomListener: MyRecyclerView.MyZoomListener? = null private var storedItems = ArrayList() - private var storedTextColor = 0 private var storedFontSize = 0 private var storedDateFormat = "" private var storedTimeFormat = "" - lateinit var mView: View - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - mView = inflater.inflate(R.layout.items_fragment, container, false)!! - storeStateVariables() - return mView - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - mView.apply { + fun setupFragment(activity: SimpleActivity) { + if (this.activity == null) { + this.activity = activity items_swipe_refresh.setOnRefreshListener { refreshItems() } items_fab.setOnClickListener { createNewItem() } breadcrumbs.listener = this@ItemsFragment } } - override fun onSaveInstanceState(outState: Bundle) { - outState.putString(PATH, currentPath) - super.onSaveInstanceState(outState) - } - - override fun onViewStateRestored(savedInstanceState: Bundle?) { - super.onViewStateRestored(savedInstanceState) - if (savedInstanceState != null) { - currentPath = savedInstanceState.getString(PATH)!! - storedItems.clear() + private fun storeStateVariables() { + context!!.config.apply { + storedFontSize = fontSize + storedDateFormat = dateFormat + storedTimeFormat = context.getTimeFormat() } } - override fun onResume() { - super.onResume() - context!!.updateTextColors(mView as ViewGroup) - mView.items_fastscroller.updatePrimaryColor() - val newTextColor = context!!.config.textColor - if (storedTextColor != newTextColor) { - storedItems = ArrayList() - getRecyclerAdapter()?.apply { - updateTextColor(newTextColor) - initDrawables() - } - mView.breadcrumbs.updateColor(newTextColor) - storedTextColor = newTextColor + fun setupColors(textColor: Int, adjustedPrimaryColor: Int) { + context!!.updateTextColors(this) + items_fastscroller.updatePrimaryColor() + storedItems = ArrayList() + getRecyclerAdapter()?.apply { + updateTextColor(textColor) + initDrawables() } + breadcrumbs.updateColor(textColor) + + items_fastscroller.updateBubbleColors() + val configFontSize = context!!.config.fontSize if (storedFontSize != configFontSize) { getRecyclerAdapter()?.updateFontSizes() storedFontSize = configFontSize - mView.breadcrumbs.updateFontSize(context!!.getTextSize()) + breadcrumbs.updateFontSize(context!!.getTextSize()) } if (storedDateFormat != context!!.config.dateFormat || storedTimeFormat != context!!.getTimeFormat()) { getRecyclerAdapter()?.updateDateTimeFormat() } - mView.items_fastscroller.updateBubbleColors() if (!isFirstResume) { refreshItems() } @@ -118,22 +99,8 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb isFirstResume = false } - override fun onPause() { - super.onPause() - storeStateVariables() - } - - private fun storeStateVariables() { - context!!.config.apply { - storedTextColor = textColor - storedFontSize = fontSize - storedDateFormat = dateFormat - storedTimeFormat = context.getTimeFormat() - } - } - fun openPath(path: String, forceRefresh: Boolean = false) { - if (!isAdded || (activity as? BaseSimpleActivity)?.isAskingPermissions == true) { + if ((activity as? BaseSimpleActivity)?.isAskingPermissions == true) { return } @@ -146,7 +113,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb currentPath = realPath showHidden = context!!.config.shouldShowHidden getItems(currentPath) { originalPath, listItems -> - if (currentPath != originalPath || !isAdded) { + if (currentPath != originalPath) { return@getItems } @@ -164,50 +131,48 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb private fun addItems(items: ArrayList, forceRefresh: Boolean = false) { skipItemUpdating = false - mView.apply { - activity?.runOnUiThread { - items_swipe_refresh?.isRefreshing = false - breadcrumbs.setBreadcrumb(currentPath) - if (!forceRefresh && items.hashCode() == storedItems.hashCode()) { - return@runOnUiThread - } + activity?.runOnUiThread { + items_swipe_refresh?.isRefreshing = false + breadcrumbs.setBreadcrumb(currentPath) + if (!forceRefresh && items.hashCode() == storedItems.hashCode()) { + return@runOnUiThread + } - storedItems = items - if (items_list.adapter == null) { - breadcrumbs.updateFontSize(context!!.getTextSize()) - } + storedItems = items + if (items_list.adapter == null) { + breadcrumbs.updateFontSize(context!!.getTextSize()) + } - ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller, - items_swipe_refresh) { - if ((it as? ListItem)?.isSectionTitle == true) { - openDirectory(it.mPath) - searchClosed() - } else { - itemClicked(it as FileDirItem) - } - }.apply { - setupZoomListener(zoomListener) - items_list.adapter = this + ItemsAdapter(activity as SimpleActivity, storedItems, this@ItemsFragment, items_list, isPickMultipleIntent, items_fastscroller, + items_swipe_refresh) { + if ((it as? ListItem)?.isSectionTitle == true) { + openDirectory(it.mPath) + searchClosed() + } else { + itemClicked(it as FileDirItem) } + }.apply { + setupZoomListener(zoomListener) + items_list.adapter = this + } - items_list.scheduleLayoutAnimation() - items_fastscroller.setViews(items_list, items_swipe_refresh) { - val listItem = getRecyclerAdapter()?.listItems?.getOrNull(it) - items_fastscroller.updateBubbleText(listItem?.getBubbleText(context, storedDateFormat, storedTimeFormat) ?: "") - } + items_list.scheduleLayoutAnimation() + items_fastscroller.setViews(items_list, items_swipe_refresh) { + val listItem = getRecyclerAdapter()?.listItems?.getOrNull(it) + items_fastscroller.updateBubbleText(listItem?.getBubbleText(context, storedDateFormat, storedTimeFormat) ?: "") + } - getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath]) - items_list.onGlobalLayout { - items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset()) - calculateContentHeight(storedItems) - } + getRecyclerLayoutManager().onRestoreInstanceState(scrollStates[currentPath]) + items_list.onGlobalLayout { + items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset()) + calculateContentHeight(storedItems) } } } private fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState() - private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as MyGridLayoutManager) + private fun getRecyclerLayoutManager() = (items_list.layoutManager as MyGridLayoutManager) private fun getItems(path: String, callback: (originalPath: String, items: ArrayList) -> Unit) { skipItemUpdating = false @@ -314,7 +279,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb activity?.toast(R.string.select_audio_file) } } else { - activity!!.tryOpenPathIntent(path, false) + activity?.tryOpenPathIntent(path, false) } } } @@ -337,19 +302,15 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb when { searchText.isEmpty() -> activity?.runOnUiThread { - mView.apply { - items_list.beVisible() - getRecyclerAdapter()?.updateItems(storedItems) - items_placeholder.beGone() - items_placeholder_2.beGone() - } + items_list.beVisible() + getRecyclerAdapter()?.updateItems(storedItems) + items_placeholder.beGone() + items_placeholder_2.beGone() } searchText.length == 1 -> activity?.runOnUiThread { - mView.apply { - items_list.beGone() - items_placeholder.beVisible() - items_placeholder_2.beVisible() - } + items_list.beGone() + items_placeholder.beVisible() + items_placeholder_2.beVisible() } else -> { val files = searchFiles(searchText, currentPath) @@ -383,15 +344,13 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb activity?.runOnUiThread { getRecyclerAdapter()?.updateItems(listItems, text) - mView.apply { - items_list.beVisibleIf(listItems.isNotEmpty()) - items_placeholder.beVisibleIf(listItems.isEmpty()) - items_placeholder_2.beGone() + items_list.beVisibleIf(listItems.isNotEmpty()) + items_placeholder.beVisibleIf(listItems.isEmpty()) + items_placeholder_2.beGone() - items_list.onGlobalLayout { - items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset()) - calculateContentHeight(listItems) - } + items_list.onGlobalLayout { + items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset()) + calculateContentHeight(listItems) } } } @@ -437,7 +396,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb fun searchOpened() { isSearchOpen = true lastSearchedText = "" - mView.items_swipe_refresh.isEnabled = false + items_swipe_refresh.isEnabled = false } fun searchClosed() { @@ -449,12 +408,10 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb skipItemUpdating = false lastSearchedText = "" - mView.apply { - items_swipe_refresh.isEnabled = true - items_list.beVisible() - items_placeholder.beGone() - items_placeholder_2.beGone() - } + items_swipe_refresh.isEnabled = true + items_list.beVisible() + items_placeholder.beGone() + items_placeholder_2.beGone() } private fun createNewItem() { @@ -467,7 +424,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb } } - private fun getRecyclerAdapter() = mView.items_list.adapter as? ItemsAdapter + private fun getRecyclerAdapter() = items_list.adapter as? ItemsAdapter private fun setupLayoutManager() { if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID) { @@ -478,13 +435,13 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb setupListLayoutManager() } - mView.items_list.adapter = null + items_list.adapter = null initZoomListener() addItems(storedItems, true) } private fun setupGridLayoutManager() { - val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager + val layoutManager = items_list.layoutManager as MyGridLayoutManager layoutManager.spanCount = context?.config?.fileColumnCnt ?: 3 layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { @@ -499,14 +456,14 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb } private fun setupListLayoutManager() { - val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager + val layoutManager = items_list.layoutManager as MyGridLayoutManager layoutManager.spanCount = 1 zoomListener = null } private fun initZoomListener() { if (context?.config?.getFolderViewType(currentPath) == VIEW_TYPE_GRID) { - val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager + val layoutManager = items_list.layoutManager as MyGridLayoutManager zoomListener = object : MyRecyclerView.MyZoomListener { override fun zoomIn() { if (layoutManager.spanCount > 1) { @@ -528,20 +485,20 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb } private fun calculateContentHeight(items: MutableList) { - val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager + val layoutManager = items_list.layoutManager as MyGridLayoutManager val thumbnailHeight = layoutManager.getChildAt(0)?.height ?: 0 val fullHeight = ((items.size - 1) / layoutManager.spanCount + 1) * thumbnailHeight - mView.items_fastscroller.setContentHeight(fullHeight) - mView.items_fastscroller.setScrollToY(mView.items_list.computeVerticalScrollOffset()) + items_fastscroller.setContentHeight(fullHeight) + items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset()) } fun increaseColumnCount() { - context?.config?.fileColumnCnt = ++(mView.items_list.layoutManager as MyGridLayoutManager).spanCount + context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount columnCountChanged() } fun reduceColumnCount() { - context?.config?.fileColumnCnt = --(mView.items_list.layoutManager as MyGridLayoutManager).spanCount + context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount columnCountChanged() } @@ -565,7 +522,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb openPath(it) } } else { - val item = mView.breadcrumbs.getChildAt(id).tag as FileDirItem + val item = breadcrumbs.getChildAt(id).tag as FileDirItem openPath(item.path) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7ad67744..45b61f2d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,9 +4,8 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - diff --git a/app/src/main/res/layout/items_fragment.xml b/app/src/main/res/layout/items_fragment.xml index c5d9df29..c82625e2 100644 --- a/app/src/main/res/layout/items_fragment.xml +++ b/app/src/main/res/layout/items_fragment.xml @@ -1,7 +1,7 @@ - @@ -83,4 +83,4 @@ android:layout_margin="@dimen/activity_margin" android:src="@drawable/ic_plus_vector" /> - + diff --git a/app/src/main/res/layout/recents_fragment.xml b/app/src/main/res/layout/recents_fragment.xml index 6eafb31d..dd1ddbe2 100644 --- a/app/src/main/res/layout/recents_fragment.xml +++ b/app/src/main/res/layout/recents_fragment.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/recents_wrapper" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="match_parent">