Skip to content

Commit

Permalink
update dependency
Browse files Browse the repository at this point in the history
launch configure activity on widget added to home screen
small widget layout adjustment
  • Loading branch information
Steve-Mr committed May 17, 2024
1 parent 6113c47 commit de3bcc8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "com.maary.yetanothercalendarwidget"
minSdk = 31
targetSdk = 34
versionCode = 2
versionName = "1.0Alpha.2"
versionCode = 3
versionName = "1.0Alpha.3"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.YetAnotherCalendarWidget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>

<receiver android:name=".calendarwidget.CalendarWidgetReceiver"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.maary.yetanothercalendarwidget

import android.appwidget.AppWidgetManager
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.maary.yetanothercalendarwidget.ui.CalendarsListScreen
import com.maary.yetanothercalendarwidget.ui.theme.YetAnotherCalendarWidgetTheme
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -20,32 +19,25 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
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)
setResult(RESULT_CANCELED, resultValue)
setContent {
YetAnotherCalendarWidgetTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
CalendarsListScreen()
CalendarsListScreen(appWidgetId)
}
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
YetAnotherCalendarWidgetTheme {
Greeting("Android")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.glance.layout.Box
import androidx.glance.layout.Column
import androidx.glance.layout.Row
import androidx.glance.layout.Spacer
import androidx.glance.layout.fillMaxSize
import androidx.glance.layout.fillMaxWidth
import androidx.glance.layout.height
import androidx.glance.layout.padding
Expand Down Expand Up @@ -66,7 +67,8 @@ class CalendarWidget : GlanceAppWidget() {
val weeklyEvents = calendarContentResolver.weeklyEventsStateFlow.collectAsState().value
val threeDayEvents = calendarContentResolver.threeDayEventsStateFlow.collectAsState().value

Box(contentAlignment = Alignment.TopEnd) {
Box(modifier = GlanceModifier.fillMaxSize(),
contentAlignment = Alignment.TopEnd) {
if (isWeekView) {
WeekView(events = weeklyEvents)
} else {
Expand Down Expand Up @@ -243,7 +245,7 @@ class CalendarWidget : GlanceAppWidget() {
tag: String,
background: ColorProvider
) {
Column {
Column (modifier = GlanceModifier.padding(4.dp)){
DayTag(tag = tag)

Spacer(GlanceModifier.height(8.dp).padding(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.maary.yetanothercalendarwidget.ui

import android.Manifest
import android.app.Activity
import android.appwidget.AppWidgetManager
import android.content.Intent
import android.content.pm.PackageManager
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
Expand All @@ -24,7 +26,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.content.ContextCompat
import androidx.lifecycle.viewmodel.compose.viewModel
import com.maary.yetanothercalendarwidget.CalendarContentResolver
Expand All @@ -33,7 +34,7 @@ import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CalendarsListScreen() {
fun CalendarsListScreen(appWidgetId: Int) {

val context = LocalContext.current

Expand Down Expand Up @@ -81,10 +82,14 @@ fun CalendarsListScreen() {
floatingActionButton = {
FloatingActionButton(onClick = {
viewModel.finishSelection()
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)

}
}
) { innerPadding ->
Expand All @@ -97,11 +102,6 @@ fun CalendarsListScreen() {
calendars.value[index],
onItemClick = {
coroutineScope.launch {
// runBlocking {
// preferenceRepository.setCalendars(calendars.value[index].id.toString())
// }
// Log.v("CAS", calendars.value[index].id.toString())
// (context as? Activity)?.finish()
calendars.value[index].id?.let { viewModel.selectCalendar(it) }
}
}
Expand Down Expand Up @@ -132,8 +132,8 @@ fun CalendarItem(
}


@Preview(showSystemUi = true)
@Composable
fun CalendarsListScreenPreview() {
CalendarsListScreen()
}
//@Preview(showSystemUi = true)
//@Composable
//fun CalendarsListScreenPreview() {
// CalendarsListScreen()
//}
2 changes: 1 addition & 1 deletion app/src/main/res/xml/calendar_widget_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:updatePeriodMillis="10800000"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen"
android:widgetFeatures="reconfigurable|configuration_optional"
android:widgetFeatures="reconfigurable"
android:configure="com.maary.yetanothercalendarwidget.MainActivity">

</appwidget-provider>
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[versions]
agp = "8.4.0"
datastorePreferences = "1.1.1"
glanceAppwidget = "1.1.0-beta02"
glanceAppwidget = "1.1.0-rc01"
hiltAndroid = "2.51.1"
hiltAndroidCompiler = "2.51.1"
kotlin = "1.9.23"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.7.0"
lifecycleRuntimeKtx = "2.8.0"
activityCompose = "1.9.0"
composeBom = "2024.05.00"
lifecycleViewmodelCompose = "2.7.0"
lifecycleViewmodelCompose = "2.8.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down

0 comments on commit de3bcc8

Please sign in to comment.