Pārlūkot izejas kodu

Merge pull request #2887 from nextcloud/2886/setMinSdkVersion24

Set minSdkVersion to 24 + remove checks
Marcel Hibbe 2 gadi atpakaļ
vecāks
revīzija
e79cc8cee2

+ 1 - 1
app/build.gradle

@@ -42,7 +42,7 @@ android {
     namespace 'com.nextcloud.talk'
 
     defaultConfig {
-        minSdkVersion 23
+        minSdkVersion 24
         targetSdkVersion 31
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 

+ 2 - 14
app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt

@@ -41,7 +41,6 @@ import android.text.TextUtils
 import android.util.Base64
 import android.util.Log
 import android.widget.Toast
-import androidx.annotation.RequiresApi
 import androidx.core.app.NotificationCompat
 import androidx.core.app.NotificationManagerCompat
 import androidx.core.app.Person
@@ -483,19 +482,13 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
         val systemNotificationId: Int =
             activeStatusBarNotification?.id ?: calculateCRC32(System.currentTimeMillis().toString()).toInt()
 
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
-            TYPE_CHAT == pushMessage.type &&
-            pushMessage.notificationUser != null
-        ) {
+        if (TYPE_CHAT == pushMessage.type && pushMessage.notificationUser != null) {
             prepareChatNotification(notificationBuilder, activeStatusBarNotification, systemNotificationId)
             addReplyAction(notificationBuilder, systemNotificationId)
             addMarkAsReadAction(notificationBuilder, systemNotificationId)
         }
 
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N &&
-            TYPE_RECORDING == pushMessage.type &&
-            ncNotification != null
-        ) {
+        if (TYPE_RECORDING == pushMessage.type && ncNotification != null) {
             addDismissRecordingAvailableAction(notificationBuilder, systemNotificationId, ncNotification)
             addShareRecordingToChatAction(notificationBuilder, systemNotificationId, ncNotification)
         }
@@ -536,7 +529,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
         return crc32.value
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     private fun prepareChatNotification(
         notificationBuilder: NotificationCompat.Builder,
         activeStatusBarNotification: StatusBarNotification?,
@@ -616,7 +608,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
         }
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     private fun addReplyAction(notificationBuilder: NotificationCompat.Builder, systemNotificationId: Int) {
         val replyLabel = context!!.resources.getString(R.string.nc_reply)
         val remoteInput = RemoteInput.Builder(NotificationUtils.KEY_DIRECT_REPLY)
@@ -637,7 +628,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
         notificationBuilder.addAction(replyAction)
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     private fun addDismissRecordingAvailableAction(
         notificationBuilder: NotificationCompat.Builder,
         systemNotificationId: Int,
@@ -671,7 +661,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
         notificationBuilder.addAction(dismissAction)
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     private fun addShareRecordingToChatAction(
         notificationBuilder: NotificationCompat.Builder,
         systemNotificationId: Int,
@@ -716,7 +705,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
         notificationBuilder.addAction(shareRecordingAction)
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     private fun getStyle(person: Person, style: NotificationCompat.MessagingStyle?): NotificationCompat.MessagingStyle {
         val newStyle = NotificationCompat.MessagingStyle(person)
         newStyle.conversationTitle = pushMessage.subject

+ 0 - 8
app/src/main/java/com/nextcloud/talk/receivers/DirectReplyReceiver.kt

@@ -25,11 +25,9 @@ import android.app.NotificationManager
 import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
-import android.os.Build
 import android.text.SpannableStringBuilder
 import android.text.style.ForegroundColorSpan
 import android.util.Log
-import androidx.annotation.RequiresApi
 import androidx.core.app.NotificationCompat
 import androidx.core.app.NotificationManagerCompat
 import androidx.core.app.Person
@@ -104,12 +102,10 @@ class DirectReplyReceiver : BroadcastReceiver() {
                     // unused atm
                 }
 
-                @RequiresApi(Build.VERSION_CODES.N)
                 override fun onNext(genericOverall: GenericOverall) {
                     confirmReplySent()
                 }
 
-                @RequiresApi(Build.VERSION_CODES.N)
                 override fun onError(e: Throwable) {
                     Log.e(TAG, "Failed to send reply", e)
                     informReplyFailed()
@@ -121,12 +117,10 @@ class DirectReplyReceiver : BroadcastReceiver() {
             })
     }
 
-    @RequiresApi(Build.VERSION_CODES.N)
     private fun confirmReplySent() {
         appendMessageToNotification(replyMessage!!)
     }
 
-    @RequiresApi(Build.VERSION_CODES.N)
     private fun informReplyFailed() {
         val errorColor = ForegroundColorSpan(context.resources.getColor(R.color.medium_emphasis_text, context.theme))
         val errorMessageHeader = context.resources.getString(R.string.nc_message_failed_to_send)
@@ -134,13 +128,11 @@ class DirectReplyReceiver : BroadcastReceiver() {
         appendMessageToNotification(errorMessage)
     }
 
-    @RequiresApi(Build.VERSION_CODES.N)
     private fun findActiveNotification(notificationId: Int): Notification? {
         val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
         return notificationManager.activeNotifications.find { it.id == notificationId }?.notification
     }
 
-    @RequiresApi(Build.VERSION_CODES.N)
     private fun appendMessageToNotification(reply: CharSequence) {
         // Implementation inspired by the SO question and article below:
         // https://stackoverflow.com/questions/51549456/android-o-notification-for-direct-reply-message

+ 0 - 5
app/src/main/java/com/nextcloud/talk/receivers/MarkAsReadReceiver.kt

@@ -26,9 +26,7 @@ import android.app.NotificationManager
 import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
-import android.os.Build
 import android.util.Log
-import androidx.annotation.RequiresApi
 import autodagger.AutoInjector
 import com.nextcloud.talk.api.NcApi
 import com.nextcloud.talk.application.NextcloudTalkApplication
@@ -97,12 +95,10 @@ class MarkAsReadReceiver : BroadcastReceiver() {
                     // unused atm
                 }
 
-                @RequiresApi(Build.VERSION_CODES.N)
                 override fun onNext(genericOverall: GenericOverall) {
                     cancelNotification(systemNotificationId!!)
                 }
 
-                @RequiresApi(Build.VERSION_CODES.N)
                 override fun onError(e: Throwable) {
                     Log.e(TAG, "Failed to set chat read marker", e)
                 }
@@ -113,7 +109,6 @@ class MarkAsReadReceiver : BroadcastReceiver() {
             })
     }
 
-    @RequiresApi(Build.VERSION_CODES.N)
     private fun cancelNotification(notificationId: Int) {
         val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
         notificationManager.cancel(notificationId)

+ 34 - 49
app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt

@@ -25,7 +25,6 @@ import android.content.res.Resources
 import android.icu.text.RelativeDateTimeFormatter
 import android.icu.text.RelativeDateTimeFormatter.Direction
 import android.icu.text.RelativeDateTimeFormatter.RelativeUnit
-import android.os.Build
 import com.nextcloud.talk.R
 import java.text.DateFormat
 import java.util.Calendar
@@ -40,23 +39,13 @@ class DateUtils(val context: Context) {
     private var format: DateFormat = DateFormat.getDateTimeInstance(
         DateFormat.DEFAULT, // dateStyle
         DateFormat.SHORT, // timeStyle
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            context.resources.configuration.locales[0]
-        } else {
-            @Suppress("DEPRECATION")
-            context.resources.configuration.locale
-        }
+        context.resources.configuration.locales[0]
     )
 
     /* date formatter in local timezone and locale */
     private var formatTime: DateFormat = DateFormat.getTimeInstance(
         DateFormat.SHORT, // timeStyle
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            context.resources.configuration.locales[0]
-        } else {
-            @Suppress("DEPRECATION")
-            context.resources.configuration.locale
-        }
+        context.resources.configuration.locales[0]
     )
 
     init {
@@ -73,48 +62,44 @@ class DateUtils(val context: Context) {
     }
 
     fun relativeStartTimeForLobby(timestampMilliseconds: Long, resources: Resources): String {
-        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            val fmt = RelativeDateTimeFormatter.getInstance()
-            val timeLeftMillis = timestampMilliseconds - System.currentTimeMillis()
-            val minutes = timeLeftMillis.toDouble() / DateConstants.SECOND_DIVIDER / DateConstants.MINUTES_DIVIDER
-            val hours = minutes / DateConstants.HOURS_DIVIDER
-            val days = hours / DateConstants.DAYS_DIVIDER
+        val fmt = RelativeDateTimeFormatter.getInstance()
+        val timeLeftMillis = timestampMilliseconds - System.currentTimeMillis()
+        val minutes = timeLeftMillis.toDouble() / DateConstants.SECOND_DIVIDER / DateConstants.MINUTES_DIVIDER
+        val hours = minutes / DateConstants.HOURS_DIVIDER
+        val days = hours / DateConstants.DAYS_DIVIDER
 
-            val minutesInt = minutes.roundToInt()
-            val hoursInt = hours.roundToInt()
-            val daysInt = days.roundToInt()
+        val minutesInt = minutes.roundToInt()
+        val hoursInt = hours.roundToInt()
+        val daysInt = days.roundToInt()
 
-            when {
-                daysInt > 0 -> {
-                    fmt.format(
-                        daysInt.toDouble(),
-                        Direction.NEXT,
-                        RelativeUnit.DAYS
-                    )
-                }
+        return when {
+            daysInt > 0 -> {
+                fmt.format(
+                    daysInt.toDouble(),
+                    Direction.NEXT,
+                    RelativeUnit.DAYS
+                )
+            }
 
-                hoursInt > 0 -> {
-                    fmt.format(
-                        hoursInt.toDouble(),
-                        Direction.NEXT,
-                        RelativeUnit.HOURS
-                    )
-                }
+            hoursInt > 0 -> {
+                fmt.format(
+                    hoursInt.toDouble(),
+                    Direction.NEXT,
+                    RelativeUnit.HOURS
+                )
+            }
 
-                minutesInt > 1 -> {
-                    fmt.format(
-                        minutesInt.toDouble(),
-                        Direction.NEXT,
-                        RelativeUnit.MINUTES
-                    )
-                }
+            minutesInt > 1 -> {
+                fmt.format(
+                    minutesInt.toDouble(),
+                    Direction.NEXT,
+                    RelativeUnit.MINUTES
+                )
+            }
 
-                else -> {
-                    resources.getString(R.string.nc_lobby_start_soon)
-                }
+            else -> {
+                resources.getString(R.string.nc_lobby_start_soon)
             }
-        } else {
-            ""
         }
     }
 }

+ 7 - 14
app/src/main/java/com/nextcloud/talk/utils/FileViewerUtils.kt

@@ -25,7 +25,6 @@ import android.content.ComponentName
 import android.content.Context
 import android.content.Intent
 import android.net.Uri
-import android.os.Build
 import android.util.Log
 import android.view.View
 import android.widget.ImageView
@@ -184,19 +183,13 @@ class FileViewerUtils(private val context: Context, private val user: User) {
     private fun openFileByExternalApp(fileName: String, mimetype: String) {
         val path = context.cacheDir.absolutePath + "/" + fileName
         val file = File(path)
-        val intent: Intent
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
-            intent = Intent(Intent.ACTION_VIEW)
-            intent.setDataAndType(Uri.fromFile(file), mimetype)
-            intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
-        } else {
-            intent = Intent()
-            intent.action = Intent.ACTION_VIEW
-            val pdfURI = FileProvider.getUriForFile(context, context.packageName, file)
-            intent.setDataAndType(pdfURI, mimetype)
-            intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
-            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
-        }
+        val intent = Intent()
+        intent.action = Intent.ACTION_VIEW
+        val pdfURI = FileProvider.getUriForFile(context, context.packageName, file)
+        intent.setDataAndType(pdfURI, mimetype)
+        intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
+        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+
         try {
             if (intent.resolveActivity(context.packageManager) != null) {
                 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

+ 1 - 6
app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.kt

@@ -55,12 +55,7 @@ object LoggingUtils {
         // emailIntent.type = TEXT_PLAIN
         // emailIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
         // val uri: Uri
-        //
-        // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
-        //     uri = Uri.fromFile(logFile)
-        // } else {
-        //     uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, logFile)
-        // }
+        // uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, logFile)
         //
         // emailIntent.putExtra(Intent.EXTRA_STREAM, uri)
         // emailIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

+ 8 - 19
app/src/main/java/com/nextcloud/talk/utils/power/PowerManagerUtils.java

@@ -27,14 +27,15 @@ import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.net.wifi.WifiManager;
-import android.os.Build;
 import android.os.PowerManager;
 import android.provider.Settings;
-import autodagger.AutoInjector;
+
 import com.nextcloud.talk.application.NextcloudTalkApplication;
 
 import javax.inject.Inject;
 
+import autodagger.AutoInjector;
+
 @AutoInjector(NextcloudTalkApplication.class)
 
 public class PowerManagerUtils {
@@ -56,9 +57,7 @@ public class PowerManagerUtils {
         PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
         fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "nctalk:fullwakelock");
         partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "nctalk:partialwakelock");
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-            proximityLock = new ProximityLock(pm);
-        }
+        proximityLock = new ProximityLock(pm);
 
         // we suppress a possible leak because this is indeed application context
         @SuppressLint("WifiManagerPotentialLeak") WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
@@ -127,10 +126,7 @@ public class PowerManagerUtils {
                 if (!wifiLock.isHeld()) {
                     wifiLock.acquire();
                 }
-
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-                    proximityLock.release();
-                }
+                proximityLock.release();
                 break;
             case PARTIAL:
                 if (!partialLock.isHeld()) {
@@ -142,18 +138,13 @@ public class PowerManagerUtils {
                 }
 
                 fullLock.release();
-
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-                    proximityLock.release();
-                }
+                proximityLock.release();
                 break;
             case SLEEP:
                 fullLock.release();
                 partialLock.release();
                 wifiLock.release();
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-                    proximityLock.release();
-                }
+                proximityLock.release();
                 break;
             case PROXIMITY:
                 if (!partialLock.isHeld()) {
@@ -167,9 +158,7 @@ public class PowerManagerUtils {
                 fullLock.release(
 
                 );
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-                    proximityLock.acquire();
-                }
+                proximityLock.acquire();
                 break;
             default:
                 // something went very very wrong

+ 0 - 6
app/src/main/java/com/nextcloud/talk/utils/power/ProximityLock.java

@@ -21,21 +21,17 @@
 package com.nextcloud.talk.utils.power;
 
 import android.annotation.SuppressLint;
-import android.os.Build;
 import android.os.PowerManager;
-import androidx.annotation.RequiresApi;
 
 import java.util.Optional;
 
 class ProximityLock {
     private final Optional<PowerManager.WakeLock> proximityLock;
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     ProximityLock(PowerManager pm) {
         proximityLock = getProximityLock(pm);
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     private Optional<PowerManager.WakeLock> getProximityLock(PowerManager powerManager) {
         if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
             return Optional.ofNullable(powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "nctalk:proximitylock"));
@@ -45,7 +41,6 @@ class ProximityLock {
     }
 
     @SuppressLint("WakelockTimeout")
-    @RequiresApi(api = Build.VERSION_CODES.N)
     void acquire() {
         if (!proximityLock.isPresent() || proximityLock.get().isHeld()) {
             return;
@@ -54,7 +49,6 @@ class ProximityLock {
         proximityLock.get().acquire();
     }
 
-    @RequiresApi(api = Build.VERSION_CODES.N)
     void release() {
         if (!proximityLock.isPresent() || !proximityLock.get().isHeld()) {
             return;

+ 0 - 0
app/src/main/res/drawable-v24/ic_avatar_background.xml → app/src/main/res/drawable/ic_avatar_background.xml


+ 0 - 0
app/src/main/res/drawable-v24/ic_launcher_background.xml → app/src/main/res/drawable/ic_launcher_background.xml


+ 0 - 26
app/src/qa/res/drawable-v24/ic_launcher_background.xml

@@ -1,26 +0,0 @@
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:aapt="http://schemas.android.com/aapt"
-    android:width="108dp"
-    android:height="108dp"
-    android:viewportWidth="108"
-    android:viewportHeight="108">
-  <group android:scaleX="0.08035714"
-      android:scaleY="0.08035714">
-    <path
-        android:pathData="M0,0h1344v1344h-1344z"
-        android:strokeLineJoin="round"
-        android:fillType="evenOdd">
-      <aapt:attr name="android:fillColor">
-        <gradient 
-            android:startY="1344.0002"
-            android:startX="163.34073"
-            android:endY="1.2959057E-4"
-            android:endX="1343.9999"
-            android:type="linear">
-          <item android:offset="0" android:color="#FF0082C9"/>
-          <item android:offset="1" android:color="#FF1CAFFF"/>
-        </gradient>
-      </aapt:attr>
-    </path>
-  </group>
-</vector>

+ 24 - 35
app/src/qa/res/drawable/ic_launcher_background.xml

@@ -1,37 +1,26 @@
-<!--
-  ~ /*
-  ~  * Nextcloud Talk application
-  ~  *
-  ~  * @author Mario Danic
-  ~  * Copyright (C) 2017-2020 Mario Danic <mario@lovelyhq.com>
-  ~  *
-  ~  * 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.
-  ~  *
-  ~  * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
-  ~  */
-  -->
-
-<vector android:autoMirrored="true" android:height="108dp"
-    android:viewportHeight="1344" android:viewportWidth="1344"
-    android:width="108dp" xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
-    <path android:fillType="evenOdd"
-        android:pathData="M0,0h1344v1344h-1344z" android:strokeLineJoin="round">
-        <aapt:attr name="android:fillColor">
-            <gradient android:endX="1343.9999"
-                android:endY="1.2959057E-4" android:startX="163.34073"
-                android:startY="1344.0002" android:type="linear">
-                <item android:color="#FF0082C9" android:offset="0"/>
-                <item android:color="#FF1CAFFF" android:offset="1"/>
-            </gradient>
-        </aapt:attr>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:aapt="http://schemas.android.com/aapt"
+    android:width="108dp"
+    android:height="108dp"
+    android:viewportWidth="108"
+    android:viewportHeight="108">
+  <group android:scaleX="0.08035714"
+      android:scaleY="0.08035714">
+    <path
+        android:pathData="M0,0h1344v1344h-1344z"
+        android:strokeLineJoin="round"
+        android:fillType="evenOdd">
+      <aapt:attr name="android:fillColor">
+        <gradient 
+            android:startY="1344.0002"
+            android:startX="163.34073"
+            android:endY="1.2959057E-4"
+            android:endX="1343.9999"
+            android:type="linear">
+          <item android:offset="0" android:color="#FF0082C9"/>
+          <item android:offset="1" android:color="#FF1CAFFF"/>
+        </gradient>
+      </aapt:attr>
     </path>
+  </group>
 </vector>