some actions
This commit is contained in:
parent
8494cfb633
commit
8e9bc2f840
|
@ -2,12 +2,10 @@ package org.torproject.android.ui.hs;
|
||||||
|
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
@ -27,6 +25,7 @@ public class HiddenServicesActivity extends AppCompatActivity {
|
||||||
private String[] mProjection = new String[]{
|
private String[] mProjection = new String[]{
|
||||||
HSContentProvider.HiddenService._ID,
|
HSContentProvider.HiddenService._ID,
|
||||||
HSContentProvider.HiddenService.NAME,
|
HSContentProvider.HiddenService.NAME,
|
||||||
|
HSContentProvider.HiddenService.PORT,
|
||||||
HSContentProvider.HiddenService.DOMAIN};
|
HSContentProvider.HiddenService.DOMAIN};
|
||||||
|
|
||||||
class HSObserver extends ContentObserver {
|
class HSObserver extends ContentObserver {
|
||||||
|
@ -60,7 +59,7 @@ public class HiddenServicesActivity extends AppCompatActivity {
|
||||||
|
|
||||||
mAdapter = new OnionListAdapter(
|
mAdapter = new OnionListAdapter(
|
||||||
this,
|
this,
|
||||||
getContentResolver().query(
|
mCR.query(
|
||||||
HSContentProvider.CONTENT_URI, mProjection, null, null, null
|
HSContentProvider.CONTENT_URI, mProjection, null, null, null
|
||||||
),
|
),
|
||||||
0
|
0
|
||||||
|
@ -77,7 +76,15 @@ public class HiddenServicesActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
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();
|
HSActionsDialog dialog = new HSActionsDialog();
|
||||||
|
dialog.setArguments(arguments);
|
||||||
dialog.show(getSupportFragmentManager(), "HSActionsDialog");
|
dialog.show(getSupportFragmentManager(), "HSActionsDialog");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,6 +23,8 @@ public class OnionListAdapter extends CursorAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
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);
|
TextView name = (TextView) view.findViewById(R.id.hs_name);
|
||||||
name.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)));
|
name.setText(cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)));
|
||||||
TextView domain = (TextView) view.findViewById(R.id.hs_onion);
|
TextView domain = (TextView) view.findViewById(R.id.hs_onion);
|
||||||
|
|
|
@ -2,20 +2,29 @@ package org.torproject.android.ui.hs.dialogs;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Dialog;
|
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.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.torproject.android.R;
|
import org.torproject.android.R;
|
||||||
|
import org.torproject.android.hsutils.HiddenServiceUtils;
|
||||||
|
import org.torproject.android.ui.hs.providers.HSContentProvider;
|
||||||
|
|
||||||
public class HSActionsDialog extends DialogFragment {
|
public class HSActionsDialog extends DialogFragment {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final Bundle arguments = getArguments();
|
||||||
|
|
||||||
final View dialog_view = getActivity().getLayoutInflater().inflate(R.layout.layout_hs_actions, null);
|
final View dialog_view = getActivity().getLayoutInflater().inflate(R.layout.layout_hs_actions, null);
|
||||||
final AlertDialog actionDialog = new AlertDialog.Builder(getActivity())
|
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);
|
Button save = (Button) dialog_view.findViewById(R.id.btn_hs_backup);
|
||||||
save.setOnClickListener(new View.OnClickListener() {
|
save.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
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();
|
actionDialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Button cancel = (Button) dialog_view.findViewById(R.id.btn_hs_clipboard);
|
Button copy = (Button) dialog_view.findViewById(R.id.btn_hs_clipboard);
|
||||||
cancel.setOnClickListener(new View.OnClickListener() {
|
copy.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
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();
|
actionDialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -40,12 +76,15 @@ public class HSActionsDialog extends DialogFragment {
|
||||||
Button delete = (Button) dialog_view.findViewById(R.id.btn_hs_delete);
|
Button delete = (Button) dialog_view.findViewById(R.id.btn_hs_delete);
|
||||||
delete.setOnClickListener(new View.OnClickListener() {
|
delete.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
v.getContext().getContentResolver().delete(
|
||||||
|
HSContentProvider.CONTENT_URI, "port=" + arguments.getString("port"), null
|
||||||
|
);
|
||||||
actionDialog.dismiss();
|
actionDialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Button btn_cancel = (Button) dialog_view.findViewById(R.id.btn_hs_cancel);
|
Button cancel = (Button) dialog_view.findViewById(R.id.btn_hs_cancel);
|
||||||
btn_cancel.setOnClickListener(new View.OnClickListener() {
|
cancel.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
actionDialog.dismiss();
|
actionDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,42 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
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
|
<TextView
|
||||||
android:id="@+id/hs_name"
|
android:id="@+id/hs_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingBottom="10dp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/hs_onion"
|
android:id="@+id/hs_onion"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp"
|
||||||
|
android:paddingLeft="10dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -341,4 +341,6 @@
|
||||||
<string name="copy_address_to_clipboard">Copy address to clipboard</string>
|
<string name="copy_address_to_clipboard">Copy address to clipboard</string>
|
||||||
<string name="backup_service">Backup Service</string>
|
<string name="backup_service">Backup Service</string>
|
||||||
<string name="delete_service">Delete Service</string>
|
<string name="delete_service">Delete Service</string>
|
||||||
|
<string name="done">Done!</string>
|
||||||
|
<string name="filemanager_not_available">Filemanager not available</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue