Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/BDBD-506' into stage/san…
Browse files Browse the repository at this point in the history
…dbox
  • Loading branch information
minseonglove committed Dec 29, 2022
2 parents f8cfa46 + 338da3e commit 6c3d5e3
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 239 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package com.fakedevelopers.bidderbidder.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.fakedevelopers.bidderbidder.R
import com.fakedevelopers.bidderbidder.databinding.ActivityLoginBinding
import com.fakedevelopers.bidderbidder.ui.base.BaseActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class LoginActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
}
}
class LoginActivity : BaseActivity<ActivityLoginBinding>(ActivityLoginBinding::inflate)
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,22 @@ import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import androidx.annotation.IdRes
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import androidx.navigation.fragment.NavHostFragment
import com.fakedevelopers.bidderbidder.R
import com.fakedevelopers.bidderbidder.databinding.ActivityMainBinding
import com.fakedevelopers.bidderbidder.ui.base.BaseActivity
import com.jakewharton.threetenabp.AndroidThreeTen
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::inflate) {

private lateinit var navController: NavController
private var _binding: ActivityMainBinding? = null
private val binding get() = _binding!!

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
_binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
AndroidThreeTen.init(this)
navController = (supportFragmentManager.findFragmentById(R.id.navigation_main) as NavHostFragment).navController

navController.addOnDestinationChangedListener { _, destination, _ ->
private val destinationChangeListener by lazy {
NavController.OnDestinationChangedListener { _, destination, _ ->
when (destination.id) {
R.id.productListFragment -> {
binding.bottomNavigationMain.run {
Expand All @@ -39,6 +31,13 @@ class MainActivity : AppCompatActivity() {
else -> binding.bottomNavigationMain.visibility = View.GONE
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidThreeTen.init(this)
navController = (supportFragmentManager.findFragmentById(R.id.navigation_main) as NavHostFragment).navController
navController.addOnDestinationChangedListener(destinationChangeListener)
binding.bottomNavigationMain.setOnItemSelectedListener { item ->
when (item.itemId) {
R.id.menu_product_registration -> navController.safeNavigate(R.id.productRegistrationFragment)
Expand All @@ -60,7 +59,7 @@ class MainActivity : AppCompatActivity() {

override fun onDestroy() {
super.onDestroy()
_binding = null
navController.removeOnDestinationChangedListener(destinationChangeListener)
}

private fun NavController.safeNavigate(direction: NavDirections) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.fakedevelopers.bidderbidder.ui.base

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding

abstract class BaseActivity<VB : ViewBinding>(
private val bindingFactory: (LayoutInflater) -> VB
) : AppCompatActivity() {

protected lateinit var binding: VB

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = bindingFactory(layoutInflater)
setContentView(binding.root)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.fakedevelopers.bidderbidder.ui.base

import android.content.Intent
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.Fragment
import com.google.android.material.snackbar.Snackbar

abstract class BaseFragment<VB : ViewDataBinding>(
@LayoutRes private val layoutRes: Int
) : Fragment() {

private var _binding: VB? = null
protected val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
return binding.run {
lifecycleOwner = viewLifecycleOwner
root
}
}

fun sendSnackBar(
message: String,
@androidx.annotation.IntRange(from = -2) length: Int = Snackbar.LENGTH_SHORT,
anchorView: View? = null
) {
Snackbar.make(
binding.root,
message,
length
).apply {
if (anchorView != null) {
this.anchorView = anchorView
}
}.show()
}

fun navigateActivity(activity: Class<*>) {
startActivity(Intent(requireContext(), activity))
requireActivity().finish()
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.fakedevelopers.bidderbidder.ui.chat.channel

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -15,6 +11,7 @@ import androidx.navigation.navGraphViewModels
import com.fakedevelopers.bidderbidder.R
import com.fakedevelopers.bidderbidder.api.data.Constants.Companion.STREAM_KEY
import com.fakedevelopers.bidderbidder.databinding.FragmentChannelListBinding
import com.fakedevelopers.bidderbidder.ui.base.BaseFragment
import com.fakedevelopers.bidderbidder.ui.util.ApiErrorHandler
import dagger.hilt.android.AndroidEntryPoint
import io.getstream.chat.android.client.ChatClient
Expand All @@ -29,30 +26,17 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

@AndroidEntryPoint
class ChannelListFragment : Fragment() {
class ChannelListFragment : BaseFragment<FragmentChannelListBinding>(
R.layout.fragment_channel_list
) {

private var _binding: FragmentChannelListBinding? = null
private val binding get() = _binding!!
private val viewModel: CLViewModel by navGraphViewModels(R.id.nav_graph) {
defaultViewModelProviderFactory
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = DataBindingUtil.inflate(
inflater,
R.layout.fragment_channel_list,
container,
false
)
return binding.run {
vm = viewModel
lifecycleOwner = viewLifecycleOwner
root
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
initCollector()
initListener()
}
Expand Down Expand Up @@ -144,9 +128,4 @@ class ChannelListFragment : Fragment() {
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.fakedevelopers.bidderbidder.ui.chat.chatting

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.fakedevelopers.bidderbidder.R
import com.fakedevelopers.bidderbidder.databinding.FragmentChattingBinding
import com.fakedevelopers.bidderbidder.ui.base.BaseFragment
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel
import io.getstream.chat.android.ui.message.input.viewmodel.bindView
Expand All @@ -20,10 +17,10 @@ import io.getstream.chat.android.ui.message.list.header.viewmodel.bindView
import io.getstream.chat.android.ui.message.list.viewmodel.bindView
import io.getstream.chat.android.ui.message.list.viewmodel.factory.MessageListViewModelFactory

class ChattingFragment : Fragment() {
class ChattingFragment : BaseFragment<FragmentChattingBinding>(
R.layout.fragment_chatting
) {

private var _binding: FragmentChattingBinding? = null
private val binding get() = _binding!!
private val args: ChattingFragmentArgs by navArgs()
private val backPressedCallback by lazy {
object : OnBackPressedCallback(true) {
Expand All @@ -33,16 +30,6 @@ class ChattingFragment : Fragment() {
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = DataBindingUtil.inflate(
inflater,
R.layout.fragment_chatting,
container,
false
)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
runCatching {
Expand Down Expand Up @@ -94,6 +81,5 @@ class ChattingFragment : Fragment() {
override fun onDestroyView() {
super.onDestroyView()
backPressedCallback.remove()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.fakedevelopers.bidderbidder.ui.login

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -16,40 +11,20 @@ import com.fakedevelopers.bidderbidder.R
import com.fakedevelopers.bidderbidder.api.data.Constants.Companion.LOGIN_SUCCESS
import com.fakedevelopers.bidderbidder.databinding.FragmentLoginBinding
import com.fakedevelopers.bidderbidder.ui.MainActivity
import com.orhanobut.logger.Logger
import com.fakedevelopers.bidderbidder.ui.base.BaseFragment
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class LoginFragment : Fragment() {
class LoginFragment : BaseFragment<FragmentLoginBinding>(
R.layout.fragment_login
) {

private var _binding: FragmentLoginBinding? = null

private val binding get() = _binding!!
private val viewModel: LoginViewModel by viewModels()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = DataBindingUtil.inflate(
inflater,
R.layout.fragment_login,
container,
false
)
return binding.run {
vm = viewModel
lifecycleOwner = viewLifecycleOwner
root
}
}

// 버튼 클릭 시 로그인 확인 API 호출
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.vm = viewModel
initListener()
initCollector()
}
Expand All @@ -71,18 +46,12 @@ class LoginFragment : Fragment() {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.loginResponse.collect {
if (it.isSuccessful && it.body().toString() == LOGIN_SUCCESS) {
startActivity(Intent(requireContext(), MainActivity::class.java))
requireActivity().finish()
navigateActivity(MainActivity::class.java)
} else {
Logger.e(it.errorBody().toString())
sendSnackBar(it.errorBody().toString())
}
}
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Loading

0 comments on commit 6c3d5e3

Please sign in to comment.