diff --git a/gallery/src/main/java/com/jt/gallery/FullScreenView.kt b/gallery/src/main/java/com/jt/gallery/FullScreenView.kt index 2f37e49..0e03ed3 100644 --- a/gallery/src/main/java/com/jt/gallery/FullScreenView.kt +++ b/gallery/src/main/java/com/jt/gallery/FullScreenView.kt @@ -4,5 +4,4 @@ interface FullScreenView { fun showSystemUI() fun hideSystemUI() fun isNavigationVisible(): Boolean - fun resetAdapter(index: Int) } \ No newline at end of file diff --git a/gallery/src/main/java/com/jt/gallery/GalleryActivity.kt b/gallery/src/main/java/com/jt/gallery/GalleryActivity.kt index a4127db..a926a25 100644 --- a/gallery/src/main/java/com/jt/gallery/GalleryActivity.kt +++ b/gallery/src/main/java/com/jt/gallery/GalleryActivity.kt @@ -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() diff --git a/gallery/src/main/java/com/jt/gallery/GalleryAdapter.kt b/gallery/src/main/java/com/jt/gallery/GalleryAdapter.kt index 97a1250..aada67f 100644 --- a/gallery/src/main/java/com/jt/gallery/GalleryAdapter.kt +++ b/gallery/src/main/java/com/jt/gallery/GalleryAdapter.kt @@ -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 { _, _, _ ->