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
5 changes: 5 additions & 0 deletions app/src/org/commcare/activities/connect/ConnectActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.commcare.connect.ConnectConstants.GO_TO_JOB_STATUS;
import static org.commcare.connect.ConnectConstants.REDIRECT_ACTION;
import static org.commcare.connect.ConnectConstants.SHOW_LAUNCH_BUTTON;
import static org.commcare.personalId.PersonalIdFeatureFlagChecker.FeatureFlag.NOTIFICATIONS;

import android.content.BroadcastReceiver;
import android.content.Context;
Expand Down Expand Up @@ -35,6 +36,7 @@
import org.commcare.connect.database.ConnectMessagingDatabaseHelper;
import org.commcare.dalvik.R;
import org.commcare.fragments.RefreshableFragment;
import org.commcare.personalId.PersonalIdFeatureFlagChecker;
import org.commcare.utils.FirebaseMessagingUtil;
import org.commcare.views.dialogs.CustomProgressDialog;

Expand Down Expand Up @@ -145,6 +147,9 @@ public boolean onCreateOptionsMenu(Menu menu) {
messagingMenuItem = menu.findItem(R.id.action_messaging);
updateMessagingIcon();

MenuItem notiificationsMenuItem = menu.findItem(R.id.action_bell);
notiificationsMenuItem.setVisible(PersonalIdFeatureFlagChecker.isFeatureEnabled(NOTIFICATIONS));

return super.onCreateOptionsMenu(menu);
}

Expand Down
30 changes: 21 additions & 9 deletions app/src/org/commcare/navdrawer/BaseDrawerController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import org.commcare.connect.database.NotificationRecordDatabaseHelper
import org.commcare.dalvik.BuildConfig
import org.commcare.dalvik.R
import org.commcare.google.services.analytics.FirebaseAnalyticsUtil
import org.commcare.personalId.PersonalIdFeatureFlagChecker
import org.commcare.personalId.PersonalIdFeatureFlagChecker.Companion.isFeatureEnabled
import org.commcare.personalId.PersonalIdFeatureFlagChecker.FeatureFlag.Companion.NOTIFICATIONS
import org.commcare.personalId.PersonalIdFeatureFlagChecker.FeatureFlag.Companion.WORK_HISTORY
import org.commcare.utils.MultipleAppsUtil
import org.commcare.views.ViewUtil
Expand Down Expand Up @@ -130,13 +131,8 @@ class BaseDrawerController(
fun refreshDrawerContent() {
if (PersonalIdManager.getInstance().isloggedIn()) {
setSignedInState(true)
val notifications = NotificationRecordDatabaseHelper().getAllNotifications(activity)
val hasUnreadNotification = notifications!!.any { !it.readStatus }
updateNotificationsIcon()

binding.ivNotification.setImageResource(
if (hasUnreadNotification) R.drawable.ic_new_notification_bell
else R.drawable.ic_bell
)
val user = ConnectUserDatabaseUtil.getUser(activity)
binding.userName.text = user.name
Glide.with(binding.imageUserProfile)
Expand Down Expand Up @@ -224,16 +220,32 @@ class BaseDrawerController(
}
}

private fun updateNotificationsIcon() {
if(shouldShowNotiifcations()) {
val notifications = NotificationRecordDatabaseHelper().getAllNotifications(activity)
val hasUnreadNotification = notifications!!.any { !it.readStatus }

binding.ivNotification.setImageResource(
if (hasUnreadNotification) R.drawable.ic_new_notification_bell
else R.drawable.ic_bell
)
}
}

private fun setSignedInState(isSignedIn: Boolean) {
binding.signoutView.visibility = if (isSignedIn) View.GONE else View.VISIBLE
binding.navDrawerRecycler.visibility = if (isSignedIn) View.VISIBLE else View.GONE
binding.profileCard.visibility = if (isSignedIn) View.VISIBLE else View.GONE
binding.notificationView.visibility = if (isSignedIn) View.VISIBLE else View.GONE
binding.notificationView.visibility = if (shouldShowNotiifcations()) View.VISIBLE else View.GONE
}

private fun shouldShowCredential(): Boolean {
// we are keeping this off for now until we have go ahead to release this feature
return PersonalIdManager.getInstance().isloggedIn() && PersonalIdFeatureFlagChecker.isFeatureEnabled(WORK_HISTORY);
return PersonalIdManager.getInstance().isloggedIn() && isFeatureEnabled(WORK_HISTORY);
}

private fun shouldShowNotiifcations(): Boolean {
return PersonalIdManager.getInstance().isloggedIn() && isFeatureEnabled(NOTIFICATIONS);
}

fun closeDrawer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PersonalIdFeatureFlagChecker {
annotation class FeatureFlag {
companion object {
const val WORK_HISTORY = "work_history"
const val NOTIFICATIONS = "notifications"
}
}

Expand All @@ -21,6 +22,7 @@ class PersonalIdFeatureFlagChecker {
fun isFeatureEnabled(@FeatureFlag feature: String): Boolean {
return when(feature) {
FeatureFlag.WORK_HISTORY -> false
FeatureFlag.NOTIFICATIONS -> false
else -> throw IllegalStateException("Unknown feature flag: $feature")
}
}
Expand Down