[Android] Code cleanup

Robert Stone git at videolan.org
Tue Jul 12 07:56:38 UTC 2022


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Mon Jul 11 23:59:18 2022 -0700| [46c46eb9a4fc05e18410459e53504e59fc1ab69c] | committer: Robert Stone

Code cleanup

> https://code.videolan.org/videolan/vlc-android/commit/46c46eb9a4fc05e18410459e53504e59fc1ab69c
---

 .../src/main/java/org/videolan/tools/AppUtils.kt   | 42 +++++++++++++++++++---
 .../src/org/videolan/vlc/gui/helpers/BitmapUtil.kt | 10 +++---
 .../src/org/videolan/vlc/gui/helpers/Navigator.kt  | 11 +-----
 3 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/application/tools/src/main/java/org/videolan/tools/AppUtils.kt b/application/tools/src/main/java/org/videolan/tools/AppUtils.kt
index 51e6d7d00..a8098eb47 100644
--- a/application/tools/src/main/java/org/videolan/tools/AppUtils.kt
+++ b/application/tools/src/main/java/org/videolan/tools/AppUtils.kt
@@ -1,3 +1,26 @@
+/*
+ * ************************************************************************
+ *  AppUtils.kt
+ * *************************************************************************
+ * Copyright © 2022 VLC authors and VideoLAN
+ * Author: Nicolas POMEPUY
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * **************************************************************************
+ *
+ *
+ */
 package org.videolan.tools
 
 import android.content.Context
@@ -5,6 +28,7 @@ import android.os.Build
 import android.os.Environment
 import android.os.StatFs
 
+ at Suppress("DEPRECATION")
 object AppUtils {
 
     fun getVersionName(context: Context): String {
@@ -19,18 +43,28 @@ object AppUtils {
 
     fun totalMemory(): Long {
         val statFs = StatFs(Environment.getRootDirectory().absolutePath)
-        return (statFs.blockCount * statFs.blockSize).toLong()
+        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
+            statFs.blockCountLong * statFs.blockSizeLong
+        else (statFs.blockCount * statFs.blockSize).toLong()
     }
 
     fun freeMemory(): Long {
         val statFs = StatFs(Environment.getRootDirectory().absolutePath)
-        return (statFs.availableBlocks * statFs.blockSize).toLong()
+        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
+            statFs.availableBlocksLong * statFs.blockSizeLong
+        else (statFs.availableBlocks * statFs.blockSize).toLong()
     }
 
     fun busyMemory(): Long {
         val statFs = StatFs(Environment.getRootDirectory().absolutePath)
-        val total = (statFs.blockCount * statFs.blockSize).toLong()
-        val free = (statFs.availableBlocks * statFs.blockSize).toLong()
+        val total = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
+            statFs.blockCountLong * statFs.blockSizeLong
+        else (statFs.blockCount * statFs.blockSize).toLong()
+
+        val free = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
+            statFs.availableBlocksLong * statFs.blockSizeLong
+        else (statFs.availableBlocks * statFs.blockSize).toLong()
+
         return total - free
     }
 }
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt
index e9203489a..1cd80f63a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapUtil.kt
@@ -145,13 +145,11 @@ object BitmapUtil {
     }
 
     fun vectorToBitmap(context: Context, @DrawableRes resVector: Int, width: Int? = null, height: Int? = null): Bitmap? {
-        val drawable = AppCompatResources.getDrawable(context, resVector)
-        val b = Bitmap.createBitmap(width ?: drawable!!.intrinsicWidth, height
-                ?: drawable!!.intrinsicHeight,
-                Bitmap.Config.ARGB_8888)
+        val drawable = AppCompatResources.getDrawable(context, resVector) ?: return null
+        val b = Bitmap.createBitmap(width ?: drawable.intrinsicWidth, height ?: drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
         val c = Canvas(b)
-        drawable!!.setBounds(0, 0, c.width, c.height)
-        drawable!!.draw(c)
+        drawable.setBounds(0, 0, c.width, c.height)
+        drawable.draw(c)
         return b
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
index 2ff5d0011..b7d1614bf 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/Navigator.kt
@@ -54,7 +54,7 @@ import org.videolan.vlc.gui.video.VideoGridFragment
 import org.videolan.vlc.util.getScreenWidth
 
 private const val TAG = "Navigator"
-class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, DefaultLifecycleObserver, INavigator {
+class Navigator : NavigationBarView.OnItemSelectedListener, DefaultLifecycleObserver, INavigator {
 
     private val defaultFragmentId= R.id.nav_video
     override var currentFragmentId : Int = 0
@@ -129,15 +129,6 @@ class Navigator : BottomNavigationView.OnNavigationItemSelectedListener, Default
         currentFragmentId = id
     }
 
-    private fun showSecondaryFragment(fragmentTag: String, param: String? = null) {
-        val i = Intent(activity, SecondaryActivity::class.java)
-        i.putExtra("fragment", fragmentTag)
-        param?.let { i.putExtra("param", it) }
-        activity.startActivityForResult(i, SecondaryActivity.ACTIVITY_RESULT_SECONDARY)
-        // Slide down the audio player if needed.
-        activity.slideDownAudioPlayer()
-    }
-
     override fun currentIdIsExtension() = idIsExtension(currentFragmentId)
 
     private fun idIsExtension(id: Int) = id in 1..100



More information about the Android mailing list