diff --git a/app/src/main/java/org/bepass/oblivion/EndpointsBottomSheet.java b/app/src/main/java/org/bepass/oblivion/EndpointsBottomSheet.java index ab61862b..b373aff1 100644 --- a/app/src/main/java/org/bepass/oblivion/EndpointsBottomSheet.java +++ b/app/src/main/java/org/bepass/oblivion/EndpointsBottomSheet.java @@ -1,9 +1,13 @@ package org.bepass.oblivion; +import android.annotation.SuppressLint; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -20,24 +24,54 @@ import java.util.Set; public class EndpointsBottomSheet extends BottomSheetDialogFragment { - private List endpointsList; + private static List endpointsList; public EndpointSelectionListener selectionListener; + private EndpointsAdapter adapter; + @SuppressLint("NotifyDataSetChanged") @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.bottom_sheet_endpoints, container, false); 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); + endpointsList = new ArrayList<>(); loadEndpoints(); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - EndpointsAdapter adapter = new EndpointsAdapter(endpointsList, this::onEndpointSelected); + adapter = new EndpointsAdapter(endpointsList, this::onEndpointSelected); recyclerView.setAdapter(adapter); + 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(); + + 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 savedEndpoints = FileManager.getStringSet("saved_endpoints", new HashSet<>()); for (String endpoint : savedEndpoints) { @@ -48,6 +82,14 @@ private void loadEndpoints() { } } + private void saveEndpoint(Endpoint endpoint) { + endpointsList.add(endpoint); + + // Save to FileManager + Set savedEndpoints = FileManager.getStringSet("saved_endpoints", new HashSet<>()); + savedEndpoints.add(endpoint.getTitle() + "::" + endpoint.getContent()); + FileManager.set("saved_endpoints", savedEndpoints); + } private void onEndpointSelected(String content) { if (selectionListener != null) { selectionListener.onEndpointSelected(content); @@ -77,6 +119,14 @@ public String getContent() { } } + private static void saveEndpoints() { + Set 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 { private final List endpointsList; public final EndpointSelectionListener selectionListener; @@ -104,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 @@ -113,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 } } } @@ -125,4 +188,4 @@ static class EndpointViewHolder extends RecyclerView.ViewHolder { public interface EndpointSelectionListener { void onEndpointSelected(String content); } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/bepass/oblivion/service/OblivionVpnService.java b/app/src/main/java/org/bepass/oblivion/service/OblivionVpnService.java index 056f2a4d..4adc587f 100644 --- a/app/src/main/java/org/bepass/oblivion/service/OblivionVpnService.java +++ b/app/src/main/java/org/bepass/oblivion/service/OblivionVpnService.java @@ -88,7 +88,7 @@ public void run() { } }; // For JNI Calling in a new threa - private static final ExecutorService executorService = Executors.newFixedThreadPool(1); + private static final ExecutorService executorService = Executors.newSingleThreadExecutor(); // For PingHTTPTestConnection to don't busy-waiting private static ScheduledExecutorService scheduler; private Notification notification; @@ -452,23 +452,23 @@ public void onRevoke() { } stopForegroundService(); stopSelf(); - // Shutdown executor service + // Shutdown executor service properly if (executorService != null) { - ExecutorService service = (ExecutorService) executorService; + executorService.shutdown(); // Initiates an orderly shutdown try { - service.shutdownNow(); // Attempt to forcibly shutdown - if (!service.awaitTermination(300, TimeUnit.MILLISECONDS)) { - Log.e(TAG, "ExecutorService did not terminate in the specified time"); - List droppedTasks = service.shutdownNow(); - Log.e(TAG, "ExecutorService was forcibly shut down. Dropped tasks: " + droppedTasks); + if (!executorService.awaitTermination(1, TimeUnit.SECONDS)) { + executorService.shutdownNow(); // Force shutdown if it doesn't terminate in time + if (!executorService.awaitTermination(1, TimeUnit.SECONDS)) { + Log.e(TAG, "ExecutorService did not terminate"); + } } - Log.e(TAG, "ExecutorService shut down successfully"); } catch (InterruptedException ie) { Log.e(TAG, "Interrupted during ExecutorService shutdown", ie); + executorService.shutdownNow(); // Force shutdown Thread.currentThread().interrupt(); } } else { - Log.w(TAG, "ExecutorService was not an instance of ExecutorService"); + Log.w(TAG, "ExecutorService was not initialized or is already null"); } Log.e(TAG, "VPN stopped successfully or encountered errors. Check logs for details."); diff --git a/app/src/main/java/org/bepass/oblivion/ui/SettingsActivity.java b/app/src/main/java/org/bepass/oblivion/ui/SettingsActivity.java index 8dcab339..e2f9f56a 100644 --- a/app/src/main/java/org/bepass/oblivion/ui/SettingsActivity.java +++ b/app/src/main/java/org/bepass/oblivion/ui/SettingsActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -97,6 +98,7 @@ public void onNothingSelected(AdapterView parent) { binding.endpointLayout.setOnClickListener(v -> { EndpointsBottomSheet bottomSheet = new EndpointsBottomSheet(); bottomSheet.setEndpointSelectionListener(content -> { + Log.d("100","Selected Endpoint: " + content); FileManager.set("USERSETTING_endpoint", content); binding.endpoint.post(() -> binding.endpoint.setText(content)); }); @@ -145,11 +147,9 @@ public void onNothingSelected(AdapterView parent) { if (isChecked && binding.psiphon.isChecked()) { binding.psiphon.post(() -> setCheckBoxWithoutTriggeringListener(binding.psiphon, false, psiphonListener)); FileManager.set("USERSETTING_psiphon", false); + binding.countryLayout.setAlpha(0.2f); + binding.country.setEnabled(false); } - binding.countryLayout.post(() -> { - binding.countryLayout.setAlpha(isChecked ? 1f : 0.2f); - binding.country.setEnabled(isChecked); - }); }; proxyModeListener = (buttonView, isChecked) -> { diff --git a/app/src/main/java/org/bepass/oblivion/utils/FileManager.java b/app/src/main/java/org/bepass/oblivion/utils/FileManager.java index 3b42ffc9..e8af9ead 100644 --- a/app/src/main/java/org/bepass/oblivion/utils/FileManager.java +++ b/app/src/main/java/org/bepass/oblivion/utils/FileManager.java @@ -196,6 +196,7 @@ public static void cleanOrMigrateSettings(Context context) { set("USERSETTING_psiphon", false); set("USERSETTING_lan", false); set("USERSETTING_proxymode", false); + set("USERSETTING_endpoint_type", 0); set("isFirstValueInit", true); } diff --git a/app/src/main/res/drawable/button_op.xml b/app/src/main/res/drawable/button_op.xml new file mode 100644 index 00000000..255a3339 --- /dev/null +++ b/app/src/main/res/drawable/button_op.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/endpoint_sheet.xml b/app/src/main/res/drawable/endpoint_sheet.xml new file mode 100644 index 00000000..446c62be --- /dev/null +++ b/app/src/main/res/drawable/endpoint_sheet.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/layout/activity_info.xml b/app/src/main/res/layout/activity_info.xml index 9bbcde84..1fdfcb93 100644 --- a/app/src/main/res/layout/activity_info.xml +++ b/app/src/main/res/layout/activity_info.xml @@ -21,10 +21,10 @@ android:layout_height="48dp" android:layout_marginTop="8dp"> - @@ -63,7 +63,7 @@ android:text='@string/aboutAppDesc' android:textAlignment="center" android:textColor="@color/subtitle_color" - android:textSize="16sp" + android:textSize="16dp" tools:ignore="RtlCompat" android:focusable="true" app:layout_constraintLeft_toLeftOf="parent" @@ -105,7 +105,7 @@ android:fontFamily="@font/shabnam" android:text="Github" android:textColor="@color/black" - android:textSize="14sp" /> + android:textSize="14dp" /> + android:textSize="14dp" /> @@ -128,7 +128,7 @@ android:gravity="center" android:text="@string/appVersion" android:textColor="@color/subtitle_color" - android:textSize="14sp" /> + android:textSize="14dp" /> diff --git a/app/src/main/res/layout/activity_log.xml b/app/src/main/res/layout/activity_log.xml index 59b4c0a4..ac1655a4 100644 --- a/app/src/main/res/layout/activity_log.xml +++ b/app/src/main/res/layout/activity_log.xml @@ -25,8 +25,8 @@ @@ -69,7 +69,7 @@ android:layout_height="wrap_content" android:textColor="@color/subtitle_color" android:text="Start Logging Here.." - android:textSize="11sp" /> + android:textSize="11dp" />