Skip to content

Commit a56d16b

Browse files
committed
feat: impl design for next_lecture
todo: make responsive view & impl timetable and timeline
1 parent 26c4f38 commit a56d16b

File tree

10 files changed

+261
-33
lines changed

10 files changed

+261
-33
lines changed

android/app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ flutter {
9090
}
9191

9292
dependencies {
93+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
9394
testImplementation("junit:junit:4.13.2")
9495
androidTestImplementation("androidx.test:runner:1.6.1")
9596
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")

android/app/src/main/java/org/sparcs/otlplus/TimeTableWidget.kt

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,65 @@ package org.sparcs.otlplus
33
import android.appwidget.AppWidgetManager
44
import android.appwidget.AppWidgetProvider
55
import android.content.Context
6+
import android.os.Bundle
67
import android.widget.RemoteViews
8+
import org.sparcs.otlplus.api.Data
79

810
/**
911
* Implementation of App Widget functionality.
1012
*/
13+
14+
enum class WidgetType {
15+
NextLecture,
16+
Timeline,
17+
Timetable,
18+
}
19+
1120
class TimeTableWidget : AppWidgetProvider() {
21+
private var widgetType = WidgetType.NextLecture
22+
23+
private fun updateWidget(
24+
context: Context,
25+
appWidgetManager: AppWidgetManager,
26+
appWidgetId: Int
27+
) {
28+
when (widgetType) {
29+
WidgetType.NextLecture -> updateNextLecture(context, appWidgetManager, appWidgetId)
30+
WidgetType.Timeline -> updateTimeLine(context, appWidgetManager, appWidgetId)
31+
WidgetType.Timetable -> updateTimeLine(context, appWidgetManager, appWidgetId)
32+
}
33+
}
34+
1235
override fun onUpdate(
1336
context: Context,
1437
appWidgetManager: AppWidgetManager,
1538
appWidgetIds: IntArray
1639
) {
1740
// There may be multiple widgets active, so update all of them
1841
for (appWidgetId in appWidgetIds) {
19-
updateAppWidget(context, appWidgetManager, appWidgetId)
42+
updateWidget(context, appWidgetManager, appWidgetId)
43+
}
44+
}
45+
46+
override fun onAppWidgetOptionsChanged(
47+
context: Context?,
48+
appWidgetManager: AppWidgetManager?,
49+
appWidgetId: Int,
50+
newOptions: Bundle?
51+
) {
52+
super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
53+
54+
val minWidth = newOptions?.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH) ?: 0
55+
val minHeight = newOptions?.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) ?: 0
56+
57+
widgetType = when {
58+
minWidth <= 200 -> WidgetType.NextLecture
59+
minHeight > 220 -> WidgetType.Timetable
60+
else -> WidgetType.Timeline
2061
}
62+
63+
if (context != null && appWidgetManager != null)
64+
updateWidget(context, appWidgetManager, appWidgetId)
2165
}
2266

2367
override fun onEnabled(context: Context) {
@@ -29,16 +73,34 @@ class TimeTableWidget : AppWidgetProvider() {
2973
}
3074
}
3175

32-
internal fun updateAppWidget(
76+
internal fun updateNextLecture(
3377
context: Context,
3478
appWidgetManager: AppWidgetManager,
3579
appWidgetId: Int
3680
) {
37-
val widgetText = context.getString(R.string.appwidget_text)
3881
// Construct the RemoteViews object
39-
val views = RemoteViews(context.packageName, R.layout.time_table_widget)
40-
views.setTextViewText(R.id.appwidget_text, widgetText)
82+
RemoteViews(context.packageName, R.layout.next_lecture_widget).let {
83+
it.setTextViewText(R.id.nextLectureDate, Data.nextLectureDate)
84+
it.setTextViewText(R.id.nextLectureName, Data.nextLectureName)
85+
it.setTextViewText(R.id.nextLecturePlace, Data.nextLecturePlace)
86+
it.setTextViewText(R.id.nextLectureProfessor, Data.nextLectureProfessor)
87+
// Instruct the widget manager to update the widget
88+
appWidgetManager.updateAppWidget(appWidgetId, it)
89+
}
90+
}
4191

42-
// Instruct the widget manager to update the widget
43-
appWidgetManager.updateAppWidget(appWidgetId, views)
92+
internal fun updateTimeLine(
93+
context: Context,
94+
appWidgetManager: AppWidgetManager,
95+
appWidgetId: Int
96+
) {
97+
RemoteViews(context.packageName, R.layout.next_lecture_widget).let {
98+
it.setTextViewText(R.id.nextLecture, "타임라인입니다.")
99+
it.setTextViewText(R.id.nextLectureDate, Data.nextLectureDate)
100+
it.setTextViewText(R.id.nextLectureName, Data.nextLectureName)
101+
it.setTextViewText(R.id.nextLecturePlace, Data.nextLecturePlace)
102+
it.setTextViewText(R.id.nextLectureProfessor, Data.nextLectureProfessor)
103+
// Instruct the widget manager to update the widget
104+
appWidgetManager.updateAppWidget(appWidgetId, it)
105+
}
44106
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.sparcs.otlplus.api
2+
3+
object Data { // TODO: Get data using api
4+
val nextLectureDate
5+
get() = "다음주 월요일"
6+
7+
val nextLectureName
8+
get() = "그래프이론 개론"
9+
10+
val nextLecturePlace
11+
get() = "(E2)산업경영학동1225"
12+
13+
val nextLectureProfessor
14+
get() = "김재훈"
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
2+
<solid android:color="@color/accent" /> <!-- Circle color -->
3+
<corners android:radius="50dp" />
4+
<size android:width="50dp" android:height="50dp"/>
5+
</shape>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:layout_width="match_parent"
3+
android:layout_height="match_parent"
4+
android:padding="12dp"
5+
android:background="@color/page_background">
6+
7+
<LinearLayout
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:orientation="vertical">
11+
12+
<TextView
13+
android:id="@+id/nextLecture"
14+
android:layout_width="wrap_content"
15+
android:layout_height="wrap_content"
16+
android:textColor="@color/primary"
17+
android:textSize="11sp"
18+
android:textFontWeight="700"
19+
android:text="@string/next_lecture" />
20+
21+
<TextView
22+
android:id="@+id/nextLectureDate"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:textColor="@color/gray0"
26+
android:textSize="11sp"
27+
android:textFontWeight="700"
28+
android:text="@string/placeholder" />
29+
30+
<LinearLayout
31+
android:layout_marginTop="6dp"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:gravity="center">
35+
36+
<ImageView
37+
android:layout_width="10dp"
38+
android:layout_height="10dp"
39+
android:background="@drawable/circle"
40+
android:importantForAccessibility="no" />
41+
42+
<TextView
43+
android:layout_marginStart="4dp"
44+
android:id="@+id/nextLectureName"
45+
android:layout_width="0dp"
46+
android:layout_height="wrap_content"
47+
android:layout_weight="1"
48+
android:textSize="11sp"
49+
android:textColor="@color/gray0"
50+
android:textFontWeight="700"
51+
android:ellipsize="end"
52+
android:maxLines="1"
53+
android:text="@string/placeholder"/>
54+
</LinearLayout>
55+
56+
<TextView
57+
android:id="@+id/nextLecturePlace"
58+
android:layout_width="match_parent"
59+
android:layout_height="wrap_content"
60+
android:textSize="11sp"
61+
android:textColor="@color/gray0"
62+
android:textFontWeight="400"
63+
android:ellipsize="end"
64+
android:maxLines="1"
65+
android:text="@string/placeholder"/>
66+
67+
<TextView
68+
android:id="@+id/nextLectureProfessor"
69+
android:layout_width="match_parent"
70+
android:layout_height="wrap_content"
71+
android:textSize="11sp"
72+
android:textColor="@color/gray75"
73+
android:textFontWeight="500"
74+
android:ellipsize="end"
75+
android:maxLines="1"
76+
android:text="@string/placeholder"/>
77+
</LinearLayout>
78+
</RelativeLayout>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:layout_width="match_parent"
3+
android:layout_height="match_parent"
4+
android:padding="12dp"
5+
android:background="@color/page_background">
6+
7+
<LinearLayout
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:orientation="vertical">
11+
12+
<TextView
13+
android:id="@+id/nextLecture"
14+
android:layout_width="wrap_content"
15+
android:layout_height="wrap_content"
16+
android:textColor="@color/primary"
17+
android:textSize="11sp"
18+
android:textStyle="bold"
19+
android:text="@string/next_lecture" />
20+
21+
<TextView
22+
android:id="@+id/nextLectureDate"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:textColor="@color/gray0"
26+
android:textSize="11sp"
27+
android:textStyle="bold"
28+
android:text="@string/placeholder" />
29+
30+
<LinearLayout
31+
android:layout_marginTop="6dp"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:gravity="center">
35+
36+
<ImageView
37+
android:layout_width="10dp"
38+
android:layout_height="10dp"
39+
android:background="@drawable/circle"
40+
android:importantForAccessibility="no" />
41+
42+
<TextView
43+
android:layout_marginStart="4dp"
44+
android:id="@+id/nextLectureName"
45+
android:layout_width="0dp"
46+
android:layout_height="wrap_content"
47+
android:layout_weight="1"
48+
android:textSize="11sp"
49+
android:textColor="@color/gray0"
50+
android:textStyle="bold"
51+
android:ellipsize="end"
52+
android:maxLines="1"
53+
android:text="@string/placeholder"/>
54+
</LinearLayout>
55+
56+
<TextView
57+
android:id="@+id/nextLecturePlace"
58+
android:layout_width="match_parent"
59+
android:layout_height="wrap_content"
60+
android:textSize="11sp"
61+
android:textColor="@color/gray0"
62+
android:textStyle="normal"
63+
android:ellipsize="end"
64+
android:maxLines="1"
65+
android:text="@string/placeholder"/>
66+
67+
<TextView
68+
android:id="@+id/nextLectureProfessor"
69+
android:layout_width="match_parent"
70+
android:layout_height="wrap_content"
71+
android:textSize="11sp"
72+
android:textColor="@color/gray75"
73+
android:textStyle="normal"
74+
android:ellipsize="end"
75+
android:maxLines="1"
76+
android:text="@string/placeholder"/>
77+
</LinearLayout>
78+
</RelativeLayout>

android/app/src/main/res/layout/time_table_widget.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3+
<!--Start Widget-->
4+
<color name="page_background">#F9F0F0</color>
5+
<color name="primary">#E54C65</color>
6+
<color name="gray0">#000000</color>
7+
<color name="gray75">#757575</color>
8+
<color name="accent">#B54896</color>
9+
<color name="guideline">#40000000</color>
10+
11+
<!--End Widget-->
12+
313
<color name="ic_launcher_background">#F9F0F0</color>
4-
<color name="light_blue_50">#FFE1F5FE</color>
5-
<color name="light_blue_200">#FF81D4FA</color>
6-
<color name="light_blue_600">#FF039BE5</color>
7-
<color name="light_blue_900">#FF01579B</color>
814
</resources>

android/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<string name="appwidget_text">EXAMPLE</string>
44
<string name="add_widget">Add widget</string>
55
<string name="app_widget_description">This is an app widget description</string>
6+
<string name="next_lecture">다음 강의</string>
7+
<string name="placeholder">{placeholder}</string>
68
</resources>

android/app/src/main/res/xml/time_table_widget_info.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
33
android:description="@string/app_widget_description"
4-
android:initialKeyguardLayout="@layout/time_table_widget"
5-
android:initialLayout="@layout/time_table_widget"
4+
android:initialKeyguardLayout="@layout/next_lecture_widget"
5+
android:initialLayout="@layout/next_lecture_widget"
66
android:minWidth="40dp"
77
android:minHeight="40dp"
88
android:previewImage="@drawable/example_appwidget_preview"
9-
android:previewLayout="@layout/time_table_widget"
9+
android:previewLayout="@layout/next_lecture_widget"
1010
android:resizeMode="horizontal|vertical"
1111
android:targetCellWidth="1"
1212
android:targetCellHeight="1"

0 commit comments

Comments
 (0)