Skip to content

Commit

Permalink
#45 splash view 및 에러 페이지 추가 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
junhyung0927 authored Jun 13, 2022
1 parent 901ff2f commit ddaaa51
Show file tree
Hide file tree
Showing 34 changed files with 1,757 additions and 8 deletions.
20 changes: 20 additions & 0 deletions .idea/misc.xml

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

3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
android:usesCleartextTraffic="true">

<activity
android:name="github.dev_playground.jeju_road.presentation.ui.main.MainActivity"
android:name="github.dev_playground.jeju_road.presentation.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".presentation.ui.main.MainActivity"/>
<activity android:name="github.dev_playground.jeju_road.presentation.ui.page.RestaurantDetailActivity" />
<activity android:name="github.dev_playground.jeju_road.presentation.ui.image.FullSizeImageActivity" />
</application>
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/java/Dep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ object Dep {
const val analytics = "com.google.firebase:firebase-analytics-ktx"
}

const val lottie = "com.airbnb.android:lottie:5.0.3"
const val gson = "com.google.code.gson:gson:2.8.7"
const val photoView = "com.github.chrisbanes:PhotoView:2.3.0"
const val shimmer = "com.facebook.shimmer:shimmer:0.5.0"
Expand Down
2 changes: 2 additions & 0 deletions data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="github.dev_playground.jeju_road.data">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package github.dev_playground.jeju_road.data.di

import github.dev_playground.jeju_road.data.api.RestaurantApi
import github.dev_playground.jeju_road.data.api.mock.MockRestaurantApi
import github.dev_playground.jeju_road.data.util.NetworkHealthCheckingInterceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.android.ext.koin.androidApplication
import org.koin.android.ext.koin.androidContext
import org.koin.core.qualifier.named
import org.koin.dsl.module
Expand All @@ -24,6 +26,7 @@ val networkModule = module {
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.addNetworkInterceptor(NetworkHealthCheckingInterceptor())
.addNetworkInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
Expand All @@ -38,7 +41,7 @@ val networkModule = module {
.build()
}

// single { get<Retrofit>().create(RestaurantApi::class.java) }
single<RestaurantApi> { MockRestaurantApi(androidContext()) }
single { get<Retrofit>().create(RestaurantApi::class.java) }
// single<RestaurantApi> { MockRestaurantApi(androidContext()) }

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ internal class RestaurantRepositoryImpl(
}.getOrThrow()
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package github.dev_playground.jeju_road.data.util

import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class NetworkHealthCheckingInterceptor() : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val response = chain.proceed(request)

if (response.code == 500) {
throw ConnectionShutdownException()
}
return response
}
}

class ConnectionShutdownException : IOException() {
override val message: String
get() = "500 ERROR: 서버가 종료되었습니다. 다시 시도해주세요."
}
1 change: 1 addition & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
implementation(Dep.Glide.glide)
implementation(Dep.Glide.glideCompiler)
implementation(Dep.shimmer)
implementation(Dep.lottie)

testImplementation(Dep.Test.junit)
androidTestImplementation(Dep.Test.junitExt)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package github.dev_playground.jeju_road.presentation

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import github.dev_playground.jeju_road.presentation.ui.main.MainActivity
import github.dev_playground.jeju_road.presentation.util.startActivity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@SuppressLint("CustomSplashScreen")
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)

setContentView(R.layout.activity_splash)

CoroutineScope(Dispatchers.IO).launch {
delay(2000)

this@SplashActivity.startActivity<MainActivity> { }
finish()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope
import github.dev_playground.jeju_road.presentation.util.Event
import github.dev_playground.jeju_road.presentation.util.UiState

abstract class BaseActivity<B: ViewDataBinding>(@LayoutRes layoutId: Int): AppCompatActivity(layoutId) {
abstract class BaseActivity<B: ViewDataBinding>(
@LayoutRes layoutId: Int
): AppCompatActivity(layoutId) {

//baseviewmodel에서 ui state 상태 바뀐거 여기서 onSuccess, onFailure, onLoading 처리?

protected val binding: B by lazy { DataBindingUtil.setContentView<B>(this, layoutId) }

Expand All @@ -37,6 +43,7 @@ abstract class BaseActivity<B: ViewDataBinding>(@LayoutRes layoutId: Int): AppCo
if (item.itemId == android.R.id.home) {
finish()
}

return super.onOptionsItemSelected(item)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package github.dev_playground.jeju_road.presentation.ui.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.DialogFragment

abstract class BaseDialogFragment<VB: ViewDataBinding>(
@LayoutRes val layoutId: Int
) : DialogFragment() {
private var _binding: VB? = null
val binding: VB by lazy { _binding!! }

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = DataBindingUtil.inflate(
inflater,
layoutId,
container,
false
)

binding {
lifecycleOwner = viewLifecycleOwner
}

return binding.root
}

protected fun binding(action: VB.() -> Unit) {
binding.run(action)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package github.dev_playground.jeju_road.presentation.ui.error

import android.app.Dialog
import android.graphics.Point
import android.os.Bundle
import android.view.*
import androidx.fragment.app.DialogFragment
import github.dev_playground.jeju_road.presentation.R
import github.dev_playground.jeju_road.presentation.databinding.ActivityRestaurantDetailBinding
import github.dev_playground.jeju_road.presentation.databinding.FragmentDialogErrorBinding
import github.dev_playground.jeju_road.presentation.ui.base.BaseDialogFragment

class ErrorDialogFragment
: BaseDialogFragment<FragmentDialogErrorBinding>(R.layout.fragment_dialog_error) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog?.setCanceledOnTouchOutside(false)
binding {
imageViewCloseErrorDialog.setOnClickListener {
dialog?.dismiss()
}
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
setStyle(STYLE_NO_TITLE, R.style.Dialog_ERROR_DIALOG)
return super.onCreateDialog(savedInstanceState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import github.dev_playground.jeju_road.domain.model.Content
import github.dev_playground.jeju_road.presentation.R
import github.dev_playground.jeju_road.presentation.databinding.FragmentRestaurantListBinding
import github.dev_playground.jeju_road.presentation.ui.base.BaseFragment
import github.dev_playground.jeju_road.presentation.ui.error.ErrorDialogFragment
import github.dev_playground.jeju_road.presentation.ui.page.RestaurantDetailActivity
import github.dev_playground.jeju_road.presentation.ui.page.RestaurantDetailActivity.Companion.KEY_RESTAURANT_ID
import github.dev_playground.jeju_road.presentation.ui.page.RestaurantDetailActivity.Companion.KEY_TRANSITION_NAME
import github.dev_playground.jeju_road.presentation.util.UiState
import github.dev_playground.jeju_road.presentation.util.onFailure
import github.dev_playground.jeju_road.presentation.util.onSuccess
import org.koin.androidx.viewmodel.ext.android.sharedViewModel

Expand Down Expand Up @@ -73,10 +75,14 @@ class RestaurantListFragment : BaseFragment<FragmentRestaurantListBinding>(

contentUiState.observe {
restaurantListAdapter.submitList(it.data)

it.onSuccess {
savedState.value?.let { state ->
recyclerViewRestaurantList.layoutManager?.onRestoreInstanceState(state)
}
}.onFailure {
val errorDialog = ErrorDialogFragment()
errorDialog.show(requireActivity().supportFragmentManager, "tag")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import github.dev_playground.jeju_road.domain.model.Content
import github.dev_playground.jeju_road.domain.usecase.GetRestaurantListUseCase
import github.dev_playground.jeju_road.presentation.util.Pager
import github.dev_playground.jeju_road.presentation.util.UiState
import github.dev_playground.jeju_road.presentation.util.toUiState
import github.dev_playground.jeju_road.presentation.util.*
import kotlinx.coroutines.launch

class RestaurantListViewModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package github.dev_playground.jeju_road.presentation.util

import kotlinx.coroutines.flow.MutableStateFlow

data class UiState<T>(
val loading: Boolean = false,
val exception: Throwable? = null,
Expand All @@ -22,12 +24,13 @@ data class UiState<T>(
}

companion object {
fun <T> loading(): UiState<T> = UiState(loading = true)
fun <T> loading(): UiState<T> = UiState(loading = false)

fun <T> success(value: T?): UiState<T> = UiState(data = value)

fun <T> failure(exception: Throwable?): UiState<T> = UiState(exception = exception)
}

}

inline fun <T> UiState<T>.onSuccess(action: (T) -> Unit) = apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners android:radius="@dimen/error_dialog_radius"/>
</shape>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/orangeMainColor"/>
<corners android:radius="@dimen/error_dialog_retry_button_radius"/>
</shape>
9 changes: 9 additions & 0 deletions presentation/src/main/res/drawable/ic_close_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M11.615,11.615C11.731,11.499 11.869,11.406 12.021,11.343C12.173,11.28 12.336,11.248 12.5,11.248C12.665,11.248 12.827,11.28 12.979,11.343C13.131,11.406 13.269,11.499 13.385,11.615L20,18.233L26.615,11.615C26.731,11.499 26.869,11.407 27.021,11.344C27.173,11.281 27.336,11.248 27.5,11.248C27.664,11.248 27.827,11.281 27.979,11.344C28.131,11.407 28.269,11.499 28.385,11.615C28.501,11.731 28.593,11.869 28.656,12.021C28.719,12.173 28.752,12.336 28.752,12.5C28.752,12.664 28.719,12.827 28.656,12.979C28.593,13.131 28.501,13.269 28.385,13.385L21.767,20L28.385,26.615C28.501,26.731 28.593,26.869 28.656,27.021C28.719,27.173 28.752,27.336 28.752,27.5C28.752,27.664 28.719,27.827 28.656,27.979C28.593,28.131 28.501,28.269 28.385,28.385C28.269,28.501 28.131,28.593 27.979,28.656C27.827,28.719 27.664,28.752 27.5,28.752C27.336,28.752 27.173,28.719 27.021,28.656C26.869,28.593 26.731,28.501 26.615,28.385L20,21.767L13.385,28.385C13.269,28.501 13.131,28.593 12.979,28.656C12.827,28.719 12.664,28.752 12.5,28.752C12.336,28.752 12.173,28.719 12.021,28.656C11.869,28.593 11.731,28.501 11.615,28.385C11.499,28.269 11.407,28.131 11.344,27.979C11.281,27.827 11.248,27.664 11.248,27.5C11.248,27.336 11.281,27.173 11.344,27.021C11.407,26.869 11.499,26.731 11.615,26.615L18.233,20L11.615,13.385C11.499,13.269 11.406,13.131 11.343,12.979C11.28,12.827 11.248,12.665 11.248,12.5C11.248,12.336 11.28,12.173 11.343,12.021C11.406,11.869 11.499,11.731 11.615,11.615Z"
android:fillColor="#141414"/>
</vector>
9 changes: 9 additions & 0 deletions presentation/src/main/res/drawable/ic_devplayground.xml

Large diffs are not rendered by default.

Loading

0 comments on commit ddaaa51

Please sign in to comment.