Skip to content

Commit

Permalink
Merge pull request #887
Browse files Browse the repository at this point in the history
Redesign home and hooks page
  • Loading branch information
siavash79 authored Sep 25, 2024
2 parents 8edb563 + 2e25eca commit e7f0506
Show file tree
Hide file tree
Showing 49 changed files with 1,596 additions and 1,025 deletions.
3 changes: 1 addition & 2 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,7 @@ dependencies {
//Google Subject Segmentation - MLKit
implementation libs.play.services.mlkit.subject.segmentation
implementation libs.play.services.base

// Collapsing Toolbar with subtitle
implementation "com.hendraanggrian.material:collapsingtoolbarlayout-subtitle:1.5.0"
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package sh.siava.pixelxpert.ui.activities;

import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
Expand All @@ -19,7 +17,6 @@

import sh.siava.pixelxpert.R;

@SuppressWarnings("unused")
public class BaseActivity extends AppCompatActivity {

@Override
Expand Down Expand Up @@ -57,16 +54,4 @@ private void setupEdgeToEdge() {
});
}
}

public static void setHeader(Context context, int title) {
Toolbar toolbar = ((AppCompatActivity) context).findViewById(R.id.toolbar);
((AppCompatActivity) context).setSupportActionBar(toolbar);
toolbar.setTitle(title);
}

public static void setHeader(Context context, CharSequence title) {
Toolbar toolbar = ((AppCompatActivity) context).findViewById(R.id.toolbar);
((AppCompatActivity) context).setSupportActionBar(toolbar);
toolbar.setTitle(title);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
Expand Down Expand Up @@ -75,22 +74,6 @@ public class SettingsActivity extends BaseActivity implements PreferenceFragment
private HeaderFragment headerFragment;
private static SearchPreferenceItem[] searchItems = null;

private static ActionBar actionBar;

public static void backButtonEnabled() {
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}

public static void backButtonDisabled() {
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
}
}

@Override
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
MenuInflater inflater = getMenuInflater();
Expand All @@ -107,8 +90,6 @@ protected void onCreate(Bundle savedInstanceState) {

createNotificationChannel();
fragmentManager = getSupportFragmentManager();
setSupportActionBar(binding.header.toolbar);
actionBar = getSupportActionBar();
initSearchableItems();

PreferenceHelper.init(ExtendedSharedPreferences.from(getDefaultSharedPreferences(createDeviceProtectedStorageContext())));
Expand All @@ -117,8 +98,6 @@ protected void onCreate(Bundle savedInstanceState) {

if (savedInstanceState == null) {
replaceFragment(new HeaderFragment());
} else {
setHeader(this, savedInstanceState.getCharSequence(TITLE_TAG));
}

if (getIntent() != null && getIntent().getBooleanExtra("updateTapped", false)) {
Expand All @@ -142,8 +121,7 @@ protected void onCreate(Bundle savedInstanceState) {

setupBottomNavigationView();

if (!isLikelyPixelBuild() && !BuildConfig.DEBUG)
{
if (!isLikelyPixelBuild() && !BuildConfig.DEBUG) {
new MaterialAlertDialogBuilder(this, R.style.MaterialComponents_MaterialAlertDialog)
.setTitle(R.string.incompatible_alert_title)
.setMessage(R.string.incompatible_alert_body)
Expand Down Expand Up @@ -185,23 +163,15 @@ private void setupBottomNavigationView() {
if (Objects.equals(tag, HeaderFragment.class.getSimpleName())) {
selectedFragment = R.id.navigation_home;
binding.bottomNavigationView.getMenu().getItem(0).setChecked(true);
setHeader(this, getString(R.string.app_name));
backButtonDisabled();
} else if (Objects.equals(tag, UpdateFragment.class.getSimpleName())) {
selectedFragment = R.id.navigation_update;
binding.bottomNavigationView.getMenu().getItem(1).setChecked(true);
setHeader(this, getString(R.string.menu_updates));
backButtonEnabled();
} else if (Objects.equals(tag, HooksFragment.class.getSimpleName())) {
selectedFragment = R.id.navigation_hooks;
binding.bottomNavigationView.getMenu().getItem(2).setChecked(true);
setHeader(this, getString(R.string.hooked_packages_title));
backButtonEnabled();
} else if (Objects.equals(tag, OwnPrefsFragment.class.getSimpleName())) {
selectedFragment = R.id.navigation_settings;
binding.bottomNavigationView.getMenu().getItem(3).setChecked(true);
setHeader(this, getString(R.string.own_prefs_header));
backButtonEnabled();
}
});

Expand Down Expand Up @@ -326,16 +296,6 @@ private void createNotificationChannel() {
notificationManager.createNotificationChannel(channel);
}

@Override
protected void onResume() {
super.onResume();
if (Objects.equals(getTopFragment(), HeaderFragment.class.getSimpleName())) {
backButtonDisabled();
} else {
backButtonEnabled();
}
}

@Override
public boolean onSupportNavigateUp() {
if (getSupportFragmentManager().popBackStackImmediate()) {
Expand All @@ -353,8 +313,6 @@ public boolean onPreferenceStartFragment(@NonNull PreferenceFragmentCompat calle
fragment.setTargetFragment(caller, 0);
// Replace the existing Fragment with the new Fragment
replaceFragment(fragment);
setHeader(this, pref.getTitle());
backButtonEnabled();
return true;
}

Expand Down Expand Up @@ -418,6 +376,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
public static class HeaderFragment extends ControlledPreferenceFragmentCompat {
SearchPreference searchPreference;

@Override
public boolean isBackButtonEnabled() {
return false;
}

@Override
public String getTitle() {
return getString(R.string.app_name);
Expand All @@ -428,6 +391,11 @@ public int getLayoutResource() {
return R.xml.header_preferences;
}

@Override
protected int getDefaultThemeResource() {
return R.style.PrefsThemeCollapsingToolbar;
}

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
Expand Down Expand Up @@ -463,12 +431,6 @@ private void onSearchResultClicked(SearchPreferenceResult result) {
}
}
}

@Override
public void onResume() {
super.onResume();
backButtonDisabled();
}
}

private static void replaceFragment(Fragment fragment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

@SuppressLint("CustomSplashScreen")
public class SplashScreenActivity extends AppCompatActivity {
/** @noinspection unused*/
/**
* @noinspection unused
*/
String TAG = getClass().getSimpleName();
private ActivitySplashScreenBinding mBinding;
private final CountDownLatch mRootCheckPassed = new CountDownLatch(1);
Expand All @@ -33,9 +35,6 @@ protected void onCreate(Bundle savedInstanceState) {
mBinding = ActivitySplashScreenBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());

if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getColorFromAttribute(this, R.attr.colorSurface));

Expand All @@ -44,7 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (PixelXpert.get().hasRootAccess()) {
mRootCheckPassed.countDown();
} else {
if(!getIntent().hasExtra("FromKSU")) {
if (!getIntent().hasExtra("FromKSU")) {
AppUtils.runKSURootActivity(this, true);
}

Expand All @@ -67,8 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
mRootCheckPassed.await();

PixelXpert app = PixelXpert.get();
if(!PixelXpert.get().isCoreRootServiceBound())
{
if (!PixelXpert.get().isCoreRootServiceBound()) {
app.tryConnectRootService();
}

Expand All @@ -93,7 +91,8 @@ protected void onCreate(Bundle savedInstanceState) {
.setPositiveButton(getText(R.string.exit), (dialog, i) -> System.exit(0))
.show());
}
} catch (InterruptedException ignored) {}
} catch (InterruptedException ignored) {
}
}).start();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package sh.siava.pixelxpert.ui.fragments;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;

import sh.siava.pixelxpert.R;

abstract class BaseFragment extends Fragment {

protected boolean isBackButtonEnabled() {
return true;
}

public boolean getBackButtonEnabled() {
return isBackButtonEnabled();
}

public abstract String getTitle();

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

AppCompatActivity baseContext = (AppCompatActivity) getContext();
Toolbar toolbar = view.findViewById(R.id.toolbar);

if (baseContext != null) {
if (toolbar != null) {
baseContext.setSupportActionBar(toolbar);
toolbar.setTitle(getTitle());
}
if (baseContext.getSupportActionBar() != null) {
baseContext.getSupportActionBar().setDisplayHomeAsUpEnabled(getBackButtonEnabled());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.os.CountDownTimer;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
Expand All @@ -34,7 +35,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ipc.RootService;
Expand All @@ -52,21 +52,30 @@
import sh.siava.pixelxpert.service.RootProvider;
import sh.siava.pixelxpert.utils.AppUtils;

public class HooksFragment extends Fragment {
public class HooksFragment extends BaseFragment {

private FragmentHooksBinding binding;
/** @noinspection unused*/
/**
* @noinspection unused
*/
private final String TAG = getClass().getSimpleName();
IntentFilter intentFilterHookedPackages = new IntentFilter();
private final List<String> hookedPackageList = new ArrayList<>();
private List<String> monitorPackageList;
private int dotCount = 0;
/** @noinspection FieldCanBeLocal*/
/**
* @noinspection FieldCanBeLocal
*/
private ServiceConnection mCoreRootServiceConnection;
private IRootProviderService mRootServiceIPC = null;
private boolean rebootPending = false;
private final String reboot_key = "reboot_pending";

@Override
public String getTitle() {
return getString(R.string.hooked_packages_title);
}

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentHooksBinding.inflate(inflater, container, false);
Expand Down Expand Up @@ -193,12 +202,16 @@ private void initListItem(List<String> pack) {

for (int i = 0; i < pack.size(); i++) {
View list = LayoutInflater.from(requireContext()).inflate(R.layout.view_hooked_package_list, binding.content, false);
int margin = getResources().getDimensionPixelSize(R.dimen.ui_container_margin_side);

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) list.getLayoutParams();
if (i == 0) {
params.setMargins(margin, dp2px(requireContext(), 12), margin, dp2px(requireContext(), 6));
list.setBackgroundResource(R.drawable.container_top);
params.topMargin = dp2px(requireContext(), 16);
} else if (i == pack.size() - 1) {
params.setMargins(margin, dp2px(requireContext(), 6), margin, dp2px(requireContext(), 12));
list.setBackgroundResource(R.drawable.container_bottom);
params.bottomMargin = dp2px(requireContext(), 16);
} else {
list.setBackgroundResource(R.drawable.container_mid);
}

TextView title = list.findViewById(R.id.title);
Expand Down Expand Up @@ -233,7 +246,7 @@ private void initListItem(List<String> pack) {
} catch (RemoteException e) {
Toast.makeText(requireContext(), getText(R.string.package_activation_failed), Toast.LENGTH_SHORT).show();
activateInLSPosed.setEnabled(true);
e.printStackTrace();
Log.e(TAG, e.toString());
}
});

Expand Down
Loading

0 comments on commit e7f0506

Please sign in to comment.