Browse Source

Android Back button like home button (#212)

pull/215/head
Dan Ballard 3 months ago
parent
commit
6af91b71c1

+ 7
- 0
android/src/ca/openprivacy/cwtch/ui/CwtchActivity.java View File

@@ -124,4 +124,11 @@ public class CwtchActivity extends org.qtproject.qt5.android.bindings.QtActivity

}
}

// handle root level back button push as a home button push: don't exit, just go to home screen
public static void rootHomeHandle() {
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
m_instance.startActivity(i);
}
}

+ 19
- 3
go/gothings/android/CwtchActivity.go View File

@@ -1,6 +1,7 @@
package android

import (
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"github.com/therecipe/qt/androidextras"
"github.com/therecipe/qt/core"
)
@@ -13,10 +14,12 @@ type CwtchActivity struct {
_ string `property:"notification"`

_ func(string) `slot:"updateAndroidNotification"`

_ func() `signal:"rootHomeButtonHandle,auto"`
}

func (c *CwtchActivity) init() {
log.Debugln("CwtchActivity.init()")
c.createOngoingNotification()
c.ConnectNotificationChanged(c.updateAndroidNotification)
}
@@ -31,7 +34,7 @@ func (c *CwtchActivity) updateAndroidNotification(n string) {
)

if err != nil {
println(err.Error())
log.Errorf("Error calling Java CwtchActivity.notify(): %v\n", err.Error())
}
}

@@ -45,6 +48,19 @@ func (c *CwtchActivity) createOngoingNotification() {
)

if err != nil {
println(err.Error())
log.Errorf("Error calling Java CwtchActivity.ongoingNotify(): %v\n", err.Error())
}
}

func (c *CwtchActivity) rootHomeButtonHandle() {
log.Infoln("CwtchActivity.rootHomeButtonHandle()!")
var err = androidextras.QAndroidJniObject_CallStaticMethodVoid2Caught(
"ca/openprivacy/cwtch/ui/CwtchActivity",
"rootHomeHandle",
"()V",
)

if err != nil {
log.Errorf("Error calling Java CwtchActivity.rootHomeButtonHandle(): %v\n", err.Error())
}
}

+ 1
- 1
go/gothings/gcd.go View File

@@ -75,7 +75,7 @@ type GrandCentralDispatcher struct {
_ func(onion, nick string) `signal:"savePeerSettings,auto"`
_ func(onion, groupID string) `signal:"inviteToGroup,auto"`
_ func(onion, key, nick string) `signal:"setAttribute,auto"`
_ func(onion string) `signal:"deleteContact,auto""`
_ func(onion string) `signal:"deleteContact,auto"`
_ func(locale string) `signal:"setLocale,auto"`
_ func() `signal:"allowUnknownPeers,auto"`
_ func() `signal:"blockUnknownPeers,auto"`

+ 14
- 0
qml/main.qml View File

@@ -195,6 +195,20 @@ ApplicationWindow {
}
}
}

focus: true
Keys.onPressed: {
if (event.key == Qt.Key_Back) {
event.accepted = true
if (theStack.currentIndex == theStack.emptyPane) {
androidCwtchActivity.rootHomeButtonHandle()
} else if (theStack.currentIndex == theStack.userProfilePane || theStack.currentIndex == theStack.groupProfilePane) {
theStack.currentIndex = theStack.messagePane
} else {
theStack.currentIndex = theStack.emptyPane
}
}
}
}

PropertyAnimation { id: anmPopup; easing.type: Easing.InQuart; duration: 7000; target: popup; property: "opacity"; to: 0; }

Loading…
Cancel
Save