Skip to content

Commit d677c9e

Browse files
authored
feat(widget): add monthly calendar grid (#1161)
* feat(widget): add monthly calendar grid * feat(CHANGELOG.md): update unreleased note * fix(CHANGELOG.md): merge conflict * chore(WidgetMonthly): line indent
1 parent 98674d2 commit d677c9e

8 files changed

Lines changed: 648 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Added
99
- Holidays for New Zealand ([#1157])
10+
- Added grid into monthly calendar widget
1011

1112
### Changed
1213
- Updated holiday data

app/src/main/kotlin/org/fossify/calendar/activities/WidgetMonthlyConfigureActivity.kt

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
3636
private var mBgColor = 0
3737
private var mTextColor = 0
3838

39+
private var mShowGrid = false
40+
3941
private val binding by viewBinding(WidgetConfigMonthlyBinding::inflate)
4042
private val topNavigationBinding by lazy { TopNavigationBinding.bind(binding.root) }
4143

4244
public override fun onCreate(savedInstanceState: Bundle?) {
4345
useDynamicTheme = false
4446
super.onCreate(savedInstanceState)
45-
setResult(Activity.RESULT_CANCELED)
47+
setResult(RESULT_CANCELED)
4648
setContentView(binding.root)
4749
setupEdgeToEdge(padTopSystem = listOf(binding.configHolder), padBottomSystem = listOf(binding.root))
4850
initVariables()
@@ -59,13 +61,16 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
5961
configSave.setOnClickListener { saveConfig() }
6062
configBgColor.setOnClickListener { pickBackgroundColor() }
6163
configTextColor.setOnClickListener { pickTextColor() }
64+
configGrid.setOnClickListener { pickGridShow() }
6265
configBgSeekbar.setColors(mTextColor, primaryColor, primaryColor)
66+
configGrid.isChecked = mShowGrid
6367
}
6468
}
6569

6670
private fun initVariables() {
6771
mBgColor = config.widgetBgColor
6872
mBgAlpha = Color.alpha(mBgColor) / 255f
73+
mShowGrid = config.widgetShowGrid
6974

7075
mBgColorWithoutTransparency = Color.rgb(Color.red(mBgColor), Color.green(mBgColor), Color.blue(mBgColor))
7176
binding.configBgSeekbar.apply {
@@ -84,7 +89,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
8489
}
8590

8691
updateTextColor()
87-
92+
updateGridShow()
8893
MonthlyCalendarImpl(this, this).updateMonthlyCalendar(DateTime().withDayOfMonth(1))
8994
}
9095

@@ -94,7 +99,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
9499

95100
Intent().apply {
96101
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId)
97-
setResult(Activity.RESULT_OK, this)
102+
setResult(RESULT_OK, this)
98103
}
99104
finish()
100105
}
@@ -103,6 +108,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
103108
config.apply {
104109
widgetBgColor = mBgColor
105110
widgetTextColor = mTextColor
111+
widgetShowGrid = mShowGrid
106112
}
107113
}
108114

@@ -111,6 +117,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
111117
if (wasPositivePressed) {
112118
mBgColorWithoutTransparency = color
113119
updateBackgroundColor()
120+
updateGridShow()
114121
}
115122
}
116123
}
@@ -125,6 +132,45 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
125132
}
126133
}
127134

135+
private fun pickGridShow() {
136+
mShowGrid = !mShowGrid
137+
updateGridShow()
138+
}
139+
140+
private fun updateGridShow() {
141+
if (mShowGrid) {
142+
binding.configCalendar.apply {
143+
val tableView = arrayOf(
144+
tableHolder,
145+
monthLineHolder1,
146+
monthLineHolder2,
147+
monthLineHolder3,
148+
monthLineHolder4,
149+
monthLineHolder5,
150+
monthLineHolder6
151+
)
152+
for (i in tableView) {
153+
i.showDividers = LinearLayout.SHOW_DIVIDER_MIDDLE
154+
}
155+
}
156+
return
157+
}
158+
binding.configCalendar.apply {
159+
val tableView = arrayOf(
160+
tableHolder,
161+
monthLineHolder1,
162+
monthLineHolder2,
163+
monthLineHolder3,
164+
monthLineHolder4,
165+
monthLineHolder5,
166+
monthLineHolder6
167+
)
168+
for (i in tableView) {
169+
i.showDividers = LinearLayout.SHOW_DIVIDER_NONE
170+
}
171+
}
172+
}
173+
128174
private fun requestWidgetUpdate() {
129175
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetMonthlyProvider::class.java).apply {
130176
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
@@ -145,6 +191,10 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
145191
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
146192
binding.configCalendar.root.background.applyColorFilter(mBgColor)
147193
binding.configBgColor.setFillWithStroke(mBgColor, mBgColor)
194+
binding.configGrid.trackTintList = ColorStateList(
195+
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
196+
intArrayOf(getProperPrimaryColor(), Color.GRAY)
197+
)
148198
binding.configSave.backgroundTintList = ColorStateList.valueOf(getProperPrimaryColor())
149199
}
150200

@@ -196,7 +246,8 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
196246
}
197247

198248
DayMonthlyNumberViewBinding.inflate(layoutInflater).apply {
199-
root.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
249+
root.layoutParams =
250+
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
200251
linearLayout.addView(root)
201252

202253
dayMonthlyNumberBackground.beVisibleIf(day.isToday)
@@ -213,7 +264,13 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
213264
}
214265
}
215266

216-
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime) {
267+
override fun updateMonthlyCalendar(
268+
context: Context,
269+
month: String,
270+
days: ArrayList<DayMonthly>,
271+
checkedEvents: Boolean,
272+
currTargetDate: DateTime
273+
) {
217274
runOnUiThread {
218275
mDays = days
219276
topNavigationBinding.topValue.text = month

app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,8 @@ class Config(context: Context) : BaseConfig(context) {
332332
get() = prefs.getBoolean(LAST_USED_SHOW_LIST_WIDGET_HEADER, true)
333333
set(lastUsedShowListWidgetHeader) = prefs.edit()
334334
.putBoolean(LAST_USED_SHOW_LIST_WIDGET_HEADER, lastUsedShowListWidgetHeader).apply()
335+
336+
var widgetShowGrid: Boolean
337+
get() = prefs.getBoolean(WIDGET_SHOW_GRID, false)
338+
set(widgetShowGrid) = prefs.edit().putBoolean(WIDGET_SHOW_GRID, widgetShowGrid).apply()
335339
}

app/src/main/kotlin/org/fossify/calendar/helpers/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const val AUTO_BACKUP_TASKS = "auto_backup_tasks"
149149
const val AUTO_BACKUP_PAST_ENTRIES = "auto_backup_past_entries"
150150
const val LAST_AUTO_BACKUP_TIME = "last_auto_backup_time"
151151
const val LAST_USED_SHOW_LIST_WIDGET_HEADER = "last_used_show_widget_header"
152+
const val WIDGET_SHOW_GRID = "widget_show_grid"
152153

153154
// repeat_rule for monthly and yearly repetition
154155
const val REPEAT_SAME_DAY =

app/src/main/kotlin/org/fossify/calendar/helpers/MyWidgetMonthlyProvider.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,14 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
185185
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime) {
186186
val largerFontSize = context.getWidgetFontSize() + 3f
187187
val textColor = context.config.widgetTextColor
188+
val showGrid = context.config.widgetShowGrid
188189
val resources = context.resources
189190

190191
val appWidgetManager = AppWidgetManager.getInstance(context) ?: return
191192
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
192-
val views = RemoteViews(context.packageName, R.layout.fragment_month_widget)
193+
val layoutId = if (showGrid) R.layout.fragment_month_widget_grid else R.layout.fragment_month_widget
194+
195+
val views = RemoteViews(context.packageName, layoutId)
193196
views.setText(R.id.top_value, month)
194197

195198
views.applyColorFilter(R.id.widget_month_background, context.config.widgetBgColor)
@@ -214,7 +217,6 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
214217

215218
updateDayLabels(context, views, resources, textColor)
216219
updateDays(context, views, days)
217-
218220
setupIntent(context, views, PREV, R.id.top_left_arrow)
219221
setupIntent(context, views, NEXT, R.id.top_right_arrow)
220222
setupIntent(context, views, GO_TO_TODAY, R.id.top_go_to_today)

app/src/main/res/layout/fragment_month_widget_config.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
android:layout_width="match_parent"
2323
android:layout_height="match_parent"
2424
android:layout_below="@+id/first_row"
25+
android:divider="@color/dark_grey"
2526
android:gravity="center"
2627
android:orientation="vertical">
2728

2829
<LinearLayout
2930
android:id="@+id/month_line_holder_1"
3031
android:layout_width="match_parent"
3132
android:layout_height="match_parent"
33+
android:divider="@color/dark_grey"
3234
android:layout_weight="2"
3335
android:orientation="horizontal">
3436

@@ -110,6 +112,7 @@
110112
android:layout_width="match_parent"
111113
android:layout_height="match_parent"
112114
android:layout_weight="2"
115+
android:divider="@color/dark_grey"
113116
android:orientation="horizontal">
114117

115118
<org.fossify.commons.views.MyTextView
@@ -191,6 +194,7 @@
191194
android:layout_width="match_parent"
192195
android:layout_height="match_parent"
193196
android:layout_weight="2"
197+
android:divider="@color/dark_grey"
194198
android:orientation="horizontal">
195199

196200
<org.fossify.commons.views.MyTextView
@@ -271,6 +275,7 @@
271275
android:layout_width="match_parent"
272276
android:layout_height="match_parent"
273277
android:layout_weight="2"
278+
android:divider="@color/dark_grey"
274279
android:orientation="horizontal">
275280

276281
<org.fossify.commons.views.MyTextView
@@ -352,6 +357,7 @@
352357
android:layout_width="match_parent"
353358
android:layout_height="match_parent"
354359
android:layout_weight="2"
360+
android:divider="@color/dark_grey"
355361
android:orientation="horizontal">
356362

357363
<org.fossify.commons.views.MyTextView
@@ -433,6 +439,7 @@
433439
android:layout_width="match_parent"
434440
android:layout_height="match_parent"
435441
android:layout_weight="2"
442+
android:divider="@color/dark_grey"
436443
android:orientation="horizontal">
437444

438445
<org.fossify.commons.views.MyTextView

0 commit comments

Comments
 (0)