| | package com.example.citrusclient.views; |
---|
| | |
---|
| | import android.content.res.ColorStateList; |
---|
| | import android.graphics.Color; |
---|
| | import android.os.Bundle; |
---|
| | |
---|
| | import androidx.annotation.NonNull; |
---|
| | import androidx.annotation.Nullable; |
---|
| | import androidx.fragment.app.Fragment; |
---|
| | import androidx.lifecycle.MutableLiveData; |
---|
| | import androidx.lifecycle.Observer; |
---|
| | import androidx.lifecycle.ViewModelProvider; |
---|
| | |
---|
| | import android.text.Editable; |
---|
| | import android.view.LayoutInflater; |
---|
| | import android.view.View; |
---|
| | import android.view.ViewGroup; |
---|
| | import android.widget.Button; |
---|
| | import android.widget.EditText; |
---|
| | import android.widget.TextView; |
---|
| | |
---|
| | import com.example.citrusclient.Citrus; |
---|
| | import com.example.citrusclient.R; |
---|
| | import com.example.citrusclient.viewmodels.SettingsViewModel; |
---|
| | import com.example.citrusclient.viewmodels.TodosViewModel; |
---|
| | |
---|
| | /** |
---|
| | * A simple {@link Fragment} subclass. Use the {@link SettingsFragment#newInstance} factory method |
---|
| | * to create an instance of this fragment. |
---|
| |
---|
| | Bundle savedInstanceState) { |
---|
| | // Inflate the layout for this fragment |
---|
| | return inflater.inflate(R.layout.fragment_settings, container, false); |
---|
| | } |
---|
| | |
---|
| | private String accountColor; //色 |
---|
| | @Override |
---|
| | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
---|
| | super.onViewCreated(view, savedInstanceState); |
---|
| | Citrus citrus = (Citrus)(getActivity().getApplication()); |
---|
| | String token = citrus.getToken(); |
---|
| | String accountId = citrus.getAccountId(); |
---|
| | |
---|
| | SettingsViewModel settingsViewModel = new ViewModelProvider(this).get(SettingsViewModel.class); |
---|
| | MutableLiveData<String> accountColor = settingsViewModel.getAccountColorLiveData(); |
---|
| | accountColor.observe(getViewLifecycleOwner(), new Observer<String>() { |
---|
| | @Override |
---|
| | public void onChanged(String accountColor) { |
---|
| | //ここを完成させる |
---|
| | if (accountColor != null){ |
---|
| | settingsViewModel.loadAccountColor(accountId); |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | //accountの色の変更 |
---|
| | |
---|
| | view.findViewById(R.id.icon).setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | AccountColorDialogFragment accountColorDialogFragment = new AccountColorDialogFragment(SettingsFragment.this); |
---|
| | accountColorDialogFragment.show(getActivity().getSupportFragmentManager(),"simple2"); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | |
---|
| | //ユーザネーム変更 |
---|
| | view.findViewById(R.id.UpdateName).setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view2) { |
---|
| | EditText NowPass = (EditText) view.findViewById(R.id.EnterNowPassword); //現在のパスワードを入力する |
---|
| | Editable NowPassEditable = NowPass.getText(); |
---|
| | |
---|
| | EditText NewUsername = (EditText) view.findViewById(R.id.EnterNewUsename); //新しいユーザーネームを入力する |
---|
| | Editable NewIdEditable = NewUsername.getText(); |
---|
| | |
---|
| | TextView textNote1 = (TextView) view.findViewById(R.id.textNotes1); //ユーザネーム変更でパスワードやユーザーネームなどの入力が無かったら入力してと表示する |
---|
| | |
---|
| | |
---|
| | if (NowPassEditable == null ||textNote1 != null) { //現在のパスワードの入力がなかったら |
---|
| | System.out.println("現在のパスワードを正しく入力してください"); |
---|
| | textNote1.setText("現在のパスワードを正しく入力してください!");//画面に表示 |
---|
| | |
---|
| | String nowpass = NowPassEditable.toString().trim(); |
---|
| | //String nowpass = NowPass.getText().toString().trim(); //こっちでもよき |
---|
| | if (nowpass == null || nowpass.length() == 0) { //現在のパスワードの入力がなかったら |
---|
| | System.out.println("現在のパスワードを正しく入力してください"); |
---|
| | } |
---|
| | |
---|
| | } else if(NewIdEditable == null || textNote1 != null){ //新しいユーザーネームの入力が無かったら |
---|
| | System.out.println("新しいユーザネームを正しく入力してください"); |
---|
| | textNote1.setText("新しいユーザネームを正しく入力してください!"); //画面に表示 |
---|
| | |
---|
| | String newUsername = NewIdEditable.toString().trim(); |
---|
| | // String newUsername = newUsername.getText().toString().trim(); //こっちでもよき |
---|
| | if (newUsername == null || newUsername.length() == 0) { //新しいユーザネームの入力がなかったら |
---|
| | System.out.println("新しいユーザネームを正しく入力してください"); |
---|
| | } |
---|
| | |
---|
| | } else { |
---|
| | System.out.println(NowPass); //確認のため |
---|
| | System.out.println(NewUsername); |
---|
| | |
---|
| | String accountId = ((Citrus) getActivity().getApplication()).getAccountId(); |
---|
| | String token = ((Citrus) getActivity().getApplication()).getToken(); |
---|
| | |
---|
| | //SettingsViewModel.createBook(accountId, nowpass, color, publicity, token); //SettingsViewModelを呼ぶ |
---|
| | } |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | |
---|
| | //パスワード変更 |
---|
| | view.findViewById(R.id.UpdatePass).setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view2) { |
---|
| | EditText NowPass = (EditText) view.findViewById(R.id.EnterNowPassword); //現在のパスワードを入力する |
---|
| | Editable NowPassEditable = NowPass.getText(); |
---|
| | |
---|
| | EditText NewPass = (EditText) view.findViewById(R.id.EnterNewPassword); //新しいパスワードを入力する |
---|
| | Editable NewPassEditable = NewPass.getText(); |
---|
| | |
---|
| | TextView textNote2 = (TextView) view.findViewById(R.id.textNotes2); //パスワード変更で入力が足りないとき |
---|
| | |
---|
| | |
---|
| | if (NowPassEditable == null || textNote2 != null) { //現在のパスワードの入力がなかったら |
---|
| | System.out.println("現在のパスワードを正しく入力してください"); |
---|
| | textNote2.setText("現在のパスワードを正しく入力してください!");//画面に表示 |
---|
| | |
---|
| | String nowpass = NowPassEditable.toString().trim(); |
---|
| | //String nowpass = NowPass.getText().toString().trim(); //こっちでもよき |
---|
| | if (nowpass == null || nowpass.length() == 0) { //現在のパスワードの入力がなかったら |
---|
| | System.out.println("現在のパスワードを正しく入力してください"); |
---|
| | } |
---|
| | |
---|
| | } else if(NewPassEditable == null || textNote2 != null){ //新しいパスワードの入力が無かったら |
---|
| | System.out.println("新しいパスワードを正しく入力してください"); |
---|
| | textNote2.setText("新しいパスワードを正しく入力してください!"); //画面に表示 |
---|
| | |
---|
| | String newUsername = NewPassEditable.toString().trim(); |
---|
| | // String newUsername = newUsername.getText().toString().trim(); //こっちでもよき |
---|
| | if (newUsername == null || newUsername.length() == 0) { //新しいユーザネームの入力がなかったら |
---|
| | System.out.println("新しいパスワードを正しく入力してください"); |
---|
| | } |
---|
| | |
---|
| | } else { |
---|
| | System.out.println(NowPass); //確認のため |
---|
| | System.out.println(NewPass); |
---|
| | |
---|
| | String accountId = ((Citrus) getActivity().getApplication()).getAccountId(); |
---|
| | String token = ((Citrus) getActivity().getApplication()).getToken(); |
---|
| | |
---|
| | //SettingsViewModel.createBook(accountId, nowpass, color, publicity, token); //SettingsViewModelを呼ぶ |
---|
| | } |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | // |
---|
| | //textLikes.setText(); |
---|
| | } |
---|
| | |
---|
| | public void returnAccountColor(String iconColor){ |
---|
| | accountColor = iconColor;//createBookの変数colorに入る |
---|
| | |
---|
| | View view = getView(); // FragmentのView |
---|
| | |
---|
| | if (view != null) { |
---|
| | Button iconButton = view.findViewById(R.id.icon); |
---|
| | int parsedColor = Color.parseColor(accountColor); |
---|
| | iconButton.setBackgroundTintList(ColorStateList.valueOf(parsedColor)); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |
---|
| | |