diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-06-24 13:30:36 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-06-24 13:30:36 -0300 |
| commit | e24b67eab9ecc69781fd0f8f05039cf03914c91b (patch) | |
| tree | cfd8a2adf0bce5bf68869826d3241b506a1f21cf /android/src | |
| parent | 70779ba7aa7aa41a24558f99698d8b106a4ec457 (diff) | |
| parent | e76c997d2cc654b6c4ea24f079fde9cf1ac038a1 (diff) | |
| download | mullvadvpn-e24b67eab9ecc69781fd0f8f05039cf03914c91b.tar.xz mullvadvpn-e24b67eab9ecc69781fd0f8f05039cf03914c91b.zip | |
Merge branch 'confirm-no-email-dialog'
Diffstat (limited to 'android/src')
6 files changed, 135 insertions, 9 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConfirmNoEmailDialogFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConfirmNoEmailDialogFragment.kt new file mode 100644 index 0000000000..1502d01a4f --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConfirmNoEmailDialogFragment.kt @@ -0,0 +1,60 @@ +package net.mullvad.mullvadvpn + +import kotlinx.coroutines.CompletableDeferred + +import android.app.Dialog +import android.content.Context +import android.content.DialogInterface +import android.graphics.drawable.ColorDrawable +import android.os.Bundle +import android.support.v4.app.DialogFragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button + +import net.mullvad.mullvadvpn.dataproxy.MullvadProblemReport + +class ConfirmNoEmailDialogFragment : DialogFragment() { + private var confirmNoEmail: CompletableDeferred<Boolean>? = null + + override fun onAttach(context: Context) { + super.onAttach(context) + + val parentActivity = context as MainActivity + + confirmNoEmail = parentActivity.problemReport.confirmNoEmail + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + val view = inflater.inflate(R.layout.confirm_no_email, container, false) + + view.findViewById<Button>(R.id.back_button).setOnClickListener { + activity?.onBackPressed() + } + + view.findViewById<Button>(R.id.send_button).setOnClickListener { + confirmNoEmail?.complete(true) + confirmNoEmail = null + dismiss() + } + + return view + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = super.onCreateDialog(savedInstanceState) + + dialog.window.setBackgroundDrawable(ColorDrawable(android.R.color.transparent)) + + return dialog + } + + override fun onDismiss(dialogInterface: DialogInterface) { + confirmNoEmail?.complete(false) + } +} diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ProblemReportFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ProblemReportFragment.kt index 1e72aef5f6..e2caee4fd8 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ProblemReportFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ProblemReportFragment.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn import kotlinx.coroutines.async import kotlinx.coroutines.launch +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job @@ -82,7 +83,7 @@ class ProblemReportFragment : Fragment() { sendButton.setOnClickListener { sendReportJob?.cancel() - sendReportJob = sendReport() + sendReportJob = sendReport(true) } editMessageButton.setOnClickListener { @@ -90,7 +91,7 @@ class ProblemReportFragment : Fragment() { } tryAgainButton.setOnClickListener { - sendReportJob = sendReport() + sendReportJob = sendReport(false) } userEmailInput.setText(problemReport.userEmail) @@ -112,22 +113,33 @@ class ProblemReportFragment : Fragment() { super.onDestroyView() } - private fun sendReport() = GlobalScope.launch(Dispatchers.Main) { + private fun sendReport(shouldConfirmNoEmail: Boolean) = GlobalScope.launch(Dispatchers.Main) { val userEmail = userEmailInput.text.toString() problemReport.userEmail = userEmail problemReport.userMessage = userMessageInput.text.toString() - showSendingScreen() + if (!userEmail.isEmpty() || !shouldConfirmNoEmail || confirmSendWithNoEmail()) { + showSendingScreen() - if (problemReport.send().await()) { - clearForm() - showSuccessScreen(userEmail) - } else { - showErrorScreen() + if (problemReport.send().await()) { + clearForm() + showSuccessScreen(userEmail) + } else { + showErrorScreen() + } } } + private suspend fun confirmSendWithNoEmail(): Boolean { + val confirmation = CompletableDeferred<Boolean>() + + problemReport.confirmNoEmail = confirmation + showConfirmNoEmailDialog() + + return confirmation.await() + } + private fun clearForm() { userEmailInput.setText("") userMessageInput.setText("") @@ -140,6 +152,14 @@ class ProblemReportFragment : Fragment() { bodyContainer.displayedChild = 0 } + private fun showConfirmNoEmailDialog() { + val transaction = fragmentManager?.beginTransaction() + + transaction?.addToBackStack(null) + + ConfirmNoEmailDialogFragment().show(transaction, null) + } + private fun showSendingScreen() { bodyContainer.displayedChild = 1 diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt index d1794fbc3f..4a8ac58a24 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/MullvadProblemReport.kt @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.dataproxy import java.io.File import kotlinx.coroutines.async +import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -13,6 +14,8 @@ class MullvadProblemReport { private var collectJob: Deferred<Boolean>? = null private var sendJob: Deferred<Boolean>? = null + var confirmNoEmail: CompletableDeferred<Boolean>? = null + var userEmail = "" var userMessage = "" diff --git a/android/src/main/res/drawable/dialog_background.xml b/android/src/main/res/drawable/dialog_background.xml new file mode 100644 index 0000000000..1dbad0d9b1 --- /dev/null +++ b/android/src/main/res/drawable/dialog_background.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape + xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle" + > + <corners android:radius="11dp"/> + <solid android:color="@color/darkBlue"/> +</shape> diff --git a/android/src/main/res/layout/confirm_no_email.xml b/android/src/main/res/layout/confirm_no_email.xml new file mode 100644 index 0000000000..dc6561e530 --- /dev/null +++ b/android/src/main/res/layout/confirm_no_email.xml @@ -0,0 +1,29 @@ +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="16dp" + android:background="@drawable/dialog_background" + android:orientation="vertical" + android:gravity="left" + android:elevation="2dp" + > + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="0" + android:layout_marginBottom="12dp" + android:textColor="@color/white80" + android:textSize="16sp" + android:text="@string/confirm_no_email" + /> + <Button android:id="@+id/send_button" + android:text="@string/send_anyway" + style="@style/GreenButton" + /> + <Button android:id="@+id/back_button" + android:layout_marginTop="16dp" + android:text="@string/back" + style="@style/RedButton" + /> +</LinearLayout> diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml index b0087e1942..a3da5d4e96 100644 --- a/android/src/main/res/values/strings.xml +++ b/android/src/main/res/values/strings.xml @@ -36,6 +36,12 @@ <string name="sending">Sending...</string> <string name="sent">Sent</string> <string name="failed_to_send">Failed to send</string> + <string name="confirm_no_email"> + You are about to send the problem report without a way for us to get back to you. If you + want an answer to your report you will have to enter an email address. + </string> + <string name="send_anyway">Send anyway</string> + <string name="back">Back</string> <string name="sent_thanks">Thanks! We will look into this.</string> <string name="sent_contact">If needed we will contact you on</string> <string name="failed_to_send_details"> |
