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
4 changes: 4 additions & 0 deletions app/src/org/commcare/connect/PersonalIdManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.commcare.google.services.analytics.FirebaseAnalyticsUtil;
import org.commcare.navdrawer.BaseDrawerActivity;
import org.commcare.pn.workermanager.NotificationsSyncWorkerManager;
import org.commcare.preferences.NotificationPrefs;
import org.commcare.util.LogTypes;
import org.commcare.utils.BiometricsHelper;
import org.commcare.utils.CrashUtil;
Expand Down Expand Up @@ -227,6 +228,9 @@ public void forgetUser(String reason) {

// Cancel periodic push notification retrieval when user logs out
NotificationsSyncWorkerManager.cancelPeriodicPushNotificationRetrieval(CommCareApplication.instance());

// remove notification read / unread preferences
NotificationPrefs.INSTANCE.removeNotificationReadPref(CommCareApplication.instance());
}

public AuthInfo.TokenAuth getConnectToken() {
Expand Down
63 changes: 29 additions & 34 deletions app/src/org/commcare/navdrawer/BaseDrawerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.commcare.utils.FirebaseMessagingUtil
import org.javarosa.core.services.Logger

abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {

private var drawerController: BaseDrawerController? = null

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -31,36 +30,22 @@ abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {
}
}
}

override fun onResume() {
super.onResume()
LocalBroadcastManager.getInstance(this).registerReceiver(
messagingUpdateReceiver,
IntentFilter(FirebaseMessagingUtil.MESSAGING_UPDATE_BROADCAST)
)
}

override fun onPause() {
super.onPause()
LocalBroadcastManager.getInstance(this).unregisterReceiver(messagingUpdateReceiver)
}

fun refreshDrawer() {
drawerController?.refreshDrawerContent()
}

private val messagingUpdateReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
drawerController?.refreshDrawerContent()
}
}
protected open fun shouldShowDrawer(): Boolean = false

protected open fun shouldShowDrawer(): Boolean {
return false
}

protected open fun shouldHighlightSeatedApp(): Boolean {
return false
}
protected open fun shouldHighlightSeatedApp(): Boolean = false

fun checkForDrawerSetUp() {
if (shouldShowDrawer()) {
Expand All @@ -71,23 +56,33 @@ abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {
private fun setupDrawerController() {
val rootView = findViewById<View>(android.R.id.content)
val drawerRefs = DrawerViewRefs(rootView)
drawerController = BaseDrawerController(
this,
drawerRefs,
shouldHighlightSeatedApp()
) { navItemType: NavItemType, recordId: String? ->
handleDrawerItemClick(navItemType, recordId)
}
drawerController =
BaseDrawerController(
this,
drawerRefs,
shouldHighlightSeatedApp(),
) { navItemType: NavItemType, recordId: String? ->
handleDrawerItemClick(navItemType, recordId)
}
drawerController!!.setupDrawer()
}

protected open fun handleDrawerItemClick(itemType: NavItemType, recordId: String?) {
protected open fun handleDrawerItemClick(
itemType: NavItemType,
recordId: String?,
) {
when (itemType) {
NavItemType.OPPORTUNITIES -> { navigateToConnectMenu() }
NavItemType.OPPORTUNITIES -> {
navigateToConnectMenu()
}
NavItemType.COMMCARE_APPS -> { /* No nav, expands/collapses menu */ }
NavItemType.PAYMENTS -> {}
NavItemType.MESSAGING -> { navigateToMessaging() }
NavItemType.WORK_HISTORY -> { navigateToWorkHistory() }
NavItemType.MESSAGING -> {
navigateToMessaging()
}
NavItemType.WORK_HISTORY -> {
navigateToWorkHistory()
}
}
}

Expand All @@ -108,7 +103,7 @@ abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {
closeDrawer()
}
}
}
},
)
}

Expand All @@ -121,7 +116,7 @@ abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {
closeDrawer()
}
}
}
},
)
}

Expand All @@ -134,15 +129,15 @@ abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {
closeDrawer()
}
}
}
},
)
}

protected fun closeDrawer() {
if (drawerController == null) {
Logger.exception(
"There was an error closing the app's sidebar.",
NullPointerException("The BaseDrawerController is null!")
NullPointerException("The BaseDrawerController is null!"),
)
}

Expand All @@ -153,7 +148,7 @@ abstract class BaseDrawerActivity<T> : CommCareActivity<T>() {
if (drawerController == null) {
Logger.exception(
"There was an error opening the app's sidebar.",
NullPointerException("The BaseDrawerController is null!")
NullPointerException("The BaseDrawerController is null!"),
)
}

Expand Down
27 changes: 15 additions & 12 deletions app/src/org/commcare/navdrawer/BaseDrawerController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,22 @@ class BaseDrawerController(
),
)

if (ConnectMessagingDatabaseHelper.getMessagingChannels(activity).isNotEmpty()) {
val unreadCount = ConnectMessagingDatabaseHelper.getUnviewedMessages(activity).size
val messageCount = if (unreadCount > 0) unreadCount else null
val unreadCount =
if (ConnectMessagingDatabaseHelper.getMessagingChannels(activity).isNotEmpty()) {
ConnectMessagingDatabaseHelper.getUnviewedMessages(activity).size
} else {
0
}
val messageCount = if (unreadCount > 0) unreadCount else null

items.add(
NavDrawerItem.ParentItem(
activity.getString(R.string.connect_messaging_title),
R.drawable.nav_drawer_message_icon,
NavItemType.MESSAGING,
badgeCount = messageCount,
),
)
}
items.add(
NavDrawerItem.ParentItem(
activity.getString(R.string.connect_messaging_title),
R.drawable.nav_drawer_message_icon,
NavItemType.MESSAGING,
badgeCount = messageCount,
),
)

if (shouldShowWorkHistory()) {
items.add(
Expand Down
16 changes: 12 additions & 4 deletions app/src/org/commcare/preferences/NotificationPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ object NotificationPrefs {
private const val KEY_NOTIFICATION_READ_STATUS = "notification_read_status"

fun setNotificationAsUnread(context: Context) {
context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
context
.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
.edit { putBoolean(KEY_NOTIFICATION_READ_STATUS, false) }
}

fun setNotificationAsRead(context: Context) {
context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
context
.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
.edit { putBoolean(KEY_NOTIFICATION_READ_STATUS, true) }
}

fun getNotificationReadStatus(context: Context): Boolean {
return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
fun getNotificationReadStatus(context: Context): Boolean =
context
.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
.getBoolean(KEY_NOTIFICATION_READ_STATUS, true)

fun removeNotificationReadPref(context: Context) {
context
.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
.edit { remove(KEY_NOTIFICATION_READ_STATUS) }
}
}