Skip to content

Commit cd6267d

Browse files
committed
Upgrade dependencies; Avoid memory leaks
1 parent 0334f56 commit cd6267d

File tree

4 files changed

+66
-43
lines changed

4 files changed

+66
-43
lines changed

bazaar/build.gradle

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies {
4848
implementation 'androidx.constraintlayout:constraintlayout:2.1.0-beta02'
4949

5050
// Fragment
51-
implementation 'androidx.fragment:fragment-ktx:1.3.4'
51+
implementation 'androidx.fragment:fragment-ktx:1.3.5'
5252

5353
// Lifecycle
5454
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
@@ -60,16 +60,16 @@ dependencies {
6060

6161
// Cinema, Museum, Radio (Video, image fullscreen preview & audio player, respectively).
6262
// Radio is an audio player.
63-
api 'com.github.zhombie.arbat:cinema:1.2.5'
64-
api 'com.github.zhombie.arbat:museum:1.2.5'
65-
api 'com.github.zhombie.arbat:radio:1.2.5'
63+
api 'com.github.zhombie.arbat:cinema:1.2.6'
64+
api 'com.github.zhombie.arbat:museum:1.2.6'
65+
api 'com.github.zhombie.arbat:radio:1.2.6'
6666

6767
// ExoPlayer
68-
implementation 'com.google.android.exoplayer:exoplayer-core:2.14.0'
69-
implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.0'
68+
implementation 'com.google.android.exoplayer:exoplayer-core:2.14.1'
69+
implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.1'
7070

7171
// Material components
72-
implementation 'com.google.android.material:material:1.3.0'
72+
implementation 'com.google.android.material:material:1.4.0-rc01'
7373

7474
// Kotlin coroutines
7575
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'

bazaar/src/main/java/kz/zhombie/bazaar/ui/presentation/MediaStoreFragment.kt

+19-35
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.widget.Toast
1010
import androidx.activity.result.contract.ActivityResultContracts
1111
import androidx.constraintlayout.widget.ConstraintLayout
1212
import androidx.core.view.updateLayoutParams
13-
import androidx.fragment.app.DialogFragment
1413
import androidx.lifecycle.ViewModelProvider
1514
import androidx.recyclerview.widget.RecyclerView
1615
import com.google.android.material.bottomsheet.BottomSheetBehavior
@@ -30,6 +29,8 @@ import kz.zhombie.bazaar.core.logging.Logger
3029
import kz.zhombie.bazaar.core.media.MediaScanManager
3130
import kz.zhombie.bazaar.ui.components.view.HeaderView
3231
import kz.zhombie.bazaar.ui.components.view.SelectButton
32+
import kz.zhombie.bazaar.ui.model.UIMedia
33+
import kz.zhombie.bazaar.ui.model.UIMultimedia
3334
import kz.zhombie.bazaar.ui.presentation.audible.AudiosAdapter
3435
import kz.zhombie.bazaar.ui.presentation.audible.AudiosAdapterManager
3536
import kz.zhombie.bazaar.ui.presentation.audible.AudiosHeaderAdapter
@@ -40,13 +41,10 @@ import kz.zhombie.bazaar.ui.presentation.folder.FoldersAdapterManager
4041
import kz.zhombie.bazaar.ui.presentation.visual.VisualMediaAdapter
4142
import kz.zhombie.bazaar.ui.presentation.visual.VisualMediaAdapterManager
4243
import kz.zhombie.bazaar.ui.presentation.visual.VisualMediaHeaderAdapter
43-
import kz.zhombie.bazaar.ui.model.UIMedia
44-
import kz.zhombie.bazaar.ui.model.UIMultimedia
4544
import kz.zhombie.bazaar.utils.*
4645
import kz.zhombie.bazaar.utils.contract.GetContentContract
4746
import kz.zhombie.bazaar.utils.contract.GetMultipleContentsContract
4847
import kz.zhombie.bazaar.utils.contract.TakeVideoContract
49-
import kz.zhombie.bazaar.utils.windowHeight
5048
import kz.zhombie.cinema.CinemaDialogFragment
5149
import kz.zhombie.cinema.model.Movie
5250
import kz.zhombie.museum.MuseumDialogFragment
@@ -97,10 +95,6 @@ internal class MediaStoreFragment : BottomSheetDialogFragment(),
9795
// ViewModel
9896
private lateinit var viewModel: MediaStoreViewModel
9997

100-
// UI interface floating messages
101-
private var dialogFragment: DialogFragment? = null
102-
private var toast: Toast? = null
103-
10498
// RecyclerView Adapters
10599
private var foldersAdapterManager: FoldersAdapterManager? = null
106100
private var visualMediaAdapterManager: VisualMediaAdapterManager? = null
@@ -277,6 +271,7 @@ internal class MediaStoreFragment : BottomSheetDialogFragment(),
277271
super.onDestroy()
278272

279273
eventListener?.onDestroy()
274+
eventListener = null
280275
}
281276

282277
private fun setupHeaderView() {
@@ -609,38 +604,40 @@ internal class MediaStoreFragment : BottomSheetDialogFragment(),
609604
*/
610605

611606
override fun onImageClicked(imageView: ShapeableImageView, uiMedia: UIMedia) {
612-
dialogFragment?.dismiss()
613-
dialogFragment = null
614-
dialogFragment = MuseumDialogFragment.Builder()
607+
MuseumDialogFragment.Builder()
615608
.setPaintingLoader(Settings.getImageLoader())
616609
.setPainting(
617610
Painting(
618611
uri = uiMedia.media.uri,
619-
info = Painting.Info(uiMedia.getDisplayTitle(), uiMedia.media.folderDisplayName)
612+
info = Painting.Info(
613+
title = uiMedia.getDisplayTitle(),
614+
subtitle = uiMedia.media.folderDisplayName
615+
)
620616
)
621617
)
622618
.setImageView(imageView)
623619
.setFooterViewEnabled(true)
624-
.show(childFragmentManager)
620+
.showSafely(childFragmentManager)
625621
}
626622

627623
override fun onImageCheckboxClicked(uiMedia: UIMedia) {
628624
viewModel.onMediaCheckboxClicked(uiMedia)
629625
}
630626

631627
override fun onVideoClicked(imageView: ShapeableImageView, uiMedia: UIMedia) {
632-
dialogFragment?.dismiss()
633-
dialogFragment = null
634-
dialogFragment = CinemaDialogFragment.Builder()
628+
CinemaDialogFragment.Builder()
635629
.setMovie(
636630
Movie(
637631
uri = uiMedia.media.uri,
638-
info = Movie.Info(uiMedia.getDisplayTitle(), uiMedia.media.folderDisplayName)
632+
info = Movie.Info(
633+
title = uiMedia.getDisplayTitle(),
634+
subtitle = uiMedia.media.folderDisplayName
635+
)
639636
)
640637
)
641638
.setScreenView(imageView)
642639
.setFooterViewEnabled(true)
643-
.show(childFragmentManager)
640+
.showSafely(childFragmentManager)
644641
}
645642

646643
override fun onVideoCheckboxClicked(uiMedia: UIMedia) {
@@ -739,10 +736,7 @@ internal class MediaStoreFragment : BottomSheetDialogFragment(),
739736
}
740737

741738
override fun onPlayerError(cause: Throwable?) {
742-
toast?.cancel()
743-
toast = null
744-
toast = Toast.makeText(context, R.string.bazaar_error_player, Toast.LENGTH_SHORT)
745-
toast?.show()
739+
Toast.makeText(context, R.string.bazaar_error_player, Toast.LENGTH_SHORT).show()
746740
}
747741
})
748742
.also { viewLifecycleOwner.lifecycle.addObserver(it) }
@@ -799,27 +793,17 @@ internal class MediaStoreFragment : BottomSheetDialogFragment(),
799793
override fun onDocumentIconClicked(uiMultimedia: UIMultimedia) {
800794
val path = uiMultimedia.multimedia.path
801795
if (path.isNullOrBlank()) {
802-
toast?.cancel()
803-
toast = null
804-
toast = Toast.makeText(requireContext(), R.string.bazaar_error_file_not_found, Toast.LENGTH_SHORT)
805-
toast?.show()
806-
return
796+
return Toast.makeText(context, R.string.bazaar_error_file_not_found, Toast.LENGTH_SHORT).show()
807797
}
808798
val file = File(path)
809799
when (val action = file.open(requireContext())) {
810800
is OpenFileAction.Success -> {
811801
if (!action.tryToLaunch(requireContext())) {
812-
toast?.cancel()
813-
toast = null
814-
toast = Toast.makeText(requireContext(), R.string.bazaar_error_file_not_found, Toast.LENGTH_SHORT)
815-
toast?.show()
802+
Toast.makeText(context, R.string.bazaar_error_file_not_found, Toast.LENGTH_SHORT).show()
816803
}
817804
}
818805
is OpenFileAction.Error -> {
819-
toast?.cancel()
820-
toast = null
821-
toast = Toast.makeText(requireContext(), R.string.bazaar_error_file_not_found, Toast.LENGTH_SHORT)
822-
toast?.show()
806+
Toast.makeText(context, R.string.bazaar_error_file_not_found, Toast.LENGTH_SHORT).show()
823807
}
824808
}
825809
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package kz.zhombie.bazaar.utils
2+
3+
import androidx.fragment.app.Fragment
4+
import androidx.fragment.app.FragmentManager
5+
import kz.zhombie.cinema.CinemaDialogFragment
6+
import kz.zhombie.museum.MuseumDialogFragment
7+
8+
const val TAG = "ArbatDialogFragment"
9+
10+
@Suppress("unused")
11+
fun MuseumDialogFragment.Builder.dismissPrevious(fragmentManager: FragmentManager): Fragment? {
12+
val fragment = fragmentManager.findFragmentByTag(TAG)
13+
if (fragment is MuseumDialogFragment) {
14+
fragment.dismiss()
15+
}
16+
return fragment
17+
}
18+
19+
fun MuseumDialogFragment.Builder.showSafely(fragmentManager: FragmentManager): MuseumDialogFragment {
20+
dismissPrevious(fragmentManager)
21+
setTag(TAG)
22+
return show(fragmentManager)
23+
}
24+
25+
26+
@Suppress("unused")
27+
fun CinemaDialogFragment.Builder.dismissPrevious(fragmentManager: FragmentManager): Fragment? {
28+
val fragment = fragmentManager.findFragmentByTag(TAG)
29+
if (fragment is CinemaDialogFragment) {
30+
fragment.dismiss()
31+
}
32+
return fragment
33+
}
34+
35+
fun CinemaDialogFragment.Builder.showSafely(fragmentManager: FragmentManager): CinemaDialogFragment {
36+
dismissPrevious(fragmentManager)
37+
setTag(TAG)
38+
return show(fragmentManager)
39+
}

sample/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ dependencies {
7878
implementation 'androidx.appcompat:appcompat:1.3.0'
7979

8080
// Material components
81-
implementation 'com.google.android.material:material:1.3.0'
81+
implementation 'com.google.android.material:material:1.4.0-rc01'
8282

8383
// Firebase
8484
implementation platform('com.google.firebase:firebase-bom:28.1.0')

0 commit comments

Comments
 (0)