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

[Team-04][Android][Linus_Jay][3주차 금요일 여섯번째 PR] #285

Open
wants to merge 17 commits into
base: team-04
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ plugins {

android {
compileSdk 32

packagingOptions {
pickFirst "META-INF/DEPENDENCIES"
}
defaultConfig {
applicationId "com.example.issu_tracker"
minSdk 23
Expand Down Expand Up @@ -38,8 +40,12 @@ android {
}

dependencies {

implementation 'com.google.code.gson:gson:2.9.0'

//Room
implementation "androidx.room:room-ktx:2.4.2"
implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.7.1'
kapt "androidx.room:room-compiler:2.4.2"
implementation "androidx.room:room-runtime:2.4.2"
annotationProcessor "androidx.room:room-compiler:2.4.2"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<application
android:name=".IssueTrackerApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/example/issu_tracker/data/Comment.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.issu_tracker.data

import androidx.room.Entity
import java.io.Serializable

@Entity
data class Comment(
val user: User? = null,
val content: String = "",
Expand Down
72 changes: 58 additions & 14 deletions app/src/main/java/com/example/issu_tracker/data/Issue.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.issu_tracker.data

import androidx.room.*
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.io.Serializable
import java.lang.Exception

data class IssueDto(
var id: String = "",
Expand All @@ -14,20 +16,62 @@ data class IssueDto(
val user: User? = null
)

data class Issue(
var id: String,
val comments: List<Comment>,
val description: String,
val label: List<Label>,
val mileStone: String,
val state: Boolean,
val title: String,
val user: User
) : Serializable

fun IssueDto.toIssue(): Issue? {
sealed class IssueList : Serializable {

object IssueProgressBar : IssueList()

@Entity
data class Issue(
@ColumnInfo(name = "issue_id")
var id: String,
val comments: List<Comment>,
val description: String,
val label: List<Label>,
val mileStone: String,
val state: Boolean,
val title: String,
@Embedded
val user: User
) : IssueList(), Serializable {
@PrimaryKey(autoGenerate = true)
var idx: Int = 0
}
}
Comment on lines +19 to +39

Choose a reason for hiding this comment

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

sealed class 로 구현하셨던 이유가 무엇일까요?


class Converters {
@TypeConverter
fun fromCommentList(comments: List<Comment>): String? {
val gson = Gson()
val type = object : TypeToken<List<Comment>>() {}.type
return gson.toJson(comments, type)
}

@TypeConverter
fun toCommentList(value: String?): List<Comment> {
val gson = Gson()
val type = object : TypeToken<List<Comment>>() {}.type
return gson.fromJson(value, type)
}

@TypeConverter
fun fromLabelList(comments: List<Label>): String? {
val gson = Gson()
val type = object : TypeToken<List<Label>>() {}.type
return gson.toJson(comments, type)
}

@TypeConverter
fun toLabelList(value: String?): List<Label> {
val gson = Gson()
val type = object : TypeToken<List<Label>>() {}.type
return gson.fromJson(value, type)
}

}

fun IssueDto.toIssue(): IssueList.Issue? {
return try {
Issue(id, comments, description, label, mileStoneID, state, title, user!!)
IssueList.Issue(id, comments, description, label, mileStoneID, state, title, user!!)
} catch (e: Exception) {
null
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/example/issu_tracker/data/Label.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.issu_tracker.data

import androidx.room.Entity
import java.io.Serializable

@Entity
data class Label(val color: String = "", val content: String = "") :Serializable
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/issu_tracker/data/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.room.PrimaryKey
import java.io.Serializable

@Entity
data class User(val UID: String = "", val name: String = "", val userPhoto: String?=null) :
data class User(val uid: String = "", val name: String = "", val userPhoto: String?=null) :
Serializable {
@PrimaryKey(autoGenerate = true)
var id: Int = 0
Expand Down

This file was deleted.

26 changes: 26 additions & 0 deletions app/src/main/java/com/example/issu_tracker/data/local/IssueDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.issu_tracker.data.local

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import com.example.issu_tracker.data.IssueList


@Dao
interface IssueDao {
@Insert
suspend fun insert(issue: IssueList.Issue)

@Delete
suspend fun delete(issue: IssueList.Issue)

@Query("SELECT * FROM Issue") // 테이블의 모든 값을 가져와라
suspend fun getAll(): List<IssueList.Issue>

@Query("DELETE FROM Issue WHERE id = :id")
suspend fun deleteIssueByName(id: String)

@Query("DELETE FROM Issue")
suspend fun deleteAllIssue()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.issu_tracker.data.local

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.example.issu_tracker.data.Converters
import com.example.issu_tracker.data.IssueList
import com.example.issu_tracker.data.User

@Database(entities = [User::class , IssueList.Issue::class ], version = 2,exportSchema = false)
@TypeConverters(Converters::class)
abstract class IssueTrackerDatabase : RoomDatabase() {
abstract fun userDao(): UserDao
abstract fun issueDao(): IssueDao
}
Comment on lines +10 to +15

Choose a reason for hiding this comment

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

Use, Issue 정보를 Disk 에 저장하는 이유가 있나용?
Memory 에 저장해도 되지 않았나 싶네요 ㅎㅎ

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ interface UserDao {
@Insert
suspend fun insert(user: User)

@Update
suspend fun update(user: User)

@Delete
suspend fun delete(user: User)

Expand All @@ -21,8 +18,8 @@ interface UserDao {
@Query("DELETE FROM User WHERE name = :name")
suspend fun deleteUserByName(name: String)

@Query("UPDATE User SET userPhoto =:userPhoto,name=:name WHERE UID = :UID")
suspend fun updateUser(userPhoto: String, UID: String, name: String)
@Query("UPDATE User SET userPhoto =:userPhoto,name=:name WHERE uid = :uid")
suspend fun updateUser(userPhoto: String, uid: String, name: String)

@Query("DELETE FROM User")
suspend fun deleteAllUsers()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.issu_tracker.data.network

sealed class NetworkResult<T : Any> {
class Success<T : Any>(val data: T) : NetworkResult<T>()
class Cached<T : Any>(val data: T) : NetworkResult<T>()
class Loading<T : Any> : NetworkResult<T>()
class Error<T : Any>(val code: Int = EMPTY) : NetworkResult<T>()
class Exception<T : Any>(val e: Throwable) : NetworkResult<T>()
Comment on lines +7 to +8

Choose a reason for hiding this comment

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

ErrorException 을 구분하셨던 이유가 있나요?? (궁금해서요 ㅎㅎ)

companion object {
const val EMPTY = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.example.issu_tracker.data.repository

import android.util.Log
import com.example.issu_tracker.data.User
import com.example.issu_tracker.data.network.NetworkResult
import kotlinx.coroutines.tasks.await

interface FriendRemoteRepository {

suspend fun loadFriendList(): List<User>
suspend fun loadFriendList(): NetworkResult<List<User>>
suspend fun updateFriend(users: List<User>)

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,46 @@ package com.example.issu_tracker.data.repository

import android.util.Log
import com.example.issu_tracker.data.User
import com.example.issu_tracker.data.network.NetworkResult
import com.example.issu_tracker.data.network.NetworkResult.Companion.EMPTY
import com.example.issu_tracker.ui.home.userUid
import com.google.firebase.firestore.FirebaseFirestore
import com.google.protobuf.Empty
import kotlinx.coroutines.tasks.await
import java.lang.Exception
import java.lang.StringBuilder
import javax.inject.Inject


class FriendRemoteRepositoryIml @Inject constructor(private val fireStore: FirebaseFirestore) :
FriendRemoteRepository {

override suspend fun loadFriendList(): List<User> {
val userData =
fireStore.collection(HomeRepositoryImpl.FIREBASE_COLLECTION_FRIEND_PATH)
.document(userUid).get().await()
val friendData = userData["friend"] as List<Map<String, String>>
Log.d("friend", friendData.toString())

val friendList = mutableListOf<User>()

friendData.forEach {
val user =
User(
it["UID"] ?: "", it["name"] ?: "",
it["userPhoto"] ?: ""
)
friendList.add(user)
override suspend fun loadFriendList(): NetworkResult<List<User>> {
try {
val userData =
fireStore.collection(HomeRepositoryImpl.FIREBASE_COLLECTION_FRIEND_PATH)
.document(userUid).get().await()
val friendData = userData["friend"] as List<Map<String, String>>
Log.d("friend", friendData.toString())

val friendList = mutableListOf<User>()

friendData.forEach {
val user =
User(
it["uid"] ?: "", it["name"] ?: "",
it["userPhoto"] ?: ""
)
friendList.add(user)
}
Comment on lines +29 to +36

Choose a reason for hiding this comment

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

map 연산자를 사용하면 좀더 깔끔하겠네요~ ㅎㅎ

return if (friendList.isNotEmpty()) {
NetworkResult.Success(friendList)
} else {
NetworkResult.Error(EMPTY)
}
} catch (e: Exception) {
return NetworkResult.Exception(e)
}
return friendList
}

override suspend fun updateFriend(users: List<User>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.example.issu_tracker.data.repository

import com.example.issu_tracker.data.Issue
import com.example.issu_tracker.data.IssueList
import com.example.issu_tracker.data.IssueList.Issue
import com.example.issu_tracker.data.User
import com.example.issu_tracker.data.network.NetworkResult

interface HomeRepository {

suspend fun loadIssues(): List<Issue>
suspend fun loadFirstPageIssues(): NetworkResult<List<IssueList>>
suspend fun loadNextPageIssues(currentNumber: Int): List<IssueList>
suspend fun updateIssueState(itemId: String, boolean: Boolean)
suspend fun deleteIssueList(list: List<IssueList>)
suspend fun updateIssueListState(list: List<IssueList>, boolean: Boolean)

suspend fun deleteIssueList(list: List<Issue>)

suspend fun updateIssueListState(list: List<Issue>, boolean: Boolean)
}
Loading