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 {
compile 'com.simplemobiletools:commons:2.26.9'
compile 'com.simplemobiletools:commons:2.27.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

View file

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

View file

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

View file

@ -1,34 +1,24 @@
package com.simplemobiletools.filemanager.dialogs
import android.content.DialogInterface
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.filemanager.Config
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
class ChangeSortingDialog(val activity: SimpleActivity, val path: String = "", val callback: () -> Unit) :
DialogInterface.OnClickListener {
companion object {
private var currSorting = 0
lateinit var config: Config
lateinit var view: View
}
class ChangeSortingDialog(val activity: SimpleActivity, val path: String = "", val callback: () -> Unit) {
private var currSorting = 0
private var config = activity.config
private var view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null)
init {
config = activity.config
view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null).apply {
sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
}
view.sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, this)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.sort_by)
@ -62,7 +52,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val path: String = "", v
orderBtn.isChecked = true
}
override fun onClick(dialog: DialogInterface, which: Int) {
private fun dialogConfirmed() {
val sortingRadio = view.sorting_dialog_radio_sorting
var sorting = when (sortingRadio.checkedRadioButtonId) {
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)
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)
if (mStoredTextColor != config.textColor) {
mItems = ArrayList<FileDirItem>()
mItems = ArrayList()
fillItems()
mStoredTextColor = config.textColor
}
@ -78,6 +78,9 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
mPath = arguments.getString(PATH)
getItems(mPath) {
if (!isAdded)
return@getItems
val newItems = it
FileDirItem.sorting = context.config.getFolderSorting(mPath)
newItems.sort()