Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material You design changes and widgets update #209

Merged
merged 11 commits into from
Jun 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/bluetooth_label"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
Expand All @@ -20,7 +20,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/bluetooth_description"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
Expand Down
4 changes: 2 additions & 2 deletions app-wear/src/main/res/layout/overview_nomaindevice_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
Expand All @@ -31,7 +31,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
Expand Down
9 changes: 5 additions & 4 deletions app-wear/src/main/res/layout/overview_permission_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/request_description"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
Expand All @@ -20,7 +20,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/permission_label"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.BodyLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
Expand All @@ -32,7 +32,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/permission_description"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
Expand All @@ -44,11 +44,12 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/grant_action"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.Material3.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:text="@string/general_grant_permission_action"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/permission_description" />
Expand Down
46 changes: 43 additions & 3 deletions app/src/main/java/eu/darken/capod/main/ui/widget/WidgetProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.RemoteViews
import androidx.annotation.LayoutRes
import dagger.hilt.android.AndroidEntryPoint
import eu.darken.capod.R
import eu.darken.capod.common.coroutine.AppScope
Expand Down Expand Up @@ -41,6 +42,7 @@ import kotlinx.coroutines.withTimeout
import java.time.Duration
import javax.inject.Inject


@AndroidEntryPoint
class WidgetProvider : AppWidgetProvider() {

Expand Down Expand Up @@ -95,6 +97,27 @@ class WidgetProvider : AppWidgetProvider() {
}
}

/**
* Returns number of cells needed for given size of the widget.
*
* The value is determined in accordance with official guidelines
* for designing widgets, see:
* https://developer.android.com/guide/practices/ui_guidelines/widget_design
*
* Thanks to Jakub S. on Stackoverflow for this solution:
* https://stackoverflow.com/a/37522648/10866268
*
* @param size Widget size in dp.
* @return Size in number of cells.
*/
private fun getCellsForSize(size: Int): Int {
var n = 2
while (70 * n - 30 < size) {
rcky844 marked this conversation as resolved.
Show resolved Hide resolved
++n
}
return n - 1
}

private suspend fun updateWidget(
context: Context,
widgetManager: AppWidgetManager,
Expand All @@ -107,7 +130,23 @@ class WidgetProvider : AppWidgetProvider() {

val layout = when {
!upgradeRepo.isPro() -> createUpgradeRequiredLayout(context)
device is DualPodDevice -> createDualPodLayout(context, device)
device is DualPodDevice -> {
val minWidth = widgetManager.getAppWidgetOptions(widgetId)
.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)
val columns = getCellsForSize(minWidth)

/* Enable wide widgets only when we are provided with 5 or
* more columns of space.
* Although the minimum size is only 2x1, the safeguards are
* added if these restrictions will ever be loosened in the future.
*/
val layout = when (columns) {
in 1 .. 4 -> R.layout.widget_pod_dual_compact_layout
else -> R.layout.widget_pod_dual_wide_layout
}

createDualPodLayout(context, device, layout)
}
device is SinglePodDevice -> createSinglePodLayout(context, device)
device is PodDevice -> createUnknownPodLayout(context, device)
else -> createNoDeviceLayout(context)
Expand Down Expand Up @@ -169,8 +208,9 @@ class WidgetProvider : AppWidgetProvider() {
private fun createDualPodLayout(
context: Context,
podDevice: DualPodDevice,
): RemoteViews = RemoteViews(context.packageName, R.layout.widget_pod_dual_layout).apply {
log(TAG, VERBOSE) { "createSinglePodLayout(context=$context, podDevice=$podDevice)" }
@LayoutRes layout: Int
): RemoteViews = RemoteViews(context.packageName, layout).apply {
log(TAG, VERBOSE) { "createSinglePodLayout(context=$context, podDevice=$podDevice), layout=${layout}" }
val pendingIntent: PendingIntent = PendingIntent.getActivity(
context,
0,
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/debug_recording_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<TextView
android:id="@+id/label_path"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.TitleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand All @@ -30,7 +30,7 @@

<TextView
android:id="@+id/recording_path"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand All @@ -44,7 +44,7 @@

<TextView
android:id="@+id/label_size"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.TitleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
Expand All @@ -58,7 +58,7 @@

<TextView
android:id="@+id/recording_size"
style="@style/TextAppearance.AppCompat.Body1"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
Expand All @@ -70,7 +70,7 @@

<TextView
android:id="@+id/label_compressed_size"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.TitleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand All @@ -83,7 +83,7 @@

<TextView
android:id="@+id/recording_size_compressed"
style="@style/TextAppearance.AppCompat.Body1"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@+id/label_compressed_size"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/main_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
style="@style/Widget.Material3.Toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/onboarding_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body1"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.BodyLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
Expand All @@ -41,7 +41,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body2"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.BodyLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
Expand All @@ -50,7 +50,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body3"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.BodyLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
Expand All @@ -59,7 +59,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/body4"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.BodyLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/overview_bluetooth_disabled_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/bluetooth_label"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand All @@ -27,7 +27,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/bluetooth_description"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/overview_nomaindevice_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/permission_label"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand All @@ -27,7 +27,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/permission_description"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/layout/overview_permission_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/request_description"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand All @@ -27,7 +27,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/permission_label"
style="@style/TextAppearance.MaterialComponents.Body1"
style="@style/TextAppearance.Material3.BodyLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand All @@ -39,7 +39,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/permission_description"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="match_parent"
android:layout_marginTop="4dp"
android:layout_marginHorizontal="16dp"
Expand All @@ -51,7 +51,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/privacy_policy"
style="@style/TextAppearance.MaterialComponents.Tooltip"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_height="wrap_content"
Expand All @@ -63,7 +63,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/grant_action"
style="@style/Widget.MaterialComponents.Button"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_height="wrap_content"
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/overview_pods_dual_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/name"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.TitleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand All @@ -44,7 +44,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/last_seen"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/first_seen"
Expand All @@ -56,7 +56,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/first_seen"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
Expand All @@ -68,7 +68,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/reception"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand All @@ -82,7 +82,7 @@

<ImageView
android:id="@+id/reception_icon"
style="@style/TextAppearance.MaterialComponents.Caption"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginHorizontal="16dp"
Expand Down Expand Up @@ -432,7 +432,7 @@

<com.google.android.material.textview.MaterialTextView
android:id="@+id/status"
style="@style/TextAppearance.MaterialComponents.Body2"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
Expand Down
Loading
Loading