Skip to content

Commit

Permalink
Remove InsetAwareFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Dec 29, 2022
1 parent 987d31b commit 5eae423
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 108 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto"
android:versionCode="308"
android:versionCode="309"
android:versionName="1.5.15">

<uses-feature android:glEsVersion="0x00020000" android:required="true" />
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),
val bottomSheetContainer = findViewById<SheetLayout>(R.id.bottom_sheet_overlay)
bottomSheetContainer.edgeInsets = safeInsets
bottomSheetContainer.postInvalidate()

(supportFragmentManager.findFragmentById(R.id.celestia_fragment_container) as? CelestiaFragment)?.handleInsetsChanged(safeInsets)
}

private fun loadExternalConfig(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -1920,11 +1922,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),

// Utilities
private fun showBottomSheetFragment(fragment: Fragment) {
val ref = WeakReference(fragment)
hideOverlay(true) {
ref.get()?.let {
showBottomSheetFragmentDirect(it)
}
showBottomSheetFragmentDirect(fragment)
}
}

Expand All @@ -1939,11 +1938,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),
}

private fun showToolbarFragment(fragment: Fragment) {
val ref = WeakReference(fragment)
hideOverlay(true) {
ref.get()?.let {
showToolbarFragmentDirect(it)
}
showToolbarFragmentDirect(fragment)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.animation.doOnEnd
import androidx.core.view.MenuCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import space.celestia.celestia.*
import space.celestia.mobilecelestia.MainActivity
import space.celestia.mobilecelestia.R
import space.celestia.mobilecelestia.common.EdgeInsets
import space.celestia.mobilecelestia.common.InsetAwareFragment
import space.celestia.mobilecelestia.common.RoundedCorners
import space.celestia.mobilecelestia.info.model.CelestiaAction
import space.celestia.mobilecelestia.utils.AppStatusReporter
import space.celestia.mobilecelestia.utils.CelestiaString
Expand All @@ -42,7 +41,7 @@ import javax.inject.Inject
import kotlin.concurrent.fixedRateTimer

@AndroidEntryPoint
class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaControlView.Listener, AppStatusReporter.Listener, AppCore.ContextMenuHandler {
class CelestiaFragment: Fragment(), SurfaceHolder.Callback, CelestiaControlView.Listener, AppStatusReporter.Listener, AppCore.ContextMenuHandler {
private var activity: Activity? = null

@Inject
Expand Down Expand Up @@ -72,7 +71,7 @@ class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaCo
private var browserItems: ArrayList<BrowserItem> = arrayListOf()
private var density: Float = 1f
private var previousDensity: Float = 0f
private var savedInsets: EdgeInsets? = null
private var savedInsets = EdgeInsets()
private var hasSetRenderer: Boolean = false

private var isControlViewVisible = true
Expand Down Expand Up @@ -216,41 +215,27 @@ class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaCo

override fun celestiaLoadingProgress(status: String) {}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

handleInsetsChanged(view, currentSafeInsets, currentRoundedCorners)
}

override fun onInsetChanged(view: View, newInsets: EdgeInsets, roundedCorners: RoundedCorners) {
super.onInsetChanged(view, newInsets, roundedCorners)

handleInsetsChanged(view, newInsets, roundedCorners)
}

fun updateFrameRateOption(newFrameRateOption: Int) {
frameRateOption = newFrameRateOption
renderer.enqueueTask {
renderer.setFrameRateOption(newFrameRateOption)
}
}

private fun handleInsetsChanged(view: View, newInsets: EdgeInsets, roundedCorners: RoundedCorners) {
val safeInsets = EdgeInsets(newInsets, roundedCorners, resources.configuration)
if (!loadSuccess) {
savedInsets = safeInsets
return
}
fun handleInsetsChanged(newInsets: EdgeInsets) {
savedInsets = newInsets
val thisView = view ?: return
if (!loadSuccess) { return }

val insets = safeInsets.scaleBy(scaleFactor)
val insets = savedInsets.scaleBy(scaleFactor)
renderer.enqueueTask {
appCore.setSafeAreaInsets(insets)
}

val ltr = resources.configuration.layoutDirection != View.LAYOUT_DIRECTION_RTL
val safeInsetEnd = if (ltr) newInsets.right else newInsets.left

val controlView = view.findViewById<FrameLayout>(currentControlViewID) ?: return
val controlView = thisView.findViewById<FrameLayout>(currentControlViewID) ?: return
val params = controlView.layoutParams as? ConstraintLayout.LayoutParams
if (params != null) {
params.marginEnd = resources.getDimensionPixelOffset(R.dimen.control_view_container_margin_end) + safeInsetEnd
Expand Down Expand Up @@ -348,11 +333,7 @@ class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaCo
appCore.setDPI((96 * density * scaleFactor).toInt())
appCore.setPickTolerance(10f * density * scaleFactor)

val insets = savedInsets
if (insets != null) {
appCore.setSafeAreaInsets(insets.scaleBy(scaleFactor))
savedInsets = null
}
appCore.setSafeAreaInsets(savedInsets.scaleBy(scaleFactor))

appCore.clearFonts()

Expand Down Expand Up @@ -381,8 +362,6 @@ class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaCo
}

private fun setupInteractions() {
val thisView = view ?: return

glView.isReady = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
glView.isContextClickable = true
Expand All @@ -400,7 +379,7 @@ class CelestiaFragment: InsetAwareFragment(), SurfaceHolder.Callback, CelestiaCo

Log.d(TAG, "Ready to display")

handleInsetsChanged(thisView, currentSafeInsets, currentRoundedCorners)
handleInsetsChanged(savedInsets)
}

override fun onCreateContextMenu(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
package space.celestia.mobilecelestia.common

import android.content.res.Configuration
import androidx.core.view.DisplayCutoutCompat
import androidx.core.view.WindowInsetsCompat
import kotlin.math.max

class EdgeInsets(val left: Int = 0, val top: Int = 0, val right: Int = 0, val bottom: Int = 0) {
constructor(insets: WindowInsetsCompat?) : this(insets?.displayCutout)

constructor(cutout: DisplayCutoutCompat?) : this(
cutout?.safeInsetLeft ?: 0,
cutout?.safeInsetTop ?: 0,
cutout?.safeInsetRight ?: 0,
cutout?.safeInsetBottom ?: 0)
constructor(insets: WindowInsetsCompat?) : this(
insets?.systemWindowInsetLeft ?: 0,
insets?.systemWindowInsetTop ?: 0,
insets?.systemWindowInsetRight ?: 0,
insets?.stableInsetBottom ?: 0)

constructor(edgeInsets: EdgeInsets, roundedCorners: RoundedCorners, configuration: Configuration) : this(
if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) edgeInsets.left else max(edgeInsets.left, max(roundedCorners.topLeft, roundedCorners.bottomLeft)),
Expand Down

This file was deleted.

0 comments on commit 5eae423

Please sign in to comment.