Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Holidays for New Zealand ([#1157])
- Added grid into monthly calendar widget

### Changed
- Updated holiday data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
private var mBgColor = 0
private var mTextColor = 0

private var mShowGrid = false

private val binding by viewBinding(WidgetConfigMonthlyBinding::inflate)
private val topNavigationBinding by lazy { TopNavigationBinding.bind(binding.root) }

public override fun onCreate(savedInstanceState: Bundle?) {
useDynamicTheme = false
super.onCreate(savedInstanceState)
setResult(Activity.RESULT_CANCELED)
setResult(RESULT_CANCELED)
setContentView(binding.root)
setupEdgeToEdge(padTopSystem = listOf(binding.configHolder), padBottomSystem = listOf(binding.root))
initVariables()
Expand All @@ -59,13 +61,16 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
configSave.setOnClickListener { saveConfig() }
configBgColor.setOnClickListener { pickBackgroundColor() }
configTextColor.setOnClickListener { pickTextColor() }
configGrid.setOnClickListener { pickGridShow() }
configBgSeekbar.setColors(mTextColor, primaryColor, primaryColor)
configGrid.isChecked = mShowGrid
}
}

private fun initVariables() {
mBgColor = config.widgetBgColor
mBgAlpha = Color.alpha(mBgColor) / 255f
mShowGrid = config.widgetShowGrid

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

updateTextColor()

updateGridShow()
MonthlyCalendarImpl(this, this).updateMonthlyCalendar(DateTime().withDayOfMonth(1))
}

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

Intent().apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId)
setResult(Activity.RESULT_OK, this)
setResult(RESULT_OK, this)
}
finish()
}
Expand All @@ -103,6 +108,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
config.apply {
widgetBgColor = mBgColor
widgetTextColor = mTextColor
widgetShowGrid = mShowGrid
}
}

Expand All @@ -111,6 +117,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
if (wasPositivePressed) {
mBgColorWithoutTransparency = color
updateBackgroundColor()
updateGridShow()
}
}
}
Expand All @@ -125,6 +132,45 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
}
}

private fun pickGridShow() {
mShowGrid = !mShowGrid
updateGridShow()
}

private fun updateGridShow() {
if (mShowGrid) {
binding.configCalendar.apply {
val tableView = arrayOf(
tableHolder,
monthLineHolder1,
monthLineHolder2,
monthLineHolder3,
monthLineHolder4,
monthLineHolder5,
monthLineHolder6
)
for (i in tableView) {
i.showDividers = LinearLayout.SHOW_DIVIDER_MIDDLE
}
}
return
}
binding.configCalendar.apply {
val tableView = arrayOf(
tableHolder,
monthLineHolder1,
monthLineHolder2,
monthLineHolder3,
monthLineHolder4,
monthLineHolder5,
monthLineHolder6
)
for (i in tableView) {
i.showDividers = LinearLayout.SHOW_DIVIDER_NONE
}
}
}

private fun requestWidgetUpdate() {
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetMonthlyProvider::class.java).apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
Expand All @@ -145,6 +191,10 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
mBgColor = mBgColorWithoutTransparency.adjustAlpha(mBgAlpha)
binding.configCalendar.root.background.applyColorFilter(mBgColor)
binding.configBgColor.setFillWithStroke(mBgColor, mBgColor)
binding.configGrid.trackTintList = ColorStateList(
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
intArrayOf(getProperPrimaryColor(), Color.GRAY)
)
binding.configSave.backgroundTintList = ColorStateList.valueOf(getProperPrimaryColor())
}

Expand Down Expand Up @@ -196,7 +246,8 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
}

DayMonthlyNumberViewBinding.inflate(layoutInflater).apply {
root.layoutParams = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
root.layoutParams =
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
linearLayout.addView(root)

dayMonthlyNumberBackground.beVisibleIf(day.isToday)
Expand All @@ -213,7 +264,13 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
}
}

override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime) {
override fun updateMonthlyCalendar(
context: Context,
month: String,
days: ArrayList<DayMonthly>,
checkedEvents: Boolean,
currTargetDate: DateTime
) {
runOnUiThread {
mDays = days
topNavigationBinding.topValue.text = month
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/kotlin/org/fossify/calendar/helpers/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,8 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(LAST_USED_SHOW_LIST_WIDGET_HEADER, true)
set(lastUsedShowListWidgetHeader) = prefs.edit()
.putBoolean(LAST_USED_SHOW_LIST_WIDGET_HEADER, lastUsedShowListWidgetHeader).apply()

var widgetShowGrid: Boolean
get() = prefs.getBoolean(WIDGET_SHOW_GRID, false)
set(widgetShowGrid) = prefs.edit().putBoolean(WIDGET_SHOW_GRID, widgetShowGrid).apply()
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const val AUTO_BACKUP_TASKS = "auto_backup_tasks"
const val AUTO_BACKUP_PAST_ENTRIES = "auto_backup_past_entries"
const val LAST_AUTO_BACKUP_TIME = "last_auto_backup_time"
const val LAST_USED_SHOW_LIST_WIDGET_HEADER = "last_used_show_widget_header"
const val WIDGET_SHOW_GRID = "widget_show_grid"

// repeat_rule for monthly and yearly repetition
const val REPEAT_SAME_DAY =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,14 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime) {
val largerFontSize = context.getWidgetFontSize() + 3f
val textColor = context.config.widgetTextColor
val showGrid = context.config.widgetShowGrid
val resources = context.resources

val appWidgetManager = AppWidgetManager.getInstance(context) ?: return
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
val views = RemoteViews(context.packageName, R.layout.fragment_month_widget)
val layoutId = if (showGrid) R.layout.fragment_month_widget_grid else R.layout.fragment_month_widget

val views = RemoteViews(context.packageName, layoutId)
views.setText(R.id.top_value, month)

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

updateDayLabels(context, views, resources, textColor)
updateDays(context, views, days)

setupIntent(context, views, PREV, R.id.top_left_arrow)
setupIntent(context, views, NEXT, R.id.top_right_arrow)
setupIntent(context, views, GO_TO_TODAY, R.id.top_go_to_today)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/fragment_month_widget_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/first_row"
android:divider="@color/dark_grey"
android:gravity="center"
android:orientation="vertical">

<LinearLayout
android:id="@+id/month_line_holder_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/dark_grey"
android:layout_weight="2"
android:orientation="horizontal">

Expand Down Expand Up @@ -110,6 +112,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:divider="@color/dark_grey"
android:orientation="horizontal">

<org.fossify.commons.views.MyTextView
Expand Down Expand Up @@ -191,6 +194,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:divider="@color/dark_grey"
android:orientation="horizontal">

<org.fossify.commons.views.MyTextView
Expand Down Expand Up @@ -271,6 +275,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:divider="@color/dark_grey"
android:orientation="horizontal">

<org.fossify.commons.views.MyTextView
Expand Down Expand Up @@ -352,6 +357,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:divider="@color/dark_grey"
android:orientation="horizontal">

<org.fossify.commons.views.MyTextView
Expand Down Expand Up @@ -433,6 +439,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:divider="@color/dark_grey"
android:orientation="horizontal">

<org.fossify.commons.views.MyTextView
Expand Down
Loading
Loading