Repo created
This commit is contained in:
parent
21de94943c
commit
4e2998210b
143 changed files with 10606 additions and 2 deletions
|
|
@ -0,0 +1,81 @@
|
|||
package com.sunilpaulmathew.debloater.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.sunilpaulmathew.debloater.BuildConfig;
|
||||
import com.sunilpaulmathew.debloater.R;
|
||||
import com.sunilpaulmathew.debloater.adapters.AboutAdapter;
|
||||
import com.sunilpaulmathew.debloater.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sCommonUtils;
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sSerializableItems;
|
||||
import in.sunilpaulmathew.sCommon.PackageUtils.sPackageUtils;
|
||||
|
||||
/*
|
||||
* Created by sunilpaulmathew <sunil.kde@gmail.com> on October 28, 2020
|
||||
*/
|
||||
|
||||
public class AboutFragment extends Fragment {
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View mRootView = inflater.inflate(R.layout.fragment_about, container, false);
|
||||
|
||||
RecyclerView mRecyclerView = mRootView.findViewById(R.id.recycler_view);
|
||||
mRecyclerView.setLayoutManager(new GridLayoutManager(requireActivity(), Utils.getSpanCount(requireActivity())));
|
||||
AboutAdapter mRecycleViewAdapter = new AboutAdapter(getData());
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
|
||||
requireActivity().getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
Utils.navigateToFragment(requireActivity());
|
||||
}
|
||||
});
|
||||
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
private List<sSerializableItems> getData() {
|
||||
List <sSerializableItems> mData = new ArrayList<>();
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.mipmap.ic_launcher_round, requireActivity()), getString(R.string.version).replace(": %s",""), (sPackageUtils.isPackageInstalled(
|
||||
"com.android.vending", requireActivity()) ? "Pro " : "") + BuildConfig.VERSION_NAME, null));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_support, requireActivity()), getString(R.string.support), getString(R.string.support_summary),"https://t.me/smartpack_kmanager"));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_github, requireActivity()), getString(R.string.source_code), getString(R.string.source_code_summary),"https://github.com/sunilpaulmathew/De-Bloater"));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_issue, requireActivity()), getString(R.string.report_issue), getString(R.string.report_issue_summary),"https://github.com/sunilpaulmathew/De-Bloater/issues/new"));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_active, requireActivity()), getString(R.string.change_logs), getString(R.string.change_logs_summary), null));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_playstore, requireActivity()), getString(R.string.more_apps), getString(R.string.more_apps_summary), "https://play.google.com/store/apps/dev?id=5836199813143882901"));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_licence, requireActivity()), getString(R.string.licence), getString(R.string.licence_summary), "https://www.gnu.org/licenses/gpl-3.0-standalone.html"));
|
||||
if (sPackageUtils.isPackageInstalled("com.android.vending", requireActivity())) {
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_rate, requireActivity()), getString(R.string.rate_us), getString(R.string.rate_us_Summary), "https://play.google.com/store/apps/details?id=com.sunilpaulmathew.debloater"));
|
||||
} else if (sPackageUtils.isPackageInstalled("org.fdroid.fdroid", requireActivity())) {
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_fdroid, requireActivity()), getString(R.string.fdroid), getString(R.string.fdroid_summary), "https://f-droid.org/packages/com.sunilpaulmathew.debloater"));
|
||||
} else {
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_update, requireActivity()),getString(R.string.check_update), getString(R.string.check_update_summary), null));
|
||||
}
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_translate, requireActivity()), getString(R.string.translations), getString(R.string.translations_summary), null));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_credits, requireActivity()), getString(R.string.credits), getString(R.string.credits_summary), null));
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_share, requireActivity()), getString(R.string.invite_friend), getString(R.string.invite_friend_summary), null));
|
||||
if (!sPackageUtils.isPackageInstalled("com.android.vending", requireActivity())) {
|
||||
mData.add(new sSerializableItems(sCommonUtils.getDrawable(R.drawable.ic_donate, requireActivity()), getString(R.string.donate), getString(R.string.donate_summary), "https://smartpack.github.io/donation/"));
|
||||
}
|
||||
return mData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,321 @@
|
|||
package com.sunilpaulmathew.debloater.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatEditText;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
import com.sunilpaulmathew.debloater.R;
|
||||
import com.sunilpaulmathew.debloater.activities.TomatotActivity;
|
||||
import com.sunilpaulmathew.debloater.activities.UADActivity;
|
||||
import com.sunilpaulmathew.debloater.adapters.ActivePackagesAdapter;
|
||||
import com.sunilpaulmathew.debloater.utils.PackageTasks;
|
||||
import com.sunilpaulmathew.debloater.utils.UpdateCheck;
|
||||
import com.sunilpaulmathew.debloater.utils.Utils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sCommonUtils;
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sExecutor;
|
||||
|
||||
/*
|
||||
* Created by sunilpaulmathew <sunil.kde@gmail.com> on October 28, 2020
|
||||
*/
|
||||
|
||||
public class ActivePackagesFragment extends Fragment {
|
||||
|
||||
private AppCompatEditText mSearchWord;
|
||||
private AppCompatImageButton mMenu;
|
||||
private boolean mExit = false;
|
||||
private final Handler mHandler = new Handler();
|
||||
private LinearLayout mProgressLayout;
|
||||
private MaterialCardView mReverse;
|
||||
private RecyclerView mRecyclerView;
|
||||
private ActivePackagesAdapter mRecycleViewAdapter;
|
||||
private String mSearchText = null;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View mRootView = inflater.inflate(R.layout.fragment_packages, container, false);
|
||||
|
||||
mSearchWord = mRootView.findViewById(R.id.search_word);
|
||||
AppCompatImageButton mSearchButton = mRootView.findViewById(R.id.search_button);
|
||||
AppCompatTextView mSummary = mRootView.findViewById(R.id.about_summary);
|
||||
MaterialTextView mPageTitle = mRootView.findViewById(R.id.page_title);
|
||||
mReverse = mRootView.findViewById(R.id.reverse_button);
|
||||
mMenu = mRootView.findViewById(R.id.menu_button);
|
||||
mProgressLayout = mRootView.findViewById(R.id.progress_layout);
|
||||
mRecyclerView = mRootView.findViewById(R.id.recycler_view);
|
||||
TabLayout mTabLayout = mRootView.findViewById(R.id.tab_layout);
|
||||
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(requireActivity()));
|
||||
|
||||
mPageTitle.setText(getString(R.string.apps, getString(R.string.active)));
|
||||
mSummary.setText(getString(R.string.active_app_summary));
|
||||
mReverse.setElevation(10);
|
||||
mReverse.setOnClickListener(v -> {
|
||||
sCommonUtils.saveBoolean("reverse_order", !sCommonUtils.getBoolean("reverse_order", false, requireActivity()), requireActivity());
|
||||
loadUI(requireActivity(), mSearchText);
|
||||
});
|
||||
|
||||
mSearchButton.setOnClickListener(v -> {
|
||||
if (mSearchWord.getVisibility() == View.VISIBLE) {
|
||||
if (mSearchText != null && !mSearchText.isEmpty()) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
mSummary.setVisibility(View.VISIBLE);
|
||||
mSearchWord.setVisibility(View.GONE);
|
||||
PackageTasks.toggleKeyboard(mSearchWord, 0, requireActivity());
|
||||
} else {
|
||||
mSummary.setVisibility(View.GONE);
|
||||
mSearchWord.setVisibility(View.VISIBLE);
|
||||
PackageTasks.toggleKeyboard(mSearchWord, 1, requireActivity());
|
||||
}
|
||||
});
|
||||
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText(getString(R.string.apps_all)));
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText(getString(R.string.apps_system)));
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText(getString(R.string.apps_product)));
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText(getString(R.string.apps_vendor)));
|
||||
|
||||
mTabLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
Objects.requireNonNull(mTabLayout.getTabAt(getTabPosition(requireActivity()))).select();
|
||||
|
||||
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
String mStatus = sCommonUtils.getString("appTypes", "all", requireActivity());
|
||||
switch (tab.getPosition()) {
|
||||
case 0:
|
||||
if (!mStatus.equals("all")) {
|
||||
sCommonUtils.saveString("appTypes", "all", requireActivity());
|
||||
loadUI(requireActivity(), mSearchText);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!mStatus.equals("system")) {
|
||||
sCommonUtils.saveString("appTypes", "system", requireActivity());
|
||||
loadUI(requireActivity(), mSearchText);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!mStatus.equals("product")) {
|
||||
sCommonUtils.saveString("appTypes", "product", requireActivity());
|
||||
loadUI(requireActivity(), mSearchText);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (!mStatus.equals("vendor")) {
|
||||
sCommonUtils.saveString("appTypes", "vendor", requireActivity());
|
||||
loadUI(requireActivity(), mSearchText);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
}
|
||||
});
|
||||
|
||||
mSearchWord.addTextChangedListener(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) {
|
||||
loadUI(requireActivity(), s.toString().toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
mMenu.setOnClickListener(v -> menuOptions(requireActivity()));
|
||||
|
||||
loadUI(requireActivity(), mSearchText);
|
||||
|
||||
if (UpdateCheck.isSignatureMatched(requireActivity()) && sCommonUtils.getInt("update_enabled", 2, requireActivity()) == 2) {
|
||||
new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setIcon(R.mipmap.ic_launcher_round)
|
||||
.setTitle("Please Note")
|
||||
.setMessage("""
|
||||
De-Bloater includes a built-in auto-update system that is active only when the app is installed via the GitHub release page or through IzzyOnDroid. Updates are fetched directly from the latest official release on GitHub.
|
||||
|
||||
You can choose to enable or disable this feature. This prompt will keep appearing until you make a decision.""")
|
||||
.setCancelable(false)
|
||||
.setNeutralButton("No, Thanks", (dialogInterface, i) ->
|
||||
sCommonUtils.saveInt("update_enabled", 1, requireActivity()))
|
||||
.setPositiveButton("Yes, Enable", (dialogInterface, i) ->
|
||||
sCommonUtils.saveInt("update_enabled", 0, requireActivity()))
|
||||
.show();
|
||||
}
|
||||
|
||||
requireActivity().getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
if (mSearchWord.getVisibility() == View.VISIBLE) {
|
||||
if (mSearchText != null) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
mSearchWord.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
if (mExit) {
|
||||
mExit = false;
|
||||
requireActivity().finish();
|
||||
} else {
|
||||
sCommonUtils.toast(getString(R.string.press_back_exit), requireActivity()).show();
|
||||
mExit = true;
|
||||
mHandler.postDelayed(() -> mExit = false, 2000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
private int getTabPosition(Activity activity) {
|
||||
String mStatus = sCommonUtils.getString("appTypes", "all", activity);
|
||||
return switch (mStatus) {
|
||||
case "vendor" -> 3;
|
||||
case "product" -> 2;
|
||||
case "system" -> 1;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
private void menuOptions(Activity activity) {
|
||||
PopupMenu popupMenu = new PopupMenu(activity, mMenu);
|
||||
Menu menu = popupMenu.getMenu();
|
||||
if (PackageTasks.isModuleInitialized()) {
|
||||
menu.add(Menu.NONE, 1, Menu.NONE, R.string.module_status_reset);
|
||||
}
|
||||
SubMenu sort = menu.addSubMenu(Menu.NONE, 0, Menu.NONE, getString(R.string.sort_by));
|
||||
sort.add(0, 2, Menu.NONE, getString(R.string.name)).setCheckable(true)
|
||||
.setChecked(sCommonUtils.getInt("sort_apps", 1, activity) == 0);
|
||||
sort.add(0, 3, Menu.NONE, getString(R.string.package_id)).setCheckable(true)
|
||||
.setChecked(sCommonUtils.getInt("sort_apps", 1, activity) == 1);
|
||||
sort.setGroupCheckable(0, true, true);
|
||||
SubMenu customScripts = menu.addSubMenu(Menu.NONE, 0, Menu.NONE, getString(R.string.custom_scripts));
|
||||
customScripts.add(Menu.NONE, 4, Menu.NONE, R.string.custom_scripts_tomatot);
|
||||
customScripts.add(Menu.NONE, 5, Menu.NONE, R.string.custom_scripts_uad);
|
||||
menu.add(Menu.NONE, 6, Menu.NONE, R.string.reboot);
|
||||
popupMenu.setOnMenuItemClickListener(item -> {
|
||||
switch (item.getItemId()) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
PackageTasks.removeModule(activity);
|
||||
break;
|
||||
case 2:
|
||||
if (sCommonUtils.getInt("sort_apps", 1, activity) != 0) {
|
||||
sCommonUtils.saveInt("sort_apps", 0, activity);
|
||||
loadUI(activity, mSearchText);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (sCommonUtils.getInt("sort_apps", 1, activity) != 1) {
|
||||
sCommonUtils.saveInt("sort_apps", 1, activity);
|
||||
loadUI(activity, mSearchText);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
Intent tomatotScript = new Intent(activity, TomatotActivity.class);
|
||||
startActivity(tomatotScript);
|
||||
break;
|
||||
case 5:
|
||||
Intent uadScript = new Intent(activity, UADActivity.class);
|
||||
startActivity(uadScript);
|
||||
break;
|
||||
case 6:
|
||||
Utils.runCommand("svc power reboot");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
popupMenu.show();
|
||||
}
|
||||
|
||||
private void loadUI(Activity activity, String searchText) {
|
||||
new sExecutor() {
|
||||
|
||||
@Override
|
||||
public void onPreExecute() {
|
||||
mProgressLayout.setVisibility(View.VISIBLE);
|
||||
mReverse.setVisibility(View.GONE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mRecyclerView.removeAllViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInBackground() {
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(PackageTasks.getActivePackageData(activity, searchText), searchText);
|
||||
if (searchText != null) {
|
||||
mSearchText = searchText;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute() {
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
mProgressLayout.setVisibility(View.GONE);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mReverse.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (mSearchText != null) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mSearchText != null) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,313 @@
|
|||
package com.sunilpaulmathew.debloater.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatEditText;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
import com.sunilpaulmathew.debloater.BuildConfig;
|
||||
import com.sunilpaulmathew.debloater.R;
|
||||
import com.sunilpaulmathew.debloater.adapters.InactivePackagesAdapter;
|
||||
import com.sunilpaulmathew.debloater.utils.EditTextInterface;
|
||||
import com.sunilpaulmathew.debloater.utils.PackageTasks;
|
||||
import com.sunilpaulmathew.debloater.utils.Restore;
|
||||
import com.sunilpaulmathew.debloater.utils.Utils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import in.sunilpaulmathew.rootfilepicker.utils.FilePicker;
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sCommonUtils;
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sExecutor;
|
||||
|
||||
/*
|
||||
* Created by sunilpaulmathew <sunil.kde@gmail.com> on October 28, 2020
|
||||
*/
|
||||
|
||||
public class InactivePackagesFragment extends Fragment {
|
||||
|
||||
private AppCompatEditText mSearchWord;
|
||||
private AppCompatImageButton mMenu;
|
||||
private LinearLayout mProgressLayout;
|
||||
private MaterialTextView mProgressText;
|
||||
private RecyclerView mRecyclerView;
|
||||
private InactivePackagesAdapter mRecycleViewAdapter;
|
||||
private String mSearchText = null;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View mRootView = inflater.inflate(R.layout.fragment_packages, container, false);
|
||||
|
||||
mSearchWord = mRootView.findViewById(R.id.search_word);
|
||||
AppCompatTextView mSummary = mRootView.findViewById(R.id.about_summary);
|
||||
mProgressLayout = mRootView.findViewById(R.id.progress_layout);
|
||||
mProgressText = mRootView.findViewById(R.id.progress_text);
|
||||
mRecyclerView = mRootView.findViewById(R.id.recycler_view);
|
||||
mRecyclerView = mRootView.findViewById(R.id.recycler_view);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(requireActivity()));
|
||||
MaterialTextView mTitle = mRootView.findViewById(R.id.page_title);
|
||||
AppCompatImageButton mSearchButton = mRootView.findViewById(R.id.search_button);
|
||||
mMenu = mRootView.findViewById(R.id.menu_button);
|
||||
|
||||
mTitle.setText(getString(R.string.apps, getString(R.string.inactive)));
|
||||
mSummary.setText(getString(R.string.inactive_apps_summary));
|
||||
|
||||
mMenu.setOnClickListener(v -> menuOptions(requireActivity()));
|
||||
|
||||
loadUI(mSearchText);
|
||||
|
||||
mSearchButton.setOnClickListener(v -> {
|
||||
if (mSearchWord.getVisibility() == View.VISIBLE) {
|
||||
if (mSearchText != null && !mSearchText.isEmpty()) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
mSummary.setVisibility(View.VISIBLE);
|
||||
mSearchWord.setVisibility(View.GONE);
|
||||
PackageTasks.toggleKeyboard(mSearchWord, 0, requireActivity());
|
||||
} else {
|
||||
mSummary.setVisibility(View.GONE);
|
||||
mSearchWord.setVisibility(View.VISIBLE);
|
||||
PackageTasks.toggleKeyboard(mSearchWord, 1, requireActivity());
|
||||
}
|
||||
});
|
||||
|
||||
mSearchWord.addTextChangedListener(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) {
|
||||
loadUI(s.toString().toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
requireActivity().getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
if (mSearchWord.getVisibility() == View.VISIBLE) {
|
||||
if (mSearchText != null) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
mSummary.setVisibility(View.VISIBLE);
|
||||
mSearchWord.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
Utils.navigateToFragment(requireActivity());
|
||||
}
|
||||
});
|
||||
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
private void menuOptions(Activity activity) {
|
||||
PopupMenu popupMenu = new PopupMenu(activity, mMenu);
|
||||
Menu menu = popupMenu.getMenu();
|
||||
if (PackageTasks.isModuleInitialized()) {
|
||||
menu.add(Menu.NONE, 0, Menu.NONE, R.string.module_status_reset);
|
||||
}
|
||||
menu.add(Menu.NONE, 1, Menu.NONE, R.string.reboot);
|
||||
menu.add(Menu.NONE, 2, Menu.NONE, R.string.backup);
|
||||
menu.add(Menu.NONE, 3, Menu.NONE, R.string.restore);
|
||||
popupMenu.setOnMenuItemClickListener(item -> {
|
||||
switch (item.getItemId()) {
|
||||
case 0:
|
||||
PackageTasks.removeModule(activity);
|
||||
loadUI(mSearchText);
|
||||
break;
|
||||
case 1:
|
||||
Utils.runCommand("svc power reboot");
|
||||
break;
|
||||
case 2:
|
||||
if (!PackageTasks.getInactivePackageData(null).isEmpty()) {
|
||||
new EditTextInterface(Build.MODEL.replace(" ","_")
|
||||
.replace("(","_").replace(")","_") + "_" +
|
||||
Build.VERSION.SDK_INT, getString(R.string.backup_list_as), activity) {
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
@Override
|
||||
public void positiveButtonLister(Editable editable) {
|
||||
String name = editable.toString().trim().replace(" ","_")
|
||||
.replace("(","_").replace(")","_");
|
||||
if (!name.endsWith(".json")) {
|
||||
name = name + ".json";
|
||||
}
|
||||
File jsonFile = new File(PackageTasks.getStoragePath(), name);
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
JSONObject device = new JSONObject();
|
||||
JSONArray DeBloater = new JSONArray();
|
||||
device.put("Manufacturer", Build.MANUFACTURER);
|
||||
device.put("Brand", Build.BRAND);
|
||||
device.put("Model", Build.MODEL);
|
||||
device.put("Version", Build.VERSION.RELEASE);
|
||||
device.put("SDK", Build.VERSION.SDK_INT);
|
||||
obj.put("Device", device);
|
||||
for (String s : PackageTasks.getInactivePackageData(null)) {
|
||||
JSONObject app = new JSONObject();
|
||||
app.put("name", Utils.read(s));
|
||||
app.put("path", s);
|
||||
DeBloater.put(app);
|
||||
obj.put("DeBloater", DeBloater);
|
||||
}
|
||||
Utils.create(obj.toString(), jsonFile.getAbsolutePath());
|
||||
new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setIcon(R.mipmap.ic_launcher)
|
||||
.setTitle(R.string.app_name)
|
||||
.setMessage(getString(R.string.backup_message, jsonFile.getAbsolutePath()) + "\n\n" + getString(R.string.backup_share_message))
|
||||
.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
|
||||
})
|
||||
.setPositiveButton(getString(R.string.share_profile), (dialogInterface, i) -> {
|
||||
Uri uriFile = FileProvider.getUriForFile(activity,
|
||||
BuildConfig.APPLICATION_ID + ".provider", jsonFile);
|
||||
Intent share = new Intent(Intent.ACTION_SEND);
|
||||
share.setType("*/*");
|
||||
share.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
|
||||
share.putExtra(Intent.EXTRA_TEXT, "De-Bloater profile for " + Build.MODEL + " (SDK: " + Build.VERSION.SDK_INT + ").");
|
||||
share.putExtra(Intent.EXTRA_STREAM, uriFile);
|
||||
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
Intent shareIntent = Intent.createChooser(share, null);
|
||||
startActivity(shareIntent);
|
||||
}).show();
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
}
|
||||
}.show();
|
||||
} else {
|
||||
sCommonUtils.snackBar(mRecyclerView, getString(R.string.backup_list_empty)).show();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
FilePicker filePicker = new FilePicker(restoreResultLauncher, requireActivity());
|
||||
filePicker.setPath(Environment.getExternalStorageDirectory().toString());
|
||||
filePicker.setExtension("json");
|
||||
filePicker.launch();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
popupMenu.show();
|
||||
}
|
||||
|
||||
private void loadUI(String searchText) {
|
||||
new sExecutor() {
|
||||
|
||||
@Override
|
||||
public void onPreExecute() {
|
||||
mProgressLayout.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mRecyclerView.removeAllViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInBackground() {
|
||||
mRecycleViewAdapter = new InactivePackagesAdapter(PackageTasks.getInactivePackageData(searchText));
|
||||
if (searchText != null) {
|
||||
mSearchText = searchText;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute() {
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
mProgressLayout.setVisibility(View.GONE);
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
private final ActivityResultLauncher<Intent> restoreResultLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> {
|
||||
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
|
||||
File mSelectedFile = FilePicker.getSelectedFile();
|
||||
if (!Restore.isValidBackup(mSelectedFile.getAbsolutePath())) {
|
||||
sCommonUtils.snackBar(mRecyclerView, getString(R.string.restore_error_message)).show();
|
||||
return;
|
||||
}
|
||||
new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setMessage(Restore.isJSONMatched(mSelectedFile.getAbsolutePath()) ? getString(R.string.restore_question,
|
||||
mSelectedFile.getName()) : getString(R.string.restore_mismatch_message))
|
||||
.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
|
||||
})
|
||||
.setPositiveButton(getString(R.string.restore), (dialogInterface, i) ->
|
||||
new sExecutor() {
|
||||
|
||||
@Override
|
||||
public void onPreExecute() {
|
||||
mProgressLayout.setVisibility(View.VISIBLE);
|
||||
mProgressText.setText(getString(R.string.restoring));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInBackground() {
|
||||
Restore.restoreBackup(mSelectedFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute() {
|
||||
mProgressLayout.setVisibility(View.GONE);
|
||||
loadUI(mSearchText);
|
||||
}
|
||||
}.execute())
|
||||
.show();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (mSearchText != null) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mSearchText != null) {
|
||||
mSearchText = null;
|
||||
mSearchWord.setText(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
package com.sunilpaulmathew.debloater.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
import com.sunilpaulmathew.debloater.R;
|
||||
import com.sunilpaulmathew.debloater.adapters.ActivePackagesAdapter;
|
||||
import com.sunilpaulmathew.debloater.utils.Common;
|
||||
import com.sunilpaulmathew.debloater.utils.Tomatot;
|
||||
import com.sunilpaulmathew.debloater.utils.Utils;
|
||||
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sCommonUtils;
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sExecutor;
|
||||
import in.sunilpaulmathew.sCommon.ThemeUtils.sThemeUtils;
|
||||
|
||||
/*
|
||||
* Created by sunilpaulmathew <sunil.kde@gmail.com> on November 4, 2020
|
||||
*/
|
||||
|
||||
public class TomatotDebloaterFragment extends Fragment {
|
||||
|
||||
private boolean mExtremeT = false, mInvisibleT = false, mLightT = false;
|
||||
private MaterialCardView mAppListCard;
|
||||
private LinearLayout mProgressLayout;
|
||||
private RecyclerView mRecyclerView;
|
||||
private ActivePackagesAdapter mRecycleViewAdapter;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View mRootView = inflater.inflate(R.layout.fragment_tomatot_debloater, container, false);
|
||||
|
||||
AppCompatImageButton mActionIcon = mRootView.findViewById(R.id.action_icon);
|
||||
mProgressLayout = mRootView.findViewById(R.id.progress_layout);
|
||||
LinearLayout mTitleLayout = mRootView.findViewById(R.id.title_layout);
|
||||
MaterialTextView mInvisible = mRootView.findViewById(R.id.invisible);
|
||||
MaterialTextView mLight = mRootView.findViewById(R.id.light);
|
||||
MaterialTextView mExtreme = mRootView.findViewById(R.id.extreme);
|
||||
MaterialTextView mStatus = mRootView.findViewById(R.id.deblaoter_status);
|
||||
MaterialTextView mActionMessage = mRootView.findViewById(R.id.action_message);
|
||||
mRecyclerView = mRootView.findViewById(R.id.recycler_view);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(requireActivity()));
|
||||
|
||||
MaterialTextView mAppsListTitle = mRootView.findViewById(R.id.apps_list_title);
|
||||
mAppListCard = mRootView.findViewById(R.id.apps_list_card);
|
||||
FrameLayout mActionLayout = mRootView.findViewById(R.id.action_layout);
|
||||
if (sThemeUtils.isDarkTheme(requireActivity())) {
|
||||
mActionMessage.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mActionIcon.setColorFilter(Utils.getThemeAccentColor(requireActivity()));
|
||||
mAppsListTitle.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
}
|
||||
|
||||
if (Tomatot.isScriptEnabled("tomatot_extreme", requireActivity())) {
|
||||
mInvisible.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mLight.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mExtreme.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mStatus.setText(R.string.custom_scripts_uad_enabled);
|
||||
mActionMessage.setText(R.string.restore);
|
||||
mExtremeT = true;
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getTExtreme(), null);
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
mAppListCard.setVisibility(View.VISIBLE);
|
||||
} else if (Tomatot.isScriptEnabled("tomatot_light", requireActivity())) {
|
||||
mInvisible.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mLight.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mExtreme.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mStatus.setText(R.string.custom_scripts_uad_enabled);
|
||||
mActionMessage.setText(R.string.restore);
|
||||
mLightT = true;
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getTLight(), null);
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
mAppListCard.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mInvisible.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mLight.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mExtreme.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mStatus.setText(sCommonUtils.getBoolean("tomatot_invisible", false, requireActivity()) ?
|
||||
R.string.custom_scripts_uad_enabled : R.string.custom_scripts_tomatot_invisible);
|
||||
mActionMessage.setText(sCommonUtils.getBoolean("tomatot_invisible", false, requireActivity()) ?
|
||||
R.string.restore : R.string.apply);
|
||||
mInvisibleT = true;
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.geTInvisible(), null);
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
mAppListCard.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mTitleLayout.setOnClickListener(v -> sCommonUtils.launchUrl("https://forum.xda-developers.com" +
|
||||
"/oneplus-6/oneplus-6--6t-cross-device-development/tool-tomatot-debloater-basic-script-to-t3869427",
|
||||
requireActivity()));
|
||||
mInvisible.setOnClickListener(v -> {
|
||||
mExtremeT = false;
|
||||
mInvisibleT = true;
|
||||
mLightT = false;
|
||||
mInvisible.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mLight.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mExtreme.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mStatus.setText(sCommonUtils.getBoolean("tomatot_invisible", false, requireActivity()) ?
|
||||
R.string.custom_scripts_uad_enabled : R.string.custom_scripts_tomatot_invisible);
|
||||
mActionMessage.setText(sCommonUtils.getBoolean("tomatot_invisible", false, requireActivity()) ?
|
||||
R.string.restore : R.string.apply);
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.geTInvisible(), null);
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
});
|
||||
mLight.setOnClickListener(v -> {
|
||||
mExtremeT = false;
|
||||
mInvisibleT = false;
|
||||
mLightT = true;
|
||||
mInvisible.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mLight.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mExtreme.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mStatus.setText(sCommonUtils.getBoolean("tomatot_light", false, requireActivity()) ?
|
||||
R.string.custom_scripts_uad_enabled : R.string.custom_scripts_tomatot_light);
|
||||
mActionMessage.setText(sCommonUtils.getBoolean("tomatot_light", false, requireActivity()) ?
|
||||
R.string.restore : R.string.apply);
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getTLight(), null);
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
});
|
||||
mExtreme.setOnClickListener(v -> {
|
||||
mExtremeT = true;
|
||||
mInvisibleT = false;
|
||||
mLightT = false;
|
||||
mInvisible.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mLight.setTextColor(Utils.getPrimaryTextColor(requireActivity()));
|
||||
mExtreme.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mStatus.setText(sCommonUtils.getBoolean("tomatot_extreme", false, requireActivity()) ?
|
||||
R.string.custom_scripts_uad_enabled : R.string.custom_scripts_tomatot_extreme);
|
||||
mActionMessage.setText(sCommonUtils.getBoolean("tomatot_extreme", false, requireActivity()) ?
|
||||
R.string.restore : R.string.apply);
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getTExtreme(), null);
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
});
|
||||
mActionLayout.setOnClickListener(v ->
|
||||
new sExecutor() {
|
||||
|
||||
@Override
|
||||
public void onPreExecute() {
|
||||
mProgressLayout.setVisibility(View.VISIBLE);
|
||||
mAppListCard.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInBackground() {
|
||||
if (mExtremeT) {
|
||||
if (sCommonUtils.getBoolean("tomatot_extreme", false, requireActivity())) {
|
||||
Tomatot.disable("tomatot_extreme", Common.getTExtreme(), requireActivity());
|
||||
} else {
|
||||
if (Tomatot.isScriptEnabled("tomatot_invisible", requireActivity())) {
|
||||
Tomatot.disable("tomatot_invisible", Common.geTInvisible(), requireActivity());
|
||||
}
|
||||
if (Tomatot.isScriptEnabled("tomatot_light", requireActivity())) {
|
||||
Tomatot.disable("tomatot_light", Common.getTLight(), requireActivity());
|
||||
}
|
||||
Tomatot.enable("tomatot_extreme", Common.getTExtreme(), requireActivity());
|
||||
}
|
||||
} else if (mInvisibleT) {
|
||||
if (sCommonUtils.getBoolean("tomatot_invisible", false, requireActivity())) {
|
||||
Tomatot.disable("tomatot_invisible", Common.geTInvisible(), requireActivity());
|
||||
} else {
|
||||
if (Tomatot.isScriptEnabled("tomatot_light", requireActivity())) {
|
||||
Tomatot.disable("tomatot_light", Common.getTLight(), requireActivity());
|
||||
}
|
||||
if (Tomatot.isScriptEnabled("tomatot_extreme", requireActivity())) {
|
||||
Tomatot.disable("tomatot_extreme", Common.getTExtreme(), requireActivity());
|
||||
}
|
||||
Tomatot.enable("tomatot_invisible", Common.geTInvisible(), requireActivity());
|
||||
}
|
||||
} else if (mLightT) {
|
||||
if (sCommonUtils.getBoolean("tomatot_light", false, requireActivity())) {
|
||||
Tomatot.disable("tomatot_light", Common.getTLight(), requireActivity());
|
||||
} else {
|
||||
if (Tomatot.isScriptEnabled("tomatot_invisible", requireActivity())) {
|
||||
Tomatot.disable("tomatot_invisible", Common.geTInvisible(), requireActivity());
|
||||
}
|
||||
if (Tomatot.isScriptEnabled("tomatot_extreme", requireActivity())) {
|
||||
Tomatot.disable("tomatot_extreme", Common.getTExtreme(), requireActivity());
|
||||
}
|
||||
Tomatot.enable("tomatot_light", Common.getTLight(), requireActivity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute() {
|
||||
mProgressLayout.setVisibility(View.GONE);
|
||||
new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setMessage(R.string.custom_scripts_applied_message)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(getString(R.string.cancel), (dialog, id) -> requireActivity().finish()).show();
|
||||
}
|
||||
}.execute()
|
||||
);
|
||||
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,331 @@
|
|||
package com.sunilpaulmathew.debloater.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
import com.sunilpaulmathew.debloater.R;
|
||||
import com.sunilpaulmathew.debloater.adapters.ActivePackagesAdapter;
|
||||
import com.sunilpaulmathew.debloater.utils.Common;
|
||||
import com.sunilpaulmathew.debloater.utils.PackageTasks;
|
||||
import com.sunilpaulmathew.debloater.utils.UAD;
|
||||
import com.sunilpaulmathew.debloater.utils.Utils;
|
||||
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sCommonUtils;
|
||||
import in.sunilpaulmathew.sCommon.CommonUtils.sExecutor;
|
||||
import in.sunilpaulmathew.sCommon.ThemeUtils.sThemeUtils;
|
||||
|
||||
/*
|
||||
* Created by sunilpaulmathew <sunil.kde@gmail.com> on January 26, 2021
|
||||
*/
|
||||
|
||||
public class UADFragment extends Fragment {
|
||||
|
||||
private AppCompatImageButton mSelectIcon;
|
||||
private MaterialCardView mAppListCard;
|
||||
private MaterialTextView mActionMessage, mScriptTitle, mScriptStatus;
|
||||
private LinearLayout mProgressLayout;
|
||||
private RecyclerView mRecyclerView;
|
||||
private ActivePackagesAdapter mRecycleViewAdapter;
|
||||
private String mScriptPath;
|
||||
private String mTitle;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View mRootView = inflater.inflate(R.layout.fragment_uad, container, false);
|
||||
|
||||
AppCompatImageButton mActionIcon = mRootView.findViewById(R.id.action_icon);
|
||||
mSelectIcon = mRootView.findViewById(R.id.select_icon);
|
||||
FrameLayout mActionLayout = mRootView.findViewById(R.id.action_layout);
|
||||
mProgressLayout = mRootView.findViewById(R.id.progress_layout);
|
||||
LinearLayout mTitleLayout = mRootView.findViewById(R.id.title_layout);
|
||||
mAppListCard = mRootView.findViewById(R.id.apps_list_card);
|
||||
mActionMessage = mRootView.findViewById(R.id.action_message);
|
||||
MaterialTextView mAppsListTitle = mRootView.findViewById(R.id.apps_list_title);
|
||||
mScriptTitle = mRootView.findViewById(R.id.script_title);
|
||||
mScriptStatus = mRootView.findViewById(R.id.deblaoter_status);
|
||||
mRecyclerView = mRootView.findViewById(R.id.recycler_view);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(requireActivity()));
|
||||
|
||||
if (sThemeUtils.isDarkTheme(requireActivity())) {
|
||||
mActionMessage.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mActionIcon.setColorFilter(Utils.getThemeAccentColor(requireActivity()));
|
||||
mAppsListTitle.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
mScriptTitle.setTextColor(Utils.getThemeAccentColor(requireActivity()));
|
||||
}
|
||||
|
||||
if (Build.BRAND.equalsIgnoreCase("oneplus")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_oneplus";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getOnePlus(), null);
|
||||
mTitle = getString(R.string.oneplus);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("asus")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_asus";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getAsus(), null);
|
||||
mTitle = getString(R.string.asus);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("motorola")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_motorola";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getMoto(), null);
|
||||
mTitle = getString(R.string.motorola);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("huawei")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_huawei";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getHuawei(), null);
|
||||
mTitle = getString(R.string.huawei);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("lg")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_lg";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getLG(), null);
|
||||
mTitle = getString(R.string.lg);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("samsung")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_samsung";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getSamsung(), null);
|
||||
mTitle = getString(R.string.samsung);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("nokia")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_nokia";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getNokia(), null);
|
||||
mTitle = getString(R.string.nokia);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("oppo")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_oppo";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getOppo(), null);
|
||||
mTitle = getString(R.string.oppo);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("sony")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_sony";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getSony(), null);
|
||||
mTitle = getString(R.string.sony);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("xiaomi")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_xiaomi";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getXiaomi(), null);
|
||||
mTitle = getString(R.string.xiaomi);
|
||||
} else if (Build.BRAND.equalsIgnoreCase("zte")) {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_zte";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getZTE(), null);
|
||||
mTitle = getString(R.string.zte);
|
||||
} else {
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_google";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getGoogle(), null);
|
||||
mTitle = getString(R.string.google);
|
||||
}
|
||||
|
||||
setStatus();
|
||||
|
||||
mTitleLayout.setOnClickListener(v -> sCommonUtils.launchUrl( "https://gitlab.com/W1nst0n/universal-android-debloater",
|
||||
requireActivity()));
|
||||
|
||||
mActionLayout.setOnClickListener(v ->
|
||||
new sExecutor() {
|
||||
|
||||
@Override
|
||||
public void onPreExecute() {
|
||||
mProgressLayout.setVisibility(View.VISIBLE);
|
||||
mAppListCard.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInBackground() {
|
||||
UAD.applyScript(mScriptPath, requireActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostExecute() {
|
||||
mProgressLayout.setVisibility(View.GONE);
|
||||
new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setMessage(R.string.custom_scripts_applied_message)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(getString(R.string.cancel), (dialog, id) -> requireActivity().finish()).show();
|
||||
}
|
||||
}.execute()
|
||||
);
|
||||
|
||||
mSelectIcon.setOnClickListener(v -> selectionMenu(requireActivity()));
|
||||
|
||||
return mRootView;
|
||||
}
|
||||
|
||||
private void selectionMenu(Activity activity) {
|
||||
PopupMenu popupMenu = new PopupMenu(requireActivity(), mSelectIcon);
|
||||
Menu menu = popupMenu.getMenu();
|
||||
if (!Common.getAOSP().isEmpty() || Utils.exist("uad_aosp")) {
|
||||
menu.add(Menu.NONE, 0, Menu.NONE, R.string.aosp);
|
||||
}
|
||||
if (!Common.getGoogle().isEmpty() || Utils.exist("uad_google")) {
|
||||
menu.add(Menu.NONE, 1, Menu.NONE, R.string.google);
|
||||
}
|
||||
if (!Common.getOnePlus().isEmpty() || Utils.exist("uad_oneplus")) {
|
||||
menu.add(Menu.NONE, 2, Menu.NONE, R.string.oneplus);
|
||||
}
|
||||
if (!Common.getAsus().isEmpty() || Utils.exist("uad_asus")) {
|
||||
menu.add(Menu.NONE, 3, Menu.NONE, R.string.asus);
|
||||
}
|
||||
if (!Common.getHuawei().isEmpty() || Utils.exist("uad_huawei")) {
|
||||
menu.add(Menu.NONE, 4, Menu.NONE, R.string.huawei);
|
||||
}
|
||||
if (!Common.getLG().isEmpty() || Utils.exist("uad_lg")) {
|
||||
menu.add(Menu.NONE, 5, Menu.NONE, R.string.lg);
|
||||
}
|
||||
if (!Common.getSamsung().isEmpty() || Utils.exist("uad_samsung")) {
|
||||
menu.add(Menu.NONE, 6, Menu.NONE, R.string.samsung);
|
||||
}
|
||||
if (!Common.getMoto().isEmpty() || Utils.exist("uad_motorola")) {
|
||||
menu.add(Menu.NONE, 7, Menu.NONE, R.string.motorola);
|
||||
}
|
||||
if (!Common.getNokia().isEmpty() || Utils.exist("uad_nokia")) {
|
||||
menu.add(Menu.NONE, 8, Menu.NONE, R.string.nokia);
|
||||
}
|
||||
if (!Common.getOppo().isEmpty() || Utils.exist("uad_oppo")) {
|
||||
menu.add(Menu.NONE, 9, Menu.NONE, R.string.oppo);
|
||||
}
|
||||
if (!Common.getSony().isEmpty() || Utils.exist("uad_sony")) {
|
||||
menu.add(Menu.NONE, 10, Menu.NONE, R.string.sony);
|
||||
}
|
||||
if (!Common.getXiaomi().isEmpty() || Utils.exist("uad_xiaomi")) {
|
||||
menu.add(Menu.NONE, 11, Menu.NONE, R.string.xiaomi);
|
||||
}
|
||||
if (!Common.getZTE().isEmpty() || Utils.exist("uad_zte")) {
|
||||
menu.add(Menu.NONE, 12, Menu.NONE, R.string.zte);
|
||||
}
|
||||
if (!Common.getCarrier().isEmpty() || Utils.exist("uad_carrier")) {
|
||||
menu.add(Menu.NONE, 13, Menu.NONE, R.string.carrier);
|
||||
}
|
||||
if (!Common.getMisc().isEmpty() || Utils.exist("uad_misc")) {
|
||||
menu.add(Menu.NONE, 14, Menu.NONE, R.string.miscellaneous);
|
||||
}
|
||||
popupMenu.setOnMenuItemClickListener(item -> {
|
||||
switch (item.getItemId()) {
|
||||
case 0:
|
||||
sCommonUtils.saveString("setDefault", "aosp", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_aosp";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getAOSP(), null);
|
||||
mTitle = getString(R.string.aosp);
|
||||
setStatus();
|
||||
break;
|
||||
case 1:
|
||||
sCommonUtils.saveString("setDefault", "google", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_google";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getGoogle(), null);
|
||||
mTitle = getString(R.string.google);
|
||||
setStatus();
|
||||
break;
|
||||
case 2:
|
||||
sCommonUtils.saveString("setDefault", "oneplus", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_oneplus";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getOnePlus(), null);
|
||||
mTitle = getString(R.string.oneplus);
|
||||
setStatus();
|
||||
break;
|
||||
case 3:
|
||||
sCommonUtils.saveString("setDefault", "asus", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_aosp";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getAsus(), null);
|
||||
mTitle = getString(R.string.asus);
|
||||
setStatus();
|
||||
break;
|
||||
case 4:
|
||||
sCommonUtils.saveString("setDefault", "huawei", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_huawei";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getHuawei(), null);
|
||||
mTitle = getString(R.string.huawei);
|
||||
setStatus();
|
||||
break;
|
||||
case 5:
|
||||
sCommonUtils.saveString("setDefault", "lg", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_lg";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getLG(), null);
|
||||
mTitle = getString(R.string.lg);
|
||||
setStatus();
|
||||
break;
|
||||
case 6:
|
||||
sCommonUtils.saveString("setDefault", "samsung", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_samsung";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getSamsung(), null);
|
||||
mTitle = getString(R.string.samsung);
|
||||
setStatus();
|
||||
break;
|
||||
case 7:
|
||||
sCommonUtils.saveString("setDefault", "motorola", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_motorola";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getMoto(), null);
|
||||
mTitle = getString(R.string.motorola);
|
||||
setStatus();
|
||||
break;
|
||||
case 8:
|
||||
sCommonUtils.saveString("setDefault", "nokia", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_nokia";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getNokia(), null);
|
||||
mTitle = getString(R.string.nokia);
|
||||
setStatus();
|
||||
break;
|
||||
case 9:
|
||||
sCommonUtils.saveString("setDefault", "oppo", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_oppo";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getOppo(), null);
|
||||
mTitle = getString(R.string.oppo);
|
||||
setStatus();
|
||||
break;
|
||||
case 10:
|
||||
sCommonUtils.saveString("setDefault", "sony", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_sony";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getSony(), null);
|
||||
mTitle = getString(R.string.sony);
|
||||
setStatus();
|
||||
break;
|
||||
case 11:
|
||||
sCommonUtils.saveString("setDefault", "xiaomi", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_xiaomi";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getXiaomi(), null);
|
||||
mTitle = getString(R.string.xiaomi);
|
||||
setStatus();
|
||||
break;
|
||||
case 12:
|
||||
sCommonUtils.saveString("setDefault", "zte", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_zte";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getZTE(), null);
|
||||
mTitle = getString(R.string.zte);
|
||||
setStatus();
|
||||
break;
|
||||
case 13:
|
||||
sCommonUtils.saveString("setDefault", "carrier", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_carrier";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getCarrier(), null);
|
||||
mTitle = getString(R.string.carrier);
|
||||
setStatus();
|
||||
break;
|
||||
case 14:
|
||||
sCommonUtils.saveString("setDefault", "misc", activity);
|
||||
mScriptPath = PackageTasks.getModulePath() + "/uad_misc";
|
||||
mRecycleViewAdapter = new ActivePackagesAdapter(Common.getMisc(), null);
|
||||
mTitle = getString(R.string.miscellaneous);
|
||||
setStatus();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
popupMenu.show();
|
||||
}
|
||||
|
||||
private void setStatus() {
|
||||
if (Utils.exist(mScriptPath)) {
|
||||
mScriptStatus.setText(getString(R.string.custom_scripts_uad_enabled));
|
||||
} else {
|
||||
mScriptStatus.setText(getString(R.string.custom_scripts_uad_disabled));
|
||||
}
|
||||
mActionMessage.setText(Utils.exist(mScriptPath) ? getString(R.string.restore) : getString(R.string.apply));
|
||||
mScriptTitle.setText(mTitle);
|
||||
mRecyclerView.setAdapter(mRecycleViewAdapter);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue