Bläddra i källkod

Remove drawer activity inheritance

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 9 månader sedan
förälder
incheckning
b1734b377f

+ 69 - 56
app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt

@@ -1,6 +1,7 @@
 /*
  * Nextcloud - Android Client
  *
+ * SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
  * SPDX-FileCopyrightText: 2020 Chris Narkiewicz <hello@ezaquarii.com>
  * SPDX-FileCopyrightText: 2017 Mario Danic <mario@lovelyhq.com>
  * SPDX-FileCopyrightText: 2017 Nextcloud GmbH
@@ -8,18 +9,24 @@
  */
 package com.owncloud.android.ui.activity
 
+import android.os.Build
 import android.os.Bundle
 import android.view.Menu
 import android.view.MenuItem
 import android.view.View
+import android.view.WindowInsetsController
 import androidx.annotation.VisibleForTesting
-import androidx.core.content.res.ResourcesCompat
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.ContextCompat
 import androidx.recyclerview.widget.LinearLayoutManager
 import com.google.android.material.snackbar.Snackbar
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
+import com.nextcloud.client.di.Injectable
 import com.nextcloud.client.jobs.NotificationWork
+import com.nextcloud.client.network.ClientFactory
 import com.nextcloud.client.network.ClientFactory.CreationException
+import com.nextcloud.client.preferences.AppPreferences
 import com.nextcloud.common.NextcloudClient
 import com.owncloud.android.R
 import com.owncloud.android.databinding.NotificationsLayoutBinding
@@ -34,12 +41,14 @@ import com.owncloud.android.ui.asynctasks.DeleteAllNotificationsTask
 import com.owncloud.android.ui.notifications.NotificationsContract
 import com.owncloud.android.utils.DisplayUtils
 import com.owncloud.android.utils.PushUtils
+import com.owncloud.android.utils.theme.ViewThemeUtils
 import java.util.Optional
+import javax.inject.Inject
 
 /**
  * Activity displaying all server side stored notification items.
  */
-class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
+class NotificationsActivity : AppCompatActivity(), NotificationsContract.View, Injectable {
 
     lateinit var binding: NotificationsLayoutBinding
 
@@ -48,6 +57,18 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
     private var client: NextcloudClient? = null
     private var optionalUser: Optional<User>? = null
 
+    @Inject
+    lateinit var viewThemeUtils: ViewThemeUtils
+
+    @Inject
+    lateinit var accountManager: UserAccountManager
+
+    @Inject
+    lateinit var clientFactory: ClientFactory
+
+    @Inject
+    lateinit var preferences: AppPreferences
+
     override fun onCreate(savedInstanceState: Bundle?) {
         Log_OC.v(TAG, "onCreate() start")
 
@@ -55,18 +76,9 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
 
         binding = NotificationsLayoutBinding.inflate(layoutInflater)
         setContentView(binding.root)
-
-        optionalUser = user
-
-        intent?.let {
-            it.extras?.let { bundle ->
-                setupUser(bundle)
-            }
-        }
-
-        setupToolbar()
-        setupDrawer()
-        setupBack()
+        setupActionBar()
+        setupStatusBar()
+        initUser()
         setupContainingList()
         setupPushWarning()
         setupContent()
@@ -76,28 +88,43 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
         }
     }
 
-    private fun setupBack() {
-        updateActionBarTitleAndHomeButtonByString("1")
-
-        if (resources == null) return
-        val menuIcon = ResourcesCompat.getDrawable(
-            resources,
-            R.drawable.ic_arrow_back,
-            null
-        )
-
-        if (menuIcon == null) return
+    private fun initUser() {
+        optionalUser = Optional.of(accountManager.user)
+        intent?.let {
+            it.extras?.let { bundle ->
+                setupUser(bundle)
+            }
+        }
+    }
 
-        supportActionBar?.let {
-            it.setDisplayHomeAsUpEnabled(true)
-            it.setDisplayShowTitleEnabled(true)
+    private fun setupActionBar() {
+        setSupportActionBar(findViewById(R.id.toolbar_back_button))
+        supportActionBar?.apply {
+            setTitle(R.string.drawer_item_notifications)
+            setDisplayHomeAsUpEnabled(true)
+            setHomeAsUpIndicator(R.drawable.ic_arrow_back_foreground)
+        }
+    }
 
-            viewThemeUtils.androidx.themeActionBar(
-                this,
-                it,
-                getString(R.string.drawer_item_notifications),
-                menuIcon
+    private fun setupStatusBar() {
+        window.statusBarColor = ContextCompat.getColor(this, R.color.bg_default)
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+            val appearanceLightStatusBars = if (preferences.isDarkModeEnabled) {
+                0
+            } else {
+                WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
+            }
+            window.insetsController?.setSystemBarsAppearance(
+                appearanceLightStatusBars,
+                WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
             )
+        } else {
+            @Suppress("DEPRECATION")
+            window.decorView.systemUiVisibility = if (preferences.isDarkModeEnabled) {
+                0
+            } else {
+                View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+            }
         }
     }
 
@@ -122,8 +149,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
             val user = optionalUser?.get()
             if (user?.accountName.equals(accountName, ignoreCase = true)) {
                 accountManager.setCurrentOwnCloudAccount(accountName)
-                setUser(userAccountManager.user)
-                optionalUser = getUser()
             }
         }
     }
@@ -192,18 +217,6 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
         }
     }
 
-    override fun openDrawer() {
-        super.openDrawer()
-        if (snackbar != null && snackbar?.isShown == true) {
-            snackbar?.dismiss()
-        }
-    }
-
-    override fun closeDrawer() {
-        super.closeDrawer()
-        setupPushWarning()
-    }
-
     /**
      * sets up the UI elements and loads all notification items.
      */
@@ -290,16 +303,16 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
         var retval = true
         val itemId = item.itemId
-        if (itemId == android.R.id.home) {
-            if (isDrawerOpen) {
-                closeDrawer()
-            } else {
-                openDrawer()
+        when (itemId) {
+            android.R.id.home -> {
+                onBackPressedDispatcher.onBackPressed()
+            }
+            R.id.action_empty_notifications -> {
+                DeleteAllNotificationsTask(client, this).execute()
+            }
+            else -> {
+                retval = super.onOptionsItemSelected(item)
             }
-        } else if (itemId == R.id.action_empty_notifications) {
-            DeleteAllNotificationsTask(client, this).execute()
-        } else {
-            retval = super.onOptionsItemSelected(item)
         }
         return retval
     }

+ 13 - 0
app/src/main/res/drawable/ic_arrow_back_foreground.xml

@@ -0,0 +1,13 @@
+<!--
+  ~ Nextcloud - Android Client
+  ~
+  ~ SPDX-FileCopyrightText: 2018-2024 Google LLC
+  ~ SPDX-License-Identifier: Apache-2.0
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="@color/foreground_highlight" android:pathData="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" />
+</vector>

+ 2 - 1
app/src/main/res/layout/notifications_layout.xml

@@ -20,11 +20,12 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
-        <include layout="@layout/toolbar_standard" />
+        <include layout="@layout/toolbar_back_button" />
 
         <FrameLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
+            android:layout_marginTop="@dimen/standard_double_margin"
             android:layout_below="@id/appbar"
             app:layout_behavior="@string/appbar_scrolling_view_behavior">
 

+ 15 - 0
app/src/main/res/layout/toolbar_back_button.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud - Android Client
+  ~
+  ~ SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
+  ~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
+-->
+<androidx.appcompat.widget.Toolbar
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/toolbar_back_button"
+    android:layout_width="match_parent"
+    android:layout_height="?attr/actionBarSize"
+    android:background="@color/bg_default"
+    app:popupTheme="@style/Theme.AppCompat.DayNight.NoActionBar" />