feature/manage_child #150
|
@ -31,7 +31,7 @@ public interface ChildData {
|
||||||
* 子ユーザー情報更新
|
* 子ユーザー情報更新
|
||||||
* @param child 子ユーザー情報
|
* @param child 子ユーザー情報
|
||||||
*/
|
*/
|
||||||
void updateChild(ChildModel child);
|
CompletableFuture<ChildModel> updateChild(ChildModel child);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子ユーザー追加
|
* 子ユーザー追加
|
||||||
|
@ -43,7 +43,7 @@ public interface ChildData {
|
||||||
* 子ユーザー削除
|
* 子ユーザー削除
|
||||||
* @param childId 子ID
|
* @param childId 子ID
|
||||||
*/
|
*/
|
||||||
void removeChild(String childId);
|
CompletableFuture<Void> removeChild(String childId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子ユーザーログインコード発行
|
* 子ユーザーログインコード発行
|
||||||
|
|
|
@ -94,8 +94,22 @@ public class ChildDataImpl implements ChildData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
|
@ -118,8 +132,21 @@ public class ChildDataImpl implements ChildData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
|
|
|
@ -126,6 +126,25 @@ public interface KidShiftApiService {
|
||||||
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
|
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
|
||||||
Call<ChildResponse> addChild(@Body ChildAddRequest request);
|
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
|
* @param id 子供ID
|
||||||
|
|
|
@ -2,7 +2,10 @@ package one.nem.kidshift.feature.child;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.print.PrintAttributes;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -43,13 +46,6 @@ public class ChildManageMainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
ChildListAdapter childListAdapter;
|
ChildListAdapter childListAdapter;
|
||||||
|
|
||||||
/* MEMO
|
|
||||||
- ToolBarの設定
|
|
||||||
- タイトル
|
|
||||||
- 戻るボタン
|
|
||||||
- 追加ボタン
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -68,13 +64,13 @@ public class ChildManageMainActivity extends AppCompatActivity {
|
||||||
// タイトル
|
// タイトル
|
||||||
toolbar.setTitle("子供アカウント管理");
|
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.setNavigationOnClickListener(v -> finish());
|
||||||
// 追加ボタン
|
// 追加ボタン
|
||||||
toolbar.inflateMenu(R.menu.child_manage_main_toolbar_item);
|
toolbar.inflateMenu(R.menu.child_manage_main_toolbar_item);
|
||||||
toolbar.setOnMenuItemClickListener(item -> {
|
toolbar.setOnMenuItemClickListener(item -> {
|
||||||
if (item.getItemId() == R.id.add_child_account) {
|
if (item.getItemId() == R.id.add_child_account) {
|
||||||
Toast.makeText(this, "Add button clicked", Toast.LENGTH_SHORT).show();
|
showAddChildDialog();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -85,8 +81,7 @@ public class ChildManageMainActivity extends AppCompatActivity {
|
||||||
childListAdapter.setButtonEventCallback(new ChildListAdapter.ButtonEventCallback() {
|
childListAdapter.setButtonEventCallback(new ChildListAdapter.ButtonEventCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onEditButtonClick(ChildModel childModel) {
|
public void onEditButtonClick(ChildModel childModel) {
|
||||||
Toast.makeText(ChildManageMainActivity.this, "Edit button clicked", Toast.LENGTH_SHORT).show();
|
showEditChildDialog(childModel);
|
||||||
// TODO: 実装
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,6 +111,65 @@ public class ChildManageMainActivity extends AppCompatActivity {
|
||||||
.show();
|
.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")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private void updateList() {
|
private void updateList() {
|
||||||
childData.getChildList(new ChildModelCallback() {
|
childData.getChildList(new ChildModelCallback() {
|
||||||
|
@ -137,4 +191,11 @@ public class ChildManageMainActivity extends AppCompatActivity {
|
||||||
runOnUiThread(() -> childListAdapter.notifyDataSetChanged());
|
runOnUiThread(() -> childListAdapter.notifyDataSetChanged());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
|
private void updateListDirectly() {
|
||||||
|
childData.getChildListDirect().thenAccept(childListAdapter::setChildList).thenRun(() -> {
|
||||||
|
runOnUiThread(() -> childListAdapter.notifyDataSetChanged());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
10
shared/src/main/res/drawable/close_24px.xml
Normal file
10
shared/src/main/res/drawable/close_24px.xml
Normal 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>
|
Loading…
Reference in New Issue
Block a user