Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/team-winey/Winey-AOS intโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆo feature/mod-levelup-guide-noti

# Conflicts:
#	app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt
#	app/src/main/java/org/go/sopt/winey/presentation/splash/SplashActivity.kt
  • Loading branch information
leeeha committed Mar 2, 2024
2 parents 4788e58 + f58802b commit 8cca570
Show file tree
Hide file tree
Showing 17 changed files with 870 additions and 391 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
android:name=".presentation.main.notification.NotificationActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.main.mypage.setting.SettingActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.main.mypage.goal.GoalPathActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import android.provider.Settings
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.fragment.app.replace
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -41,7 +39,6 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
private val isUploadSuccess by lazy { intent.getBooleanExtra(KEY_FEED_UPLOAD, false) }
private val isDeleteSuccess by lazy { intent.getBooleanExtra(KEY_FEED_DELETE, false) }

private val prevScreenName by lazy { intent.getStringExtra(KEY_PREV_SCREEN) }
private val notiType by lazy { intent.getStringExtra(KEY_NOTI_TYPE) }
private val feedId by lazy { intent.getStringExtra(KEY_FEED_ID) }

Expand Down Expand Up @@ -125,11 +122,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
return
}

if (prevScreenName == MY_FEED_SCREEN) {
navigateToMyPageFragment(KEY_TO_MYFEED, true)
} else {
navigateTo<WineyFeedFragment>()
}
navigateTo<WineyFeedFragment>()
}

private fun showWineyFeedResultSnackBar() {
Expand Down Expand Up @@ -204,12 +197,6 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}
}

private inline fun <reified T : Fragment> navigateTo() {
supportFragmentManager.commit {
replace<T>(R.id.fcv_main, T::class.simpleName)
}
}

private fun navigateToMyPageFragment(key: String, value: Boolean) {
supportFragmentManager.commit {
val bundle = Bundle()
Expand All @@ -232,18 +219,20 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
startActivity(intent)
}

companion object {
const val KEY_FEED_ID = "feedId"
const val KEY_TO_MY_PAGE = "navigateMyPage"
const val KEY_FROM_GOAL_PATH = "fromGoalPath"
private inline fun <reified T : Fragment> navigateTo() {
supportFragmentManager.commit {
replace<T>(R.id.fcv_main, T::class.simpleName)
}
}

companion object {
private const val KEY_FEED_UPLOAD = "upload"
private const val KEY_FEED_DELETE = "delete"
private const val KEY_NOTI_TYPE = "notiType"
private const val KEY_FROM_NOTI = "fromNoti"
private const val KEY_TO_MYFEED = "toMyFeed"

private const val KEY_PREV_SCREEN = "PREV_SCREEN_NAME"
private const val MY_FEED_SCREEN = "MyFeedFragment"
const val KEY_FEED_ID = "feedId"
const val KEY_TO_MY_PAGE = "navigateMyPage"
const val KEY_FROM_GOAL_PATH = "fromGoalPath"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MainViewModel @Inject constructor(
private val dataStoreRepository: DataStoreRepository,
private val notificationRepository: NotificationRepository
) : ViewModel() {
private val _getUserState = MutableStateFlow<UiState<UserV2?>>(UiState.Loading)
private val _getUserState = MutableStateFlow<UiState<UserV2?>>(UiState.Empty)
val getUserState: StateFlow<UiState<UserV2?>> = _getUserState.asStateFlow()

private val _logoutState = MutableStateFlow<UiState<ResponseLogoutDto?>>(UiState.Empty)
Expand All @@ -44,7 +44,7 @@ class MainViewModel @Inject constructor(

authRepository.getUser()
.onSuccess { response ->
Timber.e("SUCCESS GET USER IN MAIN")
Timber.d("SUCCESS GET USER IN MAIN")
dataStoreRepository.saveUserInfo(response)
_getUserState.value = UiState.Success(response)
}
Expand All @@ -61,7 +61,7 @@ class MainViewModel @Inject constructor(
}
}

private fun postLogout() {
fun postLogout() {
viewModelScope.launch {
_logoutState.value = UiState.Loading

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@ import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.paging.LoadState
import androidx.paging.PagingData
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.SimpleItemAnimator
import com.google.android.material.bottomnavigation.BottomNavigationView
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.go.sopt.winey.R
import org.go.sopt.winey.databinding.FragmentWineyFeedBinding
import org.go.sopt.winey.domain.entity.UserV2
import org.go.sopt.winey.domain.entity.WineyFeed
import org.go.sopt.winey.domain.repository.DataStoreRepository
import org.go.sopt.winey.presentation.main.MainViewModel
import org.go.sopt.winey.presentation.main.feed.detail.DetailActivity
import org.go.sopt.winey.presentation.main.feed.upload.UploadActivity
import org.go.sopt.winey.presentation.main.mypage.MyPageFragment
import org.go.sopt.winey.presentation.main.mypage.goal.GoalPathActivity
import org.go.sopt.winey.presentation.main.notification.NotificationActivity
import org.go.sopt.winey.presentation.model.WineyDialogLabel
Expand Down Expand Up @@ -60,9 +57,9 @@ class WineyFeedFragment :
private val viewModel by viewModels<WineyFeedViewModel>()
private val mainViewModel by activityViewModels<MainViewModel>()
private lateinit var wineyFeedAdapter: WineyFeedAdapter
private lateinit var wineyFeedHeaderAdapter: WineyFeedHeaderAdapter
private lateinit var wineyFeedGoalAdapter: WineyFeedGoalAdapter
private lateinit var wineyFeedLoadAdapter: WineyFeedLoadAdapter
private lateinit var wineyFeedHeaderAdapter: WineyFeedHeaderAdapter
private var wineyFeedGoalAdapter: WineyFeedGoalAdapter? = null
private var clickedFeedId = -1

@Inject
Expand Down Expand Up @@ -109,7 +106,6 @@ class WineyFeedFragment :

/** Adapter */
private fun initAdapter() {
initGoalAdapter()
wineyFeedHeaderAdapter = WineyFeedHeaderAdapter(
onBannerClicked = {
navigateToWineyInstagram()
Expand All @@ -129,21 +125,16 @@ class WineyFeedFragment :
}
)
wineyFeedLoadAdapter = WineyFeedLoadAdapter()
initConcatAdapter()
}

private fun initConcatAdapter() {
binding.rvWineyfeedPost.adapter = ConcatAdapter(
wineyFeedHeaderAdapter,
wineyFeedGoalAdapter,
wineyFeedAdapter.withLoadStateFooter(wineyFeedLoadAdapter)
)
}

private fun initGoalAdapter() {
viewLifeCycleScope.launch {
val user = dataStoreRepository.getUserInfo().firstOrNull() ?: return@launch
wineyFeedGoalAdapter = WineyFeedGoalAdapter(requireContext(), user)
}
}

private fun navigateToWineyInstagram() {
val url = INSTAGRAM_URL
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
Expand Down Expand Up @@ -278,13 +269,25 @@ class WineyFeedFragment :
mainViewModel.getUserState.flowWithLifecycle(viewLifeCycle)
.onEach { state ->
when (state) {
is UiState.Loading -> {
showLoadingProgressBar()
}

is UiState.Success -> {
// ํ”ผ๋“œ ์ƒ์„ฑ, ์‚ญ์ œ์— ๋”ฐ๋ผ ์œ ์ € ๋ฐ์ดํ„ฐ์™€ ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ๊ฐฑ์‹ 
val userInfo = state.data ?: return@onEach
wineyFeedGoalAdapter.updateProgressBar(userInfo)

if (wineyFeedGoalAdapter == null) {
updateConcatAdapter(userInfo)
} else {
// ํ”ผ๋“œ ์ƒ์„ฑ, ์‚ญ์ œ์— ๋”ฐ๋ผ ์œ ์ € ๋ฐ์ดํ„ฐ์™€ ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ๊ฐฑ์‹ 
wineyFeedGoalAdapter?.updateGoalProgressBar(userInfo)
}

dismissLoadingProgressBar()
}

is UiState.Failure -> {
dismissLoadingProgressBar()
snackBar(binding.root) { state.msg }
}

Expand All @@ -293,6 +296,25 @@ class WineyFeedFragment :
}.launchIn(viewLifeCycleScope)
}

private fun updateConcatAdapter(user: UserV2) {
wineyFeedGoalAdapter = WineyFeedGoalAdapter(requireContext(), user)
binding.rvWineyfeedPost.adapter = ConcatAdapter(
wineyFeedHeaderAdapter,
wineyFeedGoalAdapter,
wineyFeedAdapter.withLoadStateFooter(wineyFeedLoadAdapter)
)
}

private fun showLoadingProgressBar() {
binding.pbWineyfeedLoading.isVisible = true
binding.rvWineyfeedPost.isVisible = false
}

private fun dismissLoadingProgressBar() {
binding.pbWineyfeedLoading.isVisible = false
binding.rvWineyfeedPost.isVisible = true
}

private fun initGetWineyFeedListStateObserver() {
viewModel.getWineyFeedListState.flowWithLifecycle(viewLifeCycle)
.onEach { state ->
Expand Down Expand Up @@ -450,23 +472,6 @@ class WineyFeedFragment :
}

/** Amplitude Event Tagging */
private fun sendDialogClickEvent(isNavigate: Boolean) {
val eventProperties = JSONObject()

try {
if (isNavigate) {
eventProperties.put("method", "yes")
} else {
eventProperties.put("method", "no")
}
} catch (e: JSONException) {
System.err.println("Invalid JSON")
e.printStackTrace()
}

amplitudeUtils.logEvent("click_goalsetting", eventProperties)
}

private fun sendWineyFeedEvent(type: EventType, feed: WineyFeed) {
val eventProperties = JSONObject()

Expand Down Expand Up @@ -496,59 +501,18 @@ class WineyFeedFragment :
}
}

private fun showDefaultGoalSettingDialog() {
amplitudeUtils.logEvent("view_goalsetting_popup")

val dialog = WineyDialogFragment.newInstance(
WineyDialogLabel(
stringOf(R.string.wineyfeed_goal_dialog_title),
stringOf(R.string.wineyfeed_goal_dialog_subtitle),
stringOf(R.string.wineyfeed_goal_dialog_negative_button),
stringOf(R.string.wineyfeed_goal_dialog_positive_button)
),
handleNegativeButton = {
sendDialogClickEvent(false)
},
handlePositiveButton = {
sendDialogClickEvent(true)
navigateToMyPageWithBundle()
}
)

activity?.supportFragmentManager?.let { dialog.show(it, TAG_DEFAULT_GOAL_SETTING_DIALOG) }
}

private fun navigateToMyPageWithBundle() {
val myPageFragment = MyPageFragment().apply {
arguments = Bundle().apply {
putBoolean(KEY_FROM_WINEY_FEED, true)
}
}
activity?.supportFragmentManager?.commit {
replace(R.id.fcv_main, myPageFragment)
}
syncBnvSelectedItem()
}

private fun syncBnvSelectedItem() {
val bottomNav: BottomNavigationView = requireActivity().findViewById(R.id.bnv_main)
bottomNav.selectedItemId = R.id.menu_mypage
}

companion object {
private const val INSTAGRAM_URL =
"https://instagram.com/winey__official?igshid=MzRlODBiNWFlZA=="

private const val MSG_WINEYFEED_ERROR = "ERROR"
private const val TAG_DEFAULT_GOAL_SETTING_DIALOG = "DEFAULT_GOAL_SETTING_DIALOG"

private const val TAG_FEED_DELETE_DIALOG = "FEED_DELETE_DIALOG"
private const val TAG_FEED_REPORT_DIALOG = "FEED_REPORT_DIALOG"
private const val TAG_UPLOAD_DIALOG = "UPLOAD_DIALOG"
private const val TAG_CONGRATULATION_DIALOG = "CONGRATULATION_DIALOG"

private const val KEY_PREV_SCREEN_NAME = "PREV_SCREEN_NAME"
private const val WINEY_FEED_SCREEN = "WineyFeedFragment"
private const val KEY_FROM_WINEY_FEED = "fromWineyFeed"
private const val KEY_FEED_ID = "feedId"
private const val KEY_FEED_WRITER_ID = "feedWriterId"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class WineyFeedGoalAdapter(
private val initialUser: UserV2
) : RecyclerView.Adapter<WineyFeedGoalAdapter.WineyFeedGoalViewHolder>() {
private lateinit var binding: ItemWineyfeedGoalBinding
private var isInitialized = false

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WineyFeedGoalViewHolder {
binding = ItemWineyfeedGoalBinding.inflate(
Expand All @@ -33,18 +32,21 @@ class WineyFeedGoalAdapter(
override fun getItemCount(): Int = ITEM_COUNT

inner class WineyFeedGoalViewHolder : RecyclerView.ViewHolder(binding.root) {
private var isInitialized = false

fun bind() {
if (!isInitialized) {
isInitialized = true

// ์ตœ์ดˆ 1ํšŒ๋งŒ ์‹คํ–‰ (์•„์ดํ…œ ๋ทฐ์˜ ์žฌํ™œ์šฉ์— ๋”ฐ๋ผ ์˜ˆ์ „ ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ฐ˜์˜๋˜๋Š” ๋ฌธ์ œ ํ•ด๊ฒฐ)
updateProgressBar(initialUser)
// ์ดˆ๊ธฐ ์œ ์ € ๋ฐ์ดํ„ฐ๋กœ ์ตœ์ดˆ 1ํšŒ๋งŒ ๋ฐ”์ธ๋”ฉ
updateGoalProgressBar(initialUser)
}
}
}

fun updateProgressBar(user: UserV2) {
fun updateGoalProgressBar(user: UserV2) {
if (::binding.isInitialized) {
// ํ”ผ๋“œ ์ƒ์„ฑ, ์‚ญ์ œ์— ๋”ฐ๋ผ ๋ฐ”๋€Œ๋Š” ์œ ์ € ๋ฐ์ดํ„ฐ ๋ฐ˜์˜
binding.user = user
updateProgressBarRate(user)
}
Expand Down
Loading

0 comments on commit 8cca570

Please sign in to comment.