feat(notification): 알림 수신 설정 화면을 추가한다
This commit is contained in:
@@ -160,6 +160,7 @@ import kr.co.vividnext.sodalive.settings.event.EventViewModel
|
||||
import kr.co.vividnext.sodalive.settings.notice.NoticeApi
|
||||
import kr.co.vividnext.sodalive.settings.notice.NoticeRepository
|
||||
import kr.co.vividnext.sodalive.settings.notice.NoticeViewModel
|
||||
import kr.co.vividnext.sodalive.settings.notification.NotificationReceiveSettingsViewModel
|
||||
import kr.co.vividnext.sodalive.settings.notification.NotificationSettingsViewModel
|
||||
import kr.co.vividnext.sodalive.settings.signout.SignOutViewModel
|
||||
import kr.co.vividnext.sodalive.settings.terms.TermsApi
|
||||
@@ -329,6 +330,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||
viewModel { NoticeViewModel(get()) }
|
||||
viewModel { EventViewModel(get()) }
|
||||
viewModel { NotificationSettingsViewModel(get()) }
|
||||
viewModel { NotificationReceiveSettingsViewModel(get(), get()) }
|
||||
viewModel { ContentSettingsViewModel() }
|
||||
viewModel { SettingsViewModel(get(), get()) }
|
||||
viewModel { SeriesDetailViewModel(get(), get()) }
|
||||
|
||||
@@ -14,6 +14,7 @@ import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.databinding.ActivityPushNotificationListBinding
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.home.HomeContentThemeAdapter
|
||||
import kr.co.vividnext.sodalive.settings.notification.NotificationReceiveSettingsActivity
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
class PushNotificationListActivity : BaseActivity<ActivityPushNotificationListBinding>(
|
||||
@@ -37,6 +38,9 @@ class PushNotificationListActivity : BaseActivity<ActivityPushNotificationListBi
|
||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||
binding.tvBack.text = getString(R.string.screen_push_notification_title)
|
||||
binding.tvBack.setOnClickListener { finish() }
|
||||
binding.ivSettings.setOnClickListener {
|
||||
startActivity(Intent(this, NotificationReceiveSettingsActivity::class.java))
|
||||
}
|
||||
|
||||
setupCategoryList()
|
||||
setupNotificationList()
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
package kr.co.vividnext.sodalive.settings.notification
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.base.BaseActivity
|
||||
import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.databinding.ActivityNotificationReceiveSettingsBinding
|
||||
import kr.co.vividnext.sodalive.explorer.profile.CreatorFollowNotifyFragment
|
||||
import kr.co.vividnext.sodalive.explorer.profile.UserProfileActivity
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.following.FollowingCreatorAdapter
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
class NotificationReceiveSettingsActivity : BaseActivity<ActivityNotificationReceiveSettingsBinding>(
|
||||
ActivityNotificationReceiveSettingsBinding::inflate
|
||||
) {
|
||||
|
||||
private val viewModel: NotificationReceiveSettingsViewModel by inject()
|
||||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
private lateinit var adapter: FollowingCreatorAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
bindData()
|
||||
|
||||
viewModel.getNotificationSettings()
|
||||
viewModel.getFollowedCreatorAllList()
|
||||
}
|
||||
|
||||
override fun setupView() {
|
||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||
|
||||
binding.toolbar.tvBack.text = getString(R.string.screen_notification_receive_settings_title)
|
||||
binding.toolbar.tvBack.setOnClickListener { finish() }
|
||||
|
||||
binding.ivNotifiedLive.setOnClickListener {
|
||||
viewModel.toggleFollowingChannelLiveNotice()
|
||||
}
|
||||
|
||||
binding.ivNotifiedUploadContent.setOnClickListener {
|
||||
viewModel.toggleFollowingChannelUploadContentNotice()
|
||||
}
|
||||
|
||||
binding.ivMessage.setOnClickListener { viewModel.toggleMessage() }
|
||||
|
||||
setupFollowingChannels()
|
||||
}
|
||||
|
||||
private fun setupFollowingChannels() {
|
||||
adapter = FollowingCreatorAdapter(
|
||||
onClickItem = { creatorId ->
|
||||
startActivity(
|
||||
Intent(applicationContext, UserProfileActivity::class.java).apply {
|
||||
putExtra(Constants.EXTRA_USER_ID, creatorId)
|
||||
}
|
||||
)
|
||||
},
|
||||
onClickFollow = { creatorId, isFollow ->
|
||||
if (isFollow) {
|
||||
val notifyFragment = CreatorFollowNotifyFragment(
|
||||
onClickNotifyAll = {
|
||||
viewModel.follow(creatorId, follow = true, notify = true)
|
||||
},
|
||||
onClickNotifyNone = {
|
||||
viewModel.follow(creatorId, follow = true, notify = false)
|
||||
},
|
||||
onClickUnFollow = {
|
||||
viewModel.follow(creatorId, follow = false, notify = false)
|
||||
}
|
||||
)
|
||||
|
||||
if (notifyFragment.isAdded) return@FollowingCreatorAdapter
|
||||
notifyFragment.show(supportFragmentManager, notifyFragment.tag)
|
||||
} else {
|
||||
viewModel.follow(creatorId)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
binding.rvFollowingChannel.layoutManager = LinearLayoutManager(
|
||||
applicationContext,
|
||||
LinearLayoutManager.VERTICAL,
|
||||
false
|
||||
)
|
||||
|
||||
binding.rvFollowingChannel.addItemDecoration(object : RecyclerView.ItemDecoration() {
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
outRect.left = 13.3f.dpToPx().toInt()
|
||||
outRect.right = 13.3f.dpToPx().toInt()
|
||||
}
|
||||
})
|
||||
|
||||
binding.rvFollowingChannel.adapter = adapter
|
||||
|
||||
binding.nsvContent.setOnScrollChangeListener { _, _, scrollY, _, _ ->
|
||||
val contentView = binding.nsvContent.getChildAt(0) ?: return@setOnScrollChangeListener
|
||||
if (scrollY >= contentView.measuredHeight - binding.nsvContent.measuredHeight) {
|
||||
viewModel.getFollowedCreatorAllList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun bindData() {
|
||||
viewModel.followingChannelLiveNotice.observe(this) {
|
||||
binding.ivNotifiedLive.setImageResource(
|
||||
if (it) {
|
||||
R.drawable.btn_toggle_on_big
|
||||
} else {
|
||||
R.drawable.btn_toggle_off_big
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
viewModel.followingChannelUploadContentNotice.observe(this) {
|
||||
binding.ivNotifiedUploadContent.setImageResource(
|
||||
if (it) {
|
||||
R.drawable.btn_toggle_on_big
|
||||
} else {
|
||||
R.drawable.btn_toggle_off_big
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
viewModel.isMessage.observe(this) {
|
||||
binding.ivMessage.setImageResource(
|
||||
if (it) {
|
||||
R.drawable.btn_toggle_on_big
|
||||
} else {
|
||||
R.drawable.btn_toggle_off_big
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
viewModel.creatorListLiveData.observe(this) {
|
||||
if (viewModel.page == 2) adapter.clear()
|
||||
adapter.addAll(it)
|
||||
}
|
||||
|
||||
viewModel.creatorListTotalCountLiveData.observe(this) {
|
||||
binding.tvTotalCount.text = " ${getString(
|
||||
R.string.following_creator_total_count_value,
|
||||
it
|
||||
)} "
|
||||
|
||||
if (it > 0) {
|
||||
binding.tvNone.visibility = View.GONE
|
||||
binding.rvFollowingChannel.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.tvNone.visibility = View.VISIBLE
|
||||
binding.rvFollowingChannel.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.isLoading.observe(this) {
|
||||
if (it) {
|
||||
loadingDialog.show(screenWidth, "")
|
||||
} else {
|
||||
loadingDialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.toastLiveData.observe(this) {
|
||||
val text = it?.message ?: it?.resId?.let { resId -> getString(resId) }
|
||||
text?.let { message ->
|
||||
Toast.makeText(applicationContext, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package kr.co.vividnext.sodalive.settings.notification
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.orhanobut.logger.Logger
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.base.BaseViewModel
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.common.ToastMessage
|
||||
import kr.co.vividnext.sodalive.following.FollowingCreatorRepository
|
||||
import kr.co.vividnext.sodalive.following.GetCreatorFollowingAllListItem
|
||||
import kr.co.vividnext.sodalive.user.UserRepository
|
||||
|
||||
class NotificationReceiveSettingsViewModel(
|
||||
private val userRepository: UserRepository,
|
||||
private val followingCreatorRepository: FollowingCreatorRepository
|
||||
) : BaseViewModel() {
|
||||
|
||||
private val _toastLiveData = MutableLiveData<ToastMessage?>()
|
||||
val toastLiveData: LiveData<ToastMessage?>
|
||||
get() = _toastLiveData
|
||||
|
||||
private val _isLoading = MutableLiveData(false)
|
||||
val isLoading: LiveData<Boolean>
|
||||
get() = _isLoading
|
||||
|
||||
private val _followingChannelLiveNotice = MutableLiveData(false)
|
||||
val followingChannelLiveNotice: LiveData<Boolean>
|
||||
get() = _followingChannelLiveNotice
|
||||
|
||||
private val _isMessage = MutableLiveData(false)
|
||||
val isMessage: LiveData<Boolean>
|
||||
get() = _isMessage
|
||||
|
||||
private val _followingChannelUploadContentNotice = MutableLiveData(false)
|
||||
val followingChannelUploadContentNotice: LiveData<Boolean>
|
||||
get() = _followingChannelUploadContentNotice
|
||||
|
||||
private val _creatorListLiveData = MutableLiveData<List<GetCreatorFollowingAllListItem>>()
|
||||
val creatorListLiveData: LiveData<List<GetCreatorFollowingAllListItem>>
|
||||
get() = _creatorListLiveData
|
||||
|
||||
private val _creatorListTotalCountLiveData = MutableLiveData(0)
|
||||
val creatorListTotalCountLiveData: LiveData<Int>
|
||||
get() = _creatorListTotalCountLiveData
|
||||
|
||||
private var _isFollowingListLoading = MutableLiveData(false)
|
||||
|
||||
var page = 1
|
||||
var isLast = false
|
||||
private var pageSize = PAGE_SIZE
|
||||
|
||||
fun getNotificationSettings() {
|
||||
_isLoading.value = true
|
||||
|
||||
compositeDisposable.add(
|
||||
userRepository.getMemberInfo(token = "Bearer ${SharedPreferenceManager.token}")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
|
||||
if (it.success && it.data != null) {
|
||||
val data = it.data
|
||||
_isMessage.value = data.messageNotice ?: false
|
||||
_followingChannelUploadContentNotice.value =
|
||||
data.followingChannelUploadContentNotice ?: false
|
||||
_followingChannelLiveNotice.value =
|
||||
data.followingChannelLiveNotice ?: false
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(ToastMessage(message = it.message))
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
ToastMessage(resId = R.string.common_error_unknown)
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
_isLoading.value = false
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue(ToastMessage(resId = R.string.retry))
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun toggleFollowingChannelLiveNotice() {
|
||||
val nextValue = !(_followingChannelLiveNotice.value ?: false)
|
||||
_followingChannelLiveNotice.value = nextValue
|
||||
updateNotificationSettings(live = nextValue)
|
||||
}
|
||||
|
||||
fun toggleFollowingChannelUploadContentNotice() {
|
||||
val nextValue = !(_followingChannelUploadContentNotice.value ?: false)
|
||||
_followingChannelUploadContentNotice.value = nextValue
|
||||
updateNotificationSettings(uploadContent = nextValue)
|
||||
}
|
||||
|
||||
fun toggleMessage() {
|
||||
val nextValue = !(_isMessage.value ?: false)
|
||||
_isMessage.value = nextValue
|
||||
updateNotificationSettings(message = nextValue)
|
||||
}
|
||||
|
||||
private fun updateNotificationSettings(
|
||||
live: Boolean? = null,
|
||||
uploadContent: Boolean? = null,
|
||||
message: Boolean? = null
|
||||
) {
|
||||
if (live != null || uploadContent != null || message != null) {
|
||||
compositeDisposable.add(
|
||||
userRepository.updateNotificationSettings(
|
||||
request = UpdateNotificationSettingRequest(
|
||||
live = live,
|
||||
uploadContent = uploadContent,
|
||||
message = message
|
||||
),
|
||||
token = "Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({}, {})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun getFollowedCreatorAllList() {
|
||||
if (isLast || _isFollowingListLoading.value == true) {
|
||||
return
|
||||
}
|
||||
|
||||
_isFollowingListLoading.value = true
|
||||
|
||||
compositeDisposable.add(
|
||||
followingCreatorRepository.getFollowedCreatorAllList(
|
||||
page = page,
|
||||
size = pageSize,
|
||||
token = "Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isFollowingListLoading.value = false
|
||||
pageSize = PAGE_SIZE
|
||||
|
||||
if (it.success && it.data != null) {
|
||||
if (it.data.items.isEmpty()) {
|
||||
isLast = true
|
||||
} else {
|
||||
page += 1
|
||||
_creatorListTotalCountLiveData.value = it.data.totalCount
|
||||
_creatorListLiveData.value = it.data.items
|
||||
}
|
||||
} else if (it.message != null) {
|
||||
_toastLiveData.postValue(ToastMessage(message = it.message))
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
ToastMessage(resId = R.string.common_error_unknown)
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
_isFollowingListLoading.value = false
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue(ToastMessage(resId = R.string.common_error_unknown))
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun follow(creatorId: Long, follow: Boolean = true, notify: Boolean = true) {
|
||||
_isLoading.value = true
|
||||
|
||||
compositeDisposable.add(
|
||||
userRepository.creatorFollow(
|
||||
creatorId = creatorId,
|
||||
follow = follow,
|
||||
notify = notify,
|
||||
token = "Bearer ${SharedPreferenceManager.token}"
|
||||
)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
{
|
||||
_isLoading.value = false
|
||||
|
||||
if (it.success && it.data != null) {
|
||||
isLast = false
|
||||
pageSize *= page
|
||||
page = 1
|
||||
getFollowedCreatorAllList()
|
||||
} else if (it.message != null) {
|
||||
_toastLiveData.postValue(ToastMessage(message = it.message))
|
||||
} else {
|
||||
_toastLiveData.postValue(
|
||||
ToastMessage(resId = R.string.common_error_unknown)
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
_isLoading.value = false
|
||||
it.message?.let { message -> Logger.e(message) }
|
||||
_toastLiveData.postValue(ToastMessage(resId = R.string.common_error_unknown))
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val PAGE_SIZE = 20
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user