Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 039480e

Browse files
committed
Make module layout more compact
1 parent d0e4b99 commit 039480e

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fox2code.mmm.MainApplication;
2323
import com.fox2code.mmm.NotificationType;
2424
import com.fox2code.mmm.R;
25+
import com.fox2code.mmm.compat.CompatDisplay;
2526
import com.fox2code.mmm.manager.LocalModuleInfo;
2627
import com.fox2code.mmm.manager.ModuleInfo;
2728
import com.fox2code.mmm.manager.ModuleManager;
@@ -75,14 +76,13 @@ public static class ViewHolder extends RecyclerView.ViewHolder {
7576
private final TextView creditText;
7677
private final TextView descriptionText;
7778
private final HorizontalScrollView moduleOptionsHolder;
79+
private final TextView moduleLayoutHelper;
7880
private final TextView updateText;
7981
private final Chip[] actionsButtons;
8082
private final ArrayList<ActionButtonType> actionButtonsTypes;
8183
private boolean initState;
8284
public ModuleHolder moduleHolder;
8385
public Drawable background;
84-
private boolean canExpand;
85-
private boolean expanded;
8686

8787
public ViewHolder(@NonNull View itemView) {
8888
super(itemView);
@@ -95,6 +95,7 @@ public ViewHolder(@NonNull View itemView) {
9595
this.creditText = itemView.findViewById(R.id.credit_text);
9696
this.descriptionText = itemView.findViewById(R.id.description_text);
9797
this.moduleOptionsHolder = itemView.findViewById(R.id.module_options_holder);
98+
this.moduleLayoutHelper = itemView.findViewById(R.id.module_layout_helper);
9899
this.updateText = itemView.findViewById(R.id.updated_text);
99100
this.actionsButtons = new Chip[6];
100101
this.actionsButtons[0] = itemView.findViewById(R.id.button_action1);
@@ -114,11 +115,6 @@ public ViewHolder(@NonNull View itemView) {
114115
} else if (moduleHolder.notificationType != null) {
115116
onClickListener = moduleHolder.notificationType.onClickListener;
116117
if (onClickListener != null) onClickListener.onClick(v);
117-
} else if (this.canExpand) {
118-
this.cardView.setClickable(false);
119-
if (this.expanded) return;
120-
this.expanded = true;
121-
// TODO Animated expand code
122118
}
123119
}
124120
});
@@ -178,17 +174,13 @@ public boolean update(ModuleHolder moduleHolder) {
178174
this.cardView.setVisibility(View.GONE);
179175
this.moduleHolder = null;
180176
this.initState = false;
181-
this.expanded = false;
182177
return true;
183-
} else if (moduleHolder != this.moduleHolder) {
184-
this.expanded = false;
185178
}
186179
ModuleHolder.Type type = moduleHolder.getType();
187180
ModuleHolder.Type vType = moduleHolder.getCompareType(type);
188181
this.cardView.setVisibility(View.VISIBLE);
189182
boolean showCaseMode = MainApplication.isShowcaseMode();
190183
if (moduleHolder.isModuleHolder()) {
191-
this.canExpand = false;
192184
this.buttonAction.setVisibility(View.GONE);
193185
this.buttonAction.setBackground(null);
194186
LocalModuleInfo localModuleInfo = moduleHolder.moduleInfo;
@@ -201,6 +193,7 @@ public boolean update(ModuleHolder moduleHolder) {
201193
}
202194
this.creditText.setVisibility(View.VISIBLE);
203195
this.moduleOptionsHolder.setVisibility(View.VISIBLE);
196+
this.moduleLayoutHelper.setVisibility(View.VISIBLE);
204197
this.descriptionText.setVisibility(View.VISIBLE);
205198

206199
ModuleInfo moduleInfo = moduleHolder.getMainModuleInfo();
@@ -230,6 +223,7 @@ public boolean update(ModuleHolder moduleHolder) {
230223
this.descriptionText.setText(moduleInfo.description);
231224
}
232225
String updateText = moduleHolder.getUpdateTimeText();
226+
boolean hasUpdateText = true;
233227
if (!updateText.isEmpty()) {
234228
RepoModule repoModule = moduleHolder.repoModule;
235229
this.updateText.setVisibility(View.VISIBLE);
@@ -247,8 +241,7 @@ public boolean update(ModuleHolder moduleHolder) {
247241
this.updateText.setText(R.string.substratum_builtin_module);
248242
} else {
249243
this.updateText.setVisibility(View.GONE);
250-
this.canExpand = false;
251-
this.expanded = true;
244+
hasUpdateText = false;
252245
}
253246
this.actionButtonsTypes.clear();
254247
moduleHolder.getButtons(itemView.getContext(), this.actionButtonsTypes, showCaseMode);
@@ -271,8 +264,13 @@ public boolean update(ModuleHolder moduleHolder) {
271264
}
272265
}
273266
if (this.actionButtonsTypes.isEmpty()) {
274-
this.canExpand = false;
275-
this.expanded = false;
267+
this.moduleOptionsHolder.setVisibility(View.GONE);
268+
this.moduleLayoutHelper.setVisibility(View.GONE);
269+
} else if (this.actionButtonsTypes.size() > 3 || !hasUpdateText) {
270+
this.moduleLayoutHelper.setMinHeight(
271+
this.moduleOptionsHolder.getHeight() - CompatDisplay.dpToPixel(14F));
272+
} else {
273+
this.moduleLayoutHelper.setMinHeight(CompatDisplay.dpToPixel(4F));
276274
}
277275
this.cardView.setClickable(false);
278276
if (moduleHolder.isModuleHolder() &&
@@ -282,8 +280,6 @@ public boolean update(ModuleHolder moduleHolder) {
282280
this.titleText.setTypeface(Typeface.DEFAULT);
283281
}
284282
} else {
285-
this.canExpand = false;
286-
this.expanded = false;
287283
if (type == ModuleHolder.Type.SEPARATOR && moduleHolder.filterLevel != 0) {
288284
this.buttonAction.setVisibility(View.VISIBLE);
289285
this.buttonAction.setImageResource(moduleHolder.filterLevel);
@@ -297,6 +293,7 @@ public boolean update(ModuleHolder moduleHolder) {
297293
this.switchMaterial.setVisibility(View.GONE);
298294
this.creditText.setVisibility(View.GONE);
299295
this.moduleOptionsHolder.setVisibility(View.GONE);
296+
this.moduleLayoutHelper.setVisibility(View.GONE);
300297
this.descriptionText.setVisibility(View.GONE);
301298
this.updateText.setVisibility(View.GONE);
302299
this.titleText.setText(" ");
@@ -384,11 +381,6 @@ public boolean update(ModuleHolder moduleHolder) {
384381
} else {
385382
this.titleText.setMinHeight(0);
386383
}
387-
if (this.expanded) {
388-
// TODO Static expand code
389-
} else {
390-
// TODO Static retract code
391-
}
392384
this.moduleHolder = moduleHolder;
393385
this.initState = false;
394386
return false;

app/src/main/res/layout/module_entry.xml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
android:layout_height="wrap_content"
1919
style="?attr/materialCardViewFilledStyle">
2020

21-
<LinearLayout
21+
<androidx.constraintlayout.widget.ConstraintLayout
2222
android:layout_width="match_parent"
2323
android:layout_height="wrap_content"
2424
android:orientation="vertical">
2525

2626
<LinearLayout
27+
app:layout_constraintTop_toTopOf="parent"
28+
android:id="@+id/main_card_text"
2729
android:layout_width="match_parent"
2830
android:layout_height="wrap_content"
2931
android:orientation="vertical"
@@ -113,14 +115,26 @@
113115

114116
</LinearLayout>
115117

118+
<TextView
119+
app:layout_constraintTop_toBottomOf="@id/main_card_text"
120+
android:visibility="gone"
121+
android:layout_width="match_parent"
122+
android:layout_height="wrap_content"
123+
android:id="@+id/module_layout_helper"
124+
android:orientation="vertical">
125+
126+
</TextView>
116127
<!-- Buttons -->
117128
<HorizontalScrollView
129+
app:layout_constraintBottom_toBottomOf="@id/module_layout_helper"
118130
android:visibility="gone"
119131
android:id="@+id/module_options_holder"
120132
android:layout_width="match_parent"
121-
android:layout_height="wrap_content">
133+
android:layout_height="wrap_content"
134+
android:scrollbars="none">
122135

123136
<com.google.android.material.chip.ChipGroup
137+
android:animateLayoutChanges="true"
124138
android:layout_width="wrap_content"
125139
android:layout_height="wrap_content"
126140
android:layout_gravity="end"
@@ -178,7 +192,7 @@
178192
app:chipIcon="@drawable/ic_baseline_error_24" />
179193
</com.google.android.material.chip.ChipGroup>
180194
</HorizontalScrollView>
181-
</LinearLayout>
195+
</androidx.constraintlayout.widget.ConstraintLayout>
182196

183197
</com.google.android.material.card.MaterialCardView>
184198
</LinearLayout>

0 commit comments

Comments
 (0)