Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions app/src/main/java/org/bepass/oblivion/EndpointsBottomSheet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,24 +24,54 @@
import java.util.Set;

public class EndpointsBottomSheet extends BottomSheetDialogFragment {
private List<Endpoint> endpointsList;
private static List<Endpoint> 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<String> savedEndpoints = FileManager.getStringSet("saved_endpoints", new HashSet<>());
for (String endpoint : savedEndpoints) {
Expand All @@ -48,6 +82,14 @@ private void loadEndpoints() {
}
}

private void saveEndpoint(Endpoint endpoint) {
endpointsList.add(endpoint);

// Save to FileManager
Set<String> 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);
Expand Down Expand Up @@ -77,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 @@ -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
Expand All @@ -113,16 +174,18 @@ 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
}
}
}

public interface EndpointSelectionListener {
void onEndpointSelected(String content);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Runnable> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
});
Expand Down Expand Up @@ -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) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/endpoint_sheet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/background" />
<corners android:topLeftRadius="30dp" android:topRightRadius="30dp" />
</shape>
16 changes: 8 additions & 8 deletions app/src/main/res/layout/activity_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
android:layout_height="48dp"
android:layout_marginTop="8dp">

<ImageView
<org.bepass.oblivion.component.Icon
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="?selectableItemBackgroundBorderless"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
Expand All @@ -44,7 +44,7 @@
android:fontFamily="@font/shabnamlight"
android:text="@string/aboutApp"
android:textColor="@color/text_color"
android:textSize="32sp"
android:textSize="32dp"
tools:ignore="RelativeOverlap" />

</RelativeLayout>
Expand All @@ -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"
Expand Down Expand Up @@ -105,7 +105,7 @@
android:fontFamily="@font/shabnam"
android:text="Github"
android:textColor="@color/black"
android:textSize="14sp" />
android:textSize="14dp" />

<TextView
android:layout_width="wrap_content"
Expand All @@ -116,7 +116,7 @@
android:fontFamily="@font/shabnambold"
android:text="Bepass/Oblivion"
android:textColor="@color/black"
android:textSize="14sp" />
android:textSize="14dp" />

</RelativeLayout>

Expand All @@ -128,7 +128,7 @@
android:gravity="center"
android:text="@string/appVersion"
android:textColor="@color/subtitle_color"
android:textSize="14sp" />
android:textSize="14dp" />

</LinearLayout>
</layout>
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_log.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

<org.bepass.oblivion.component.Icon
android:id="@+id/back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="?selectableItemBackgroundBorderless"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
Expand All @@ -45,7 +45,7 @@
android:fontFamily="@font/shabnamlight"
android:text="@string/logApp"
android:textColor="@color/text_color"
android:textSize="32sp"
android:textSize="32dp"
tools:ignore="RelativeOverlap" />
</RelativeLayout>

Expand All @@ -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" />
</ScrollView>

<Button
Expand All @@ -80,7 +80,7 @@
android:fontFamily="@font/shabnam"
android:text="@string/copytoclip"
android:textColor="@color/white"
android:textSize="18sp"
android:textSize="18dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -114,7 +114,7 @@
android:layout_gravity="center"
android:text="Getting ISP..."
android:textColor="@android:color/white"
android:textSize="16sp"
android:textSize="16dp"
android:padding="8dp"/>
</FrameLayout>

Expand Down
Loading