-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
NextcloudServerDialog.kt
56 lines (48 loc) · 1.98 KB
/
NextcloudServerDialog.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.qosp.notes.ui.sync.nextcloud
import android.app.AlertDialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.webkit.URLUtil
import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.fragment.app.activityViewModels
import dagger.hilt.android.AndroidEntryPoint
import org.qosp.notes.R
import org.qosp.notes.databinding.DialogNextcloudServerBinding
import org.qosp.notes.ui.common.BaseDialog
import org.qosp.notes.ui.common.setButton
import org.qosp.notes.ui.utils.requestFocusAndKeyboard
@AndroidEntryPoint
class NextcloudServerDialog : BaseDialog<DialogNextcloudServerBinding>() {
private val model: NextcloudViewModel by activityViewModels()
private var url: String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
url = arguments?.getString(URL, "").toString()
}
override fun createBinding(inflater: LayoutInflater) = DialogNextcloudServerBinding.inflate(layoutInflater)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
dialog.setTitle(getString(R.string.preferences_nextcloud_instance_url))
binding.editTextServerUrl.setText(url)
dialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.action_save), this) {
val url = binding.editTextServerUrl.text?.toString()?.trim() ?: ""
if (URLUtil.isHttpsUrl(url)) {
model.setURL(url)
return@setButton dismiss()
}
Toast.makeText(requireContext(), getString(R.string.message_not_valid_https), Toast.LENGTH_SHORT).show()
}
binding.editTextServerUrl.requestFocusAndKeyboard()
}
companion object {
private const val URL = "URL"
fun build(url: String?): NextcloudServerDialog {
return NextcloudServerDialog().apply {
arguments = bundleOf(
URL to url
)
}
}
}
}