名字修改 及保存
This commit is contained in:
parent
15512e8b30
commit
a9160244b3
|
|
@ -2,12 +2,15 @@ package com.gamedog.vididin.main.fragments
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
|
import androidx.core.widget.addTextChangedListener
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import com.ama.core.architecture.appBase.AppViewsFragment
|
import com.ama.core.architecture.appBase.AppViewsFragment
|
||||||
import com.ama.core.architecture.appBase.OnFragmentBackgroundListener
|
import com.ama.core.architecture.appBase.OnFragmentBackgroundListener
|
||||||
|
|
@ -48,7 +51,7 @@ class MineFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ViewBinding.initViews() {
|
override fun ViewBinding.initViews() {
|
||||||
setOnClickBatch(rlPrivacy, rlVersion, rlFeedback, ivEditName) {
|
setOnClickBatch(rlPrivacy, rlVersion, rlFeedback, ivEditName, ivSaveName) {
|
||||||
when (this) {
|
when (this) {
|
||||||
rlPrivacy -> {
|
rlPrivacy -> {
|
||||||
Router.Privacy.startActivity(requireActivity())
|
Router.Privacy.startActivity(requireActivity())
|
||||||
|
|
@ -61,20 +64,47 @@ class MineFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
|
||||||
}
|
}
|
||||||
|
|
||||||
ivEditName -> {
|
ivEditName -> {
|
||||||
switchNameEditState(!etAccountName.isVisible)
|
switchNameEditState(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
ivSaveName -> {
|
||||||
|
switchNameEditState(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nameEditRoot.isVisible = false
|
||||||
|
nameNormalRoot.isVisible = true
|
||||||
tvAccountName.text = AccountManager.getAccount().userName
|
tvAccountName.text = AccountManager.getAccount().userName
|
||||||
|
|
||||||
|
etAccountName.addTextChangedListener(object : TextWatcher {
|
||||||
|
override fun afterTextChanged(s: Editable?) {
|
||||||
|
tvNameCharactCount.setText("(${s?.length}/15)")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun beforeTextChanged(
|
||||||
|
s: CharSequence?,
|
||||||
|
start: Int,
|
||||||
|
count: Int,
|
||||||
|
after: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTextChanged(
|
||||||
|
s: CharSequence?,
|
||||||
|
start: Int,
|
||||||
|
before: Int,
|
||||||
|
count: Int
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchNameEditState(isEnterEdit: Boolean) {
|
private fun switchNameEditState(isEnterEdit: Boolean) {
|
||||||
|
|
||||||
|
|
||||||
binding?.let {
|
binding?.let {
|
||||||
with(it) {
|
with(it) {
|
||||||
|
nameEditRoot.isVisible = isEnterEdit
|
||||||
|
nameNormalRoot.isVisible = !isEnterEdit
|
||||||
if (isEnterEdit) {
|
if (isEnterEdit) {
|
||||||
etAccountName.setText(tvAccountName.text.toString().trim())
|
etAccountName.setText(tvAccountName.text.toString().trim())
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -84,10 +114,6 @@ class MineFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
|
||||||
AccountManager.updateUserName(newName)
|
AccountManager.updateUserName(newName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
etAccountName.isVisible = isEnterEdit
|
|
||||||
tvAccountName.isVisible = !isEnterEdit
|
|
||||||
ivEditName.setImageResource(if (isEnterEdit) R.mipmap.task_gold else R.mipmap.task_gold)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp">
|
android:layout_marginTop="10dp">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:visibility="visible"
|
||||||
|
android:id="@+id/name_normal_root"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
|
@ -54,35 +56,78 @@
|
||||||
android:layout_gravity="center">
|
android:layout_gravity="center">
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/tv_account_name"
|
android:id="@+id/tv_account_name"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textColor="#000000"
|
android:textColor="#000000"
|
||||||
android:text="Miguel"
|
android:text="Miguel"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatEditText
|
|
||||||
android:id="@+id/et_account_name"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:textColor="#000000"
|
|
||||||
android:text="Miguel"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:maxLength="30"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/iv_edit_name"
|
android:id="@+id/iv_edit_name"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@mipmap/icon_glod_small"
|
android:src="@mipmap/my_edit"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="5dp"
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@+id/name_edit_root"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:layout_gravity="center">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingHorizontal="10dp"
|
||||||
|
android:paddingVertical="5dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:background="@mipmap/my_edit_bg">
|
||||||
|
<androidx.appcompat.widget.AppCompatEditText
|
||||||
|
android:id="@+id/et_account_name"
|
||||||
|
android:layout_width="210dp"
|
||||||
|
android:layout_height="28dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:background="@null"
|
||||||
|
android:textColor="@color/gray6"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:maxLength="15"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:id="@+id/tv_name_charact_count"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="3dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:textColor="@color/gray9"
|
||||||
|
android:text="(0/15)"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/iv_save_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@mipmap/my_confirm"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
Loading…
Reference in New Issue