mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-06-05 21:49:48 +02:00
Xiaomi: Display widget id when names are repeated
This commit is contained in:
@@ -29,6 +29,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -90,6 +91,9 @@ public class XiaomiWidgetManager implements WidgetManager {
|
|||||||
|
|
||||||
final XiaomiProto.WidgetParts rawWidgetParts = getRawWidgetParts();
|
final XiaomiProto.WidgetParts rawWidgetParts = getRawWidgetParts();
|
||||||
|
|
||||||
|
final Set<String> seenNames = new HashSet<>();
|
||||||
|
final Set<String> duplicatedNames = new HashSet<>();
|
||||||
|
|
||||||
for (final XiaomiProto.WidgetPart widgetPart : rawWidgetParts.getWidgetPartList()) {
|
for (final XiaomiProto.WidgetPart widgetPart : rawWidgetParts.getWidgetPartList()) {
|
||||||
final WidgetType type = fromRawWidgetType(widgetPart.getType());
|
final WidgetType type = fromRawWidgetType(widgetPart.getType());
|
||||||
|
|
||||||
@@ -118,10 +122,23 @@ public class XiaomiWidgetManager implements WidgetManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (seenNames.contains(newPart.getFullName())) {
|
||||||
|
duplicatedNames.add(newPart.getFullName());
|
||||||
|
} else {
|
||||||
|
seenNames.add(newPart.getFullName());
|
||||||
|
}
|
||||||
|
|
||||||
parts.add(newPart);
|
parts.add(newPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that all names are unique
|
||||||
|
for (final WidgetPart part : parts) {
|
||||||
|
if (duplicatedNames.contains(part.getFullName())) {
|
||||||
|
part.setName(String.format(Locale.ROOT, "%s (%s)", part.getName(), part.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -833,6 +833,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setWidgets() {
|
private void setWidgets() {
|
||||||
|
// Just take the persisted protobuf and send it (see above and XiaomiWidgetManager)
|
||||||
final String hex = getDevicePrefs().getString(XiaomiPreferences.PREF_WIDGET_SCREENS, null);
|
final String hex = getDevicePrefs().getString(XiaomiPreferences.PREF_WIDGET_SCREENS, null);
|
||||||
if (hex == null) {
|
if (hex == null) {
|
||||||
LOG.warn("raw widget screens hex is null");
|
LOG.warn("raw widget screens hex is null");
|
||||||
|
@@ -41,7 +41,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:text="2x1"
|
android:text="2x1"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/label_layout" />
|
app:layout_constraintTop_toBottomOf="@id/label_layout" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:text="TOP LEFT"
|
android:text="TOP LEFT"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/label_widget_top_left" />
|
app:layout_constraintTop_toBottomOf="@id/label_widget_top_left" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -119,7 +119,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:text="TOP RIGHT"
|
android:text="TOP RIGHT"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/label_widget_top_right" />
|
app:layout_constraintTop_toBottomOf="@id/label_widget_top_right" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -158,7 +158,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:text="CENTER"
|
android:text="CENTER"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/label_widget_center" />
|
app:layout_constraintTop_toBottomOf="@id/label_widget_center" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -197,7 +197,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:text="BOT LEFT"
|
android:text="BOT LEFT"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/label_widget_bottom_left" />
|
app:layout_constraintTop_toBottomOf="@id/label_widget_bottom_left" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -236,7 +236,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:text="BOT RIGHT"
|
android:text="BOT RIGHT"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/label_widget_bottom_right" />
|
app:layout_constraintTop_toBottomOf="@id/label_widget_bottom_right" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
Reference in New Issue
Block a user