minor code style updates

This commit is contained in:
tibbi 2017-09-28 21:48:08 +02:00
parent 9c5c359e4d
commit 74d179f86d
5 changed files with 113 additions and 28 deletions

View File

@ -135,7 +135,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
if (mStoredScrollHorizontally != config.scrollHorizontally) { if (mStoredScrollHorizontally != config.scrollHorizontally) {
directories_grid.adapter?.let { directories_grid.adapter?.let {
(it as DirectoryAdapter).scrollVertically = !config.scrollHorizontally (it as DirectoryAdapter).scrollVertically = config.viewTypeFolders == VIEW_TYPE_LIST || !config.scrollHorizontally
it.notifyDataSetChanged() it.notifyDataSetChanged()
} }
setupScrollDirection() setupScrollDirection()

View File

@ -95,7 +95,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
if (mStoredScrollHorizontally != config.scrollHorizontally) { if (mStoredScrollHorizontally != config.scrollHorizontally) {
media_grid.adapter?.let { media_grid.adapter?.let {
(it as MediaAdapter).scrollVertically = !config.scrollHorizontally (it as MediaAdapter).scrollVertically = config.viewTypeFiles == VIEW_TYPE_LIST || !config.scrollHorizontally
it.notifyDataSetChanged() it.notifyDataSetChanged()
} }
setupScrollDirection() setupScrollDirection()

View File

@ -56,12 +56,12 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
updateTitle(selectedPositions.size) updateTitle(selectedPositions.size)
} }
fun updateTitle(cnt: Int) { private fun updateTitle(cnt: Int) {
actMode?.title = "$cnt / ${dirs.size}" actMode?.title = "$cnt / ${dirs.size}"
actMode?.invalidate() actMode?.invalidate()
} }
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)
} }
@ -69,7 +69,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
override fun getSelectedPositions(): HashSet<Int> = selectedPositions override fun getSelectedPositions(): HashSet<Int> = 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_properties -> showProperties() R.id.cab_properties -> showProperties()
@ -119,7 +119,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
fun checkHideBtnVisibility(menu: Menu) { fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0 var hiddenCnt = 0
var unhiddenCnt = 0 var unhiddenCnt = 0
selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach { selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach {
if (File(it).containsNoMedia()) if (File(it).containsNoMedia())
hiddenCnt++ hiddenCnt++
else else
@ -134,7 +134,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
val pinnedFolders = config.pinnedFolders val pinnedFolders = config.pinnedFolders
var pinnedCnt = 0 var pinnedCnt = 0
var unpinnedCnt = 0 var unpinnedCnt = 0
selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach { selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach {
if (pinnedFolders.contains(it)) if (pinnedFolders.contains(it))
pinnedCnt++ pinnedCnt++
else else
@ -242,7 +242,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
fun selectAll() { fun selectAll() {
val cnt = dirs.size val cnt = dirs.size
for (i in 0..cnt - 1) { for (i in 0 until cnt) {
selectedPositions.add(i) selectedPositions.add(i)
notifyItemChanged(i) notifyItemChanged(i)
} }
@ -286,13 +286,9 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
listener?.tryDeleteFolders(folders) listener?.tryDeleteFolders(folders)
val newItems = SparseArray<View>() val newItems = SparseArray<View>()
var curIndex = 0 (0 until itemViews.size())
for (i in 0..itemViews.size() - 1) { .filter { itemViews[it] != null }
if (itemViews[i] != null) { .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
newItems.put(curIndex, itemViews[i])
curIndex++
}
}
itemViews = newItems itemViews = newItems
} }
@ -330,7 +326,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
} }
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_item_grid, parent, false) val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_item_list, parent, false)
return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, isPickIntent, itemClick) return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, isPickIntent, itemClick)
} }

View File

@ -53,12 +53,12 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
updateTitle(selectedPositions.size) updateTitle(selectedPositions.size)
} }
fun updateTitle(cnt: Int) { private fun updateTitle(cnt: Int) {
actMode?.title = "$cnt / ${media.size}" actMode?.title = "$cnt / ${media.size}"
actMode?.invalidate() actMode?.invalidate()
} }
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)
} }
@ -66,7 +66,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
override fun getSelectedPositions(): HashSet<Int> = selectedPositions override fun getSelectedPositions(): HashSet<Int> = 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_properties -> showProperties() R.id.cab_properties -> showProperties()
@ -112,7 +112,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
fun checkHideBtnVisibility(menu: Menu) { fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0 var hiddenCnt = 0
var unhiddenCnt = 0 var unhiddenCnt = 0
selectedPositions.map { media.getOrNull(it) }.filterNotNull().forEach { selectedPositions.mapNotNull { media.getOrNull(it) }.forEach {
if (it.name.startsWith('.')) if (it.name.startsWith('.'))
hiddenCnt++ hiddenCnt++
else else
@ -184,7 +184,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
fun selectAll() { fun selectAll() {
val cnt = media.size val cnt = media.size
for (i in 0..cnt - 1) { for (i in 0 until cnt) {
selectedPositions.add(i) selectedPositions.add(i)
multiSelector.setSelected(i, 0, true) multiSelector.setSelected(i, 0, true)
notifyItemChanged(i) notifyItemChanged(i)
@ -227,13 +227,9 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
listener?.deleteFiles(files) listener?.deleteFiles(files)
val newItems = SparseArray<View>() val newItems = SparseArray<View>()
var curIndex = 0 (0 until itemViews.size())
for (i in 0..itemViews.size() - 1) { .filter { itemViews[it] != null }
if (itemViews[i] != null) { .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
newItems.put(curIndex, itemViews[i])
curIndex++
}
}
itemViews = newItems itemViews = newItems
} }

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dir_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1px">
<com.simplemobiletools.gallery.views.MySquareImageView
android:id="@+id/dir_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/dir_check"
android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/selection_check_size"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/small_margin"
android:background="@drawable/circle_background"
android:padding="@dimen/tiny_margin"
android:src="@drawable/ic_check"/>
<ImageView
android:id="@+id/dir_pin"
android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/selection_check_size"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/small_margin"
android:background="@drawable/circle_black_background"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_pin"/>
<ImageView
android:id="@+id/dir_shadow_holder"
android:layout_width="match_parent"
android:layout_height="@dimen/tmb_shadow_height"
android:layout_alignLeft="@+id/dir_bottom_holder"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/dir_bottom_holder"
android:background="@drawable/gradient_background"/>
<LinearLayout
android:id="@+id/dir_bottom_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/dir_thumbnail"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/dir_thumbnail"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/small_margin"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:paddingTop="@dimen/small_margin">
<TextView
android:id="@+id/dir_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:paddingBottom="@dimen/small_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size"/>
<TextView
android:id="@+id/photo_cnt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size"/>
</LinearLayout>
<ImageView
android:id="@+id/dir_sd_card"
android:layout_width="@dimen/sd_card_icon_size"
android:layout_height="@dimen/sd_card_icon_size"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/dir_bottom_holder"
android:alpha="0.8"
android:paddingBottom="@dimen/small_margin"
android:paddingEnd="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:src="@drawable/ic_sd_card"
android:visibility="gone"/>
</RelativeLayout>