misc code style updates

This commit is contained in:
tibbi 2017-08-30 20:53:51 +02:00
parent a6f6963834
commit 433d31385e
6 changed files with 43 additions and 56 deletions

View File

@ -37,7 +37,7 @@ android {
} }
dependencies { dependencies {
compile 'com.simplemobiletools:commons:2.26.9' compile 'com.simplemobiletools:commons:2.27.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
} }

View File

@ -29,17 +29,14 @@ import kotlinx.android.synthetic.main.activity_main.*
import java.util.* import java.util.*
class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener { class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
var latestFragment: ItemsFragment? = null
var mScrollStates = HashMap<String, Parcelable>()
var mStoredTextColor = 0
var currentPath = ""
companion object {
private val STORAGE_PERMISSION = 1 private val STORAGE_PERMISSION = 1
private val BACK_PRESS_TIMEOUT = 5000 private val BACK_PRESS_TIMEOUT = 5000
private var mWasBackJustPressed: Boolean = false private var latestFragment: ItemsFragment? = null
} private var scrollStates = HashMap<String, Parcelable>()
private var storedTextColor = 0
private var currentPath = ""
private var wasBackJustPressed = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -53,9 +50,9 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
updateTextColors(main_screen) updateTextColors(main_screen)
if (mStoredTextColor != config.textColor) { if (storedTextColor != config.textColor) {
mStoredTextColor = config.textColor storedTextColor = config.textColor
breadcrumbs.setTextColor(mStoredTextColor) breadcrumbs.setTextColor(storedTextColor)
openPath(currentPath) openPath(currentPath)
} }
invalidateOptionsMenu() invalidateOptionsMenu()
@ -63,7 +60,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
mStoredTextColor = config.textColor storedTextColor = config.textColor
} }
override fun onDestroy() { override fun onDestroy() {
@ -89,12 +86,12 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
val bundle = Bundle() val bundle = Bundle()
bundle.putString(PATH, realPath) bundle.putString(PATH, realPath)
if (mScrollStates.containsKey(realPath)) { if (scrollStates.containsKey(realPath)) {
bundle.putParcelable(SCROLL_STATE, mScrollStates[realPath]) bundle.putParcelable(SCROLL_STATE, scrollStates[realPath])
} }
if (latestFragment != null) { if (latestFragment != null) {
mScrollStates.put(latestFragment!!.mPath.trimEnd('/'), latestFragment!!.getScrollState()) scrollStates.put(latestFragment!!.mPath.trimEnd('/'), latestFragment!!.getScrollState())
} }
latestFragment = ItemsFragment().apply { latestFragment = ItemsFragment().apply {
@ -208,17 +205,16 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
override fun onBackPressed() { override fun onBackPressed() {
if (breadcrumbs.childCount <= 1) { if (breadcrumbs.childCount <= 1) {
if (!mWasBackJustPressed) { if (!wasBackJustPressed) {
mWasBackJustPressed = true wasBackJustPressed = true
toast(R.string.press_back_again) toast(R.string.press_back_again)
Handler().postDelayed({ mWasBackJustPressed = false }, BACK_PRESS_TIMEOUT.toLong()) Handler().postDelayed({ wasBackJustPressed = false }, BACK_PRESS_TIMEOUT.toLong())
} else { } else {
finish() finish()
} }
} else { } else {
breadcrumbs.removeBreadcrumb() breadcrumbs.removeBreadcrumb()
val item = breadcrumbs.lastItem openPath(breadcrumbs.lastItem.path)
openPath(item.path)
} }
} }

View File

@ -43,8 +43,8 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
var textColor = activity.config.textColor var textColor = activity.config.textColor
lateinit var folderDrawable: Drawable private val folderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder, textColor)
lateinit var fileDrawable: Drawable private val fileDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_file, textColor)
fun toggleItemSelection(select: Boolean, pos: Int) { fun toggleItemSelection(select: Boolean, pos: Int) {
itemViews[pos]?.item_frame?.isSelected = select itemViews[pos]?.item_frame?.isSelected = select
@ -68,21 +68,19 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
} }
init { init {
folderDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder, textColor)
folderDrawable.alpha = 180 folderDrawable.alpha = 180
fileDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_file, textColor)
fileDrawable.alpha = 180 fileDrawable.alpha = 180
} }
val adapterListener = object : MyAdapterListener { private val adapterListener = object : MyAdapterListener {
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
toggleItemSelection(select, position) toggleItemSelection(select, position)
} }
override fun getSelectedPositions(): HashSet<Int> = selectedPositions override fun getSelectedPositions() = selectedPositions
} }
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.cab_rename -> displayRenameDialog() R.id.cab_rename -> displayRenameDialog()
@ -201,7 +199,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
fun selectAll() { fun selectAll() {
val cnt = mItems.size val cnt = mItems.size
for (i in 0..cnt - 1) { for (i in 0 until cnt) {
selectedPositions.add(i) selectedPositions.add(i)
notifyItemChanged(i) notifyItemChanged(i)
} }
@ -237,7 +235,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
val newItems = SparseArray<View>() val newItems = SparseArray<View>()
var curIndex = 0 var curIndex = 0
for (i in 0..itemViews.size() - 1) { for (i in 0 until itemViews.size()) {
if (itemViews[i] != null) { if (itemViews[i] != null) {
newItems.put(curIndex, itemViews[i]) newItems.put(curIndex, itemViews[i])
curIndex++ curIndex++
@ -293,7 +291,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
toggleItemSelection(true, i) toggleItemSelection(true, i)
if (min > -1 && min < to) { if (min > -1 && min < to) {
(min..to - 1).filter { it != from } (min until to).filter { it != from }
.forEach { toggleItemSelection(false, it) } .forEach { toggleItemSelection(false, it) }
} }
if (max > -1) { if (max > -1) {
@ -310,7 +308,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
} }
if (min > -1) { if (min > -1) {
for (i in min..from - 1) for (i in min until from)
toggleItemSelection(false, i) toggleItemSelection(false, i)
} }
} }
@ -350,7 +348,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
return activity.resources.getQuantityString(R.plurals.items, children, children) return activity.resources.getQuantityString(R.plurals.items, children, children)
} }
fun viewClicked(fileDirItem: FileDirItem) { private fun viewClicked(fileDirItem: FileDirItem) {
if (multiSelector.isSelectable) { if (multiSelector.isSelectable) {
val isSelected = adapterListener.getSelectedPositions().contains(layoutPosition) val isSelected = adapterListener.getSelectedPositions().contains(layoutPosition)
adapterListener.toggleItemSelectionAdapter(!isSelected, layoutPosition) adapterListener.toggleItemSelectionAdapter(!isSelected, layoutPosition)
@ -359,7 +357,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
} }
} }
fun viewLongClicked() { private fun viewLongClicked() {
if (listener != null) { if (listener != null) {
if (!multiSelector.isSelectable) { if (!multiSelector.isSelectable) {
activity.startSupportActionMode(multiSelectorCallback) activity.startSupportActionMode(multiSelectorCallback)

View File

@ -1,34 +1,24 @@
package com.simplemobiletools.filemanager.dialogs package com.simplemobiletools.filemanager.dialogs
import android.content.DialogInterface
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.filemanager.Config
import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.extensions.config import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.dialog_change_sorting.view.* import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
class ChangeSortingDialog(val activity: SimpleActivity, val path: String = "", val callback: () -> Unit) : class ChangeSortingDialog(val activity: SimpleActivity, val path: String = "", val callback: () -> Unit) {
DialogInterface.OnClickListener {
companion object {
private var currSorting = 0 private var currSorting = 0
private var config = activity.config
lateinit var config: Config private var view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null)
lateinit var view: View
}
init { init {
config = activity.config view.sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null).apply {
sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
}
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, this) .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
activity.setupDialogStuff(view, this, R.string.sort_by) activity.setupDialogStuff(view, this, R.string.sort_by)
@ -62,7 +52,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val path: String = "", v
orderBtn.isChecked = true orderBtn.isChecked = true
} }
override fun onClick(dialog: DialogInterface, which: Int) { private fun dialogConfirmed() {
val sortingRadio = view.sorting_dialog_radio_sorting val sortingRadio = view.sorting_dialog_radio_sorting
var sorting = when (sortingRadio.checkedRadioButtonId) { var sorting = when (sortingRadio.checkedRadioButtonId) {
R.id.sorting_dialog_radio_name -> SORT_BY_NAME R.id.sorting_dialog_radio_name -> SORT_BY_NAME

View File

@ -89,8 +89,8 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
success(alertDialog) success(alertDialog)
callback(true) callback(true)
} }
} catch (ignored: IOException) { } catch (exception: IOException) {
activity.showErrorToast(exception.toString())
} }
} }

View File

@ -61,7 +61,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
} }
context.updateTextColors(items_holder) context.updateTextColors(items_holder)
if (mStoredTextColor != config.textColor) { if (mStoredTextColor != config.textColor) {
mItems = ArrayList<FileDirItem>() mItems = ArrayList()
fillItems() fillItems()
mStoredTextColor = config.textColor mStoredTextColor = config.textColor
} }
@ -78,6 +78,9 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
mPath = arguments.getString(PATH) mPath = arguments.getString(PATH)
getItems(mPath) { getItems(mPath) {
if (!isAdded)
return@getItems
val newItems = it val newItems = it
FileDirItem.sorting = context.config.getFolderSorting(mPath) FileDirItem.sorting = context.config.getFolderSorting(mPath)
newItems.sort() newItems.sort()