|
|
|
@ -1,20 +1,15 @@ |
|
|
|
|
package com.community.pocket.ui.login; |
|
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
|
|
import android.content.Context; |
|
|
|
|
import android.content.Intent; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.text.Editable; |
|
|
|
|
import android.text.TextWatcher; |
|
|
|
|
import android.view.KeyEvent; |
|
|
|
|
import android.view.LayoutInflater; |
|
|
|
|
import android.view.View; |
|
|
|
|
import android.view.inputmethod.EditorInfo; |
|
|
|
|
import android.widget.AdapterView; |
|
|
|
|
import android.widget.Button; |
|
|
|
|
import android.widget.EditText; |
|
|
|
|
import android.widget.ProgressBar; |
|
|
|
|
import android.widget.Spinner; |
|
|
|
|
import android.widget.TextView; |
|
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
@ -24,14 +19,11 @@ import androidx.lifecycle.Observer; |
|
|
|
|
import androidx.lifecycle.ViewModelProvider; |
|
|
|
|
|
|
|
|
|
import com.community.pocket.R; |
|
|
|
|
import com.community.pocket.data.adapter.LocaleAdapter; |
|
|
|
|
import com.community.pocket.ui.BaseActivity; |
|
|
|
|
import com.community.pocket.util.LocalManageUtil; |
|
|
|
|
import com.community.pocket.util.LocaleType; |
|
|
|
|
import com.community.pocket.util.PropertiesUtil; |
|
|
|
|
import com.community.pocket.util.SPUtil; |
|
|
|
|
|
|
|
|
|
import org.xutils.view.annotation.ContentView; |
|
|
|
|
import org.xutils.view.annotation.Event; |
|
|
|
|
import org.xutils.view.annotation.ViewInject; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -43,10 +35,6 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
|
private LoginViewModel loginViewModel; |
|
|
|
|
|
|
|
|
|
//选择语言
|
|
|
|
|
@ViewInject(R.id.selectLang) |
|
|
|
|
private Spinner spinner; |
|
|
|
|
|
|
|
|
|
//用户名
|
|
|
|
|
@ViewInject(R.id.username) |
|
|
|
|
private EditText usernameEditText; |
|
|
|
@ -66,7 +54,6 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
@Override |
|
|
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
|
// setContentView(R.layout.activity_login);
|
|
|
|
|
|
|
|
|
|
loginViewModel = new ViewModelProvider(this, new LoginViewModelFactory()).get(LoginViewModel.class); |
|
|
|
|
|
|
|
|
@ -109,25 +96,6 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//加载语言选项
|
|
|
|
|
spinner.setAdapter(new LocaleAdapter(LayoutInflater.from(this))); |
|
|
|
|
spinner.setSelection(SPUtil.getInstance(getBaseContext()).getSelectLanguage()); |
|
|
|
|
//选择语言事件
|
|
|
|
|
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
|
|
|
|
if (SPUtil.getInstance(getBaseContext()).getSelectLanguage() != position) { |
|
|
|
|
LocaleType locale = LocaleType.getLocale(position); |
|
|
|
|
selectLanguage(locale); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 监听用户密码文本输入框内容改变
|
|
|
|
|
TextWatcher afterTextChangedListener = new TextWatcher() { |
|
|
|
|
@Override |
|
|
|
@ -150,12 +118,20 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
//添加监听器到组件
|
|
|
|
|
usernameEditText.addTextChangedListener(afterTextChangedListener); |
|
|
|
|
passwordEditText.addTextChangedListener(afterTextChangedListener); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//监听密码软键盘输入
|
|
|
|
|
passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { |
|
|
|
|
//登录按钮触发登录请求操作
|
|
|
|
|
@Event(value = R.id.login) |
|
|
|
|
private void login(View v) { |
|
|
|
|
//显示登录请求处理进度
|
|
|
|
|
loadingProgressBar.setVisibility(View.VISIBLE); |
|
|
|
|
loginViewModel.login(usernameEditText.getText().toString(), |
|
|
|
|
passwordEditText.getText().toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
|
|
|
|
//监听密码软键盘输入
|
|
|
|
|
@Event(type = TextView.OnEditorActionListener.class, value = R.id.password) |
|
|
|
|
private boolean onEditorAction(TextView v, int actionId, KeyEvent event) { |
|
|
|
|
//点击完成执行登陆操作
|
|
|
|
|
if (actionId == EditorInfo.IME_ACTION_DONE) { |
|
|
|
|
loginViewModel.login(usernameEditText.getText().toString(), |
|
|
|
@ -164,19 +140,6 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
//默认不执行任何操作
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//登录按钮触发登录请求操作
|
|
|
|
|
loginButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onClick(View v) { |
|
|
|
|
//显示登录请求处理进度
|
|
|
|
|
loadingProgressBar.setVisibility(View.VISIBLE); |
|
|
|
|
loginViewModel.login(usernameEditText.getText().toString(), |
|
|
|
|
passwordEditText.getText().toString()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//登陆成功信息
|
|
|
|
|
private void updateUiWithUser(LoggedInUserView model) { |
|
|
|
@ -190,24 +153,4 @@ public class LoginActivity extends BaseActivity { |
|
|
|
|
Toast.makeText(getApplicationContext(), errorString, Toast.LENGTH_SHORT).show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 选择语言 |
|
|
|
|
* |
|
|
|
|
* @param locale 语言 |
|
|
|
|
*/ |
|
|
|
|
private void selectLanguage(LocaleType locale) { |
|
|
|
|
LocalManageUtil.saveSelectLanguage(this, locale.getType()); |
|
|
|
|
reStart(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 重启 |
|
|
|
|
* |
|
|
|
|
* @param context 应用上下文 |
|
|
|
|
*/ |
|
|
|
|
public static void reStart(Context context) { |
|
|
|
|
Intent intent = new Intent(context, LoginActivity.class); |
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
|
context.startActivity(intent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|