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

feat: Analog clock configuration #334

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading