-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18169 from wordpress-mobile/issue/18114-wp-jp-plu…
…gin-overlay-dialog [WP Individual JP Plugin] Show dialog with overlay
- Loading branch information
Showing
20 changed files
with
500 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.wordpress.android.ui.jetpackoverlay.individualplugin | ||
|
||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.lifecycleScope | ||
import com.google.android.material.bottomsheet.BottomSheetDialog | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import org.wordpress.android.ui.ActivityLauncherWrapper | ||
import org.wordpress.android.ui.compose.theme.AppTheme | ||
import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginViewModel.ActionEvent | ||
import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginViewModel.UiState | ||
import org.wordpress.android.ui.jetpackoverlay.individualplugin.compose.WPJetpackIndividualPluginOverlayScreen | ||
import org.wordpress.android.util.extensions.exhaustive | ||
import org.wordpress.android.util.extensions.fillScreen | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class WPJetpackIndividualPluginFragment : BottomSheetDialogFragment() { | ||
private val viewModel: WPJetpackIndividualPluginViewModel by viewModels() | ||
|
||
@Inject | ||
lateinit var activityLauncher: ActivityLauncherWrapper | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View = ComposeView(requireContext()).apply { | ||
setContent { | ||
AppTheme { | ||
val uiState by viewModel.uiState.collectAsState() | ||
when (val state = uiState) { | ||
is UiState.Loaded -> { | ||
WPJetpackIndividualPluginOverlayScreen( | ||
state.sites, | ||
onCloseClick = viewModel::onDismissScreenClick, | ||
onPrimaryButtonClick = viewModel::onPrimaryButtonClick, | ||
onSecondaryButtonClick = viewModel::onDismissScreenClick, | ||
) | ||
} | ||
|
||
is UiState.None -> {} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
viewModel.onScreenShown() | ||
observeActionEvents() | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = | ||
super.onCreateDialog(savedInstanceState).apply { | ||
(this as? BottomSheetDialog)?.fillScreen() | ||
} | ||
|
||
override fun onCancel(dialog: DialogInterface) { | ||
// called when user hits the back button | ||
viewModel.onDismissScreenClick() | ||
} | ||
|
||
private fun observeActionEvents() { | ||
viewModel.actionEvents.onEach(this::handleActionEvents).launchIn(lifecycleScope) | ||
} | ||
|
||
private fun handleActionEvents(actionEvent: ActionEvent) { | ||
when (actionEvent) { | ||
is ActionEvent.PrimaryButtonClick -> activityLauncher.openPlayStoreLink( | ||
requireActivity(), | ||
ActivityLauncherWrapper.JETPACK_PACKAGE_NAME | ||
) | ||
|
||
is ActionEvent.Dismiss -> dismiss() | ||
}.exhaustive | ||
} | ||
|
||
companion object { | ||
const val TAG = "WP_JETPACK_INDIVIDUAL_PLUGIN_FRAGMENT" | ||
|
||
@JvmStatic | ||
fun newInstance(): WPJetpackIndividualPluginFragment = WPJetpackIndividualPluginFragment() | ||
|
||
@JvmStatic | ||
fun show(fm: FragmentManager): WPJetpackIndividualPluginFragment = newInstance().also { | ||
it.show(fm, TAG) | ||
} | ||
} | ||
} |
Oops, something went wrong.