Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#55 follow setting refactor, 상수화 #59

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class BindingFragment<T : ViewDataBinding>(


override fun onDestroyView() {
super.onDestroyView()
_binding = null
super.onDestroyView()
}
}
12 changes: 9 additions & 3 deletions data-remote/src/main/java/com/data_remote/api/SignApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package com.data_remote.api

import com.velogm.data.dto.response.TokenResponseDto
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface SignApiService {
@GET("/sign-api/google-login")

companion object {
const val SIGN_API = "sign-api"
const val GOOGLE_LOGIN = "google-login"
const val CODE = "code"
}

@GET("/$SIGN_API/$GOOGLE_LOGIN")
suspend fun getGoogleLogin(
@Query("code") code: String
@Query(CODE) code: String
): TokenResponseDto
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,44 @@ import retrofit2.http.Path
import retrofit2.http.Query

interface SubscribeApiService {

@GET("/subscribe/trendposts")
companion object {
const val SUBSCRIBE = "subscribe"
const val TREND_POSTS = "trendposts"
const val SUBSCRIBER_POSTS = "subscriberpost"
const val GET_SUBSCRIBER = "getsubscriber"
const val UNSUBSCRIBE = "unsubscribe"
const val TARGET_NAME = "targetName"
const val INPUT_NAME = "inputname"
const val NAME = "name"
const val ADD_SUBSCRIBER = "addsubscriber"
const val FCM_TOKEN = "fcmToken"
}

@GET("/$SUBSCRIBE/$TREND_POSTS")
suspend fun getTrendPost(
): PostListDto

@GET("/subscribe/subscriberpost")
@GET("/$SUBSCRIBE/$SUBSCRIBER_POSTS")
suspend fun getFollowPost(
): PostFollowListDto

@GET("/subscribe/getsubscriber")
@GET("/$SUBSCRIBE/$GET_SUBSCRIBER")
suspend fun getFollower(
): List<FollowerDto>

@DELETE("/subscribe/unsubscribe/{targetName}")
@DELETE("/$SUBSCRIBE/$UNSUBSCRIBE/{$TARGET_NAME}")
suspend fun deleteFollower(
@Path(value = "targetName") followerName: String
@Path(value = TARGET_NAME) followerName: String
): DeleteFollowerDto

@GET("/subscribe/inputname/{name}")
@GET("/$SUBSCRIBE/$INPUT_NAME/{$NAME}")
suspend fun getInputFollower(
@Path(value = "name") followerName: String?
@Path(value = NAME) followerName: String?
): InputFollowerDto

@POST("/subscribe/addsubscriber")
@POST("/$SUBSCRIBE/$ADD_SUBSCRIBER")
suspend fun postAddFollower(
@Query("fcmToken") token: String,
@Query("name") followerName: String
@Query(FCM_TOKEN) token: String,
@Query(NAME) followerName: String
): String
}
35 changes: 22 additions & 13 deletions data-remote/src/main/java/com/data_remote/api/TagApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,36 @@ import retrofit2.http.POST
import retrofit2.http.Query

interface TagApiService {
@GET("/tag/gettag")

companion object {
const val TAG = "tag"
const val GET_TAG = "gettag"
const val POPULAR_POST = "popularpost"
const val DELETE_TAG = "deletetag"
const val ADD_TAG = "addtag"
const val GET_TAG_POST = "gettagpost"
}

@GET("/$TAG/$GET_TAG")
suspend fun getTag(
):List<String>
): List<String>

@GET("/tag/popularpost")
@GET("/$TAG/$POPULAR_POST")
suspend fun getPopularTag(
):List<String>
): List<String>

@DELETE("/tag/deletetag")
@DELETE("/$TAG/$DELETE_TAG")
suspend fun deleteTag(
@Query("tag") tag:String
):String
@Query(TAG) tag: String
): String

@POST("/tag/addtag")
@POST("/$TAG/$ADD_TAG")
suspend fun addTag(
@Query("tag") tag:String
):String
@Query(TAG) tag: String
): String

@GET("/tag/gettagpost")
@GET("/$TAG/$GET_TAG_POST")
suspend fun getTagPost(
@Query("tag") tag:String
@Query(TAG) tag: String
): List<TrendPostDto>

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.velogm.core_ui.base.BindingFragment
import com.velogm.core_ui.context.hideKeyboard
import com.velogm.core_ui.view.UiState
import com.velogm.presentation.R
import com.velogm.presentation.databinding.FragmentAddFollowerBinding
Expand All @@ -34,42 +35,10 @@ class AddFollowerFragment :
initClickEventListeners()
initEditText()
addFollower()
removeText()
collectInputResult()
collectEventData()
collectDeleteFollower()
removeText()
}

private fun collectInputResult() {
addFollowerViewModel.getInputFollower.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Loading -> {
}

is UiState.Success -> {
with(binding) {
addFollower = it.data
val list: ArrayList<String>? =
requireArguments().getStringArrayList(FOLLOWER_LIST)

layoutAddFollower.visibility =
if (it.data.validate) View.VISIBLE else View.GONE

if (list != null) {
val isFollowing = it.data.userName in list
binding.tvAddFollowerLabel.text = if (isFollowing) "팔로우 취소" else "팔로우"
}

layoutAddFollowerEmpty.visibility =
if (!it.data.validate) View.VISIBLE else View.GONE
}
}

else -> {
binding.layoutAddFollowerEmpty.visibility = View.VISIBLE
}
}
}.launchIn(lifecycleScope)
}

private fun initClickEventListeners() {
Expand All @@ -85,6 +54,7 @@ class AddFollowerFragment :
if (actionId == EditorInfo.IME_ACTION_DONE || (event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER)) {
addFollowerViewModel.getInputFollower(binding.etAddFollowerSearch.text.toString())
binding.etAddFollowerSearch.text?.clear()
requireActivity().hideKeyboard(binding.root)
true
} else {
false
Expand All @@ -94,7 +64,7 @@ class AddFollowerFragment :

private fun addFollower() {
binding.tvAddFollowerLabel.setOnClickListener {
if (binding.tvAddFollowerLabel.text == "팔로우") {
if (binding.tvAddFollowerLabel.text == getString(R.string.tv_add_follower_button)) {
addFollowerViewModel.addFollower(binding.tvAddFollowerName.text.toString())
} else {
val dialog = DeleteFollowerDialogFragment(deleteFollower = {
Expand All @@ -105,44 +75,71 @@ class AddFollowerFragment :
}
}

private fun collectEventData() {
addFollowerViewModel.eventData.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Loading -> {
private fun removeText() {
with(binding) {
etAddFollowerSearch.doAfterTextChanged { text ->
if (text?.length == 0) {
ivAddFollowerCancel.visibility = View.INVISIBLE
} else {
ivAddFollowerCancel.visibility = View.VISIBLE
ivAddFollowerCancel.setOnClickListener { etAddFollowerSearch.text.clear() }
}
}
}
}

private fun collectInputResult() {
addFollowerViewModel.getInputFollower.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Loading -> Unit

is UiState.Success -> {
binding.tvAddFollowerLabel.text = "팔로우 취소"
with(binding) {
addFollower = it.data
val list: ArrayList<String>? =
requireArguments().getStringArrayList(FOLLOWER_LIST)

layoutAddFollower.visibility =
if (it.data.validate) View.VISIBLE else View.GONE

if (list != null) {
val isFollowing = it.data.userName in list
binding.tvAddFollowerLabel.text =
if (isFollowing) getString(R.string.tv_item_rv_follow_cancel) else getString(
R.string.tv_add_follower_button
)
}

layoutAddFollowerEmpty.visibility =
if (!it.data.validate) View.VISIBLE else View.GONE
}
}

else -> {}
else -> binding.layoutAddFollowerEmpty.visibility = View.VISIBLE
}
}.launchIn(lifecycleScope)
}

private fun collectDeleteFollower() {
followViewModel.deleteFollower.flowWithLifecycle(lifecycle).onEach {
private fun collectEventData() {
addFollowerViewModel.eventData.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Success -> {
binding.tvAddFollowerLabel.text = "팔로우"
}
is UiState.Success -> binding.tvAddFollowerLabel.text =
getString(R.string.tv_item_rv_follow_cancel)

else -> {}
else -> Unit
}
}.launchIn(lifecycleScope)
}

private fun removeText() {
with(binding) {
etAddFollowerSearch.doAfterTextChanged { text ->
if (text?.length == 0) {
ivAddFollowerCancel.visibility = View.INVISIBLE
} else {
ivAddFollowerCancel.visibility = View.VISIBLE
ivAddFollowerCancel.setOnClickListener { etAddFollowerSearch.text.clear() }
}
private fun collectDeleteFollower() {
followViewModel.deleteFollower.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Success -> binding.tvAddFollowerLabel.text =
getString(R.string.tv_add_follower_button)

else -> Unit
}
}
}.launchIn(lifecycleScope)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.velogm.core_ui.base.BindingFragment
import com.velogm.core_ui.fragment.toast
import com.velogm.core_ui.view.UiState
import com.velogm.presentation.R
import com.velogm.presentation.databinding.FragmentFollowBinding
Expand Down Expand Up @@ -40,21 +39,23 @@ class FollowFragment : BindingFragment<FragmentFollowBinding>(R.layout.fragment_
private fun collectFollowerNameList() {
viewModel.getFollowerNameList.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Success -> {
openAddFollower(it.data.name)
}

else -> {}
is UiState.Success -> openAddFollower(it.data.name)
else -> Unit
}
}.launchIn(lifecycleScope)
}

private fun openAddFollower(list: ArrayList<String>) {
binding.tvFollowAddFollower.setOnClickListener {
findNavController().navigate(
R.id.action_follow_to_addFollowerFragment, bundleOf(FOLLOWER_LIST to list)
)
}
}

private fun collectFollower() {
viewModel.getFollower.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Loading -> {
}

is UiState.Success -> {
binding.rvFollow.adapter = FollowerAdapter(deleteFollowerClick = {
val dialog = DeleteFollowerDialogFragment(deleteFollower = {
Expand All @@ -68,28 +69,17 @@ class FollowFragment : BindingFragment<FragmentFollowBinding>(R.layout.fragment_
}
}

else -> {}
else -> Unit
}
}.launchIn(lifecycleScope)
}

private fun collectDeleteFollower() {
viewModel.deleteFollower.flowWithLifecycle(lifecycle).onEach {
when (it) {
is UiState.Success -> {
viewModel.getFollower()
}

else -> {}
is UiState.Success -> viewModel.getFollower()
else -> Unit
}
}.launchIn(lifecycleScope)
}

private fun openAddFollower(list: ArrayList<String>) {
binding.tvFollowAddFollower.setOnClickListener {
findNavController().navigate(
R.id.action_follow_to_addFollowerFragment, bundleOf(FOLLOWER_LIST to list)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ class FollowViewModel @Inject constructor(
}
_deleteFollower.value = UiState.Loading
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@ class SettingFragment : BindingFragment<FragmentSettingBinding>(R.layout.fragmen
dialog.show(childFragmentManager, "withdrawal")
}
}

}
1 change: 1 addition & 0 deletions presentation/src/main/res/layout/fragment_add_follower.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
android:drawableStart="@drawable/ic_follow_reading_glasses"
android:drawablePadding="10dp"
android:hint="@string/et_follow_hint"
android:maxLines="1"
android:paddingHorizontal="14dp"
android:paddingVertical="10dp"
android:textAppearance="@style/TextAppearance.VelogM.Body1_M"
Expand Down