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

Refactor/code #133

Merged
merged 12 commits into from
Sep 7, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package com.depromeet.housekeeper

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.depromeet.housekeeper", appContext.packageName)
}
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.depromeet.housekeeper", appContext.packageName)
}
}
12 changes: 7 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<queries>
<package android:name="com.kakao.talk" />
</queries>

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

<application
android:name=".HouseKeeperApplication"
Expand All @@ -21,8 +22,8 @@
<activity
android:name=".ui.HouseKeeperActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.HouseKeeper.SplashScreen">
android:theme="@style/Theme.HouseKeeper.SplashScreen"
android:windowSoftInputMode="adjustResize">
<nav-graph android:value="@navigation/nav_graph" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -50,11 +51,12 @@
</activity>
<service
android:name=".service.FairerFirebaseMessagingService"
android:exported="false"
android:directBootAware="true">
android:directBootAware="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>

<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_launcher_fairer" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import timber.log.Timber

class HouseKeeperApplication : Application() {

override fun onCreate() {
super.onCreate()
PrefsManager.init(applicationContext)
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
override fun onCreate() {
super.onCreate()
PrefsManager.init(applicationContext)
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
KakaoSdk.init(this, resources.getString(R.string.KAKAO_NATIVE_APP_KEY))
}
KakaoSdk.init(this, resources.getString(R.string.KAKAO_NATIVE_APP_KEY))
}
}
82 changes: 42 additions & 40 deletions app/src/main/java/com/depromeet/housekeeper/data/RetrofitBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,54 @@ import retrofit2.converter.moshi.MoshiConverterFactory
import java.util.concurrent.TimeUnit

object RetrofitBuilder {
private const val BASE_URL = "http://ec2-3-39-60-64.ap-northeast-2.compute.amazonaws.com:8080"
private const val BASE_URL = "http://ec2-3-39-60-64.ap-northeast-2.compute.amazonaws.com:8080"

private val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
private val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}

private val okHttpBuilder = OkHttpClient.Builder()
.addInterceptor(NetworkInterceptor())
.addNetworkInterceptor(httpLoggingInterceptor)
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.writeTimeout(5, TimeUnit.SECONDS)
private val okHttpBuilder = OkHttpClient.Builder()
.addInterceptor(NetworkInterceptor())
.addNetworkInterceptor(httpLoggingInterceptor)
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(5, TimeUnit.SECONDS)
.writeTimeout(5, TimeUnit.SECONDS)

private val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
private val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()

private val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpBuilder.build())
.addConverterFactory(MoshiConverterFactory.create(moshi).asLenient())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()
private val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpBuilder.build())
.addConverterFactory(MoshiConverterFactory.create(moshi).asLenient())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()

val apiService: ApiService = retrofit.create(ApiService::class.java)
val apiService: ApiService = retrofit.create(ApiService::class.java)

private class NetworkInterceptor : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
return try {
chain.proceed(
request.newBuilder()
.addHeader("Authorization", PrefsManager.refreshToken.ifEmpty { PrefsManager.authCode })
.build()
)
} catch (e: Exception) {
Response.Builder()
.request(request)
.protocol(Protocol.HTTP_1_1)
.code(NETWORK_ERROR)
.message(e.message ?: "")
.body(ResponseBody.create(null, e.message ?: ""))
.build()
}
private class NetworkInterceptor : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
return try {
chain.proceed(
request.newBuilder()
.addHeader(
"Authorization",
PrefsManager.refreshToken.ifEmpty { PrefsManager.authCode })
.build()
)
} catch (e: Exception) {
Response.Builder()
.request(request)
.protocol(Protocol.HTTP_1_1)
.code(NETWORK_ERROR)
.message(e.message ?: "")
.body(ResponseBody.create(null, e.message ?: ""))
.build()
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.depromeet.housekeeper.data.remote


import com.depromeet.housekeeper.model.*
import com.depromeet.housekeeper.model.HouseWorkCreateResponse
import com.depromeet.housekeeper.model.LoginResponse
import retrofit2.http.*

interface ApiService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.depromeet.housekeeper.data.remote

import com.depromeet.housekeeper.model.*
import com.depromeet.housekeeper.model.HouseWorkCreateResponse
import com.depromeet.housekeeper.model.LoginResponse
import kotlinx.coroutines.flow.Flow

interface RemoteDataSource {
Expand All @@ -24,7 +22,11 @@ interface RemoteDataSource {
): Flow<UpdateChoreResponse>

suspend fun getDetailHouseWorks(houseWorkId: Int): Flow<HouseWork>
suspend fun getDateHouseWorkList(fromDate: String, toDate: String): Flow<Map<String, HouseWorks>>
suspend fun getDateHouseWorkList(
fromDate: String,
toDate: String
): Flow<Map<String, HouseWorks>>

suspend fun getPeriodHouseWorkListOfMember(
teamMemberId: Int,
fromDate: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.depromeet.housekeeper.data.repository

import com.depromeet.housekeeper.data.remote.RemoteDataSource
import com.depromeet.housekeeper.data.remote.RemoteDataSourceImpl
import com.depromeet.housekeeper.model.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

// mutex 사용할 일 있으면 여기서
// todo CoroutineScope Default로 받아와 결과 캐시 작업
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.depromeet.housekeeper.data.repository

import com.depromeet.housekeeper.model.*
import com.depromeet.housekeeper.data.remote.RemoteDataSource
import com.depromeet.housekeeper.model.HouseWorkCreateResponse
import com.depromeet.housekeeper.model.LoginResponse
import com.depromeet.housekeeper.data.RetrofitBuilder
import com.depromeet.housekeeper.data.remote.RemoteDataSource
import com.depromeet.housekeeper.model.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class Assignee(
val memberId: Int,
val memberName: String,
val profilePath: String,
): Parcelable
) : Parcelable

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class AssigneeSelect(
val memberId: Int,
val memberName: String,
val profilePath: String,
var selected: Boolean = false,
val memberId: Int,
val memberName: String,
val profilePath: String,
var selected: Boolean = false,
) : Parcelable

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.depromeet.housekeeper.model

data class BuildTeam(
val teamName : String
val teamName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
class BuildTeamResponse (
val inviteCode : String,
val teamId : Int
):Parcelable
class BuildTeamResponse(
val inviteCode: String,
val teamId: Int
) : Parcelable

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.Serializable

@Serializable
data class ChoreList(
val space : String,
val houseWorks : List<String>
val space: String,
val houseWorks: List<String>

)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class DayOfWeek(
val date: String, // ex) 2022-08-13-토
var isSelect: Boolean = false
val date: String, // ex) 2022-08-13-토
var isSelect: Boolean = false
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ data class GetInviteCode(
val inviteCode: String,
val inviteCodeExpirationDateTime: String,
val teamName: String
):Parcelable
) : Parcelable
20 changes: 10 additions & 10 deletions app/src/main/java/com/depromeet/housekeeper/model/HouseWork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class HouseWork(
val assignees: List<Assignee>,
val houseWorkId: Int,
val houseWorkName: String,
val scheduledDate: String,
val scheduledTime: String?,
val space: String,
val success: Boolean,
val successDateTime: String?,
var now: Int = 0,
): Parcelable
val assignees: List<Assignee>,
val houseWorkId: Int,
val houseWorkName: String,
val scheduledDate: String,
val scheduledTime: String?,
val space: String,
val success: Boolean,
val successDateTime: String?,
var now: Int = 0,
) : Parcelable
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.depromeet.housekeeper.model

import android.os.Parcelable
import com.depromeet.housekeeper.model.HouseWork
import kotlinx.parcelize.Parcelize

@Parcelize
data class HouseWorkCreateResponse(
val houseWorks: List<HouseWork>
): Parcelable
) : Parcelable
10 changes: 5 additions & 5 deletions app/src/main/java/com/depromeet/housekeeper/model/HouseWorks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class HouseWorks(
val countDone: Int,
val countLeft: Int,
val houseWorks: List<HouseWork>,
val scheduledDate: String,
val memberId: Int,
val countDone: Int,
val countLeft: Int,
val houseWorks: List<HouseWork>,
val scheduledDate: String,
val memberId: Int,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class InviteFailedResponse(
val code : Int,
val errorMessage : String,
val referrerUrl : String
):Parcelable
val code: Int,
val errorMessage: String,
val referrerUrl: String
) : Parcelable
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.depromeet.housekeeper.model

data class JoinTeam(
val inviteCode : String
val inviteCode: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class JoinTeamResponse(
val memberNames : List<String>,
val teamId : Int
):Parcelable
val memberNames: List<String>,
val teamId: Int
) : Parcelable
Loading