jaredsburrows / gradle-license-plugin

Gradle plugin that provides a task to generate a HTML license report of your project.
https://central.sonatype.com/artifact/com.jaredsburrows/gradle-license-plugin
Apache License 2.0
411 stars 66 forks source link

IDE warning about the fragmentTransition when copying the code from the README sample #299

Closed StylianosGakis closed 9 months ago

StylianosGakis commented 1 year ago

In the section that shows

class OpenSourceLicensesDialog : DialogFragment() {

  fun showLicenses(activity: AppCompatActivity) {
    val fragmentManager = activity.getSupportFragmentManager()
    val fragmentTransaction = fragmentManager.beginTransaction()
    val previousFragment = fragmentManager.findFragmentByTag("dialog_licenses")
    if (previousFragment != null) {
      fragmentTransaction.remove(previousFragment)
    }
    fragmentTransaction.addToBackStack(null)

    show(fragmentManager, "dialog_licenses")
  }

  override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val webView = WebView(requireActivity())
    webView.loadUrl("file:///android_asset/open_source_licenses.html")

    return Builder(requireActivity())
      .setTitle("Open Source Licenses")
      .setView(webView)
      .setPositiveButton("OK",
        DialogInterface.OnClickListener { dialog: DialogInterface, which: Int -> dialog.dismiss() })
      .create()
  }
}

The IDE is complaining that there is no commit() call on the fragmentTransaction. Is this a false-positive warning from the IDE, or should this snippet be updated to contain more correct code?

Not super familiar myself with such dialog handling so I can't deduce that myself to give some suggestion.

StylianosGakis commented 1 year ago

I did end up testing this a bit, and turns out that if you do commit() and then you close this dialog by clicking outside of its bounds, then if you press the back button it does nothing, since it first consumes this committed fragment which doesn't get dismissed properly when just clicking outside. So I think if anything this is a false positive warning from the IDE, I'll leave this open in case someone else knows something more about this.