| |
---|
| | import android.widget.Button; |
---|
| | import android.widget.TextView; |
---|
| | |
---|
| | import org.ntlab.acanthus_client.R; |
---|
| | import org.ntlab.acanthus_client.databinding.ActivitySignUpBinding; |
---|
| | import org.ntlab.acanthus_client.entities.AccountUidJson; |
---|
| | import org.ntlab.acanthus_client.resources.accounts.AccountsRest; |
---|
| | import org.ntlab.acanthus_client.views.login.LoginScreenActivity; |
---|
| | |
---|
| |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // |
---|
| | public class SignUpActivity extends AppCompatActivity { |
---|
| | //----------------------------------------------------------------- |
---|
| | // 各Viewの列挙型 |
---|
| | public enum EditTexts { |
---|
| | nameForm(0), emailForm(1), passwordForm(2), signUpButton(3), loginButton(4); |
---|
| | |
---|
| | private int textId; |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | private EditTexts(int textId) { |
---|
| | this.textId = textId; |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // getter |
---|
| | public int getTextId() { |
---|
| | return this.textId; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | private ArrayList<TextView> views = new ArrayList<>(); |
---|
| | private ActivitySignUpBinding binding; |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // |
---|
| | @Override |
---|
| | protected void onCreate(Bundle savedInstanceState) { |
---|
| | super.onCreate(savedInstanceState); |
---|
| | setContentView(R.layout.activity_sign_up); |
---|
| | initView(); |
---|
| | init(); |
---|
| | |
---|
| | onClickSignUp(); |
---|
| | onClickAlreadyLoggedIn(); |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | //----------------------------------------------------------------- |
---|
| | // サインアップ時押下時 |
---|
| | private void onClickSignUp() { |
---|
| | Retrofit retrofit = new Retrofit.Builder() |
---|
| | .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/acanthus/") |
---|
| | .addConverterFactory(JacksonConverterFactory.create()) |
---|
| | .build(); |
---|
| | final AccountsRest accountsRest = retrofit.create(AccountsRest.class); |
---|
| | |
---|
| | onClickSignUp(accountsRest); |
---|
| | onClickAlreadyLoggedIn(); |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | //----------------------------------------------------------------- |
---|
| | // サインアップ時押下時 |
---|
| | private void onClickSignUp(AccountsRest accountsRest) { |
---|
| | Button signUpButton = (Button) views.get(EditTexts.signUpButton.getTextId()); |
---|
| | Button signUpButton = (Button) binding.buttonSignUpRegister; |
---|
| | |
---|
| | // |
---|
| | signUpButton.setOnClickListener(v -> { |
---|
| | String name = views.get(EditTexts.nameForm.getTextId()).getText().toString(); |
---|
| | ; |
---|
| | String emailAddress = views.get(EditTexts.emailForm.getTextId()).getText().toString(); |
---|
| | ; |
---|
| | String password = views.get(EditTexts.passwordForm.getTextId()).getText().toString(); |
---|
| | ; |
---|
| | String name = binding.editTextTextSignUpPersonName.getText().toString(); |
---|
| | String emailAddress = binding.editTextTextSignUpEmailAddress.getText().toString(); |
---|
| | String password = binding.editTextTextSignUpPassword.getText().toString(); |
---|
| | |
---|
| | Call<AccountUidJson> call = accountsRest.createAccount(name, emailAddress, password); |
---|
| | call.enqueue(new Callback<AccountUidJson>() { |
---|
| | @Override |
---|
| |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // アカウント所持ボタン押下処理 |
---|
| | private void onClickAlreadyLoggedIn() { |
---|
| | Button alreadyLoggedInButton = (Button) views.get(EditTexts.loginButton.getTextId()); |
---|
| | Button alreadyLoggedInButton = (Button) binding.buttonAlreadyLoggedIn; |
---|
| | |
---|
| | // ログイン画面に遷移 |
---|
| | alreadyLoggedInButton.setOnClickListener(v -> { |
---|
| | transitionLoginActivity(); |
---|
| |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | // 登録内容のクリア |
---|
| | private void clearForm() { |
---|
| | for (int i = EditTexts.nameForm.getTextId(); i <= EditTexts.passwordForm.getTextId(); i++) { |
---|
| | views.get(i).getEditableText().clear(); |
---|
| | } |
---|
| | |
---|
| | binding.editTextTextSignUpPersonName.getEditableText().clear(); |
---|
| | binding.editTextTextSignUpEmailAddress.getEditableText().clear(); |
---|
| | binding.editTextTextSignUpPassword.getEditableText().clear(); |
---|
| | } |
---|
| | |
---|
| | //----------------------------------------------------------------- |
---|
| | //----------------------------------------------------------------- |
---|
| | // |
---|
| | private void initView() { |
---|
| | views.add(findViewById(R.id.editTextTextSignUpPersonName)); |
---|
| | views.add(findViewById(R.id.editTextTextSignUpEmailAddress)); |
---|
| | views.add(findViewById(R.id.editTextTextSignUpPassword)); |
---|
| | views.add(findViewById(R.id.buttonSignUpRegister)); |
---|
| | views.add(findViewById(R.id.buttonAlreadyLoggedIn)); |
---|
| | // 初期化 |
---|
| | private void init() { |
---|
| | setContentView(R.layout.activity_sign_up); |
---|
| | binding = ActivitySignUpBinding.inflate(getLayoutInflater()); |
---|
| | } |
---|
| | //----------------------------------------------------------------- |
---|
| | } |
---|
| | |