From 692ac8e70937f028b9ecc5c3efb1ad617f5efffe Mon Sep 17 00:00:00 2001 From: The Developer Date: Fri, 16 Aug 2024 00:50:40 +0330 Subject: [PATCH] Add Search apps to SplitTunnelActivity modified: app/src/main/java/org/bepass/oblivion/BypassListAppsAdapter.java modified: app/src/main/java/org/bepass/oblivion/ui/SplitTunnelActivity.java modified: app/src/main/res/layout/activity_split_tunnel.xml modified: app/src/main/res/values-fa/strings.xml modified: app/src/main/res/values-ru/strings.xml modified: app/src/main/res/values-tr/strings.xml modified: app/src/main/res/values-zh/strings.xml modified: app/src/main/res/values/strings.xml --- .../oblivion/BypassListAppsAdapter.java | 39 ++++++++++++------- .../oblivion/ui/SplitTunnelActivity.java | 28 ++++++++++++- .../main/res/layout/activity_split_tunnel.xml | 18 ++++++++- app/src/main/res/values-fa/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 74 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/bepass/oblivion/BypassListAppsAdapter.java b/app/src/main/java/org/bepass/oblivion/BypassListAppsAdapter.java index 3f4a1186..02b8a403 100644 --- a/app/src/main/java/org/bepass/oblivion/BypassListAppsAdapter.java +++ b/app/src/main/java/org/bepass/oblivion/BypassListAppsAdapter.java @@ -35,16 +35,21 @@ public class BypassListAppsAdapter extends RecyclerView.Adapter 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); @@ -52,7 +57,7 @@ private void loadApps(Context context, boolean shouldShowSystemApps) { }); } - private List getInstalledApps(Context context, boolean shouldShowSystemApps) { + private List getInstalledApps(Context context, boolean shouldShowSystemApps, String filterStr) { Set selectedApps = FileManager.getStringSet("splitTunnelApps", new HashSet<>()); PackageManager packageManager = context.getPackageManager(); @SuppressLint("QueryPermissionsNeeded") List packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); @@ -62,18 +67,21 @@ private List 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) { @@ -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; diff --git a/app/src/main/java/org/bepass/oblivion/ui/SplitTunnelActivity.java b/app/src/main/java/org/bepass/oblivion/ui/SplitTunnelActivity.java index f6d2706f..061e4d00 100644 --- a/app/src/main/java/org/bepass/oblivion/ui/SplitTunnelActivity.java +++ b/app/src/main/java/org/bepass/oblivion/ui/SplitTunnelActivity.java @@ -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; @@ -18,6 +20,7 @@ public class SplitTunnelActivity extends StateAwareBaseActivity { + BypassListAppsAdapter bypassListAppsAdapter; @Override protected int getLayoutResourceId() { @@ -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(); @@ -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 diff --git a/app/src/main/res/layout/activity_split_tunnel.xml b/app/src/main/res/layout/activity_split_tunnel.xml index 921df6e0..2dcd17cf 100644 --- a/app/src/main/res/layout/activity_split_tunnel.xml +++ b/app/src/main/res/layout/activity_split_tunnel.xml @@ -54,6 +54,22 @@ + + + + + بریتانیا ایالات متحده + جستجو \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 4a4bac26..77363362 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -92,4 +92,5 @@ Великобритания Соединенные Штаты + Поиск \ No newline at end of file diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 5b9194c8..501259ba 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -92,4 +92,5 @@ Birleşik Krallık Birleşik Devletler + Aramak \ No newline at end of file diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index aeff9aa7..42804649 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -92,5 +92,6 @@ 美国 选择语言 + 搜索 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c0eeb599..9d93e998 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,6 +58,7 @@ Reset Proxy Mode Running in proxy mode, not VPN + Search Austria Belgium