package com.tejia.lijin.app.ui.mine;
|
|
import android.content.SharedPreferences;
|
import android.os.Bundle;
|
import android.text.Editable;
|
import android.text.TextWatcher;
|
import android.view.View;
|
import android.widget.EditText;
|
import android.widget.ImageView;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.app.hubert.guide.util.ScreenUtils;
|
import com.tejia.lijin.app.ShoppingApplication;
|
import com.tejia.lijin.app.util.user.UserUtil;
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.ui.BaseActivity;
|
import com.tejia.lijin.app.util.TopStatusSettings;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
/**
|
* 修改用户昵称
|
*/
|
public class MyNickName extends BaseActivity implements View.OnClickListener {
|
private TextView tv_left, tv_middle;
|
private TextView tv_top_bar_right;
|
private EditText mynickanme_memoName;//昵称 输入框
|
private ImageView mynickanme_clear;//清除昵称
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_mynickanme);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
inint();
|
OnClickListener();
|
}
|
|
|
private void inint() {
|
tv_left = findViewById(R.id.tv_top_bar_left);
|
tv_middle = findViewById(R.id.tv_top_bar_middle);
|
tv_top_bar_right = findViewById(R.id.tv_top_bar_right);
|
mynickanme_memoName = findViewById(R.id.mynickanme_memoName);
|
mynickanme_clear = findViewById(R.id.mynickanme_clear);
|
tv_middle.setText("修改昵称");
|
tv_top_bar_right.setText("保存");
|
// tv_top_bar_right.setVisibility(View.VISIBLE);
|
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) tv_top_bar_right.getLayoutParams();
|
lp.leftMargin = ScreenUtils.dp2px(this, 16);
|
tv_top_bar_right.setLayoutParams(lp);
|
mynickanme_memoName.setHint(getIntent().getStringExtra("name"));
|
}
|
|
private void OnClickListener() {
|
tv_left.setOnClickListener(this);
|
tv_top_bar_right.setOnClickListener(this);
|
mynickanme_clear.setOnClickListener(this);
|
|
mynickanme_memoName.addTextChangedListener(new TextWatcher() {
|
@Override
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
}
|
|
@Override
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
}
|
|
@Override
|
public void afterTextChanged(Editable s) {
|
mynickanme_clear.setVisibility(StringUtils.isEmpty(s.toString())
|
? View.GONE : View.VISIBLE);
|
}
|
});
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
//返回
|
case R.id.tv_top_bar_left:
|
finish();
|
break;
|
case R.id.tv_top_bar_right://保存昵称
|
if (mynickanme_memoName.getText().toString().length() > 0) {
|
saveInfo();
|
} else {
|
Toast.makeText(this, "请输入要修改的昵称", Toast.LENGTH_SHORT).show();
|
}
|
break;
|
case R.id.mynickanme_clear:
|
mynickanme_memoName.getText().clear();//清除文字
|
break;
|
default:
|
break;
|
}
|
}
|
|
/**
|
* 更换昵称
|
*/
|
private void saveInfo() {
|
final SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
|
if (sp.getBoolean("isLogin", false)) {
|
ShoppingApi.saveInfo(this, UserUtil.getUid(ShoppingApplication.application), mynickanme_memoName.getText().toString(), null, null, null, null, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {//修改成功
|
Toast.makeText(MyNickName.this, "修改成功", Toast.LENGTH_SHORT).show();
|
finish();
|
} else if (jsonObject.optInt("code") == 1) {//修改失败
|
Toast.makeText(MyNickName.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
});
|
}
|
}
|
}
|