mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Implement edge-to-edge, add edit button, and main transport selection
- Add android:fitsSystemWindows="true" to activity layout for proper edge-to-edge support - Add edit button (pencil icon) next to delete button for editing transports - Add "Main" indicator for the main transport (CONFIG_CONFIGURED_ADDRESS) - Clicking on a transport now makes it the main transport instead of opening edit - Edit button opens EditTransportActivity with transport data - FAB still adds new transport as intended Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
This commit is contained in:
@@ -30,6 +30,7 @@ public class TransportListActivity extends BaseActionBarActivity
|
||||
private FloatingActionButton fabAdd;
|
||||
private Rpc rpc;
|
||||
private int accId;
|
||||
private String mainTransportAddr;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -67,9 +68,11 @@ public class TransportListActivity extends BaseActionBarActivity
|
||||
Util.runOnBackground(() -> {
|
||||
try {
|
||||
List<EnteredLoginParam> transports = rpc.listTransports(accId);
|
||||
Util.runOnMain(() -> adapter.setTransports(transports));
|
||||
mainTransportAddr = DcHelper.get(this, DcHelper.CONFIG_CONFIGURED_ADDRESS);
|
||||
Util.runOnMain(() -> adapter.setTransports(transports, mainTransportAddr));
|
||||
} catch (RpcException e) {
|
||||
Util.runOnMain(() -> adapter.setTransports(null));
|
||||
mainTransportAddr = DcHelper.get(this, DcHelper.CONFIG_CONFIGURED_ADDRESS);
|
||||
Util.runOnMain(() -> adapter.setTransports(null, mainTransportAddr));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -81,6 +84,17 @@ public class TransportListActivity extends BaseActionBarActivity
|
||||
|
||||
@Override
|
||||
public void onTransportClick(EnteredLoginParam transport) {
|
||||
// Clicking on a transport makes it the main transport
|
||||
if (transport.addr != null && !transport.addr.equals(mainTransportAddr)) {
|
||||
Util.runOnBackground(() -> {
|
||||
DcHelper.getContext(this).setConfig(DcHelper.CONFIG_CONFIGURED_ADDRESS, transport.addr);
|
||||
Util.runOnMain(this::loadTransports);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportEdit(EnteredLoginParam transport) {
|
||||
Intent intent = new Intent(this, EditTransportActivity.class);
|
||||
intent.putExtra(EXTRA_TRANSPORT_ADDR, transport.addr);
|
||||
startActivity(intent);
|
||||
|
||||
@@ -18,9 +18,11 @@ public class TransportListAdapter extends RecyclerView.Adapter<TransportListAdap
|
||||
|
||||
private List<EnteredLoginParam> transports = new ArrayList<>();
|
||||
private final OnTransportClickListener listener;
|
||||
private String mainTransportAddr;
|
||||
|
||||
public interface OnTransportClickListener {
|
||||
void onTransportClick(EnteredLoginParam transport);
|
||||
void onTransportEdit(EnteredLoginParam transport);
|
||||
void onTransportDelete(EnteredLoginParam transport);
|
||||
}
|
||||
|
||||
@@ -28,8 +30,9 @@ public class TransportListAdapter extends RecyclerView.Adapter<TransportListAdap
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setTransports(List<EnteredLoginParam> transports) {
|
||||
public void setTransports(List<EnteredLoginParam> transports, String mainTransportAddr) {
|
||||
this.transports = transports != null ? transports : new ArrayList<>();
|
||||
this.mainTransportAddr = mainTransportAddr;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -44,7 +47,8 @@ public class TransportListAdapter extends RecyclerView.Adapter<TransportListAdap
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull TransportViewHolder holder, int position) {
|
||||
EnteredLoginParam transport = transports.get(position);
|
||||
holder.bind(transport, listener);
|
||||
boolean isMain = transport.addr != null && transport.addr.equals(mainTransportAddr);
|
||||
holder.bind(transport, isMain, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,16 +59,20 @@ public class TransportListAdapter extends RecyclerView.Adapter<TransportListAdap
|
||||
static class TransportViewHolder extends RecyclerView.ViewHolder {
|
||||
private final TextView emailText;
|
||||
private final TextView serverText;
|
||||
private final TextView mainIndicator;
|
||||
private final ImageView editButton;
|
||||
private final ImageView deleteButton;
|
||||
|
||||
public TransportViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
emailText = itemView.findViewById(R.id.transport_email);
|
||||
serverText = itemView.findViewById(R.id.transport_server);
|
||||
mainIndicator = itemView.findViewById(R.id.main_transport_indicator);
|
||||
editButton = itemView.findViewById(R.id.edit_button);
|
||||
deleteButton = itemView.findViewById(R.id.delete_button);
|
||||
}
|
||||
|
||||
public void bind(EnteredLoginParam transport, OnTransportClickListener listener) {
|
||||
public void bind(EnteredLoginParam transport, boolean isMain, OnTransportClickListener listener) {
|
||||
emailText.setText(transport.addr);
|
||||
|
||||
String serverInfo = "";
|
||||
@@ -74,12 +82,20 @@ public class TransportListAdapter extends RecyclerView.Adapter<TransportListAdap
|
||||
serverText.setText(serverInfo);
|
||||
serverText.setVisibility(serverInfo.isEmpty() ? View.GONE : View.VISIBLE);
|
||||
|
||||
mainIndicator.setVisibility(isMain ? View.VISIBLE : View.GONE);
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
if (listener != null) {
|
||||
listener.onTransportClick(transport);
|
||||
}
|
||||
});
|
||||
|
||||
editButton.setOnClickListener(v -> {
|
||||
if (listener != null) {
|
||||
listener.onTransportEdit(transport);
|
||||
}
|
||||
});
|
||||
|
||||
deleteButton.setOnClickListener(v -> {
|
||||
if (listener != null) {
|
||||
listener.onTransportDelete(transport);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="?android:attr/windowBackground">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
@@ -15,14 +15,35 @@
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/transport_email"
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
tools:text="user@example.com" />
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/transport_email"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textSize="16sp"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
tools:text="user@example.com" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/main_transport_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:text="@string/main"
|
||||
android:textSize="12sp"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/transport_server"
|
||||
@@ -36,6 +57,16 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/edit_button"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/ic_create_white_24dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/edit_transport"
|
||||
android:tint="?android:attr/textColorSecondary" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/delete_button"
|
||||
android:layout_width="48dp"
|
||||
|
||||
@@ -693,6 +693,7 @@
|
||||
<string name="add_transport">Add Transport</string>
|
||||
<string name="remove_transport">Remove Transport</string>
|
||||
<string name="edit_transport">Edit Transport</string>
|
||||
<string name="main">Main</string>
|
||||
<!-- shown if a QR code was scanned that can be used as a transport -->
|
||||
<string name="confirm_add_transport">Add this transport?</string>
|
||||
<string name="invalid_transport_qr">The scanned QR code does not contain a valid transport.</string>
|
||||
|
||||
Reference in New Issue
Block a user