Skip to content

Commit

Permalink
Merge pull request #4504 from nextcloud/feature/4501/notificationWarn…
Browse files Browse the repository at this point in the history
…ingLessProminent

new notification warner
  • Loading branch information
mahibi authored Dec 2, 2024
2 parents 2340272 + 366c2b5 commit 187f98a
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class ConversationsListActivity :
adapter!!.addListener(this)
prepareViews()

updateNotificationWarning()
showNotificationWarning()

showShareToScreen = hasActivityActionSendIntent()

Expand All @@ -296,6 +296,13 @@ class ConversationsListActivity :
loadUserAvatar(binding.switchAccountButton)
viewThemeUtils.material.colorMaterialTextButton(binding.switchAccountButton)
viewThemeUtils.material.themeCardView(binding.conversationListHintInclude.hintLayoutCardview)
viewThemeUtils.material.themeCardView(
binding.conversationListNotificationWarning.notificationWarningCardview
)
viewThemeUtils.material.colorMaterialButtonText(binding.conversationListNotificationWarning.notNowButton)
viewThemeUtils.material.colorMaterialButtonText(
binding.conversationListNotificationWarning.showSettingsButton
)
searchBehaviorSubject.onNext(false)
fetchRooms()
fetchPendingInvitations()
Expand All @@ -307,14 +314,6 @@ class ConversationsListActivity :
showSearchOrToolbar()
}

private fun updateNotificationWarning() {
if (shouldShowNotificationWarning()) {
showNotificationWarning()
} else {
binding.chatListNotificationWarning.visibility = View.GONE
}
}

private fun initObservers() {
this.lifecycleScope.launch {
networkMonitor.isOnline.onEach { isOnline ->
Expand All @@ -326,14 +325,17 @@ class ConversationsListActivity :
conversationsListViewModel.getFederationInvitationsViewState.observe(this) { state ->
when (state) {
is ConversationsListViewModel.GetFederationInvitationsStartState -> {
binding.conversationListHintInclude.conversationListHintLayout.visibility = View.GONE
binding.conversationListHintInclude.conversationListHintLayout.visibility =
View.GONE
}

is ConversationsListViewModel.GetFederationInvitationsSuccessState -> {
if (state.showInvitationsHint) {
binding.conversationListHintInclude.conversationListHintLayout.visibility = View.VISIBLE
binding.conversationListHintInclude.conversationListHintLayout.visibility =
View.VISIBLE
} else {
binding.conversationListHintInclude.conversationListHintLayout.visibility = View.GONE
binding.conversationListHintInclude.conversationListHintLayout.visibility =
View.GONE
}
}

Expand Down Expand Up @@ -1502,17 +1504,48 @@ class ConversationsListActivity :
}

private fun showNotificationWarning() {
binding.chatListNotificationWarning.visibility = View.VISIBLE
binding.chatListNotificationWarning.setOnClickListener {
val bundle = Bundle()
bundle.putBoolean(KEY_SCROLL_TO_NOTIFICATION_CATEGORY, true)
val settingsIntent = Intent(context, SettingsActivity::class.java)
settingsIntent.putExtras(bundle)
startActivity(settingsIntent)
if (shouldShowNotificationWarning()) {
binding.conversationListNotificationWarning.conversationListNotificationWarningLayout.visibility =
View.VISIBLE
binding.conversationListNotificationWarning.notNowButton.setOnClickListener {
binding.conversationListNotificationWarning.conversationListNotificationWarningLayout.visibility =
View.GONE
val lastWarningDate = System.currentTimeMillis()
appPreferences.setNotificationWarningLastPostponedDate(lastWarningDate)
}
binding.conversationListNotificationWarning.showSettingsButton.setOnClickListener {
val bundle = Bundle()
bundle.putBoolean(KEY_SCROLL_TO_NOTIFICATION_CATEGORY, true)
val settingsIntent = Intent(context, SettingsActivity::class.java)
settingsIntent.putExtras(bundle)
startActivity(settingsIntent)
}
} else {
binding.conversationListNotificationWarning.conversationListNotificationWarningLayout.visibility = View.GONE
}
}

private fun shouldShowNotificationWarning(): Boolean {
fun shouldShowWarningIfDateTooOld(date1: Long): Boolean {
val currentTimeMillis = System.currentTimeMillis()
val differenceMillis = currentTimeMillis - date1
val daysForWarningInMillis = TimeUnit.DAYS.toMillis(DAYS_FOR_NOTIFICATION_WARNING)
return differenceMillis > daysForWarningInMillis
}

fun shouldShowNotificationWarningByUserChoice(): Boolean {
if (appPreferences.showRegularNotificationWarning) {
val lastWarningDate = appPreferences.getNotificationWarningLastPostponedDate()
return if (lastWarningDate == NOTIFICATION_WARNING_DATE_NOT_SET) {
true
} else {
shouldShowWarningIfDateTooOld(lastWarningDate)
}
} else {
return false
}
}

val notificationPermissionNotGranted = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
!platformPermissionUtil.isPostNotificationsPermissionGranted()
val batteryOptimizationNotIgnored = !PowerManagerUtils().isIgnoringBatteryOptimizations()
Expand All @@ -1529,10 +1562,8 @@ class ConversationsListActivity :
callsChannelNotEnabled ||
!serverNotificationAppInstalled

val userWantsToBeNotifiedAboutWrongSettings = appPreferences.getShowNotificationWarning()

return settingsOfUserAreWrong &&
userWantsToBeNotifiedAboutWrongSettings &&
shouldShowNotificationWarningByUserChoice() &&
ClosedInterfaceImpl().isGooglePlayServicesAvailable
}

Expand Down Expand Up @@ -1927,5 +1958,7 @@ class ConversationsListActivity :
const val MAINTENANCE_MODE_HEADER_KEY = "X-Nextcloud-Maintenance-Mode"
const val REQUEST_POST_NOTIFICATIONS_PERMISSION = 111
const val BADGE_OFFSET = 35
const val DAYS_FOR_NOTIFICATION_WARNING = 5L
const val NOTIFICATION_WARNING_DATE_NOT_SET = 0L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.nextcloud.talk.api.NcApiCoroutines
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.setAppTheme
import com.nextcloud.talk.conversationlist.ConversationsListActivity
import com.nextcloud.talk.conversationlist.ConversationsListActivity.Companion.NOTIFICATION_WARNING_DATE_NOT_SET
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ActivitySettingsBinding
import com.nextcloud.talk.diagnose.DiagnoseActivity
Expand Down Expand Up @@ -927,13 +928,16 @@ class SettingsActivity :

private fun setupCheckables() {
binding.settingsShowNotificationWarningSwitch.isChecked =
appPreferences.showNotificationWarning
appPreferences.showRegularNotificationWarning

if (ClosedInterfaceImpl().isGooglePlayServicesAvailable) {
binding.settingsShowNotificationWarning.setOnClickListener {
val isChecked = binding.settingsShowNotificationWarningSwitch.isChecked
binding.settingsShowNotificationWarningSwitch.isChecked = !isChecked
appPreferences.setShowNotificationWarning(!isChecked)
appPreferences.setShowRegularNotificationWarning(!isChecked)
if (!isChecked) {
appPreferences.setNotificationWarningLastPostponedDate(NOTIFICATION_WARNING_DATE_NOT_SET)
}
}
} else {
binding.settingsShowNotificationWarning.visibility = View.GONE
Expand Down Expand Up @@ -1427,5 +1431,6 @@ class SettingsActivity :
private const val LINEBREAK = "\n"
const val HTTP_CODE_OK: Int = 200
const val HTTP_ERROR_CODE_BAD_REQUEST: Int = 400
const val NO_NOTIFICATION_REMINDER_WANTED = 0L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,13 @@ public interface AppPreferences {

void deleteAllMessageQueuesFor(String userId);

boolean getShowNotificationWarning();
Long getNotificationWarningLastPostponedDate();

void setShowNotificationWarning(boolean showNotificationWarning);
void setNotificationWarningLastPostponedDate(Long showNotificationWarning);

Boolean getShowRegularNotificationWarning();

void setShowRegularNotificationWarning(boolean value);

void clear();
}
Loading

0 comments on commit 187f98a

Please sign in to comment.