Skip to content

Commit

Permalink
Support separate parameter in landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed May 15, 2024
1 parent 09230be commit 6639b4f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/com/hiddenramblings/tagmo/BrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,16 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,

nfcFab = findViewById<FABulous>(R.id.nfc_fab).apply {
(behavior as FloatingActionButton.Behavior).isAutoHideEnabled = false
loadSavedPosition(prefs)
loadSavedPosition(resources.configuration)
setOnMoveListener(object : FABulous.OnViewMovedListener {
override fun onActionMove(x: Float, y: Float) {
prefs.fabulousX(x)
prefs.fabulousY(y)
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
prefs.fabulousX(x)
prefs.fabulousY(y)
} else {
prefs.fabulousHorzX(x)
prefs.fabulousHorzY(y)
}
}
})
}
Expand Down Expand Up @@ -1780,7 +1785,7 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
private fun loadAmiiboFiles(rootFolder: File?, recursiveFiles: Boolean) {
setSnackbarListener(object: SnackbarListener {
override fun onSnackbarHidden(fakeSnackbar: AnimatedLinearLayout) {
nfcFab.loadSavedPosition(prefs)
nfcFab.loadSavedPosition(resources.configuration)
snackbarListener = null
}
})
Expand All @@ -1802,7 +1807,7 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
private fun loadAmiiboDocuments(rootFolder: DocumentFile?, recursiveFiles: Boolean) {
setSnackbarListener(object: SnackbarListener {
override fun onSnackbarHidden(fakeSnackbar: AnimatedLinearLayout) {
nfcFab.loadSavedPosition(prefs)
nfcFab.loadSavedPosition(resources.configuration)
snackbarListener = null
}
})
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/hiddenramblings/tagmo/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ class Preferences(context: Context) {
putFloat(fabulousY, value)
}

private val fabulousHorzX = "fabulousHorzX"
fun fabulousHorzX(fab: FABulous): Float {
return getFloat(fabulousHorzX, fab.x)
}

fun fabulousHorzX(value: Float) {
putFloat(fabulousHorzX, value)
}

private val fabulousHorzY = "fabulousHorzY"
fun fabulousHorzY(fab: FABulous): Float {
return getFloat(fabulousHorzY, fab.y)
}

fun fabulousHorzY(value: Float) {
putFloat(fabulousHorzY, value)
}

private val query = "query"
fun query(): String? {
return getString(query, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import kotlin.math.abs

class FABulous : FloatingActionButton, OnTouchListener {

private val prefs: Preferences by lazy { Preferences(TagMo.appContext) }

private var downRawX = 0f
private var downRawY = 0f
private var dX = 0f
Expand Down Expand Up @@ -123,19 +125,26 @@ class FABulous : FloatingActionButton, OnTouchListener {
this.viewMoveListener = listener
}

override fun onConfigurationChanged(newConfig: Configuration?) {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
postDelayed({
val bounds = getViewCoordinates(this, x, y)
animate().x(bounds[0]).y(bounds[1]).setDuration(0).start()
}, TagMo.uiDelay.toLong())
loadSavedPosition(newConfig)
}

fun loadSavedPosition(prefs: Preferences) {
fun loadSavedPosition(configuration: Configuration) {
postDelayed({
val bounds = getViewCoordinates(
this, prefs.fabulousX(this), prefs.fabulousY(this)
)
val bounds = if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
getViewCoordinates(
this,
prefs.fabulousX(this),
prefs.fabulousY(this)
)
} else {
getViewCoordinates(
this,
prefs.fabulousHorzX(this),
prefs.fabulousHorzY(this)
)
}
animate().x(bounds[0]).y(bounds[1]).setDuration(0).start()
}, TagMo.uiDelay.toLong())
}
Expand Down

0 comments on commit 6639b4f

Please sign in to comment.