Skip to content

Commit

Permalink
Merge pull request #334 from SuhasDissa/analog_clock
Browse files Browse the repository at this point in the history
feat: Analog clock configuration
  • Loading branch information
SuhasDissa authored Apr 25, 2024
2 parents acda51c + 89f7017 commit 2559350
Show file tree
Hide file tree
Showing 33 changed files with 1,452 additions and 19 deletions.
11 changes: 9 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity
android:name=".presentation.widgets.AnalogClockWidgetConfig"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity
android:name=".ui.MainActivity"
android:exported="true"
Expand All @@ -50,9 +57,9 @@
android:name=".presentation.screens.alarm.AlarmActivity"
android:configChanges="orientation|keyboardHidden|keyboard|navigation"
android:excludeFromRecents="true"
android:theme="@style/Theme.ClockYou"
android:launchMode="singleInstance"
android:taskAffinity="" />
android:taskAffinity=""
android:theme="@style/Theme.ClockYou" />

<receiver
android:name=".util.receivers.AlarmReceiver"
Expand Down
89 changes: 89 additions & 0 deletions app/src/main/java/com/bnyro/clock/domain/model/AnalogClockFace.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.bnyro.clock.domain.model

import androidx.annotation.DrawableRes
import com.bnyro.clock.R

sealed class AnalogClockFace(
val name: String,
val author: String? = null,
val authorUrl: String? = null,
@DrawableRes val dial: Int = 0,
@DrawableRes val hourHand: Int = 0,
@DrawableRes val minuteHand: Int = 0,
@DrawableRes val secondHand: Int = 0
) {

object System : AnalogClockFace(
name = "System"
)

object Classic76 : AnalogClockFace(
name = "Classic76",
author = "§",
authorUrl = "https://github.com/shuvashish76",
dial = R.drawable.classic76_dial,
hourHand = R.drawable.classic76_hour_hand,
minuteHand = R.drawable.classic76_minute_hand,
secondHand = R.drawable.classic76_second_hand
)

object TwoDBall : AnalogClockFace(
name = "2D Ball",
author = "§",
authorUrl = "https://github.com/shuvashish76",
dial = R.drawable.twod_ball_dial,
hourHand = R.drawable.twod_ball_hour_hand,
minuteHand = R.drawable.twod_ball_minute_hand,
secondHand = R.drawable.twod_ball_second_hand
)

object ClassicClockYou : AnalogClockFace(
name = "Classic Clock You",
author = "SuhasDissa",
authorUrl = "https://github.com/SuhasDissa",
dial = R.drawable.classic_clock_you_dial,
hourHand = R.drawable.classic_clock_you_hour_hand,
minuteHand = R.drawable.classic_clock_you_minute_hand
)

object AnalogClock : AnalogClockFace(
name = "Analog Clock",
author = "DG-RA",
authorUrl = "https://openclipart.org/artist/DG-RA",
dial = R.drawable.analog_clock_black_dial,
hourHand = R.drawable.analog_clock_black_hour_hand,
minuteHand = R.drawable.analog_clock_black_minute_hand,
secondHand = R.drawable.analog_clock_black_second_hand
)

object MinimalisticCircular : AnalogClockFace(
name = "Minimalistic - Circular",
author = "§",
authorUrl = "https://github.com/shuvashish76",
dial = R.drawable.minimalistic_circular_dial,
hourHand = R.drawable.minimalistic_circular_hour_hand,
minuteHand = R.drawable.minimalistic_circular_minute_hand
)

object MinimalisticBar : AnalogClockFace(
name = "Minimalistic - Bar",
author = "§",
authorUrl = "https://github.com/shuvashish76",
dial = R.drawable.minimalistic_bar_dial,
hourHand = R.drawable.minimalistic_bar_hour_hand,
minuteHand = R.drawable.minimalistic_bar_minute_hand
)

companion object {
val all = listOf(
System,
Classic76,
TwoDBall,
ClassicClockYou,
AnalogClock,
MinimalisticCircular,
MinimalisticBar
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.bnyro.clock.domain.model

import androidx.annotation.DrawableRes

data class AnalogClockWidgetOptions(
var clockFaceName: String,
@DrawableRes var hourHand: Int,
@DrawableRes var minuteHand: Int,
@DrawableRes var secondHand: Int,
@DrawableRes var dial: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import android.content.Intent
import android.widget.RemoteViews
import com.bnyro.clock.R
import com.bnyro.clock.ui.MainActivity
import com.bnyro.clock.util.widgets.applyAnalogClockWidgetOptions
import com.bnyro.clock.util.widgets.deleteAnalogClockWidgetPref
import com.bnyro.clock.util.widgets.loadAnalogClockWidgetSettings

class AnalogClockWidget : AppWidgetProvider() {

Expand All @@ -16,7 +19,7 @@ class AnalogClockWidget : AppWidgetProvider() {
appWidgetManager: AppWidgetManager,
appWidgetIds: IntArray
) {
appWidgetIds.forEach { appWidgetId ->
for (appWidgetId in appWidgetIds) {
val pendingIntent: PendingIntent = PendingIntent.getActivity(
context,
0,
Expand All @@ -27,8 +30,16 @@ class AnalogClockWidget : AppWidgetProvider() {
val views = RemoteViews(context.packageName, R.layout.analog_clock).apply {
setOnClickPendingIntent(R.id.analog_clock, pendingIntent)
}

val options = context.loadAnalogClockWidgetSettings(appWidgetId)
views.applyAnalogClockWidgetOptions(options, context)
appWidgetManager.updateAppWidget(appWidgetId, views)
}
}

override fun onDeleted(context: Context, appWidgetIds: IntArray) {
for (appWidgetId in appWidgetIds) {
context.deleteAnalogClockWidgetPref(appWidgetId)
}
super.onDeleted(context, appWidgetIds)
}
}
Loading

0 comments on commit 2559350

Please sign in to comment.