feature/updateupdate #138

Merged
Fujimatsu merged 4 commits from feature/updateupdate into main 2024-07-06 02:11:16 +00:00
7 changed files with 223 additions and 89 deletions

View File

@ -0,0 +1,43 @@
package one.nem.kidshift.feature.parent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import one.nem.kidshift.model.ChildModel;
public class ChildListAdapter2 extends RecyclerView.Adapter<ChildListAdapter2.MainViewHolder> {
private final List<ChildModel> childDataList;
ChildListAdapter2(List<ChildModel> childDataList){this.childDataList = childDataList;}
static class MainViewHolder extends RecyclerView.ViewHolder{
TextView actchildname;
MainViewHolder(@NonNull View itemView){
super(itemView);
actchildname = itemView.findViewById(R.id.actchildname);
}
}
@NonNull
@Override
public MainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_act_child_name,parent,false);
return new MainViewHolder(view);
}
public void onBindViewHolder(@NonNull MainViewHolder holder,int position){
ChildModel childData = this.childDataList.get(position);
holder.actchildname.setText(childData.getName());
}
public int getItemCount(){ return childDataList.size();}
}

View File

@ -3,6 +3,7 @@ package one.nem.kidshift.feature.parent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -15,20 +16,37 @@ import one.nem.kidshift.model.tasks.TaskItemModel;
public class ParentAdapter extends RecyclerView.Adapter<ParentAdapter.MainViewHolder> { public class ParentAdapter extends RecyclerView.Adapter<ParentAdapter.MainViewHolder> {
private final List<TaskItemModel> taskDataList; public interface CompleteButtonClickedCallback {
void onClicked(String taskId);
}
ParentAdapter(List<TaskItemModel> taskDataList) { this.taskDataList = taskDataList; } private List<TaskItemModel> taskDataList;
private CompleteButtonClickedCallback callback;
// ParentAdapter(List<TaskItemModel> taskDataList) { this.taskDataList = taskDataList; }
ParentAdapter(){
}
public void setTaskDataList(List<TaskItemModel> taskDataList){
this.taskDataList = taskDataList;
}
public void setCallback(CompleteButtonClickedCallback callback) {
this.callback = callback;
}
static class MainViewHolder extends RecyclerView.ViewHolder{ static class MainViewHolder extends RecyclerView.ViewHolder{
TextView taskTitle; TextView taskTitle;
TextView taskContents; TextView taskContents;
Button completedButton;
MainViewHolder(@NonNull View itemView){ MainViewHolder(@NonNull View itemView){
super(itemView); super(itemView);
taskTitle = itemView.findViewById(R.id.task_title_text_view); taskTitle = itemView.findViewById(R.id.task_title_text_view);
taskContents = itemView.findViewById(R.id.task_contents_text_view); taskContents = itemView.findViewById(R.id.task_contents_text_view);
completedButton = itemView.findViewById(R.id.actbutton);
} }
} }
@ -43,10 +61,13 @@ public class ParentAdapter extends RecyclerView.Adapter<ParentAdapter.MainViewHo
TaskItemModel taskData = this.taskDataList.get(position); TaskItemModel taskData = this.taskDataList.get(position);
holder.taskTitle.setText(taskData.getName()); holder.taskTitle.setText(taskData.getName());
holder.taskContents.setText(Long.toString(taskData.getReward())); holder.taskContents.setText(Long.toString(taskData.getReward()));
holder.completedButton.setOnClickListener(v -> {
this.callback.onClicked(taskData.getId());
});
} }
@Override @Override
public int getItemCount(){ public int getItemCount(){
return taskDataList.size(); return taskDataList == null ? 0 : taskDataList.size();
} }
} }

View File

@ -13,6 +13,8 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -25,20 +27,15 @@ import dagger.hilt.android.AndroidEntryPoint;
import one.nem.kidshift.data.ChildData; import one.nem.kidshift.data.ChildData;
import one.nem.kidshift.data.TaskData; import one.nem.kidshift.data.TaskData;
import one.nem.kidshift.model.ChildModel; import one.nem.kidshift.model.ChildModel;
import one.nem.kidshift.model.callback.ChildModelCallback;
import one.nem.kidshift.model.callback.TaskItemModelCallback; import one.nem.kidshift.model.callback.TaskItemModelCallback;
import one.nem.kidshift.model.tasks.TaskItemModel; import one.nem.kidshift.model.tasks.TaskItemModel;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
@AndroidEntryPoint @AndroidEntryPoint
public class ParentMainFragment extends Fragment { public class ParentMainFragment extends Fragment {
@Inject @Inject
KSLoggerFactory loggerFactory; KSLogger ksLogger;
private KSLogger ksLogger;
@Inject @Inject
TaskData taskData; TaskData taskData;
@Inject @Inject
@ -47,8 +44,11 @@ public class ParentMainFragment extends Fragment {
ParentAdapter parentAdapter; ParentAdapter parentAdapter;
SwipeRefreshLayout swipeRefreshLayout; SwipeRefreshLayout swipeRefreshLayout;
@SuppressLint("DatasetChange") @SuppressLint("DatasetChange")
private void updateTaskInfo(){ private void updateTaskInfo(){
swipeRefreshLayout.setRefreshing(true);
taskData.getTasks(new TaskItemModelCallback() { taskData.getTasks(new TaskItemModelCallback() {
@Override @Override
public void onUnchanged() { public void onUnchanged() {
@ -65,6 +65,7 @@ public class ParentMainFragment extends Fragment {
} }
}).thenAccept(taskItemModel -> { }).thenAccept(taskItemModel -> {
parentAdapter.setTaskDataList(taskItemModel);
requireActivity().runOnUiThread(()->{ requireActivity().runOnUiThread(()->{
parentAdapter.notifyDataSetChanged(); parentAdapter.notifyDataSetChanged();
}); });
@ -77,45 +78,7 @@ public class ParentMainFragment extends Fragment {
// Required empty public constructor // Required empty public constructor
} }
@Override @SuppressLint("MissingInflatedId")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ksLogger = loggerFactory.create("ParentMain");
}
private void dataRefresh(){
swipeRefreshLayout = requireView().findViewById(R.id.swipe_refresh_layout);
swipeRefreshLayout.setRefreshing(true);
RecyclerView recyclerView =requireView().findViewById(R.id.main_recycle_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
List<TaskItemModel> task = taskData.getTasks(new TaskItemModelCallback() {
@Override
public void onUnchanged() {
// TODO
}
@Override
public void onUpdated(List<TaskItemModel> taskItem) {
// TODO
}
@Override
public void onFailed(String message) {
// TODO
}
}).join();
RecyclerView.Adapter mainAdapter = new ParentAdapter(task);
recyclerView.setAdapter(mainAdapter);
swipeRefreshLayout.setRefreshing(false);
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -124,6 +87,58 @@ public class ParentMainFragment extends Fragment {
//タスク一覧表示 //タスク一覧表示
View view = inflater.inflate(R.layout.fragment_parent_main, container, false); View view = inflater.inflate(R.layout.fragment_parent_main, container, false);
swipeRefreshLayout = view.findViewById(R.id.swipe_refresh_layout);
RecyclerView recyclerView = view.findViewById(R.id.main_recycle_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
parentAdapter = new ParentAdapter();
parentAdapter.setCallback(new ParentAdapter.CompleteButtonClickedCallback() {
@Override
public void onClicked(String taskId) {
Toast.makeText(requireContext(), "TaskID: " + taskId, Toast.LENGTH_LONG).show();
//お手伝い完了処理
LayoutInflater inflater2 = requireActivity().getLayoutInflater();
View view2 = inflater2.inflate(R.layout.act_child_select_dialog,null);
//子供一覧表示
RecyclerView recyclerView2 = view2.findViewById(R.id.act_recycle_view);
recyclerView2.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager2 = new LinearLayoutManager(getContext());
recyclerView2.setLayoutManager(layoutManager2);
List<ChildModel> child1 = childData.getChildList().join();
RecyclerView.Adapter mainAdapter2 = new ChildListAdapter2(child1);
recyclerView2.setAdapter(mainAdapter2);
MaterialAlertDialogBuilder builder1 = new MaterialAlertDialogBuilder(getContext());
builder1.setTitle("お手伝いをしたお子様の名前を選択してください")
.setView(view2)
.setNeutralButton("閉じる",null);
builder1.create().show();
}
});
recyclerView.setAdapter(parentAdapter);
updateTaskInfo();
//Pull-to-refreshスワイプで更新
try {
swipeRefreshLayout.setOnRefreshListener(() ->{
updateTaskInfo();
});
} catch (Exception e){
}
//お手伝い追加ダイアログ //お手伝い追加ダイアログ
LayoutInflater inflater1 = requireActivity().getLayoutInflater(); LayoutInflater inflater1 = requireActivity().getLayoutInflater();
View view1 = inflater1.inflate(R.layout.add_task_list_dialog,null); View view1 = inflater1.inflate(R.layout.add_task_list_dialog,null);
@ -136,23 +151,10 @@ public class ParentMainFragment extends Fragment {
RecyclerView.LayoutManager layoutManager1 = new LinearLayoutManager(getContext()); RecyclerView.LayoutManager layoutManager1 = new LinearLayoutManager(getContext());
recyclerView1.setLayoutManager(layoutManager1); recyclerView1.setLayoutManager(layoutManager1);
ksLogger.debug("子供一覧取得開始"); ksLogger.debug("子供一覧取得開始");
List<ChildModel> child = childData.getChildList(new ChildModelCallback() { List<ChildModel> child = childData.getChildList().join();
@Override
public void onUnchanged() {
}
@Override
public void onUpdated(List<ChildModel> childModelList) {
}
@Override
public void onFailed(String message) {
}
}).join();
ksLogger.debug("子供一覧取得完了"); ksLogger.debug("子供一覧取得完了");
RecyclerView.Adapter mainAdapter1 = new ChildListAdapter(child); RecyclerView.Adapter mainAdapter1 = new ChildListAdapter(child);
@ -176,10 +178,6 @@ public class ParentMainFragment extends Fragment {
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
// Do something... // Do something...
SwipeRefreshLayout swipeRefreshLayout = view.findViewById(R.id.swipe_refresh_layout);
swipeRefreshLayout.setOnRefreshListener(()->{
dataRefresh();
});
} }
} }

View File

@ -0,0 +1,18 @@
<?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">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/act_recycle_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,31 @@
<?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">
<TextView
android:id="@+id/actchildname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:text="TextView"
android:textSize="14dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.517" />
<Button
android:id="@+id/selectChild"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="30dp"
android:text="完了"
android:textSize="14dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,19 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="12dp"> android:layout_margin="12dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/textContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView <TextView
android:id="@+id/task_title_text_view" android:id="@+id/task_title_text_view"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="12dp" android:layout_marginStart="12dp"
android:text="お手伝い名" android:text="お手伝い名"
android:textSize="24dp" android:textSize="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -21,11 +26,26 @@
android:id="@+id/task_contents_text_view" android:id="@+id/task_contents_text_view"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginStart="12dp"
android:layout_marginTop="13dp"
android:text="円/回" android:text="円/回"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/task_title_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0">
<Button
android:id="@+id/actbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="完了"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/task_title_text_view" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/task_title_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

View File

@ -11,6 +11,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -58,6 +59,7 @@ public class SettingMainFragment extends Fragment {
SettingAdapter mainAdapter; SettingAdapter mainAdapter;
SwipeRefreshLayout swipeRefreshLayout; SwipeRefreshLayout swipeRefreshLayout;
public SettingMainFragment() { public SettingMainFragment() {
// Required empty public constructor // Required empty public constructor
} }
@ -260,6 +262,7 @@ public class SettingMainFragment extends Fragment {
} }
}); });
return view; return view;
} }