Skip to content

Commit

Permalink
Fix options being cut off when selecting files
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Nov 7, 2016
1 parent 2f9dec6 commit aa6e804
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 76 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId 'com.stevenschoen.putionew'
minSdkVersion 19
targetSdkVersion 25
versionCode 102
versionName '4.0'
versionCode 103
versionName '4.0.1'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
Expand Down Expand Up @@ -41,13 +41,13 @@ dependencies {
compile 'com.android.support:palette-v7:25.0.0'
compile 'com.google.android.gms:play-services-cast-framework:9.6.1'
compile 'commons-io:commons-io:2.5'
compile 'joda-time:joda-time:2.9.4'
compile 'joda-time:joda-time:2.9.5'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.trello:rxlifecycle:0.8.0'
compile 'com.trello:rxlifecycle-components:0.8.0'
compile 'com.trello:rxlifecycle-kotlin:0.8.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.trello:rxlifecycle:1.0'
compile 'com.trello:rxlifecycle-components:1.0'
compile 'com.trello:rxlifecycle-kotlin:1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.2'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract class FileListFragment<CallbacksClass: FileListFragment.Callbacks> : Rx

var filesAdapter: FilesAdapter? = null

val actionModeHelper by lazy { ActionModeHelper() }
val selectionHelper by lazy { SelectionHelper() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -77,12 +77,12 @@ abstract class FileListFragment<CallbacksClass: FileListFragment.Callbacks> : Rx
})
filesAdapter!!.setItemsCheckedChangedListener(object : FilesAdapter.OnItemsCheckedChangedListener {
override fun onItemsCheckedChanged() {
if (!actionModeHelper.hasActionMode()) {
if (!selectionHelper.isShowing()) {
if (filesAdapter!!.isInCheckMode()) {
actionModeHelper.startFloatingActionMode()
selectionHelper.show()
}
} else {
actionModeHelper.invalidateActionMode()
selectionHelper.invalidate()
}
}
})
Expand Down Expand Up @@ -283,12 +283,12 @@ abstract class FileListFragment<CallbacksClass: FileListFragment.Callbacks> : Rx
abstract fun refresh()
abstract fun isRefreshing(): Boolean

inner class ActionModeHelper() {
fun hasActionMode(): Boolean {
inner class SelectionHelper() {
fun isShowing(): Boolean {
return getSelectionFragment() != null
}

fun invalidateActionMode() {
fun invalidate() {
val count = filesAdapter!!.checkedCount()
if (count == 0) {
childFragmentManager.beginTransaction()
Expand All @@ -300,7 +300,7 @@ abstract class FileListFragment<CallbacksClass: FileListFragment.Callbacks> : Rx
}
}

fun startFloatingActionMode() {
fun show() {
callbacks?.onSelectionStarted()
val selectionFragment = Fragment.instantiate(context, FileSelectionFragment::class.java.name) as FileSelectionFragment
childFragmentManager.beginTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.stevenschoen.putionew.files

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.widget.PopupMenuCompat
import android.support.v7.widget.PopupMenu
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
Expand All @@ -29,13 +32,6 @@ class FileSelectionFragment : Fragment() {
callbacks?.onCancel()
}

val renameView = view.findViewById(R.id.file_selection_rename)
renameView.setOnClickListener { callbacks?.onRenameSelected()}
renameView.setOnLongClickListener {
Toast.makeText(context, R.string.rename, Toast.LENGTH_SHORT).show()
true
}

val downloadView = view.findViewById(R.id.file_selection_download)
downloadView.setOnClickListener { callbacks?.onDownloadSelected() }
downloadView.setOnLongClickListener {
Expand All @@ -50,29 +46,41 @@ class FileSelectionFragment : Fragment() {
true
}

val moveView = view.findViewById(R.id.file_selection_move)
moveView.setOnClickListener { callbacks?.onMoveSelected() }
moveView.setOnLongClickListener {
Toast.makeText(context, R.string.move, Toast.LENGTH_SHORT).show()
true
}

val deleteView = view.findViewById(R.id.file_selection_delete)
deleteView.setOnClickListener { callbacks?.onDeleteSelected() }
deleteView.setOnLongClickListener {
Toast.makeText(context, R.string.delete, Toast.LENGTH_SHORT).show()
true
}

val idRename = 1
val idMove = 2

val moreView = view.findViewById(R.id.file_selection_more)
moreView.setOnClickListener {
val popup = PopupMenu(context, moreView)
if (amountSelected.value == 1) popup.menu.add(0, idRename, 0, R.string.rename)
popup.menu.add(0, idMove, 0, R.string.move)
popup.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
idRename -> {
callbacks?.onRenameSelected();
return@setOnMenuItemClickListener true
}
idMove -> {
callbacks?.onMoveSelected()
return@setOnMenuItemClickListener true
}
}
false
}
popup.show()
}

val titleView = view.findViewById(R.id.file_selection_title) as TextView

fun updateAmount(amount: Int) {
titleView.text = getString(R.string.x_selected, amount)
if (amount > 1) {
renameView.visibility = View.GONE
} else {
renameView.visibility = View.VISIBLE
}
}

if (savedInstanceState != null) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_selection_copy.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="56dp"
android:height="56dp"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/drawable/ic_selection_delete.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<vector android:height="56dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="56dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/ic_selection_download.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="56dp"
android:height="56dp"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_selection_more.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>
4 changes: 0 additions & 4 deletions app/src/main/res/drawable/ic_selection_move.xml

This file was deleted.

4 changes: 0 additions & 4 deletions app/src/main/res/drawable/ic_selection_rename.xml

This file was deleted.

30 changes: 4 additions & 26 deletions app/src/main/res/layout/file_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,32 @@
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
tools:text="1 selected"/>

<ImageButton
android:id="@+id/file_selection_rename"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_selection_rename"/>

<ImageButton
android:id="@+id/file_selection_download"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_selection_download"/>

<ImageButton
android:id="@+id/file_selection_copylink"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_selection_copy"/>

<ImageButton
android:id="@+id/file_selection_move"
android:id="@+id/file_selection_delete"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_selection_move"/>
android:src="@drawable/ic_selection_delete"/>

<ImageButton
android:id="@+id/file_selection_delete"
android:id="@+id/file_selection_more"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?selectableItemBackgroundBorderless"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_selection_delete"/>
android:src="@drawable/ic_selection_more"/>

</LinearLayout>

0 comments on commit aa6e804

Please sign in to comment.