Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use one nav host #111

Closed
wants to merge 9 commits into from
Closed
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
13 changes: 8 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.baselineprofile)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.hilt)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.ksp)
alias(libs.plugins.secrets)
}
Expand All @@ -34,12 +36,12 @@ secrets {

android {
namespace = "com.google.android.samples.socialite"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.google.android.samples.socialite"
minSdk = 21
targetSdk = 34
targetSdk = 35
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -63,9 +65,6 @@ android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand Down Expand Up @@ -107,6 +106,7 @@ dependencies {

implementation(libs.activity.compose)
implementation(libs.navigation.compose)
implementation(libs.kotlinx.serialization.json)

implementation(libs.accompanist.painter)
implementation(libs.accompanist.permissions)
Expand All @@ -124,6 +124,9 @@ dependencies {
implementation(libs.splashscreen)
implementation(libs.concurrent.kts)

implementation(libs.core.performance)
implementation(libs.core.performance.play.services)

implementation(libs.camera.core)
implementation(libs.camera2)
implementation(libs.camera.lifecycle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.google.android.samples.socialite.repository

import androidx.test.platform.app.InstrumentationRegistry
import com.google.android.samples.socialite.data.createTestDatabase
import com.google.android.samples.socialite.widget.model.WidgetModelRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand All @@ -31,8 +30,6 @@ fun createTestRepository(): ChatRepository {
contactDao = database.contactDao(),
messageDao = database.messageDao(),
notificationHelper = NotificationHelper(context),
widgetModelRepository = WidgetModelRepository(database.widgetDao(), CoroutineScope(SupervisorJob() + Dispatchers.Default), context),
coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default),
appContext = InstrumentationRegistry.getInstrumentation().targetContext,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import app.cash.turbine.test
import com.google.android.samples.socialite.awaitNotEmpty
import com.google.android.samples.socialite.repository.createTestRepository
import com.google.android.samples.socialite.ui.home.chatlist.ChatListViewModel
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class HomeViewModelTest {
class ChatListViewModelTest {

@Test
fun initialize() = runTest {
val viewModel = HomeViewModel(createTestRepository())
val viewModel = ChatListViewModel(createTestRepository())
viewModel.chats.test {
assertThat(awaitNotEmpty()).hasSize(4)
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />

<!--
minSdk for this project is 21, but the PlayServicesDevicePerformance from the
core-performance-play-services dependency requires minSdk 24. We fall back to using
DefaultDevicePerformance from the core-performance dependency (minSdk 19) if the SDK level
is <24.
-->
<uses-sdk tools:overrideLibrary="androidx.core.performance.play.services" />

<application
android:name=".SocialApp"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ import com.google.android.samples.socialite.data.DatabaseManager
import com.google.android.samples.socialite.data.MessageDao
import com.google.android.samples.socialite.data.RoomDatabaseManager
import com.google.android.samples.socialite.data.populateInitialData
import com.google.android.samples.socialite.widget.model.WidgetModelDao
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.Executors
import javax.inject.Qualifier
import javax.inject.Singleton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.asCoroutineDispatcher

@Qualifier
annotation class AppCoroutineScope
Expand All @@ -49,14 +48,12 @@ object DatabaseModule {
@Singleton
fun providesAppDatabase(@ApplicationContext context: Context): AppDatabase =
Room.databaseBuilder(context, AppDatabase::class.java, "app.db")
.addCallback(
object : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
db.populateInitialData()
}
},
).build()
.addCallback(object : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
db.populateInitialData()
}
}).build()

@Provides
fun providesChatDao(database: AppDatabase): ChatDao = database.chatDao()
Expand All @@ -67,9 +64,6 @@ object DatabaseModule {
@Provides
fun providesContactDao(database: AppDatabase): ContactDao = database.contactDao()

@Provides
fun providesWidgetModelDao(database: AppDatabase): WidgetModelDao = database.widgetDao()

@Provides
@Singleton
@AppCoroutineScope
Expand Down
Loading