migrate activities to viewbinding

This commit is contained in:
fatih ergin 2023-08-09 18:15:25 +03:00
parent 505839c84a
commit 6a88111d32
8 changed files with 342 additions and 284 deletions

View File

@ -11,9 +11,9 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.adapters.DecompressItemsAdapter import com.simplemobiletools.filemanager.pro.adapters.DecompressItemsAdapter
import com.simplemobiletools.filemanager.pro.databinding.ActivityDecompressBinding
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.models.ListItem import com.simplemobiletools.filemanager.pro.models.ListItem
import kotlinx.android.synthetic.main.activity_decompress.*
import net.lingala.zip4j.exception.ZipException import net.lingala.zip4j.exception.ZipException
import net.lingala.zip4j.exception.ZipException.Type import net.lingala.zip4j.exception.ZipException.Type
import net.lingala.zip4j.io.inputstream.ZipInputStream import net.lingala.zip4j.io.inputstream.ZipInputStream
@ -26,6 +26,7 @@ class DecompressActivity : SimpleActivity() {
} }
private val allFiles = ArrayList<ListItem>() private val allFiles = ArrayList<ListItem>()
private lateinit var binding: ActivityDecompressBinding
private var currentPath = "" private var currentPath = ""
private var uri: Uri? = null private var uri: Uri? = null
private var password: String? = null private var password: String? = null
@ -34,10 +35,13 @@ class DecompressActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_decompress) binding = ActivityDecompressBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu() setupOptionsMenu()
updateMaterialActivityViews(decompress_coordinator, decompress_list, useTransparentNavigation = true, useTopSearchMenu = false) binding.apply {
setupMaterialScrollListener(decompress_list, decompress_toolbar) updateMaterialActivityViews(decompressCoordinator, decompressList, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(decompressList, decompressToolbar)
}
uri = intent.data uri = intent.data
if (uri == null) { if (uri == null) {
@ -48,13 +52,13 @@ class DecompressActivity : SimpleActivity() {
password = savedInstanceState?.getString(PASSWORD, null) password = savedInstanceState?.getString(PASSWORD, null)
val realPath = getRealPathFromURI(uri!!) val realPath = getRealPathFromURI(uri!!)
decompress_toolbar.title = realPath?.getFilenameFromPath() ?: Uri.decode(uri.toString().getFilenameFromPath()) binding.decompressToolbar.title = realPath?.getFilenameFromPath() ?: Uri.decode(uri.toString().getFilenameFromPath())
setupFilesList() setupFilesList()
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(decompress_toolbar, NavigationIcon.Arrow) setupToolbar(binding.decompressToolbar, NavigationIcon.Arrow)
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
@ -63,7 +67,7 @@ class DecompressActivity : SimpleActivity() {
} }
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
decompress_toolbar.setOnMenuItemClickListener { menuItem -> binding.decompressToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.decompress -> decompressFiles() R.id.decompress -> decompressFiles()
else -> return@setOnMenuItemClickListener false else -> return@setOnMenuItemClickListener false
@ -90,12 +94,12 @@ class DecompressActivity : SimpleActivity() {
currentPath = path currentPath = path
try { try {
val listItems = getFolderItems(currentPath) val listItems = getFolderItems(currentPath)
DecompressItemsAdapter(this, listItems, decompress_list) { DecompressItemsAdapter(this, listItems, binding.decompressList) {
if ((it as ListItem).isDirectory) { if ((it as ListItem).isDirectory) {
updateCurrentPath(it.path) updateCurrentPath(it.path)
} }
}.apply { }.apply {
decompress_list.adapter = this binding.decompressList.adapter = this
} }
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)

View File

@ -10,28 +10,32 @@ import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.adapters.ManageFavoritesAdapter import com.simplemobiletools.filemanager.pro.adapters.ManageFavoritesAdapter
import com.simplemobiletools.filemanager.pro.databinding.ActivityFavoritesBinding
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.activity_favorites.*
class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener { class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener {
private lateinit var binding: ActivityFavoritesBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_favorites) binding = ActivityFavoritesBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu() setupOptionsMenu()
updateFavorites() updateFavorites()
updateMaterialActivityViews(manage_favorites_coordinator, manage_favorites_list, useTransparentNavigation = true, useTopSearchMenu = false) binding.apply {
setupMaterialScrollListener(manage_favorites_list, manage_favorites_toolbar) updateMaterialActivityViews(manageFavoritesCoordinator, manageFavoritesList, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(manageFavoritesList, manageFavoritesToolbar)
}
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(manage_favorites_toolbar, NavigationIcon.Arrow) setupToolbar(binding.manageFavoritesToolbar, NavigationIcon.Arrow)
} }
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
manage_favorites_toolbar.setOnMenuItemClickListener { menuItem -> binding.manageFavoritesToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.add_favorite -> addFavorite() R.id.add_favorite -> addFavorite()
else -> return@setOnMenuItemClickListener false else -> return@setOnMenuItemClickListener false
@ -41,22 +45,24 @@ class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
private fun updateFavorites() { private fun updateFavorites() {
val favorites = ArrayList<String>() binding.apply {
config.favorites.mapTo(favorites) { it } val favorites = ArrayList<String>()
manage_favorites_placeholder.beVisibleIf(favorites.isEmpty()) config.favorites.mapTo(favorites) { it }
manage_favorites_placeholder.setTextColor(getProperTextColor()) manageFavoritesPlaceholder.beVisibleIf(favorites.isEmpty())
manageFavoritesPlaceholder.setTextColor(getProperTextColor())
manage_favorites_placeholder_2.apply { manageFavoritesPlaceholder2.apply {
paintFlags = paintFlags or Paint.UNDERLINE_TEXT_FLAG paintFlags = paintFlags or Paint.UNDERLINE_TEXT_FLAG
beVisibleIf(favorites.isEmpty()) beVisibleIf(favorites.isEmpty())
setTextColor(getProperPrimaryColor()) setTextColor(getProperPrimaryColor())
setOnClickListener { setOnClickListener {
addFavorite() addFavorite()
}
} }
}
ManageFavoritesAdapter(this, favorites, this, manage_favorites_list) { }.apply { ManageFavoritesAdapter(this@FavoritesActivity, favorites, this@FavoritesActivity, manageFavoritesList) { }.apply {
manage_favorites_list.adapter = this manageFavoritesList.adapter = this
}
} }
} }

View File

@ -25,6 +25,7 @@ import com.simplemobiletools.commons.models.Release
import com.simplemobiletools.filemanager.pro.BuildConfig import com.simplemobiletools.filemanager.pro.BuildConfig
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.adapters.ViewPagerAdapter import com.simplemobiletools.filemanager.pro.adapters.ViewPagerAdapter
import com.simplemobiletools.filemanager.pro.databinding.ActivityMainBinding
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
import com.simplemobiletools.filemanager.pro.dialogs.InsertFilenameDialog import com.simplemobiletools.filemanager.pro.dialogs.InsertFilenameDialog
@ -38,11 +39,6 @@ import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import com.stericson.RootTools.RootTools 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 kotlinx.android.synthetic.main.recents_fragment.*
import kotlinx.android.synthetic.main.storage_fragment.*
import me.grantland.widget.AutofitHelper import me.grantland.widget.AutofitHelper
import java.io.File import java.io.File
@ -50,6 +46,7 @@ class MainActivity : SimpleActivity() {
private val BACK_PRESS_TIMEOUT = 5000 private val BACK_PRESS_TIMEOUT = 5000
private val MANAGE_STORAGE_RC = 201 private val MANAGE_STORAGE_RC = 201
private val PICKED_PATH = "picked_path" private val PICKED_PATH = "picked_path"
private lateinit var binding: ActivityMainBinding
private var wasBackJustPressed = false private var wasBackJustPressed = false
private var mIsPasswordProtectionPending = false private var mIsPasswordProtectionPending = false
private var mWasProtectionHandled = false private var mWasProtectionHandled = false
@ -63,7 +60,8 @@ class MainActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
appLaunched(BuildConfig.APPLICATION_ID) appLaunched(BuildConfig.APPLICATION_ID)
setupOptionsMenu() setupOptionsMenu()
refreshMenuItems() refreshMenuItems()
@ -79,7 +77,7 @@ class MainActivity : SimpleActivity() {
storeStateVariables() storeStateVariables()
setupTabs() setupTabs()
updateMaterialActivityViews(main_coordinator, null, useTransparentNavigation = false, useTopSearchMenu = true) updateMaterialActivityViews(binding.mainCoordinator, null, useTransparentNavigation = false, useTopSearchMenu = true)
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
@ -132,7 +130,7 @@ class MainActivity : SimpleActivity() {
} }
} }
if (main_view_pager.adapter == null && mWasProtectionHandled) { if (binding.mainViewPager.adapter == null && mWasProtectionHandled) {
initFragments() initFragments()
} }
} }
@ -140,7 +138,7 @@ class MainActivity : SimpleActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
storeStateVariables() storeStateVariables()
config.lastUsedViewPagerPage = main_view_pager.currentItem config.lastUsedViewPagerPage = binding.mainViewPager.currentItem
} }
override fun onDestroy() { override fun onDestroy() {
@ -150,11 +148,11 @@ class MainActivity : SimpleActivity() {
override fun onBackPressed() { override fun onBackPressed() {
val currentFragment = getCurrentFragment() val currentFragment = getCurrentFragment()
if (main_menu.isSearchOpen) { if (binding.mainMenu.isSearchOpen) {
main_menu.closeSearch() binding.mainMenu.closeSearch()
} else if (currentFragment is RecentsFragment || currentFragment is StorageFragment) { } else if (currentFragment is RecentsFragment || currentFragment is StorageFragment) {
super.onBackPressed() super.onBackPressed()
} else if (currentFragment!!.breadcrumbs.getItemCount() <= 1) { } else if ((currentFragment as ItemsFragment).getBreadcrumbs().getItemCount() <= 1) {
if (!wasBackJustPressed && config.pressBackTwice) { if (!wasBackJustPressed && config.pressBackTwice) {
wasBackJustPressed = true wasBackJustPressed = true
toast(R.string.press_back_again) toast(R.string.press_back_again)
@ -165,8 +163,8 @@ class MainActivity : SimpleActivity() {
finish() finish()
} }
} else { } else {
currentFragment.breadcrumbs?.removeBreadcrumb() currentFragment.getBreadcrumbs().removeBreadcrumb()
openPath(currentFragment.breadcrumbs.getLastItem().path) openPath(currentFragment.getBreadcrumbs().getLastItem().path)
} }
} }
@ -176,7 +174,7 @@ class MainActivity : SimpleActivity() {
val currentViewType = config.getFolderViewType(currentFragment.currentPath) val currentViewType = config.getFolderViewType(currentFragment.currentPath)
val favorites = config.favorites val favorites = config.favorites
main_menu.getToolbar().menu.apply { binding.mainMenu.getToolbar().menu.apply {
findItem(R.id.sort).isVisible = currentFragment is ItemsFragment findItem(R.id.sort).isVisible = currentFragment is ItemsFragment
findItem(R.id.change_view_type).isVisible = currentFragment !is StorageFragment findItem(R.id.change_view_type).isVisible = currentFragment !is StorageFragment
@ -200,49 +198,51 @@ class MainActivity : SimpleActivity() {
} }
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
main_menu.getToolbar().inflateMenu(R.menu.menu) binding.mainMenu.apply {
main_menu.toggleHideOnScroll(false) getToolbar().inflateMenu(R.menu.menu)
main_menu.setupMenu() toggleHideOnScroll(false)
setupMenu()
main_menu.onSearchClosedListener = { onSearchClosedListener = {
getAllFragments().forEach { getAllFragments().forEach {
it?.searchQueryChanged("") it?.searchQueryChanged("")
}
} }
}
main_menu.onSearchTextChangedListener = { text -> onSearchTextChangedListener = { text ->
getCurrentFragment()?.searchQueryChanged(text) getCurrentFragment()?.searchQueryChanged(text)
} }
main_menu.getToolbar().setOnMenuItemClickListener { menuItem -> getToolbar().setOnMenuItemClickListener { menuItem ->
if (getCurrentFragment() == null) { if (getCurrentFragment() == null) {
return@setOnMenuItemClickListener true
}
when (menuItem.itemId) {
R.id.go_home -> goHome()
R.id.go_to_favorite -> goToFavorite()
R.id.sort -> showSortingDialog()
R.id.add_favorite -> addFavorite()
R.id.remove_favorite -> removeFavorite()
R.id.toggle_filename -> 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.column_count -> changeColumnCount()
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true return@setOnMenuItemClickListener true
} }
when (menuItem.itemId) {
R.id.go_home -> goHome()
R.id.go_to_favorite -> goToFavorite()
R.id.sort -> showSortingDialog()
R.id.add_favorite -> addFavorite()
R.id.remove_favorite -> removeFavorite()
R.id.toggle_filename -> 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.column_count -> changeColumnCount()
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
R.id.settings -> launchSettings()
R.id.about -> launchAbout()
else -> return@setOnMenuItemClickListener false
}
return@setOnMenuItemClickListener true
} }
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
outState.putString(PICKED_PATH, items_fragment?.currentPath ?: "") outState.putString(PICKED_PATH, getItemsFragment()?.currentPath ?: "")
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled) outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
} }
@ -251,8 +251,8 @@ class MainActivity : SimpleActivity() {
mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false) mWasProtectionHandled = savedInstanceState.getBoolean(WAS_PROTECTION_HANDLED, false)
val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath
if (main_view_pager.adapter == null) { if (binding.mainViewPager.adapter == null) {
main_view_pager.onGlobalLayout { binding.mainViewPager.onGlobalLayout {
restorePath(path) restorePath(path)
} }
} else { } else {
@ -287,7 +287,7 @@ class MainActivity : SimpleActivity() {
private fun updateMenuColors() { private fun updateMenuColors() {
updateStatusbarColor(getProperBackgroundColor()) updateStatusbarColor(getProperBackgroundColor())
main_menu.updateColors() binding.mainMenu.updateColors()
} }
private fun storeStateVariables() { private fun storeStateVariables() {
@ -304,11 +304,11 @@ class MainActivity : SimpleActivity() {
handleStoragePermission { handleStoragePermission {
checkOTGPath() checkOTGPath()
if (it) { if (it) {
if (main_view_pager.adapter == null) { if (binding.mainViewPager.adapter == null) {
initFragments() initFragments()
} }
main_view_pager.onGlobalLayout { binding.mainViewPager.onGlobalLayout {
initFileManager(!hadPermission) initFileManager(!hadPermission)
} }
} else { } else {
@ -368,41 +368,43 @@ class MainActivity : SimpleActivity() {
tryOpenPathIntent(data.path!!, false, finishActivity = true) tryOpenPathIntent(data.path!!, false, finishActivity = true)
} }
main_view_pager.currentItem = 0 binding.mainViewPager.currentItem = 0
} else { } else {
openPath(config.homeFolder) openPath(config.homeFolder)
} }
if (refreshRecents) { if (refreshRecents) {
recents_fragment?.refreshFragment() getRecentsFragment()?.refreshFragment()
} }
} }
private fun initFragments() { private fun initFragments() {
main_view_pager.adapter = ViewPagerAdapter(this, mTabsToShow) binding.mainViewPager.apply {
main_view_pager.offscreenPageLimit = 2 adapter = ViewPagerAdapter(this@MainActivity, mTabsToShow)
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { offscreenPageLimit = 2
override fun onPageScrollStateChanged(state: Int) {} addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {} override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
main_tabs_holder.getTabAt(position)?.select() binding.mainTabsHolder.getTabAt(position)?.select()
getAllFragments().forEach { getAllFragments().forEach {
(it as? ItemOperationsListener)?.finishActMode() (it as? ItemOperationsListener)?.finishActMode()
}
refreshMenuItems()
} }
})
currentItem = config.lastUsedViewPagerPage
onGlobalLayout {
refreshMenuItems() refreshMenuItems()
} }
})
main_view_pager.currentItem = config.lastUsedViewPagerPage
main_view_pager.onGlobalLayout {
refreshMenuItems()
} }
} }
private fun setupTabs() { private fun setupTabs() {
main_tabs_holder.removeAllTabs() binding.mainTabsHolder.removeAllTabs()
val action = intent.action val action = intent.action
val isPickFileIntent = action == RingtoneManager.ACTION_RINGTONE_PICKER || action == Intent.ACTION_GET_CONTENT || action == Intent.ACTION_PICK val isPickFileIntent = action == RingtoneManager.ACTION_RINGTONE_PICKER || action == Intent.ACTION_GET_CONTENT || action == Intent.ACTION_PICK
val isCreateDocumentIntent = action == Intent.ACTION_CREATE_DOCUMENT val isCreateDocumentIntent = action == Intent.ACTION_CREATE_DOCUMENT
@ -421,41 +423,45 @@ class MainActivity : SimpleActivity() {
mTabsToShow.forEachIndexed { index, value -> mTabsToShow.forEachIndexed { index, value ->
if (config.showTabs and value != 0) { if (config.showTabs and value != 0) {
main_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply { binding.mainTabsHolder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
customView?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index)) customView?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index) customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
AutofitHelper.create(customView?.findViewById(R.id.tab_item_label)) AutofitHelper.create(customView?.findViewById(R.id.tab_item_label))
main_tabs_holder.addTab(this) binding.mainTabsHolder.addTab(this)
} }
} }
} }
main_tabs_holder.onTabSelectionChanged( binding.mainTabsHolder.apply {
tabUnselectedAction = { onTabSelectionChanged(
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position]) tabUnselectedAction = {
}, updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
tabSelectedAction = { },
main_menu.closeSearch() tabSelectedAction = {
main_view_pager.currentItem = it.position binding.mainMenu.closeSearch()
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position]) binding.mainViewPager.currentItem = it.position
} updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
) }
)
main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1) beGoneIf(tabCount == 1)
}
} }
private fun setupTabColors() { private fun setupTabColors() {
val activeView = main_tabs_holder.getTabAt(main_view_pager.currentItem)?.customView binding.apply {
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[main_view_pager.currentItem]) val activeView = mainTabsHolder.getTabAt(mainViewPager.currentItem)?.customView
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[mainViewPager.currentItem])
getInactiveTabIndexes(main_view_pager.currentItem).forEach { index -> getInactiveTabIndexes(mainViewPager.currentItem).forEach { index ->
val inactiveView = main_tabs_holder.getTabAt(index)?.customView val inactiveView = mainTabsHolder.getTabAt(index)?.customView
updateBottomTabItemColors(inactiveView, false, getDeselectedTabDrawableIds()[index]) updateBottomTabItemColors(inactiveView, false, getDeselectedTabDrawableIds()[index])
}
val bottomBarColor = getBottomNavigationBackgroundColor()
updateNavigationBarColor(bottomBarColor)
mainTabsHolder.setBackgroundColor(bottomBarColor)
} }
val bottomBarColor = getBottomNavigationBackgroundColor()
updateNavigationBarColor(bottomBarColor)
main_tabs_holder.setBackgroundColor(bottomBarColor)
} }
private fun getTabIcon(position: Int): Drawable { private fun getTabIcon(position: Int): Drawable {
@ -504,7 +510,7 @@ class MainActivity : SimpleActivity() {
newPath = internalStoragePath newPath = internalStoragePath
} }
items_fragment?.openPath(newPath, forceRefresh) getItemsFragment()?.openPath(newPath, forceRefresh)
} }
private fun goHome() { private fun goHome() {
@ -714,12 +720,12 @@ class MainActivity : SimpleActivity() {
} }
fun openedDirectory() { fun openedDirectory() {
if (main_menu.isSearchOpen) { if (binding.mainMenu.isSearchOpen) {
main_menu.closeSearch() binding.mainMenu.closeSearch()
} }
} }
private fun getInactiveTabIndexes(activeIndex: Int) = (0 until main_tabs_holder.tabCount).filter { it != activeIndex } private fun getInactiveTabIndexes(activeIndex: Int) = (0 until binding.mainTabsHolder.tabCount).filter { it != activeIndex }
private fun getSelectedTabDrawableIds(): ArrayList<Int> { private fun getSelectedTabDrawableIds(): ArrayList<Int> {
val showTabs = config.showTabs val showTabs = config.showTabs
@ -759,24 +765,28 @@ class MainActivity : SimpleActivity() {
return icons return icons
} }
private fun getAllFragments(): ArrayList<MyViewPagerFragment?> = arrayListOf(items_fragment, recents_fragment, storage_fragment) private fun getRecentsFragment() = findViewById<RecentsFragment>(R.id.recents_fragment);
private fun getItemsFragment() = findViewById<ItemsFragment>(R.id.items_fragment);
private fun getStorageFragment() = findViewById<StorageFragment>(R.id.storage_fragment);
private fun getAllFragments(): ArrayList<MyViewPagerFragment<*>?> =
arrayListOf(getItemsFragment(), getRecentsFragment(), getStorageFragment())
private fun getCurrentFragment(): MyViewPagerFragment? { private fun getCurrentFragment(): MyViewPagerFragment<*>? {
val showTabs = config.showTabs val showTabs = config.showTabs
val fragments = arrayListOf<MyViewPagerFragment>() val fragments = arrayListOf<MyViewPagerFragment<*>>()
if (showTabs and TAB_FILES != 0) { if (showTabs and TAB_FILES != 0) {
fragments.add(items_fragment) fragments.add(getItemsFragment())
} }
if (showTabs and TAB_RECENT_FILES != 0) { if (showTabs and TAB_RECENT_FILES != 0) {
fragments.add(recents_fragment) fragments.add(getRecentsFragment())
} }
if (showTabs and TAB_STORAGE_ANALYSIS != 0) { if (showTabs and TAB_STORAGE_ANALYSIS != 0) {
fragments.add(storage_fragment) fragments.add(getStorageFragment())
} }
return fragments.getOrNull(main_view_pager.currentItem) return fragments.getOrNull(binding.mainViewPager.currentItem)
} }
private fun getTabsList() = arrayListOf(TAB_FILES, TAB_RECENT_FILES, TAB_STORAGE_ANALYSIS) private fun getTabsList() = arrayListOf(TAB_FILES, TAB_RECENT_FILES, TAB_STORAGE_ANALYSIS)

View File

@ -21,6 +21,7 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.pro.databinding.ActivityMimetypesBinding
import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
@ -28,10 +29,10 @@ import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
import com.simplemobiletools.filemanager.pro.helpers.* import com.simplemobiletools.filemanager.pro.helpers.*
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import com.simplemobiletools.filemanager.pro.models.ListItem import com.simplemobiletools.filemanager.pro.models.ListItem
import kotlinx.android.synthetic.main.activity_mimetypes.*
import java.util.Locale import java.util.Locale
class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
private lateinit var binding: ActivityMimetypesBinding
private var isSearchOpen = false private var isSearchOpen = false
private var currentMimeType = "" private var currentMimeType = ""
private var lastSearchedText = "" private var lastSearchedText = ""
@ -43,14 +44,17 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mimetypes) binding = ActivityMimetypesBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu() setupOptionsMenu()
refreshMenuItems() refreshMenuItems()
updateMaterialActivityViews(mimetypes_coordinator, mimetypes_list, useTransparentNavigation = true, useTopSearchMenu = false) binding.apply {
setupMaterialScrollListener(mimetypes_list, mimetypes_toolbar) updateMaterialActivityViews(mimetypesCoordinator, mimetypesList, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(mimetypesList, mimetypesToolbar)
}
currentMimeType = intent.getStringExtra(SHOW_MIMETYPE) ?: return currentMimeType = intent.getStringExtra(SHOW_MIMETYPE) ?: return
mimetypes_toolbar.title = getString( binding.mimetypesToolbar.title = getString(
when (currentMimeType) { when (currentMimeType) {
IMAGES -> R.string.images IMAGES -> R.string.images
VIDEOS -> R.string.videos VIDEOS -> R.string.videos
@ -70,20 +74,22 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
reFetchItems() reFetchItems()
} }
mimetypes_fastscroller.updateColors(getProperPrimaryColor()) binding.apply {
mimetypes_placeholder.setTextColor(getProperTextColor()) mimetypesFastscroller.updateColors(getProperPrimaryColor())
mimetypes_placeholder_2.setTextColor(getProperTextColor()) mimetypesPlaceholder.setTextColor(getProperTextColor())
mimetypesPlaceholder2.setTextColor(getProperTextColor())
}
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(mimetypes_toolbar, NavigationIcon.Arrow, searchMenuItem = searchMenuItem) setupToolbar(binding.mimetypesToolbar, NavigationIcon.Arrow, searchMenuItem = searchMenuItem)
} }
private fun refreshMenuItems() { private fun refreshMenuItems() {
val currentViewType = config.getFolderViewType(currentMimeType) val currentViewType = config.getFolderViewType(currentMimeType)
mimetypes_toolbar.menu.apply { binding.mimetypesToolbar.menu.apply {
findItem(R.id.toggle_filename).isVisible = currentViewType == VIEW_TYPE_GRID findItem(R.id.toggle_filename).isVisible = currentViewType == VIEW_TYPE_GRID
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden() findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden()
@ -94,8 +100,8 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
} }
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
setupSearch(mimetypes_toolbar.menu) setupSearch(binding.mimetypesToolbar.menu)
mimetypes_toolbar.setOnMenuItemClickListener { menuItem -> binding.mimetypesToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.sort -> showSortingDialog() R.id.sort -> showSortingDialog()
R.id.toggle_filename -> toggleFilenameVisibility() R.id.toggle_filename -> toggleFilenameVisibility()
@ -130,15 +136,19 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
lastSearchedText = searchText lastSearchedText = searchText
when { when {
searchText.isEmpty() -> { searchText.isEmpty() -> {
mimetypes_fastscroller.beVisible() binding.apply {
getRecyclerAdapter()?.updateItems(storedItems) mimetypesFastscroller.beVisible()
mimetypes_placeholder.beGoneIf(storedItems.isNotEmpty()) getRecyclerAdapter()?.updateItems(storedItems)
mimetypes_placeholder_2.beGone() mimetypesPlaceholder.beGoneIf(storedItems.isNotEmpty())
mimetypesPlaceholder2.beGone()
}
} }
searchText.length == 1 -> { searchText.length == 1 -> {
mimetypes_fastscroller.beGone() binding.apply {
mimetypes_placeholder.beVisible() mimetypesFastscroller.beGone()
mimetypes_placeholder_2.beVisible() mimetypesPlaceholder.beVisible()
mimetypesPlaceholder2.beVisible()
}
} }
else -> { else -> {
ensureBackgroundThread { ensureBackgroundThread {
@ -150,9 +160,11 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
runOnUiThread { runOnUiThread {
getRecyclerAdapter()?.updateItems(listItems, text) getRecyclerAdapter()?.updateItems(listItems, text)
mimetypes_fastscroller.beVisibleIf(listItems.isNotEmpty()) binding.apply {
mimetypes_placeholder.beVisibleIf(listItems.isEmpty()) mimetypesFastscroller.beVisibleIf(listItems.isNotEmpty())
mimetypes_placeholder_2.beGone() mimetypesPlaceholder.beVisibleIf(listItems.isEmpty())
mimetypesPlaceholder2.beGone()
}
} }
} }
} }
@ -199,7 +211,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
} }
override fun columnCountChanged() { override fun columnCountChanged() {
(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount = config.fileColumnCnt (binding.mimetypesList.layoutManager as MyGridLayoutManager).spanCount = config.fileColumnCnt
refreshMenuItems() refreshMenuItems()
getRecyclerAdapter()?.apply { getRecyclerAdapter()?.apply {
notifyItemRangeChanged(0, listItems.size) notifyItemRangeChanged(0, listItems.size)
@ -337,21 +349,21 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
} }
storedItems = items storedItems = items
ItemsAdapter(this as SimpleActivity, storedItems, this, mimetypes_list, false, null) { ItemsAdapter(this as SimpleActivity, storedItems, this, binding.mimetypesList, false, null) {
tryOpenPathIntent((it as ListItem).path, false) tryOpenPathIntent((it as ListItem).path, false)
}.apply { }.apply {
setupZoomListener(zoomListener) setupZoomListener(zoomListener)
mimetypes_list.adapter = this binding.mimetypesList.adapter = this
} }
if (areSystemAnimationsEnabled) { if (areSystemAnimationsEnabled) {
mimetypes_list.scheduleLayoutAnimation() binding.mimetypesList.scheduleLayoutAnimation()
} }
mimetypes_placeholder.beVisibleIf(items.isEmpty()) binding.mimetypesPlaceholder.beVisibleIf(items.isEmpty())
} }
private fun getRecyclerAdapter() = mimetypes_list.adapter as? ItemsAdapter private fun getRecyclerAdapter() = binding.mimetypesList.adapter as? ItemsAdapter
private fun showSortingDialog() { private fun showSortingDialog() {
ChangeSortingDialog(this, currentMimeType) { ChangeSortingDialog(this, currentMimeType) {
@ -396,13 +408,13 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
setupListLayoutManager() setupListLayoutManager()
} }
mimetypes_list.adapter = null binding.mimetypesList.adapter = null
initZoomListener() initZoomListener()
addItems(storedItems) addItems(storedItems)
} }
private fun setupGridLayoutManager() { private fun setupGridLayoutManager() {
val layoutManager = mimetypes_list.layoutManager as MyGridLayoutManager val layoutManager = binding.mimetypesList.layoutManager as MyGridLayoutManager
layoutManager.spanCount = config.fileColumnCnt ?: 3 layoutManager.spanCount = config.fileColumnCnt ?: 3
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
@ -417,14 +429,14 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
} }
private fun setupListLayoutManager() { private fun setupListLayoutManager() {
val layoutManager = mimetypes_list.layoutManager as MyGridLayoutManager val layoutManager = binding.mimetypesList.layoutManager as MyGridLayoutManager
layoutManager.spanCount = 1 layoutManager.spanCount = 1
zoomListener = null zoomListener = null
} }
private fun initZoomListener() { private fun initZoomListener() {
if (config.getFolderViewType(currentMimeType) == VIEW_TYPE_GRID) { if (config.getFolderViewType(currentMimeType) == VIEW_TYPE_GRID) {
val layoutManager = mimetypes_list.layoutManager as MyGridLayoutManager val layoutManager = binding.mimetypesList.layoutManager as MyGridLayoutManager
zoomListener = object : MyRecyclerView.MyZoomListener { zoomListener = object : MyRecyclerView.MyZoomListener {
override fun zoomIn() { override fun zoomIn() {
if (layoutManager.spanCount > 1) { if (layoutManager.spanCount > 1) {

View File

@ -16,15 +16,13 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.isPiePlus import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.ActivityPdfViewerBinding
import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
import kotlinx.android.synthetic.main.activity_pdf_viewer.pdf_viewer
import kotlinx.android.synthetic.main.activity_pdf_viewer.pdf_viewer_appbar
import kotlinx.android.synthetic.main.activity_pdf_viewer.pdf_viewer_toolbar
import kotlinx.android.synthetic.main.activity_pdf_viewer.top_shadow
class PDFViewerActivity : SimpleActivity() { class PDFViewerActivity : SimpleActivity() {
private lateinit var binding: ActivityPdfViewerBinding
private var realFilePath = "" private var realFilePath = ""
private var isFullScreen = false private var isFullScreen = false
private var passwordDialog: EnterPasswordDialog? = null private var passwordDialog: EnterPasswordDialog? = null
@ -33,14 +31,15 @@ class PDFViewerActivity : SimpleActivity() {
showTransparentTop = true showTransparentTop = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_pdf_viewer) binding = ActivityPdfViewerBinding.inflate(layoutInflater)
setContentView(binding.root)
if (checkAppSideloading()) { if (checkAppSideloading()) {
return return
} }
checkNotchSupport() checkNotchSupport()
pdf_viewer_toolbar.apply { binding.pdfViewerToolbar.apply {
setTitleTextColor(Color.WHITE) setTitleTextColor(Color.WHITE)
overflowIcon = resources.getColoredDrawableWithColor(R.drawable.ic_three_dots_vector, Color.WHITE) overflowIcon = resources.getColoredDrawableWithColor(R.drawable.ic_three_dots_vector, Color.WHITE)
navigationIcon = resources.getColoredDrawableWithColor(R.drawable.ic_arrow_left_vector, Color.WHITE) navigationIcon = resources.getColoredDrawableWithColor(R.drawable.ic_arrow_left_vector, Color.WHITE)
@ -48,7 +47,7 @@ class PDFViewerActivity : SimpleActivity() {
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) { if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
realFilePath = intent.extras?.get(REAL_FILE_PATH)?.toString() ?: "" realFilePath = intent.extras?.get(REAL_FILE_PATH)?.toString() ?: ""
pdf_viewer_toolbar.title = realFilePath.getFilenameFromPath() binding.pdfViewerToolbar.title = realFilePath.getFilenameFromPath()
} }
setupMenu() setupMenu()
@ -61,8 +60,8 @@ class PDFViewerActivity : SimpleActivity() {
} }
private fun setupMenu() { private fun setupMenu() {
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight (binding.pdfViewerAppbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
pdf_viewer_toolbar.menu.apply { binding.pdfViewerToolbar.menu.apply {
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty() findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
findItem(R.id.menu_print).setOnMenuItemClickListener { findItem(R.id.menu_print).setOnMenuItemClickListener {
printText() printText()
@ -70,24 +69,24 @@ class PDFViewerActivity : SimpleActivity() {
} }
} }
pdf_viewer_toolbar.setNavigationOnClickListener { binding.pdfViewerToolbar.setNavigationOnClickListener {
finish() finish()
} }
if (!portrait && navigationBarOnSide && navigationBarWidth > 0) { if (!portrait && navigationBarOnSide && navigationBarWidth > 0) {
pdf_viewer_appbar.setPadding(0, 0, navigationBarWidth, 0) binding.pdfViewerAppbar.setPadding(0, 0, navigationBarWidth, 0)
} else { } else {
pdf_viewer_appbar.setPadding(0, 0, 0, 0) binding.pdfViewerAppbar.setPadding(0, 0, 0, 0)
} }
} }
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight (binding.pdfViewerAppbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
if (!portrait && navigationBarOnSide && navigationBarWidth > 0) { if (!portrait && navigationBarOnSide && navigationBarWidth > 0) {
pdf_viewer_appbar.setPadding(0, 0, navigationBarWidth, 0) binding.pdfViewerAppbar.setPadding(0, 0, navigationBarWidth, 0)
} else { } else {
pdf_viewer_appbar.setPadding(0, 0, 0, 0) binding.pdfViewerAppbar.setPadding(0, 0, 0, 0)
} }
} }
@ -103,8 +102,8 @@ class PDFViewerActivity : SimpleActivity() {
private fun loadPdfViewer(uri: Uri, filePassword: String? = null) { private fun loadPdfViewer(uri: Uri, filePassword: String? = null) {
val primaryColor = getProperPrimaryColor() val primaryColor = getProperPrimaryColor()
pdf_viewer.setBackgroundColor(getProperBackgroundColor()) binding.pdfViewer.setBackgroundColor(getProperBackgroundColor())
pdf_viewer.fromUri(uri) binding.pdfViewer.fromUri(uri)
.password(filePassword) .password(filePassword)
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor)) .scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
.spacing(15) .spacing(15)
@ -140,7 +139,7 @@ class PDFViewerActivity : SimpleActivity() {
val filename = getFilenameFromUri(uri) val filename = getFilenameFromUri(uri)
if (filename.isNotEmpty()) { if (filename.isNotEmpty()) {
pdf_viewer_toolbar.title = filename binding.pdfViewerToolbar.title = filename
} }
} }
@ -163,14 +162,14 @@ class PDFViewerActivity : SimpleActivity() {
showSystemUI(true) showSystemUI(true)
} }
top_shadow.animate().alpha(newAlpha).start() binding.topShadow.animate().alpha(newAlpha).start()
pdf_viewer_appbar.animate().alpha(newAlpha).withStartAction { binding.pdfViewerAppbar.animate().alpha(newAlpha).withStartAction {
if (newAlpha == 1f) { if (newAlpha == 1f) {
pdf_viewer_appbar.beVisible() binding.pdfViewerAppbar.beVisible()
} }
}.withEndAction { }.withEndAction {
if (newAlpha == 0f) { if (newAlpha == 0f) {
pdf_viewer_appbar.beGone() binding.pdfViewerAppbar.beGone()
} }
}.start() }.start()

View File

@ -21,11 +21,10 @@ import com.simplemobiletools.commons.helpers.SAVE_DISCARD_PROMPT_INTERVAL
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.views.MyEditText import com.simplemobiletools.commons.views.MyEditText
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.ActivityReadTextBinding
import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog import com.simplemobiletools.filemanager.pro.dialogs.SaveAsDialog
import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.extensions.openPath import com.simplemobiletools.filemanager.pro.extensions.openPath
import com.simplemobiletools.filemanager.pro.views.GestureEditText import com.simplemobiletools.filemanager.pro.views.GestureEditText
import kotlinx.android.synthetic.main.activity_read_text.*
import java.io.File import java.io.File
import java.io.OutputStream import java.io.OutputStream
@ -40,6 +39,7 @@ class ReadTextActivity : SimpleActivity() {
private var searchMatches = emptyList<Int>() private var searchMatches = emptyList<Int>()
private var isSearchActive = false private var isSearchActive = false
private lateinit var binding: ActivityReadTextBinding
private lateinit var searchQueryET: MyEditText private lateinit var searchQueryET: MyEditText
private lateinit var searchPrevBtn: ImageView private lateinit var searchPrevBtn: ImageView
private lateinit var searchNextBtn: ImageView private lateinit var searchNextBtn: ImageView
@ -48,10 +48,13 @@ class ReadTextActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_read_text) binding = ActivityReadTextBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu() setupOptionsMenu()
updateMaterialActivityViews(read_text_coordinator, read_text_view, useTransparentNavigation = true, useTopSearchMenu = false) binding.apply {
setupMaterialScrollListener(read_text_holder, read_text_toolbar) updateMaterialActivityViews(readTextCoordinator, readTextView, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(readTextHolder, readTextToolbar)
}
searchQueryET = findViewById(R.id.search_query) searchQueryET = findViewById(R.id.search_query)
searchPrevBtn = findViewById(R.id.search_previous) searchPrevBtn = findViewById(R.id.search_previous)
@ -75,10 +78,10 @@ class ReadTextActivity : SimpleActivity() {
val filename = getFilenameFromUri(uri) val filename = getFilenameFromUri(uri)
if (filename.isNotEmpty()) { if (filename.isNotEmpty()) {
read_text_toolbar.title = Uri.decode(filename) binding.readTextToolbar.title = Uri.decode(filename)
} }
read_text_view.onGlobalLayout { binding.readTextView.onGlobalLayout {
ensureBackgroundThread { ensureBackgroundThread {
checkIntent(uri) checkIntent(uri)
} }
@ -89,7 +92,7 @@ class ReadTextActivity : SimpleActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(read_text_toolbar, NavigationIcon.Arrow) setupToolbar(binding.readTextToolbar, NavigationIcon.Arrow)
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
@ -107,7 +110,7 @@ class ReadTextActivity : SimpleActivity() {
} }
override fun onBackPressed() { override fun onBackPressed() {
val hasUnsavedChanges = originalText != read_text_view.text.toString() val hasUnsavedChanges = originalText != binding.readTextView.text.toString()
when { when {
isSearchActive -> closeSearch() isSearchActive -> closeSearch()
hasUnsavedChanges && System.currentTimeMillis() - lastSavePromptTS > SAVE_DISCARD_PROMPT_INTERVAL -> { hasUnsavedChanges && System.currentTimeMillis() - lastSavePromptTS > SAVE_DISCARD_PROMPT_INTERVAL -> {
@ -125,7 +128,7 @@ class ReadTextActivity : SimpleActivity() {
} }
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
read_text_toolbar.setOnMenuItemClickListener { menuItem -> binding.readTextToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.menu_search -> openSearch() R.id.menu_search -> openSearch()
R.id.menu_save -> saveText() R.id.menu_save -> saveText()
@ -139,11 +142,11 @@ class ReadTextActivity : SimpleActivity() {
private fun openSearch() { private fun openSearch() {
isSearchActive = true isSearchActive = true
search_wrapper.beVisible() binding.searchWrapper.beVisible()
showKeyboard(searchQueryET) showKeyboard(searchQueryET)
read_text_view.requestFocus() binding.readTextView.requestFocus()
read_text_view.setSelection(0) binding.readTextView.setSelection(0)
searchQueryET.postDelayed({ searchQueryET.postDelayed({
searchQueryET.requestFocus() searchQueryET.requestFocus()
@ -187,7 +190,7 @@ class ReadTextActivity : SimpleActivity() {
private fun saveTextContent(outputStream: OutputStream?, shouldExitAfterSaving: Boolean, shouldOverwriteOriginalText: Boolean) { private fun saveTextContent(outputStream: OutputStream?, shouldExitAfterSaving: Boolean, shouldOverwriteOriginalText: Boolean) {
if (outputStream != null) { if (outputStream != null) {
val currentText = read_text_view.text.toString() val currentText = binding.readTextView.text.toString()
outputStream.bufferedWriter().use { it.write(currentText) } outputStream.bufferedWriter().use { it.write(currentText) }
toast(R.string.file_saved) toast(R.string.file_saved)
hideKeyboard() hideKeyboard()
@ -215,7 +218,7 @@ class ReadTextActivity : SimpleActivity() {
} }
} }
webView.loadData(read_text_view.text.toString(), "text/plain", "UTF-8") webView.loadData(binding.readTextView.text.toString(), "text/plain", "UTF-8")
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)
} }
@ -264,11 +267,11 @@ class ReadTextActivity : SimpleActivity() {
} }
runOnUiThread { runOnUiThread {
read_text_view.setText(originalText) binding.readTextView.setText(originalText)
if (originalText.isNotEmpty()) { if (originalText.isNotEmpty()) {
hideKeyboard() hideKeyboard()
} else { } else {
showKeyboard(read_text_view) showKeyboard(binding.readTextView)
} }
} }
} }
@ -299,7 +302,7 @@ class ReadTextActivity : SimpleActivity() {
false false
}) })
search_wrapper.setBackgroundColor(getProperPrimaryColor()) binding.searchWrapper.setBackgroundColor(getProperPrimaryColor())
val contrastColor = getProperPrimaryColor().getContrastColor() val contrastColor = getProperPrimaryColor().getContrastColor()
arrayListOf(searchPrevBtn, searchNextBtn, searchClearBtn).forEach { arrayListOf(searchPrevBtn, searchNextBtn, searchClearBtn).forEach {
it.applyColorFilter(contrastColor) it.applyColorFilter(contrastColor)
@ -307,16 +310,16 @@ class ReadTextActivity : SimpleActivity() {
} }
private fun searchTextChanged(text: String) { private fun searchTextChanged(text: String) {
read_text_view.text?.clearBackgroundSpans() binding.readTextView.text?.clearBackgroundSpans()
if (text.isNotBlank() && text.length > 1) { if (text.isNotBlank() && text.length > 1) {
searchMatches = read_text_view.value.searchMatches(text) searchMatches = binding.readTextView.value.searchMatches(text)
read_text_view.highlightText(text, getProperPrimaryColor()) binding.readTextView.highlightText(text, getProperPrimaryColor())
} }
if (searchMatches.isNotEmpty()) { if (searchMatches.isNotEmpty()) {
read_text_view.requestFocus() binding.readTextView.requestFocus()
read_text_view.setSelection(searchMatches.getOrNull(searchIndex) ?: 0) binding.readTextView.setSelection(searchMatches.getOrNull(searchIndex) ?: 0)
} }
searchQueryET.postDelayed({ searchQueryET.postDelayed({
@ -331,7 +334,7 @@ class ReadTextActivity : SimpleActivity() {
searchIndex = searchMatches.lastIndex searchIndex = searchMatches.lastIndex
} }
selectSearchMatch(read_text_view) selectSearchMatch(binding.readTextView)
} }
private fun goToNextSearchResult() { private fun goToNextSearchResult() {
@ -341,13 +344,13 @@ class ReadTextActivity : SimpleActivity() {
searchIndex = 0 searchIndex = 0
} }
selectSearchMatch(read_text_view) selectSearchMatch(binding.readTextView)
} }
private fun closeSearch() { private fun closeSearch() {
searchQueryET.text?.clear() searchQueryET.text?.clear()
isSearchActive = false isSearchActive = false
search_wrapper.beGone() binding.searchWrapper.beGone()
hideKeyboard() hideKeyboard()
} }

View File

@ -8,14 +8,17 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.NavigationIcon import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.ActivitySaveAsBinding
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.activity_save_as.activity_save_as_toolbar
import java.io.File import java.io.File
class SaveAsActivity : SimpleActivity() { class SaveAsActivity : SimpleActivity() {
private lateinit var binding: ActivitySaveAsBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_save_as) binding = ActivitySaveAsBinding.inflate(layoutInflater)
setContentView(binding.root)
if (intent.action == Intent.ACTION_SEND && intent.extras?.containsKey(Intent.EXTRA_STREAM) == true) { if (intent.action == Intent.ACTION_SEND && intent.extras?.containsKey(Intent.EXTRA_STREAM) == true) {
FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden(), showFAB = true, showFavoritesButton = true) { FilePickerDialog(this, pickFile = false, showHidden = config.shouldShowHidden(), showFAB = true, showFavoritesButton = true) {
@ -59,6 +62,6 @@ class SaveAsActivity : SimpleActivity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(activity_save_as_toolbar, NavigationIcon.Arrow) setupToolbar(binding.activitySaveAsToolbar, NavigationIcon.Arrow)
} }
} }

View File

@ -10,26 +10,30 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.databinding.ActivitySettingsBinding
import com.simplemobiletools.filemanager.pro.dialogs.ManageVisibleTabsDialog import com.simplemobiletools.filemanager.pro.dialogs.ManageVisibleTabsDialog
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
import kotlinx.android.synthetic.main.activity_settings.* import java.util.Locale
import java.util.*
import kotlin.system.exitProcess import kotlin.system.exitProcess
class SettingsActivity : SimpleActivity() { class SettingsActivity : SimpleActivity() {
private lateinit var binding: ActivitySettingsBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings) binding = ActivitySettingsBinding.inflate(layoutInflater)
updateMaterialActivityViews(settings_coordinator, settings_holder, useTransparentNavigation = true, useTopSearchMenu = false) setContentView(binding.root)
setupMaterialScrollListener(settings_nested_scrollview, settings_toolbar) binding.apply {
updateMaterialActivityViews(settingsCoordinator, settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(settingsNestedScrollview, settingsToolbar)
}
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(settings_toolbar, NavigationIcon.Arrow) setupToolbar(binding.settingsToolbar, NavigationIcon.Arrow)
setupCustomizeColors() setupCustomizeColors()
setupUseEnglish() setupUseEnglish()
@ -47,65 +51,71 @@ class SettingsActivity : SimpleActivity() {
setupKeepLastModified() setupKeepLastModified()
setupDeleteConfirmation() setupDeleteConfirmation()
setupEnableRootAccess() setupEnableRootAccess()
updateTextColors(settings_nested_scrollview) updateTextColors(binding.settingsNestedScrollview)
arrayOf( binding.apply {
settings_color_customization_section_label, arrayOf(
settings_general_settings_label, settingsColorCustomizationSectionLabel,
settings_visibility_label, settingsGeneralSettingsLabel,
settings_scrolling_label, settingsVisibilityLabel,
settings_file_operations_label, settingsScrollingLabel,
settings_security_label settingsFileOperationsLabel,
).forEach { settingsSecurityLabel
it.setTextColor(getProperPrimaryColor()) ).forEach {
it.setTextColor(getProperPrimaryColor())
}
} }
} }
private fun setupCustomizeColors() { private fun setupCustomizeColors() {
settings_color_customization_holder.setOnClickListener { binding.settingsColorCustomizationHolder.setOnClickListener {
startCustomizationActivity() startCustomizationActivity()
} }
} }
private fun setupUseEnglish() { private fun setupUseEnglish() {
settings_use_english_holder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus()) binding.apply {
settings_use_english.isChecked = config.useEnglish settingsUseEnglishHolder.beVisibleIf((config.wasUseEnglishToggled || Locale.getDefault().language != "en") && !isTiramisuPlus())
settings_use_english_holder.setOnClickListener { settingsUseEnglish.isChecked = config.useEnglish
settings_use_english.toggle() settingsUseEnglishHolder.setOnClickListener {
config.useEnglish = settings_use_english.isChecked settingsUseEnglish.toggle()
exitProcess(0) config.useEnglish = settingsUseEnglish.isChecked
exitProcess(0)
}
} }
} }
private fun setupLanguage() { private fun setupLanguage() {
settings_language.text = Locale.getDefault().displayLanguage binding.apply {
settings_language_holder.beVisibleIf(isTiramisuPlus()) settingsLanguage.text = Locale.getDefault().displayLanguage
settings_language_holder.setOnClickListener { settingsLanguageHolder.beVisibleIf(isTiramisuPlus())
launchChangeAppLanguageIntent() settingsLanguageHolder.setOnClickListener {
launchChangeAppLanguageIntent()
}
} }
} }
private fun setupManageFavorites() { private fun setupManageFavorites() {
settings_manage_favorites_holder.setOnClickListener { binding.settingsManageFavoritesHolder.setOnClickListener {
startActivity(Intent(this, FavoritesActivity::class.java)) startActivity(Intent(this, FavoritesActivity::class.java))
} }
} }
private fun setupManageShownTabs() { private fun setupManageShownTabs() {
settings_manage_tabs_holder.setOnClickListener { binding.settingsManageTabsHolder.setOnClickListener {
ManageVisibleTabsDialog(this) ManageVisibleTabsDialog(this)
} }
} }
private fun setupChangeDateTimeFormat() { private fun setupChangeDateTimeFormat() {
settings_change_date_time_format_holder.setOnClickListener { binding.settingsChangeDateTimeFormatHolder.setOnClickListener {
ChangeDateTimeFormatDialog(this) {} ChangeDateTimeFormatDialog(this) {}
} }
} }
private fun setupFontSize() { private fun setupFontSize() {
settings_font_size.text = getFontSizeText() binding.settingsFontSize.text = getFontSizeText()
settings_font_size_holder.setOnClickListener { binding.settingsFontSizeHolder.setOnClickListener {
val items = arrayListOf( val items = arrayListOf(
RadioItem(FONT_SIZE_SMALL, getString(R.string.small)), RadioItem(FONT_SIZE_SMALL, getString(R.string.small)),
RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)), RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)),
@ -115,14 +125,14 @@ class SettingsActivity : SimpleActivity() {
RadioGroupDialog(this@SettingsActivity, items, config.fontSize) { RadioGroupDialog(this@SettingsActivity, items, config.fontSize) {
config.fontSize = it as Int config.fontSize = it as Int
settings_font_size.text = getFontSizeText() binding.settingsFontSize.text = getFontSizeText()
} }
} }
} }
private fun setupShowHidden() { private fun setupShowHidden() {
settings_show_hidden.isChecked = config.showHidden binding.settingsShowHidden.isChecked = config.showHidden
settings_show_hidden_holder.setOnClickListener { binding.settingsShowHiddenHolder.setOnClickListener {
if (config.showHidden) { if (config.showHidden) {
toggleShowHidden() toggleShowHidden()
} else { } else {
@ -134,34 +144,39 @@ class SettingsActivity : SimpleActivity() {
} }
private fun toggleShowHidden() { private fun toggleShowHidden() {
settings_show_hidden.toggle() binding.settingsShowHidden.toggle()
config.showHidden = settings_show_hidden.isChecked config.showHidden = binding.settingsShowHidden.isChecked
} }
private fun setupEnablePullToRefresh() { private fun setupEnablePullToRefresh() {
settings_enable_pull_to_refresh.isChecked = config.enablePullToRefresh binding.apply {
settings_enable_pull_to_refresh_holder.setOnClickListener { settingsEnablePullToRefresh
settings_enable_pull_to_refresh.toggle() settingsEnablePullToRefresh.isChecked = config.enablePullToRefresh
config.enablePullToRefresh = settings_enable_pull_to_refresh.isChecked settingsEnablePullToRefreshHolder.setOnClickListener {
settingsEnablePullToRefresh.toggle()
config.enablePullToRefresh = settingsEnablePullToRefresh.isChecked
}
} }
} }
private fun setupPressBackTwice() { private fun setupPressBackTwice() {
settings_press_back_twice.isChecked = config.pressBackTwice binding.apply {
settings_press_back_twice_holder.setOnClickListener { settingsPressBackTwice.isChecked = config.pressBackTwice
settings_press_back_twice.toggle() settingsPressBackTwiceHolder.setOnClickListener {
config.pressBackTwice = settings_press_back_twice.isChecked settingsPressBackTwice.toggle()
config.pressBackTwice = settingsPressBackTwice.isChecked
}
} }
} }
private fun setupHiddenItemPasswordProtection() { private fun setupHiddenItemPasswordProtection() {
settings_password_protection.isChecked = config.isHiddenPasswordProtectionOn binding.settingsPasswordProtection.isChecked = config.isHiddenPasswordProtectionOn
settings_password_protection_holder.setOnClickListener { binding.settingsPasswordProtectionHolder.setOnClickListener {
val tabToShow = if (config.isHiddenPasswordProtectionOn) config.hiddenProtectionType else SHOW_ALL_TABS val tabToShow = if (config.isHiddenPasswordProtectionOn) config.hiddenProtectionType else SHOW_ALL_TABS
SecurityDialog(this, config.hiddenPasswordHash, tabToShow) { hash, type, success -> SecurityDialog(this, config.hiddenPasswordHash, tabToShow) { hash, type, success ->
if (success) { if (success) {
val hasPasswordProtection = config.isHiddenPasswordProtectionOn val hasPasswordProtection = config.isHiddenPasswordProtectionOn
settings_password_protection.isChecked = !hasPasswordProtection binding.settingsPasswordProtection.isChecked = !hasPasswordProtection
config.isHiddenPasswordProtectionOn = !hasPasswordProtection config.isHiddenPasswordProtectionOn = !hasPasswordProtection
config.hiddenPasswordHash = if (hasPasswordProtection) "" else hash config.hiddenPasswordHash = if (hasPasswordProtection) "" else hash
config.hiddenProtectionType = type config.hiddenProtectionType = type
@ -177,13 +192,13 @@ class SettingsActivity : SimpleActivity() {
} }
private fun setupAppPasswordProtection() { private fun setupAppPasswordProtection() {
settings_app_password_protection.isChecked = config.isAppPasswordProtectionOn binding.settingsAppPasswordProtection.isChecked = config.isAppPasswordProtectionOn
settings_app_password_protection_holder.setOnClickListener { binding.settingsAppPasswordProtectionHolder.setOnClickListener {
val tabToShow = if (config.isAppPasswordProtectionOn) config.appProtectionType else SHOW_ALL_TABS val tabToShow = if (config.isAppPasswordProtectionOn) config.appProtectionType else SHOW_ALL_TABS
SecurityDialog(this, config.appPasswordHash, tabToShow) { hash, type, success -> SecurityDialog(this, config.appPasswordHash, tabToShow) { hash, type, success ->
if (success) { if (success) {
val hasPasswordProtection = config.isAppPasswordProtectionOn val hasPasswordProtection = config.isAppPasswordProtectionOn
settings_app_password_protection.isChecked = !hasPasswordProtection binding.settingsAppPasswordProtection.isChecked = !hasPasswordProtection
config.isAppPasswordProtectionOn = !hasPasswordProtection config.isAppPasswordProtectionOn = !hasPasswordProtection
config.appPasswordHash = if (hasPasswordProtection) "" else hash config.appPasswordHash = if (hasPasswordProtection) "" else hash
config.appProtectionType = type config.appProtectionType = type
@ -199,13 +214,13 @@ class SettingsActivity : SimpleActivity() {
} }
private fun setupFileDeletionPasswordProtection() { private fun setupFileDeletionPasswordProtection() {
settings_file_deletion_password_protection.isChecked = config.isDeletePasswordProtectionOn binding.settingsFileDeletionPasswordProtection.isChecked = config.isDeletePasswordProtectionOn
settings_file_deletion_password_protection_holder.setOnClickListener { binding.settingsFileDeletionPasswordProtectionHolder.setOnClickListener {
val tabToShow = if (config.isDeletePasswordProtectionOn) config.deleteProtectionType else SHOW_ALL_TABS val tabToShow = if (config.isDeletePasswordProtectionOn) config.deleteProtectionType else SHOW_ALL_TABS
SecurityDialog(this, config.deletePasswordHash, tabToShow) { hash, type, success -> SecurityDialog(this, config.deletePasswordHash, tabToShow) { hash, type, success ->
if (success) { if (success) {
val hasPasswordProtection = config.isDeletePasswordProtectionOn val hasPasswordProtection = config.isDeletePasswordProtectionOn
settings_file_deletion_password_protection.isChecked = !hasPasswordProtection binding.settingsFileDeletionPasswordProtection.isChecked = !hasPasswordProtection
config.isDeletePasswordProtectionOn = !hasPasswordProtection config.isDeletePasswordProtectionOn = !hasPasswordProtection
config.deletePasswordHash = if (hasPasswordProtection) "" else hash config.deletePasswordHash = if (hasPasswordProtection) "" else hash
config.deleteProtectionType = type config.deleteProtectionType = type
@ -221,37 +236,43 @@ class SettingsActivity : SimpleActivity() {
} }
private fun setupKeepLastModified() { private fun setupKeepLastModified() {
settings_keep_last_modified.isChecked = config.keepLastModified binding.apply {
settings_keep_last_modified_holder.setOnClickListener { settingsKeepLastModified.isChecked = config.keepLastModified
settings_keep_last_modified.toggle() settingsKeepLastModifiedHolder.setOnClickListener {
config.keepLastModified = settings_keep_last_modified.isChecked settingsKeepLastModified.toggle()
config.keepLastModified = settingsKeepLastModified.isChecked
}
} }
} }
private fun setupDeleteConfirmation() { private fun setupDeleteConfirmation() {
settings_skip_delete_confirmation.isChecked = config.skipDeleteConfirmation binding.apply {
settings_skip_delete_confirmation_holder.setOnClickListener { settingsSkipDeleteConfirmation.isChecked = config.skipDeleteConfirmation
settings_skip_delete_confirmation.toggle() settingsSkipDeleteConfirmationHolder.setOnClickListener {
config.skipDeleteConfirmation = settings_skip_delete_confirmation.isChecked settingsSkipDeleteConfirmation.toggle()
config.skipDeleteConfirmation = settingsSkipDeleteConfirmation.isChecked
}
} }
} }
private fun setupEnableRootAccess() { private fun setupEnableRootAccess() {
settings_enable_root_access_holder.beVisibleIf(config.isRootAvailable) binding.apply {
settings_enable_root_access.isChecked = config.enableRootAccess settingsEnableRootAccessHolder.beVisibleIf(config.isRootAvailable)
settings_enable_root_access_holder.setOnClickListener { settingsEnableRootAccess.isChecked = config.enableRootAccess
if (!config.enableRootAccess) { settingsEnableRootAccessHolder.setOnClickListener {
RootHelpers(this).askRootIfNeeded { if (!config.enableRootAccess) {
toggleRootAccess(it) RootHelpers(this@SettingsActivity).askRootIfNeeded {
toggleRootAccess(it)
}
} else {
toggleRootAccess(false)
} }
} else {
toggleRootAccess(false)
} }
} }
} }
private fun toggleRootAccess(enable: Boolean) { private fun toggleRootAccess(enable: Boolean) {
settings_enable_root_access.isChecked = enable binding.settingsEnableRootAccess.isChecked = enable
config.enableRootAccess = enable config.enableRootAccess = enable
} }
} }