From 1af8303bbb7a54b5d42dd1ca83d1b57795126194 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 10 Oct 2021 22:44:30 +0200 Subject: [PATCH] adding the core of a new Storage fragment --- .../pro/activities/MainActivity.kt | 7 +-- .../pro/fragments/StorageFragment.kt | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt 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 da278734..6e9cf8a8 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 @@ -138,6 +138,7 @@ class MainActivity : SimpleActivity() { override fun onPrepareOptionsMenu(menu: Menu?): Boolean { val currentFragment = getCurrentFragment() ?: return true + val currentViewType = config.getFolderViewType(currentFragment.currentPath) val favorites = config.favorites menu!!.apply { @@ -148,15 +149,15 @@ class MainActivity : SimpleActivity() { findItem(R.id.remove_favorite).isVisible = currentFragment is ItemsFragment && favorites.contains(currentFragment.currentPath) findItem(R.id.go_to_favorite).isVisible = currentFragment is ItemsFragment && favorites.isNotEmpty() - findItem(R.id.toggle_filename).isVisible = config.getFolderViewType(currentFragment.currentPath) == VIEW_TYPE_GRID + findItem(R.id.toggle_filename).isVisible = currentViewType == VIEW_TYPE_GRID findItem(R.id.go_home).isVisible = currentFragment is ItemsFragment && currentFragment.currentPath != config.homeFolder findItem(R.id.set_as_home).isVisible = currentFragment is ItemsFragment && currentFragment.currentPath != config.homeFolder findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden - findItem(R.id.increase_column_count).isVisible = config.getFolderViewType(currentFragment.currentPath) == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT - findItem(R.id.reduce_column_count).isVisible = config.getFolderViewType(currentFragment.currentPath) == VIEW_TYPE_GRID && config.fileColumnCnt > 1 + findItem(R.id.increase_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT + findItem(R.id.reduce_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt > 1 } return true diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt new file mode 100644 index 00000000..7e6fb471 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/StorageFragment.kt @@ -0,0 +1,51 @@ +package com.simplemobiletools.filemanager.pro.fragments + +import android.content.Context +import android.net.Uri +import android.provider.MediaStore +import android.util.AttributeSet +import com.simplemobiletools.commons.extensions.getLongValue +import com.simplemobiletools.commons.extensions.queryCursor +import com.simplemobiletools.filemanager.pro.activities.SimpleActivity + +class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) { + override fun setupFragment(activity: SimpleActivity) {} + + override fun refreshItems() {} + + override fun setupColors(textColor: Int, primaryColor: Int) {} + + override fun toggleFilenameVisibility() {} + + override fun increaseColumnCount() {} + + override fun reduceColumnCount() {} + + override fun setupFontSize() {} + + override fun setupDateTimeFormat() {} + + override fun searchQueryChanged(text: String) {} + + override fun finishActMode() {} + + private fun getFileTypeSize(uri: Uri): Long { + val projection = arrayOf( + MediaStore.Files.FileColumns.SIZE + ) + + var totalSize = 0L + try { + context.queryCursor(uri, projection) { cursor -> + try { + val size = cursor.getLongValue(MediaStore.Files.FileColumns.SIZE) + totalSize += size + } catch (e: Exception) { + } + } + } catch (e: Exception) { + } + + return totalSize + } +}