Make module layout more compact

This commit is contained in:
Fox2Code 2022-06-03 16:13:13 +02:00
parent d0e4b9994a
commit 039480ebb0
2 changed files with 31 additions and 25 deletions

View File

@ -22,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.fox2code.mmm.MainApplication; import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.NotificationType; import com.fox2code.mmm.NotificationType;
import com.fox2code.mmm.R; import com.fox2code.mmm.R;
import com.fox2code.mmm.compat.CompatDisplay;
import com.fox2code.mmm.manager.LocalModuleInfo; import com.fox2code.mmm.manager.LocalModuleInfo;
import com.fox2code.mmm.manager.ModuleInfo; import com.fox2code.mmm.manager.ModuleInfo;
import com.fox2code.mmm.manager.ModuleManager; import com.fox2code.mmm.manager.ModuleManager;
@ -75,14 +76,13 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
private final TextView creditText; private final TextView creditText;
private final TextView descriptionText; private final TextView descriptionText;
private final HorizontalScrollView moduleOptionsHolder; private final HorizontalScrollView moduleOptionsHolder;
private final TextView moduleLayoutHelper;
private final TextView updateText; private final TextView updateText;
private final Chip[] actionsButtons; private final Chip[] actionsButtons;
private final ArrayList<ActionButtonType> actionButtonsTypes; private final ArrayList<ActionButtonType> actionButtonsTypes;
private boolean initState; private boolean initState;
public ModuleHolder moduleHolder; public ModuleHolder moduleHolder;
public Drawable background; public Drawable background;
private boolean canExpand;
private boolean expanded;
public ViewHolder(@NonNull View itemView) { public ViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
@ -95,6 +95,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
this.creditText = itemView.findViewById(R.id.credit_text); this.creditText = itemView.findViewById(R.id.credit_text);
this.descriptionText = itemView.findViewById(R.id.description_text); this.descriptionText = itemView.findViewById(R.id.description_text);
this.moduleOptionsHolder = itemView.findViewById(R.id.module_options_holder); this.moduleOptionsHolder = itemView.findViewById(R.id.module_options_holder);
this.moduleLayoutHelper = itemView.findViewById(R.id.module_layout_helper);
this.updateText = itemView.findViewById(R.id.updated_text); this.updateText = itemView.findViewById(R.id.updated_text);
this.actionsButtons = new Chip[6]; this.actionsButtons = new Chip[6];
this.actionsButtons[0] = itemView.findViewById(R.id.button_action1); this.actionsButtons[0] = itemView.findViewById(R.id.button_action1);
@ -114,11 +115,6 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
} else if (moduleHolder.notificationType != null) { } else if (moduleHolder.notificationType != null) {
onClickListener = moduleHolder.notificationType.onClickListener; onClickListener = moduleHolder.notificationType.onClickListener;
if (onClickListener != null) onClickListener.onClick(v); if (onClickListener != null) onClickListener.onClick(v);
} else if (this.canExpand) {
this.cardView.setClickable(false);
if (this.expanded) return;
this.expanded = true;
// TODO Animated expand code
} }
} }
}); });
@ -178,17 +174,13 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
this.cardView.setVisibility(View.GONE); this.cardView.setVisibility(View.GONE);
this.moduleHolder = null; this.moduleHolder = null;
this.initState = false; this.initState = false;
this.expanded = false;
return true; return true;
} else if (moduleHolder != this.moduleHolder) {
this.expanded = false;
} }
ModuleHolder.Type type = moduleHolder.getType(); ModuleHolder.Type type = moduleHolder.getType();
ModuleHolder.Type vType = moduleHolder.getCompareType(type); ModuleHolder.Type vType = moduleHolder.getCompareType(type);
this.cardView.setVisibility(View.VISIBLE); this.cardView.setVisibility(View.VISIBLE);
boolean showCaseMode = MainApplication.isShowcaseMode(); boolean showCaseMode = MainApplication.isShowcaseMode();
if (moduleHolder.isModuleHolder()) { if (moduleHolder.isModuleHolder()) {
this.canExpand = false;
this.buttonAction.setVisibility(View.GONE); this.buttonAction.setVisibility(View.GONE);
this.buttonAction.setBackground(null); this.buttonAction.setBackground(null);
LocalModuleInfo localModuleInfo = moduleHolder.moduleInfo; LocalModuleInfo localModuleInfo = moduleHolder.moduleInfo;
@ -201,6 +193,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
} }
this.creditText.setVisibility(View.VISIBLE); this.creditText.setVisibility(View.VISIBLE);
this.moduleOptionsHolder.setVisibility(View.VISIBLE); this.moduleOptionsHolder.setVisibility(View.VISIBLE);
this.moduleLayoutHelper.setVisibility(View.VISIBLE);
this.descriptionText.setVisibility(View.VISIBLE); this.descriptionText.setVisibility(View.VISIBLE);
ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo(); ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo();
@ -230,6 +223,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
this.descriptionText.setText(moduleInfo.description); this.descriptionText.setText(moduleInfo.description);
} }
String updateText = moduleHolder.getUpdateTimeText(); String updateText = moduleHolder.getUpdateTimeText();
boolean hasUpdateText = true;
if (!updateText.isEmpty()) { if (!updateText.isEmpty()) {
RepoModule repoModule = moduleHolder.repoModule; RepoModule repoModule = moduleHolder.repoModule;
this.updateText.setVisibility(View.VISIBLE); this.updateText.setVisibility(View.VISIBLE);
@ -247,8 +241,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
this.updateText.setText(R.string.substratum_builtin_module); this.updateText.setText(R.string.substratum_builtin_module);
} else { } else {
this.updateText.setVisibility(View.GONE); this.updateText.setVisibility(View.GONE);
this.canExpand = false; hasUpdateText = false;
this.expanded = true;
} }
this.actionButtonsTypes.clear(); this.actionButtonsTypes.clear();
moduleHolder.getButtons(itemView.getContext(), this.actionButtonsTypes, showCaseMode); moduleHolder.getButtons(itemView.getContext(), this.actionButtonsTypes, showCaseMode);
@ -271,8 +264,13 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
} }
} }
if (this.actionButtonsTypes.isEmpty()) { if (this.actionButtonsTypes.isEmpty()) {
this.canExpand = false; this.moduleOptionsHolder.setVisibility(View.GONE);
this.expanded = false; this.moduleLayoutHelper.setVisibility(View.GONE);
} else if (this.actionButtonsTypes.size() > 3 || !hasUpdateText) {
this.moduleLayoutHelper.setMinHeight(
this.moduleOptionsHolder.getHeight() - CompatDisplay.dpToPixel(14F));
} else {
this.moduleLayoutHelper.setMinHeight(CompatDisplay.dpToPixel(4F));
} }
this.cardView.setClickable(false); this.cardView.setClickable(false);
if (moduleHolder.isModuleHolder() && if (moduleHolder.isModuleHolder() &&
@ -282,8 +280,6 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
this.titleText.setTypeface(Typeface.DEFAULT); this.titleText.setTypeface(Typeface.DEFAULT);
} }
} else { } else {
this.canExpand = false;
this.expanded = false;
if (type == ModuleHolder.Type.SEPARATOR && moduleHolder.filterLevel != 0) { if (type == ModuleHolder.Type.SEPARATOR && moduleHolder.filterLevel != 0) {
this.buttonAction.setVisibility(View.VISIBLE); this.buttonAction.setVisibility(View.VISIBLE);
this.buttonAction.setImageResource(moduleHolder.filterLevel); this.buttonAction.setImageResource(moduleHolder.filterLevel);
@ -297,6 +293,7 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
this.switchMaterial.setVisibility(View.GONE); this.switchMaterial.setVisibility(View.GONE);
this.creditText.setVisibility(View.GONE); this.creditText.setVisibility(View.GONE);
this.moduleOptionsHolder.setVisibility(View.GONE); this.moduleOptionsHolder.setVisibility(View.GONE);
this.moduleLayoutHelper.setVisibility(View.GONE);
this.descriptionText.setVisibility(View.GONE); this.descriptionText.setVisibility(View.GONE);
this.updateText.setVisibility(View.GONE); this.updateText.setVisibility(View.GONE);
this.titleText.setText(" "); this.titleText.setText(" ");
@ -384,11 +381,6 @@ public final class ModuleViewAdapter extends RecyclerView.Adapter<ModuleViewAdap
} else { } else {
this.titleText.setMinHeight(0); this.titleText.setMinHeight(0);
} }
if (this.expanded) {
// TODO Static expand code
} else {
// TODO Static retract code
}
this.moduleHolder = moduleHolder; this.moduleHolder = moduleHolder;
this.initState = false; this.initState = false;
return false; return false;

View File

@ -18,12 +18,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="?attr/materialCardViewFilledStyle"> style="?attr/materialCardViewFilledStyle">
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/main_card_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
@ -113,14 +115,26 @@
</LinearLayout> </LinearLayout>
<TextView
app:layout_constraintTop_toBottomOf="@id/main_card_text"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/module_layout_helper"
android:orientation="vertical">
</TextView>
<!-- Buttons --> <!-- Buttons -->
<HorizontalScrollView <HorizontalScrollView
app:layout_constraintBottom_toBottomOf="@id/module_layout_helper"
android:visibility="gone" android:visibility="gone"
android:id="@+id/module_options_holder" android:id="@+id/module_options_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:scrollbars="none">
<com.google.android.material.chip.ChipGroup <com.google.android.material.chip.ChipGroup
android:animateLayoutChanges="true"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
@ -178,7 +192,7 @@
app:chipIcon="@drawable/ic_baseline_error_24" /> app:chipIcon="@drawable/ic_baseline_error_24" />
</com.google.android.material.chip.ChipGroup> </com.google.android.material.chip.ChipGroup>
</HorizontalScrollView> </HorizontalScrollView>
</LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>