From 668e251c183f70b9929a301a767bd5edfbcef6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=BD=EC=9D=98=EC=A7=84?= Date: Sun, 16 Jul 2023 00:35:45 +0900 Subject: [PATCH] =?UTF-8?q?[feat/delete=5Frefresh]:=20delete=20refresh=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../album/detail/AlbumDetailActivity.kt | 1 + .../feature/album/list/AlbumListActivity.kt | 32 +++++++++++-------- .../album/list/adapter/AlbumListAdapter.kt | 11 ++++--- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/teampophory/pophory/feature/album/detail/AlbumDetailActivity.kt b/app/src/main/java/com/teampophory/pophory/feature/album/detail/AlbumDetailActivity.kt index bd7fe32d..42df8fc8 100644 --- a/app/src/main/java/com/teampophory/pophory/feature/album/detail/AlbumDetailActivity.kt +++ b/app/src/main/java/com/teampophory/pophory/feature/album/detail/AlbumDetailActivity.kt @@ -47,6 +47,7 @@ class AlbumDetailActivity : AppCompatActivity() { (fragment as? AlbumDeleteDialogFragment)?.dismissAllowingStateLoss() } toast("앨범이 삭제되었습니다.") + setResult(RESULT_OK) finish() } diff --git a/app/src/main/java/com/teampophory/pophory/feature/album/list/AlbumListActivity.kt b/app/src/main/java/com/teampophory/pophory/feature/album/list/AlbumListActivity.kt index 09561f12..20bb10aa 100644 --- a/app/src/main/java/com/teampophory/pophory/feature/album/list/AlbumListActivity.kt +++ b/app/src/main/java/com/teampophory/pophory/feature/album/list/AlbumListActivity.kt @@ -12,14 +12,14 @@ import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import com.teampophory.pophory.R -import com.teampophory.pophory.feature.album.albumsort.AlbumSortBottomSheet -import com.teampophory.pophory.feature.album.albumsort.AlbumSortType import com.teampophory.pophory.common.activity.hideLoading import com.teampophory.pophory.common.activity.showLoading import com.teampophory.pophory.common.context.stringOf import com.teampophory.pophory.common.intent.parcelableExtra import com.teampophory.pophory.common.view.viewBinding import com.teampophory.pophory.databinding.ActivityAlbumListBinding +import com.teampophory.pophory.feature.album.albumsort.AlbumSortBottomSheet +import com.teampophory.pophory.feature.album.albumsort.AlbumSortType import com.teampophory.pophory.feature.album.list.adapter.AlbumListAdapter import com.teampophory.pophory.feature.home.photo.AddPhotoActivity import com.teampophory.pophory.feature.home.store.model.AlbumItem @@ -31,25 +31,29 @@ import timber.log.Timber @AndroidEntryPoint class AlbumListActivity : AppCompatActivity() { - private val albumListAdapter = AlbumListAdapter() + private val albumListAdapter = AlbumListAdapter { intent, activityOptionsCompat -> + photoCountRefreshLauncher.launch(intent, activityOptionsCompat) + } private val viewModel by viewModels() private val binding by viewBinding(ActivityAlbumListBinding::inflate) private val albumItem by parcelableExtra() - private val addAlbumActivityLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> - if (result.resultCode == RESULT_OK) { - setResult(RESULT_OK) - finish() + private val photoCountRefreshLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == RESULT_OK) { + setResult(RESULT_OK) + finish() + } } - } - private val imagePicker = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> - val currentAlbum = viewModel.albumItem.value - val intent = currentAlbum?.let { albumItem -> - AddPhotoActivity.getIntent(this, uri.toString(), albumItem) + private val imagePicker = + registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri -> + val currentAlbum = viewModel.albumItem.value + val intent = currentAlbum?.let { albumItem -> + AddPhotoActivity.getIntent(this, uri.toString(), albumItem) + } + photoCountRefreshLauncher.launch(intent) } - addAlbumActivityLauncher.launch(intent) - } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/teampophory/pophory/feature/album/list/adapter/AlbumListAdapter.kt b/app/src/main/java/com/teampophory/pophory/feature/album/list/adapter/AlbumListAdapter.kt index 31bc45f0..a5916c12 100644 --- a/app/src/main/java/com/teampophory/pophory/feature/album/list/adapter/AlbumListAdapter.kt +++ b/app/src/main/java/com/teampophory/pophory/feature/album/list/adapter/AlbumListAdapter.kt @@ -1,11 +1,12 @@ package com.teampophory.pophory.feature.album.list.adapter import android.app.Activity -import android.app.ActivityOptions import android.content.Context +import android.content.Intent import android.view.LayoutInflater import android.view.ViewGroup import android.widget.ImageView +import androidx.core.app.ActivityOptionsCompat import androidx.recyclerview.widget.ListAdapter import com.teampophory.pophory.common.view.ItemDiffCallback import com.teampophory.pophory.databinding.ItemHorizontalPhotoBinding @@ -16,7 +17,9 @@ import com.teampophory.pophory.feature.album.model.OrientType import com.teampophory.pophory.feature.album.model.PhotoDetail import com.teampophory.pophory.feature.album.model.PhotoItem -class AlbumListAdapter : ListAdapter( +class AlbumListAdapter( + private val onItemClicked: (Intent, ActivityOptionsCompat) -> Unit +) : ListAdapter( ItemDiffCallback( onItemsTheSame = { old, new -> old == new }, onContentsTheSame = { old, new -> old == new } @@ -80,9 +83,9 @@ class AlbumListAdapter : ListAdapter( ) { val activity = context as? Activity ?: return val transitionAnimation = - ActivityOptions.makeSceneTransitionAnimation(activity, imageView, "thumb").toBundle() + ActivityOptionsCompat.makeSceneTransitionAnimation(activity, imageView, "thumb") val intent = AlbumDetailActivity.newIntent(context, photoDetail) - context.startActivity(intent, transitionAnimation) + onItemClicked(intent, transitionAnimation) } enum class AlbumViewType {