From 99b3d1c40ae657f62fe8a01d0597769dcba5c914 Mon Sep 17 00:00:00 2001 From: Levin Li Date: Sat, 5 Jun 2021 23:06:42 +0800 Subject: [PATCH] Update dependencies --- app/build.gradle | 5 ++-- app/src/main/AndroidManifest.xml | 2 +- .../celestia/mobilecelestia/MainActivity.kt | 29 +++++++------------ .../control/BottomControlFragment.kt | 7 ++--- .../resource/model/ResourceManager.kt | 2 +- 5 files changed, 18 insertions(+), 27 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1273d11a..777d0821 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -74,16 +74,17 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'androidx.core:core-ktx:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation 'androidx.recyclerview:recyclerview:1.2.0' + implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" implementation 'com.google.android.material:material:1.3.0' - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.8.7' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' + implementation "com.squareup.okhttp3:okhttp:4.9.1" implementation 'net.lingala.zip4j:zip4j:2.8.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fd84ed32..4a848ed2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ diff --git a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt index 66dfbceb..f84b10b9 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt @@ -25,7 +25,6 @@ import android.view.* import android.widget.Toast import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.Guideline @@ -33,9 +32,7 @@ import androidx.core.animation.addListener import androidx.core.app.ShareCompat import androidx.core.content.FileProvider import androidx.core.graphics.contains -import androidx.core.view.WindowCompat -import androidx.core.view.WindowInsetsCompat -import androidx.core.view.WindowInsetsControllerCompat +import androidx.core.view.* import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import com.google.gson.Gson @@ -196,15 +193,12 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), reporter.register(this) // Handle notch - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - val rootView = findViewById(android.R.id.content).rootView - rootView.setOnApplyWindowInsetsListener { _, insets -> - insets.displayCutout?.let { - applyCutout(it) - } - return@setOnApplyWindowInsetsListener insets + ViewCompat.setOnApplyWindowInsetsListener( findViewById(android.R.id.content).rootView, { _, insets -> + insets?.displayCutout?.let { + applyDisplayCutout(it) } - } + return@setOnApplyWindowInsetsListener insets + }) findViewById(R.id.overlay_container).setOnTouchListener { _, e -> if (e.actionMasked == MotionEvent.ACTION_UP) { @@ -399,16 +393,13 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), override fun onAttachedToWindow() { super.onAttachedToWindow() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - val rootView = findViewById(android.R.id.content).rootView - rootView.rootWindowInsets.displayCutout?.let { - applyCutout(it) - } + val rootView = findViewById(android.R.id.content).rootView + ViewCompat.getRootWindowInsets(rootView)?.displayCutout?.let { + applyDisplayCutout(it) } } - @RequiresApi(Build.VERSION_CODES.P) - private fun applyCutout(cutout: DisplayCutout) { + private fun applyDisplayCutout(cutout: DisplayCutoutCompat) { val density = resources.displayMetrics.density val ltr = resources.configuration.layoutDirection != View.LAYOUT_DIRECTION_RTL diff --git a/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt b/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt index 8970391c..e12ffd3c 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/control/BottomControlFragment.kt @@ -50,14 +50,14 @@ class CelestiaActionItem(val action: CelestiaAction, val image: Int) class BottomControlFragment : Fragment() { private var listener: Listener? = null - private var items: List? = null + private var items: List = listOf() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) arguments?.let { @Suppress("UNCHECKED_CAST") - items = it.getSerializable(ARG_ACTIONS) as? List + items = it.getSerializable(ARG_ACTIONS) as? List ?: listOf() } } @@ -74,7 +74,7 @@ class BottomControlFragment : Fragment() { manager.orientation = LinearLayoutManager.HORIZONTAL layoutManager = manager adapter = BottomControlRecyclerViewAdapter( - items!!.map { + items.map { CelestiaActionItem( it, it.imageID() ?: 0 @@ -105,7 +105,6 @@ class BottomControlFragment : Fragment() { } companion object { - const val ARG_ACTIONS = "action" @JvmStatic diff --git a/app/src/main/java/space/celestia/mobilecelestia/resource/model/ResourceManager.kt b/app/src/main/java/space/celestia/mobilecelestia/resource/model/ResourceManager.kt index 36190ad9..483ebe4e 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/resource/model/ResourceManager.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/resource/model/ResourceManager.kt @@ -119,7 +119,7 @@ class ResourceManager { val call = client.newCall(Request.Builder().url(item.item).get().build()) try { val response = call.execute() - val body = response.body() + val body = response.body if (!response.isSuccessful || body == null) { return@executeAsyncTask false }