Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Search apps to SplitTunnelActivity #383

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
39 changes: 26 additions & 13 deletions app/src/main/java/org/bepass/oblivion/BypassListAppsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,29 @@ public class BypassListAppsAdapter extends RecyclerView.Adapter<BypassListAppsAd
private final LoadListener loadListener;
private List<AppInfo> appList = new ArrayList<>();
private OnAppSelectListener onAppSelectListener;
private String filterString = "";
private Context context;
private boolean shouldShowSystemApps;

public BypassListAppsAdapter(Context context, LoadListener loadListener) {
this.context = context;
this.loadListener = loadListener;
loadApps(context, false);
shouldShowSystemApps = false;
loadApps();
}

private void loadApps(Context context, boolean shouldShowSystemApps) {
if (loadListener != null) loadListener.onLoad(true);
private void loadApps() {
if (this.loadListener != null) this.loadListener.onLoad(true);
executor.submit(() -> {
appList = getInstalledApps(context, shouldShowSystemApps);
appList = getInstalledApps(context, shouldShowSystemApps, filterString);
handler.post(() -> {
notifyDataSetChanged();
if (loadListener != null) loadListener.onLoad(false);
});
});
}

private List<AppInfo> getInstalledApps(Context context, boolean shouldShowSystemApps) {
private List<AppInfo> getInstalledApps(Context context, boolean shouldShowSystemApps, String filterStr) {
Set<String> selectedApps = FileManager.getStringSet("splitTunnelApps", new HashSet<>());
PackageManager packageManager = context.getPackageManager();
@SuppressLint("QueryPermissionsNeeded") List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
Expand All @@ -62,18 +67,21 @@ private List<AppInfo> getInstalledApps(Context context, boolean shouldShowSystem
if (!shouldShowSystemApps && (packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) continue;
if (packageInfo.packageName.equals(context.getPackageName())) continue;

appList.add(new AppInfo(
packageInfo.loadLabel(packageManager).toString(),
() -> packageInfo.loadIcon(packageManager),
packageInfo.packageName,
selectedApps.contains(packageInfo.packageName)
));
if (filterStr.isEmpty() || packageInfo.loadLabel(packageManager).toString().toLowerCase().contains(filterStr.toLowerCase())) {
appList.add(new AppInfo(
packageInfo.loadLabel(packageManager).toString(),
() -> packageInfo.loadIcon(packageManager),
packageInfo.packageName,
selectedApps.contains(packageInfo.packageName)
));
}
}
return appList;
}

public void setShouldShowSystemApps(Context context, boolean shouldShowSystemApps) {
loadApps(context, shouldShowSystemApps);
public void setShouldShowSystemApps(boolean shouldShowSystemApps) {
this.shouldShowSystemApps = shouldShowSystemApps;
loadApps();
}

public void setOnAppSelectListener(OnAppSelectListener onAppSelectListener) {
Expand Down Expand Up @@ -124,6 +132,11 @@ public interface OnAppSelectListener {
void onSelect(String packageName, boolean selected);
}

public void setFilterString(String filterString) {
this.filterString = filterString;
loadApps();
}

public static class ViewHolder extends RecyclerView.ViewHolder {
TextView appNameTextView;
CheckBox checkBox;
Expand Down
28 changes: 26 additions & 2 deletions app/src/main/java/org/bepass/oblivion/ui/SplitTunnelActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.bepass.oblivion.ui;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;

import androidx.annotation.NonNull;
Expand All @@ -18,6 +20,7 @@


public class SplitTunnelActivity extends StateAwareBaseActivity<ActivitySplitTunnelBinding> {
BypassListAppsAdapter bypassListAppsAdapter;

@Override
protected int getLayoutResourceId() {
Expand All @@ -39,7 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
binding.back.setOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed());

// Set up the app list
BypassListAppsAdapter bypassListAppsAdapter = new BypassListAppsAdapter(this, loading -> {
bypassListAppsAdapter = new BypassListAppsAdapter(this, loading -> {
binding.appsRecycler.setVisibility(loading ? View.INVISIBLE : View.VISIBLE);
if (loading) binding.progress.show();
else binding.progress.hide();
Expand All @@ -60,11 +63,32 @@ public void splitTunnelMode(SplitTunnelMode mode) {

@Override
public void shouldShowSystemApps(boolean show) {
bypassListAppsAdapter.setShouldShowSystemApps(SplitTunnelActivity.this, show);
bypassListAppsAdapter.setShouldShowSystemApps(show);
}
});

binding.appsRecycler.setAdapter(new ConcatAdapter(optionsAdapter, bypassListAppsAdapter));

binding.filterListEditText.addTextChangedListener(getTextWatcher());
}

private @NonNull TextWatcher getTextWatcher() {
return new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}

@Override
public void afterTextChanged(Editable s) {
if (bypassListAppsAdapter != null) {
bypassListAppsAdapter.setFilterString(s.toString());
}
}
};
}

@Override
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/res/layout/activity_split_tunnel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@

</RelativeLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/filterListEditTextLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_bar">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/filterListEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/search_app"/>
</com.google.android.material.textfield.TextInputLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/appsRecycler"
android:layout_width="0dp"
Expand All @@ -63,7 +79,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_bar"
app:layout_constraintTop_toBottomOf="@+id/filterListEditTextLayout"
tools:itemCount="20"
tools:listitem="@layout/installed_app_item"
tools:visibility="visible"
Expand Down
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 @@ -92,4 +92,5 @@
<item>بریتانیا</item>
<item>ایالات متحده</item>
</string-array>
<string name="search_app">جستجو</string>
</resources>
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 @@ -92,4 +92,5 @@
<item>Великобритания</item>
<item>Соединенные Штаты</item>
</string-array>
<string name="search_app">Поиск</string>
</resources>
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 @@ -92,4 +92,5 @@
<item>Birleşik Krallık</item>
<item>Birleşik Devletler</item>
</string-array>
<string name="search_app">Aramak</string>
</resources>
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 @@ -92,5 +92,6 @@
<item>美国</item>
</string-array>
<string name="select_language">选择语言</string>
<string name="search_app">搜索</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<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 name="search_app">Search</string>
<string-array name="countries">
<item>Austria</item>
<item>Belgium</item>
Expand Down