[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [orbot/master] some actions



commit 8e9bc2f840874e0b9751942240be6a93c31857f5
Author: arrase <arrase@xxxxxxxxx>
Date:   Sun Nov 20 04:39:34 2016 +0100

    some actions
---
 .../android/ui/hs/HiddenServicesActivity.java      | 13 ++++--
 .../android/ui/hs/adapters/OnionListAdapter.java   |  2 +
 .../android/ui/hs/dialogs/HSActionsDialog.java     | 47 ++++++++++++++++++++--
 app/src/main/res/layout/layout_hs_list_item.xml    | 42 +++++++++++++++----
 app/src/main/res/values/strings.xml                |  2 +
 5 files changed, 91 insertions(+), 15 deletions(-)

diff --git a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
index 576f083..26889d0 100644
--- a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
+++ b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java
@@ -2,12 +2,10 @@ package org.torproject.android.ui.hs;
 
 
 import android.content.ContentResolver;
-import android.content.DialogInterface;
 import android.database.ContentObserver;
 import android.os.Bundle;
 import android.os.Handler;
 import android.support.design.widget.FloatingActionButton;
-import android.support.v7.app.AlertDialog;
 import android.support.v7.app.AppCompatActivity;
 import android.view.View;
 import android.widget.AdapterView;
@@ -27,6 +25,7 @@ public class HiddenServicesActivity extends AppCompatActivity {
     private String[] mProjection = new String[]{
             HSContentProvider.HiddenService._ID,
             HSContentProvider.HiddenService.NAME,
+            HSContentProvider.HiddenService.PORT,
             HSContentProvider.HiddenService.DOMAIN};
 
     class HSObserver extends ContentObserver {
@@ -60,7 +59,7 @@ public class HiddenServicesActivity extends AppCompatActivity {
 
         mAdapter = new OnionListAdapter(
                 this,
-                getContentResolver().query(
+                mCR.query(
                         HSContentProvider.CONTENT_URI, mProjection, null, null, null
                 ),
                 0
@@ -77,7 +76,15 @@ public class HiddenServicesActivity extends AppCompatActivity {
 
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                TextView port = (TextView) view.findViewById(R.id.hs_port);
+                TextView onion = (TextView) view.findViewById(R.id.hs_onion);
+
+                Bundle arguments = new Bundle();
+                arguments.putString("port", port.getText().toString());
+                arguments.putString("onion", onion.getText().toString());
+
                 HSActionsDialog dialog = new HSActionsDialog();
+                dialog.setArguments(arguments);
                 dialog.show(getSupportFragmentManager(), "HSActionsDialog");
             }
         });
diff --git a/app/src/main/java/org/torproject/android/ui/hs/adapters/OnionListAdapter.java b/app/src/main/java/org/torproject/android/ui/hs/adapters/OnionListAdapter.java
index 5275730..0ae10cb 100644
--- a/app/src/main/java/org/torproject/android/ui/hs/adapters/OnionListAdapter.java
+++ b/app/src/main/java/org/torproject/android/ui/hs/adapters/OnionListAdapter.java
@@ -23,6 +23,8 @@ public class OnionListAdapter extends CursorAdapter {
 
     @Override
     public void bindView(View view, Context context, Cursor cursor) {
+        TextView port = (TextView) view.findViewById(R.id.hs_port);
+        port.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.PORT)));
         TextView name = (TextView) view.findViewById(R.id.hs_name);
         name.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)));
         TextView domain = (TextView) view.findViewById(R.id.hs_onion);
diff --git a/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java
index 8c5ca48..f490586 100644
--- a/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java
+++ b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSActionsDialog.java
@@ -2,20 +2,29 @@ package org.torproject.android.ui.hs.dialogs;
 
 
 import android.app.Dialog;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
 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.Toast;
 
 import org.torproject.android.R;
+import org.torproject.android.hsutils.HiddenServiceUtils;
+import org.torproject.android.ui.hs.providers.HSContentProvider;
 
 public class HSActionsDialog extends DialogFragment {
 
     @NonNull
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
+        final Bundle arguments = getArguments();
 
         final View dialog_view = getActivity().getLayoutInflater().inflate(R.layout.layout_hs_actions, null);
         final AlertDialog actionDialog = new AlertDialog.Builder(getActivity())
@@ -26,13 +35,40 @@ public class HSActionsDialog extends DialogFragment {
         Button save = (Button) dialog_view.findViewById(R.id.btn_hs_backup);
         save.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
+                Context mContext = v.getContext();
+                HiddenServiceUtils hsutils = new HiddenServiceUtils(mContext);
+                String backupPath = hsutils.createOnionBackup(Integer.parseInt(arguments.getString("port")));
+
+                if (backupPath == null || backupPath.length() < 1) {
+                    Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show();
+                    actionDialog.dismiss();
+                    return;
+                }
+
+                Toast.makeText(mContext, R.string.done, Toast.LENGTH_LONG).show();
+
+                Uri selectedUri = Uri.parse(backupPath);
+                Intent intent = new Intent(Intent.ACTION_VIEW);
+                intent.setDataAndType(selectedUri, "resource/folder");
+
+
+                if (intent.resolveActivityInfo(mContext.getPackageManager(), 0) != null) {
+                    startActivity(intent);
+                } else {
+                    Toast.makeText(mContext, R.string.filemanager_not_available, Toast.LENGTH_LONG).show();
+                }
                 actionDialog.dismiss();
             }
         });
 
-        Button cancel = (Button) dialog_view.findViewById(R.id.btn_hs_clipboard);
-        cancel.setOnClickListener(new View.OnClickListener() {
+        Button copy = (Button) dialog_view.findViewById(R.id.btn_hs_clipboard);
+        copy.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("onion", arguments.getString("onion"));
+                clipboard.setPrimaryClip(clip);
+                Toast.makeText(mContext, R.string.done, Toast.LENGTH_LONG).show();
                 actionDialog.dismiss();
             }
         });
@@ -40,12 +76,15 @@ public class HSActionsDialog extends DialogFragment {
         Button delete = (Button) dialog_view.findViewById(R.id.btn_hs_delete);
         delete.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
+                v.getContext().getContentResolver().delete(
+                        HSContentProvider.CONTENT_URI, "port=" + arguments.getString("port"), null
+                );
                 actionDialog.dismiss();
             }
         });
 
-        Button btn_cancel = (Button) dialog_view.findViewById(R.id.btn_hs_cancel);
-        btn_cancel.setOnClickListener(new View.OnClickListener() {
+        Button cancel = (Button) dialog_view.findViewById(R.id.btn_hs_cancel);
+        cancel.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 actionDialog.dismiss();
             }
diff --git a/app/src/main/res/layout/layout_hs_list_item.xml b/app/src/main/res/layout/layout_hs_list_item.xml
index 539de8f..33ed374 100644
--- a/app/src/main/res/layout/layout_hs_list_item.xml
+++ b/app/src/main/res/layout/layout_hs_list_item.xml
@@ -5,16 +5,42 @@
     android:layout_height="match_parent"
     android:orientation="vertical">
 
-    <TextView
-        android:id="@+id/hs_name"
+    <LinearLayout
+        android:orientation="horizontal"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:textSize="24sp" />
+        android:paddingLeft="15dp"
+        tools:paddingLeft="15dp">
 
-    <TextView
-        android:id="@+id/hs_onion"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:textSize="18sp" />
+        <TextView
+            android:layout_height="match_parent"
+            android:id="@+id/hs_port"
+            android:layout_width="wrap_content"
+            android:textSize="35sp" />
+
+        <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_weight="1">
+
+            <TextView
+                android:id="@+id/hs_name"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textSize="24sp"
+                android:paddingLeft="10dp"
+                android:paddingBottom="10dp" />
+
+            <TextView
+                android:id="@+id/hs_onion"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textSize="18sp"
+                android:paddingLeft="10dp" />
+
+        </LinearLayout>
+
+    </LinearLayout>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6ed7777..cfa2393 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -341,4 +341,6 @@
     <string name="copy_address_to_clipboard">Copy address to clipboard</string>
     <string name="backup_service">Backup Service</string>
     <string name="delete_service">Delete Service</string>
+    <string name="done">Done!</string>
+    <string name="filemanager_not_available">Filemanager not available</string>
 </resources>



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits