Skip to content

Commit 649c126

Browse files
committed
chore: Update and improve layouts
1 parent 573ed24 commit 649c126

File tree

17 files changed

+194
-97
lines changed

17 files changed

+194
-97
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ buildscript {
1515
ext.fragmentVersion = '1.8.9'
1616
ext.lifecycleVersion = '2.9.2'
1717
ext.loaderVersion = '1.1.0'
18-
ext.materialVersion = '1.14.0-alpha05'
18+
ext.materialVersion = '1.14.0-alpha08'
1919
ext.mediarouterVersion = '1.8.1'
2020
ext.multidexVersion = '2.0.1'
2121
ext.navigationVersion = '2.9.3'

play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractSelfCheckFragment.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import androidx.annotation.Nullable;
3232
import androidx.fragment.app.Fragment;
3333

34+
import com.google.android.material.card.MaterialCardView;
3435
import com.google.android.material.chip.Chip;
3536
import com.google.android.material.chip.ChipGroup;
37+
import com.google.android.material.color.MaterialColors;
3638
import com.google.android.material.transition.MaterialSharedAxis;
3739

3840
import org.microg.tools.selfcheck.SelfCheckGroup;
@@ -49,6 +51,10 @@
4951

5052
public abstract class AbstractSelfCheckFragment extends Fragment {
5153
private ViewGroup root;
54+
private ImageView statusShape;
55+
private MaterialCardView statusCard;
56+
private boolean hasFailures = false;
57+
5258
protected ActivityResultLauncher<Intent> resolutionLauncher;
5359
protected ActivityResultLauncher<String[]> permissionsLauncher;
5460

@@ -81,8 +87,11 @@ public void launchIntent(Intent intent) {
8187
@Nullable
8288
@Override
8389
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
84-
View scrollRoot = inflater.inflate(org.microg.tools.ui.R.layout.self_check, container, false);
85-
root = scrollRoot.findViewById(org.microg.tools.ui.R.id.self_check_root);
90+
View scrollRoot = inflater.inflate(R.layout.self_check, container, false);
91+
root = scrollRoot.findViewById(R.id.self_check_root);
92+
statusShape = scrollRoot.findViewById(R.id.self_check_status_shape);
93+
statusCard = scrollRoot.findViewById(R.id.self_check_status_card);
94+
8695
reset(inflater);
8796
return scrollRoot;
8897
}
@@ -91,18 +100,34 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
91100

92101
protected void reset(LayoutInflater inflater) {
93102
if (root == null) return;
103+
104+
hasFailures = false;
105+
updateStatusHeader();
106+
94107
List<SelfCheckGroup> selfCheckGroupList = new ArrayList<>();
95108
prepareSelfCheckList(selfCheckGroupList);
96109
root.removeAllViews();
97110
for (SelfCheckGroup group : selfCheckGroupList) {
98-
View groupView = inflater.inflate(org.microg.tools.ui.R.layout.self_check_group, root, false);
111+
View groupView = inflater.inflate(R.layout.self_check_group, root, false);
99112
((TextView) groupView.findViewById(android.R.id.title)).setText(group.getGroupName(getContext()));
100-
final ViewGroup viewGroup = groupView.findViewById(org.microg.tools.ui.R.id.group_content);
113+
114+
ViewGroup viewGroup = groupView.findViewById(R.id.group_content);
101115
group.doChecks(getContext(), new GroupResultCollector(viewGroup));
102116
root.addView(groupView);
103117
}
104118
}
105119

120+
private void updateStatusHeader() {
121+
if (statusShape == null || statusCard == null) return;
122+
123+
statusShape.setImageResource(hasFailures ? R.drawable.ic_negative : R.drawable.ic_positive);
124+
125+
int cardColorAttr = hasFailures ? R.attr.colorErrorContainer : R.attr.colorPrimaryContainer;
126+
127+
int cardColor = MaterialColors.getColor(statusCard, cardColorAttr);
128+
statusCard.setCardBackgroundColor(cardColor);
129+
}
130+
106131
private class GroupResultCollector implements SelfCheckGroup.ResultCollector {
107132
private final ViewGroup viewGroup;
108133

@@ -123,12 +148,18 @@ public void addResult(String name, SelfCheckGroup.Result result, String resoluti
123148
@Override
124149
public void addResult(String name, SelfCheckGroup.Result result, String resolution, boolean showIcon, List<ChipInfo> chips, SelfCheckGroup.CheckResolver resolver) {
125150
if (getActivity() == null || getContext() == null) return;
151+
152+
if (result == Negative && showIcon) {
153+
hasFailures = true;
154+
}
155+
126156
getActivity().runOnUiThread(() -> {
127-
View entry = LayoutInflater.from(getContext()).inflate(org.microg.tools.ui.R.layout.self_check_entry, viewGroup, false);
128-
TextView nameView = entry.findViewById(org.microg.tools.ui.R.id.self_check_name);
129-
TextView resView = entry.findViewById(org.microg.tools.ui.R.id.self_check_resolution);
130-
ImageView resultIcon = entry.findViewById(org.microg.tools.ui.R.id.self_check_result_icon);
131-
ChipGroup chipGroup = entry.findViewById(org.microg.tools.ui.R.id.self_check_chip_group);
157+
View entry = LayoutInflater.from(getContext()).inflate(R.layout.self_check_entry, viewGroup, false);
158+
159+
TextView nameView = entry.findViewById(R.id.self_check_name);
160+
TextView resView = entry.findViewById(R.id.self_check_resolution);
161+
ImageView resultIcon = entry.findViewById(R.id.self_check_result_icon);
162+
ChipGroup chipGroup = entry.findViewById(R.id.self_check_chip_group);
132163

133164
nameView.setText(name);
134165

@@ -160,7 +191,7 @@ public void addResult(String name, SelfCheckGroup.Result result, String resoluti
160191
chipGroup.setVisibility(VISIBLE);
161192
chipGroup.removeAllViews();
162193
for (ChipInfo info : chips) {
163-
Chip chip = (Chip) LayoutInflater.from(getContext()).inflate(org.microg.tools.ui.R.layout.self_check_chip, chipGroup, false);
194+
Chip chip = (Chip) LayoutInflater.from(getContext()).inflate(R.layout.self_check_chip, chipGroup, false);
164195
chip.setText(info.label);
165196
if (info.icon != null) {
166197
chip.setChipIcon(info.icon);
@@ -175,6 +206,7 @@ public void addResult(String name, SelfCheckGroup.Result result, String resoluti
175206

176207
viewGroup.addView(entry);
177208
updateSegmentedStyle();
209+
updateStatusHeader();
178210
});
179211
}
180212

play-services-core/microg-ui-tools/src/main/res/drawable/ic_deny.xml renamed to play-services-core/microg-ui-tools/src/main/res/drawable/ic_negative.xml

File renamed without changes.

play-services-core/microg-ui-tools/src/main/res/drawable/ic_allow.xml renamed to play-services-core/microg-ui-tools/src/main/res/drawable/ic_positive.xml

File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<selector xmlns:android="http://schemas.android.com/apk/res/android">
2-
<item android:drawable="@drawable/ic_allow" android:state_activated="true" />
3-
<item android:drawable="@drawable/ic_deny" />
2+
<item android:drawable="@drawable/ic_positive" android:state_activated="true" />
3+
<item android:drawable="@drawable/ic_negative" />
44
</selector>

play-services-core/microg-ui-tools/src/main/res/layout/library_item.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
xmlns:app="http://schemas.android.com/apk/res-auto"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:id="@+id/list_item_library"
5-
style="?attr/listItemLayoutSegmentedStyle"
65
android:layout_width="match_parent"
76
android:layout_height="wrap_content"
8-
android:layout_marginBottom="2dp"
9-
android:background="@android:color/transparent">
7+
android:layout_marginBottom="2dp">
108

11-
<com.google.android.material.card.MaterialCardView
9+
<com.google.android.material.listitem.ListItemCardView
1210
android:layout_width="match_parent"
1311
android:layout_height="wrap_content"
14-
android:checkable="false"
1512
app:cardBackgroundColor="?attr/colorSurfaceContainer">
1613

1714
<androidx.constraintlayout.widget.ConstraintLayout
1815
android:layout_width="match_parent"
1916
android:layout_height="wrap_content"
20-
android:padding="16dp">
17+
android:layout_marginTop="6dp"
18+
android:layout_marginBottom="6dp">
2119

2220
<com.google.android.material.imageview.ShapeableImageView
2321
android:id="@+id/icon"
@@ -58,5 +56,5 @@
5856
app:layout_constraintTop_toBottomOf="@android:id/text1"
5957
tools:text="Apache License 2.0, The Android Open Source Project." />
6058
</androidx.constraintlayout.widget.ConstraintLayout>
61-
</com.google.android.material.card.MaterialCardView>
59+
</com.google.android.material.listitem.ListItemCardView>
6260
</com.google.android.material.listitem.ListItemLayout>

play-services-core/microg-ui-tools/src/main/res/layout/self_check.xml

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,49 @@
1515
-->
1616

1717
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
xmlns:tools="http://schemas.android.com/tools"
1820
android:layout_width="match_parent"
19-
android:layout_height="match_parent"
20-
android:layout_marginStart="?attr/listPreferredItemPaddingStart"
21-
android:layout_marginEnd="?attr/listPreferredItemPaddingEnd">
21+
android:layout_height="match_parent">
2222

2323
<androidx.appcompat.widget.LinearLayoutCompat
24-
android:id="@+id/self_check_root"
25-
android:layout_width="fill_parent"
26-
android:layout_height="fill_parent"
27-
android:orientation="vertical" />
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:layout_marginStart="?attr/listPreferredItemPaddingStart"
27+
android:layout_marginEnd="?attr/listPreferredItemPaddingEnd"
28+
android:orientation="vertical">
29+
30+
<com.google.android.material.card.MaterialCardView
31+
android:id="@+id/self_check_status_card"
32+
style="?attr/materialCardViewFilledStyle"
33+
android:layout_width="fill_parent"
34+
android:layout_height="wrap_content"
35+
android:layout_gravity="center"
36+
app:cardBackgroundColor="?attr/colorSurfaceContainer"
37+
app:cardCornerRadius="20dp"
38+
app:cardElevation="0dp">
39+
40+
<FrameLayout
41+
android:layout_width="fill_parent"
42+
android:layout_height="wrap_content"
43+
android:padding="24dp">
44+
45+
<com.google.android.material.imageview.ShapeableImageView
46+
android:id="@+id/self_check_status_shape"
47+
android:layout_width="120dp"
48+
android:layout_height="120dp"
49+
android:layout_gravity="center"
50+
android:importantForAccessibility="no"
51+
android:scaleType="fitCenter"
52+
tools:src="@drawable/ic_self_check_result" />
53+
54+
</FrameLayout>
55+
</com.google.android.material.card.MaterialCardView>
56+
57+
<androidx.appcompat.widget.LinearLayoutCompat
58+
android:id="@+id/self_check_root"
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content"
61+
android:orientation="vertical" />
62+
</androidx.appcompat.widget.LinearLayoutCompat>
2863
</androidx.core.widget.NestedScrollView>

play-services-core/microg-ui-tools/src/main/res/layout/self_check_entry.xml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
xmlns:app="http://schemas.android.com/apk/res-auto"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:id="@+id/list_item_check"
5-
style="?attr/listItemLayoutSegmentedStyle"
65
android:layout_width="match_parent"
76
android:layout_height="wrap_content"
8-
android:layout_marginBottom="2dp"
9-
android:background="@android:color/transparent">
7+
android:layout_marginBottom="2dp">
108

11-
<com.google.android.material.card.MaterialCardView
9+
<com.google.android.material.listitem.ListItemCardView
1210
android:id="@+id/material_card_view"
1311
android:layout_width="match_parent"
1412
android:layout_height="wrap_content"
@@ -17,9 +15,8 @@
1715
<androidx.constraintlayout.widget.ConstraintLayout
1816
android:layout_width="match_parent"
1917
android:layout_height="wrap_content"
20-
android:paddingVertical="16dp"
21-
android:paddingStart="?attr/listPreferredItemPaddingStart"
22-
android:paddingEnd="?attr/listPreferredItemPaddingEnd">
18+
android:layout_marginTop="6dp"
19+
android:layout_marginBottom="6dp">
2320

2421
<com.google.android.material.textview.MaterialTextView
2522
android:id="@+id/self_check_name"
@@ -55,7 +52,6 @@
5552
android:layout_height="wrap_content"
5653
android:layout_marginTop="8dp"
5754
android:visibility="gone"
58-
app:chipSpacingVertical="4dp"
5955
app:layout_constraintBottom_toBottomOf="parent"
6056
app:layout_constraintEnd_toEndOf="@id/self_check_name"
6157
app:layout_constraintStart_toStartOf="@id/self_check_name"
@@ -72,5 +68,5 @@
7268
app:layout_constraintEnd_toEndOf="parent"
7369
app:layout_constraintTop_toTopOf="parent" />
7470
</androidx.constraintlayout.widget.ConstraintLayout>
75-
</com.google.android.material.card.MaterialCardView>
71+
</com.google.android.material.listitem.ListItemCardView>
7672
</com.google.android.material.listitem.ListItemLayout>

play-services-core/src/main/java/org/microg/gms/ui/AccountsFragment.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import android.accounts.AccountManager
55
import android.content.ActivityNotFoundException
66
import android.content.Intent
77
import android.graphics.Bitmap
8+
import android.graphics.drawable.Drawable
89
import android.os.Bundle
910
import android.provider.Settings
1011
import android.util.Log
1112
import android.view.LayoutInflater
1213
import android.view.View
14+
import androidx.appcompat.content.res.AppCompatResources
1315
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
1416
import androidx.core.net.toUri
1517
import androidx.lifecycle.lifecycleScope
@@ -78,7 +80,8 @@ class AccountsFragment : PreferenceFragmentCompat() {
7880
private fun setupPreferenceListeners() {
7981
findPreference<Preference>("pref_manage_accounts")?.setOnPreferenceClickListener {
8082
startActivitySafelyIntent(
81-
Intent(Settings.ACTION_SYNC_SETTINGS), "Failed to launch sync in device settings"
83+
Intent(Settings.ACTION_SYNC_SETTINGS),
84+
"Failed to launch account sync in device settings"
8285
)
8386
true
8487
}
@@ -105,8 +108,10 @@ class AccountsFragment : PreferenceFragmentCompat() {
105108
}
106109
}
107110

108-
private fun startActivitySafely(activityClass: Class<*>, errorMessage: String) {
109-
startActivitySafelyIntent(Intent(requireContext(), activityClass), errorMessage)
111+
private fun startActivitySafely(activityClass: Class<*>) {
112+
startActivitySafelyIntent(
113+
Intent(requireContext(), activityClass), "Failed to launch login activity"
114+
)
110115
}
111116

112117
private fun openUrl(url: String) {
@@ -120,7 +125,7 @@ class AccountsFragment : PreferenceFragmentCompat() {
120125
fab.text = getString(R.string.auth_add_account)
121126
fab.setIconResource(R.drawable.ic_add)
122127
fab.setOnClickListener {
123-
startActivitySafely(LoginActivity::class.java, "Failed to launch login activity")
128+
startActivitySafely(LoginActivity::class.java)
124129
}
125130
}
126131

@@ -289,8 +294,16 @@ class AccountsFragment : PreferenceFragmentCompat() {
289294
}
290295
}
291296

292-
private fun getCircleBitmapDrawable(bitmap: Bitmap?) = bitmap?.let {
293-
RoundedBitmapDrawableFactory.create(resources, it).apply { isCircular = true }
297+
private fun getCircleBitmapDrawable(bitmap: Bitmap?): Drawable {
298+
return if (bitmap != null) {
299+
RoundedBitmapDrawableFactory.create(resources, bitmap).apply {
300+
isCircular = true
301+
}
302+
} else {
303+
AppCompatResources.getDrawable(
304+
requireContext(), R.drawable.ic_account_avatar
305+
)!!
306+
}
294307
}
295308

296309
private fun showSnackbar(message: String) {

0 commit comments

Comments
 (0)