Skip to content

Commit

Permalink
[MERGE/#11] merge develop into seminar7
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Jun 23, 2023
2 parents 4d41f2e + 83558e2 commit b74e153
Show file tree
Hide file tree
Showing 29 changed files with 421 additions and 132 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies {
implementation "androidx.appcompat:appcompat:1.6.1"

// material
implementation "com.google.android.material:material:1.8.0"
implementation "com.google.android.material:material:1.9.0"

// constraint layout
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
Expand Down Expand Up @@ -107,4 +107,7 @@ dependencies {

// splash screen
implementation "androidx.core:core-splashscreen:1.0.1"

// lottie
implementation 'com.airbnb.android:lottie:3.7.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.android.go.sopt.presentation.dialog

import android.os.Bundle
import android.view.View
import org.android.go.sopt.R
import org.android.go.sopt.databinding.FragmentLoadingDialogBinding
import org.android.go.sopt.util.binding.BindingDialogFragment

class LoadingDialogFragment :
BindingDialogFragment<FragmentLoadingDialogBinding>(R.layout.fragment_loading_dialog) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initDialogCancelable()
}

private fun initDialogCancelable() {
dialog?.setCancelable(false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.activity.viewModels
import dagger.hilt.android.AndroidEntryPoint
import org.android.go.sopt.R
import org.android.go.sopt.databinding.ActivityLoginBinding
import org.android.go.sopt.presentation.dialog.LoadingDialogFragment
import org.android.go.sopt.presentation.main.MainActivity
import org.android.go.sopt.presentation.signup.SignupActivity
import org.android.go.sopt.util.binding.BindingActivity
Expand All @@ -16,12 +17,15 @@ import org.android.go.sopt.util.extension.showSnackbar
import org.android.go.sopt.util.extension.showToast
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Loading
import org.android.go.sopt.util.state.RemoteUiState.Success

@AndroidEntryPoint
class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_login) {
private val viewModel by viewModels<LoginViewModel>()

private val loadingDialog by lazy { LoadingDialogFragment() }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.vm = viewModel
Expand All @@ -46,18 +50,41 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
private fun setupLoginState() {
viewModel.loginState.observe(this) { state ->
when (state) {
is Success -> navigateToMainScreen()
is Failure -> showSnackbar(binding.root, getString(R.string.wrong_input_msg))
is Error -> showSnackbar(binding.root, getString(R.string.unknown_error_msg))
is Loading -> {
loadingDialog.show(supportFragmentManager, TAG_LOADING_DIALOG)
}

is Success -> {
dismissLoadingDialog()
navigateToMainScreen()
}

is Failure -> {
dismissLoadingDialog()
showSnackbar(binding.root, getString(R.string.wrong_input_msg))
}

is Error -> {
dismissLoadingDialog()
showSnackbar(binding.root, getString(R.string.unknown_error_msg))
}
}
}
}

private fun dismissLoadingDialog() {
if (loadingDialog.isAdded) loadingDialog.dismiss()
}

private fun navigateToMainScreen() {
showToast(getString(R.string.login_login_success_msg))
Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(this)
}
}

companion object {
const val TAG_LOADING_DIALOG = "LOADING_DIALOG"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.android.go.sopt.domain.repository.AuthRepository
import org.android.go.sopt.util.state.RemoteUiState
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Loading
import org.android.go.sopt.util.state.RemoteUiState.Success
import retrofit2.HttpException
import timber.log.Timber
Expand Down Expand Up @@ -43,19 +44,19 @@ class LoginViewModel @Inject constructor(
}
}

private fun isValidInput() = id.isNotBlank() && pwd.isNotBlank()

fun login() {
if (!isValidInput()) {
_loginState.value = Failure(null)
return
}

val requestPostSignInDto = RequestPostSignInDto(
id = id,
password = pwd,
)
viewModelScope.launch {
_loginState.value = Loading

if (!isValidInput()) {
_loginState.value = Failure(CODE_INVALID_INPUT)
return@launch
}

val requestPostSignInDto = RequestPostSignInDto(
id = id,
password = pwd,
)
authRepository.postSignin(requestPostSignInDto)
.onSuccess { response ->
authRepository.setSignedUpUser(
Expand All @@ -82,6 +83,8 @@ class LoginViewModel @Inject constructor(
}
}

private fun isValidInput() = id.isNotBlank() && pwd.isNotBlank()

companion object {
const val CODE_INVALID_INPUT = 400
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,52 @@ import androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup
import dagger.hilt.android.AndroidEntryPoint
import org.android.go.sopt.R
import org.android.go.sopt.databinding.FragmentFollowerBinding
import org.android.go.sopt.presentation.dialog.LoadingDialogFragment
import org.android.go.sopt.presentation.login.LoginActivity.Companion.TAG_LOADING_DIALOG
import org.android.go.sopt.presentation.main.follower.FollowerAdapter.Companion.VIEW_TYPE_HEADER
import org.android.go.sopt.util.binding.BindingFragment
import org.android.go.sopt.util.extension.showSnackbar
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Loading
import org.android.go.sopt.util.state.RemoteUiState.Success

@AndroidEntryPoint
class FollowerFragment : BindingFragment<FragmentFollowerBinding>(R.layout.fragment_follower) {
private val viewModel by viewModels<FollowerViewModel>()

private var followerAdapter: FollowerAdapter? = null
private var _followerAdapter: FollowerAdapter? = null
private val followerAdapter
get() = requireNotNull(_followerAdapter) { getString(R.string.adapter_not_initialized_error_msg) }

private var _loadingDialog: LoadingDialogFragment? = null
private val loadingDialog
get() = requireNotNull(_loadingDialog) { getString(R.string.dialog_not_initialized_error_msg) }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel

initFollowerAdapter()
initLoadingDialogFragment()
initRecyclerViewLayoutManager()
setupGetFollowerListState()
}

private fun initFollowerAdapter() {
followerAdapter = FollowerAdapter()
_followerAdapter = FollowerAdapter()
binding.rvFollower.adapter = followerAdapter
}

private fun initLoadingDialogFragment() {
_loadingDialog = LoadingDialogFragment()
}

private fun initRecyclerViewLayoutManager() {
val layoutManager = GridLayoutManager(activity, 2)
layoutManager.spanSizeLookup = object : SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return when (followerAdapter?.getItemViewType(position)) {
return when (followerAdapter.getItemViewType(position)) {
VIEW_TYPE_HEADER -> 2
else -> 1
}
Expand All @@ -51,16 +65,42 @@ class FollowerFragment : BindingFragment<FragmentFollowerBinding>(R.layout.fragm
private fun setupGetFollowerListState() {
viewModel.getFollowerListState.observe(viewLifecycleOwner) { state ->
when (state) {
is Success -> followerAdapter?.submitList(viewModel.followerList)
is Failure -> requireContext().showSnackbar(binding.root, getString(R.string.follower_get_follower_list_null_msg))
is Error -> requireContext().showSnackbar(binding.root, getString(R.string.unknown_error_msg))
is Loading -> {
loadingDialog.show(parentFragmentManager, TAG_LOADING_DIALOG)
}

is Success -> {
dismissLoadingDialog()
followerAdapter.submitList(viewModel.followerList)
}

is Failure -> {
dismissLoadingDialog()
requireContext().showSnackbar(
binding.root,
getString(R.string.follower_get_follower_list_null_msg),
)
}

is Error -> {
dismissLoadingDialog()
requireContext().showSnackbar(
binding.root,
getString(R.string.unknown_error_msg),
)
}
}
}
}

private fun dismissLoadingDialog() {
if (loadingDialog.isAdded) loadingDialog.dismiss()
}

override fun onDestroyView() {
super.onDestroyView()
followerAdapter = null
_followerAdapter = null
_loadingDialog = null
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.android.go.sopt.domain.repository.FollowerRepository
import org.android.go.sopt.util.state.RemoteUiState
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Loading
import org.android.go.sopt.util.state.RemoteUiState.Success
import retrofit2.HttpException
import timber.log.Timber
Expand All @@ -33,8 +34,9 @@ class FollowerViewModel @Inject constructor(
}

private fun getFollowerList() {
Timber.d("get follower list 시작")
viewModelScope.launch {
_getFollowerListState.value = Loading
// TODO: 팔로워 페이징 구현
followerRepository.getFollowerList(1)
.onSuccess { response ->
if (response.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.android.go.sopt.util.ContentUriRequestBody
import org.android.go.sopt.util.binding.BindingFragment
import org.android.go.sopt.util.extension.setOnSingleClickListener
import org.android.go.sopt.util.extension.showSnackbar
import org.android.go.sopt.util.state.RemoteUiState
import org.android.go.sopt.util.state.RemoteUiState.Error
import org.android.go.sopt.util.state.RemoteUiState.Failure
import org.android.go.sopt.util.state.RemoteUiState.Success
Expand Down Expand Up @@ -53,16 +54,29 @@ class GalleryFragment : BindingFragment<FragmentGalleryBinding>(R.layout.fragmen
private fun setupPostImageState() {
viewModel.postImageState.observe(viewLifecycleOwner) { state ->
when (state) {
is RemoteUiState.Loading -> {
// TODO: 로딩 처리
}

is Success -> {
requireContext().showSnackbar(binding.root, getString(R.string.gallery_post_image_success_msg))
requireContext().showSnackbar(
binding.root,
getString(R.string.gallery_post_image_success_msg),
)
}

is Failure -> {
requireContext().showSnackbar(binding.root, getString(R.string.gallery_image_oversized_error_msg))
requireContext().showSnackbar(
binding.root,
getString(R.string.gallery_image_oversized_error_msg),
)
}

is Error -> {
requireContext().showSnackbar(binding.root, getString(R.string.unknown_error_msg))
requireContext().showSnackbar(
binding.root,
getString(R.string.unknown_error_msg),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.android.go.sopt.presentation.main.gallery

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.DrawableRes
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import org.android.go.sopt.databinding.ItemGalleryImageBinding
Expand All @@ -20,16 +19,10 @@ class ImageAdapter : ListAdapter<Int, RecyclerView.ViewHolder>(diffUtil) {
)
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is ImageViewHolder) holder.setImage(getItem(position))
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {}

class ImageViewHolder(private val binding: ItemGalleryImageBinding) :
RecyclerView.ViewHolder(binding.root) {
fun setImage(@DrawableRes index: Int) {
// TODO : 이미지 연결
}
}
RecyclerView.ViewHolder(binding.root)

companion object {
private val diffUtil = DiffCallback<Int>(
Expand Down
Loading

0 comments on commit b74e153

Please sign in to comment.