2018-12-25 12:54:41 +01:00
|
|
|
package jp.juggler.subwaytooter.dialog
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
|
import android.app.Dialog
|
|
|
|
import android.view.View
|
|
|
|
import android.view.WindowManager
|
|
|
|
import android.widget.Button
|
|
|
|
import android.widget.CheckBox
|
|
|
|
import android.widget.EditText
|
|
|
|
import android.widget.TextView
|
2020-02-14 15:16:07 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2018-12-25 12:54:41 +01:00
|
|
|
import jp.juggler.subwaytooter.R
|
2020-02-02 15:19:57 +01:00
|
|
|
import jp.juggler.subwaytooter.api.entity.Host
|
2019-10-03 18:47:15 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootInstance
|
2019-10-08 23:57:21 +02:00
|
|
|
import jp.juggler.subwaytooter.util.DecodeOptions
|
|
|
|
import jp.juggler.subwaytooter.util.LinkHelper
|
2020-09-29 19:44:56 +02:00
|
|
|
import jp.juggler.subwaytooter.util.openCustomTab
|
2020-09-09 21:46:50 +02:00
|
|
|
import jp.juggler.util.neatSpaces
|
|
|
|
import jp.juggler.util.notBlank
|
|
|
|
import jp.juggler.util.showToast
|
|
|
|
import jp.juggler.util.vg
|
2018-12-25 12:54:41 +01:00
|
|
|
|
2019-12-15 20:12:57 +01:00
|
|
|
class DlgCreateAccount(
|
2021-06-20 15:12:25 +02:00
|
|
|
val activity: AppCompatActivity,
|
|
|
|
val apiHost: Host,
|
|
|
|
val onClickOk: (
|
|
|
|
dialog: Dialog,
|
|
|
|
username: String,
|
|
|
|
email: String,
|
|
|
|
password: String,
|
|
|
|
agreement: Boolean,
|
|
|
|
reason: String?
|
|
|
|
) -> Unit
|
2019-12-15 20:12:57 +01:00
|
|
|
) : View.OnClickListener {
|
2021-06-20 15:12:25 +02:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
// private val log = LogCategory("DlgCreateAccount")
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams")
|
|
|
|
private val viewRoot = activity.layoutInflater
|
|
|
|
.inflate(R.layout.dlg_account_create, null, false)
|
|
|
|
|
|
|
|
private val etUserName: EditText = viewRoot.findViewById(R.id.etUserName)
|
|
|
|
private val etEmail: EditText = viewRoot.findViewById(R.id.etEmail)
|
|
|
|
private val etPassword: EditText = viewRoot.findViewById(R.id.etPassword)
|
|
|
|
private val cbAgreement: CheckBox = viewRoot.findViewById(R.id.cbAgreement)
|
|
|
|
private val tvDescription: TextView = viewRoot.findViewById(R.id.tvDescription)
|
|
|
|
private val etReason: EditText = viewRoot.findViewById(R.id.etReason)
|
|
|
|
private val tvReasonCaption: TextView = viewRoot.findViewById(R.id.tvReasonCaption)
|
|
|
|
|
|
|
|
private val dialog = Dialog(activity)
|
|
|
|
|
|
|
|
init {
|
|
|
|
viewRoot.findViewById<TextView>(R.id.tvInstance).text = apiHost.pretty
|
|
|
|
|
2021-06-28 09:09:00 +02:00
|
|
|
intArrayOf(
|
2021-06-20 15:12:25 +02:00
|
|
|
R.id.btnRules,
|
|
|
|
R.id.btnTerms,
|
|
|
|
R.id.btnCancel,
|
|
|
|
R.id.btnOk
|
|
|
|
).forEach {
|
|
|
|
viewRoot.findViewById<Button>(it)?.setOnClickListener(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
val instanceInfo = TootInstance.getCached(apiHost)
|
|
|
|
|
|
|
|
tvDescription.text =
|
|
|
|
DecodeOptions(
|
|
|
|
activity,
|
|
|
|
linkHelper = LinkHelper.create(
|
|
|
|
apiHost,
|
|
|
|
misskeyVersion = instanceInfo?.misskeyVersion ?: 0
|
|
|
|
)
|
|
|
|
).decodeHTML(
|
|
|
|
instanceInfo?.short_description?.notBlank()
|
|
|
|
?: instanceInfo?.description?.notBlank()
|
|
|
|
?: TootInstance.DESCRIPTION_DEFAULT
|
|
|
|
).neatSpaces()
|
|
|
|
|
|
|
|
val showReason = instanceInfo?.approval_required ?: false
|
|
|
|
tvReasonCaption.vg(showReason)
|
|
|
|
etReason.vg(showReason)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun show() {
|
|
|
|
dialog.setContentView(viewRoot)
|
|
|
|
|
|
|
|
dialog.window?.setLayout(
|
|
|
|
WindowManager.LayoutParams.MATCH_PARENT,
|
|
|
|
WindowManager.LayoutParams.WRAP_CONTENT
|
|
|
|
)
|
|
|
|
dialog.show()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onClick(v: View?) {
|
|
|
|
when (v?.id) {
|
|
|
|
R.id.btnRules ->
|
|
|
|
activity.openCustomTab("https://$apiHost/about/more")
|
|
|
|
|
|
|
|
R.id.btnTerms ->
|
|
|
|
activity.openCustomTab("https://$apiHost/terms")
|
|
|
|
|
|
|
|
R.id.btnCancel ->
|
|
|
|
dialog.cancel()
|
|
|
|
|
|
|
|
R.id.btnOk -> {
|
|
|
|
val username = etUserName.text.toString().trim()
|
|
|
|
val email = etEmail.text.toString().trim()
|
|
|
|
val password = etPassword.text.toString().trim()
|
|
|
|
|
|
|
|
when {
|
|
|
|
username.isEmpty() ->
|
|
|
|
activity.showToast(true, R.string.username_empty)
|
|
|
|
|
|
|
|
email.isEmpty() ->
|
|
|
|
activity.showToast(true, R.string.email_empty)
|
|
|
|
|
|
|
|
password.isEmpty() ->
|
|
|
|
activity.showToast(true, R.string.password_empty)
|
|
|
|
|
|
|
|
username.contains("/") || username.contains("@") ->
|
|
|
|
activity.showToast(true, R.string.username_not_need_atmark)
|
|
|
|
|
|
|
|
else -> onClickOk(
|
|
|
|
dialog,
|
|
|
|
username,
|
|
|
|
email,
|
|
|
|
password,
|
|
|
|
cbAgreement.isChecked,
|
|
|
|
when (etReason.visibility) {
|
|
|
|
View.VISIBLE -> etReason.text.toString().trim()
|
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-25 12:54:41 +01:00
|
|
|
}
|