Skip to content

Commit

Permalink
Fix textStoryToggle visibility when hasSelectedMedia
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagar0-0 committed Jan 28, 2025
1 parent ec84072 commit 4367bf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ class MediaSelectionActivity :
textViewModel.restoreFromInstanceState(savedInstanceState)
}

viewModel.hasSelectedMedia.observe(this) { hasSelectedMedia->
if(hasSelectedMedia) {
textStoryToggle.visible = false
} else {
textStoryToggle.visible = canDisplayStorySwitch()
}
}

(supportFragmentManager.findFragmentByTag(NAV_HOST_TAG) as NavHostFragment).navController.addOnDestinationChangedListener { _, d, _ ->
when (d.id) {
R.id.mediaCaptureFragment -> {
Expand Down Expand Up @@ -233,7 +241,6 @@ class MediaSelectionActivity :
private fun canDisplayStorySwitch(): Boolean {
return Stories.isFeatureEnabled() &&
isCameraFirst() &&
!viewModel.hasSelectedMedia() &&
(destination == MediaSelectionDestination.ChooseAfterMediaSelection || destination is MediaSelectionDestination.SingleStory)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.os.Parcel
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.distinctUntilChanged
import androidx.lifecycle.map
import com.google.common.io.ByteStreams
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
Expand Down Expand Up @@ -80,6 +82,8 @@ class MediaSelectionViewModel(

val state: LiveData<MediaSelectionState> = store.stateLiveData

val hasSelectedMedia: LiveData<Boolean> = store.stateLiveData.map { it.selectedMedia.isNotEmpty() }.distinctUntilChanged()

private val internalHudCommands = PublishSubject.create<HudCommand>()

val mediaErrors: BehaviorSubject<MediaValidator.FilterError> = BehaviorSubject.createDefault(MediaValidator.FilterError.None)
Expand Down Expand Up @@ -469,10 +473,6 @@ class MediaSelectionViewModel(
}
}

fun hasSelectedMedia(): Boolean {
return store.state.selectedMedia.isNotEmpty()
}

fun clearMediaErrors() {
mediaErrors.onNext(MediaValidator.FilterError.None)
}
Expand Down

0 comments on commit 4367bf4

Please sign in to comment.