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) {
directories_grid.adapter?.let {
(it as DirectoryAdapter).scrollVertically = !config.scrollHorizontally
(it as DirectoryAdapter).scrollVertically = config.viewTypeFolders == VIEW_TYPE_LIST || !config.scrollHorizontally
it.notifyDataSetChanged()
}
setupScrollDirection()

View file

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

View file

@ -56,12 +56,12 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
updateTitle(selectedPositions.size)
}
fun updateTitle(cnt: Int) {
private fun updateTitle(cnt: Int) {
actMode?.title = "$cnt / ${dirs.size}"
actMode?.invalidate()
}
val adapterListener = object : MyAdapterListener {
private val adapterListener = object : MyAdapterListener {
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
toggleItemSelection(select, position)
}
@ -69,7 +69,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
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 {
when (item.itemId) {
R.id.cab_properties -> showProperties()
@ -119,7 +119,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0
var unhiddenCnt = 0
selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach {
selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach {
if (File(it).containsNoMedia())
hiddenCnt++
else
@ -134,7 +134,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
val pinnedFolders = config.pinnedFolders
var pinnedCnt = 0
var unpinnedCnt = 0
selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach {
selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach {
if (pinnedFolders.contains(it))
pinnedCnt++
else
@ -242,7 +242,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
fun selectAll() {
val cnt = dirs.size
for (i in 0..cnt - 1) {
for (i in 0 until cnt) {
selectedPositions.add(i)
notifyItemChanged(i)
}
@ -286,13 +286,9 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
listener?.tryDeleteFolders(folders)
val newItems = SparseArray<View>()
var curIndex = 0
for (i in 0..itemViews.size() - 1) {
if (itemViews[i] != null) {
newItems.put(curIndex, itemViews[i])
curIndex++
}
}
(0 until itemViews.size())
.filter { itemViews[it] != null }
.forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
itemViews = newItems
}
@ -330,7 +326,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
}
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)
}

View file

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