Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit ad27081

Browse files
committed
[FIXED] Lint error Fragment not instantiatable
``` Fragment not instantiatable ../../src/main/java/com/hossainkhan/android/demo/ui/dialog/LayoutInfoDialog.kt:35: Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead 32 /** 33 * Bottom sheet dialog to show layout information. 34 */ 35 class LayoutInfoDialog( 36 private val title: String = "", 37 private val desciption: String = "", 38 private val previewXmlListener: (() -> Unit)? = null ```
1 parent 0ecdaf9 commit ad27081

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

app/src/main/java/com/hossainkhan/android/demo/ui/dialog/LayoutInfoDialog.kt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,33 @@ import com.hossainkhan.android.demo.R
3232
/**
3333
* Bottom sheet dialog to show layout information.
3434
*/
35-
class LayoutInfoDialog(
36-
private val title: String = "",
37-
private val desciption: String = "",
38-
private val previewXmlListener: (() -> Unit)? = null
39-
) : BottomSheetDialogFragment() {
35+
class LayoutInfoDialog : BottomSheetDialogFragment() {
36+
companion object {
37+
private const val BUNDLE_ARG_KEY_TITLE = "BUNDLE_TITLE"
38+
private const val BUNDLE_ARG_KEY_DESC = "BUNDLE_DESCRIPTION"
39+
40+
fun newInstance(title: String, description: String): LayoutInfoDialog {
41+
val args = Bundle()
42+
args.putString(BUNDLE_ARG_KEY_TITLE, title)
43+
args.putString(BUNDLE_ARG_KEY_DESC, description)
44+
45+
val dialog = LayoutInfoDialog()
46+
47+
dialog.arguments = args
48+
49+
return dialog
50+
}
51+
}
52+
53+
4054
lateinit var infoTitle: TextView
4155
lateinit var infoDescription: TextView
4256
lateinit var okButton: MaterialButton
4357
lateinit var previewXml: MaterialButton
58+
var previewXmlListener: (() -> Unit)? = null
4459

4560
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
46-
val view = inflater.inflate(R.layout.dialog_layout_info_sheet, container, false)
61+
val view = inflater.inflate(com.hossainkhan.android.demo.R.layout.dialog_layout_info_sheet, container, false)
4762
infoTitle = view.findViewById(R.id.layout_info_title)
4863
infoDescription = view.findViewById(R.id.layout_info_description)
4964
okButton = view.findViewById(R.id.layout_info_ok)
@@ -64,7 +79,10 @@ class LayoutInfoDialog(
6479
behavior.peekHeight = 0
6580
}
6681

67-
bindView()
82+
bindView(
83+
arguments!!.getString(BUNDLE_ARG_KEY_TITLE, ""),
84+
arguments!!.getString(BUNDLE_ARG_KEY_DESC, "")
85+
)
6886
}
6987

7088
override fun onPause() {
@@ -73,9 +91,9 @@ class LayoutInfoDialog(
7391
}
7492

7593

76-
private fun bindView() {
94+
private fun bindView(title: String, description: String) {
7795
infoTitle.text = title
78-
infoDescription.text = desciption
96+
infoDescription.text = description
7997

8098
okButton.setOnClickListener { dismiss() }
8199
previewXml.setOnClickListener {

app/src/main/java/com/hossainkhan/android/demo/ui/layoutpreview/LayoutPreviewBaseActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ open class LayoutPreviewBaseActivity : AppCompatActivity() {
112112
* Loads layout information and previews in a snackbar.
113113
*/
114114
private fun showLayoutInfo(layoutInformation: LayoutInformation, fromUser: Boolean = false) {
115-
infoDialog = LayoutInfoDialog(
115+
infoDialog = LayoutInfoDialog.newInstance(
116116
layoutInformation.title.toString(),
117117
layoutInformation.description.toString()
118-
) { loadLayoutUrl() }
118+
)
119+
infoDialog?.previewXmlListener = { loadLayoutUrl() }
119120

120121
Timber.d("Layout info showing: %s", infoDialog?.isVisible)
121122
if (infoDialog?.isVisible == false) {

app/src/main/res/layout/dialog_layout_info_sheet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
android:layout_width="match_parent"
2323
android:layout_height="wrap_content"
2424
android:background="@color/colorPrimary"
25-
android:padding="24dp">
25+
android:padding="16dp">
2626

2727
<TextView
2828
android:id="@+id/layout_info_title"

0 commit comments

Comments
 (0)