Skip to content

Commit

Permalink
Closes mozilla-mobile#27209: remove the snackbar refference
Browse files Browse the repository at this point in the history
  • Loading branch information
mike a committed Sep 29, 2022
1 parent 90765ad commit d7b4b4f
Showing 1 changed file with 50 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.ViewGroup
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
Expand All @@ -37,60 +38,62 @@ class WallpaperSettingsFragment : Fragment() {
requireComponents.useCases.wallpaperUseCases
}

private var snackBar: FenixSnackbar? = null

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
Wallpapers.wallpaperSettingsOpened.record(NoExtras())
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
FirefoxTheme {
val wallpapers = appStore.observeAsComposableState { state ->
state.wallpaperState.availableWallpapers
}.value ?: listOf()
val currentWallpaper = appStore.observeAsComposableState { state ->
state.wallpaperState.currentWallpaper
}.value ?: Wallpaper.Default
return CoordinatorLayout(requireContext()).apply {
addView(
ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
FirefoxTheme {
val wallpapers = appStore.observeAsComposableState { state ->
state.wallpaperState.availableWallpapers
}.value ?: listOf()
val currentWallpaper = appStore.observeAsComposableState { state ->
state.wallpaperState.currentWallpaper
}.value ?: Wallpaper.Default

val coroutineScope = rememberCoroutineScope()
val coroutineScope = rememberCoroutineScope()

WallpaperSettings(
wallpaperGroups = if (FeatureFlags.wallpaperV2Enabled) {
wallpapers.groupByDisplayableCollection()
} else {
mapOf(Wallpaper.ClassicFirefoxCollection to wallpapers)
},
defaultWallpaper = Wallpaper.Default,
selectedWallpaper = currentWallpaper,
loadWallpaperResource = {
wallpaperUseCases.loadThumbnail(it)
},
onSelectWallpaper = {
coroutineScope.launch {
val result = wallpaperUseCases.selectWallpaper(it)
onWallpaperSelected(it, result, this@apply)
}
},
onLearnMoreClick = { url, collectionName ->
(activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = url,
newTab = true,
from = BrowserDirection.FromWallpaper,
)
Wallpapers.learnMoreLinkClick.record(
Wallpapers.LearnMoreLinkClickExtra(
url = url,
collectionName = collectionName,
),
WallpaperSettings(
wallpaperGroups = if (FeatureFlags.wallpaperV2Enabled) {
wallpapers.groupByDisplayableCollection()
} else {
mapOf(Wallpaper.ClassicFirefoxCollection to wallpapers)
},
defaultWallpaper = Wallpaper.Default,
selectedWallpaper = currentWallpaper,
loadWallpaperResource = {
wallpaperUseCases.loadThumbnail(it)
},
onSelectWallpaper = {
coroutineScope.launch {
val result = wallpaperUseCases.selectWallpaper(it)
onWallpaperSelected(it, result, requireView())
}
},
onLearnMoreClick = { url, collectionName ->
(activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = url,
newTab = true,
from = BrowserDirection.FromWallpaper,
)
Wallpapers.learnMoreLinkClick.record(
Wallpapers.LearnMoreLinkClickExtra(
url = url,
collectionName = collectionName,
),
)
},
)
},
)
}
}
}
}
},
)
}
}

Expand All @@ -108,10 +111,7 @@ class WallpaperSettingsFragment : Fragment() {
.setText(view.context.getString(R.string.wallpaper_updated_snackbar_message))
.setAction(requireContext().getString(R.string.wallpaper_updated_snackbar_action)) {
findNavController().navigate(R.id.homeFragment)
}.also { snackBar ->
this.snackBar = snackBar
snackBar.show()
}
}.show()

Wallpapers.wallpaperSelected.record(
Wallpapers.WallpaperSelectedExtra(
Expand All @@ -132,10 +132,7 @@ class WallpaperSettingsFragment : Fragment() {
val retryResult = wallpaperUseCases.selectWallpaper(wallpaper)
onWallpaperSelected(wallpaper, retryResult, view)
}
}.also { snackBar ->
this.snackBar = snackBar
snackBar.show()
}
}.show()
}
else -> { /* noop */ }
}
Expand All @@ -145,9 +142,4 @@ class WallpaperSettingsFragment : Fragment() {
super.onResume()
showToolbar(getString(R.string.customize_wallpapers))
}

override fun onStop() {
super.onStop()
snackBar?.dismiss()
}
}

0 comments on commit d7b4b4f

Please sign in to comment.