Skip to content

Commit

Permalink
[bugfix] item cannot be deselected
Browse files Browse the repository at this point in the history
[bugfix] MainActivity calls finish() too early
update readme images
  • Loading branch information
Steve-Mr committed May 17, 2024
1 parent de3bcc8 commit e593632
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish()
return
}
// if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
// finish()
// return
// }

// Set the result to CANCELED initially to handle the case where the user backs out
val resultValue = Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class CalendarWidget : GlanceAppWidget() {
.cornerRadius(16.dp)
.clickable {
calendarContentResolver.getThreeEventsForCalendar()
calendarContentResolver.getWeeklyEventsForCalendar()
}
.background(GlanceTheme.colors.inversePrimary)
.padding(4.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.core.content.ContextCompat
import androidx.glance.appwidget.GlanceAppWidgetManager
import androidx.lifecycle.viewmodel.compose.viewModel
import com.maary.yetanothercalendarwidget.CalendarContentResolver
import com.maary.yetanothercalendarwidget.R
import com.maary.yetanothercalendarwidget.calendarwidget.CalendarWidget
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -82,11 +84,18 @@ fun CalendarsListScreen(appWidgetId: Int) {
floatingActionButton = {
FloatingActionButton(onClick = {
viewModel.finishSelection()
coroutineScope.launch {
val manager = GlanceAppWidgetManager(context)
val widget = CalendarWidget()
val glanceIds = manager.getGlanceIds(widget.javaClass)
glanceIds.forEach { glanceId ->
widget.update(context, glanceId)
}
}
val resultIntent = Intent().apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
}
(context as? Activity)?.setResult(Activity.RESULT_OK, resultIntent)

(context as? Activity)?.finish()
}) {
Icon(painter = painterResource(id = R.drawable.ic_done), contentDescription = null)
Expand Down Expand Up @@ -129,11 +138,4 @@ fun CalendarItem(
Text(calendar.displayName)
},
)
}


//@Preview(showSystemUi = true)
//@Composable
//fun CalendarsListScreenPreview() {
// CalendarsListScreen()
//}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ class CalendarsViewModel @Inject constructor(

fun selectCalendar(id: Long) {
_selected.update {
_selected.value.plus(id)
if (_selected.value.contains(id)) {
_selected.value.minus(id)
}else {
_selected.value.plus(id)
}
}
}

fun finishSelection() {
viewModelScope.launch {
preferenceRepository.setCalendars(_selected.value)
calendarContentResolver.getWeeklyEventsForCalendar()
calendarContentResolver.getThreeEventsForCalendar()
Log.v("CAS", "${_selected.value}")
}
}
Expand Down
Binary file modified imgs/3days.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified imgs/weekly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e593632

Please sign in to comment.