Skip to content

Commit

Permalink
🔥 :: apiErrorHandling 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
ImGaram committed Sep 17, 2023
1 parent 0423b25 commit 2715f05
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ import com.goms.domain.data.late.LateUserResponseData
import com.goms.domain.data.profile.ProfileResponseData
import com.goms.presentation.R
import com.goms.presentation.databinding.FragmentHomeBinding
import com.goms.presentation.view.home.dialog.GomsBlackListDialog
import com.goms.presentation.utils.apiErrorHandling
import com.goms.presentation.utils.checkUserIsAdmin
import com.goms.presentation.view.home.component.HomeItemCard
import com.goms.presentation.view.home.component.LateRankEmptyScreen
import com.goms.presentation.view.home.dialog.GomsBlackListDialog
import com.goms.presentation.view.main.MainActivity
import com.goms.presentation.view.manage.StudentManageActivity
import com.goms.presentation.view.profile.ProfileActivity
Expand Down Expand Up @@ -111,26 +110,11 @@ class HomeFragment : Fragment() {

private fun homeLogic() {
setLoading()
lifecycleScope.launch {
apiErrorHandling(
context = context,
logic = { setProfile() }
)
}
lifecycleScope.launch { setProfile() }

lifecycleScope.launch {
apiErrorHandling(
context = context,
logic = { getOutingCount() }
)
}
lifecycleScope.launch { getOutingCount() }

lifecycleScope.launch {
apiErrorHandling(
context = context,
logic = { setLateRankList() }
)
}
lifecycleScope.launch { setLateRankList() }
}

private fun setLoading() {
Expand All @@ -153,7 +137,7 @@ class HomeFragment : Fragment() {
}

private suspend fun getOutingCount() {
outingViewModel.outingCount()
outingViewModel.outingCount(activity = activity as MainActivity)
outingViewModel.outingCount.collect { people ->
binding.currentStudentOutingText.setContent {
StudentOutingText(people!!.outingCount)
Expand All @@ -162,7 +146,7 @@ class HomeFragment : Fragment() {
}

private suspend fun setLateRankList() {
lateViewModel.getLateRanking()
lateViewModel.getLateRanking(activity = activity as MainActivity)
lateViewModel.lateRanking.collect { list ->
binding.lateRankingLazyRow.setContent {
if (list != null) {
Expand All @@ -174,7 +158,7 @@ class HomeFragment : Fragment() {
}

private suspend fun setProfile() {
profileViewModel.getProfileLogic()
profileViewModel.getProfileLogic(activity = activity as MainActivity)
profileViewModel.profile.collect { data ->
if (data != null) {
response = data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import coil.load
import com.goms.domain.data.profile.ProfileResponseData
import com.goms.presentation.R
import com.goms.presentation.databinding.ActivityMainBinding
import com.goms.presentation.utils.apiErrorHandling
import com.goms.presentation.utils.checkUserIsAdmin
import com.goms.presentation.view.profile.ProfileActivity
import com.goms.presentation.viewmodel.ProfileViewModel
Expand Down Expand Up @@ -58,7 +57,11 @@ class MainActivity : AppCompatActivity() {
}

val intentExtra = intent.getSerializableExtra("profile") as ProfileResponseData?
if (intentExtra == null) setProfile()
if (intentExtra == null) {
lifecycleScope.launch {
getProfile()
}
}
else {
response = intentExtra
binding.mainCircleProfileIcon.load(intentExtra.profileUrl ?: R.drawable.user_profile)
Expand All @@ -82,17 +85,8 @@ class MainActivity : AppCompatActivity() {
.check()
}

private fun setProfile() {
lifecycleScope.launch {
apiErrorHandling(
context = this@MainActivity,
logic = { getProfile() }
)
}
}

private suspend fun getProfile() {
profileViewModel.getProfileLogic()
profileViewModel.getProfileLogic(activity = this)
profileViewModel.profile.collect { data ->
if (data != null) {
response = data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.goms.domain.data.council.response.UserInfoResponseData
import com.goms.presentation.R
import com.goms.presentation.databinding.ActivityStudentManageBinding
import com.goms.presentation.utils.dialog.GomsDialog
import com.goms.presentation.utils.apiErrorHandling
import com.goms.presentation.view.manage.bottomsheet.ModifyRoleBottomSheetDialog
import com.goms.presentation.view.manage.bottomsheet.SearchFilterBottomSheetDialog
import com.goms.presentation.view.manage.component.SearchResultEmptyScreen
Expand Down Expand Up @@ -65,13 +64,8 @@ class StudentManageActivity : AppCompatActivity() {
private fun studentManageLogic() {
setLoading()
lifecycleScope.launch {
apiErrorHandling(
context = this@StudentManageActivity,
logic = {
if (userFilterOptions != null) refreshSearchUser(userFilterOptions!!)
else getUserList()
}
)
if (userFilterOptions != null) refreshSearchUser(userFilterOptions!!)
else getUserList()
}
}

Expand All @@ -85,7 +79,7 @@ class StudentManageActivity : AppCompatActivity() {
}

private suspend fun getUserList() {
councilViewModel.getUserList()
councilViewModel.getUserList(activity = this)
councilViewModel.userList.collect { list ->
if (list != null) initUserList(list)
}
Expand Down Expand Up @@ -194,18 +188,20 @@ class StudentManageActivity : AppCompatActivity() {

private fun refreshSearchUser(options: UserFilterOptions) {
lifecycleScope.launch {
apiErrorHandling(
context = this@StudentManageActivity,
logic = {
options.apply {
councilViewModel.searchStudent(grade, classNum, name, isBlackList, authority)
}
options.apply {
councilViewModel.searchStudent(
grade = grade,
classNum = classNum,
name = name,
isBlackList = isBlackList,
authority = authority,
activity = this@StudentManageActivity
)
}

councilViewModel.searchStudent.collect { list ->
if (list != null) searchUserList(list)
}
}
)
councilViewModel.searchStudent.collect { list ->
if (list != null) searchUserList(list)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
Expand All @@ -14,7 +13,6 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
Expand All @@ -27,15 +25,16 @@ import androidx.lifecycle.lifecycleScope
import com.goms.domain.data.user.UserResponseData
import com.goms.presentation.R
import com.goms.presentation.databinding.FragmentOutingBinding
import com.goms.presentation.utils.apiErrorHandling
import com.goms.presentation.view.main.MainActivity
import com.goms.presentation.view.outing.component.EmptyScreen
import com.goms.presentation.view.outing.component.OutingStudentCard
import com.goms.presentation.viewmodel.OutingViewModel
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.SwipeRefreshIndicator
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import java.util.*
import java.util.UUID

@AndroidEntryPoint
class OutingFragment : Fragment() {
Expand All @@ -49,8 +48,8 @@ class OutingFragment : Fragment() {
): View {
binding = FragmentOutingBinding.inflate(layoutInflater)

binding.outingStudentSearchButton.setOnClickListener { view ->
var inputText = binding.outingStudentSearch.text.toString()
binding.outingStudentSearchButton.setOnClickListener {
val inputText = binding.outingStudentSearch.text.toString()
searchOutingStudentLogic(name = inputText)
}
outingLogic()
Expand All @@ -60,29 +59,29 @@ class OutingFragment : Fragment() {

private fun outingLogic() {
setLoading()
lifecycleScope.launch {
apiErrorHandling(
context = context,
logic = { getOutingList() }
)
}
getOutingList()
}

private fun getOutingList() {
lifecycleScope.launch {
outingViewModel.outingListLogic()
outingViewModel.outingListLogic(activity as MainActivity)
outingViewModel.outingList.collect { list ->
binding.outingStudentListLazyColumn.setContent {
if (list!!.isEmpty()) EmptyScreen()
else OutingLazyColumn(list)
if (list != null) {
if (list.isEmpty()) EmptyScreen()
else OutingLazyColumn(list)
}
}
}
}
}

private fun searchOutingStudentLogic(name: String) {
lifecycleScope.launch {
outingViewModel.searchOutingStudent(name)
outingViewModel.searchOutingStudent(
name = name,
activity = activity as MainActivity
)
outingViewModel.outingList.collect { list ->
binding.outingStudentListLazyColumn.setContent {
if (list!!.isEmpty()) EmptyScreen()
Expand All @@ -104,9 +103,9 @@ class OutingFragment : Fragment() {

private fun deleteOuting(accountIdx: UUID) {
lifecycleScope.launch {
apiErrorHandling(
context = context,
logic = { outingViewModel.deleteOuting(accountIdx) }
outingViewModel.deleteOuting(
accountIdx = accountIdx,
activity = activity as MainActivity
)
getOutingList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import com.goms.presentation.BuildConfig
import com.goms.presentation.databinding.FragmentQrScanBinding
import com.goms.presentation.utils.apiErrorHandling
import com.goms.presentation.utils.checkUserIsAdmin
import com.goms.presentation.view.main.MainActivity
import com.goms.presentation.view.qr_scan.capture.QrCodeActivity
import com.goms.presentation.viewmodel.CouncilViewModel
import com.google.zxing.BarcodeFormat
Expand All @@ -23,7 +23,8 @@ import java.util.UUID

@AndroidEntryPoint
class QrScanFragment : Fragment() {
private val councilViewModel by viewModels<CouncilViewModel>()
private
val councilViewModel by viewModels<CouncilViewModel>()
private lateinit var binding: FragmentQrScanBinding
private var outingUUID = UUID.randomUUID()

Expand All @@ -40,7 +41,7 @@ class QrScanFragment : Fragment() {
} else {
setLoading()
lifecycleScope.launch {
makeQr()
qrLogic()
}
}

Expand All @@ -64,17 +65,8 @@ class QrScanFragment : Fragment() {
}
}

private suspend fun makeQr() {
lifecycleScope.launch {
apiErrorHandling(
context = context,
logic = { qrLogic() }
)
}
}

private suspend fun qrLogic() {
councilViewModel.makeQrCode()
councilViewModel.makeQrCode(activity = activity as MainActivity)
councilViewModel.makeQr.collect { uuid ->
kotlin.runCatching {
if (uuid!!.outingUUID != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.budiyev.android.codescanner.DecodeCallback
import com.budiyev.android.codescanner.ErrorCallback
import com.budiyev.android.codescanner.ScanMode
import com.goms.presentation.databinding.ActivityQrCodeBinding
import com.goms.presentation.utils.apiErrorHandling
import com.goms.presentation.view.main.MainActivity
import com.goms.presentation.viewmodel.OutingViewModel
import com.gun0912.tedpermission.PermissionListener
Expand Down Expand Up @@ -58,10 +57,7 @@ class QrCodeActivity : AppCompatActivity() {
codeScanner.decodeCallback = DecodeCallback { resultUrl ->
runOnUiThread {
lifecycleScope.launch {
apiErrorHandling(
context = this@QrCodeActivity,
logic = { outingLogic(resultUrl.text) }
)
outingLogic(resultUrl.text)
}
}
}
Expand All @@ -81,7 +77,10 @@ class QrCodeActivity : AppCompatActivity() {
val qrUUID = text.split("/")
val resultUUID = UUID.fromString(qrUUID[qrUUID.lastIndex])

outingViewModel.outingLogic(resultUUID)
outingViewModel.outingLogic(
outingUUID = resultUUID,
activity = this
)
outingViewModel.isOuting.collect { outAble ->
if (outAble == true) {
MainActivity.getInstance().navigateComplete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.lifecycle.lifecycleScope
import com.goms.presentation.BuildConfig
import com.goms.presentation.R
import com.goms.presentation.databinding.ActivitySignInBinding
import com.goms.presentation.utils.apiErrorHandling
import com.goms.presentation.view.main.MainActivity
import com.goms.presentation.viewmodel.NotificationViewModel
import com.goms.presentation.viewmodel.SignInViewModel
Expand Down Expand Up @@ -87,18 +86,18 @@ class SignInActivity : AppCompatActivity() {
) { code ->
binding.gauthWebView.visibility = View.INVISIBLE

signInViewModel.signInLogic(code)
signInViewModel.signInLogic(
code = code,
activity = this
)
lifecycleScope.launch {
signInViewModel.isLoading.collect { loading ->
if (loading) {
binding.signInScreenView.visibility = View.GONE
binding.signInProgressBar.visibility = View.VISIBLE
} else {
binding.signInProgressBar.visibility = View.GONE
apiErrorHandling(
context = this@SignInActivity,
logic = { signInLogic() }
)
signInLogic()
}
}
}
Expand All @@ -122,7 +121,10 @@ class SignInActivity : AppCompatActivity() {
val deviceTokenSF = getSharedPreferences("deviceToken", MODE_PRIVATE)
val token = task.result
if (deviceTokenSF.getString("device", "") == token) {
notificationViewModel.setNotification(token)
notificationViewModel.setNotification(
deviceToken = token,
activity = this
)
setNotificationLogic(token)
}
}
Expand Down
Loading

0 comments on commit 2715f05

Please sign in to comment.