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

Make custom sync server preferences easier to understand #12367

Merged
merged 6 commits into from
Oct 17, 2022

Conversation

oakkitten
Copy link
Contributor

@oakkitten oakkitten commented Sep 10, 2022

This implements my own suggestion from the point 2 in Remaining issues in #12112 nearly verbatim, except I added a note about Sync url preference expecting the full URL as discussed in #12269. @dobefore What do you think?

device-2022-09-08-015053.mp4

As usual, please see the commits for individual changes.

Note that in the first commit there's a link to the fragment https://docs.ankidroid.org/#_custom_sync_server which doesn't exist yet. I suppose the docs will have to be amended for the new release, and this section could be added later.

Also note that Accessibility scanner complains about two things; not sure if this is actionable.

  • Help preference summary: Link text. Consider using more descriptive text in the link. The link “Learn more” may not independently convey the link's purpose.
  • Sync url preference switch widget: Item descriptions. Multiple items have the same description. This clickable item's speakable text: "OFF" is identical to that of 1 other item(s).

Edit: The test pass in my repo.

How Has This Been Tested?

Manually tested on my Xiaomi Mi A2 (Android 11) and Motorola Moto G 1st Gen (Android 6).
Added a unit test for preference migration.

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@github-actions
Copy link
Contributor

Message to maintainers, this PR contains strings changes.

  1. Before merging this PR, it is best to run the "Sync Translations" GitHub action, then make and merge a PR from the i18n_sync branch to get translations cleaned out.
  2. Then merge this PR, and immediately do another translation PR so the huge change made by this PR's key changes are all by themselves.

Read more about updating strings on the wiki,

Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I like it. It's a great improvement on this screen. Even being the least used screen, it's a nice progress for the app

AnkiDroid/src/main/res/values/10-preferences.xml Outdated Show resolved Hide resolved
@@ -206,6 +206,9 @@
<string name="advanced_forecast_stats_mc_n_iterations_title" maxLength="41">Number of iterations of the simulation</string>
<!-- Custom sync server settings -->
<string name="custom_sync_server_title" maxLength="41">Custom sync server</string>
<string name="custom_sync_server_summary_none_of_the_two_servers_used">Not used</string>
<string name="custom_sync_server_summary_both_or_either_of_the_two_servers_used">Collection: %1$s\nMedia: %2$s</string>
<string name="custom_sync_server_summary_placeholder_default">default</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we use the AnkiWeb string here? I think that it is more specific + would be one less string to translate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that and while I don't have a strong preference I like “default” more. If you read Custom server? AnkiWeb! it may sound a bit like maybe AnkiWeb is the name of a server application that you can install for yourself. “Default” also chimes a bit better with “Not used”, which I liked better than having “Default” if neither server is used. If you say “AnkiWeb” then “Not used” is a bit awkward... I guess in that case you'd also want to say “AnkiWeb” and that would be less ideal. Anyway, I'not a native so this is not a strong opinion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, it's more of a question that I have to think what default means, while AnkiWeb is straighthead, no thinking and no confusion. I'm not a native as well and I don't find having Not used first and AnkiWeb awkward at all. On my mind, their uses are distinct enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in the context of custom x, it's rather clear that default x means not using the custom x. Or maybe not. Where are the natives when you need them? 😪

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the confusion can be minimised if we just mention that AnkiWeb is the default server with something like:
AnkiWeb (default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still dislike AnkiWeb, even with (default), for the reasons mentioned above. I am willing to give in to peer pressure, but I request more peers (or one very assertive peer).

AnkiDroid/src/main/res/values/10-preferences.xml Outdated Show resolved Hide resolved
AnkiDroid/src/main/res/values/10-preferences.xml Outdated Show resolved Hide resolved
@BrayanDSO BrayanDSO added Needs Author Reply Waiting for a reply from the original author Needs Review labels Sep 10, 2022
@oakkitten oakkitten force-pushed the custom-sync-server branch 2 times, most recently from 77cc1e5 to 19792cf Compare September 10, 2022 21:40
@BrayanDSO
Copy link
Member

Pending to me will be only

  1. the URL extraction to a constant from the string, so it may be changed in the future if necessary
  2. Adding search:ignore to the HtmlHelpPreference

I'll leave the strings' texts to the natives.

@oakkitten
Copy link
Contributor Author

Rebased onto v2.16alpha85 to resolve a conflict and to add search:ignore to HtmlHelpPreference

@BrayanDSO BrayanDSO added Needs Second Approval Has one approval, one more approval to merge and removed Needs Author Reply Waiting for a reply from the original author labels Sep 25, 2022
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like all of this except:

  • I liked the language but tried to make it even more precise + prescriptive
  • we must maintain URL flexibility without trashing translations, so that should be interpolated

AnkiDroid/src/main/res/values/10-preferences.xml Outdated Show resolved Hide resolved
@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Oct 13, 2022
@mikehardy
Copy link
Member

And took a conflict during my current merge-fest, apologies. Probably an AlertDialog thing 🙈

@oakkitten
Copy link
Contributor Author

oakkitten commented Oct 15, 2022

Rebased on current main to resolve conflicts, also incorporated suggested wording changes into the first commit and added a commit extracting the URL into a separate string. Now if the tests would be so kind to pass...

@BrayanDSO BrayanDSO self-requested a review October 15, 2022 20:29
Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last changes LGTM.

Noticed only now, after reading HtmlHelpPreference javadoc, that the new preferences are on com.ichi2.anki.preferences, but all the other individual Preference classes are on com.ichi2.preferences, so they should be moved.

@BrayanDSO BrayanDSO removed the Needs Second Approval Has one approval, one more approval to merge label Oct 15, 2022
@oakkitten
Copy link
Contributor Author

Good catch! Rebased. (Rebasing with renaming is hell!)

I put the helper methods into a new file com/ichi2/preferences/PreferenceUtil.kt since they belong with the preferences. They were in com/ichi2/preferences/anki/PreferenceUtils.kt before. Didn't have a better name for the file, opted to change Utils to Util so it's not the same.

Copy link
Member

@BrayanDSO BrayanDSO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming on a rebase is quite painful. My condolences

edit: There is a lint error. Good old missing copyright header

@BrayanDSO BrayanDSO removed the Needs Author Reply Waiting for a reply from the original author label Oct 16, 2022
@mikehardy mikehardy added Needs Author Reply Waiting for a reply from the original author and removed Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) labels Oct 17, 2022
@mikehardy
Copy link
Member

and a conflict, just for extra fun 🙈

@oakkitten
Copy link
Contributor Author

Done, and rebased on current main to resolve conflict.

@mikehardy mikehardy added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Author Reply Waiting for a reply from the original author labels Oct 17, 2022
@mikehardy
Copy link
Member

Great - running through ./tools/test-commits.sh <hash> on the commit stream now, and will do a strings sync to clear things out for all the changes here

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well...that's weird, on the very first commit ./gradlew ktlintFormat fails with:

/home/mike/work/AnkiDroid/Anki-Android-Upstream/AnkiDroid/src/main/java/com/ichi2/preferences/PreferenceUtil.kt
interface DialogFragmentProvider should be declared in a file named DialogFragmentProvider.kt 

...but....it works on the other 5 commits (!?)

Something about the extra sauce added in the following commit: d0e1209 makes ktlint okay with the interface in file not named after the interface 🤔

Could either dig deep and learn a bunch of things that may never be needed again to fix it, or just squash those two commits and be done, or squash them all 😆

Let me know what you think

@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Oct 17, 2022
HtmlHelpPreference is a preference that only provides help. It does not
need a key and it is not selectable. It treats its summary text as HTML
an renders it as such--including links.

This commit implements it and adds it to the top of Custom sync server
preference screen.
DialogFragmentProvider is an interface that slightly simplifies finding
relations between the preferences that display dialogs on click, and the
dialogs themselves.
At the time being, it serves two purposes:

  * It supports changing input type via android:inputType XML
    attribute, which can help the keyboard app with choosing a more
    suitable keyboard layout.

  * If continuousValidator is set, it is used to prevent the user from
    entering invalid data. On each text change, the validator is run;
    if it throws, the Ok button gets disabled.

It was designed as a drop-in replacement of EditTextPreference with the
extra functionality disabled by default. Additional functionality can be
added as needed.
VersatileTextWithASwitchPreference is a combination of a TextPreference
and a SwitchPreference. It mostly looks like a SwitchPreference, but the
switch and the title can be clicked separately.

The behavior is a bit special, see the javadoc for explanation.
Before, Custom sync server preferences were a bit confusing. There was
a master switch for both of them, but you could actually disable either
of the custom servers, or both of them, by not specifying the URL.

This is an attempt to resolve the confusion by removing the master
switch, and adding individual switches to the two custom server
preferences. Also, the parent preference, that is the one that you
click to get to Custom sync server preferences, now shows the status
of both child preferences in its summary. Hopefully this is less
confusing.

Additionally, instead of showing an error dialog in the case of invalid
URL, the edit text dialog doesn't allow accepting such an URL by
disabling the Ok button. Allowing the user to okay bad input means it is
going to be discarded, and that's pretty awful. What if user's custom
sync URL is 420 characters long?

Note that the URLs are now validated using OkHttp, which is more strict.

Preference migration follows in the next commit.
Use custom sync server preference was the master switch for both
collection and media custom sync servers. These preferences now have
individual switches; this migration applies the old master switch to
both individual switches, as long as the custom sync URLs are set.
@oakkitten
Copy link
Contributor Author

oakkitten commented Oct 17, 2022

I assume this rule is supposed to catch typos, like when you have a class FooBar in FooBaz.kt or something. Rebased to reorder commits 1 & 2 that should remove the lint error.

(Why squash though? I'm not exactly sure why one of commits failing lint is an issue. As long as you don't merge with --ff-only—I prefer --no-ff for almost every merge—you get a merge commit and you can revert a merge commit. You can eat a cake and have it too eh?

I'd even go so far to say there's not much value in ensuring every commit builds. If something breaks you can still use git blamegit bisect with --first-parent, and if this finds that the offending commit comes from a feature branch that has broken commits, well, fixing those commits while doing git blamegit bisect is about the same amount of work as doing it right away. Of course, if you happen to find that the feature is broken in another git blamegit bisect you'll have to redo the work but what are the chances of that.)

@mikehardy
Copy link
Member

  • No idea what ktlint is unhappy with at a technical level here
  • github doesn't allow FF control when using web UI and we're using the web UI so it's a constraint we're stuck with
  • we have tools that git bisect, every commit building is a useful thing

will re-check...

@oakkitten
Copy link
Contributor Author

  • I think that rule is not like an actual lint rule but more of a warning
  • It doesn't allow --ff-only, but I think the default merge strategy is --no-ff, so as long as you don't squash or rebase it will make a neat merge commit
  • I was actually talking about git bisect (I always confuse the two!), it also has --first-parent

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/bin/nice -n 19 ./tools/test-commits.sh 0746ab0b4b08a74b6b7f609703d2628c496e8c35 clean

@mikehardy
Copy link
Member

merge commit is not currently enabled for the repo, I've got squash or rebase - this is "rebase clean" now, so I'm going with that - will do the strings sync after

@mikehardy mikehardy merged commit d18cba8 into ankidroid:main Oct 17, 2022
@github-actions github-actions bot added this to the 2.16 release milestone Oct 17, 2022
@github-actions github-actions bot removed Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) squash-merge The pull request currently requires maintainers to "Squash Merge" Needs Author Reply Waiting for a reply from the original author labels Oct 17, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2022

Hi there @oakkitten! This is the OpenCollective Notice for PRs merged from 2022-10-01 through 2022-10-31

If you are interested in compensation for this work, the process with details is here:

https://github.com/ankidroid/Anki-Android/wiki/OpenCollective-Payment-Process#how-to-get-paid

We only post one comment per person per month to avoid spamming you, regardless of the number of PRs merged, but this note applies to all PRs merged for this month

Please note that GSoC contributions are okay for this process. Our philosophy is that our users have donated to AnkiDroid for all contributions. The only PRs that will not go through the OpenCollective process are ones directly related to am accepted GSoC project from a selected participant, since those receive a stipend from GSoC itself.

Please understand that our monthly budget is never guaranteed to cover all claims - the cap on payments-per-person may be lower, but we try to make our process as fair and transparent as possible, we just need your understanding.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants