Skip to content

Commit

Permalink
feat: add todayLectureBlock layout
Browse files Browse the repository at this point in the history
  • Loading branch information
SungyeopJeong authored and happycastle114 committed Nov 4, 2024
1 parent ad28bb1 commit 5c6bfab
Show file tree
Hide file tree
Showing 23 changed files with 898 additions and 9 deletions.
55 changes: 46 additions & 9 deletions android/app/src/main/java/org/sparcs/otlplus/TodayWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.appwidget.AppWidgetProvider
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.util.Log
import android.view.View
import java.util.Calendar
import android.widget.RemoteViews
Expand Down Expand Up @@ -60,8 +61,9 @@ class TodayWidget : AppWidgetProvider() {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val intent = Intent(context, TodayWidget::class.java)
intent.action = ACTION_UPDATE_WIDGET
val pendingIntent =
PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val pendingIntent = PendingIntent.getBroadcast(
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)

// Schedule alarm to update widget every minute
alarmManager.setRepeating(
Expand All @@ -74,12 +76,11 @@ class TodayWidget : AppWidgetProvider() {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val intent = Intent(context, TodayWidget::class.java)
intent.action = ACTION_UPDATE_WIDGET
val pendingIntent =
PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
val pendingIntent = PendingIntent.getBroadcast(
context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
alarmManager.cancel(pendingIntent)
}


}

internal fun updateTodayWidget(
Expand All @@ -94,8 +95,9 @@ internal fun updateTodayWidget(
val dottedWidth = context.resources.getDimensionPixelSize(R.dimen.today_dotted_time_width)
val indicatorWidth = context.resources.getDimensionPixelSize(R.dimen.time_indicator_width)
val itemMargin = context.resources.getDimensionPixelSize(R.dimen.today_time_margin)
val blockMargin = context.resources.getDimensionPixelSize(R.dimen.block_margin)
val hourMargin = solidWidth + dottedWidth + itemMargin * 2
val startMargin = itemMargin + solidWidth / 2.0 - indicatorWidth / 2.0
val startMargin = itemMargin + solidWidth / 2.0

// Construct the RemoteViews object
val views = RemoteViews(context.packageName, R.layout.today_widget)
Expand Down Expand Up @@ -126,10 +128,12 @@ internal fun updateTodayWidget(
val hour = calendar.get(Calendar.HOUR_OF_DAY)
val minute = calendar.get(Calendar.MINUTE)
val visibility = isVisible(hour, minute)
val offset = getOffset(hour, minute)

Log.d("TodayWidget", "updated at $hour:$minute")

if (visibility) {
val margin = getMargin(hour, minute)
val offset = getOffset(hour, minute)
val margin = getMargin(hour, minute) - indicatorWidth / 2.0

views.setViewPadding(R.id.todayTimetable, (itemMargin - offset).roundToInt(), 0, 0, 0)
views.setViewVisibility(R.id.timeIndicator, View.VISIBLE)
Expand All @@ -139,6 +143,39 @@ internal fun updateTodayWidget(
views.setViewVisibility(R.id.timeIndicator, View.INVISIBLE)
}

// Add lecture blocks
views.removeAllViews(R.id.todayLectureBlockContainer)

fun getLayoutId(minute: Int): Int? = when (minute) {
30 -> R.layout.today_lecture_block_30
50 -> R.layout.today_lecture_block_50
60 -> R.layout.today_lecture_block_60
70 -> R.layout.today_lecture_block_70
75 -> R.layout.today_lecture_block_75
90 -> R.layout.today_lecture_block_90
110 -> R.layout.today_lecture_block_110
120 -> R.layout.today_lecture_block_120
150 -> R.layout.today_lecture_block_150
165 -> R.layout.today_lecture_block_165
170 -> R.layout.today_lecture_block_170
180 -> R.layout.today_lecture_block_180
210 -> R.layout.today_lecture_block_210
240 -> R.layout.today_lecture_block_240
300 -> R.layout.today_lecture_block_300
360 -> R.layout.today_lecture_block_360
420 -> R.layout.today_lecture_block_420
480 -> R.layout.today_lecture_block_480
540 -> R.layout.today_lecture_block_540
else -> null
}

(getLayoutId(110))?.let { layoutId ->
val margin = getMargin(10, 30) + blockMargin
val lectureBlock = RemoteViews(context.packageName, layoutId)
lectureBlock.setViewPadding(R.id.todayLectureBlock, (margin - offset).roundToInt(), 0, 0, 0)
views.addView(R.id.todayLectureBlockContainer, lectureBlock)
}

// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="2dp" />
<solid android:color="@color/lecture_0" />
</shape>
43 changes: 43 additions & 0 deletions android/app/src/main/res/layout/today_lecture_block_110.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todayLectureBlock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:textSize="11sp" />

<LinearLayout
android:layout_width="@dimen/block_width_110"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@drawable/lecture_block_background"
android:orientation="vertical"
android:padding="6dp">

<TextView
android:id="@+id/lectureTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_title"
android:textColor="@color/grays_gray0_black"
android:textSize="11sp" />

<TextView
android:id="@+id/lectureRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_room"
android:textColor="@color/grays_gray0_50"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
43 changes: 43 additions & 0 deletions android/app/src/main/res/layout/today_lecture_block_120.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todayLectureBlock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:textSize="11sp" />

<LinearLayout
android:layout_width="@dimen/block_width_120"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@drawable/lecture_block_background"
android:orientation="vertical"
android:padding="6dp">

<TextView
android:id="@+id/lectureTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_title"
android:textColor="@color/grays_gray0_black"
android:textSize="11sp" />

<TextView
android:id="@+id/lectureRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_room"
android:textColor="@color/grays_gray0_50"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
43 changes: 43 additions & 0 deletions android/app/src/main/res/layout/today_lecture_block_150.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todayLectureBlock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:textSize="11sp" />

<LinearLayout
android:layout_width="@dimen/block_width_150"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@drawable/lecture_block_background"
android:orientation="vertical"
android:padding="6dp">

<TextView
android:id="@+id/lectureTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_title"
android:textColor="@color/grays_gray0_black"
android:textSize="11sp" />

<TextView
android:id="@+id/lectureRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_room"
android:textColor="@color/grays_gray0_50"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
43 changes: 43 additions & 0 deletions android/app/src/main/res/layout/today_lecture_block_165.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todayLectureBlock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:textSize="11sp" />

<LinearLayout
android:layout_width="@dimen/block_width_165"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@drawable/lecture_block_background"
android:orientation="vertical"
android:padding="6dp">

<TextView
android:id="@+id/lectureTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_title"
android:textColor="@color/grays_gray0_black"
android:textSize="11sp" />

<TextView
android:id="@+id/lectureRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_room"
android:textColor="@color/grays_gray0_50"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
43 changes: 43 additions & 0 deletions android/app/src/main/res/layout/today_lecture_block_170.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todayLectureBlock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:textSize="11sp" />

<LinearLayout
android:layout_width="@dimen/block_width_170"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@drawable/lecture_block_background"
android:orientation="vertical"
android:padding="6dp">

<TextView
android:id="@+id/lectureTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_title"
android:textColor="@color/grays_gray0_black"
android:textSize="11sp" />

<TextView
android:id="@+id/lectureRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_room"
android:textColor="@color/grays_gray0_50"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
43 changes: 43 additions & 0 deletions android/app/src/main/res/layout/today_lecture_block_180.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todayLectureBlock"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:textSize="11sp" />

<LinearLayout
android:layout_width="@dimen/block_width_180"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:background="@drawable/lecture_block_background"
android:orientation="vertical"
android:padding="6dp">

<TextView
android:id="@+id/lectureTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_title"
android:textColor="@color/grays_gray0_black"
android:textSize="11sp" />

<TextView
android:id="@+id/lectureRoom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/notosanskr_regular"
android:includeFontPadding="false"
android:text="@string/sample_room"
android:textColor="@color/grays_gray0_50"
android:textSize="11sp" />
</LinearLayout>
</LinearLayout>
Loading

0 comments on commit 5c6bfab

Please sign in to comment.