Skip to content

Commit

Permalink
Fix endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielcoderX authored and markpash committed Sep 5, 2024
1 parent e8670f9 commit cff6122
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 36 deletions.
39 changes: 34 additions & 5 deletions app/src/main/java/org/bepass/oblivion/EndpointsBottomSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
Expand All @@ -23,7 +24,7 @@
import java.util.Set;

public class EndpointsBottomSheet extends BottomSheetDialogFragment {
private List<Endpoint> endpointsList;
private static List<Endpoint> endpointsList;
public EndpointSelectionListener selectionListener;
private EndpointsAdapter adapter;

Expand All @@ -34,6 +35,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,

RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
Button saveButton = view.findViewById(R.id.saveButton);
Button resetDefaultButton = view.findViewById(R.id.resetDefaultButton); // Add this line
EditText titleEditText = view.findViewById(R.id.titleEditText);
EditText contentEditText = view.findViewById(R.id.contentEditText);

Expand All @@ -44,25 +46,32 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
adapter = new EndpointsAdapter(endpointsList, this::onEndpointSelected);
recyclerView.setAdapter(adapter);

// Handle save button press
saveButton.setOnClickListener(v -> {
String title = titleEditText.getText().toString().trim();
String content = contentEditText.getText().toString().trim();

if (!title.isEmpty() && !content.isEmpty()) {
Endpoint newEndpoint = new Endpoint(title, content);
saveEndpoint(newEndpoint);
adapter.notifyDataSetChanged(); // Refresh the RecyclerView
adapter.notifyDataSetChanged();

// Clear the input fields
titleEditText.setText("");
contentEditText.setText("");
}
});

// Handle reset to default button press
resetDefaultButton.setOnClickListener(v -> {
endpointsList.clear();
endpointsList.add(new Endpoint("Default", "engage.cloudflareclient.com:2408")); // Add default endpoint
saveEndpoints(); // Save the updated list
adapter.notifyDataSetChanged();
});

return view;
}


private void loadEndpoints() {
Set<String> savedEndpoints = FileManager.getStringSet("saved_endpoints", new HashSet<>());
for (String endpoint : savedEndpoints) {
Expand All @@ -81,7 +90,6 @@ private void saveEndpoint(Endpoint endpoint) {
savedEndpoints.add(endpoint.getTitle() + "::" + endpoint.getContent());
FileManager.set("saved_endpoints", savedEndpoints);
}

private void onEndpointSelected(String content) {
if (selectionListener != null) {
selectionListener.onEndpointSelected(content);
Expand Down Expand Up @@ -111,6 +119,14 @@ public String getContent() {
}
}

private static void saveEndpoints() {
Set<String> savedEndpoints = new HashSet<>();
for (Endpoint endpoint : endpointsList) {
savedEndpoints.add(endpoint.getTitle() + "::" + endpoint.getContent());
}
FileManager.set("saved_endpoints", savedEndpoints);
}

private static class EndpointsAdapter extends RecyclerView.Adapter<EndpointsAdapter.EndpointViewHolder> {
private final List<Endpoint> endpointsList;
public final EndpointSelectionListener selectionListener;
Expand Down Expand Up @@ -138,6 +154,17 @@ public void onBindViewHolder(@NonNull EndpointViewHolder holder, int position) {
selectionListener.onEndpointSelected(endpoint.getContent());
}
});

// Handle delete button click
holder.deleteIcon.setOnClickListener(v -> {
// Remove the endpoint from the list and update the RecyclerView
endpointsList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, endpointsList.size());

// Save the updated list to FileManager
saveEndpoints();
});
}

@Override
Expand All @@ -147,11 +174,13 @@ public int getItemCount() {

static class EndpointViewHolder extends RecyclerView.ViewHolder {
TextView titleTextView, contentTextView;
ImageView deleteIcon; // Added for delete icon

EndpointViewHolder(@NonNull View itemView) {
super(itemView);
titleTextView = itemView.findViewById(R.id.titleTextView);
contentTextView = itemView.findViewById(R.id.contentTextView);
deleteIcon = itemView.findViewById(R.id.delIcon); // Initialize delete icon
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/button_op.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffa200" />
<stroke
android:width="0dp"
android:color="#00FFFFFF" />
<corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" />
</shape>
15 changes: 13 additions & 2 deletions app/src/main/res/layout/bottom_sheet_endpoints.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
android:textSize="16dp"
android:hint="@string/content"
android:textColorHint="@color/text_color"/>
/>
</LinearLayout>

<Button
Expand All @@ -92,6 +91,18 @@
android:textColor="@color/white"
android:textSize="18dp" />

<Button
android:id="@+id/resetDefaultButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16sp"
android:layout_marginTop="8sp"
android:background="@drawable/button_op"
android:fontFamily="@font/shabnambold"
android:text="@string/reset_to_default_endpoint"
android:textColor="@color/white"
android:textSize="18dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -110,4 +121,4 @@
android:layout_marginVertical="12sp"
android:background="@color/background" />
</LinearLayout>
</ScrollView>
</ScrollView>
44 changes: 16 additions & 28 deletions app/src/main/res/layout/item_endpoint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,28 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
android:orientation="horizontal"
android:padding="8dp">

<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/shabnam"
android:textColor="@color/text_color"
android:textSize="18dp"
android:textStyle="bold"
android:paddingBottom="4dp"/>
android:layout_weight="1"
android:textSize="16sp"
android:textColor="@color/text_color" />

<TextView
android:id="@+id/contentTextView"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fontFamily="@font/shabnam"
android:textColor="@color/text_color"
android:textSize="16dp" />
<LinearLayout
android:id="@+id/battery_opt_line"
android:layout_width="match_parent"
android:layout_height="10dp"
android:gravity="center"
android:orientation="vertical">

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
</LinearLayout>
</LinearLayout>
android:layout_weight="2"
android:textSize="16sp"
android:textColor="@color/text_color" />

<ImageView
android:id="@+id/delIcon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@android:drawable/ic_menu_close_clear_cancel" />
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="resetAppText">بازنشانی</string>
<string name="proxy_mode">حالت پراکسی</string>
<string name="running_in_proxy_mode_not_vpn">در حال اجرا در حالت پراکسی، نه VPN</string>
<string name="reset_to_default_endpoint">بازنشانی به نقطه پیش‌فرض</string>
<string-array name="countries">
<item>استرالیا</item>
<item>اتریش</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="resetAppText">Сброс</string>
<string name="proxy_mode">Режим прокси</string>
<string name="running_in_proxy_mode_not_vpn">Работает в режиме прокси, а не VPN</string>
<string name="reset_to_default_endpoint">Сбросить на стандартную конечную точку</string>
<string-array name="countries">
<item>Австралия</item>
<item>Австрия</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="resetAppText">Sıfırla</string>
<string name="proxy_mode">Proxy Modu</string>
<string name="running_in_proxy_mode_not_vpn">Proxy modunda çalışıyor, VPN değil</string>
<string name="reset_to_default_endpoint">Varsayılan Uç Noktaya Sıfırla</string>
<string-array name="countries">
<item>Avustralya</item>
<item>Avusturya</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="resetAppText">重置</string>
<string name="proxy_mode">代理模式</string>
<string name="running_in_proxy_mode_not_vpn">以代理模式运行,而不是VPN</string>
<string name="reset_to_default_endpoint">重置为默认端点</string>
<string-array name="countries">
<item>澳大利亚</item>
<item>奥地利</item>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
<string name="resetAppText">Reset</string>
<string name="proxy_mode">Proxy Mode</string>
<string name="running_in_proxy_mode_not_vpn">Running in proxy mode, not VPN</string>
<string-array name="countries">
<string name="reset_to_default_endpoint">Reset to Default Endpoint</string>
<string-array name="countries">
<item>Australia</item>
<item>Austria</item>
<item>Belgium</item>
Expand Down

0 comments on commit cff6122

Please sign in to comment.