Skip to content

Commit

Permalink
allow to share and delete proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Sep 23, 2024
1 parent 8abe45f commit 4ba9f15
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,22 @@ public View getView(final int position, View v, final ViewGroup parent) {
checkmark.setVisibility(View.GONE);
status.setVisibility(View.GONE);
}

v.setOnClickListener(view -> {
if (itemClickListener != null) {
itemClickListener.onItemClick(proxyUrl);
}
});
v.findViewById(R.id.share).setOnClickListener(view -> {
if (itemClickListener != null) {
itemClickListener.onItemShare(proxyUrl);
}
});
v.findViewById(R.id.delete).setOnClickListener(view -> {
if (itemClickListener != null) {
itemClickListener.onItemDelete(proxyUrl);
}
});

return v;
}
Expand Down Expand Up @@ -148,5 +159,8 @@ public void setItemClickListener(@Nullable ItemClickListener listener) {

public interface ItemClickListener {
void onItemClick(String proxyUrl);
void onItemShare(String proxyUrl);
void onItemDelete(String proxyUrl);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_PROXY_ENABLED;
import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_PROXY_URL;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -24,6 +25,9 @@
import org.thoughtcrime.securesms.connect.DcEventCenter;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.Util;

import java.util.LinkedList;

public class ProxySettingsActivity extends BaseActionBarActivity
implements ProxyListAdapter.ItemClickListener, DcEventCenter.DcEventDelegate {
Expand Down Expand Up @@ -100,6 +104,43 @@ public void onItemClick(String proxyUrl) {
}
}

@Override
public void onItemShare(String proxyUrl) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, proxyUrl);
startActivity(Intent.createChooser(intent, getString(R.string.chat_share_with_title)));
}

@Override
public void onItemDelete(String proxyUrl) {
String host = DcHelper.getContext(this).checkQr(proxyUrl).getText1();
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle(R.string.proxy_delete)
.setMessage(getString(R.string.proxy_delete_explain, host))
.setPositiveButton(R.string.delete, (dlg, btn) -> deleteProxy(proxyUrl))
.setNegativeButton(android.R.string.cancel, null)
.show();
Util.redPositiveButton(dialog);
}

private void deleteProxy(String proxyUrl) {
final LinkedList<String> proxies = new LinkedList<>();
for (String proxy: DcHelper.get(this, CONFIG_PROXY_URL).split("\n")) {
if (!proxy.equals(proxyUrl)) {
proxies.add(proxy);
}
}
if (proxies.isEmpty()) {
DcHelper.set(this, CONFIG_PROXY_ENABLED, "0");
proxySwitch.setChecked(false);
}
String proxyUrls = String.join("\n", proxies);
DcHelper.set(this, CONFIG_PROXY_URL, proxyUrls);
restartIO();
adapter.changeData(proxyUrls);
}

private void showAddProxyDialog() {
View view = View.inflate(this, R.layout.single_line_input, null);
EditText inputField = view.findViewById(R.id.input_field);
Expand Down
28 changes: 28 additions & 0 deletions src/main/res/layout/proxy_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/share"
android:drawablePadding="5dp"
android:singleLine="true"
android:ellipsize="marquee"
Expand All @@ -31,6 +32,7 @@
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/host"
android:layout_toStartOf="@id/share"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
>
Expand All @@ -41,6 +43,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="5dp"
android:contentDescription="@null"
android:src="@drawable/ic_delivery_status_sent"
app:tint="?attr/conversation_list_item_date_color"
/>
Expand Down Expand Up @@ -75,4 +78,29 @@

</LinearLayout>

<ImageButton
android:id="@+id/share"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toStartOf="@id/delete"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:contentDescription="@string/menu_share"
android:background="@drawable/touch_highlight_background"
android:src="@drawable/ic_share_white_24dp"
app:tint="?attr/conversation_list_item_date_color"
/>

<ImageButton
android:id="@+id/delete"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:contentDescription="@string/delete"
android:background="@drawable/touch_highlight_background"
android:src="@drawable/ic_delete_white_24dp"
app:tint="?attr/conversation_list_item_date_color"
/>

</RelativeLayout>
2 changes: 2 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@
<string name="proxy_add_url_hint">Enter proxy URL here</string>
<string name="proxy_invalid">Invalid or unsupported proxy URL</string>
<string name="proxy_list_header">Connections</string>
<string name="proxy_delete">Delete Proxy</string>
<string name="proxy_delete_explain">Are you sure you want to delete \"%1$s\"?</string>

<!-- deprecated -->
<string name="login_socks5">SOCKS5</string>
Expand Down

0 comments on commit 4ba9f15

Please sign in to comment.