Skip to content
Merged
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 @@ -16,6 +16,7 @@ enum class ResultFrom {
OtherUserProfileBack,
NovelRating,
WithdrawUser,
Notification,
;

val RESULT_OK: Int = ordinal + 1
Expand Down
23 changes: 15 additions & 8 deletions app/src/main/java/com/into/websoso/ui/main/home/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.into.websoso.ui.main.home

import android.Manifest
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import com.google.firebase.messaging.FirebaseMessaging
Expand All @@ -15,6 +16,7 @@ import com.into.websoso.core.common.ui.base.BaseFragment
import com.into.websoso.core.common.ui.model.ResultFrom.FeedDetailBack
import com.into.websoso.core.common.ui.model.ResultFrom.FeedDetailRemoved
import com.into.websoso.core.common.ui.model.ResultFrom.NormalExploreBack
import com.into.websoso.core.common.ui.model.ResultFrom.Notification
import com.into.websoso.core.common.ui.model.ResultFrom.NovelDetailBack
import com.into.websoso.core.common.ui.model.ResultFrom.ProfileEditSuccess
import com.into.websoso.core.common.util.tracker.Tracker
Expand All @@ -40,6 +42,15 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private val homeViewModel: HomeViewModel by viewModels()
private val mainViewModel: MainViewModel by activityViewModels()

private val homeResultLauncher: ActivityResultLauncher<Intent> =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
when (result.resultCode) {
Notification.RESULT_OK -> {
homeViewModel.updateNotificationUnread()
}
}
}

private val popularNovelsAdapter: PopularNovelsAdapter by lazy {
PopularNovelsAdapter(::onPopularNovelClick)
}
Expand Down Expand Up @@ -195,12 +206,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
}

private fun updateHasNotificationUnread(hasUnread: Boolean) {
val drawable = if (hasUnread) {
ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_notification_unread)
} else {
ContextCompat.getDrawable(requireContext(), R.drawable.ic_home_notification_read)
}
binding.ivHomeNotification.setImageDrawable(drawable)
binding.ivHomeNotification.isSelected = hasUnread
}

private fun showNotificationPermissionDialog() {
Expand Down Expand Up @@ -289,7 +295,8 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {

private fun onNotificationButtonClick() {
binding.ivHomeNotification.setOnClickListener {
startActivity(NotificationActivity.getIntent(requireContext()))
val intent = NotificationActivity.getIntent(requireContext())
homeResultLauncher.launch(intent)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class HomeViewModel
}
}

private fun updateNotificationUnread() {
fun updateNotificationUnread() {
viewModelScope.launch {
runCatching {
notificationRepository.fetchNotificationUnread()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import com.into.websoso.core.common.ui.model.ResultFrom
import com.into.websoso.core.designsystem.theme.WebsosoTheme
import com.into.websoso.domain.model.Notification
import com.into.websoso.ui.feedDetail.FeedDetailActivity
Expand All @@ -25,7 +26,10 @@ class NotificationActivity : ComponentActivity() {
viewModel = notificationViewModel,
onNotificationDetailClick = ::navigateToNotificationDetail,
onFeedDetailClick = ::navigateToFeedDetail,
onBackButtonClick = { finish() },
onBackButtonClick = {
setResult(ResultFrom.Notification.RESULT_OK)
finish()
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.into.websoso.ui.notification

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
Expand All @@ -19,6 +20,10 @@ fun NotificationScreen(
) {
val uiState by viewModel.notificationUiState.collectAsStateWithLifecycle()

BackHandler {
onBackButtonClick()
}

Column(modifier = Modifier.fillMaxSize()) {
NotificationAppBar(onBackButtonClick)
NotificationsContainer(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:layout_width="28dp"
android:layout_height="0dp"
android:layout_marginEnd="20dp"
android:src="@drawable/ic_home_notification_unread"
android:src="@drawable/ic_home_notification_selector"
app:layout_constraintBottom_toBottomOf="@id/iv_home_logo"
app:layout_constraintDimensionRatio="1"
app:layout_constraintEnd_toEndOf="parent"
Expand Down