diff --git a/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java b/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java index 3ca9851..e46feb8 100644 --- a/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java +++ b/app/src/main/java/com/example/nemophila/MyPageEditorActivity.java @@ -26,15 +26,15 @@ import java.util.List; public class MyPageEditorActivity extends AppCompatActivity { - private String img; + private String icon; //マイページ編集画面の作成 + private ActivityResultLauncher launcher = registerForActivityResult(new ActivityResultContracts.OpenMultipleDocuments(), new ActivityResultCallback>() { @Override public void onActivityResult(List uriList) { if(uriList.size() == 0)return; - String newIcon = new String(Base64.getEncoder().encode(uriList.get(0).toString().getBytes())); - img = newIcon; + icon = new String(Base64.getEncoder().encode(uriList.get(0).toString().getBytes())); } }); @@ -78,15 +78,6 @@ } }); - accountViewModel.getNameLiveData().observe(this, new Observer() { - @Override - public void onChanged(String icon) { - TextView myIcon = (TextView) findViewById(R.id.editName); - myName.setText(name); - nemophila.setName(name); - } - - }); //LiveDataへの購読 accountViewModel.getPwLiveData().observe(this, new Observer() { @Override @@ -106,8 +97,8 @@ } }); - Button selectPictureButton = (Button)findViewById(R.id.selectpicturebutton); - selectPictureButton.setOnClickListener(new View.OnClickListener(){ + ImageButton changeIconButton = (ImageButton)findViewById(R.id.changeIconButton); + changeIconButton.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { launcher.launch(new String[]{"image/*"}); } @@ -135,6 +126,10 @@ if(oldPw!=null && newPw!=null) { accountViewModel.changePw(uid, oldPw, newPw, token); } + if(icon!=null){ + accountViewModel.changeIcon(uid, icon, token); + } + } });