Skip to content
Open
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,6 @@ docs/.idea
node_modules/

# Kotlin
.kotlin/
.kotlin/

/app/full/**
8 changes: 8 additions & 0 deletions .idea/markdown.xml
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the file and add it to .gitignore.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ kotlin {

dependencies {

implementation 'androidx.work:work-runtime-ktx:2.11.2'
implementation 'androidx.hilt:hilt-common:1.3.0'
Comment thread
dahool marked this conversation as resolved.
implementation 'androidx.hilt:hilt-work:1.3.0'

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'

implementation 'androidx.core:core-ktx:1.17.0'
Expand Down Expand Up @@ -165,6 +169,10 @@ dependencies {

implementation 'sh.calvin.reorderable:reorderable:2.5.1'

implementation "androidx.room:room-runtime:2.7.1"
implementation "androidx.room:room-ktx:2.7.1"
ksp "androidx.room:room-compiler:2.7.1"

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
Expand All @@ -179,3 +187,7 @@ dependencies {
kapt {
correctErrorTypes true
}

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
37 changes: 37 additions & 0 deletions app/full/release/output-metadata.json
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the file. Looks like it has been added before the new .gitignore rule was added.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "de.lukasneugebauer.nextcloudcookbook",
"variantName": "fullRelease",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 62,
"versionName": "0.28.0",
"outputFile": "app-full-release.apk"
}
],
"elementType": "File",
"baselineProfiles": [
{
"minApi": 28,
"maxApi": 30,
"baselineProfiles": [
"baselineProfiles/1/app-full-release.dm"
]
},
{
"minApi": 31,
"maxApi": 2147483647,
"baselineProfiles": [
"baselineProfiles/0/app-full-release.dm"
]
}
],
"minSdkVersionForDexing": 25
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "b7547243a2a3d2d6dbb4309e1c15ee3f",
"entities": [
{
"tableName": "recipe_previews",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `keywords` TEXT, `category` TEXT, `dateCreated` TEXT, `dateModified` TEXT, `imageUrl` TEXT, `imagePlaceholderUrl` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "keywords",
"columnName": "keywords",
"affinity": "TEXT"
},
{
"fieldPath": "category",
"columnName": "category",
"affinity": "TEXT"
},
{
"fieldPath": "dateCreated",
"columnName": "dateCreated",
"affinity": "TEXT"
},
{
"fieldPath": "dateModified",
"columnName": "dateModified",
"affinity": "TEXT"
},
{
"fieldPath": "imageUrl",
"columnName": "imageUrl",
"affinity": "TEXT"
},
{
"fieldPath": "imagePlaceholderUrl",
"columnName": "imagePlaceholderUrl",
"affinity": "TEXT"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "recipes",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `json` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "json",
"columnName": "json",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
}
},
{
"tableName": "categories",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `recipeCount` INTEGER NOT NULL, PRIMARY KEY(`name`))",
"fields": [
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "recipeCount",
"columnName": "recipeCount",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"name"
]
}
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'b7547243a2a3d2d6dbb4309e1c15ee3f')"
]
}
}
15 changes: 14 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

Expand All @@ -14,6 +15,18 @@
android:theme="@style/Theme.NextcloudCookbook.Splash"
android:usesCleartextTraffic="true"
android:enableOnBackInvokedCallback="false">

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>

<activity
android:name=".core.presentation.MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package de.lukasneugebauer.nextcloudcookbook

import android.app.Application
import android.content.Context
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
Expand All @@ -24,10 +26,22 @@ import java.time.LocalDate
import javax.inject.Inject

@HiltAndroidApp
class NextcloudCookbookApplication : Application() {
class NextcloudCookbookApplication :
Application(),
Configuration.Provider {
@Inject
lateinit var clientProvider: OkHttpClientProvider

@Inject
lateinit var workerFactory: HiltWorkerFactory

override val workManagerConfiguration: Configuration
get() =
Configuration
.Builder()
.setWorkerFactory(workerFactory)
.build()

private val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

override fun onCreate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun SplashScreen(

LaunchedEffect(key1 = uiState) {
when (uiState) {
SplashScreenState.Initial -> viewModel.initialize()
SplashScreenState.Initial -> {}
SplashScreenState.Authorized -> {
mainViewModel.finishSplash()
navigator.navigate(HomeScreenDestination) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package de.lukasneugebauer.nextcloudcookbook.auth.presentation.splash

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.work.ExistingWorkPolicy
import androidx.work.WorkManager
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import de.lukasneugebauer.nextcloudcookbook.auth.domain.state.SplashScreenState
import de.lukasneugebauer.nextcloudcookbook.core.domain.repository.AccountRepository
import de.lukasneugebauer.nextcloudcookbook.core.util.Resource
import de.lukasneugebauer.nextcloudcookbook.core.worker.SyncWorker
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
Expand All @@ -19,22 +24,32 @@ class SplashViewModel
@Inject
constructor(
private val accountRepository: AccountRepository,
@ApplicationContext private val context: Context,
) : ViewModel() {
private val _uiState = MutableStateFlow<SplashScreenState>(SplashScreenState.Initial)
val uiState: StateFlow<SplashScreenState> = _uiState

fun initialize() {
init {
accountRepository
.getAccount()
.distinctUntilChanged()
.onEach { account ->
val userMetadata = accountRepository.getUserMetadata()

if (account is Resource.Success && userMetadata is Resource.Success) {
if (account is Resource.Success) {
triggerInitialSync()
_uiState.update { SplashScreenState.Authorized }
} else {
_uiState.update { SplashScreenState.Unauthorized }
}
}.launchIn(viewModelScope)
}

private fun triggerInitialSync() {
WorkManager
.getInstance(context)
.enqueueUniqueWork(
"sync_initial",
ExistingWorkPolicy.KEEP,
SyncWorker.buildOneTimeRequest(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.lukasneugebauer.nextcloudcookbook.category.data.dto.mapper

import de.lukasneugebauer.nextcloudcookbook.category.data.dto.CategoryDto
import de.lukasneugebauer.nextcloudcookbook.category.domain.model.CategoryEntity

fun CategoryEntity.toDto(): CategoryDto =
CategoryDto(
name = name,
recipeCount = recipeCount,
)

fun CategoryDto.toEntity(): CategoryEntity =
CategoryEntity(
name = name,
recipeCount = recipeCount,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.lukasneugebauer.nextcloudcookbook.category.domain.dao

import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Upsert
import de.lukasneugebauer.nextcloudcookbook.category.domain.model.CategoryEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface CategoryDao {
@Query("SELECT * FROM categories")
fun getAll(): Flow<List<CategoryEntity>>

@Upsert
suspend fun upsertAll(categories: List<CategoryEntity>)

@Query("DELETE FROM categories")
suspend fun deleteAll()

@Transaction
suspend fun replaceCategories(categories: List<CategoryEntity>) {
deleteAll()
upsertAll(categories)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.lukasneugebauer.nextcloudcookbook.category.domain.model

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "categories")
data class CategoryEntity(
@PrimaryKey val name: String,
val recipeCount: Int,
)
Loading
Loading