Skip to content

Commit

Permalink
[Refactor] Use outlines for color codes
Browse files Browse the repository at this point in the history
Signed-off-by: Muntashir Al-Islam <[email protected]>
  • Loading branch information
MuntashirAkon committed Mar 26, 2024
1 parent d8ba865 commit c527baa
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.google.android.material.card.MaterialCardView;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.divider.MaterialDivider;
import com.google.android.material.textview.MaterialTextView;

import java.util.Collections;
Expand All @@ -36,8 +35,6 @@ public class DebloaterRecyclerViewAdapter extends MultiSelectionView.Adapter<Deb

private final FragmentActivity mActivity;
@ColorInt
private final int mHighlightColor;
@ColorInt
private final int mRemovalSafeColor;
@ColorInt
private final int mRemovalReplaceColor;
Expand All @@ -53,7 +50,6 @@ public class DebloaterRecyclerViewAdapter extends MultiSelectionView.Adapter<Deb

public DebloaterRecyclerViewAdapter(DebloaterActivity activity) {
mActivity = activity;
mHighlightColor = ColorCodes.getListItemSelectionColor(activity);
mRemovalSafeColor = ColorCodes.getRemovalSafeIndicatorColor(activity);
mRemovalReplaceColor = ColorCodes.getRemovalReplaceIndicatorColor(activity);
mRemovalCautionColor = ColorCodes.getRemovalCautionIndicatorColor(activity);
Expand All @@ -71,11 +67,6 @@ public void setAdapterList(List<DebloatObject> adapterList) {
}
}

@Override
public int getHighlightColor() {
return mHighlightColor;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Expand Down Expand Up @@ -120,7 +111,7 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.listTypeView.setText(debloatObject.type);
holder.packageNameView.setText(debloatObject.packageName);
holder.descriptionView.setText(sb);
holder.removalIndicator.setDividerColor(removalColor);
holder.itemView.setStrokeColor(removalColor);
holder.labelView.setText(label);
holder.itemView.setOnLongClickListener(v -> {
toggleSelection(position);
Expand All @@ -135,7 +126,6 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
dialog.show(mActivity.getSupportFragmentManager(), BloatwareDetailsDialog.TAG);
}
});
holder.itemView.setCardBackgroundColor(mColorSurface);
super.onBindViewHolder(holder, position);
}

Expand Down Expand Up @@ -192,7 +182,6 @@ protected int getTotalItemCount() {

public static class ViewHolder extends MultiSelectionView.ViewHolder {
public final MaterialCardView itemView;
public final MaterialDivider removalIndicator;
public final AppCompatImageView iconView;
public final MaterialTextView listTypeView;
public final MaterialTextView labelView;
Expand All @@ -202,7 +191,6 @@ public static class ViewHolder extends MultiSelectionView.ViewHolder {
public ViewHolder(@NonNull View itemView) {
super(itemView);
this.itemView = (MaterialCardView) itemView;
removalIndicator = itemView.findViewById(R.id.divider);
iconView = itemView.findViewById(R.id.icon);
listTypeView = itemView.findViewById(R.id.list_type);
labelView = itemView.findViewById(R.id.label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.pm.PathPermission;
import android.content.pm.ProviderInfo;
import android.content.pm.ServiceInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.os.PatternMatcher;
import android.os.UserHandleHidden;
Expand All @@ -34,7 +35,6 @@
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.chip.Chip;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.divider.MaterialDivider;
import com.google.android.material.materialswitch.MaterialSwitch;

import java.lang.annotation.Retention;
Expand Down Expand Up @@ -64,12 +64,12 @@
import io.github.muntashirakon.AppManager.settings.Prefs;
import io.github.muntashirakon.AppManager.shortcut.CreateShortcutDialogFragment;
import io.github.muntashirakon.AppManager.types.UserPackagePair;
import io.github.muntashirakon.util.AdapterUtils;
import io.github.muntashirakon.AppManager.utils.ContextUtils;
import io.github.muntashirakon.AppManager.utils.ThreadUtils;
import io.github.muntashirakon.AppManager.utils.UIUtils;
import io.github.muntashirakon.AppManager.utils.Utils;
import io.github.muntashirakon.AppManager.utils.appearance.ColorCodes;
import io.github.muntashirakon.util.AdapterUtils;
import io.github.muntashirakon.view.ProgressIndicatorCompat;
import io.github.muntashirakon.widget.MaterialAlertView;
import io.github.muntashirakon.widget.RecyclerView;
Expand Down Expand Up @@ -312,21 +312,17 @@ private class AppDetailsRecyclerAdapter extends RecyclerView.Adapter<AppDetailsR
private int mUserId;
private boolean mCanModifyComponentStates;
private boolean mCanStartAnyActivity;
private final int mCardColor1;
private final int mBlockedIndicatorColor;
private final int mBlockedExternallyIndicatorColor;
private final int mTrackerIndicatorColor;
private final int mRunningIndicatorColor;
private final int mDefaultIndicatorColor;

AppDetailsRecyclerAdapter() {
mAdapterList = new ArrayList<>();
mCardColor1 = ColorCodes.getListItemColor1(activity);
mBlockedIndicatorColor = ColorCodes.getComponentBlockedIndicatorColor(activity);
mBlockedExternallyIndicatorColor = ColorCodes.getComponentExternallyBlockedIndicatorColor(activity);
mTrackerIndicatorColor = ColorCodes.getComponentTrackerIndicatorColor(activity);
mRunningIndicatorColor = ColorCodes.getComponentRunningIndicatorColor(activity);
mDefaultIndicatorColor = ColorCodes.getListItemDefaultIndicatorColor(activity);
}

@UiThread
Expand Down Expand Up @@ -358,6 +354,7 @@ void setDefaultList(@NonNull List<AppDetailsItem<?>> list) {
* the same holder for any kind of view, and view are not all sames.
*/
class ViewHolder extends RecyclerView.ViewHolder {
MaterialCardView itemView;
TextView labelView;
TextView nameView;
TextView textView1;
Expand All @@ -369,11 +366,11 @@ class ViewHolder extends RecyclerView.ViewHolder {
Button shortcutBtn;
MaterialButton launchBtn;
MaterialSwitch toggleSwitch;
MaterialDivider divider;
Chip chipType;

public ViewHolder(@NonNull View itemView) {
super(itemView);
this.itemView = (MaterialCardView) itemView;
imageView = itemView.findViewById(R.id.icon);
labelView = itemView.findViewById(R.id.label);
nameView = itemView.findViewById(R.id.name);
Expand All @@ -384,8 +381,6 @@ public ViewHolder(@NonNull View itemView) {
chipType = itemView.findViewById(R.id.type);
launchBtn = itemView.findViewById(R.id.launch);

divider = itemView.findViewById(R.id.divider);

if (mRequestedProperty == ACTIVITIES) {
textView1 = itemView.findViewById(R.id.taskAffinity);
textView2 = itemView.findViewById(R.id.launchMode);
Expand All @@ -402,7 +397,6 @@ public ViewHolder(@NonNull View itemView) {
textView2 = itemView.findViewById(R.id.launchMode);
textView3 = itemView.findViewById(R.id.orientation);
textView4 = itemView.findViewById(R.id.softInput);
divider = itemView.findViewById(R.id.divider);
launchBtn.setVisibility(View.GONE);
shortcutBtn.setVisibility(View.GONE);
} else if (mRequestedProperty == PROVIDERS) {
Expand Down Expand Up @@ -500,13 +494,13 @@ private void getActivityView(@NonNull ViewHolder holder, int index) {
final boolean isDisabled = !mIsExternalApk && componentItem.isDisabled();
// Background color: regular < tracker < disabled < blocked
if (!mIsExternalApk && componentItem.isBlocked()) {
holder.divider.setDividerColor(mBlockedIndicatorColor);
holder.itemView.setStrokeColor(mBlockedIndicatorColor);
} else if (isDisabled) {
holder.divider.setDividerColor(mBlockedExternallyIndicatorColor);
holder.itemView.setStrokeColor(mBlockedExternallyIndicatorColor);
} else if (componentItem.isTracker()) {
holder.divider.setDividerColor(mTrackerIndicatorColor);
holder.itemView.setStrokeColor(mTrackerIndicatorColor);
} else {
holder.divider.setDividerColor(mDefaultIndicatorColor);
holder.itemView.setStrokeColor(Color.TRANSPARENT);
}
if (componentItem.isTracker()) {
holder.chipType.setText(R.string.tracker);
Expand Down Expand Up @@ -605,7 +599,6 @@ private void getActivityView(@NonNull ViewHolder holder, int index) {
if (mCanModifyComponentStates) {
handleBlock(holder, componentItem, RuleType.ACTIVITY);
} else holder.toggleSwitch.setVisibility(View.GONE);
((MaterialCardView) holder.itemView).setCardBackgroundColor(mCardColor1);
}

private void getServicesView(@NonNull Context context, @NonNull ViewHolder holder, int index) {
Expand All @@ -617,15 +610,15 @@ private void getServicesView(@NonNull Context context, @NonNull ViewHolder holde
final boolean isDisabled = !mIsExternalApk && serviceItem.isDisabled();
// Background color: regular < tracker < disabled < blocked < running
if (serviceItem.isRunning()) {
holder.divider.setDividerColor(mRunningIndicatorColor);
holder.itemView.setStrokeColor(mRunningIndicatorColor);
} else if (!mIsExternalApk && serviceItem.isBlocked()) {
holder.divider.setDividerColor(mBlockedIndicatorColor);
holder.itemView.setStrokeColor(mBlockedIndicatorColor);
} else if (isDisabled) {
holder.divider.setDividerColor(mBlockedExternallyIndicatorColor);
holder.itemView.setStrokeColor(mBlockedExternallyIndicatorColor);
} else if (serviceItem.isTracker()) {
holder.divider.setDividerColor(mTrackerIndicatorColor);
holder.itemView.setStrokeColor(mTrackerIndicatorColor);
} else {
holder.divider.setDividerColor(mDefaultIndicatorColor);
holder.itemView.setStrokeColor(Color.TRANSPARENT);
}
if (serviceItem.isTracker()) {
holder.chipType.setText(R.string.tracker);
Expand Down Expand Up @@ -678,7 +671,6 @@ private void getServicesView(@NonNull Context context, @NonNull ViewHolder holde
if (mCanModifyComponentStates) {
handleBlock(holder, serviceItem, RuleType.SERVICE);
} else holder.toggleSwitch.setVisibility(View.GONE);
((MaterialCardView) holder.itemView).setCardBackgroundColor(mCardColor1);
}

private void getReceiverView(@NonNull ViewHolder holder, int index) {
Expand All @@ -689,13 +681,13 @@ private void getReceiverView(@NonNull ViewHolder holder, int index) {
final ActivityInfo activityInfo = (ActivityInfo) componentItem.mainItem;
// Background color: regular < tracker < disabled < blocked
if (!mIsExternalApk && componentItem.isBlocked()) {
holder.divider.setDividerColor(mBlockedIndicatorColor);
holder.itemView.setStrokeColor(mBlockedIndicatorColor);
} else if (!mIsExternalApk && componentItem.isDisabled()) {
holder.divider.setDividerColor(mBlockedExternallyIndicatorColor);
holder.itemView.setStrokeColor(mBlockedExternallyIndicatorColor);
} else if (componentItem.isTracker()) {
holder.divider.setDividerColor(mTrackerIndicatorColor);
holder.itemView.setStrokeColor(mTrackerIndicatorColor);
} else {
holder.divider.setDividerColor(mDefaultIndicatorColor);
holder.itemView.setStrokeColor(Color.TRANSPARENT);
}
if (componentItem.isTracker()) {
holder.chipType.setText(R.string.tracker);
Expand Down Expand Up @@ -739,7 +731,6 @@ private void getReceiverView(@NonNull ViewHolder holder, int index) {
if (mCanModifyComponentStates) {
handleBlock(holder, componentItem, RuleType.RECEIVER);
} else holder.toggleSwitch.setVisibility(View.GONE);
((MaterialCardView) holder.itemView).setCardBackgroundColor(mCardColor1);
}

private void getProviderView(@NonNull ViewHolder holder, int index) {
Expand All @@ -751,13 +742,13 @@ private void getProviderView(@NonNull ViewHolder holder, int index) {
final String providerName = providerInfo.name;
// Background color: regular < tracker < disabled < blocked
if (!mIsExternalApk && componentItem.isBlocked()) {
holder.divider.setDividerColor(mBlockedIndicatorColor);
holder.itemView.setStrokeColor(mBlockedIndicatorColor);
} else if (!mIsExternalApk && componentItem.isDisabled()) {
holder.divider.setDividerColor(mBlockedExternallyIndicatorColor);
holder.itemView.setStrokeColor(mBlockedExternallyIndicatorColor);
} else if (componentItem.isTracker()) {
holder.divider.setDividerColor(mTrackerIndicatorColor);
holder.itemView.setStrokeColor(mTrackerIndicatorColor);
} else {
holder.divider.setDividerColor(mDefaultIndicatorColor);
holder.itemView.setStrokeColor(Color.TRANSPARENT);
}
if (componentItem.isTracker()) {
holder.chipType.setText(R.string.tracker);
Expand Down Expand Up @@ -823,7 +814,6 @@ private void getProviderView(@NonNull ViewHolder holder, int index) {
if (mCanModifyComponentStates) {
handleBlock(holder, componentItem, RuleType.PROVIDER);
} else holder.toggleSwitch.setVisibility(View.GONE);
((MaterialCardView) holder.itemView).setCardBackgroundColor(mCardColor1);
}
}
}
Loading

0 comments on commit c527baa

Please sign in to comment.