-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from TeamSparker/release-1.1.0
#551 재재업로드 Release 1.1.0
- Loading branch information
Showing
125 changed files
with
1,503 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/teamsparker/android/data/remote/calladapter/CustomCall.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.teamsparker.android.data.remote.calladapter | ||
|
||
import okhttp3.Request | ||
import okio.Timeout | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
import java.io.IOException | ||
|
||
class CustomCall<T : Any>(private val call: Call<T>) : Call<NetworkState<T>> { | ||
|
||
override fun enqueue(callback: Callback<NetworkState<T>>) { | ||
call.enqueue(object : Callback<T> { | ||
override fun onResponse(call: Call<T>, response: Response<T>) { | ||
val body = response.body() | ||
val code = response.code() | ||
val error = response.errorBody()?.string() | ||
|
||
if (response.isSuccessful) { | ||
if (body != null) { | ||
callback.onResponse( | ||
this@CustomCall, | ||
Response.success(NetworkState.Success(body)) | ||
) | ||
} else { | ||
callback.onResponse( | ||
this@CustomCall, | ||
Response.success( | ||
NetworkState.UnknownError( | ||
IllegalStateException("body값이 null로 넘어옴"), | ||
"body값이 null로 넘어옴" | ||
) | ||
) | ||
) | ||
} | ||
} else { | ||
callback.onResponse( | ||
this@CustomCall, | ||
Response.success(NetworkState.Failure(code, error)) | ||
) | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<T>, t: Throwable) { | ||
val errorResponse = when (t) { | ||
is IOException -> NetworkState.NetworkError(t) | ||
else -> NetworkState.UnknownError(t, "onFailure에 진입,IoException 이외의 에러") | ||
} | ||
callback.onResponse(this@CustomCall, Response.success(errorResponse)) | ||
} | ||
}) | ||
} | ||
|
||
override fun clone(): Call<NetworkState<T>> = CustomCall(call.clone()) | ||
|
||
override fun execute(): Response<NetworkState<T>> { | ||
throw UnsupportedOperationException("커스텀한 callAdapter에서는 execute를 사용하지 않습니다 ") | ||
} | ||
|
||
override fun isExecuted(): Boolean = call.isExecuted | ||
|
||
override fun cancel() = call.cancel() | ||
|
||
override fun isCanceled(): Boolean = call.isCanceled | ||
|
||
override fun request(): Request = call.request() | ||
|
||
override fun timeout(): Timeout = call.timeout() | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/teamsparker/android/data/remote/calladapter/CustomCallAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.teamsparker.android.data.remote.calladapter | ||
|
||
import retrofit2.Call | ||
import retrofit2.CallAdapter | ||
import java.lang.reflect.Type | ||
|
||
class CustomCallAdapter<R : Any>(private val responseType: Type) : | ||
CallAdapter<R, Call<NetworkState<R>>> { | ||
override fun responseType(): Type = responseType | ||
|
||
override fun adapt(call: Call<R>): Call<NetworkState<R>> = CustomCall(call) | ||
} |
38 changes: 38 additions & 0 deletions
38
...src/main/java/com/teamsparker/android/data/remote/calladapter/CustomCallAdapterFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.teamsparker.android.data.remote.calladapter | ||
|
||
import retrofit2.Call | ||
import retrofit2.CallAdapter | ||
import retrofit2.Retrofit | ||
import java.lang.reflect.ParameterizedType | ||
import java.lang.reflect.Type | ||
|
||
class CustomCallAdapterFactory : CallAdapter.Factory() { | ||
|
||
override fun get( | ||
returnType: Type, | ||
annotations: Array<out Annotation>, | ||
retrofit: Retrofit | ||
): CallAdapter<*, *>? { | ||
if (Call::class.java != getRawType(returnType)) { | ||
return null | ||
} | ||
|
||
check(returnType is ParameterizedType) { | ||
"return type must be parameterized as Call<NetworkState<Foo>> or Call<NetworkState<out Foo>>" | ||
} | ||
|
||
val responseType = getParameterUpperBound(0, returnType) | ||
|
||
if (getRawType(responseType) != NetworkState::class.java) { | ||
return null | ||
} | ||
|
||
check(responseType is ParameterizedType) { | ||
"Response must be parameterized as NetworkState<Foo> or NetworkState<out Foo>" | ||
} | ||
|
||
val bodyType = getParameterUpperBound(0, responseType) | ||
|
||
return CustomCallAdapter<Any>(bodyType) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/teamsparker/android/data/remote/calladapter/NetworkState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.teamsparker.android.data.remote.calladapter | ||
|
||
import java.io.IOException | ||
|
||
sealed class NetworkState<out T : Any> { | ||
|
||
// 200대 응답 성공한것 | ||
data class Success<T : Any>(val body: T) : NetworkState<T>() | ||
|
||
// isSuccessful 이 false인 경우(200~300대 응답이 아닌경우) | ||
data class Failure(val code: Int, val error: String?) : NetworkState<Nothing>() | ||
|
||
// onFailure로 넘어간경우(네트워크 오류,timeout 같은거) | ||
data class NetworkError(val error: IOException) : NetworkState<Nothing>() | ||
|
||
// 예상 못한에러(기타 모든 에러처리) | ||
data class UnknownError(val t: Throwable?, val errorState: String) : NetworkState<Nothing>() | ||
} |
3 changes: 3 additions & 0 deletions
3
...ain/java/com/teamsparker/android/data/remote/calladapter/RetrofitFaliureStateException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.teamsparker.android.data.remote.calladapter | ||
|
||
class RetrofitFailureStateException(error: String?, val code: Int) : Exception(error) |
14 changes: 14 additions & 0 deletions
14
...in/java/com/teamsparker/android/data/remote/datasource/HabitRoomTImeLineDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.teamsparker.android.data.remote.datasource | ||
|
||
import com.teamsparker.android.data.remote.calladapter.NetworkState | ||
import com.teamsparker.android.data.remote.entity.response.BaseResponse | ||
import com.teamsparker.android.data.remote.entity.response.HabitRoomTimeLine | ||
import com.teamsparker.android.data.remote.service.HabitRoomTimeLineService | ||
import javax.inject.Inject | ||
|
||
class HabitRoomTImeLineDataSourceImpl @Inject constructor( | ||
private val habitRoomTimeLineService: HabitRoomTimeLineService | ||
) : HabitRoomTimeLineDataSource { | ||
override suspend fun getHabitRoomTimeLine(roomId: Int): NetworkState<BaseResponse<HabitRoomTimeLine>> = | ||
habitRoomTimeLineService.getHabitRoomRimeLine(roomId) | ||
} |
10 changes: 10 additions & 0 deletions
10
...c/main/java/com/teamsparker/android/data/remote/datasource/HabitRoomTimeLineDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.teamsparker.android.data.remote.datasource | ||
|
||
import com.teamsparker.android.data.remote.calladapter.NetworkState | ||
import com.teamsparker.android.data.remote.entity.response.BaseResponse | ||
import com.teamsparker.android.data.remote.entity.response.HabitRoomTimeLine | ||
|
||
interface HabitRoomTimeLineDataSource { | ||
|
||
suspend fun getHabitRoomTimeLine(roomId: Int): NetworkState<BaseResponse<HabitRoomTimeLine>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ain/java/com/teamsparker/android/data/remote/entity/response/HabitRoomTimeLineResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.teamsparker.android.data.remote.entity.response | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class HabitRoomTimeLine( | ||
@SerializedName("timelines") | ||
val timelines: List<Timeline> | ||
) | ||
|
||
data class Timeline( | ||
@SerializedName("content") | ||
val content: String, | ||
@SerializedName("day") | ||
val day: String, | ||
@SerializedName("isNew") | ||
val isNew: Boolean, | ||
@SerializedName("profiles") | ||
val profiles: List<String>, | ||
@SerializedName("title") | ||
val title: String | ||
) |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/teamsparker/android/data/remote/repository/HabitRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package com.teamsparker.android.data.remote.repository | ||
|
||
import com.teamsparker.android.data.remote.entity.response.HabitRoomTimeLine | ||
|
||
interface HabitRepository { | ||
|
||
fun setHabitUserGuideState(state: Boolean) | ||
|
||
fun getHabitUserGuideState(): Boolean | ||
|
||
suspend fun getHabitRoomTimeLine(roomId: Int): Result<HabitRoomTimeLine> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/teamsparker/android/data/remote/service/HabitRoomTimeLineService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.teamsparker.android.data.remote.service | ||
|
||
import com.teamsparker.android.data.remote.calladapter.NetworkState | ||
import com.teamsparker.android.data.remote.entity.response.BaseResponse | ||
import com.teamsparker.android.data.remote.entity.response.HabitRoomTimeLine | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
interface HabitRoomTimeLineService { | ||
@GET("room/{roomId}/timeline") | ||
suspend fun getHabitRoomRimeLine( | ||
@Path("roomId") roomId: Int | ||
): NetworkState<BaseResponse<HabitRoomTimeLine>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.