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

View File

@ -10,28 +10,32 @@ import com.simplemobiletools.commons.helpers.NavigationIcon
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.adapters.ManageFavoritesAdapter
import com.simplemobiletools.filemanager.pro.databinding.ActivityFavoritesBinding
import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.activity_favorites.*
class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener {
private lateinit var binding: ActivityFavoritesBinding
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_favorites)
binding = ActivityFavoritesBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu()
updateFavorites()
updateMaterialActivityViews(manage_favorites_coordinator, manage_favorites_list, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(manage_favorites_list, manage_favorites_toolbar)
binding.apply {
updateMaterialActivityViews(manageFavoritesCoordinator, manageFavoritesList, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(manageFavoritesList, manageFavoritesToolbar)
}
}
override fun onResume() {
super.onResume()
setupToolbar(manage_favorites_toolbar, NavigationIcon.Arrow)
setupToolbar(binding.manageFavoritesToolbar, NavigationIcon.Arrow)
}
private fun setupOptionsMenu() {
manage_favorites_toolbar.setOnMenuItemClickListener { menuItem ->
binding.manageFavoritesToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.add_favorite -> addFavorite()
else -> return@setOnMenuItemClickListener false
@ -41,22 +45,24 @@ class FavoritesActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
private fun updateFavorites() {
val favorites = ArrayList<String>()
config.favorites.mapTo(favorites) { it }
manage_favorites_placeholder.beVisibleIf(favorites.isEmpty())
manage_favorites_placeholder.setTextColor(getProperTextColor())
binding.apply {
val favorites = ArrayList<String>()
config.favorites.mapTo(favorites) { it }
manageFavoritesPlaceholder.beVisibleIf(favorites.isEmpty())
manageFavoritesPlaceholder.setTextColor(getProperTextColor())
manage_favorites_placeholder_2.apply {
paintFlags = paintFlags or Paint.UNDERLINE_TEXT_FLAG
beVisibleIf(favorites.isEmpty())
setTextColor(getProperPrimaryColor())
setOnClickListener {
addFavorite()
manageFavoritesPlaceholder2.apply {
paintFlags = paintFlags or Paint.UNDERLINE_TEXT_FLAG
beVisibleIf(favorites.isEmpty())
setTextColor(getProperPrimaryColor())
setOnClickListener {
addFavorite()
}
}
}
ManageFavoritesAdapter(this, favorites, this, manage_favorites_list) { }.apply {
manage_favorites_list.adapter = this
ManageFavoritesAdapter(this@FavoritesActivity, favorites, this@FavoritesActivity, manageFavoritesList) { }.apply {
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.R
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.ChangeViewTypeDialog
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.interfaces.ItemOperationsListener
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 java.io.File
@ -50,6 +46,7 @@ class MainActivity : SimpleActivity() {
private val BACK_PRESS_TIMEOUT = 5000
private val MANAGE_STORAGE_RC = 201
private val PICKED_PATH = "picked_path"
private lateinit var binding: ActivityMainBinding
private var wasBackJustPressed = false
private var mIsPasswordProtectionPending = false
private var mWasProtectionHandled = false
@ -63,7 +60,8 @@ class MainActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
appLaunched(BuildConfig.APPLICATION_ID)
setupOptionsMenu()
refreshMenuItems()
@ -79,7 +77,7 @@ class MainActivity : SimpleActivity() {
storeStateVariables()
setupTabs()
updateMaterialActivityViews(main_coordinator, null, useTransparentNavigation = false, useTopSearchMenu = true)
updateMaterialActivityViews(binding.mainCoordinator, null, useTransparentNavigation = false, useTopSearchMenu = true)
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
@ -132,7 +130,7 @@ class MainActivity : SimpleActivity() {
}
}
if (main_view_pager.adapter == null && mWasProtectionHandled) {
if (binding.mainViewPager.adapter == null && mWasProtectionHandled) {
initFragments()
}
}
@ -140,7 +138,7 @@ class MainActivity : SimpleActivity() {
override fun onPause() {
super.onPause()
storeStateVariables()
config.lastUsedViewPagerPage = main_view_pager.currentItem
config.lastUsedViewPagerPage = binding.mainViewPager.currentItem
}
override fun onDestroy() {
@ -150,11 +148,11 @@ class MainActivity : SimpleActivity() {
override fun onBackPressed() {
val currentFragment = getCurrentFragment()
if (main_menu.isSearchOpen) {
main_menu.closeSearch()
if (binding.mainMenu.isSearchOpen) {
binding.mainMenu.closeSearch()
} else if (currentFragment is RecentsFragment || currentFragment is StorageFragment) {
super.onBackPressed()
} else if (currentFragment!!.breadcrumbs.getItemCount() <= 1) {
} else if ((currentFragment as ItemsFragment).getBreadcrumbs().getItemCount() <= 1) {
if (!wasBackJustPressed && config.pressBackTwice) {
wasBackJustPressed = true
toast(R.string.press_back_again)
@ -165,8 +163,8 @@ class MainActivity : SimpleActivity() {
finish()
}
} else {
currentFragment.breadcrumbs?.removeBreadcrumb()
openPath(currentFragment.breadcrumbs.getLastItem().path)
currentFragment.getBreadcrumbs().removeBreadcrumb()
openPath(currentFragment.getBreadcrumbs().getLastItem().path)
}
}
@ -176,7 +174,7 @@ class MainActivity : SimpleActivity() {
val currentViewType = config.getFolderViewType(currentFragment.currentPath)
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.change_view_type).isVisible = currentFragment !is StorageFragment
@ -200,49 +198,51 @@ class MainActivity : SimpleActivity() {
}
private fun setupOptionsMenu() {
main_menu.getToolbar().inflateMenu(R.menu.menu)
main_menu.toggleHideOnScroll(false)
main_menu.setupMenu()
binding.mainMenu.apply {
getToolbar().inflateMenu(R.menu.menu)
toggleHideOnScroll(false)
setupMenu()
main_menu.onSearchClosedListener = {
getAllFragments().forEach {
it?.searchQueryChanged("")
onSearchClosedListener = {
getAllFragments().forEach {
it?.searchQueryChanged("")
}
}
}
main_menu.onSearchTextChangedListener = { text ->
getCurrentFragment()?.searchQueryChanged(text)
}
onSearchTextChangedListener = { text ->
getCurrentFragment()?.searchQueryChanged(text)
}
main_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
if (getCurrentFragment() == null) {
getToolbar().setOnMenuItemClickListener { menuItem ->
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
}
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) {
super.onSaveInstanceState(outState)
outState.putString(PICKED_PATH, items_fragment?.currentPath ?: "")
outState.putString(PICKED_PATH, getItemsFragment()?.currentPath ?: "")
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
}
@ -251,8 +251,8 @@ 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.onGlobalLayout {
if (binding.mainViewPager.adapter == null) {
binding.mainViewPager.onGlobalLayout {
restorePath(path)
}
} else {
@ -287,7 +287,7 @@ class MainActivity : SimpleActivity() {
private fun updateMenuColors() {
updateStatusbarColor(getProperBackgroundColor())
main_menu.updateColors()
binding.mainMenu.updateColors()
}
private fun storeStateVariables() {
@ -304,11 +304,11 @@ class MainActivity : SimpleActivity() {
handleStoragePermission {
checkOTGPath()
if (it) {
if (main_view_pager.adapter == null) {
if (binding.mainViewPager.adapter == null) {
initFragments()
}
main_view_pager.onGlobalLayout {
binding.mainViewPager.onGlobalLayout {
initFileManager(!hadPermission)
}
} else {
@ -368,41 +368,43 @@ class MainActivity : SimpleActivity() {
tryOpenPathIntent(data.path!!, false, finishActivity = true)
}
main_view_pager.currentItem = 0
binding.mainViewPager.currentItem = 0
} else {
openPath(config.homeFolder)
}
if (refreshRecents) {
recents_fragment?.refreshFragment()
getRecentsFragment()?.refreshFragment()
}
}
private fun initFragments() {
main_view_pager.adapter = ViewPagerAdapter(this, mTabsToShow)
main_view_pager.offscreenPageLimit = 2
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {}
binding.mainViewPager.apply {
adapter = ViewPagerAdapter(this@MainActivity, mTabsToShow)
offscreenPageLimit = 2
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) {
main_tabs_holder.getTabAt(position)?.select()
getAllFragments().forEach {
(it as? ItemOperationsListener)?.finishActMode()
override fun onPageSelected(position: Int) {
binding.mainTabsHolder.getTabAt(position)?.select()
getAllFragments().forEach {
(it as? ItemOperationsListener)?.finishActMode()
}
refreshMenuItems()
}
})
currentItem = config.lastUsedViewPagerPage
onGlobalLayout {
refreshMenuItems()
}
})
main_view_pager.currentItem = config.lastUsedViewPagerPage
main_view_pager.onGlobalLayout {
refreshMenuItems()
}
}
private fun setupTabs() {
main_tabs_holder.removeAllTabs()
binding.mainTabsHolder.removeAllTabs()
val action = intent.action
val isPickFileIntent = action == RingtoneManager.ACTION_RINGTONE_PICKER || action == Intent.ACTION_GET_CONTENT || action == Intent.ACTION_PICK
val isCreateDocumentIntent = action == Intent.ACTION_CREATE_DOCUMENT
@ -421,41 +423,45 @@ class MainActivity : SimpleActivity() {
mTabsToShow.forEachIndexed { index, value ->
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<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
AutofitHelper.create(customView?.findViewById(R.id.tab_item_label))
main_tabs_holder.addTab(this)
binding.mainTabsHolder.addTab(this)
}
}
}
main_tabs_holder.onTabSelectionChanged(
tabUnselectedAction = {
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
},
tabSelectedAction = {
main_menu.closeSearch()
main_view_pager.currentItem = it.position
updateBottomTabItemColors(it.customView, true, getSelectedTabDrawableIds()[it.position])
}
)
binding.mainTabsHolder.apply {
onTabSelectionChanged(
tabUnselectedAction = {
updateBottomTabItemColors(it.customView, false, getDeselectedTabDrawableIds()[it.position])
},
tabSelectedAction = {
binding.mainMenu.closeSearch()
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() {
val activeView = main_tabs_holder.getTabAt(main_view_pager.currentItem)?.customView
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[main_view_pager.currentItem])
binding.apply {
val activeView = mainTabsHolder.getTabAt(mainViewPager.currentItem)?.customView
updateBottomTabItemColors(activeView, true, getSelectedTabDrawableIds()[mainViewPager.currentItem])
getInactiveTabIndexes(main_view_pager.currentItem).forEach { index ->
val inactiveView = main_tabs_holder.getTabAt(index)?.customView
updateBottomTabItemColors(inactiveView, false, getDeselectedTabDrawableIds()[index])
getInactiveTabIndexes(mainViewPager.currentItem).forEach { index ->
val inactiveView = mainTabsHolder.getTabAt(index)?.customView
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 {
@ -504,7 +510,7 @@ class MainActivity : SimpleActivity() {
newPath = internalStoragePath
}
items_fragment?.openPath(newPath, forceRefresh)
getItemsFragment()?.openPath(newPath, forceRefresh)
}
private fun goHome() {
@ -714,12 +720,12 @@ class MainActivity : SimpleActivity() {
}
fun openedDirectory() {
if (main_menu.isSearchOpen) {
main_menu.closeSearch()
if (binding.mainMenu.isSearchOpen) {
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> {
val showTabs = config.showTabs
@ -759,24 +765,28 @@ class MainActivity : SimpleActivity() {
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 fragments = arrayListOf<MyViewPagerFragment>()
val fragments = arrayListOf<MyViewPagerFragment<*>>()
if (showTabs and TAB_FILES != 0) {
fragments.add(items_fragment)
fragments.add(getItemsFragment())
}
if (showTabs and TAB_RECENT_FILES != 0) {
fragments.add(recents_fragment)
fragments.add(getRecentsFragment())
}
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)

View File

@ -21,6 +21,7 @@ import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.filemanager.pro.R
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.ChangeViewTypeDialog
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.interfaces.ItemOperationsListener
import com.simplemobiletools.filemanager.pro.models.ListItem
import kotlinx.android.synthetic.main.activity_mimetypes.*
import java.util.Locale
class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
private lateinit var binding: ActivityMimetypesBinding
private var isSearchOpen = false
private var currentMimeType = ""
private var lastSearchedText = ""
@ -43,14 +44,17 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_mimetypes)
binding = ActivityMimetypesBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu()
refreshMenuItems()
updateMaterialActivityViews(mimetypes_coordinator, mimetypes_list, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(mimetypes_list, mimetypes_toolbar)
binding.apply {
updateMaterialActivityViews(mimetypesCoordinator, mimetypesList, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(mimetypesList, mimetypesToolbar)
}
currentMimeType = intent.getStringExtra(SHOW_MIMETYPE) ?: return
mimetypes_toolbar.title = getString(
binding.mimetypesToolbar.title = getString(
when (currentMimeType) {
IMAGES -> R.string.images
VIDEOS -> R.string.videos
@ -70,20 +74,22 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
reFetchItems()
}
mimetypes_fastscroller.updateColors(getProperPrimaryColor())
mimetypes_placeholder.setTextColor(getProperTextColor())
mimetypes_placeholder_2.setTextColor(getProperTextColor())
binding.apply {
mimetypesFastscroller.updateColors(getProperPrimaryColor())
mimetypesPlaceholder.setTextColor(getProperTextColor())
mimetypesPlaceholder2.setTextColor(getProperTextColor())
}
}
override fun onResume() {
super.onResume()
setupToolbar(mimetypes_toolbar, NavigationIcon.Arrow, searchMenuItem = searchMenuItem)
setupToolbar(binding.mimetypesToolbar, NavigationIcon.Arrow, searchMenuItem = searchMenuItem)
}
private fun refreshMenuItems() {
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.temporarily_show_hidden).isVisible = !config.shouldShowHidden()
@ -94,8 +100,8 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
}
private fun setupOptionsMenu() {
setupSearch(mimetypes_toolbar.menu)
mimetypes_toolbar.setOnMenuItemClickListener { menuItem ->
setupSearch(binding.mimetypesToolbar.menu)
binding.mimetypesToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.sort -> showSortingDialog()
R.id.toggle_filename -> toggleFilenameVisibility()
@ -130,15 +136,19 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
lastSearchedText = searchText
when {
searchText.isEmpty() -> {
mimetypes_fastscroller.beVisible()
getRecyclerAdapter()?.updateItems(storedItems)
mimetypes_placeholder.beGoneIf(storedItems.isNotEmpty())
mimetypes_placeholder_2.beGone()
binding.apply {
mimetypesFastscroller.beVisible()
getRecyclerAdapter()?.updateItems(storedItems)
mimetypesPlaceholder.beGoneIf(storedItems.isNotEmpty())
mimetypesPlaceholder2.beGone()
}
}
searchText.length == 1 -> {
mimetypes_fastscroller.beGone()
mimetypes_placeholder.beVisible()
mimetypes_placeholder_2.beVisible()
binding.apply {
mimetypesFastscroller.beGone()
mimetypesPlaceholder.beVisible()
mimetypesPlaceholder2.beVisible()
}
}
else -> {
ensureBackgroundThread {
@ -150,9 +160,11 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
runOnUiThread {
getRecyclerAdapter()?.updateItems(listItems, text)
mimetypes_fastscroller.beVisibleIf(listItems.isNotEmpty())
mimetypes_placeholder.beVisibleIf(listItems.isEmpty())
mimetypes_placeholder_2.beGone()
binding.apply {
mimetypesFastscroller.beVisibleIf(listItems.isNotEmpty())
mimetypesPlaceholder.beVisibleIf(listItems.isEmpty())
mimetypesPlaceholder2.beGone()
}
}
}
}
@ -199,7 +211,7 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
}
override fun columnCountChanged() {
(mimetypes_list.layoutManager as MyGridLayoutManager).spanCount = config.fileColumnCnt
(binding.mimetypesList.layoutManager as MyGridLayoutManager).spanCount = config.fileColumnCnt
refreshMenuItems()
getRecyclerAdapter()?.apply {
notifyItemRangeChanged(0, listItems.size)
@ -337,21 +349,21 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
}
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)
}.apply {
setupZoomListener(zoomListener)
mimetypes_list.adapter = this
binding.mimetypesList.adapter = this
}
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() {
ChangeSortingDialog(this, currentMimeType) {
@ -396,13 +408,13 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
setupListLayoutManager()
}
mimetypes_list.adapter = null
binding.mimetypesList.adapter = null
initZoomListener()
addItems(storedItems)
}
private fun setupGridLayoutManager() {
val layoutManager = mimetypes_list.layoutManager as MyGridLayoutManager
val layoutManager = binding.mimetypesList.layoutManager as MyGridLayoutManager
layoutManager.spanCount = config.fileColumnCnt ?: 3
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
@ -417,14 +429,14 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
}
private fun setupListLayoutManager() {
val layoutManager = mimetypes_list.layoutManager as MyGridLayoutManager
val layoutManager = binding.mimetypesList.layoutManager as MyGridLayoutManager
layoutManager.spanCount = 1
zoomListener = null
}
private fun initZoomListener() {
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 {
override fun zoomIn() {
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.isPiePlus
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.showSystemUI
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() {
private lateinit var binding: ActivityPdfViewerBinding
private var realFilePath = ""
private var isFullScreen = false
private var passwordDialog: EnterPasswordDialog? = null
@ -33,14 +31,15 @@ class PDFViewerActivity : SimpleActivity() {
showTransparentTop = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_pdf_viewer)
binding = ActivityPdfViewerBinding.inflate(layoutInflater)
setContentView(binding.root)
if (checkAppSideloading()) {
return
}
checkNotchSupport()
pdf_viewer_toolbar.apply {
binding.pdfViewerToolbar.apply {
setTitleTextColor(Color.WHITE)
overflowIcon = resources.getColoredDrawableWithColor(R.drawable.ic_three_dots_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) {
realFilePath = intent.extras?.get(REAL_FILE_PATH)?.toString() ?: ""
pdf_viewer_toolbar.title = realFilePath.getFilenameFromPath()
binding.pdfViewerToolbar.title = realFilePath.getFilenameFromPath()
}
setupMenu()
@ -61,8 +60,8 @@ class PDFViewerActivity : SimpleActivity() {
}
private fun setupMenu() {
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
pdf_viewer_toolbar.menu.apply {
(binding.pdfViewerAppbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
binding.pdfViewerToolbar.menu.apply {
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
findItem(R.id.menu_print).setOnMenuItemClickListener {
printText()
@ -70,24 +69,24 @@ class PDFViewerActivity : SimpleActivity() {
}
}
pdf_viewer_toolbar.setNavigationOnClickListener {
binding.pdfViewerToolbar.setNavigationOnClickListener {
finish()
}
if (!portrait && navigationBarOnSide && navigationBarWidth > 0) {
pdf_viewer_appbar.setPadding(0, 0, navigationBarWidth, 0)
binding.pdfViewerAppbar.setPadding(0, 0, navigationBarWidth, 0)
} else {
pdf_viewer_appbar.setPadding(0, 0, 0, 0)
binding.pdfViewerAppbar.setPadding(0, 0, 0, 0)
}
}
override fun onConfigurationChanged(newConfig: Configuration) {
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) {
pdf_viewer_appbar.setPadding(0, 0, navigationBarWidth, 0)
binding.pdfViewerAppbar.setPadding(0, 0, navigationBarWidth, 0)
} 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) {
val primaryColor = getProperPrimaryColor()
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
pdf_viewer.fromUri(uri)
binding.pdfViewer.setBackgroundColor(getProperBackgroundColor())
binding.pdfViewer.fromUri(uri)
.password(filePassword)
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
.spacing(15)
@ -140,7 +139,7 @@ class PDFViewerActivity : SimpleActivity() {
val filename = getFilenameFromUri(uri)
if (filename.isNotEmpty()) {
pdf_viewer_toolbar.title = filename
binding.pdfViewerToolbar.title = filename
}
}
@ -163,14 +162,14 @@ class PDFViewerActivity : SimpleActivity() {
showSystemUI(true)
}
top_shadow.animate().alpha(newAlpha).start()
pdf_viewer_appbar.animate().alpha(newAlpha).withStartAction {
binding.topShadow.animate().alpha(newAlpha).start()
binding.pdfViewerAppbar.animate().alpha(newAlpha).withStartAction {
if (newAlpha == 1f) {
pdf_viewer_appbar.beVisible()
binding.pdfViewerAppbar.beVisible()
}
}.withEndAction {
if (newAlpha == 0f) {
pdf_viewer_appbar.beGone()
binding.pdfViewerAppbar.beGone()
}
}.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.views.MyEditText
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.extensions.config
import com.simplemobiletools.filemanager.pro.extensions.openPath
import com.simplemobiletools.filemanager.pro.views.GestureEditText
import kotlinx.android.synthetic.main.activity_read_text.*
import java.io.File
import java.io.OutputStream
@ -40,6 +39,7 @@ class ReadTextActivity : SimpleActivity() {
private var searchMatches = emptyList<Int>()
private var isSearchActive = false
private lateinit var binding: ActivityReadTextBinding
private lateinit var searchQueryET: MyEditText
private lateinit var searchPrevBtn: ImageView
private lateinit var searchNextBtn: ImageView
@ -48,10 +48,13 @@ class ReadTextActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_read_text)
binding = ActivityReadTextBinding.inflate(layoutInflater)
setContentView(binding.root)
setupOptionsMenu()
updateMaterialActivityViews(read_text_coordinator, read_text_view, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(read_text_holder, read_text_toolbar)
binding.apply {
updateMaterialActivityViews(readTextCoordinator, readTextView, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(readTextHolder, readTextToolbar)
}
searchQueryET = findViewById(R.id.search_query)
searchPrevBtn = findViewById(R.id.search_previous)
@ -75,10 +78,10 @@ class ReadTextActivity : SimpleActivity() {
val filename = getFilenameFromUri(uri)
if (filename.isNotEmpty()) {
read_text_toolbar.title = Uri.decode(filename)
binding.readTextToolbar.title = Uri.decode(filename)
}
read_text_view.onGlobalLayout {
binding.readTextView.onGlobalLayout {
ensureBackgroundThread {
checkIntent(uri)
}
@ -89,7 +92,7 @@ class ReadTextActivity : SimpleActivity() {
override fun onResume() {
super.onResume()
setupToolbar(read_text_toolbar, NavigationIcon.Arrow)
setupToolbar(binding.readTextToolbar, NavigationIcon.Arrow)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
@ -107,7 +110,7 @@ class ReadTextActivity : SimpleActivity() {
}
override fun onBackPressed() {
val hasUnsavedChanges = originalText != read_text_view.text.toString()
val hasUnsavedChanges = originalText != binding.readTextView.text.toString()
when {
isSearchActive -> closeSearch()
hasUnsavedChanges && System.currentTimeMillis() - lastSavePromptTS > SAVE_DISCARD_PROMPT_INTERVAL -> {
@ -125,7 +128,7 @@ class ReadTextActivity : SimpleActivity() {
}
private fun setupOptionsMenu() {
read_text_toolbar.setOnMenuItemClickListener { menuItem ->
binding.readTextToolbar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.menu_search -> openSearch()
R.id.menu_save -> saveText()
@ -139,11 +142,11 @@ class ReadTextActivity : SimpleActivity() {
private fun openSearch() {
isSearchActive = true
search_wrapper.beVisible()
binding.searchWrapper.beVisible()
showKeyboard(searchQueryET)
read_text_view.requestFocus()
read_text_view.setSelection(0)
binding.readTextView.requestFocus()
binding.readTextView.setSelection(0)
searchQueryET.postDelayed({
searchQueryET.requestFocus()
@ -187,7 +190,7 @@ class ReadTextActivity : SimpleActivity() {
private fun saveTextContent(outputStream: OutputStream?, shouldExitAfterSaving: Boolean, shouldOverwriteOriginalText: Boolean) {
if (outputStream != null) {
val currentText = read_text_view.text.toString()
val currentText = binding.readTextView.text.toString()
outputStream.bufferedWriter().use { it.write(currentText) }
toast(R.string.file_saved)
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) {
showErrorToast(e)
}
@ -264,11 +267,11 @@ class ReadTextActivity : SimpleActivity() {
}
runOnUiThread {
read_text_view.setText(originalText)
binding.readTextView.setText(originalText)
if (originalText.isNotEmpty()) {
hideKeyboard()
} else {
showKeyboard(read_text_view)
showKeyboard(binding.readTextView)
}
}
}
@ -299,7 +302,7 @@ class ReadTextActivity : SimpleActivity() {
false
})
search_wrapper.setBackgroundColor(getProperPrimaryColor())
binding.searchWrapper.setBackgroundColor(getProperPrimaryColor())
val contrastColor = getProperPrimaryColor().getContrastColor()
arrayListOf(searchPrevBtn, searchNextBtn, searchClearBtn).forEach {
it.applyColorFilter(contrastColor)
@ -307,16 +310,16 @@ class ReadTextActivity : SimpleActivity() {
}
private fun searchTextChanged(text: String) {
read_text_view.text?.clearBackgroundSpans()
binding.readTextView.text?.clearBackgroundSpans()
if (text.isNotBlank() && text.length > 1) {
searchMatches = read_text_view.value.searchMatches(text)
read_text_view.highlightText(text, getProperPrimaryColor())
searchMatches = binding.readTextView.value.searchMatches(text)
binding.readTextView.highlightText(text, getProperPrimaryColor())
}
if (searchMatches.isNotEmpty()) {
read_text_view.requestFocus()
read_text_view.setSelection(searchMatches.getOrNull(searchIndex) ?: 0)
binding.readTextView.requestFocus()
binding.readTextView.setSelection(searchMatches.getOrNull(searchIndex) ?: 0)
}
searchQueryET.postDelayed({
@ -331,7 +334,7 @@ class ReadTextActivity : SimpleActivity() {
searchIndex = searchMatches.lastIndex
}
selectSearchMatch(read_text_view)
selectSearchMatch(binding.readTextView)
}
private fun goToNextSearchResult() {
@ -341,13 +344,13 @@ class ReadTextActivity : SimpleActivity() {
searchIndex = 0
}
selectSearchMatch(read_text_view)
selectSearchMatch(binding.readTextView)
}
private fun closeSearch() {
searchQueryET.text?.clear()
isSearchActive = false
search_wrapper.beGone()
binding.searchWrapper.beGone()
hideKeyboard()
}

View File

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