[Modify]我的地区功能
This commit is contained in:
@@ -287,6 +287,9 @@ dependencies {
|
||||
|
||||
implementation 'com.github.lihangleo2:ShadowLayout:3.3.2'
|
||||
|
||||
//wheelView
|
||||
implementation 'com.contrarywind:wheelview:4.1.0'
|
||||
|
||||
}
|
||||
|
||||
channel {
|
||||
|
@@ -283,7 +283,10 @@ class UserInfoModifyActivity : BaseViewBindingActivity<ActivityUserInfoModifyBin
|
||||
|
||||
override fun onSuccess(areaList: List<String>) {
|
||||
dialogManager.dismissDialog()
|
||||
UserAreaDialog.newInstance(areaList).show(this@UserInfoModifyActivity)
|
||||
UserAreaDialog.newInstance(areaList)
|
||||
.apply { setAction {
|
||||
reportArea(it)
|
||||
} }.show(this@UserInfoModifyActivity)
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
@@ -300,6 +303,29 @@ class UserInfoModifyActivity : BaseViewBindingActivity<ActivityUserInfoModifyBin
|
||||
}
|
||||
}
|
||||
|
||||
private fun reportArea(area: String) {
|
||||
binding.tvArea.text = area
|
||||
dialogManager.showProgressDialog(
|
||||
this@UserInfoModifyActivity,
|
||||
ResUtil.getString(R.string.ui_user_userinfomodifyactivity_02)
|
||||
)
|
||||
UserModel.get().saveArea(area).subscribe(object : SingleObserver<String> {
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
mCompositeDisposable.add(d)
|
||||
}
|
||||
|
||||
override fun onSuccess(areaList: String) {
|
||||
dialogManager.dismissDialog()
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
dialogManager.dismissDialog()
|
||||
toast(e.message)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int, permissions: Array<out String>, grantResults: IntArray
|
||||
) {
|
||||
|
@@ -0,0 +1,44 @@
|
||||
package com.yizhuan.erban.ui.user.adapter;
|
||||
|
||||
import com.contrarywind.adapter.WheelAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The simple Array wheel adapter
|
||||
* @param <T> the element type
|
||||
*/
|
||||
public class ArrayWheelAdapter<T> implements WheelAdapter {
|
||||
|
||||
|
||||
// items
|
||||
private List<T> items;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param items the items
|
||||
*/
|
||||
public ArrayWheelAdapter(List<T> items) {
|
||||
this.items = items;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int index) {
|
||||
if (index >= 0 && index < items.size()) {
|
||||
return items.get(index);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemsCount() {
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o){
|
||||
return items.indexOf(o);
|
||||
}
|
||||
|
||||
}
|
@@ -1,26 +1,27 @@
|
||||
package com.yizhuan.erban.ui.user.dialog
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.google.android.flexbox.FlexDirection
|
||||
import com.google.android.flexbox.FlexWrap
|
||||
import com.google.android.flexbox.FlexboxLayoutManager
|
||||
import com.google.android.flexbox.JustifyContent
|
||||
import com.yizhuan.erban.R
|
||||
import android.view.Gravity
|
||||
import android.view.WindowManager
|
||||
import com.yizhuan.erban.base.BaseDialog
|
||||
import com.yizhuan.erban.databinding.DialogUserTagBinding
|
||||
import com.yizhuan.erban.ui.user.activity.EditUserTagActivity
|
||||
import com.yizhuan.erban.ui.user.adapter.UserLabelDialogAdapter
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel
|
||||
import com.yizhuan.xchat_android_core.user.UserModel
|
||||
import com.yizhuan.erban.databinding.DialogUserAreaPickerBinding
|
||||
import com.yizhuan.erban.ui.user.adapter.ArrayWheelAdapter
|
||||
import java.io.Serializable
|
||||
|
||||
|
||||
/**
|
||||
* 用户地区
|
||||
* Created by wushaocheng on 2023/2/17.
|
||||
* author: wushaocheng
|
||||
* time: 2022/2/17
|
||||
* desc: 用户地区
|
||||
*/
|
||||
class UserAreaDialog :
|
||||
BaseDialog<DialogUserTagBinding>() {
|
||||
BaseDialog<DialogUserAreaPickerBinding>() {
|
||||
|
||||
private var mOptionsItems: List<String>? = null
|
||||
|
||||
private var mArea: String? = null
|
||||
|
||||
private var mAction: ((String) -> Unit)? = null
|
||||
|
||||
companion object {
|
||||
const val KEY_AREA = "key_area"
|
||||
@@ -35,20 +36,39 @@ class UserAreaDialog :
|
||||
}
|
||||
}
|
||||
|
||||
private val mTagAdapter by lazy { UserLabelDialogAdapter() }
|
||||
override fun onStart() {
|
||||
gravity = Gravity.BOTTOM
|
||||
width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
val areaList = arguments?.getSerializable(KEY_AREA) as List<String?>?
|
||||
|
||||
mOptionsItems = arguments?.getSerializable(KEY_AREA) as List<String>?
|
||||
initListener()
|
||||
setWheelView()
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
binding.ivClose.setOnClickListener { dismissAllowingStateLoss() }
|
||||
|
||||
binding.tvEdit.setOnClickListener {
|
||||
binding.tvCancel.setOnClickListener {
|
||||
dismissAllowingStateLoss()
|
||||
context?.let { it1 -> EditUserTagActivity.start(it1) }
|
||||
}
|
||||
binding.tvSure.setOnClickListener {
|
||||
mArea?.let { area ->
|
||||
dismissAllowingStateLoss()
|
||||
mAction?.invoke(area)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setAction(action: (String) -> Unit) {
|
||||
mAction = action
|
||||
}
|
||||
|
||||
private fun setWheelView() {
|
||||
mOptionsItems?.let {
|
||||
binding.wheelView.setCyclic(false)
|
||||
binding.wheelView.adapter = ArrayWheelAdapter(it)
|
||||
binding.wheelView.setOnItemSelectedListener { index -> mArea = it[index] }
|
||||
}
|
||||
}
|
||||
|
||||
|
13
app/src/main/res/drawable/bg_ffffff_top_18.xml
Normal file
13
app/src/main/res/drawable/bg_ffffff_top_18.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<corners
|
||||
android:bottomLeftRadius="@dimen/dp_0"
|
||||
android:bottomRightRadius="@dimen/dp_0"
|
||||
android:topLeftRadius="@dimen/dp_18"
|
||||
android:topRightRadius="@dimen/dp_18" />
|
||||
|
||||
<solid android:color="@color/color_FFFFFF" />
|
||||
|
||||
</shape>
|
58
app/src/main/res/layout/dialog_user_area_picker.xml
Normal file
58
app/src/main/res/layout/dialog_user_area_picker.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_ffffff_top_18"
|
||||
android:gravity="bottom"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/tv_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dp_15"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:text="@string/cancel"
|
||||
android:textColor="@color/color_B3B3C3"
|
||||
android:textSize="@dimen/sp_16"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/tv_sure"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_20"
|
||||
android:layout_marginEnd="@dimen/dp_15"
|
||||
android:text="@string/sure"
|
||||
android:textColor="@color/color_1F1B4F"
|
||||
android:textSize="@dimen/sp_16"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="190dp">
|
||||
|
||||
<com.contrarywind.view.WheelView
|
||||
android:id="@+id/wheelView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@@ -247,4 +247,9 @@ public interface IUserModel extends IModel {
|
||||
*/
|
||||
Single<List<String>> getAreaInfo();
|
||||
|
||||
/**
|
||||
* 保存地区
|
||||
*/
|
||||
Single<String> saveArea(String area);
|
||||
|
||||
}
|
||||
|
@@ -841,6 +841,13 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<String> saveArea(String area) {
|
||||
return api.saveArea(area)
|
||||
.compose(RxHelper.handleStringData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
private interface Api {
|
||||
/**
|
||||
* 获取某个用户的用户信息
|
||||
@@ -1109,5 +1116,11 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
@GET("/region/config")
|
||||
Single<ServiceResult<List<String>>> getAreaInfo();
|
||||
|
||||
/**
|
||||
* 保存地区
|
||||
*/
|
||||
@POST("/region/save")
|
||||
Single<ServiceResult<String>> saveArea(@Query("region") String region);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user