MyPageEditorActivityのレイアウトと少しのバグを修正しておきました #263

Merged a-oshimo merged 1 commit into nitta-lab-2023:master from nitta-lab-2023:MyPageEditor_Icon on 5 Oct 2023
Showing 3 changed files
View
121
app/src/main/java/com/example/nemophila/MyPageEditorActivity.java
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
 
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import java.util.List;
 
public class MyPageEditorActivity extends AppCompatActivity {
private String icon;
private Nemophila nemophila;
private String uid;
private String token;
 
//マイページ編集画面の作成
 
private ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.OpenDocument(), new ActivityResultCallback<Uri>() {
@Override
public void onActivityResult(Uri uri) {
 
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_page_editor);
 
//LiveDataへの購読
AccountViewModel accountViewModel = new ViewModelProvider(this).get(AccountViewModel.class);
Nemophila nemophila = (Nemophila) getApplication();
String name = nemophila.getName();
EditText myName = (EditText) findViewById(R.id.editName);
myName.setText(name);
nemophila = (Nemophila) getApplication();
uid = nemophila.getUid();
token = nemophila.getToken();
 
//MyPageに戻るボタン
ImageButton backButton = (ImageButton) findViewById(R.id.backMyPage);
backButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MyPageEditorActivity.this, MyPageActivity.class);
startActivity(intent);
}
});
backButton.setOnClickListener(v -> finish());
 
//LiveDataへの購読
accountViewModel.getNameLiveData().observe(this, new Observer<String>() {
@Override
public void onChanged(String name) {
TextView myName = (TextView) findViewById(R.id.editName);
myName.setText(name);
nemophila.setName(name);
}
});
 
});
accountViewModel.getNameLiveData().observe(this, new Observer<String>() {
@Override
public void onChanged(String name) {
TextView myName = (TextView) findViewById(R.id.editName);
myName.setText(name);
nemophila.setName(name);
}
 
});
//LiveDataへの購読
accountViewModel.getPwLiveData().observe(this, new Observer<String>() {
@Override
public void onChanged(String Pw) {
Intent intent = new Intent(MyPageEditorActivity.this, MyPageActivity.class);
startActivity(intent);
finish();
}
 
});
//LiveDataへの購読
EditText editNewPw = (EditText) findViewById(R.id.editNewPw);
String newPw = editNewPw.getText().toString();
 
//Nemophilaから(id)(token)をgetしてaccountViewModelに送る
String uid = nemophila.getUid();
String token = nemophila.getToken();
if(newName!=null) {
if(newName.length() > 0) {
System.out.println(newName);
accountViewModel.changeName(uid, newName, token);
}
if(oldPw!=null && newPw!=null) {
if(oldPw.length() > 0 && newPw.length() > 0) {
accountViewModel.changePw(uid, oldPw, newPw, token);
}
if(icon!=null){
accountViewModel.changeIcon(uid, icon, token);
 
}
});
 
//削除ボタンを押したときの処理
// ログアウトボタンを押したときの処理
Button logoutButton = (Button) findViewById(R.id.logoutButton);
logoutButton.setOnClickListener(v -> {
new AlertDialog.Builder(this)
.setTitle("本当にログアウトしますか?")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
nemophila.logout();
Intent intent = new Intent(MyPageEditorActivity.this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
})
.setNeutralButton("キャンセル", null)
.create()
.show();
});
 
// 削除ボタンを押したときの処理
Button deleteAccountButton = (Button) findViewById(R.id.deleteAccount);
deleteAccountButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String uid = nemophila.getUid();
String token = nemophila.getToken();
accountViewModel.deleteAccount(uid,token);
Intent intent = new Intent(MyPageEditorActivity.this, SignUpActivity.class);
startActivity(intent);
}
deleteAccountButton.setOnClickListener(v -> {
new AlertDialog.Builder(this)
.setTitle("本当に削除しますか?")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// accountViewModel.deleteAccount(uid, token);
// Intent intent = new Intent(MyPageEditorActivity.this, SignUpActivity.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
}
})
.setNeutralButton("キャンセル", null)
.create()
.show();
});
}
}
View
6
app/src/main/res/drawable/ic_backpage.xml 0 → 100644
<vector android:height="24dp" android:tint="#48A8EC"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M21,11H6.83l3.58,-3.59L9,6l-6,6 6,6 1.41,-1.41L6.83,13H21z"/>
</vector>
View
420
app/src/main/res/layout/activity_my_page_editor.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyPageEditorActivity">
 
<EditText
android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toTopOf="@+id/editOldPw"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.833" />
 
<EditText
android:id="@+id/editOldPw"
android:layout_width="220dp"
android:layout_height="63dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:hint="前のパスワード"
android:inputType="textPersonName"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.622" />
 
<EditText
android:id="@+id/editNewPw"
android:layout_width="240dp"
android:layout_height="62dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:ems="10"
android:hint="新しいパスワード"
android:inputType="textPersonName"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editOldPw"
app:layout_constraintVertical_bias="0.0" />
 
<Button
android:id="@+id/changeConfirm"
android:layout_width="116dp"
android:layout_height="78dp"
android:text="変更を確定"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editNewPw"
app:layout_constraintVertical_bias="0.244" />
 
<Button
android:id="@+id/deleteAccount"
android:layout_width="117dp"
android:layout_height="59dp"
android:text="アカウントの削除"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/changeConfirm"
app:layout_constraintVertical_bias="0.237" />
 
<TextView
android:id="@+id/mokuji"
android:layout_width="195dp"
android:layout_height="28dp"
android:text="マイページ編集"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/editName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.578"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.154" />
 
<TextView
android:id="@+id/changeName"
android:layout_width="261dp"
android:layout_height="43dp"
android:text="下に変更したい名前を入力してください"
app:layout_constraintBottom_toTopOf="@+id/editName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mokuji"
app:layout_constraintVertical_bias="1.0" />
 
<TextView
android:id="@+id/changepw"
android:layout_width="228dp"
android:layout_height="51dp"
android:text="前のパスワードを入力して新しい パスワードを入力してください"
app:layout_constraintBottom_toBottomOf="@+id/editOldPw"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editName"
app:layout_constraintVertical_bias="0.149" />
 
<ImageButton
android:id="@+id/backMyPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="戻る"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.95"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.023"
android:background="@drawable/circle_button"
android:src="@drawable/ic_baseline_replay_24"
android:scaleType="fitCenter"
android:padding="7dp"
/>
 
<ImageButton
android:id="@+id/changeIconButton"
android:layout_width="90dp"
android:layout_height="91dp"
android:scaleType="fitXY"
app:layout_constraintBottom_toTopOf="@+id/changeDefaultbutton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mokuji"
app:layout_constraintVertical_bias="0.695"
tools:srcCompat="@tools:sample/avatars" />
 
<Button
android:id="@+id/changeDefaultbutton"
android:layout_width="230dp"
android:layout_height="35dp"
android:text="デフォルト画像に戻す"
app:layout_constraintBottom_toTopOf="@+id/changeName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mokuji"
app:layout_constraintVertical_bias="1.0" />
 
</androidx.constraintlayout.widget.ConstraintLayout>
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
 
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05" />
 
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="horizontal">
 
<ImageButton
android:id="@+id/backMyPage"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:backgroundTint="#00000000"
android:src="@drawable/ic_backpage"/>
 
<TextView
android:id="@+id/mokuji"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:text="マイページ編集"
android:gravity="center"
android:autoSizeTextType="uniform"
android:autoSizeMaxTextSize="25dp"/>
 
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2" />
</LinearLayout>
 
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.025" />
 
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="horizontal" >
 
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.35" />
 
<ImageButton
android:id="@+id/changeIconButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3" />
 
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.35" />
</LinearLayout>
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1">
 
<Button
android:id="@+id/changeDefaultButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="デフォルト画像に戻す"
android:layout_gravity="center"/>
</FrameLayout>
 
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05" />
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05">
 
<TextView
android:id="@+id/changeName"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="名前を変更したい場合は下に入力してください"
android:layout_gravity="center"/>
</FrameLayout>
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1">
 
<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="新しい名前"
android:layout_gravity="center"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"/>
</FrameLayout>
 
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05" />
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05" >
 
<TextView
android:id="@+id/changePw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="パスワードを変更したい場合は下に入力してください"
android:gravity="center"
android:layout_gravity="center"/>
</FrameLayout>
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1">
 
<EditText
android:id="@+id/editOldPw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:hint="前のパスワード"
android:layout_gravity="center"/>
</FrameLayout>
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="horizontal">
 
<EditText
android:id="@+id/editNewPw"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:hint="新しいパスワード"
android:layout_gravity="center"/>
</FrameLayout>
 
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05" />
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >
 
<Button
android:id="@+id/changeConfirm"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="変更を確定"
android:layout_gravity="center"/>
</FrameLayout>
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >
 
<Button
android:id="@+id/logoutButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="ログアウト"
android:layout_gravity="center"/>
</FrameLayout>
 
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1" >
 
<Button
android:id="@+id/deleteAccount"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="アカウントの削除"
android:layout_gravity="center"/>
</FrameLayout>
 
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.05" />
</LinearLayout>