some actions

This commit is contained in:
arrase 2016-11-20 04:39:34 +01:00
parent 8494cfb633
commit 8e9bc2f840
5 changed files with 91 additions and 15 deletions

View File

@ -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");
}
});

View File

@ -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);

View File

@ -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();
}

View File

@ -5,16 +5,42 @@
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
tools:paddingLeft="15dp">
<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: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:textSize="18sp"
android:paddingLeft="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -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>