-
Notifications
You must be signed in to change notification settings - Fork 130
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 #10664 from woocommerce/issue-3885/variation-delet…
…e-confirmation [Issue 3885] product variation delete confirmation dialog to a dialog fragment
- Loading branch information
Showing
6 changed files
with
144 additions
and
13 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
15 changes: 15 additions & 0 deletions
15
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/dialog/DialogParams.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,15 @@ | ||
package com.woocommerce.android.ui.dialog | ||
|
||
import android.os.Parcelable | ||
import androidx.annotation.StringRes | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class DialogParams( | ||
@StringRes val titleId: Int? = null, | ||
@StringRes val messageId: Int? = null, | ||
@StringRes val positiveButtonId: Int? = null, | ||
@StringRes val negativeButtonId: Int? = null, | ||
@StringRes val neutralButtonId: Int? = null, | ||
val cancelable: Boolean = true | ||
) : Parcelable |
60 changes: 60 additions & 0 deletions
60
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/dialog/WooDialogFragment.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,60 @@ | ||
package com.woocommerce.android.ui.dialog | ||
|
||
import android.app.Dialog | ||
import android.os.Bundle | ||
import androidx.fragment.app.DialogFragment | ||
import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
|
||
class WooDialogFragment : DialogFragment() { | ||
|
||
private var dialogInteractionListener: DialogInteractionListener? = null | ||
|
||
fun setDialogInteractionListener(listener: DialogInteractionListener) { | ||
dialogInteractionListener = listener | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
@Suppress("DEPRECATION") val params = requireArguments().getParcelable<DialogParams>(ARG_DIALOG_PARAMS)!! | ||
|
||
val builder = MaterialAlertDialogBuilder(requireContext()) | ||
.setCancelable(params.cancelable) | ||
|
||
params.titleId?.let { builder.setTitle(it) } | ||
params.messageId?.let { builder.setMessage(it) } | ||
params.positiveButtonId?.let { posId -> | ||
builder.setPositiveButton(posId) { _, _ -> | ||
dialogInteractionListener?.onPositiveButtonClicked() | ||
} | ||
} | ||
params.negativeButtonId?.let { negId -> | ||
builder.setNegativeButton(negId) { _, _ -> | ||
dialogInteractionListener?.onNegativeButtonClicked() | ||
} | ||
} | ||
params.neutralButtonId?.let { neutId -> | ||
builder.setNeutralButton(neutId) { _, _ -> | ||
dialogInteractionListener?.onNeutralButtonClicked() | ||
} | ||
} | ||
|
||
return builder.create() | ||
} | ||
|
||
interface DialogInteractionListener { | ||
fun onPositiveButtonClicked() | ||
fun onNegativeButtonClicked() | ||
fun onNeutralButtonClicked() | ||
} | ||
|
||
companion object { | ||
const val ARG_DIALOG_PARAMS = "dialog_params" | ||
const val TAG = "WooDialogFragment" | ||
fun newInstance(params: DialogParams): WooDialogFragment { | ||
return WooDialogFragment().apply { | ||
arguments = Bundle().apply { | ||
putParcelable(ARG_DIALOG_PARAMS, params) | ||
} | ||
} | ||
} | ||
} | ||
} |
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