From 8d5df9c9eb12371a7b7c0394a6f7bb6a90e75e4e Mon Sep 17 00:00:00 2001 From: arrase Date: Mon, 5 Dec 2016 21:14:15 +0100 Subject: [PATCH] better cookie dialog --- .../dialogs/HSActionsDialog.java | 7 ++- .../dialogs/HSCookieDialog.java | 56 +++++++++++++++++++ .../hiddenservices/dialogs/HSDataDialog.java | 3 + app/src/main/res/layout/layout_hs_cookie.xml | 25 +++++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSCookieDialog.java create mode 100644 app/src/main/res/layout/layout_hs_cookie.xml diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java index 06b650bb..ff7f7e13 100644 --- a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java +++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSActionsDialog.java @@ -87,15 +87,16 @@ public class HSActionsDialog extends DialogFragment { showAuth.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String auth_cookie_value = arguments.getString("auth_cookie_value"); + if (arguments.getInt("auth_cookie") == 1) { if (auth_cookie_value == null || auth_cookie_value.length() < 1) { Toast.makeText( v.getContext(), R.string.please_restart_Orbot_to_enable_the_changes, Toast.LENGTH_LONG ).show(); } else { - new AlertDialog.Builder(getActivity()) - .setMessage(auth_cookie_value) - .show(); + HSCookieDialog dialog = new HSCookieDialog(); + dialog.setArguments(arguments); + dialog.show(getFragmentManager(), "HSCookieDialog"); } } else { Toast.makeText( diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSCookieDialog.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSCookieDialog.java new file mode 100644 index 00000000..ff53cec1 --- /dev/null +++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSCookieDialog.java @@ -0,0 +1,56 @@ +package org.torproject.android.ui.hiddenservices.dialogs; + +import android.app.Dialog; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import org.torproject.android.R; + +public class HSCookieDialog extends DialogFragment { + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final View dialog_view = getActivity().getLayoutInflater().inflate(R.layout.layout_hs_cookie, null); + + final Bundle arguments = getArguments(); + final String auth_cookie_value = arguments.getString("auth_cookie_value"); + + final AlertDialog cookieDialog = new AlertDialog.Builder(getActivity()) + .setView(dialog_view) + .create(); + + TextView cookie = (TextView) dialog_view.findViewById(R.id.hs_cookie); + cookie.setText(auth_cookie_value); + + Button clipboard = (Button) dialog_view.findViewById(R.id.hs_cookie_to_clipboard); + clipboard.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Context mContext = v.getContext(); + ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("cookie", auth_cookie_value); + clipboard.setPrimaryClip(clip); + Toast.makeText(mContext, R.string.done, Toast.LENGTH_LONG).show(); + cookieDialog.dismiss(); + } + }); + + Button cancel = (Button) dialog_view.findViewById(R.id.hs_cookie_cancel); + cancel.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + cookieDialog.dismiss(); + } + }); + + return cookieDialog; + } +} diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java index 56c6d3f4..98255604 100644 --- a/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java +++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/dialogs/HSDataDialog.java @@ -47,6 +47,9 @@ public class HSDataDialog extends DialogFragment { if (checkInput(serverName, localPort, onionPort)) { saveData(serverName, localPort, onionPort, authCookie); + Toast.makeText( + v.getContext(), R.string.please_restart_Orbot_to_enable_the_changes, Toast.LENGTH_LONG + ).show(); serviceDataDialog.dismiss(); } } diff --git a/app/src/main/res/layout/layout_hs_cookie.xml b/app/src/main/res/layout/layout_hs_cookie.xml new file mode 100644 index 00000000..398178f5 --- /dev/null +++ b/app/src/main/res/layout/layout_hs_cookie.xml @@ -0,0 +1,25 @@ + + + + + +