From f7517a2272d77fd6b431bc8442c0b82979557b95 Mon Sep 17 00:00:00 2001 From: MohitMali Date: Thu, 27 Jul 2023 18:00:11 +0530 Subject: [PATCH] Minimum SDK version changed to 24: The NDK version in kiwix-build has been upgraded (as mentioned in https://github.com/kiwix/kiwix-build/issues/544). However, to make this upgrade compatible, the minimum SDK version had to be updated to 24 since the NDK version is not compatible with Android API levels below 24. The README.md file has been updated to reflect the new minimum Android support version, which is now Android 7, due to the change in the minimum SDK version. Since the project's minimum SDK version is now 24, some conditions related to Android 23 and 24 have become unused. These unused conditions have been removed, and along with that, the drawable-night-23 and drawable-23 launch_screen.xml files, which were no longer in use, have also been removed. --- README.md | 2 +- app/src/main/AndroidManifest.xml | 3 +- .../HotspotNotificationManager.kt | 16 ++++------ .../webserver/wifi_hotspot/HotspotService.kt | 7 ++-- .../kiwixmobile/zimManager/Fat32Checker.kt | 23 ++++--------- buildSrc/src/main/kotlin/Config.kt | 2 +- .../kiwixmobile/core/main/AddNoteDialog.kt | 17 ++++------ .../core/main/CoreWebViewClient.kt | 14 +++----- .../read_aloud/ReadAloudNotificationManger.kt | 32 +++++++------------ .../core/read_aloud/ReadAloudService.kt | 6 ++-- custom/src/main/AndroidManifest.xml | 3 +- .../custom/main/CustomReaderFragment.kt | 3 -- .../res/drawable-night-v23/launch_screen.xml | 30 ----------------- .../main/res/drawable-v23/launch_screen.xml | 30 ----------------- 14 files changed, 44 insertions(+), 144 deletions(-) delete mode 100644 custom/src/main/res/drawable-night-v23/launch_screen.xml delete mode 100644 custom/src/main/res/drawable-v23/launch_screen.xml diff --git a/README.md b/README.md index 0cf852f4b..624ee8d11 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ is to make Wikipedia available offline. This is done by reading the content of a file in the ZIM format, a highly compressed open format with additional metadata. -This is the version for Android, with support versions ranging from 5 +This is the version for Android, with support versions ranging from 7 to 13 (like [mentioned here](https://github.com/kiwix/kiwix-android/blob/develop/buildSrc/src/main/kotlin/Config.kt)). diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ab9a11946..29bf808f9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,8 +27,7 @@ android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" - android:supportsRtl="true" - tools:targetApi="m"> + android:supportsRtl="true"> = Build.VERSION_CODES.M) { - PendingIntent.getService( - context, - 0, - stopIntent, - PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT - ) - } else { - PendingIntent.getService(context, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT) - } + val stopHotspot = PendingIntent.getService( + context, + 0, + stopIntent, + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + ) return NotificationCompat.Builder(context, HOTSPOT_SERVICE_CHANNEL_ID) .setContentTitle(context.getString(R.string.hotspot_notification_content_title)) .setContentText(context.getString(R.string.hotspot_running)) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt index 50daf9961..ab5fc197d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotService.kt @@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.webserver.wifi_hotspot import android.app.Service import android.content.Intent import android.os.Binder -import android.os.Build import android.os.IBinder import android.widget.Toast import org.kiwix.kiwixmobile.KiwixApp @@ -84,6 +83,7 @@ class HotspotService : onServerFailedToStart() } } ?: kotlin.run(::onServerFailedToStart) + ACTION_STOP_SERVER -> { Toast.makeText( this, R.string.server_stopped_successfully_toast_message, @@ -91,6 +91,7 @@ class HotspotService : ).show() stopHotspotAndDismissNotification() } + ACTION_CHECK_IP_ADDRESS -> webServerHelper?.pollForValidIpAddress() else -> {} } @@ -103,9 +104,7 @@ class HotspotService : private fun stopHotspotAndDismissNotification() { webServerHelper?.stopAndroidWebServer() zimHostCallbacks?.onServerStopped() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - stopForeground(STOP_FOREGROUND_REMOVE) - } + stopForeground(STOP_FOREGROUND_REMOVE) stopSelf() hotspotStateReceiver = null hotspotNotificationManager?.dismissNotification() diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt index 3dab2b4b2..db2e66e14 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/Fat32Checker.kt @@ -18,7 +18,6 @@ package org.kiwix.kiwixmobile.zimManager import android.annotation.SuppressLint -import android.os.Build import android.os.FileObserver import io.reactivex.Flowable import io.reactivex.functions.BiFunction @@ -63,22 +62,12 @@ class Fat32Checker constructor( ) } - @Suppress("DEPRECATION") - private fun fileObserver(it: String): FileObserver { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return object : FileObserver(File(it), MOVED_FROM or DELETE) { - override fun onEvent(event: Int, path: String?) { - requestCheckSystemFileType.onNext(Unit) - } - }.apply { startWatching() } - } else { - object : FileObserver(it, FileObserver.MOVED_FROM or FileObserver.DELETE) { - override fun onEvent(event: Int, path: String?) { - requestCheckSystemFileType.onNext(Unit) - } - }.apply { startWatching() } - } - } + private fun fileObserver(it: String): FileObserver = + object : FileObserver(File(it), MOVED_FROM or DELETE) { + override fun onEvent(event: Int, path: String?) { + requestCheckSystemFileType.onNext(Unit) + } + }.apply { startWatching() } private fun toFileSystemState(it: String) = when { diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index 143f6f8f6..e2c30e426 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -23,7 +23,7 @@ object Config { // Here is a list of all Android versions with their corresponding API // levels: https://apilevels.com/ const val compileSdk = 33 // SDK version used by Gradle to compile our app. - const val minSdk = 21 // Minimum SDK (Minimum Support Device) is 21 (Android 5.0 Lollipop). + const val minSdk = 24 // Minimum SDK (Minimum Support Device) is 24 (Android 7.0 Nougat). const val targetSdk = 33 // Target SDK (Maximum Support Device) is 33 (Android 13). val javaVersion = JavaVersion.VERSION_1_8 diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt index 3c8b6bb81..e280061a1 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt @@ -22,7 +22,6 @@ import android.app.Dialog import android.content.Context import android.content.Intent import android.content.pm.PackageManager -import android.net.Uri import android.os.Build import android.os.Bundle import android.text.Editable @@ -446,16 +445,12 @@ class AddNoteDialog : DialogFragment() { } val noteFile = File("$zimNotesDirectory$articleNoteFileName.txt") if (noteFile.exists()) { - val noteFileUri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - // From Nougat 7 (API 24) access to files is shared temporarily with other apps - // Need to use FileProvider for the same - FileProvider.getUriForFile( - requireContext(), requireContext().packageName + ".fileprovider", - noteFile - ) - } else { - Uri.fromFile(noteFile) - } + // From Nougat 7 (API 24) access to files is shared temporarily with other apps + // Need to use FileProvider for the same + val noteFileUri = FileProvider.getUriForFile( + requireContext(), requireContext().packageName + ".fileprovider", + noteFile + ) val noteFileShareIntent = Intent(Intent.ACTION_SEND).apply { type = "application/octet-stream" putExtra(Intent.EXTRA_STREAM, noteFileUri) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt index 34ccfb225..a58235bb9 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreWebViewClient.kt @@ -20,7 +20,6 @@ package org.kiwix.kiwixmobile.core.main import android.content.Context import android.content.Intent import android.net.Uri -import android.os.Build import android.util.Log import android.webkit.MimeTypeMap import android.webkit.WebResourceError @@ -94,17 +93,14 @@ open class CoreWebViewClient( )?.let { if (it.exists()) { val context: Context = instance - val uri = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - FileProvider.getUriForFile( - context, - context.packageName + ".fileprovider", it - ) else Uri.fromFile(it) + val uri = FileProvider.getUriForFile( + context, + context.packageName + ".fileprovider", it + ) val intent = Intent(Intent.ACTION_VIEW).apply { setDataAndType(uri, DOCUMENT_TYPES[extension]) flags = Intent.FLAG_ACTIVITY_NO_HISTORY - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - } + addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } callback.openExternalUrl(intent) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudNotificationManger.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudNotificationManger.kt index e34289642..9c5c58518 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudNotificationManger.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudNotificationManger.kt @@ -57,29 +57,21 @@ class ReadAloudNotificationManger @Inject constructor( val stopIntent = Intent(context, ReadAloudService::class.java).setAction( ReadAloudService.ACTION_STOP_TTS ) - val stopReadAloud = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PendingIntent.getService( - context, - 0, - stopIntent, - PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT - ) - } else { - PendingIntent.getService(context, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT) - } + val stopReadAloud = PendingIntent.getService( + context, + 0, + stopIntent, + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + ) val pauseOrResumeIntent = Intent(context, ReadAloudService::class.java).setAction( ReadAloudService.ACTION_PAUSE_OR_RESUME_TTS ).putExtra(IS_TTS_PAUSE_OR_RESUME, !isPauseTTS) - val pauseOrResumeReadAloud = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PendingIntent.getService( - context, - 0, - pauseOrResumeIntent, - PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT - ) - } else { - PendingIntent.getService(context, 0, pauseOrResumeIntent, PendingIntent.FLAG_UPDATE_CURRENT) - } + val pauseOrResumeReadAloud = PendingIntent.getService( + context, + 0, + pauseOrResumeIntent, + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + ) return NotificationCompat.Builder(context, READ_ALOUD_SERVICE_CHANNEL_ID) .setContentTitle(context.getString(R.string.menu_read_aloud)) .setContentText(context.getString(R.string.read_aloud_running)) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudService.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudService.kt index 735c2a279..55a8e2614 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudService.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/read_aloud/ReadAloudService.kt @@ -21,7 +21,6 @@ package org.kiwix.kiwixmobile.core.read_aloud import android.app.Service import android.content.Intent import android.os.Binder -import android.os.Build import android.os.IBinder import org.kiwix.kiwixmobile.core.CoreApp import java.lang.ref.WeakReference @@ -49,6 +48,7 @@ class ReadAloudService : Service() { startForegroundNotificationHelper(isPauseTTS) readAloudCallbacks?.onReadAloudPauseOrResume(isPauseTTS) } + ACTION_STOP_TTS -> { stopReadAloudAndDismissNotification() } @@ -58,9 +58,7 @@ class ReadAloudService : Service() { private fun stopReadAloudAndDismissNotification() { readAloudCallbacks?.onReadAloudStop() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - stopForeground(STOP_FOREGROUND_REMOVE) - } + stopForeground(STOP_FOREGROUND_REMOVE) stopSelf() readAloudNotificationManager?.dismissNotification() } diff --git a/custom/src/main/AndroidManifest.xml b/custom/src/main/AndroidManifest.xml index 4d2cb5a53..4d24c4b47 100644 --- a/custom/src/main/AndroidManifest.xml +++ b/custom/src/main/AndroidManifest.xml @@ -8,8 +8,7 @@ android:name=".CustomApp" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" - android:supportsRtl="true" - tools:targetApi="m"> + android:supportsRtl="true"> - - - - - - diff --git a/custom/src/main/res/drawable-v23/launch_screen.xml b/custom/src/main/res/drawable-v23/launch_screen.xml deleted file mode 100644 index e34f35c7e..000000000 --- a/custom/src/main/res/drawable-v23/launch_screen.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - -