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

Preference Migration Part-1: Migrated NotificationsSettingsDialogPreference #19986

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

07jasjeet
Copy link
Contributor

@07jasjeet 07jasjeet commented Jan 19, 2024

Created AndroidX implementation of NotificationsSettingsDialogPreference.java
Did not remove NotificationsSettingsDialogPreference.java due to compatibility issues but will be removed once NotificationsSettingsFragment has been migrated.

Fixes #17962 (partially)

Review Notes: Compare with NotificationsSettingsDialogPreference.java and NotificationsSettingsFragment to draw conclusions.


To Test:

Testing can be done in upcoming PRs. Otherwise, supplying dummy data and showing this dialog on any screen would work as well.


Regression Notes

  1. Potential unintended areas of impact

    None

  2. What I did to test those areas of impact (or what existing automated tests I relied on)

    Manual Testing

  3. What automated tests I added (or what prevented me from doing so)

    None


PR Submission Checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes Testing Checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

Created AndroidX implementation of NotificationsSettingsDialogPreference.java
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jan 19, 2024

Warnings
⚠️ PR is not assigned to a milestone.

Generated by 🚫 dangerJS

@07jasjeet
Copy link
Contributor Author

@antonis

@antonis antonis self-requested a review January 19, 2024 07:33
import org.wordpress.android.util.JSONUtils
import org.wordpress.android.util.extensions.getDrawableFromAttribute

class NotificationsSettingsDialogFragment(
Copy link
Member

Choose a reason for hiding this comment

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

I would advocate toward using fragment arguments instead of custom constructor parameters. I found this article useful on how to do this. This example of a DialogFragment using this pattern inside the project can be useful.

NotificationsSettings.Channel.OTHER, NotificationsSettings.Channel.WPCOM -> {}
}
if (mTitleViewWithMainSwitch != null) {
val titleView = mTitleViewWithMainSwitch!!.findViewById<TextView>(R.id.title)
Copy link
Member

Choose a reason for hiding this comment

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

One other generic issue not caught by the tools is the use of not-null assertion operator (!!) in many places in the introduced code. Though this may be introduced when converting code to Kotlin we should try to avoid it.
Since this specific case involves a View we could use a lateinit variable instead of a nullable one and not have the need for a !!. This can be applied in all interface objects used. Wdyt?
When using a nullable object is not avoidable it is preferred to use the safe call operator ?. or a simple null check.
You can find some more information on null safety in Kotlin here.


// Update the settings json
val keys: Iterator<*> = mUpdatedJson.keys()
while (keys.hasNext()) {
Copy link
Member

@antonis antonis Jan 31, 2024

Choose a reason for hiding this comment

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

What would you say of simplifying the while block with something like the following:

            for (settingName in mUpdatedJson.keys()) {
                settings.updateSettingForChannelAndType(
                    this.channel, this.type, settingName,
                    mUpdatedJson.optBoolean(settingName), this.blogId
                )
            }


override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val context = requireContext()
@SuppressLint("InflateParams")
Copy link
Member

Choose a reason for hiding this comment

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

We could avoid the use the suppress by using the onCreateView method. This is an example DialogFragment that does this.

@antonis
Copy link
Member

antonis commented Jan 31, 2024

Thank you for your contribution @07jasjeet 🙇

I've left some feedback inline your code.

Testing can be done in upcoming PRs. Otherwise, supplying dummy data and showing this dialog on any screen would work as well.

Could you help me with this to be able to test the UI properly (e.g. a patch file)?

I also noticed a lint error (you can trigger it with ./gradlew lintWordpressVanillaRelease) that would prevent the CI from merging your PR:

e: WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsDialogPreferenceX.kt:10:5 Accidental override: The following declarations have the same JVM signature (getContext()Landroid/content/Context;):
fun <get-context>(): Context defined in org.wordpress.android.ui.prefs.notifications.NotificationsSettingsDialogPreferenceX
fun getContext(): Context defined in org.wordpress.android.ui.prefs.notifications.NotificationsSettingsDialogPreferenceX

We could annotate the val context: Context parameter with the @JvmField annotation to overcome this for now and be able to compile the project.

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

Successfully merging this pull request may close these issues.

[Preference Migration] Migrate Legacy Android Preference to AndroidX Preference
2 participants