super-productivity-android icon indicating copy to clipboard operation
super-productivity-android copied to clipboard

Pressing back when a side bar is opened changes page instead of closing the bar

Open lrq3000 opened this issue 1 year ago • 7 comments

:ghost: Brief Description

When a side panel is opened, such as the side navigation bar or the task bar or notes bar, pressing the Back button on the Android interface should close the side panel, but instead the panel is ignored and the app goes to the previous page in history or it closes down if on the Today page.

:tophat: workflow configuration

Android 11 in AVD emulator.

:heavy_plus_sign: Additional context

As usual, I can work on the Android side. But here the web app needs to be modified to add required callbacks: one to hide each bar + one to query the state of each bar. But I'm very inexperienced with typescript.

I tried to register a new callback inside android-interface.ts:

  androidInterface.hideNavBarCallBack = () => {
    androidInterface.showToast('Received hideNavBarCallBack new');
    androidInterface.layoutService.hideSideNav();
    androidInterface.layoutService.hideNotes();
    androidInterface.layoutService.hideAddTaskBar();
    androidInterface.showToast('Received hideNavBarCallBack end');
    console.log('Received hideNavBarCallBack end');
  };

But the calls fail (the showToast() work fine).

Also I would need access to selectIsShow*.

If somebody can implement these changes or suggest how to do so, I would be happy to fix this issue in the Android app, so that we get a fully functional native behavior with the back button (extending the work of #27).

lrq3000 avatar Jan 27 '23 08:01 lrq3000

Hey hey! I think for this we might not need the android side of things. There is a browser event for the back button press:

document.addEventListener('backbutton', function(){
if(menu is visible) {
  //Hide the menu
  //This is also working fine
return false;
} 

I can have a look at this!

johannesjo avatar Jan 27 '23 11:01 johannesjo

Oh so you mean this way it would be implemented not only in Android but as a feature for all versions of Super Productivity? That would be awesome yes!

In Android, this is the function that is called:

webView.goBack()

I am not sure what the goBack() method exactly does, hopefully it will account for DOM manipulated backbutton and so it will work transparently, but if not we can easily fix that later with a callback to force call your event listener.

lrq3000 avatar Jan 27 '23 11:01 lrq3000

So I checked this and it turns out that the backbutton event is not a native browser event. Sorry for the confusion! So we need to go the originally proposed route. For the interface I would add two things:

  androidInterface.onBackButtonPress$ = new Subject();

Which can be used at other places to close the navigation etc.

Which should be triggered via

callJSInterfaceFunctionIfExists(
                "next",
                "onBackButtonPress$"
            )

And then it's probably good to have another function:

    triggerBackButton(): void;

that will trigger the native backbutton behavior (e.g. close the app).

What do you think? I can write the javascript part if you would provide the android side of things.

johannesjo avatar Feb 02 '23 18:02 johannesjo

The same thing happens when selecting a task. Hitting the back button should idiomatically close the task view, same as touching the X button in the top right, but it changes the page instead.

jeaye avatar Jun 02 '23 23:06 jeaye

@johannesjo Oh I'm terribly sorry, I missed your message above! Yes of course if you implement a function in TypeScript that I can callback similarly to what we didi for the folder path for the sync feature then i can implement that in Android!

Though i may be unable to do it right now because i don't have a computer for development but I should be able to find a solution soon :-)

lrq3000 avatar Jun 03 '23 20:06 lrq3000

@lrq3000 No worries! Let me know if I can help you somehow with the development computer thingy (you can write to [email protected] for further discussion :)).

johannesjo avatar Jun 04 '23 08:06 johannesjo

@johannesjo thank you very much, that's very kind! :D

lrq3000 avatar Jun 09 '23 08:06 lrq3000