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

[Core] Teacher Home Feature #172

Merged
merged 24 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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: 4 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ gradlePlugin {
id = "b1nd.dodam.primitive.multiplatform.application"
implementationClass = "com.b1nd.dodam.primitive.MultiplatformApplicationPlugin"
}
register("multiplatformCoilPlugin") {
id = "b1nd.dodam.primitive.multiplatform.coil"
implementationClass = "com.b1nd.dodam.primitive.MultiplatformCoilPlugin"
}
// convention
register("androidFeature") {
id = "b1nd.dodam.convention.android.feature"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class KotlinSerializationPlugin : Plugin<Project> {
}
dependencies {
implementation(libs.library("kotlinx-serialization-json"))
implementation(libs.library("kotlinx-io-core"))
implementation(libs.library("kotlinx-io-bytestring"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.b1nd.dodam.primitive

import com.b1nd.dodam.dsl.kotlin
import com.b1nd.dodam.dsl.library
import com.b1nd.dodam.dsl.libs
import com.b1nd.dodam.dsl.setupMultiplatform
import org.gradle.api.Plugin
import org.gradle.api.Project

class MultiplatformCoilPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.plugin.serialization")
}

kotlin {
sourceSets.commonMain.dependencies {
implementation(libs.library("kotlinx-serialization-json"))
implementation(libs.library("kotlinx-io-core"))
implementation(libs.library("kotlinx-io-bytestring"))
implementation(libs.library("coil"))
implementation(libs.library("coil.compose"))
implementation(libs.library("coil.network.ktor"))
implementation(libs.library("ktor.client.core"))
}

sourceSets.androidMain.dependencies {
implementation(libs.library("coil.network.okhttp"))
}
sourceSets.iosMain.dependencies {
implementation(libs.library("ktor.client.darwin"))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class MultiplatformKotlinSerializationPlugin : Plugin<Project> {
sourceSets.commonMain {
dependencies {
implementation(libs.library("kotlinx-serialization-json"))
implementation(libs.library("kotlinx-io-core"))
implementation(libs.library("kotlinx-io-bytestring"))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ kotlin {
commonMain.dependencies {
implementation(libs.koin.core)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.datetime)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.b1nd.dodam.common.date

import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime

expect object DodamDate {
fun now(): LocalDateTime
fun localDateNow(): LocalDate
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.b1nd.dodam.common.utiles

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.joinAll

fun <T1, T2, R> combineWhenAllComplete(flow1: Flow<T1>, flow2: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R> = flow {
var lastValue1: T1? = null
var lastValue2: T2? = null

// 첫 번째 Flow 처리
val job1 = flow1.onEach { value ->
lastValue1 = value
}.launchIn(CoroutineScope(Dispatchers.IO))

// 두 번째 Flow 처리
val job2 = flow2.onEach { value ->
lastValue2 = value
}.launchIn(CoroutineScope(Dispatchers.IO))

joinAll(job1, job2)

// 두 Flow가 모두 종료되었을 때 마지막 값으로 변환 작업 수행
emit(transform(lastValue1!!, lastValue2!!))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.b1nd.dodam.common.date

import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toKotlinInstant
import kotlinx.datetime.toLocalDateTime
import platform.Foundation.NSDate
import platform.Foundation.now

actual object DodamDate {
actual fun now(): LocalDateTime = NSDate
.now()
.toKotlinInstant()
.toLocalDateTime(TimeZone.currentSystemDefault())

actual fun localDateNow(): LocalDate = now().date
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.b1nd.dodam.common.date

import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.toKotlinLocalDate
import kotlinx.datetime.toKotlinLocalDateTime

actual object DodamDate {
actual fun now(): LocalDateTime = java.time.LocalDateTime.now().toKotlinLocalDateTime()
actual fun localDateNow(): LocalDate = java.time.LocalDate.now().toKotlinLocalDate()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ interface NightStudyRepository {
fun askNightStudy(place: Place, content: String, doNeedPhone: Boolean, reasonForPhone: String?, startAt: LocalDate, endAt: LocalDate): Flow<Result<Unit>>

fun deleteNightStudy(id: Long): Flow<Result<Unit>>

fun getNightStudy(): Flow<Result<ImmutableList<NightStudy>>>

fun getNightStudyPending(): Flow<Result<ImmutableList<NightStudy>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,16 @@ internal class NightStudyRepositoryImpl(
emit(remote.deleteNightStudy(id))
}.asResult().flowOn(dispatcher)
}

override fun getNightStudy(): Flow<Result<ImmutableList<NightStudy>>> {
return flow {
emit(remote.getNightStudy().map { it.toModel() }.toImmutableList())
}.asResult().flowOn(dispatcher)
}

override fun getNightStudyPending(): Flow<Result<ImmutableList<NightStudy>>> {
return flow {
emit(remote.getNightStudyPending().map { it.toModel() }.toImmutableList())
}.asResult().flowOn(dispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import kotlinx.datetime.LocalDateTime
interface OutingRepository {
fun getMyOut(): Flow<Result<ImmutableList<Outing>>>

fun getOutings(date: LocalDate): Flow<Result<ImmutableList<Outing>>>

fun askOuting(reason: String, startAt: LocalDateTime, endAt: LocalDateTime): Flow<Result<Unit>>

fun getSleepovers(date: LocalDate): Flow<Result<ImmutableList<Outing>>>

fun askSleepover(reason: String, startAt: LocalDate, endAt: LocalDate): Flow<Result<Unit>>

fun deleteOuting(id: Long): Flow<Result<Unit>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,24 @@ internal class OutingRepositoryImpl(
}.asResult().flowOn(dispatcher)
}

override fun getOutings(date: LocalDate): Flow<Result<ImmutableList<Outing>>> {
return flow {
emit(network.getOutings(date).map { it.toModel() }.toImmutableList())
}.asResult().flowOn(dispatcher)
}

override fun askOuting(reason: String, startAt: LocalDateTime, endAt: LocalDateTime): Flow<Result<Unit>> {
return flow {
emit(network.askOuting(reason, startAt, endAt))
}.asResult().flowOn(dispatcher)
}

override fun getSleepovers(date: LocalDate): Flow<Result<ImmutableList<Outing>>> {
return flow {
emit(network.getSleepovers(date).map { it.toModel() }.toImmutableList())
}.asResult().flowOn(dispatcher)
}

override fun askSleepover(reason: String, startAt: LocalDate, endAt: LocalDate): Flow<Result<Unit>> {
return flow {
emit(network.askSleepover(reason, startAt, endAt))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.datetime.LocalDate

interface ScheduleRepository {
fun getScheduleBetweenPeriods(startDate: LocalDate, endDate: LocalDate): Flow<Result<ImmutableList<Schedule>>>
fun getScheduleBetweenPeriods(startAt: LocalDate, endAt: LocalDate): Flow<Result<ImmutableList<Schedule>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.b1nd.dodam.common.Dispatcher
import com.b1nd.dodam.common.DispatcherType
import com.b1nd.dodam.common.result.Result
import com.b1nd.dodam.common.result.asResult
import com.b1nd.dodam.common.utiles.javaFormat
import com.b1nd.dodam.data.schedule.ScheduleRepository
import com.b1nd.dodam.data.schedule.model.Schedule
import com.b1nd.dodam.data.schedule.model.toModel
Expand All @@ -21,12 +20,12 @@ internal class ScheduleRepositoryImpl constructor(
private val network: ScheduleDataSource,
@Dispatcher(DispatcherType.IO) private val dispatcher: CoroutineDispatcher,
) : ScheduleRepository {
override fun getScheduleBetweenPeriods(startDate: LocalDate, endDate: LocalDate): Flow<Result<ImmutableList<Schedule>>> {
override fun getScheduleBetweenPeriods(startAt: LocalDate, endAt: LocalDate): Flow<Result<ImmutableList<Schedule>>> {
return flow {
emit(
network.getScheduleBetweenPeriods(
String.javaFormat("%02d-%02d-%02d", startDate.year, startDate.monthNumber, startDate.dayOfMonth),
String.javaFormat("%02d-%02d-%02d", endDate.year, endDate.monthNumber, endDate.dayOfMonth),
startAt = startAt,
endAt = endAt,
).map {
it.toModel()
}.toImmutableList(),
Expand Down
28 changes: 22 additions & 6 deletions dodam-teacher-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ plugins {
alias(libs.plugins.dodam.multiplatform.application)
alias(libs.plugins.dodam.multiplatform.compose)
alias(libs.plugins.dodam.multiplatform.kotlin)
alias(libs.plugins.dodam.multiplatform.coil)
alias(libs.plugins.dodam.multiplatform.koin)
}
kotlin {
setIOS("DodamTeacher", "com.b1nd.dodam.teacher")

sourceSets {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.compose.activity)
implementation(libs.koin.android)
implementation(projects.keystore)
}
commonMain.dependencies {
implementation(libs.dodam.design.system.cmm)
implementation(projects.common)
implementation(projects.ui)
implementation(projects.network.login)

implementation(projects.feature.onboarding)
Expand All @@ -32,6 +28,26 @@ kotlin {
implementation(projects.network.register)
implementation(projects.common)
implementation(projects.network.core)
implementation(projects.featureTeacher.home)

implementation(projects.data.login)
implementation(projects.data.banner)
implementation(projects.data.meal)
implementation(projects.data.outing)
implementation(projects.data.nightStudy)
implementation(projects.data.schedule)
implementation(projects.network.banner)
implementation(projects.network.meal)
implementation(projects.network.outing)
implementation(projects.network.nightStudy)
implementation(projects.network.schedule)
}

androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.compose.activity)
implementation(libs.koin.android)
implementation(projects.keystore)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions dodam-teacher-android/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".utiles.DodamTeacherApplication"
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<activity
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.b1nd.dodam.teacher.utiles

import android.app.Application
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
import com.b1nd.dodam.teacher.getAsyncImageLoader

class DodamTeacherApplication : Application(), SingletonImageLoader.Factory {
override fun newImageLoader(context: PlatformContext): ImageLoader {
return getAsyncImageLoader(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.annotation.ExperimentalCoilApi
import coil3.compose.setSingletonImageLoaderFactory
import coil3.memory.MemoryCache
import coil3.network.ktor.KtorNetworkFetcherFactory
import coil3.request.crossfade
import coil3.util.DebugLogger
import com.b1nd.dodam.designsystem.DodamTheme
import com.b1nd.dodam.home.navigation.homeScreen
import com.b1nd.dodam.home.navigation.navigateToHome
import com.b1nd.dodam.login.navigation.loginScreen
import com.b1nd.dodam.login.navigation.navigationToLogin
import com.b1nd.dodam.onboarding.navigation.ONBOARDING_ROUTE
Expand All @@ -15,9 +25,12 @@ import com.b1nd.dodam.register.navigation.infoScreen
import com.b1nd.dodam.register.navigation.navigateToAuth
import com.b1nd.dodam.register.navigation.navigateToInfo

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalCoilApi::class)
@Composable
fun DodamTeacherApp() {
setSingletonImageLoaderFactory { context ->
getAsyncImageLoader(context)
}
val navHostController = rememberNavController()
DodamTheme {
NavHost(
Expand Down Expand Up @@ -49,9 +62,25 @@ fun DodamTeacherApp() {

loginScreen(
onBackClick = navHostController::popBackStack,
navigateToMain = {},
navigateToMain = navHostController::navigateToHome,
role = "TEACHER",
)

homeScreen()
}
}
}

@OptIn(ExperimentalCoilApi::class)
internal fun getAsyncImageLoader(context: PlatformContext) = ImageLoader.Builder(context)
.crossfade(true)
.memoryCache {
MemoryCache.Builder()
.maxSizePercent(context, percent = 0.25)
.build()
}
.logger(DebugLogger())
.components {
add(KtorNetworkFetcherFactory())
}
.build()
Loading
Loading