Refresh adapter after the cover is changed. Some minor changes on categories.

This commit is contained in:
inorichi 2016-02-25 16:13:48 +01:00
parent 4dde6d1a31
commit 61c7feca87
3 changed files with 16 additions and 23 deletions

View File

@ -51,7 +51,7 @@ class CategoryActivity : BaseRxActivity<CategoryPresenter>(), ActionMode.Callbac
* @param context context information.
*/
@JvmStatic
fun newIntent(context: Context): Intent? {
fun newIntent(context: Context): Intent {
return Intent(context, CategoryActivity::class.java)
}
}
@ -106,21 +106,12 @@ class CategoryActivity : BaseRxActivity<CategoryPresenter>(), ActionMode.Callbac
adapter.setItems(categories)
}
/**
* Delete selected categories
*
* @param categories list containing categories
*/
private fun deleteCategories(categories: List<Category?>?) {
presenter.deleteCategories(categories)
}
/**
* Returns the selected categories
*
* @return list of selected categories
*/
private fun getSelectedCategories(): List<Category?>? {
private fun getSelectedCategories(): List<Category> {
// Create a list of the selected categories
return adapter.selectedItems.map { adapter.getItem(it) }
}
@ -130,13 +121,13 @@ class CategoryActivity : BaseRxActivity<CategoryPresenter>(), ActionMode.Callbac
*
* @param category category that will be edited.
*/
private fun editCategory(category: Category?) {
private fun editCategory(category: Category) {
MaterialDialog.Builder(this)
.title(R.string.action_rename_category)
.negativeText(R.string.button_cancel)
.onNegative { materialDialog, dialogAction -> destroyActionModeIfNeeded() }
.input(getString(R.string.name), category?.name, false)
{ dialog, input -> presenter.renameCategory(category as Category, input.toString()) }
.input(getString(R.string.name), category.name, false)
{ dialog, input -> presenter.renameCategory(category, input.toString()) }
.show()
}
@ -175,7 +166,7 @@ class CategoryActivity : BaseRxActivity<CategoryPresenter>(), ActionMode.Callbac
*
* @return false
*/
override fun onPrepareActionMode(p0: ActionMode?, p1: Menu?): Boolean {
override fun onPrepareActionMode(actionMode: ActionMode, menu: Menu): Boolean {
return false
}
@ -191,11 +182,11 @@ class CategoryActivity : BaseRxActivity<CategoryPresenter>(), ActionMode.Callbac
when (menuItem.itemId) {
R.id.action_delete -> {
// Delete select categories.
deleteCategories(getSelectedCategories())
presenter.deleteCategories(getSelectedCategories())
}
R.id.action_edit -> {
// Edit selected category
editCategory(getSelectedCategories()?.get(0))
editCategory(getSelectedCategories()[0])
}
else -> return false
}

View File

@ -28,18 +28,18 @@ class CategoryHolder(view: View, adapter: CategoryAdapter, listener: FlexibleVie
init {
// Create round letter image onclick to simulate long click
itemView.image.setOnClickListener({ v ->
itemView.image.setOnClickListener {
// Simulate long click on this view to enter selection mode
onLongClick(view)
})
}
// Set on touch listener for reorder image
itemView.reorder.setOnTouchListener({ v, event ->
itemView.reorder.setOnTouchListener { v, event ->
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
dragListener.onStartDrag(this)
}
false
})
}
}
/**

View File

@ -266,7 +266,6 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
when (item.itemId) {
R.id.action_edit_cover -> {
changeSelectedCover(presenter.selectedMangas)
adapter.refreshRegisteredAdapters()
destroyActionModeIfNeeded()
}
R.id.action_move_to_category -> {
@ -329,8 +328,11 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
try {
// Update cover to selected file, show error if something went wrong
if (!presenter.editCoverWithLocalFile(picture, manga))
if (presenter.editCoverWithLocalFile(picture, manga)) {
adapter.refreshRegisteredAdapters()
} else {
ToastUtil.showShort(context, R.string.notification_manga_update_failed)
}
} catch (e: IOException) {
e.printStackTrace()