Skip to content

Commit

Permalink
fix: Retrofit problem with R8 minification
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Info committed Oct 24, 2023
1 parent a8b894a commit c2315c3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 30 deletions.
97 changes: 71 additions & 26 deletions app/src/main/kotlin/com/zjutjh/ijh/widget/ScheduleWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,37 @@ import androidx.glance.Button
import androidx.glance.GlanceId
import androidx.glance.GlanceModifier
import androidx.glance.GlanceTheme
import androidx.glance.Image
import androidx.glance.ImageProvider
import androidx.glance.action.clickable
import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.appWidgetBackground
import androidx.glance.appwidget.cornerRadius
import androidx.glance.appwidget.provideContent
import androidx.glance.background
import androidx.glance.layout.Alignment
import androidx.glance.layout.Box
import androidx.glance.layout.Column
import androidx.glance.layout.Row
import androidx.glance.layout.Spacer
import androidx.glance.layout.fillMaxSize
import androidx.glance.layout.fillMaxWidth
import androidx.glance.layout.height
import androidx.glance.layout.padding
import androidx.glance.material3.ColorProviders
import com.zjutjh.ijh.model.Course
import com.zjutjh.ijh.ui.component.shortTime
import com.zjutjh.ijh.ui.model.toTermDayState
import com.zjutjh.ijh.ui.theme.DarkColorScheme
import com.zjutjh.ijh.ui.theme.LightColorScheme
import com.zjutjh.ijh.util.toLocalizedString
import com.zjutjh.ijh.work.ScheduleWidgetUpdateWorker
import dagger.hilt.android.EntryPointAccessors
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import java.time.Duration
import java.time.ZonedDateTime

// TODO: Unfinished yet, in early stages
Expand All @@ -51,6 +58,11 @@ class ScheduleWidget : GlanceAppWidget() {
} else flow { emit(emptyList()) }

val syncTime = entryPoint.courseRepository.lastSyncTimeStream
.map {
if (it == null) null else {
Duration.between(it, ZonedDateTime.now()).toLocalizedString(context)
}
}

provideContent {
Content(courses, syncTime) {
Expand All @@ -62,7 +74,7 @@ class ScheduleWidget : GlanceAppWidget() {
@Composable
fun Content(
coursesFlow: Flow<List<Course>>,
syncTimeFlow: Flow<ZonedDateTime?>,
syncTimeFlow: Flow<String?>,
onUpdate: () -> Unit
) {
val courses by coursesFlow.collectAsState(null)
Expand All @@ -76,19 +88,32 @@ class ScheduleWidget : GlanceAppWidget() {
.appWidgetBackground()
.padding(10.dp)
) {
if (courses != null) {
Column {
Row(modifier = GlanceModifier.fillMaxWidth()) {
if (syncTime != null)
GText(
text = "Last sync: ${syncTime!!.toLocalTime()}",
)
else
GText(text = "Never")
Column {
Row(
modifier = GlanceModifier.fillMaxWidth(),
verticalAlignment = Alignment.Vertical.CenterVertically
) {
if (syncTime != null)
GText(
text = syncTime!!,
)
else
GText(text = "Never")

Spacer(GlanceModifier.defaultWeight())
Button(text = "Update", onClick = onUpdate, maxLines = 1)
}
Spacer(GlanceModifier.defaultWeight())
Button(text = "Update", onClick = onUpdate, maxLines = 1)
}
Box(
GlanceModifier.padding(vertical = 10.dp)
) {
Spacer(
GlanceModifier
.fillMaxWidth()
.height(1.dp)
.background(GlanceTheme.colors.outline)
)
}
if (courses != null) {
if (courses!!.isEmpty()) {
GText("No course.")
} else {
Expand All @@ -102,25 +127,45 @@ class ScheduleWidget : GlanceAppWidget() {
}
}
}
} else {
GText("Loading...")
}
} else {
GText("Loading")
}
}
}
}
}

@Composable
private fun CourseItem(course: Course) {
Column(
modifier = GlanceModifier
.fillMaxWidth()
.padding(10.dp)
) {
GText("${course.name}-${course.teacherName}")
GText("${course.shortTime()} | ${course.place}")
}
// TODO: Impl icon button
@Composable
private fun IconButton(
provider: ImageProvider,
onClick: () -> Unit
) {
Box(
modifier = GlanceModifier
.background(GlanceTheme.colors.primaryContainer)
.height(50.dp)
.cornerRadius(10.dp)
.clickable(onClick)
) {
Image(
provider = provider,
contentDescription = "Image in button",
modifier = GlanceModifier.fillMaxSize()
)
}
}

@Composable
private fun CourseItem(course: Course) {
Column(
modifier = GlanceModifier
.fillMaxWidth()
.padding(10.dp)
) {
GText("${course.name}-${course.teacherName}")
GText("${course.shortTime()} | ${course.place}")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ScheduleWidgetReceiver : GlanceAppWidgetReceiver() {
// Enter relevant functionality for when the first widget is created
val manager = WorkManager.getInstance(context)
val request = PeriodicWorkRequestBuilder<ScheduleWidgetUpdateWorker>(
Duration.ofHours(1), Duration.ofMinutes(15)
Duration.ofHours(6), Duration.ofMinutes(30)
).setConstraints(
Constraints(requiresBatteryNotLow = true, requiresDeviceIdle = true)
).build()
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/xml/app_widget_schedule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
android:description="@string/app_widget_schedule_description"
android:initialKeyguardLayout="@layout/widget_loading"
android:initialLayout="@layout/widget_loading"
android:minWidth="160dp"
android:minWidth="200dp"
android:minHeight="160dp"
android:minResizeWidth="160dp"
android:minResizeWidth="200dp"
android:minResizeHeight="160dp"
android:previewLayout="@layout/widget_loading"
android:resizeMode="horizontal|vertical"
android:targetCellWidth="3"
android:targetCellHeight="3"
android:updatePeriodMillis="0"
android:updatePeriodMillis="1800000"
android:widgetCategory="home_screen"
tools:targetApi="s" />
2 changes: 2 additions & 0 deletions core/network/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ android {

defaultConfig {
minSdk min_sdk

consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
Expand Down
9 changes: 9 additions & 0 deletions core/network/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TODO: remove when new retrofit version release. (Current 2.9.0)
# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

0 comments on commit c2315c3

Please sign in to comment.