Skip to content

Commit

Permalink
WebViewUI: Open drawer instead of going back to Sitemaps
Browse files Browse the repository at this point in the history
When pressing the 'back to app' button the drawer is opened instead of closing the UI. This way users can switch faster between e.g. MainUI and notifications.

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Jun 18, 2024
1 parent 90ebb1a commit 21831bf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 5 additions & 1 deletion mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,11 @@ class MainActivity : AbstractBaseActivity(), ConnectionFactory.UpdateListener {
}

fun setDrawerLocked(locked: Boolean) {
drawerLayout.isSwipeDisabled = locked
drawerLayout.swipeToOpenDisabled = locked
}

fun openDrawer() {
drawerLayout.open()
}

private fun handlePropertyFetchFailure(result: ServerProperties.Companion.PropsFailure) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ abstract class AbstractWebViewFragment : Fragment(), ConnectionFactory.UpdateLis
callback?.updateActionBarState()
}

private fun closeFragment() {
callback?.closeFragment()
private fun openDrawer() {
callback?.openDrawer()
}

open class OHAppInterface(private val context: Context, private val fragment: AbstractWebViewFragment) {
Expand All @@ -417,7 +417,7 @@ abstract class AbstractWebViewFragment : Fragment(), ConnectionFactory.UpdateLis
fun exitToApp() {
Log.d(TAG, "exitToApp()")
fragment.launch {
fragment.closeFragment()
fragment.openDrawer()
}
}

Expand Down Expand Up @@ -474,7 +474,7 @@ abstract class AbstractWebViewFragment : Fragment(), ConnectionFactory.UpdateLis
}

interface ParentCallback {
fun closeFragment()
fun openDrawer()

fun updateActionBarState()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,8 @@ abstract class ContentController protected constructor(private val activity: Mai
return false
}

override fun closeFragment() {
if (temporaryPage != null) {
temporaryPage = null
activity.updateTitle()
updateActionBarState()
updateFragmentState(FragmentUpdateReason.PAGE_UPDATE)
updateConnectionState()
}
override fun openDrawer() {
activity.openDrawer()
}

override fun onPageUpdated(pageUrl: String, pageTitle: String?, widgets: List<Widget>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ import android.view.MotionEvent
import androidx.drawerlayout.widget.DrawerLayout

class LockableDrawerLayout(context: Context, attrs: AttributeSet?) : DrawerLayout(context, attrs) {
var isSwipeDisabled = false
var swipeToOpenDisabled = false
private val shouldIgnoreTouch
get() = swipeToOpenDisabled && !isOpen

override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
if (isSwipeDisabled) {
if (shouldIgnoreTouch) {
return false
}
return super.onInterceptTouchEvent(ev)
}

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(ev: MotionEvent): Boolean {
if (isSwipeDisabled) {
if (shouldIgnoreTouch) {
return false
}
return super.onTouchEvent(ev)
Expand Down

0 comments on commit 21831bf

Please sign in to comment.