名字修改 及保存
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.ViewGroup
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.ama.core.architecture.appBase.AppViewsFragment
|
||||
import com.ama.core.architecture.appBase.OnFragmentBackgroundListener
|
||||
|
|
@ -48,7 +51,7 @@ class MineFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
|
|||
}
|
||||
|
||||
override fun ViewBinding.initViews() {
|
||||
setOnClickBatch(rlPrivacy, rlVersion, rlFeedback, ivEditName) {
|
||||
setOnClickBatch(rlPrivacy, rlVersion, rlFeedback, ivEditName, ivSaveName) {
|
||||
when (this) {
|
||||
rlPrivacy -> {
|
||||
Router.Privacy.startActivity(requireActivity())
|
||||
|
|
@ -61,20 +64,47 @@ class MineFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
|
|||
}
|
||||
|
||||
ivEditName -> {
|
||||
switchNameEditState(!etAccountName.isVisible)
|
||||
switchNameEditState(true)
|
||||
}
|
||||
|
||||
ivSaveName -> {
|
||||
switchNameEditState(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nameEditRoot.isVisible = false
|
||||
nameNormalRoot.isVisible = true
|
||||
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) {
|
||||
|
||||
|
||||
binding?.let {
|
||||
with(it) {
|
||||
nameEditRoot.isVisible = isEnterEdit
|
||||
nameNormalRoot.isVisible = !isEnterEdit
|
||||
if (isEnterEdit) {
|
||||
etAccountName.setText(tvAccountName.text.toString().trim())
|
||||
} else {
|
||||
|
|
@ -84,10 +114,6 @@ class MineFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(),
|
|||
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_marginTop="10dp">
|
||||
<LinearLayout
|
||||
android:visibility="visible"
|
||||
android:id="@+id/name_normal_root"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
|
|
@ -54,35 +56,78 @@
|
|||
android:layout_gravity="center">
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/tv_account_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textStyle="bold"
|
||||
android:textSize="18sp"
|
||||
android:textColor="#000000"
|
||||
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
|
||||
android:id="@+id/iv_edit_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@mipmap/icon_glod_small"
|
||||
android:src="@mipmap/my_edit"
|
||||
android:layout_marginStart="5dp"
|
||||
/>
|
||||
</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>
|
||||
|
||||
</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