Merge pull request 'feature/manage_child' (#150) from feature/manage_child into main

Reviewed-on: #150
This commit is contained in:
Fujimatsu 2024-07-08 14:08:49 +00:00
commit d4a07d1b15
5 changed files with 134 additions and 17 deletions

View File

@ -31,7 +31,7 @@ public interface ChildData {
* 子ユーザー情報更新
* @param child 子ユーザー情報
*/
void updateChild(ChildModel child);
CompletableFuture<ChildModel> updateChild(ChildModel child);
/**
* 子ユーザー追加
@ -43,7 +43,7 @@ public interface ChildData {
* 子ユーザー削除
* @param childId 子ID
*/
void removeChild(String childId);
CompletableFuture<Void> removeChild(String childId);
/**
* 子ユーザーログインコード発行

View File

@ -94,8 +94,22 @@ public class ChildDataImpl implements ChildData {
}
@Override
public void updateChild(ChildModel child) {
public CompletableFuture<ChildModel> updateChild(ChildModel child) {
return CompletableFuture.supplyAsync(() -> {
Call<ChildResponse> call = kidShiftApiService.updateChild(ChildModelConverter.childModelToChildAddRequest(child), child.getId());
try {
Response<ChildResponse> response = call.execute();
if (response.isSuccessful()) {
assert response.body() != null;
logger.info("子供更新成功(childId: " + response.body().getId() + ")");
return ChildModelConverter.childResponseToChildModel(response.body());
} else {
throw new RuntimeException("HTTP Status: " + response.code());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
@Override
@ -118,8 +132,21 @@ public class ChildDataImpl implements ChildData {
}
@Override
public void removeChild(String childId) {
public CompletableFuture<Void> removeChild(String childId) {
return CompletableFuture.supplyAsync(() -> {
Call<Void> call = kidShiftApiService.removeChild(childId);
try {
Response<Void> response = call.execute();
if (response.isSuccessful()) {
logger.info("子供削除成功(childId: " + childId + ")");
return null;
} else {
throw new RuntimeException("HTTP Status: " + response.code());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
@Override

View File

@ -126,6 +126,25 @@ public interface KidShiftApiService {
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ChildResponse> addChild(@Body ChildAddRequest request);
/**
* 子供更新
* @param request ChildAddRequest
* @param id 子供ID
* @return ChildResponse
*/
@PUT("/parent/child/{id}")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<ChildResponse> updateChild(@Body ChildAddRequest request, @Path("id") String id);
/**
* 子供削除
* @param id 子供ID
* @return Void
*/
@DELETE("/parent/child/{id}")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<Void> removeChild(@Path("id") String id);
/**
* 子供ログインコード発行
* @param id 子供ID

View File

@ -2,7 +2,10 @@ package one.nem.kidshift.feature.child;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.print.PrintAttributes;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -43,13 +46,6 @@ public class ChildManageMainActivity extends AppCompatActivity {
ChildListAdapter childListAdapter;
/* MEMO
- ToolBarの設定
- タイトル
- 戻るボタン
- 追加ボタン
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -68,13 +64,13 @@ public class ChildManageMainActivity extends AppCompatActivity {
// タイトル
toolbar.setTitle("子供アカウント管理");
// 閉じる
toolbar.setNavigationIcon(one.nem.kidshift.shared.R.drawable.check_24px); // TODO: アイコン修正
toolbar.setNavigationIcon(one.nem.kidshift.shared.R.drawable.close_24px);
toolbar.setNavigationOnClickListener(v -> finish());
// 追加ボタン
toolbar.inflateMenu(R.menu.child_manage_main_toolbar_item);
toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.add_child_account) {
Toast.makeText(this, "Add button clicked", Toast.LENGTH_SHORT).show();
showAddChildDialog();
return true;
}
return false;
@ -85,8 +81,7 @@ public class ChildManageMainActivity extends AppCompatActivity {
childListAdapter.setButtonEventCallback(new ChildListAdapter.ButtonEventCallback() {
@Override
public void onEditButtonClick(ChildModel childModel) {
Toast.makeText(ChildManageMainActivity.this, "Edit button clicked", Toast.LENGTH_SHORT).show();
// TODO: 実装
showEditChildDialog(childModel);
}
@Override
@ -116,6 +111,65 @@ public class ChildManageMainActivity extends AppCompatActivity {
.show();
}
private void showAddChildDialog() {
// EditTextを作成
EditText childNameEditText = new EditText(this);
childNameEditText.setHint("子供の名前");
// FrameLayoutに入れる
FrameLayout container = new FrameLayout(this);
container.addView(childNameEditText);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) childNameEditText.getLayoutParams();
params.setMargins(32, 16, 32, 16);
childNameEditText.setLayoutParams(params);
new MaterialAlertDialogBuilder(this)
.setTitle("子供アカウント追加")
.setView(container)
.setPositiveButton("追加", (dialog, which) -> {
String childName = Objects.requireNonNull(childNameEditText.getText()).toString();
if (childName.isEmpty()) {
Toast.makeText(this, "名前を入力してください", Toast.LENGTH_SHORT).show();
}
childData.addChild(new ChildModel(childName))
.thenRun(this::updateListDirectly);
})
.setNegativeButton("キャンセル", (dialog, which) -> dialog.dismiss())
.show();
}
private void showEditChildDialog(ChildModel childModel) {
// EditTextを作成
EditText childNameEditText = new EditText(this);
childNameEditText.setHint("子供の名前");
childNameEditText.setText(childModel.getName());
// FrameLayoutに入れる
FrameLayout container = new FrameLayout(this);
container.addView(childNameEditText);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) childNameEditText.getLayoutParams();
params.setMargins(32, 16, 32, 16);
childNameEditText.setLayoutParams(params);
new MaterialAlertDialogBuilder(this)
.setTitle("子供アカウント編集")
.setView(container)
.setPositiveButton("保存", (dialog, which) -> {
String childName = Objects.requireNonNull(childNameEditText.getText()).toString();
if (childName.isEmpty()) {
Toast.makeText(this, "名前を入力してください", Toast.LENGTH_SHORT).show();
}
childModel.setName(childName);
childData.updateChild(childModel)
.thenRun(this::updateListDirectly);
})
.setNegativeButton("キャンセル", (dialog, which) -> dialog.dismiss())
// 削除ボタン
.setNeutralButton("削除", (dialog, which) -> { // TODO: 確認ダイアログを表示する
childData.removeChild(childModel.getId())
.thenRun(this::updateListDirectly);
})
.show();
}
@SuppressLint("NotifyDataSetChanged")
private void updateList() {
childData.getChildList(new ChildModelCallback() {
@ -137,4 +191,11 @@ public class ChildManageMainActivity extends AppCompatActivity {
runOnUiThread(() -> childListAdapter.notifyDataSetChanged());
});
}
@SuppressLint("NotifyDataSetChanged")
private void updateListDirectly() {
childData.getChildListDirect().thenAccept(childListAdapter::setChildList).thenRun(() -> {
runOnUiThread(() -> childListAdapter.notifyDataSetChanged());
});
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,522.15L277.08,725.08Q268.77,733.38 256.19,733.58Q243.62,733.77 234.92,725.08Q226.23,716.38 226.23,704Q226.23,691.62 234.92,682.92L437.85,480L234.92,277.08Q226.62,268.77 226.42,256.19Q226.23,243.62 234.92,234.92Q243.62,226.23 256,226.23Q268.38,226.23 277.08,234.92L480,437.85L682.92,234.92Q691.23,226.62 703.81,226.42Q716.38,226.23 725.08,234.92Q733.77,243.62 733.77,256Q733.77,268.38 725.08,277.08L522.15,480L725.08,682.92Q733.38,691.23 733.58,703.81Q733.77,716.38 725.08,725.08Q716.38,733.77 704,733.77Q691.62,733.77 682.92,725.08L480,522.15Z"/>
</vector>