This commit is contained in:
ろむねこ 2024-07-12 11:13:29 +09:00
parent 48949d3c60
commit 6160eba7ac
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168
4 changed files with 38 additions and 23 deletions

View File

@ -20,13 +20,14 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:background="?attr/colorSurface"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/app_name" />
app:title="@string/app_name"
android:elevation="8dp" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"

View File

@ -43,6 +43,7 @@ import dagger.hilt.android.AndroidEntryPoint;
import one.nem.kidshift.data.ChildData;
import one.nem.kidshift.data.RewardData;
import one.nem.kidshift.data.TaskData;
import one.nem.kidshift.data.UserSettings;
import one.nem.kidshift.feature.common.adapter.ChildListItemAdapter;
import one.nem.kidshift.feature.common.adapter.TaskListItemAdapter;
import one.nem.kidshift.model.callback.TaskItemModelCallback;
@ -74,6 +75,8 @@ public class CommonHomeFragment extends Fragment {
RewardData rewardData;
@Inject
RecyclerViewAnimUtils recyclerViewAnimUtils;
@Inject
UserSettings userSettings;
private boolean isChildMode;
@ -98,9 +101,7 @@ public class CommonHomeFragment extends Fragment {
CommonHomeFragment fragment = new CommonHomeFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_IS_CHILD_MODE, isChildMode);
if (isChildMode) {
args.putString(ARG_CHILD_ID, childId);
}
args.putString(ARG_CHILD_ID, childId);
fragment.setArguments(args);
return fragment;
}
@ -108,16 +109,30 @@ public class CommonHomeFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
isChildMode = getArguments().getBoolean(ARG_IS_CHILD_MODE);
childId = getArguments().getString(ARG_CHILD_ID);
}
logger = ksLoggerFactory.create("CommonHomeFragment");
if (isChildMode) {
logger.info("Child mode, childId: " + childId);
if (userSettings.getAppCommonSetting().isChildMode()) {
logger.debug("子供モードで起動(子供ログイン)");
isChildMode = true;
childId = userSettings.getAppCommonSetting().getChildId();
logger.debug("childId: " + childId);
} else {
logger.info("Parent mode");
if (getArguments() != null) {
isChildMode = getArguments().getBoolean(ARG_IS_CHILD_MODE) && getArguments().getBoolean(ARG_IS_CHILD_MODE);
childId = getArguments().getString(ARG_CHILD_ID) != null ? getArguments().getString(ARG_CHILD_ID) : "";
}
if (childId != null && !childId.isEmpty()) {
isChildMode = true;
}
if (isChildMode) {
logger.debug("子供モードで起動");
logger.debug("childId: " + childId);
} else {
logger.debug("保護者モードで起動");
}
}
}
@ -131,9 +146,7 @@ public class CommonHomeFragment extends Fragment {
taskListItemAdapter = new TaskListItemAdapter();
taskListItemAdapter.setCallback((taskId, taskName) -> {
if (isChildMode) {
if (showConfirmDialog(taskName)) {
taskData.recordTaskCompletion(taskId, childId);
}
showConfirmDialog(taskId, taskName);
} else {
showChildSelectDialog(taskId, taskName);
}
@ -277,24 +290,22 @@ public class CommonHomeFragment extends Fragment {
/**
* タスク完了確認ダイアログを表示 (子供モード用)
*
* @param taskId タスクID
* @param taskName タスク名
* @return OKボタンが押されたかどうか
*/
private boolean showConfirmDialog(String taskName) {
AtomicBoolean selection = new AtomicBoolean(false);
private void showConfirmDialog(String taskId, String taskName) {
new MaterialAlertDialogBuilder(requireContext())
.setTitle("タスクを完了しますか?")
.setMessage(taskName + "を完了しますか?")
.setPositiveButton("はい", (dialog, which) -> {
dialog.dismiss();
selection.set(true);
taskData.recordTaskCompletion(taskId, childId);
})
.setNegativeButton("いいえ", (dialog, which) -> {
dialog.dismiss();
selection.set(false);
taskData.recordTaskCompletion(taskId, childId);
})
.show();
return selection.get();
}
/**

View File

@ -62,9 +62,9 @@ public class CommonSelectChildFragment extends Fragment {
childListRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerViewAnimUtils.setSlideUpAnimation(childListRecyclerView);
adapter = new SelectShowChildListItemAdapter();
adapter.setCallback(taskId -> {
adapter.setCallback(childId -> {
// 静的解析エラーが発生するのになぜか実行はできる
findNavController(view).navigate(CommonSelectChildFragmentDirections.actionCommonSelectChildFragmentToCommonHomeFragmentParentChild(taskId));
findNavController(view).navigate(CommonSelectChildFragmentDirections.actionCommonSelectChildFragmentToCommonHomeFragmentParentChild(childId));
});
CompletableFuture.runAsync(() -> childListRecyclerView.setAdapter(adapter)).thenRun(() -> childData.getChildListDirect().thenAccept(childList -> {
requireActivity().runOnUiThread(() -> {

View File

@ -10,6 +10,9 @@
android:name="one.nem.kidshift.feature.common.CommonHomeFragment"
android:label="fragment_common_home"
tools:layout="@layout/fragment_common_home" >
<argument
android:name="childId"
app:argType="string" />
<argument
android:name="isChildMode"
app:argType="boolean"