Radiokot / photoprism-android-client

📸 A convenient Android gallery for your PhotoPrism library with plenty of useful features
https://radiokot.com.ua/p/photoprism-android-gallery
GNU General Public License v3.0
423 stars 32 forks source link

Cant navigate to search field on android tv #67

Open ippocratis opened 1 year ago

ippocratis commented 1 year ago

There is no way I can navigate and use the search field on android TV with a TV remote

Radiokot commented 1 year ago

The search view is quite complicated to adapt it for keyboard navigation, unfortunately I have no time to do it now.

rrednaxela commented 1 year ago

Maybe as a workaround for Android TV users you could add a key mapping to focus the search bar? I managed to get the following to work: in your method "onKeyDown" in the GalleryActivity view I added

else if (keyCode in setOf(
                KeyEvent.KEYCODE_8
                )
            ) {
            view.searchBar.requestFocus()
        }

which sets the focus to the SearchBar when the key 8 is pressed on the remote. By pressing OK on DPad, you get into the search view then. I tried to find a more meaningful key mapping, but I was having trouble to find out the right name/key for the buttons on my remote. For the settings dialogue, neither KEYCODE_SETTINGS, KEYCODE_MENU, KEYCODE_BOOKMARK were working with my remote... I'll try to debug the key mappings further when I have more time.

Radiokot commented 1 year ago

@rrednaxela thanks for investigating 🔎

rrednaxela commented 1 year ago

So I found this app to get reliable key codes for my remote contorl, and from Android Developer you can get the matching KeyEvent. Turns out that on my remote the button "context menu" has the key event KEYCODE_TV_INPUT_COMPOSITE_1 (which makes little sense). Most Android TV remote controls will however very likely have the keys KEYCODE_CHANNEL_UP and KEYCODE_CHANNEL_DOWN (used in TV mode to switch channels). So I would suggest to map KEYCODE_CHANNEL_UP to the searchview, and KEYCODE_CHANNEL_DOWN to the preferences, i.e. viewModel.onPreferencesButtonClicked() - this should work for any user I guess.

@Radiokot is there a method or could you add one to directly open the search view, similar to how viewModel.onPreferencesButtonClicked() opens the preferences? My try of view.searchBar.requestFocus() requires to press DPAD-OK afterwards, which is an unnecessary click.

If we can implement this and add a short hint for it on first launch for Android TV users, you can maybe finally get it approved for the TV store ;)

Radiokot commented 1 year ago

Many thanks for debugging key inputs from your remote control. I'll add CHANNEL_DOWN and INPUT_COMPOSITE_1 to the bindings which open the settings screen. The search, however, is more complicated case. It is not only about the search bar focus. The search configuration view is hard to adapt for keyboard navigation, unfortunately I have no time to do it now.

rrednaxela commented 1 year ago

What exactly do you mean? I was able to navigate the search view and select/remove people or albums with the dpad. It's not perfect but definitely doable. We do however need to be able to open it in an easy way :)

Radiokot commented 1 year ago

Wow, that's interesting 🤔 On TV emulator, I wasn't able to do almost anything useful.

rrednaxela commented 1 year ago

Thanks for adding the channel up button to open search 🚀 🚀 🚀 I am able to browse an album now on my TV. I also tried the TV simulator; the behavior is somewhat similar to real TV: after opening the search, it is at first unclear what is active, but if you press dpad-right 4-5 times, you'll suddenly see the albums becoming active. It would probably help if there was more contrast for the selected/hovered album (not just light-grey/grey). with dpad-down you can navigate to the apply button; this part isn't always working. I'll debug it further when I have time.

ippocratis commented 1 year ago

Channel up button opens search screen. Left/right on the dpad enables the cursor so that you can navigate to the search screen elements. OK button while on the search bar pops up the keyboard and you can type search filters. After enabling the cursor you can use up,down,left,right to navigate to people,album,type select with OK and use the apply button.

Nice work.

Thanks @Radiokot and thanks @rrednaxela for helping this happen