Merge pull request 'feature/parent_child' (#159) from feature/parent_child into main
Reviewed-on: #159
This commit is contained in:
commit
731c2b8033
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
plugins {
|
||||
alias(libs.plugins.androidLibrary)
|
||||
id 'com.google.dagger.hilt.android'
|
||||
id 'androidx.navigation.safeargs'
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<SelectShowChildListItemAdapter.ViewHolder> {
|
||||
|
||||
private List<ChildModel> childDataList;
|
||||
private CompleteButtonClickedCallback callback;
|
||||
|
||||
public SelectShowChildListItemAdapter() {
|
||||
// Empty constructor
|
||||
}
|
||||
|
||||
public SelectShowChildListItemAdapter(List<ChildModel> childDataList) {
|
||||
this.childDataList = childDataList;
|
||||
}
|
||||
|
||||
public void setChildDataList(List<ChildModel> 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".CommonSelectChildFragment" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="128dp"
|
||||
android:text="使用するお子様を選択"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/selectShowChildListRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginBottom="128dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView2" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,35 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:layout_marginVertical="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="8px"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/childNameTextView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="PLACEHOLDER"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||
|
||||
<!-- ImageButtonに変更? -->
|
||||
<Button
|
||||
android:id="@+id/selectButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="表示" />
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -3,11 +3,24 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/feature_common_parent_child_navigation"
|
||||
app:startDestination="@id/commonHomeFragmentParentChild">
|
||||
app:startDestination="@id/commonSelectChildFragment">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/commonHomeFragmentParentChild"
|
||||
android:name="one.nem.kidshift.feature.common.CommonHomeFragment"
|
||||
android:label="fragment_common_home"
|
||||
tools:layout="@layout/fragment_common_home" />
|
||||
<fragment
|
||||
android:id="@+id/commonSelectChildFragment"
|
||||
android:name="one.nem.kidshift.feature.common.CommonSelectChildFragment"
|
||||
android:label="fragment_common_select_child"
|
||||
tools:layout="@layout/fragment_common_select_child" >
|
||||
<action
|
||||
android:id="@+id/action_commonSelectChildFragment_to_commonHomeFragmentParentChild"
|
||||
app:destination="@id/commonHomeFragmentParentChild" >
|
||||
<argument
|
||||
android:name="childId"
|
||||
app:argType="string" />
|
||||
</action>
|
||||
</fragment>
|
||||
</navigation>
|
Loading…
Reference in New Issue
Block a user