Skip to content

Commit

Permalink
Merge pull request #3 from jt-gilkeson/feature/support_delete
Browse files Browse the repository at this point in the history
Simplified code
  • Loading branch information
jt-gilkeson authored Jun 17, 2019
2 parents cd0d67a + 896355a commit fab4461
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 0 additions & 1 deletion gallery/src/main/java/com/jt/gallery/FullScreenView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ interface FullScreenView {
fun showSystemUI()
fun hideSystemUI()
fun isNavigationVisible(): Boolean
fun resetAdapter(index: Int)
}
6 changes: 0 additions & 6 deletions gallery/src/main/java/com/jt/gallery/GalleryActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ class GalleryActivity : AppCompatActivity(), FullScreenView {
override fun isNavigationVisible(): Boolean =
window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_HIDE_NAVIGATION == 0

override fun resetAdapter(index: Int) {
// Need to reset the adapter to update it
galleryViewPager.adapter = GalleryAdapter(this, imageList, true)
galleryViewPager.currentItem = index
}

override fun onBackPressed() {
setResult(RESULT_OK, Intent().putStringArrayListExtra(IMAGE_LIST, imageList))
super.onBackPressed()
Expand Down
8 changes: 6 additions & 2 deletions gallery/src/main/java/com/jt/gallery/GalleryAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ class GalleryAdapter(

override fun getCount() = images.size

// This is called when notifyDataSetChanged() is called
override fun getItemPosition(any: Any): Int {
// refresh all views when data set changed
return POSITION_NONE
}

private fun deleteItem(position: Int) {
images.removeAt(position)
views.remove(position)
notifyDataSetChanged()

view.resetAdapter(if (position > images.size - 1) images.size - 1 else position)
}

private val tapListener = PhotoViewAttacher.OnViewTapListener { _, _, _ ->
Expand Down

0 comments on commit fab4461

Please sign in to comment.