Skip to content

Commit

Permalink
Merge pull request #236 from SWM-KAWAI-MANS/develop
Browse files Browse the repository at this point in the history
Release/v1.3.0
  • Loading branch information
nohjunh authored Oct 19, 2023
2 parents 3acd13e + ee71b64 commit 0bfe3aa
Show file tree
Hide file tree
Showing 86 changed files with 1,846 additions and 327 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

15 changes: 2 additions & 13 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import java.io.File
import java.io.FileInputStream
import java.util.*
import java.util.Properties

plugins {
id("nohjunh.android.application")
id("nohjunh.android.application.compose")
id("nohjunh.android.hilt")
id("com.google.gms.google-services")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
id("nohjunh.android.hilt")
}

val keystoreProperties = Properties()
Expand Down Expand Up @@ -79,21 +79,10 @@ android {
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
buildFeatures {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = Configurations.COMPOSE
}
kapt {
correctErrorTypes = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ fun SetUpMainNavGraph(
)

myPageRoute(
onSignOut = onSignOut,
navigateToSettings = {
navController.navigate(MainNavRoutes.Settings.route)
},
Expand All @@ -110,6 +109,20 @@ fun SetUpMainNavGraph(
navigateToProfile = {
navController.navigate(MainNavRoutes.Profile.route)
},
navigateToSingleResult = { isFromMyPage ->
navController.navigate("${MainNavRoutes.SingleResult.route}?isFromMyPage=$isFromMyPage") {
popUpTo(MainNavRoutes.MyPage.route) {
inclusive = false
}
}
},
navigateToBattleResult = { isFromMyPage ->
navController.navigate("${MainNavRoutes.BattleResult.route}?isFromMyPage=$isFromMyPage") {
popUpTo(MainNavRoutes.MyPage.route) {
inclusive = false
}
}
},
onShowSnackbar = onShowSnackbar
)

Expand All @@ -124,7 +137,7 @@ fun SetUpMainNavGraph(
navigateToBattleResult = {
navController.navigate(MainNavRoutes.BattleResult.route) {
popUpTo(MainNavRoutes.Battle.route) {
inclusive = false
inclusive = true
}
}
},
Expand All @@ -135,7 +148,7 @@ fun SetUpMainNavGraph(
navigateToSingleResult = {
navController.navigate(MainNavRoutes.SingleResult.route) {
popUpTo(MainNavRoutes.Single.route) {
inclusive = false
inclusive = true
}
}
},
Expand All @@ -145,10 +158,13 @@ fun SetUpMainNavGraph(
runningResultRoute(
navigateToTopLevel = {
navController.navigate(MainNavRoutes.Battle.route) {
popUpTo(MainNavRoutes.Battle.route) {
popUpTo(navController.graph.findStartDestination().id) {
inclusive = true
}
}
},
navigateToBack = {
navController.popBackStack()
}
)

Expand Down
4 changes: 4 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ gradlePlugin {
id = "nohjunh.android.library"
implementationClass = "AndroidLibraryConventionPlugin"
}
register("androidRoom") {
id = "nohjunh.android.room"
implementationClass = "AndroidRoomConventionPlugin"
}
register("androidFeature") {
id = "nohjunh.android.feature"
implementationClass = "AndroidFeatureConventionPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import com.google.devtools.ksp.gradle.KspExtension
import online.partyrun.partyrunapplication.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

class AndroidRoomConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
pluginManager.apply("com.google.devtools.ksp")

extensions.configure<KspExtension> {
}

dependencies {
add("implementation", libs.findLibrary("room.runtime").get())
add("implementation", libs.findLibrary("room.ktx").get())
add("ksp", libs.findLibrary("room.compiler").get())
}
}
}
}
6 changes: 2 additions & 4 deletions buildSrc/src/main/java/Configurations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ object Configurations {
const val MIN_SDK_VERSION = 26
const val TARGET_SDK_VERSION = 33
private const val MAJOR_VERSION = 1
private const val MINOR_VERSION = 2
private const val MINOR_VERSION = 3
private const val PATCH_VERSION = 0
const val VERSION_NAME = "$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION"
const val VERSION_CODE = 22
// kotlinCompilerExtensionVersion
const val COMPOSE = "1.4.5"
const val VERSION_CODE = 23
}
2 changes: 1 addition & 1 deletion core/common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.io.File
import java.io.FileInputStream
import java.util.*
import java.util.Properties

plugins {
id("nohjunh.android.library")
Expand Down
5 changes: 1 addition & 4 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ dependencies {
implementation(project(":core:datastore"))
implementation(project(":core:model"))
implementation(project(":core:network"))
implementation(project(":core:database"))

implementation(libs.androidx.core.ktx)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.serialization.json)

implementation(libs.hilt.android)
implementation(libs.androidx.hilt.navigation.compose)
kapt(libs.hilt.compiler)

implementation(libs.google.location)

testImplementation(project(":core:testing"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ package online.partyrun.partyrunapplication.core.data.repository
import kotlinx.coroutines.flow.Flow
import online.partyrun.partyrunapplication.core.model.running_result.battle.BattleResult
import online.partyrun.partyrunapplication.core.common.result.Result
import online.partyrun.partyrunapplication.core.model.my_page.BattleRunningHistory
import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord
import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory
import online.partyrun.partyrunapplication.core.model.running_result.single.SingleResult

interface ResultRepository {
suspend fun getBattleResults(): Flow<Result<BattleResult>>
suspend fun getSingleResults(): Flow<Result<SingleResult>>
suspend fun getComprehensiveRunRecord(): Flow<Result<ComprehensiveRunRecord>>
suspend fun updateSingleHistory(): Flow<Result<Unit>>
suspend fun updateBattleHistory(): Flow<Result<Unit>>
suspend fun getSingleHistory(): Flow<Result<SingleRunningHistory>>
suspend fun getBattleHistory(): Flow<Result<BattleRunningHistory>>
suspend fun deleteAllHistories(): Flow<Result<Unit>>

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,38 @@ package online.partyrun.partyrunapplication.core.data.repository

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import online.partyrun.partyrunapplication.core.common.network.apiRequestFlow
import online.partyrun.partyrunapplication.core.common.network.onException
import online.partyrun.partyrunapplication.core.common.network.onSuccess
import online.partyrun.partyrunapplication.core.datastore.datasource.BattlePreferencesDataSource
import online.partyrun.partyrunapplication.core.model.running_result.battle.BattleResult
import online.partyrun.partyrunapplication.core.network.datasource.ResultDataSource
import online.partyrun.partyrunapplication.core.network.model.response.toDomainModel
import online.partyrun.partyrunapplication.core.common.result.Result
import online.partyrun.partyrunapplication.core.common.result.mapResultModel
import online.partyrun.partyrunapplication.core.database.dao.BattleRunningHistoryDao
import online.partyrun.partyrunapplication.core.database.dao.SingleRunningHistoryDao
import online.partyrun.partyrunapplication.core.database.model.toDomainModel
import online.partyrun.partyrunapplication.core.datastore.datasource.SinglePreferencesDataSource
import online.partyrun.partyrunapplication.core.model.my_page.BattleRunningHistory
import online.partyrun.partyrunapplication.core.model.my_page.ComprehensiveRunRecord
import online.partyrun.partyrunapplication.core.model.my_page.SingleRunningHistory
import online.partyrun.partyrunapplication.core.model.running_result.single.SingleResult
import online.partyrun.partyrunapplication.core.network.model.response.toEntity
import javax.inject.Inject

class ResultRepositoryImpl @Inject constructor(
private val resultDataSource: ResultDataSource,
private val singleRunningHistoryDao: SingleRunningHistoryDao,
private val battleRunningHistoryDao: BattleRunningHistoryDao,
private val battlePreferencesDataSource: BattlePreferencesDataSource,
private val singlePreferencesDataSource: SinglePreferencesDataSource
) : ResultRepository {
companion object {
const val UNKNOWN_ERROR = "Unknown Error"
}

override suspend fun getBattleResults(): Flow<Result<BattleResult>> {
return apiRequestFlow {
Expand All @@ -33,4 +49,65 @@ class ResultRepositoryImpl @Inject constructor(
}.mapResultModel { it.toDomainModel() }
}

override suspend fun getComprehensiveRunRecord(): Flow<Result<ComprehensiveRunRecord>> {
return apiRequestFlow {
resultDataSource.getComprehensiveRunRecord()
}.mapResultModel { it.toDomainModel() }
}

override suspend fun updateSingleHistory(): Flow<Result<Unit>> = flow {
emit(Result.Loading)
val response = resultDataSource.getSingleHistory()
response.onSuccess { result ->
singleRunningHistoryDao.insertAllSingleRunningHistory(result.toEntity())
emit(Result.Success(Unit))
}.onException { e ->
emit(Result.Failure(e.message ?: UNKNOWN_ERROR, -1))
}
}

override suspend fun updateBattleHistory(): Flow<Result<Unit>> = flow {
emit(Result.Loading)
val response = resultDataSource.getBattleHistory()
response.onSuccess { result ->
battleRunningHistoryDao.insertAllBattleRunningHistory(result.toEntity())
emit(Result.Success(Unit))
}.onException { e ->
emit(Result.Failure(e.message ?: UNKNOWN_ERROR, -1))
}
}

override suspend fun getSingleHistory(): Flow<Result<SingleRunningHistory>> {
return singleRunningHistoryDao.getAllSingleRunningHistories()
.map { entityList ->
try {
Result.Success(SingleRunningHistory(entityList.map { it.toDomainModel() }))
} catch (e: Exception) {
Result.Failure(e.message ?: UNKNOWN_ERROR, -1)
}
}
}

override suspend fun getBattleHistory(): Flow<Result<BattleRunningHistory>> {
return battleRunningHistoryDao.getAllBattleRunningHistories()
.map { entityList ->
try {
Result.Success(BattleRunningHistory(entityList.map { it.toDomainModel() }))
} catch (e: Exception) {
Result.Failure(e.message ?: UNKNOWN_ERROR, -1)
}
}
}

override suspend fun deleteAllHistories(): Flow<Result<Unit>> = flow {
emit(Result.Loading)
try {
singleRunningHistoryDao.deleteAllSingleRunningHistories()
battleRunningHistoryDao.deleteAllBattleRunningHistories()
emit(Result.Success(Unit))
} catch (e: Exception) {
emit(Result.Failure(e.message ?: UNKNOWN_ERROR, -1))
}
}

}
1 change: 1 addition & 0 deletions core/database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
18 changes: 18 additions & 0 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("nohjunh.android.library")
id("nohjunh.android.hilt")
id("nohjunh.android.room")
}

android {
namespace = "online.partyrun.partyrunapplication.core.database"
}

dependencies {
implementation(project(":core:model"))

implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.datetime)

androidTestImplementation(project(":core:testing"))
}
4 changes: 4 additions & 0 deletions core/database/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package online.partyrun.partyrunapplication.core.database

import androidx.room.Database
import androidx.room.RoomDatabase
import online.partyrun.partyrunapplication.core.database.dao.BattleRunningHistoryDao
import online.partyrun.partyrunapplication.core.database.dao.SingleRunningHistoryDao
import online.partyrun.partyrunapplication.core.database.model.BattleRunningHistoryEntity
import online.partyrun.partyrunapplication.core.database.model.SingleRunningHistoryEntity

@Database(
entities = [SingleRunningHistoryEntity::class, BattleRunningHistoryEntity::class],
version = 1
)
abstract class PartyRunDatabase : RoomDatabase() {

abstract fun singleRunningHistoryDao(): SingleRunningHistoryDao

abstract fun battleRunningHistoryDao(): BattleRunningHistoryDao
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package online.partyrun.partyrunapplication.core.database.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
import online.partyrun.partyrunapplication.core.database.model.BattleRunningHistoryEntity

@Dao
interface BattleRunningHistoryDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAllBattleRunningHistory(historyEntities: List<BattleRunningHistoryEntity>)

@Query("SELECT * FROM battle_running_history_resource")
fun getAllBattleRunningHistories(): Flow<List<BattleRunningHistoryEntity>>

@Query("DELETE FROM battle_running_history_resource")
suspend fun deleteAllBattleRunningHistories()

}
Loading

0 comments on commit 0bfe3aa

Please sign in to comment.