Skip to content

Commit

Permalink
[WIP] WebcalSubscriptionsActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Oct 17, 2023
1 parent b78992b commit 0045b92
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ dependencies {
kapt "com.google.dagger:hilt-android-compiler:${versions.hilt}" // replace by KSP when ready [https://issuetracker.google.com/179057202]

// support libs
implementation 'androidx.activity:activity-compose:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.browser:browser:1.6.0'
implementation 'androidx.cardview:cardview:1.0.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.bitfire.davdroid.db

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
Expand All @@ -13,6 +14,9 @@ interface WebcalSubscriptionDao {
@Query("SELECT * FROM webcal_subscription WHERE collectionId=:collectionId")
fun getByCollectionId(collectionId: Long): WebcalSubscription?

@Query("SELECT * FROM webcal_subscription ORDER BY displayName, url")
fun getLive(): LiveData<List<WebcalSubscription>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(subscription: WebcalSubscription): Long

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,99 @@
package at.bitfire.davdroid.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.twotone.ShoppingCart
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModel
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.R
import at.bitfire.davdroid.db.AppDatabase
import at.bitfire.davdroid.db.WebcalSubscription
import com.google.accompanist.themeadapter.material.MdcTheme
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.HttpUrl.Companion.toHttpUrl
import javax.inject.Inject

@AndroidEntryPoint
class WebcalSubscriptionsActivity: ComponentActivity() {

val model by viewModels<Model>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
MdcTheme {
Scaffold(
topBar = {
TopAppBar(
navigationIcon = {
IconButton(onClick = { onBackPressedDispatcher.onBackPressed() }) {
Icon(imageVector = Icons.Filled.ArrowBack, contentDescription = null)
}
},
title = {
Text(stringResource(R.string.webcal_subscriptions))
}
)
}
) { paddingValues ->
Column(Modifier.padding(paddingValues)) {
model.subscriptions.observeAsState().value?.forEach { subscription ->
SubscriptionItem(subscription)
}
}
}
}
}
}


@Composable
fun SubscriptionItem(subscription: WebcalSubscription) {
Column(Modifier.padding(vertical = 8.dp)) {
Text(subscription.displayName ?: "")
Text(subscription.url.toString())

if (subscription.collectionId != null)
Icon(imageVector = Icons.TwoTone.ShoppingCart, contentDescription = null)
}
}

@Composable
@Preview
fun SubscriptionItem_Sample() {
SubscriptionItem(WebcalSubscription(
id = 0,
collectionId = 1,
calendarId = null,
"https://example.com".toHttpUrl(),
displayName = "Sample Calendar",
color = Constants.DAVDROID_GREEN_RGBA
))
}


@HiltViewModel
class Model @Inject constructor(
db: AppDatabase
): ViewModel() {

val subscriptions = db.webcalSubscriptionDao().getLive()

}

class WebcalSubscriptionsActivity: AppCompatActivity() {
}

0 comments on commit 0045b92

Please sign in to comment.