Skip to content

Commit

Permalink
Don't allow multi-select in books list
Browse files Browse the repository at this point in the history
  • Loading branch information
nevenz committed Mar 12, 2019
1 parent 6b07d66 commit 66cc409
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/orgzly/android/ui/Selection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Selection {
}
}

// TODO: Choose mode when creating selection
fun toggleSingleSelect(id: Long) {
if (contains(id)) {
idSet.clear()
} else {
idSet.clear()
idSet.add(id)
}
}

fun clear() {
idSet.clear()
}
Expand Down
31 changes: 15 additions & 16 deletions app/src/main/java/com/orgzly/android/ui/books/BooksFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.orgzly.android.ui.Fab
import com.orgzly.android.ui.OnViewHolderClickListener
import com.orgzly.android.ui.drawer.DrawerItem
import com.orgzly.android.ui.main.SharedMainActivityViewModel
import com.orgzly.android.ui.notes.query.QueryFragment
import com.orgzly.android.ui.util.ActivityUtils
import com.orgzly.android.usecase.BookDelete
import com.orgzly.android.util.LogUtils
Expand Down Expand Up @@ -60,8 +59,8 @@ class BooksFragment :

private lateinit var viewFlipper: ViewFlipper

private var mAddOptions = true
private var mShowContextMenu = true
private var withOptionsMenu = true
private var withActionBar = true

@Inject
lateinit var dataRepository: DataRepository
Expand All @@ -83,8 +82,8 @@ class BooksFragment :
throw IllegalArgumentException("No arguments found to " + BooksFragment::class.java.simpleName)
}

mAddOptions = arguments?.getBoolean(ARG_ADD_OPTIONS) ?: true
mShowContextMenu = arguments?.getBoolean(ARG_SHOW_CONTEXT_MENU) ?: true
withOptionsMenu = arguments?.getBoolean(ARG_WITH_OPTIONS_MENU) ?: true
withActionBar = arguments?.getBoolean(ARG_WITH_ACTION_BAR) ?: true
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -98,7 +97,7 @@ class BooksFragment :
/* Would like to add items to the Options Menu.
* Required (for fragments only) to receive onCreateOptionsMenu() call.
*/
setHasOptionsMenu(mAddOptions)
setHasOptionsMenu(withOptionsMenu)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Expand All @@ -123,8 +122,8 @@ class BooksFragment :
listener?.onBookClicked(item.book.id)

} else {
viewAdapter.getSelection().toggle(item.book.id)
viewAdapter.notifyItemChanged(position)
viewAdapter.getSelection().toggleSingleSelect(item.book.id)
viewAdapter.notifyDataSetChanged() // FIXME

if (viewAdapter.getSelection().count == 0) {
actionMode?.finish()
Expand All @@ -135,13 +134,13 @@ class BooksFragment :
}

override fun onLongClick(view: View, position: Int, item: BookView) {
if (!mShowContextMenu) {
if (!withActionBar) {
listener?.onBookClicked(item.book.id)
return
}

viewAdapter.getSelection().toggle(item.book.id)
viewAdapter.notifyItemChanged(position)
viewAdapter.getSelection().toggleSingleSelect(item.book.id)
viewAdapter.notifyDataSetChanged() // FIXME

if (viewAdapter.getSelection().count > 0) {
if (actionMode == null) {
Expand Down Expand Up @@ -518,18 +517,18 @@ class BooksFragment :
*/
val FRAGMENT_TAG: String = BooksFragment::class.java.name

private const val ARG_ADD_OPTIONS = "add_options"
private const val ARG_SHOW_CONTEXT_MENU = "show_context_menu"
private const val ARG_WITH_OPTIONS_MENU = "with_options_menu"
private const val ARG_WITH_ACTION_BAR = "with_action_bar"

val instance: BooksFragment
get() = getInstance(true, true)

fun getInstance(addOptions: Boolean, showContextMenu: Boolean): BooksFragment {
fun getInstance(withOptionsMenu: Boolean, withActionBar: Boolean): BooksFragment {
val fragment = BooksFragment()
val args = Bundle()

args.putBoolean(ARG_ADD_OPTIONS, addOptions)
args.putBoolean(ARG_SHOW_CONTEXT_MENU, showContextMenu)
args.putBoolean(ARG_WITH_OPTIONS_MENU, withOptionsMenu)
args.putBoolean(ARG_WITH_ACTION_BAR, withActionBar)

fragment.arguments = args
return fragment
Expand Down

0 comments on commit 66cc409

Please sign in to comment.