@@ -59,29 +59,6 @@ class InsertLinkDialog @Inject constructor(
59
59
}
60
60
}
61
61
62
- private fun resetDialogState () {
63
- binding.urlLayout.setError(null )
64
-
65
- binding.displayNameLayout.placeholderText = null
66
- }
67
-
68
- private fun setConfirmButtonListener (dialog : DialogInterface ) = with (binding) {
69
- (dialog as AlertDialog ).getButton(AlertDialog .BUTTON_POSITIVE ).setOnClickListener {
70
- val url = addMissingHttpsProtocol(urlEditText.trimmedText)
71
- if (validate(url)) {
72
- val displayName = (displayNameEditText.text?.takeIf { it.isNotBlank() } ? : urlEditText.text).toString().trim()
73
- addLink?.invoke(displayName, url)
74
- dialog.dismiss()
75
- } else {
76
- urlLayout.setError(activityContext.getString(R .string.snackbarInvalidUrl))
77
- }
78
- }
79
-
80
- urlEditText.doOnTextChanged { _, _, _, _ ->
81
- urlLayout.setError(null )
82
- }
83
- }
84
-
85
62
override fun resetCallbacks () {
86
63
addLink = null
87
64
}
@@ -116,9 +93,33 @@ class InsertLinkDialog @Inject constructor(
116
93
}
117
94
}
118
95
96
+ private fun resetDialogState () = with (binding) {
97
+ urlLayout.setError(null )
98
+ displayNameLayout.placeholderText = null
99
+ }
100
+
101
+ private fun setConfirmButtonListener (dialog : DialogInterface ) = with (binding) {
102
+ (dialog as AlertDialog ).getButton(AlertDialog .BUTTON_POSITIVE ).setOnClickListener {
103
+ val url = addMissingHttpsProtocol(urlEditText.trimmedText)
104
+
105
+ if (validate(url)) {
106
+ val displayName = (displayNameEditText.text?.takeIf { it.isNotBlank() } ? : urlEditText.text).toString().trim()
107
+ addLink?.invoke(displayName, url)
108
+
109
+ dialog.dismiss()
110
+ } else {
111
+ urlLayout.setError(activityContext.getString(R .string.snackbarInvalidUrl))
112
+ }
113
+ }
114
+
115
+ urlEditText.doOnTextChanged { _, _, _, _ ->
116
+ urlLayout.setError(null )
117
+ }
118
+ }
119
+
119
120
private fun addMissingHttpsProtocol (link : String ): String {
120
121
val protocolEndIndex = link.indexOf(" ://" )
121
- val isProtocolSpecified = protocolEndIndex > 0 // If there is indeed a specified protocol of at least 1 char long
122
+ val isProtocolSpecified = protocolEndIndex > 0 // If there is a specified protocol and it is at least 1 char long
122
123
123
124
if (isProtocolSpecified) return link
124
125
0 commit comments