Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Team-Going/Going-Android
Browse files Browse the repository at this point in the history
…into fix/#152-qa-issue
  • Loading branch information
leeeyubin committed Jan 17, 2024
2 parents 84bd261 + 76353e9 commit 257dec4
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 109 deletions.
19 changes: 19 additions & 0 deletions core-ui/src/main/java/com/going/ui/extension/ActivityExt.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package com.going.ui.extension

import android.app.Activity
import android.content.Context
import android.os.Build
import android.util.DisplayMetrics
import android.view.WindowInsets
import android.view.WindowManager
import androidx.core.content.ContextCompat

fun Activity.setStatusBarColorFromResource(colorResId: Int) {
val statusBarColor = ContextCompat.getColor(this, colorResId)
window.statusBarColor = statusBarColor
}

fun Activity.getWindowHeight(): Int {
val wm = this.getSystemService(Context.WINDOW_SERVICE) as WindowManager
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = wm.currentWindowMetrics
val insets = windowMetrics.windowInsets
.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
windowMetrics.bounds.height() - insets.bottom - insets.top
} else {
val displayMetrics = DisplayMetrics()
wm.defaultDisplay.getMetrics(displayMetrics)
displayMetrics.heightPixels
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import androidx.activity.viewModels
import com.going.presentation.R
import com.going.presentation.databinding.ActivityTripDashBoardBinding
import com.going.presentation.entertrip.StartTripSplashActivity
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID
import com.going.presentation.setting.SettingActivity
import com.going.presentation.todo.TodoActivity
import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID
import com.going.presentation.util.initOnBackPressedListener
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener
Expand All @@ -24,6 +27,7 @@ class DashBoardActivity :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

checkIsFirstEntered()
setTabLayout()
setViewPager()
setTravelerName()
Expand All @@ -32,6 +36,16 @@ class DashBoardActivity :
initOnBackPressedListener()
}

private fun checkIsFirstEntered() {
if (intent.getBooleanExtra(IS_FIRST_ENTERED, false)) {
val tripId = intent.getLongExtra(TRIP_ID, 0)
Intent(this, TodoActivity::class.java).apply {
putExtra(EXTRA_TRIP_ID, tripId)
startActivity(this)
}
}
}

private fun setTabLayout() {
binding.tabDashboard.apply {
for (tabName in tabTextList) {
Expand Down Expand Up @@ -85,5 +99,7 @@ class DashBoardActivity :
companion object {
const val TAB_ONGOING = "진행 중인 여행"
const val TAB_COMPLETED = "지나간 여행"

const val IS_FIRST_ENTERED = "isFirstEntered"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.Intent
import android.os.Bundle
import com.going.presentation.R
import com.going.presentation.dashboard.DashBoardActivity
import com.going.presentation.dashboard.DashBoardActivity.Companion.IS_FIRST_ENTERED
import com.going.presentation.databinding.ActivityFinishTripBinding
import com.going.presentation.entertrip.invitetrip.finish.InviteFinishActivity.Companion.DATE_FORMAT
import com.going.presentation.entertrip.invitetrip.finish.InviteFinishActivity.Companion.D_DAY_FORMAT
Expand All @@ -17,6 +18,7 @@ import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.INVITE_CODE
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.START
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TITLE
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID
import com.going.presentation.util.initOnBackPressedListener
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener
Expand All @@ -31,6 +33,7 @@ class FinishTripActivity :

private var inviteCode: String = ""
private var title: String = ""
private var tripId: Long = 0

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -104,6 +107,8 @@ class FinishTripActivity :
private fun initEnterTripBtnClickListener() {
binding.btnFinishTripEnterTrip.setOnSingleClickListener {
Intent(this, DashBoardActivity::class.java).apply {
putExtra(TRIP_ID, tripId)
putExtra(IS_FIRST_ENTERED, true)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
Expand All @@ -118,6 +123,7 @@ class FinishTripActivity :
val end = intent.getStringExtra(END)
inviteCode = intent.getStringExtra(INVITE_CODE) ?: ""
val day = intent.getIntExtra(DAY, 0)
tripId = intent.getLongExtra(TRIP_ID, 0)

binding.tvFinishTripName.text = title
binding.tvFinishTripDay.text = String.format(DATE_FORMAT, start, end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.INVITE_CODE
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.START
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TITLE
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID
import com.going.presentation.entertrip.preferencetag.PreferenceTagAdapter
import com.going.presentation.entertrip.preferencetag.PreferenceTagDecoration
import com.going.ui.base.BaseActivity
Expand Down Expand Up @@ -110,6 +111,7 @@ class EnterPreferenceActivity :
putExtra(END, state.data.endDate)
putExtra(INVITE_CODE, state.data.code)
putExtra(DAY, state.data.day)
putExtra(TRIP_ID, state.data.tripId)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.PreferenceData
import com.going.presentation.R
import com.going.presentation.dashboard.DashBoardActivity
import com.going.presentation.dashboard.DashBoardActivity.Companion.IS_FIRST_ENTERED
import com.going.presentation.databinding.ActivityFinishPreferenceBinding
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID
import com.going.presentation.entertrip.preferencetag.PreferenceTagAdapter
Expand Down Expand Up @@ -75,7 +76,7 @@ class FinishPreferenceActivity :
private fun observeFinishPreferenceState() {
viewModel.finishInviteState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Success -> navigateToDashBoard()
is UiState.Success -> navigateToDashBoard(state.data.tripId)

is UiState.Failure -> {
toast(getString(R.string.server_error))
Expand All @@ -88,8 +89,10 @@ class FinishPreferenceActivity :
}.launchIn(lifecycleScope)
}

private fun navigateToDashBoard() {
private fun navigateToDashBoard(tripId: Long) {
Intent(this, DashBoardActivity::class.java).apply {
putExtra(TRIP_ID, tripId)
putExtra(IS_FIRST_ENTERED, true)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class TodoActivity() : BaseActivity<ActivityTodoBinding>(R.layout.activity_todo)
}

private fun initBnvItemSelectedListener() {
supportFragmentManager.findFragmentById(R.id.fcv_todo) ?: navigateTo<OurTodoFragment>(tripId)
supportFragmentManager.findFragmentById(R.id.fcv_todo)
?: navigateTo<OurTodoFragment>(tripId)

binding.bnvTodo.setOnItemSelectedListener { menu ->
if (binding.bnvTodo.selectedItemId == menu.itemId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.view.View
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
Expand All @@ -24,10 +23,10 @@ import com.going.presentation.todo.ourtodo.OurTodoFragment.Companion.debounceTim
import com.going.presentation.todo.ourtodo.create.OurTodoCreateActivity.Companion.EXTRA_PARTICIPANT_ID
import com.going.ui.base.BaseFragment
import com.going.ui.extension.UiState
import com.going.ui.extension.getWindowHeight
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.setStatusBarColor
import com.going.ui.extension.toast
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -42,6 +41,9 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m

private val viewModel by activityViewModels<MyTodoViewModel>()

private val handler = Handler(Looper.getMainLooper())
private lateinit var enableClickRunnable: Runnable

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand All @@ -55,6 +57,7 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m
setViewPagerDebounce()
setTodoCountText()
setToolbarColor()
setEmptyViewHeight()
observeMyTripInfoState()
observeTotalUncompletedTodoCount()

Expand Down Expand Up @@ -84,7 +87,6 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m
}
}


private fun setMyTripInfo() {
arguments?.let {
viewModel.tripId = it.getLong(EXTRA_TRIP_ID)
Expand Down Expand Up @@ -137,11 +139,12 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m
for (i in tabTextList.indices) {
binding.tabMyTodo.getTabAt(i)?.view?.isClickable = false
}
Handler(Looper.getMainLooper()).postDelayed({
enableClickRunnable = Runnable {
for (i in tabTextList.indices) {
binding.tabMyTodo.getTabAt(i)?.view?.isClickable = true
}
}, debounceTime)
}
handler.postDelayed(enableClickRunnable, debounceTime)
}

private fun setTodoCountText() {
Expand All @@ -168,6 +171,17 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m
}
}

private fun setEmptyViewHeight() {
binding.appbarMyTodo.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
val displayHeight = activity?.getWindowHeight() ?: return@addOnOffsetChangedListener
val toolbarHeight = binding.toolbarMyTodo.height
val appBarHeight = appBarLayout.totalScrollRange + verticalOffset
binding.vpMyTodo.layoutParams = (binding.vpMyTodo.layoutParams).also {
it.height = displayHeight - toolbarHeight - appBarHeight - 300
}
}
}

private fun observeMyTripInfoState() {
viewModel.myTripInfoState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
Expand Down Expand Up @@ -204,15 +218,9 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m
}
}


fun setAppbarDragAvailable(isAvailable: Boolean) {
binding.appbarMyTodo
val params = binding.appbarMyTodo.layoutParams as CoordinatorLayout.LayoutParams
val behavior = params.behavior as AppBarLayout.Behavior

behavior.setDragCallback(object : AppBarLayout.Behavior.DragCallback() {
override fun canDrag(appBarLayout: AppBarLayout): Boolean = isAvailable
})
override fun onDestroyView() {
super.onDestroyView()
if (::enableClickRunnable.isInitialized) handler.removeCallbacks(enableClickRunnable)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MyTodoCompleteFragment() :
viewModel.getToRedoTodoFromServer(todoId)
},
{ todoModel ->
if (todoModel.allocators.size <= 1) {
if (todoModel.secret) {
startDetailActivity(PrivateDetailActivity::class.java, todoModel.todoId)
} else {
startDetailActivity(PublicDetailActivity::class.java, todoModel.todoId)
Expand Down Expand Up @@ -105,7 +105,6 @@ class MyTodoCompleteFragment() :
private fun setLayoutEmpty(isEmpty: Boolean) {
binding.rvMyTodoComplete.isVisible = !isEmpty
binding.layoutMyTodoCompleteEmpty.isVisible = isEmpty
(parentFragment as MyTodoFragment).setAppbarDragAvailable(!isEmpty)
}

private fun observeTodoRedoState() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.going.presentation.todo.mytodo.todolist

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
Expand Down Expand Up @@ -58,32 +57,24 @@ class MyTodoUncompleteFragment() :
},
{ },
{ todoModel ->
if (todoModel.allocators.size <= 1) {
startDetailActivity(
activity,
PrivateDetailActivity::class.java,
todoModel.todoId
)
if (todoModel.secret) {
startDetailActivity(PrivateDetailActivity::class.java, todoModel.todoId)
} else {
startDetailActivity(
activity,
PublicDetailActivity::class.java,
todoModel.todoId
)
startDetailActivity(PublicDetailActivity::class.java, todoModel.todoId)
}
})
binding.rvMyTodoUncomplete.adapter = adapter
}

private fun startDetailActivity(activity: Activity?, targetActivity: Class<*>, todoId: Long) {
private fun startDetailActivity(targetActivity: Class<*>, todoId: Long) {
Intent(activity, targetActivity).apply {
putExtra(EXTRA_TODO_ID, todoId)
activity?.startActivity(this)
}
}

private fun initItemDecoration() {
val itemDeco = TodoDecoration(requireContext(),0,0,0,30)
val itemDeco = TodoDecoration(requireContext(), 0, 0, 0, 30)
binding.rvMyTodoUncomplete.addItemDecoration(itemDeco)
}

Expand Down Expand Up @@ -114,7 +105,6 @@ class MyTodoUncompleteFragment() :
private fun setLayoutEmpty(isEmpty: Boolean) {
binding.rvMyTodoUncomplete.isVisible = !isEmpty
binding.layoutMyTodoUncompleteEmpty.isVisible = isEmpty
(parentFragment as MyTodoFragment).setAppbarDragAvailable(!isEmpty)
}

private fun observeTodoFinishState() {
Expand Down
Loading

0 comments on commit 257dec4

Please sign in to comment.