mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 13:09:39 -07:00
Update Android Regist UI
This commit is contained in:
parent
4f2e497855
commit
cbc24bd58d
4 changed files with 133 additions and 7 deletions
|
@ -22,6 +22,8 @@ import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.lifecycle.ViewModelProviders
|
||||||
import com.metallic.chiaki.R
|
import com.metallic.chiaki.R
|
||||||
import com.metallic.chiaki.common.ext.RevealActivity
|
import com.metallic.chiaki.common.ext.RevealActivity
|
||||||
import com.metallic.chiaki.lib.RegistInfo
|
import com.metallic.chiaki.lib.RegistInfo
|
||||||
|
@ -41,16 +43,43 @@ class RegistActivity: AppCompatActivity(), RevealActivity
|
||||||
override val revealIntent: Intent get() = intent
|
override val revealIntent: Intent get() = intent
|
||||||
override val revealRootLayout: View get() = rootLayout
|
override val revealRootLayout: View get() = rootLayout
|
||||||
|
|
||||||
|
private lateinit var viewModel: RegistViewModel
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?)
|
override fun onCreate(savedInstanceState: Bundle?)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_regist)
|
setContentView(R.layout.activity_regist)
|
||||||
handleReveal()
|
handleReveal()
|
||||||
|
|
||||||
|
viewModel = ViewModelProviders.of(this).get(RegistViewModel::class.java)
|
||||||
|
|
||||||
hostEditText.setText(intent.getStringExtra(EXTRA_HOST) ?: "255.255.255.255")
|
hostEditText.setText(intent.getStringExtra(EXTRA_HOST) ?: "255.255.255.255")
|
||||||
broadcastCheckBox.isChecked = intent.getBooleanExtra(EXTRA_BROADCAST, true)
|
broadcastCheckBox.isChecked = intent.getBooleanExtra(EXTRA_BROADCAST, true)
|
||||||
|
|
||||||
registButton.setOnClickListener { doRegist() }
|
registButton.setOnClickListener { doRegist() }
|
||||||
|
|
||||||
|
ps4VersionRadioGroup.check(when(viewModel.ps4Version.value ?: RegistViewModel.PS4Version.GE_7) {
|
||||||
|
RegistViewModel.PS4Version.GE_7 -> R.id.ps4VersionGE7RadioButton
|
||||||
|
RegistViewModel.PS4Version.LT_7 -> R.id.ps4VersionLT7RadioButton
|
||||||
|
})
|
||||||
|
|
||||||
|
ps4VersionRadioGroup.setOnCheckedChangeListener { _, checkedId ->
|
||||||
|
viewModel.ps4Version.value = when(checkedId)
|
||||||
|
{
|
||||||
|
R.id.ps4VersionGE7RadioButton -> RegistViewModel.PS4Version.GE_7
|
||||||
|
R.id.ps4VersionLT7RadioButton -> RegistViewModel.PS4Version.LT_7
|
||||||
|
else -> RegistViewModel.PS4Version.GE_7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.ps4Version.observe(this, Observer {
|
||||||
|
psnAccountIdHelpGroup.visibility = if(it == RegistViewModel.PS4Version.GE_7) View.VISIBLE else View.GONE
|
||||||
|
psnIdTextInputLayout.hint = getString(when(it)
|
||||||
|
{
|
||||||
|
RegistViewModel.PS4Version.GE_7 -> R.string.hint_regist_psn_account_id
|
||||||
|
RegistViewModel.PS4Version.LT_7 -> R.string.hint_regist_psn_online_id
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doRegist()
|
private fun doRegist()
|
||||||
|
@ -64,7 +93,15 @@ class RegistActivity: AppCompatActivity(), RevealActivity
|
||||||
val pinValid = pin.length == PIN_LENGTH
|
val pinValid = pin.length == PIN_LENGTH
|
||||||
|
|
||||||
hostEditText.error = if(!hostValid) getString(R.string.regist_host_invalid) else null
|
hostEditText.error = if(!hostValid) getString(R.string.regist_host_invalid) else null
|
||||||
psnIdEditText.error = if(!psnIdValid) getString(R.string.regist_psn_id_invalid) else null
|
psnIdEditText.error =
|
||||||
|
if(!psnIdValid)
|
||||||
|
getString(when(viewModel.ps4Version.value ?: RegistViewModel.PS4Version.GE_7)
|
||||||
|
{
|
||||||
|
RegistViewModel.PS4Version.GE_7 -> R.string.regist_psn_account_id_invalid
|
||||||
|
RegistViewModel.PS4Version.LT_7 -> R.string.regist_psn_online_id_invalid
|
||||||
|
})
|
||||||
|
else
|
||||||
|
null
|
||||||
pinEditText.error = if(!pinValid) getString(R.string.regist_pin_invalid, PIN_LENGTH) else null
|
pinEditText.error = if(!pinValid) getString(R.string.regist_pin_invalid, PIN_LENGTH) else null
|
||||||
|
|
||||||
if(!hostValid || !psnIdValid || !pinValid)
|
if(!hostValid || !psnIdValid || !pinValid)
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Chiaki.
|
||||||
|
*
|
||||||
|
* Chiaki is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Chiaki is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.metallic.chiaki.regist
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
|
class RegistViewModel: ViewModel()
|
||||||
|
{
|
||||||
|
enum class PS4Version {
|
||||||
|
GE_7,
|
||||||
|
LT_7
|
||||||
|
}
|
||||||
|
|
||||||
|
val ps4Version = MutableLiveData<PS4Version>(PS4Version.GE_7)
|
||||||
|
}
|
|
@ -11,7 +11,8 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp">
|
android:padding="16dp"
|
||||||
|
android:animateLayoutChanges="true">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/iconImageView"
|
android:id="@+id/iconImageView"
|
||||||
|
@ -58,16 +59,67 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintTop_toBottomOf="@id/hostTextInputLayout"
|
app:layout_constraintTop_toBottomOf="@id/hostTextInputLayout"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:text="@string/regist_broadcast"/>
|
android:text="@string/regist_broadcast"/>
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/ps4VersionRadioGroup"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/broadcastCheckBox">
|
||||||
|
|
||||||
|
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||||
|
android:id="@+id/ps4VersionGE7RadioButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/regist_option_ps4_ge_7"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:checked="true"/>
|
||||||
|
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||||
|
android:id="@+id/ps4VersionLT7RadioButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/regist_option_ps4_lt_7"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/psnAccountIdHelpTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/ps4VersionRadioGroup"
|
||||||
|
android:text="@string/regist_psn_account_id_help"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:textAppearance="?attr/textAppearanceBody1"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:layout_marginTop="8dp"/>
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/psnAccountIdHelpURLTextView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/psnAccountIdHelpTextView"
|
||||||
|
android:text="@string/regist_psn_account_id_help_url"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:autoLink="web"
|
||||||
|
android:textAppearance="?attr/textAppearanceBody1"/>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Group
|
||||||
|
android:id="@+id/psnAccountIdHelpGroup"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="visible"
|
||||||
|
app:constraint_referenced_ids="psnAccountIdHelpTextView,psnAccountIdHelpURLTextView"/>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/psnIdTextInputLayout"
|
android:id="@+id/psnIdTextInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/hint_regist_psn_id"
|
android:hint="@string/hint_regist_psn_online_id"
|
||||||
app:startIconDrawable="@drawable/ic_psn_id"
|
app:startIconDrawable="@drawable/ic_psn_id"
|
||||||
app:layout_constraintTop_toBottomOf="@id/broadcastCheckBox"
|
app:layout_constraintTop_toBottomOf="@id/psnAccountIdHelpURLTextView"
|
||||||
android:layout_marginTop="16dp">
|
android:layout_marginTop="16dp">
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
android:id="@+id/psnIdEditText"
|
android:id="@+id/psnIdEditText"
|
||||||
|
|
|
@ -20,11 +20,17 @@
|
||||||
<string name="title_regist">Register Console</string>
|
<string name="title_regist">Register Console</string>
|
||||||
<string name="hint_regist_host">Host</string>
|
<string name="hint_regist_host">Host</string>
|
||||||
<string name="regist_broadcast">Broadcast</string>
|
<string name="regist_broadcast">Broadcast</string>
|
||||||
<string name="hint_regist_psn_id">PSN ID (username, case-sensitive)</string>
|
<string name="regist_option_ps4_lt_7">PS4 < 7.0</string>
|
||||||
|
<string name="regist_option_ps4_ge_7">PS4 ≥ 7.0</string>
|
||||||
|
<string name="regist_psn_account_id_help">About obtaining your Account ID, see</string>
|
||||||
|
<string name="regist_psn_account_id_help_url">https://github.com/thestr4ng3r/chiaki/blob/master/README.md#obtaining-your-psn-accountid</string>
|
||||||
|
<string name="hint_regist_psn_online_id">PSN Online ID (username, case-sensitive)</string>
|
||||||
|
<string name="hint_regist_psn_account_id">PSN Account ID (8 bytes, base64)</string>
|
||||||
<string name="hint_regist_pin">PIN</string>
|
<string name="hint_regist_pin">PIN</string>
|
||||||
<string name="action_regist">Register</string>
|
<string name="action_regist">Register</string>
|
||||||
<string name="regist_host_invalid">Please enter a valid host name</string>
|
<string name="regist_host_invalid">Please enter a valid host name</string>
|
||||||
<string name="regist_psn_id_invalid">Please enter a valid PSN ID</string>
|
<string name="regist_psn_online_id_invalid">Please enter a valid PSN ID</string>
|
||||||
|
<string name="regist_psn_account_id_invalid">Please enter a valid 8-byte Account ID in Base64</string>
|
||||||
<string name="regist_pin_invalid">Please enter a valid %d-digit PIN</string>
|
<string name="regist_pin_invalid">Please enter a valid %d-digit PIN</string>
|
||||||
<string name="action_share_log">Share Log</string>
|
<string name="action_share_log">Share Log</string>
|
||||||
<string name="regist_info_success">Regist successful.</string>
|
<string name="regist_info_success">Regist successful.</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue