From 32a6d3465b19e90898e59cd21fa29f12941341d7 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Tue, 5 Mar 2024 14:45:28 +0100 Subject: [PATCH] feat: Include "Notifications" in the left-side navigation menu (#504) Previously the only way to access notifications was to dedicate a tab to them. Now notifications are available from the left-side navigation menu so they're always accessible. Add them to the top of the list, and swap the order of bookmarks and favourites, assuming that users are more likely to want to see their bookmarks than their favourites. Move "Edit profile" to the bottom with the other settings options, assuming that editing their profile does not happen very often, so should not be at the top of the list. --- app/src/main/AndroidManifest.xml | 1 + app/src/main/java/app/pachli/MainActivity.kt | 32 +++++--- .../notifications/NotificationsActivity.kt | 78 +++++++++++++++++++ .../res/layout/activity_notifications.xml | 48 ++++++++++++ .../app/pachli/core/navigation/Navigation.kt | 6 ++ 5 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/app/pachli/components/notifications/NotificationsActivity.kt create mode 100644 app/src/main/res/layout/activity_notifications.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fa344b86b..d2add7046 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -122,6 +122,7 @@ + diff --git a/app/src/main/java/app/pachli/MainActivity.kt b/app/src/main/java/app/pachli/MainActivity.kt index b8bbd0301..13a5d9369 100644 --- a/app/src/main/java/app/pachli/MainActivity.kt +++ b/app/src/main/java/app/pachli/MainActivity.kt @@ -89,6 +89,7 @@ import app.pachli.core.navigation.ListActivityIntent import app.pachli.core.navigation.LoginActivityIntent import app.pachli.core.navigation.LoginActivityIntent.LoginMode import app.pachli.core.navigation.MainActivityIntent +import app.pachli.core.navigation.NotificationsActivityIntent import app.pachli.core.navigation.PreferencesActivityIntent import app.pachli.core.navigation.PreferencesActivityIntent.PreferenceScreen import app.pachli.core.navigation.ScheduledStatusActivityIntent @@ -575,10 +576,19 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider { tintStatusBar = true addItems( primaryDrawerItem { - nameRes = R.string.action_edit_profile - iconicsIcon = GoogleMaterial.Icon.gmd_person + nameRes = R.string.title_notifications + iconicsIcon = GoogleMaterial.Icon.gmd_notifications onClick = { - val intent = EditProfileActivityIntent(context) + startActivityWithSlideInAnimation( + NotificationsActivityIntent(context), + ) + } + }, + primaryDrawerItem { + nameRes = R.string.action_view_bookmarks + iconicsIcon = GoogleMaterial.Icon.gmd_bookmark + onClick = { + val intent = StatusListActivityIntent.bookmarks(context) startActivityWithSlideInAnimation(intent) } }, @@ -591,14 +601,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider { startActivityWithSlideInAnimation(intent) } }, - primaryDrawerItem { - nameRes = R.string.action_view_bookmarks - iconicsIcon = GoogleMaterial.Icon.gmd_bookmark - onClick = { - val intent = StatusListActivityIntent.bookmarks(context) - startActivityWithSlideInAnimation(intent) - } - }, primaryDrawerItem { nameRes = R.string.action_view_follow_requests iconicsIcon = GoogleMaterial.Icon.gmd_person_add @@ -658,6 +660,14 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider { startActivityWithSlideInAnimation(intent) } }, + primaryDrawerItem { + nameRes = R.string.action_edit_profile + iconicsIcon = GoogleMaterial.Icon.gmd_person + onClick = { + val intent = EditProfileActivityIntent(context) + startActivityWithSlideInAnimation(intent) + } + }, secondaryDrawerItem { nameRes = app.pachli.feature.about.R.string.about_title_activity iconicsIcon = GoogleMaterial.Icon.gmd_info diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationsActivity.kt b/app/src/main/java/app/pachli/components/notifications/NotificationsActivity.kt new file mode 100644 index 000000000..e054a4153 --- /dev/null +++ b/app/src/main/java/app/pachli/components/notifications/NotificationsActivity.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2024 Pachli Association + * + * This file is a part of Pachli. + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Pachli is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Pachli; if not, + * see . + */ + +package app.pachli.components.notifications + +import android.os.Bundle +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem +import androidx.core.view.MenuProvider +import androidx.fragment.app.commit +import app.pachli.R +import app.pachli.core.activity.BottomSheetActivity +import app.pachli.core.common.extensions.viewBinding +import app.pachli.core.navigation.ComposeActivityIntent +import app.pachli.databinding.ActivityNotificationsBinding +import app.pachli.interfaces.ActionButtonActivity +import app.pachli.interfaces.AppBarLayoutHost +import app.pachli.util.unsafeLazy +import com.google.android.material.appbar.AppBarLayout + +class NotificationsActivity : BottomSheetActivity(), ActionButtonActivity, AppBarLayoutHost, MenuProvider { + private val binding by viewBinding(ActivityNotificationsBinding::inflate) + + override val actionButton by unsafeLazy { binding.composeButton } + + override val appBarLayout: AppBarLayout + get() = binding.includedToolbar.appbar + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(binding.root) + + setSupportActionBar(binding.includedToolbar.toolbar) + + supportActionBar?.run { + setTitle(R.string.title_notifications) + setDisplayHomeAsUpEnabled(true) + setDisplayShowHomeEnabled(true) + } + + if (supportFragmentManager.findFragmentById(R.id.fragmentContainer) == null) { + supportFragmentManager.commit { + val fragment = NotificationsFragment.newInstance() + replace(R.id.fragmentContainer, fragment) + } + } + + binding.composeButton.setOnClickListener { + val composeIntent = ComposeActivityIntent(applicationContext) + startActivity(composeIntent) + } + } + + override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { + super.onCreateMenu(menu, menuInflater) + menuInflater.inflate(R.menu.activity_trending, menu) + } + + override fun onMenuItemSelected(menuItem: MenuItem): Boolean { + super.onMenuItemSelected(menuItem) + return super.onOptionsItemSelected(menuItem) + } +} diff --git a/app/src/main/res/layout/activity_notifications.xml b/app/src/main/res/layout/activity_notifications.xml new file mode 100644 index 000000000..66589c32a --- /dev/null +++ b/app/src/main/res/layout/activity_notifications.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + diff --git a/core/navigation/src/main/kotlin/app/pachli/core/navigation/Navigation.kt b/core/navigation/src/main/kotlin/app/pachli/core/navigation/Navigation.kt index 6d3cbca6d..a07ba63dd 100644 --- a/core/navigation/src/main/kotlin/app/pachli/core/navigation/Navigation.kt +++ b/core/navigation/src/main/kotlin/app/pachli/core/navigation/Navigation.kt @@ -562,6 +562,12 @@ class LoginWebViewActivityIntent(context: Context) : Intent() { } } +class NotificationsActivityIntent(context: Context) : Intent() { + init { + setClassName(context, QuadrantConstants.NOTIFICATIONS_ACTIVITY) + } +} + class ScheduledStatusActivityIntent(context: Context) : Intent() { init { setClassName(context, QuadrantConstants.SCHEDULED_STATUS_ACTIVITY)