This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added notification overview * Added queues to retrive scheduled and active notifications Adjusted NotificationDebugViewFragment to display these * Fixed falsely added whitespace in DrawerMenuHelper.kt * Added logic in InformationActivity.kt for opening the NotificationOverview after 5 quick clicks * Changed to Activity and improved file structure * Added localization to StickyList headers * Added padding to StickyListItem * Added notifications from AlarmManager per NotificationType * Added get PendingIntent for every ScheduledNotification * Only textview txtVersion triggers click now * Removed unnecessary import * fixed a typo in the translations * Fixed ktlint errors * Fixed ktlint errors --------- Co-authored-by: Frank Elsinga <[email protected]>
- Loading branch information
1 parent
1912fc2
commit 4d27542
Showing
11 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../de/tum/in/tumcampusapp/component/notifications/overview/NotificationItemForStickyList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package de.tum.`in`.tumcampusapp.component.notifications.overview | ||
|
||
import de.tum.`in`.tumcampusapp.component.other.generic.adapter.SimpleStickyListHeadersAdapter | ||
|
||
data class NotificationItemForStickyList( | ||
val notificationString: String, | ||
val notificationSource: String | ||
) : SimpleStickyListHeadersAdapter.SimpleStickyListItem { | ||
|
||
override fun getHeadName(): String { | ||
return notificationSource | ||
} | ||
|
||
override fun getHeaderId(): String { | ||
return notificationSource | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...a/de/tum/in/tumcampusapp/component/notifications/overview/NotificationOverviewActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package de.tum.`in`.tumcampusapp.component.notifications.overview | ||
|
||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import de.tum.`in`.tumcampusapp.R | ||
import de.tum.`in`.tumcampusapp.component.notifications.receivers.NotificationAlarmReceiver | ||
import de.tum.`in`.tumcampusapp.component.notifications.receivers.NotificationReceiver | ||
import de.tum.`in`.tumcampusapp.component.other.generic.activity.BaseActivity | ||
import de.tum.`in`.tumcampusapp.database.TcaDb | ||
import de.tum.`in`.tumcampusapp.databinding.ActivityNotificationOverviewBinding | ||
|
||
class NotificationOverviewActivity : BaseActivity(R.layout.activity_notification_overview) { | ||
|
||
private lateinit var binding: ActivityNotificationOverviewBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = ActivityNotificationOverviewBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
setSupportActionBar(binding.toolbarInformation.toolbar) | ||
supportActionBar?.apply { | ||
setDisplayHomeAsUpEnabled(true) | ||
setDisplayShowHomeEnabled(true) | ||
} | ||
|
||
// get currently active notifications | ||
val notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
val activeNotifications = notificationManager.activeNotifications.asList() | ||
// get notifications stored in database | ||
val scheduledNotifications = TcaDb.getInstance(applicationContext).scheduledNotificationsDao().getAllScheduledNotifications() | ||
val alarms = TcaDb.getInstance(applicationContext).activeNotificationsDao().getAllAlarms() | ||
// get PendingIntent for every NotificationType | ||
val typesList = (0..5) | ||
// get PendingIntent for every ScheduledNotification | ||
val scheduledNotificationIds = scheduledNotifications.map { it.typeId } | ||
|
||
// store all notifications into one list | ||
val notificationsList = emptyList<NotificationItemForStickyList>().toMutableList() | ||
activeNotifications.forEach { | ||
notificationsList.add(NotificationItemForStickyList(it.toString(), getString(R.string.active_notifications))) | ||
} | ||
scheduledNotifications.forEach { | ||
notificationsList.add(NotificationItemForStickyList(it.toString(), getString(R.string.scheduled_notifications))) | ||
} | ||
alarms.forEach { | ||
notificationsList.add(NotificationItemForStickyList(it.toString(), getString(R.string.alarms))) | ||
} | ||
typesList.forEach { type -> | ||
getAlarmIntentPerType(type)?.let { | ||
notificationsList.add(NotificationItemForStickyList(it.toString(), getString(R.string.pendingintents_per_type))) | ||
} | ||
} | ||
scheduledNotificationIds.forEach { id -> | ||
getAlarmIntent(id)?.let { | ||
notificationsList.add(NotificationItemForStickyList(it.toString(), getString(R.string.pendingintents_per_scheduled_notification))) | ||
} | ||
} | ||
|
||
binding.notificationsListView.adapter = NotificationsListAdapter(applicationContext, notificationsList) | ||
} | ||
|
||
// mimics NotificationScheduler.getAlarmIntent(type: NotificationType) method | ||
private fun getAlarmIntentPerType(type: Int): PendingIntent? { | ||
// extra data is ignored according to intent filter | ||
val intent = Intent(applicationContext, NotificationAlarmReceiver::class.java) | ||
// FLAG_NO_CREATE to only show existing intents | ||
return PendingIntent.getBroadcast(applicationContext, type, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_NO_CREATE) | ||
} | ||
|
||
// mimics NotificationScheduler.getAlarmIntent(futureNotification: FutureNotification, globalNotificationId: Long) method | ||
private fun getAlarmIntent(id: Int): PendingIntent? { | ||
// extra data is ignored according to intent filter | ||
val intent = Intent(applicationContext, NotificationReceiver::class.java) | ||
// FLAG_NO_CREATE to only show existing intents | ||
return PendingIntent.getBroadcast( | ||
applicationContext, | ||
id, | ||
intent, | ||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_NO_CREATE | ||
) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../java/de/tum/in/tumcampusapp/component/notifications/overview/NotificationsListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package de.tum.`in`.tumcampusapp.component.notifications.overview | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import de.tum.`in`.tumcampusapp.R | ||
import de.tum.`in`.tumcampusapp.component.other.generic.adapter.SimpleStickyListHeadersAdapter | ||
|
||
class NotificationsListAdapter(context: Context, results: MutableList<NotificationItemForStickyList>) : SimpleStickyListHeadersAdapter<NotificationItemForStickyList>(context, results) { | ||
|
||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | ||
val holder: ViewHolder | ||
val view: View | ||
|
||
if (convertView == null) { | ||
view = inflater.inflate(R.layout.notification_row_item, parent, false) | ||
holder = ViewHolder() | ||
holder.textView = view.findViewById(R.id.textView) | ||
view.tag = holder | ||
} else { | ||
view = convertView | ||
holder = view.tag as ViewHolder | ||
} | ||
|
||
val notification = itemList[position] | ||
|
||
holder.textView?.text = notification.notificationString | ||
|
||
return view | ||
} | ||
|
||
// the layout of the list | ||
internal class ViewHolder { | ||
var textView: TextView? = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/res/layout/activity_notification_overview.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/drawer_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<include layout="@layout/toolbar" android:id="@+id/toolbar_information"/> | ||
|
||
<se.emilsjolander.stickylistheaders.StickyListHeadersListView | ||
android:id="@+id/notificationsListView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:importantForAutofill="noExcludeDescendants" | ||
android:scrollbars="vertical" /> | ||
</LinearLayout> | ||
|
||
</androidx.drawerlayout.widget.DrawerLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical" | ||
android:padding="@dimen/material_default_padding"> | ||
|
||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"/> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,16 @@ | |
The TUM Campus App is being developed by volunteers, students of the Android practical course and employees of the Chair of Operating Systems led by Professor Dr. Baumgarten. | ||
The app can be used on smartphones and tablets and is available for both iOS and Android.\n\nYou can reach us via the feedback form in the app or via email ([email protected]) if you have any special concerns or requests. | ||
</string> | ||
<string name="show_notification_view_progress_single">The notification overview opens in one click.</string> | ||
<string name="show_notification_view_progress_multiple">The notification overview opens in %1$d clicks.</string> | ||
|
||
<!-- Notification Overview --> | ||
<string name="notification_overview">Notification Overview</string> | ||
<string name="active_notifications">Active Notifications</string> | ||
<string name="scheduled_notifications">Scheduled Notifications</string> | ||
<string name="alarms">Alarms</string> | ||
<string name="pendingintents_per_type">PendingIntents per NotificationType</string> | ||
<string name="pendingintents_per_scheduled_notification">PendingIntents per ScheduledNotification</string> | ||
|
||
<!-- END Translated, please do not change identifiers --> | ||
<string name="min_search_len" tools:ignore="PluralsCandidate">Query must be at least %d chars long</string> | ||
|