mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 06:15:12 +00:00
Set minSdkVersion to 24 + remove checks
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
fb0a6aa4ce
commit
73d3ecac0e
@ -42,7 +42,7 @@ android {
|
||||
namespace 'com.nextcloud.talk'
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 23
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 31
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
hoursInt > 0 -> {
|
||||
fmt.format(
|
||||
hoursInt.toDouble(),
|
||||
Direction.NEXT,
|
||||
RelativeUnit.HOURS
|
||||
)
|
||||
}
|
||||
|
||||
minutesInt > 1 -> {
|
||||
fmt.format(
|
||||
minutesInt.toDouble(),
|
||||
Direction.NEXT,
|
||||
RelativeUnit.MINUTES
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
resources.getString(R.string.nc_lobby_start_soon)
|
||||
}
|
||||
return when {
|
||||
daysInt > 0 -> {
|
||||
fmt.format(
|
||||
daysInt.toDouble(),
|
||||
Direction.NEXT,
|
||||
RelativeUnit.DAYS
|
||||
)
|
||||
}
|
||||
|
||||
hoursInt > 0 -> {
|
||||
fmt.format(
|
||||
hoursInt.toDouble(),
|
||||
Direction.NEXT,
|
||||
RelativeUnit.HOURS
|
||||
)
|
||||
}
|
||||
|
||||
minutesInt > 1 -> {
|
||||
fmt.format(
|
||||
minutesInt.toDouble(),
|
||||
Direction.NEXT,
|
||||
RelativeUnit.MINUTES
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
resources.getString(R.string.nc_lobby_start_soon)
|
||||
}
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user