diff --git a/app/build.gradle b/app/build.gradle index e9c8f5e18..a1220d488 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -79,4 +79,12 @@ dependencies { fullImplementation 'com.github.topjohnwu:libsu:2.0.2' fullImplementation 'com.atlassian.commonmark:commonmark:0.11.0' fullImplementation 'org.kamranzafar:jtar:2.3' + + def butterKnifeVersion = '9.0.0-rc1' + if (properties.containsKey('android.injected.invoked.from.ide')) { + fullImplementation "com.jakewharton:butterknife-reflect:${butterKnifeVersion}" + } else { + fullImplementation "com.jakewharton:butterknife-runtime:${butterKnifeVersion}" + fullAnnotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" + } } diff --git a/app/src/full/java/com/topjohnwu/magisk/AboutActivity.java b/app/src/full/java/com/topjohnwu/magisk/AboutActivity.java index 46afa1f60..de6b34aa1 100644 --- a/app/src/full/java/com/topjohnwu/magisk/AboutActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/AboutActivity.java @@ -15,16 +15,17 @@ import java.util.Locale; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; +import butterknife.BindView; public class AboutActivity extends BaseActivity { - Toolbar toolbar; - AboutCardRow appVersionInfo; - AboutCardRow appChangelog; - AboutCardRow appTranslators; - AboutCardRow appSourceCode; - AboutCardRow supportThread; - AboutCardRow twitter; + @BindView(R.id.toolbar) Toolbar toolbar; + @BindView(R.id.app_version_info) AboutCardRow appVersionInfo; + @BindView(R.id.app_changelog) AboutCardRow appChangelog; + @BindView(R.id.app_translators) AboutCardRow appTranslators; + @BindView(R.id.app_source_code) AboutCardRow appSourceCode; + @BindView(R.id.support_thread) AboutCardRow supportThread; + @BindView(R.id.follow_twitter) AboutCardRow twitter; @Override public int getDarkTheme() { @@ -35,7 +36,7 @@ public class AboutActivity extends BaseActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); - ViewBinder.bind(this); + new AboutActivity_ViewBinding(this); setSupportActionBar(toolbar); toolbar.setNavigationOnClickListener(view -> finish()); diff --git a/app/src/full/java/com/topjohnwu/magisk/DonationActivity.java b/app/src/full/java/com/topjohnwu/magisk/DonationActivity.java index 3386bb7a6..254ee6c9b 100644 --- a/app/src/full/java/com/topjohnwu/magisk/DonationActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/DonationActivity.java @@ -10,12 +10,13 @@ import com.topjohnwu.magisk.utils.Utils; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; +import butterknife.BindView; public class DonationActivity extends BaseActivity { - Toolbar toolbar; - AboutCardRow paypal; - AboutCardRow patreon; + @BindView(R.id.toolbar) Toolbar toolbar; + @BindView(R.id.paypal) AboutCardRow paypal; + @BindView(R.id.patreon) AboutCardRow patreon; @Override public int getDarkTheme() { @@ -26,7 +27,7 @@ public class DonationActivity extends BaseActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_donation); - ViewBinder.bind(this); + new DonationActivity_ViewBinding(this); setSupportActionBar(toolbar); toolbar.setNavigationOnClickListener(view -> finish()); diff --git a/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java b/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java index 964667f2c..a6b2a5df6 100644 --- a/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/FlashActivity.java @@ -31,21 +31,25 @@ import java.util.Locale; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; +import butterknife.BindView; +import butterknife.OnClick; public class FlashActivity extends BaseActivity { - Toolbar toolbar; - TextView flashLogs; - public LinearLayout buttonPanel; - public Button reboot; - ScrollView sv; + @BindView(R.id.toolbar) Toolbar toolbar; + @BindView(R.id.txtLog) TextView flashLogs; + @BindView(R.id.button_panel) public LinearLayout buttonPanel; + @BindView(R.id.reboot) public Button reboot; + @BindView(R.id.scrollView) ScrollView sv; private List logs; + @OnClick(R.id.reboot) void reboot() { Shell.su("/system/bin/reboot").submit(); } + @OnClick(R.id.save_logs) void saveLogs() { runWithPermission(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, () -> { Calendar now = Calendar.getInstance(); @@ -78,7 +82,8 @@ public class FlashActivity extends BaseActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flash); - ViewBinder.bind(this); + new FlashActivity_ViewBinding(this); + setSupportActionBar(toolbar); ActionBar ab = getSupportActionBar(); if (ab != null) { diff --git a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java index b03dbaefe..fecf23b00 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java @@ -26,6 +26,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; +import butterknife.BindView; public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, Topic.Subscriber { @@ -34,9 +35,9 @@ public class MainActivity extends BaseActivity private int mDrawerItem; private static boolean fromShortcut = false; - public Toolbar toolbar; - DrawerLayout drawer; - NavigationView navigationView; + @BindView(R.id.toolbar) public Toolbar toolbar; + @BindView(R.id.drawer_layout) DrawerLayout drawer; + @BindView(R.id.nav_view) NavigationView navigationView; private float toolbarElevation; @@ -54,7 +55,7 @@ public class MainActivity extends BaseActivity super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - ViewBinder.bind(this); + new MainActivity_ViewBinding(this); setSupportActionBar(toolbar); diff --git a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java index b86c04253..1e3f4601c 100644 --- a/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/SuRequestActivity.java @@ -27,17 +27,18 @@ import java.io.IOException; import java.io.OutputStream; import androidx.annotation.Nullable; +import butterknife.BindView; public class SuRequestActivity extends BaseActivity { - LinearLayout suPopup; - Spinner timeout; - ImageView appIcon; - TextView appNameView; - TextView packageNameView; - Button grant_btn; - Button deny_btn; - ImageView fingerprintImg; - TextView warning; + @BindView(R.id.su_popup) LinearLayout suPopup; + @BindView(R.id.timeout) Spinner timeout; + @BindView(R.id.app_icon) ImageView appIcon; + @BindView(R.id.app_name) TextView appNameView; + @BindView(R.id.package_name) TextView packageNameView; + @BindView(R.id.grant_btn) Button grant_btn; + @BindView(R.id.deny_btn) Button deny_btn; + @BindView(R.id.fingerprint) ImageView fingerprintImg; + @BindView(R.id.warning) TextView warning; private SuConnector connector; private Policy policy; @@ -157,7 +158,7 @@ public class SuRequestActivity extends BaseActivity { } setContentView(R.layout.activity_request); - ViewBinder.bind(this); + new SuRequestActivity_ViewBinding(this); appIcon.setImageDrawable(policy.info.loadIcon(pm)); appNameView.setText(policy.appName); diff --git a/app/src/full/java/com/topjohnwu/magisk/ViewBinder.java b/app/src/full/java/com/topjohnwu/magisk/ViewBinder.java deleted file mode 100644 index cdcdd6c59..000000000 --- a/app/src/full/java/com/topjohnwu/magisk/ViewBinder.java +++ /dev/null @@ -1,293 +0,0 @@ -package com.topjohnwu.magisk; - -import android.content.Context; -import android.view.View; - -import com.topjohnwu.magisk.adapters.ApplicationAdapter; -import com.topjohnwu.magisk.adapters.ModulesAdapter; -import com.topjohnwu.magisk.adapters.PolicyAdapter; -import com.topjohnwu.magisk.adapters.ReposAdapter; -import com.topjohnwu.magisk.adapters.SuLogAdapter; -import com.topjohnwu.magisk.components.AboutCardRow; -import com.topjohnwu.magisk.components.CustomAlertDialog; -import com.topjohnwu.magisk.fragments.LogFragment; -import com.topjohnwu.magisk.fragments.MagiskFragment; -import com.topjohnwu.magisk.fragments.MagiskHideFragment; -import com.topjohnwu.magisk.fragments.MagiskLogFragment; -import com.topjohnwu.magisk.fragments.ModulesFragment; -import com.topjohnwu.magisk.fragments.ReposFragment; -import com.topjohnwu.magisk.fragments.SuLogFragment; -import com.topjohnwu.magisk.fragments.SuperuserFragment; - -import androidx.core.content.ContextCompat; - -public class ViewBinder { - - public static void bind(MainActivity target) { - target.drawer = target.findViewById(R.id.drawer_layout); - target.toolbar = target.findViewById(R.id.toolbar); - target.navigationView = target.findViewById(R.id.nav_view); - } - - public static void bind(AboutActivity target) { - target.toolbar = target.findViewById(R.id.toolbar); - target.appVersionInfo = target.findViewById(R.id.app_version_info); - target.appChangelog = target.findViewById(R.id.app_changelog); - target.appTranslators = target.findViewById(R.id.app_translators); - target.appSourceCode = target.findViewById(R.id.app_source_code); - target.supportThread = target.findViewById(R.id.support_thread); - target.twitter = target.findViewById(R.id.follow_twitter); - } - - public static void bind(DonationActivity target) { - target.toolbar = target.findViewById(R.id.toolbar); - target.paypal = target.findViewById(R.id.paypal); - target.patreon = target.findViewById(R.id.patreon); - } - - public static void bind(FlashActivity target) { - target.toolbar = target.findViewById(R.id.toolbar); - target.flashLogs = target.findViewById(R.id.txtLog); - target.buttonPanel = target.findViewById(R.id.button_panel); - target.sv = target.findViewById(R.id.scrollView); - target.reboot = target.findViewById(R.id.reboot); - target.reboot.setOnClickListener(v -> target.reboot()); - target.findViewById(R.id.close).setOnClickListener(v -> target.finish()); - target.findViewById(R.id.save_logs).setOnClickListener(v -> target.saveLogs()); - } - - public static void bind(SuRequestActivity target) { - target.suPopup = target.findViewById(R.id.su_popup); - target.timeout = target.findViewById(R.id.timeout); - target.appIcon = target.findViewById(R.id.app_icon); - target.appNameView = target.findViewById(R.id.app_name); - target.packageNameView = target.findViewById(R.id.package_name); - target.grant_btn = target.findViewById(R.id.grant_btn); - target.deny_btn = target.findViewById(R.id.deny_btn); - target.fingerprintImg = target.findViewById(R.id.fingerprint); - target.warning = target.findViewById(R.id.warning); - } - - public static void bind(LogFragment target, View v) { - target.viewPager = v.findViewById(R.id.container); - target.tab = v.findViewById(R.id.tab); - } - - public static void unbind(LogFragment target) { - target.viewPager = null; - target.tab = null; - } - - public static void bind(MagiskFragment target, View v) { - target.mSwipeRefreshLayout = v.findViewById(R.id.swipeRefreshLayout); - target.coreOnlyNotice = v.findViewById(R.id.core_only_notice); - target.magiskUpdate = v.findViewById(R.id.magisk_update); - target.magiskUpdateIcon = v.findViewById(R.id.magisk_update_icon); - target.magiskUpdateText = v.findViewById(R.id.magisk_update_status); - target.magiskUpdateProgress = v.findViewById(R.id.magisk_update_progress); - target.magiskStatusIcon = v.findViewById(R.id.magisk_status_icon); - target.magiskVersionText = v.findViewById(R.id.magisk_version); - target.safetyNetCard = v.findViewById(R.id.safetyNet_card); - target.safetyNetRefreshIcon = v.findViewById(R.id.safetyNet_refresh); - target.safetyNetStatusText = v.findViewById(R.id.safetyNet_status); - target.safetyNetProgress = v.findViewById(R.id.safetyNet_check_progress); - target.expandLayout = v.findViewById(R.id.expand_layout); - target.ctsStatusIcon = v.findViewById(R.id.cts_status_icon); - target.ctsStatusText = v.findViewById(R.id.cts_status); - target.basicStatusIcon = v.findViewById(R.id.basic_status_icon); - target.basicStatusText = v.findViewById(R.id.basic_status); - target.installOptionCard = v.findViewById(R.id.install_option_card); - target.keepEncChkbox = v.findViewById(R.id.keep_force_enc); - target.keepVerityChkbox = v.findViewById(R.id.keep_verity); - target.installButton = v.findViewById(R.id.install_button); - target.installText = v.findViewById(R.id.install_text); - target.uninstallButton = v.findViewById(R.id.uninstall_button); - - v.findViewById(R.id.safetyNet_title).setOnClickListener(v1 -> target.safetyNet()); - v.findViewById(R.id.install_button).setOnClickListener(v1 -> target.install()); - v.findViewById(R.id.uninstall_button).setOnClickListener(v1 -> target.uninstall()); - - Context ctx = target.getContext(); - target.colorBad = ContextCompat.getColor(ctx, R.color.red500); - target.colorOK = ContextCompat.getColor(ctx, R.color.green500); - target.colorWarn = ContextCompat.getColor(ctx, R.color.yellow500); - target.colorNeutral = ContextCompat.getColor(ctx, R.color.grey500); - target.colorInfo = ContextCompat.getColor(ctx, R.color.blue500); - } - - public static void unbind(MagiskFragment target) { - target.mSwipeRefreshLayout = null; - target.coreOnlyNotice = null; - target.magiskUpdate = null; - target.magiskUpdateIcon = null; - target.magiskUpdateText = null; - target.magiskUpdateProgress = null; - target.magiskStatusIcon = null; - target.magiskVersionText = null; - target.safetyNetCard = null; - target.safetyNetRefreshIcon = null; - target.safetyNetStatusText = null; - target.safetyNetProgress = null; - target.expandLayout = null; - target.ctsStatusIcon = null; - target.ctsStatusText = null; - target.basicStatusIcon = null; - target.basicStatusText = null; - target.installOptionCard = null; - target.keepEncChkbox = null; - target.keepVerityChkbox = null; - target.installButton = null; - target.installText = null; - target.uninstallButton = null; - - View v = target.getView(); - v.findViewById(R.id.safetyNet_title).setOnClickListener(null); - v.findViewById(R.id.install_button).setOnClickListener(null); - v.findViewById(R.id.uninstall_button).setOnClickListener(null); - } - - public static void bind(MagiskHideFragment target, View v) { - target.mSwipeRefreshLayout = v.findViewById(R.id.swipeRefreshLayout); - target.recyclerView = v.findViewById(R.id.recyclerView); - } - - public static void unbind(MagiskHideFragment target) { - target.mSwipeRefreshLayout = null; - target.recyclerView = null; - } - - public static void bind(MagiskLogFragment target, View v) { - target.txtLog = v.findViewById(R.id.txtLog); - target.svLog = v.findViewById(R.id.svLog); - target.hsvLog = v.findViewById(R.id.hsvLog); - target.progressBar = v.findViewById(R.id.progressBar); - } - - public static void unbind(MagiskLogFragment target) { - target.txtLog = null; - target.svLog = null; - target.hsvLog = null; - target.progressBar = null; - } - - public static void bind(ModulesFragment target, View v) { - target.mSwipeRefreshLayout = v.findViewById(R.id.swipeRefreshLayout); - target.recyclerView = v.findViewById(R.id.recyclerView); - target.emptyRv = v.findViewById(R.id.empty_rv); - v.findViewById(R.id.fab).setOnClickListener(v1 -> target.selectFile()); - } - - public static void unbind(ModulesFragment target) { - target.mSwipeRefreshLayout = null; - target.recyclerView = null; - target.emptyRv = null; - View v = target.getView(); - v.findViewById(R.id.fab).setOnClickListener(null); - } - - public static void bind(ReposFragment target, View source) { - target.recyclerView = source.findViewById(R.id.recyclerView); - target.emptyRv = source.findViewById(R.id.empty_rv); - target.mSwipeRefreshLayout = source.findViewById(R.id.swipeRefreshLayout); - } - - public static void unbind(ReposFragment target) { - target.recyclerView = null; - target.emptyRv = null; - target.mSwipeRefreshLayout = null; - } - - public static void bind(SuLogFragment target, View source) { - target.emptyRv = source.findViewById(R.id.empty_rv); - target.recyclerView = source.findViewById(R.id.recyclerView); - } - - public static void unbind(SuLogFragment target) { - target.emptyRv = null; - target.recyclerView = null; - } - - public static void bind(SuperuserFragment target, View source) { - target.recyclerView = source.findViewById(R.id.recyclerView); - target.emptyRv = source.findViewById(R.id.empty_rv); - } - - public static void unbind(SuperuserFragment target) { - target.emptyRv = null; - target.recyclerView = null; - } - - public static void bind(CustomAlertDialog.ViewHolder target, View source) { - target.dialogLayout = source.findViewById(R.id.dialog_layout); - target.buttons = source.findViewById(R.id.button_panel); - target.messageView = source.findViewById(R.id.message); - target.negative = source.findViewById(R.id.negative); - target.positive = source.findViewById(R.id.positive); - target.neutral = source.findViewById(R.id.neutral); - } - - public static void bind(AboutCardRow target, View source) { - target.mTitle = source.findViewById(android.R.id.title); - target.mSummary = source.findViewById(android.R.id.summary); - target.mIcon = source.findViewById(android.R.id.icon); - target.mView = source.findViewById(R.id.container); - } - - public static void bind(ApplicationAdapter.ViewHolder target, View source) { - target.appIcon = source.findViewById(R.id.app_icon); - target.appName = source.findViewById(R.id.app_name); - target.appPackage = source.findViewById(R.id.package_name); - target.checkBox = source.findViewById(R.id.checkbox); - } - - public static void bind(ModulesAdapter.ViewHolder target, View source) { - target.title = source.findViewById(R.id.title); - target.versionName = source.findViewById(R.id.version_name); - target.description = source.findViewById(R.id.description); - target.notice = source.findViewById(R.id.notice); - target.checkBox = source.findViewById(R.id.checkbox); - target.author = source.findViewById(R.id.author); - target.delete = source.findViewById(R.id.delete); - } - - public static void bind(PolicyAdapter.ViewHolder target, View source) { - target.appName = source.findViewById(R.id.app_name); - target.packageName = source.findViewById(R.id.package_name); - target.appIcon = source.findViewById(R.id.app_icon); - target.masterSwitch = source.findViewById(R.id.master_switch); - target.notificationSwitch = source.findViewById(R.id.notification_switch); - target.loggingSwitch = source.findViewById(R.id.logging_switch); - target.expandLayout = source.findViewById(R.id.expand_layout); - target.delete = source.findViewById(R.id.delete); - target.moreInfo = source.findViewById(R.id.more_info); - } - - public static void bind(ReposAdapter.SectionHolder target, View source) { - target.sectionText = source.findViewById(R.id.section_text); - } - - public static void bind(ReposAdapter.RepoHolder target, View source) { - target.title = source.findViewById(R.id.title); - target.versionName = source.findViewById(R.id.version_name); - target.description = source.findViewById(R.id.description); - target.author = source.findViewById(R.id.author); - target.infoLayout = source.findViewById(R.id.info_layout); - target.downloadImage = source.findViewById(R.id.download); - target.updateTime = source.findViewById(R.id.update_time); - } - - public static void bind(SuLogAdapter.SectionHolder target, View source) { - target.date = source.findViewById(R.id.date); - target.arrow = source.findViewById(R.id.arrow); - } - - public static void bind(SuLogAdapter.LogViewHolder target, View source) { - target.appName = source.findViewById(R.id.app_name); - target.action = source.findViewById(R.id.action); - target.time = source.findViewById(R.id.time); - target.fromPid = source.findViewById(R.id.fromPid); - target.toUid = source.findViewById(R.id.toUid); - target.command = source.findViewById(R.id.command); - target.expandLayout = source.findViewById(R.id.expand_layout); - } -} diff --git a/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java index 4a7382a85..76a5ac74a 100644 --- a/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -17,7 +17,6 @@ import android.widget.TextView; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.utils.LocaleManager; import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.superuser.Shell; @@ -29,6 +28,7 @@ import java.util.List; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import butterknife.BindView; public class ApplicationAdapter extends RecyclerView.Adapter { @@ -122,20 +122,20 @@ public class ApplicationAdapter extends RecyclerView.Adapter { @@ -28,6 +29,7 @@ public class ModulesAdapter extends RecyclerView.Adapter { @@ -39,6 +40,7 @@ public class PolicyAdapter extends RecyclerView.Adapter { @@ -163,29 +163,29 @@ public class ReposAdapter extends SectionedAdapter { @@ -116,32 +116,32 @@ public class SuLogAdapter extends SectionedAdapter { safetyNetProgress.setVisibility(View.VISIBLE); safetyNetRefreshIcon.setVisibility(View.GONE); @@ -106,7 +109,8 @@ public class MagiskFragment extends BaseFragment } - public void install() { + @OnClick(R.id.install_button) + void install() { shownDialog = true; // Show Manager update first @@ -119,7 +123,8 @@ public class MagiskFragment extends BaseFragment new MagiskInstallDialog((BaseActivity) getActivity()).show(); } - public void uninstall() { + @OnClick(R.id.uninstall_button) + void uninstall() { new UninstallDialog(requireActivity()).show(); } @@ -128,7 +133,7 @@ public class MagiskFragment extends BaseFragment public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_magisk, container, false); - ViewBinder.bind(this, v); + unbinder = new MagiskFragment_ViewBinding(this, v); requireActivity().setTitle(R.string.magisk); expandableContainer.expandLayout = expandLayout; @@ -145,12 +150,6 @@ public class MagiskFragment extends BaseFragment return v; } - @Override - public void onDestroyView() { - super.onDestroyView(); - ViewBinder.unbind(this); - } - @Override public void onRefresh() { Data.loadMagiskInfo(); diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java index 6d54293b9..ac9599db4 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java @@ -9,7 +9,6 @@ import android.view.ViewGroup; import android.widget.SearchView; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.adapters.ApplicationAdapter; import com.topjohnwu.magisk.components.BaseFragment; import com.topjohnwu.magisk.utils.Topic; @@ -18,11 +17,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import butterknife.BindView; public class MagiskHideFragment extends BaseFragment implements Topic.Subscriber { - public SwipeRefreshLayout mSwipeRefreshLayout; - public RecyclerView recyclerView; + @BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout; + @BindView(R.id.recyclerView) RecyclerView recyclerView; SearchView search; private ApplicationAdapter appAdapter; @@ -39,7 +39,7 @@ public class MagiskHideFragment extends BaseFragment implements Topic.Subscriber @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_magisk_hide, container, false); - ViewBinder.bind(this, view); + unbinder = new MagiskHideFragment_ViewBinding(this, view); appAdapter = new ApplicationAdapter(requireActivity()); recyclerView.setAdapter(appAdapter); @@ -73,12 +73,6 @@ public class MagiskHideFragment extends BaseFragment implements Topic.Subscriber search.setOnQueryTextListener(searchListener); } - @Override - public void onDestroyView() { - super.onDestroyView(); - ViewBinder.unbind(this); - } - @Override public int[] getSubscribedTopics() { return new int[] {Topic.MAGISK_HIDE_DONE}; diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java index 77b293578..40cd619db 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskLogFragment.java @@ -17,7 +17,6 @@ import android.widget.TextView; import com.google.android.material.snackbar.Snackbar; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.components.BaseFragment; import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.utils.Download; @@ -29,19 +28,20 @@ import java.io.IOException; import java.util.Calendar; import androidx.annotation.Nullable; +import butterknife.BindView; public class MagiskLogFragment extends BaseFragment { - public TextView txtLog; - public ScrollView svLog; - public HorizontalScrollView hsvLog; - public ProgressBar progressBar; + @BindView(R.id.txtLog) TextView txtLog; + @BindView(R.id.svLog) ScrollView svLog; + @BindView(R.id.hsvLog) HorizontalScrollView hsvLog; + @BindView(R.id.progressBar) ProgressBar progressBar; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_magisk_log, container, false); - ViewBinder.bind(this, view); + unbinder = new MagiskLogFragment_ViewBinding(this, view); setHasOptionsMenu(true); txtLog.setTextIsSelectable(true); return view; @@ -59,12 +59,6 @@ public class MagiskLogFragment extends BaseFragment { readLogs(); } - @Override - public void onDestroyView() { - super.onDestroyView(); - ViewBinder.unbind(this); - } - @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_log, menu); @@ -87,7 +81,7 @@ public class MagiskLogFragment extends BaseFragment { } } - public void readLogs() { + private void readLogs() { Shell.su("cat " + Const.MAGISK_LOG + " | tail -n 5000").submit(result -> { progressBar.setVisibility(View.GONE); if (result.getOut().isEmpty()) @@ -99,7 +93,7 @@ public class MagiskLogFragment extends BaseFragment { }); } - public void saveLogs() { + private void saveLogs() { Calendar now = Calendar.getInstance(); String filename = Utils.fmt("magisk_log_%04d%02d%02d_%02d%02d%02d.log", now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1, @@ -117,7 +111,7 @@ public class MagiskLogFragment extends BaseFragment { SnackbarMaker.make(txtLog, logFile.getPath(), Snackbar.LENGTH_SHORT).show()); } - public void clearLogs() { + private void clearLogs() { Shell.su("echo -n > " + Const.MAGISK_LOG).submit(); txtLog.setText(R.string.log_is_empty); SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show(); diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java index 51c4c5d68..f392d0fed 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/ModulesFragment.java @@ -16,7 +16,6 @@ import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.adapters.ModulesAdapter; import com.topjohnwu.magisk.components.BaseFragment; import com.topjohnwu.magisk.container.Module; @@ -32,14 +31,17 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import butterknife.BindView; +import butterknife.OnClick; public class ModulesFragment extends BaseFragment implements Topic.Subscriber { - public SwipeRefreshLayout mSwipeRefreshLayout; - public RecyclerView recyclerView; - public TextView emptyRv; + @BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout; + @BindView(R.id.recyclerView) RecyclerView recyclerView; + @BindView(R.id.empty_rv) TextView emptyRv; - public void selectFile() { + @OnClick(R.id.fab) + void selectFile() { runWithPermission(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, () -> { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("application/zip"); @@ -53,7 +55,7 @@ public class ModulesFragment extends BaseFragment implements Topic.Subscriber { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_modules, container, false); - ViewBinder.bind(this, view); + unbinder = new ModulesFragment_ViewBinding(this, view); setHasOptionsMenu(true); mSwipeRefreshLayout.setOnRefreshListener(() -> { @@ -98,12 +100,6 @@ public class ModulesFragment extends BaseFragment implements Topic.Subscriber { } } - @Override - public void onDestroyView() { - super.onDestroyView(); - ViewBinder.unbind(this); - } - @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_reboot, menu); diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/ReposFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/ReposFragment.java index e7ae2b118..a352f4b30 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/ReposFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/ReposFragment.java @@ -14,7 +14,6 @@ import android.widget.TextView; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.adapters.ReposAdapter; import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.components.BaseFragment; @@ -27,12 +26,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import butterknife.BindView; public class ReposFragment extends BaseFragment implements Topic.Subscriber { - public RecyclerView recyclerView; - public TextView emptyRv; - public SwipeRefreshLayout mSwipeRefreshLayout; + @BindView(R.id.recyclerView) RecyclerView recyclerView; + @BindView(R.id.empty_rv) TextView emptyRv; + @BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout; private ReposAdapter adapter; @@ -46,7 +46,7 @@ public class ReposFragment extends BaseFragment implements Topic.Subscriber { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_repos, container, false); - ViewBinder.bind(this, view); + unbinder = new ReposFragment_ViewBinding(this, view); mSwipeRefreshLayout.setRefreshing(true); recyclerView.setVisibility(View.GONE); @@ -120,6 +120,5 @@ public class ReposFragment extends BaseFragment implements Topic.Subscriber { public void onDestroyView() { super.onDestroyView(); mm.repoDB.unregisterAdapter(); - ViewBinder.unbind(this); } } diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SuLogFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SuLogFragment.java index 0c1891771..a982513ff 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SuLogFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SuLogFragment.java @@ -10,17 +10,17 @@ import android.view.ViewGroup; import android.widget.TextView; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.adapters.SuLogAdapter; import com.topjohnwu.magisk.components.BaseFragment; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import butterknife.BindView; public class SuLogFragment extends BaseFragment { - public TextView emptyRv; - public RecyclerView recyclerView; + @BindView(R.id.empty_rv) TextView emptyRv; + @BindView(R.id.recyclerView) RecyclerView recyclerView; private SuLogAdapter adapter; @@ -41,7 +41,7 @@ public class SuLogFragment extends BaseFragment { Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_su_log, container, false); - ViewBinder.bind(this, v); + unbinder = new SuLogFragment_ViewBinding(this, v); adapter = new SuLogAdapter(mm.mDB); recyclerView.setAdapter(adapter); @@ -76,10 +76,4 @@ public class SuLogFragment extends BaseFragment { return true; } } - - @Override - public void onDestroyView() { - super.onDestroyView(); - ViewBinder.unbind(this); - } } diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java index ee2b114e9..f8b49603e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SuperuserFragment.java @@ -8,7 +8,6 @@ import android.view.ViewGroup; import android.widget.TextView; import com.topjohnwu.magisk.R; -import com.topjohnwu.magisk.ViewBinder; import com.topjohnwu.magisk.adapters.PolicyAdapter; import com.topjohnwu.magisk.components.BaseFragment; import com.topjohnwu.magisk.container.Policy; @@ -17,11 +16,12 @@ import java.util.List; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import butterknife.BindView; public class SuperuserFragment extends BaseFragment { - public RecyclerView recyclerView; - public TextView emptyRv; + @BindView(R.id.recyclerView) RecyclerView recyclerView; + @BindView(R.id.empty_rv) TextView emptyRv; private PackageManager pm; @@ -29,7 +29,7 @@ public class SuperuserFragment extends BaseFragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_superuser, container, false); - ViewBinder.bind(this, view); + unbinder = new SuperuserFragment_ViewBinding(this, view); pm = getActivity().getPackageManager(); return view; @@ -47,12 +47,6 @@ public class SuperuserFragment extends BaseFragment { displayPolicyList(); } - @Override - public void onDestroyView() { - super.onDestroyView(); - ViewBinder.unbind(this); - } - private void displayPolicyList() { List policyList = mm.mDB.getPolicyList(pm);