diff --git a/app/src/main/java/one/nem/kidshift/MainActivity.java b/app/src/main/java/one/nem/kidshift/MainActivity.java index 3095969..dc0509d 100644 --- a/app/src/main/java/one/nem/kidshift/MainActivity.java +++ b/app/src/main/java/one/nem/kidshift/MainActivity.java @@ -70,6 +70,8 @@ public class MainActivity extends AppCompatActivity { return insets; }); + logger = loggerFactory.create("MainActivity"); + // Check logged in if (userSettings.getAppCommonSetting().isLoggedIn()) { logger.info("User is logged in!"); @@ -111,10 +113,6 @@ public class MainActivity extends AppCompatActivity { drawerLayout.addDrawerListener(actionBarDrawerToggle); actionBarDrawerToggle.syncState(); - logger = loggerFactory.create("MainActivity"); - - logger.info("MainActivity started!"); - BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_nav); // Init navigation diff --git a/build.gradle b/build.gradle index da73d9c..ef4cf7a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,10 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + dependencies { + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.7.7" // TODO: カタログと差異が出ないようにする + } +} + plugins { alias(libs.plugins.androidApplication) apply false id 'com.google.dagger.hilt.android' version '2.44' apply false diff --git a/feature/common/build.gradle b/feature/common/build.gradle index 189aead..1559905 100644 --- a/feature/common/build.gradle +++ b/feature/common/build.gradle @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.androidLibrary) id 'com.google.dagger.hilt.android' + id 'androidx.navigation.safeargs' } android { diff --git a/feature/common/src/main/java/one/nem/kidshift/feature/common/CommonSelectChildFragment.java b/feature/common/src/main/java/one/nem/kidshift/feature/common/CommonSelectChildFragment.java new file mode 100644 index 0000000..ff69520 --- /dev/null +++ b/feature/common/src/main/java/one/nem/kidshift/feature/common/CommonSelectChildFragment.java @@ -0,0 +1,71 @@ +package one.nem.kidshift.feature.common; + +import static androidx.navigation.Navigation.findNavController; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.concurrent.CompletableFuture; + +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; +import one.nem.kidshift.data.ChildData; +import one.nem.kidshift.feature.common.adapter.SelectShowChildListItemAdapter; +import one.nem.kidshift.utils.KSLogger; +import one.nem.kidshift.utils.factory.KSLoggerFactory; + +@AndroidEntryPoint +public class CommonSelectChildFragment extends Fragment { + + @Inject + KSLoggerFactory loggerFactory; + @Inject + ChildData childData; + private KSLogger logger; + + private SelectShowChildListItemAdapter adapter; + + public CommonSelectChildFragment() { + // Required empty public constructor + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + logger = loggerFactory.create("CommonSelectChildFragment"); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_common_select_child, container, false); + + RecyclerView childListRecyclerView = view.findViewById(R.id.selectShowChildListRecyclerView); + childListRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + childData.getChildListDirect().thenAccept(childList -> { + adapter = new SelectShowChildListItemAdapter(childList); + adapter.setCallback(new SelectShowChildListItemAdapter.CompleteButtonClickedCallback() { + @Override + public void onClicked(String taskId) { + // Navigate to CommonHomeFragment with navigation controller and pass the selected child id + findNavController(view).navigate(CommonSelectChildFragmentDirections.actionCommonSelectChildFragmentToCommonHomeFragmentParentChild(taskId)); + } + }); + }).thenRun(() -> { + requireActivity().runOnUiThread(() -> { + childListRecyclerView.setAdapter(adapter); + }); + }); + + return view; + } +} \ No newline at end of file diff --git a/feature/common/src/main/java/one/nem/kidshift/feature/common/adapter/SelectShowChildListItemAdapter.java b/feature/common/src/main/java/one/nem/kidshift/feature/common/adapter/SelectShowChildListItemAdapter.java new file mode 100644 index 0000000..542faf5 --- /dev/null +++ b/feature/common/src/main/java/one/nem/kidshift/feature/common/adapter/SelectShowChildListItemAdapter.java @@ -0,0 +1,75 @@ +package one.nem.kidshift.feature.common.adapter; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +import one.nem.kidshift.feature.common.R; +import one.nem.kidshift.model.ChildModel; + +public class SelectShowChildListItemAdapter extends RecyclerView.Adapter { + + private List childDataList; + private CompleteButtonClickedCallback callback; + + public SelectShowChildListItemAdapter() { + // Empty constructor + } + + public SelectShowChildListItemAdapter(List childDataList) { + this.childDataList = childDataList; + } + + public void setChildDataList(List childDataList) { + this.childDataList = childDataList; + } + + public void setCallback(CompleteButtonClickedCallback callback) { + this.callback = callback; + } + + @NonNull + @Override + public SelectShowChildListItemAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_select_show_child, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull SelectShowChildListItemAdapter.ViewHolder holder, int position) { + ChildModel childData = childDataList.get(position); + holder.childName.setText(childData.getName()); + holder.selectButton.setOnClickListener(v -> { + if (callback != null) { + callback.onClicked(childData.getId()); + } + }); + } + + @Override + public int getItemCount() { + return childDataList == null ? 0 : childDataList.size(); + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + TextView childName; + Button selectButton; + + public ViewHolder(@NonNull android.view.View itemView) { + super(itemView); + childName = itemView.findViewById(R.id.childNameTextView); + selectButton = itemView.findViewById(R.id.selectButton); + } + } + + public interface CompleteButtonClickedCallback { + void onClicked(String taskId); + } +} diff --git a/feature/common/src/main/res/layout/fragment_common_select_child.xml b/feature/common/src/main/res/layout/fragment_common_select_child.xml new file mode 100644 index 0000000..ce7dbdb --- /dev/null +++ b/feature/common/src/main/res/layout/fragment_common_select_child.xml @@ -0,0 +1,30 @@ + + + + + + + \ No newline at end of file diff --git a/feature/common/src/main/res/layout/list_item_select_show_child.xml b/feature/common/src/main/res/layout/list_item_select_show_child.xml new file mode 100644 index 0000000..372ee24 --- /dev/null +++ b/feature/common/src/main/res/layout/list_item_select_show_child.xml @@ -0,0 +1,35 @@ + + + + + + + + +