Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last Suggestion not Showing Correctly #315

Closed
alexknop opened this issue Jul 22, 2023 · 10 comments · Fixed by #346
Closed

Last Suggestion not Showing Correctly #315

alexknop opened this issue Jul 22, 2023 · 10 comments · Fixed by #346
Labels
bug Something isn't working

Comments

@alexknop
Copy link
Contributor

alexknop commented Jul 22, 2023

I have been seeing an issue on my Sonim XP5s (running Android 8.1) where the last item in the suggestions (the farthest right suggestion) is not completely showing (it is cut off on the end) when I first cycle through the suggestions. However, if I cycle through them a second time, by the second time it looks correct (see how "Hid" shows correctly the second time).
I have poked at the code a bit, learned about RecyclerView, etc. The xml/layout looks good, and possibly that isn't where the issue lies because it eventually looks good on the second try. I'm thinking it could be something with the functions for selecting left/right. I would be curious where you think the issue may lie and I am open to debugging that specific code area myself:
image
image

@alexknop
Copy link
Contributor Author

also, I am noticing on first scroll, it doesn't scroll very smooth. It kind of shifts left and then back to the right. It's almost as if the left-most suggestion is left-aligned to the screen (see how "Gi" is aligned to the left of the screen) and it's not allowing it to be cut off a bit and fade off to the left. Hope that makes sense.

@sspanak
Copy link
Owner

sspanak commented Jul 24, 2023

I see nothing wrong here. The suggestion list could be wider than the screen, because there could be many possible matches of what you typed. Naturally, they can't match the screen width perfectly every time.

The words are not aligned to either side of the screen. What you see is just a coincidence. Type something else that would cause a longer suggestion list (even "hide" should work in your case), scroll to both sides and you'll see it's all good.

There is nothing to fix here.

@sspanak sspanak added the invalid This doesn't seem right label Jul 24, 2023
@alexknop
Copy link
Contributor Author

I don't think I explained my issue enough. "Hid" is the last suggestion in a long list of suggested words. To see for yourself, type 4-4 to get these suggestions. The first screenshot is me scrolling all the way to the right until "Hid" is highlighted. You can see that it is cut off and you can't read the entire word.
The second screenshot is what it looks like when I press right (going back to the beginning of the suggestion list) and scrolling to the last suggestion again. This time around, the entire word is shown.
For some reason, on first scroll it can't fit the last suggested word on the screen.

@sspanak
Copy link
Owner

sspanak commented Jul 26, 2023

Ah, I see. Sorry, for misinterpreting.

However, scrolling works fine on both my phones. Selecting the previous/next word happens in SuggestionsBar.scrollToSuggestion(), but I see nothing wrong there.

There are two possible problems:

  1. It could be a RecyclerView bug in older Android versions (I'm testing on 10 and 11).
  2. People claim sometimes the RecyclerView needs some time before it is able to scroll

I doubt it is the second case, but could please help with confirming? In SuggestionsBar.scrollToSuggestion() try replacing:

mView.scrollToPosition(selectedIndex);

with this:

new Handler().postDelayed(() -> mView.scrollToPosition(selectedIndex), 200);

Supposingly, scrolling will become inadequately slow, but it will work. Of course, this is not a solution, it is just a test.

@sspanak sspanak added more info needed Further information is requested and removed invalid This doesn't seem right labels Jul 26, 2023
@alexknop
Copy link
Contributor Author

Yes, this workaround is working, which is bringing us closer to the root of the problem.
I've found that a more obvious way to test this bug is when you first get a list of suggestions, press the left key so that it goes directly to the last suggestion instead of scrolling left to right until the end. Typically when I press 1 and then the left key, I can't even see the "?" that is suggested, but I was able to with this patch

@sspanak
Copy link
Owner

sspanak commented Jul 31, 2023

There may be a better solution in that Stackoverflow thread. Instead of waiting for 200 ms, this is supposed to wait for the view to become ready, then scroll:

mView.post(() -> mView.scrollToPosition(selectedIndex));

Could you please replace the same line as above, but with the .post() alternative. It works very well on my phone, so if it fixes the problem on yours, we can keep it.

@alexknop
Copy link
Contributor Author

That did not work very well, the delay works better. I was even able to reduce the delay to 100 ms and I don't notice any slowness, but get to see the last suggestion correctly.

@sspanak
Copy link
Owner

sspanak commented Aug 2, 2023

This is probably happening on other low end phones too, so I would like to have it fixed.

I have two ideas how to fix it, but before that, I need to know one more thing. But let's start with the original version of SuggestionBar.java, the one that's in master.

  1. Type "4-4", then cycle the suggestions until you can see the last one.
  2. Select it, but do not press OK.
  3. Change the text case with "#" (or whatever key you have configured).

Are you still able to see the last suggestion? Has the list automatically scrolled to the beginning?

If yes, then setSuggestions() must also be fixed. Otherwise, we'll take care only of scrollToSuggestion().

Also, could you please validate one more alternative way of fixing the problem? Since your phone needs some time to update the highlighted word before scrolling, let's reverse the order of actions and first scroll, then let it draw on the screen as long as it wants. This could again fail, but we could give it a try. So, scrollToSuggestion() would look like this:

public void scrollToSuggestion(int increment) {
	if (suggestions.size() <= 1) {
		return;
	}

	int oldIndex = selectedIndex;

	selectedIndex = selectedIndex + increment;
	if (selectedIndex == suggestions.size()) {
		selectedIndex = 0;
	} else if (selectedIndex < 0) {
		selectedIndex = suggestions.size() - 1;
	}

	mView.scrollToPosition(selectedIndex);

	mSuggestionsAdapter.setSelection(selectedIndex);
	mSuggestionsAdapter.notifyItemChanged(oldIndex);
	mSuggestionsAdapter.notifyItemChanged(selectedIndex);
}

The other idea is to add a configuration option "alternative scrolling" or similar, that when enabled will allow scrolling with delay, which definitely works for you.

@sspanak sspanak added the bug Something isn't working label Aug 2, 2023
@alexknop
Copy link
Contributor Author

alexknop commented Aug 2, 2023

  1. When I change case, the last suggestion is still shown and it actually refreshes to show the full word which is nice:
    Before:
    image
    After Changing Case:
    image
  2. Your scrollToSuggestion didn't change anything. Didn't break but just didn't fix the issue.

@sspanak
Copy link
Owner

sspanak commented Aug 3, 2023

That's so sad... OK, I guess I'll add a setting for the alternative scrolling method using a delay.

@sspanak sspanak removed the more info needed Further information is requested label Aug 10, 2023
@sspanak sspanak mentioned this issue Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants