diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/edit/EditFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/edit/EditFragment.java index 80ed8e2..1bc1095 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/edit/EditFragment.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/edit/EditFragment.java @@ -43,113 +43,40 @@ binding = FragmentEditBinding.inflate(inflater, container, false); View root = binding.getRoot(); - TextView textView = binding.textMake; + editViewModel.getWorkJson().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(@Nullable WorkJson workJson) { -// Acanthus acanthus = (Acanthus) getActivity().getApplication(); -// Integer uid = 1; -// String token = "abc0"; -// editViewModel.getWorkList(uid, token); -// aid = new ArrayList<>(); -// //----------------------------------------------------------------- -// //listView -// View layout = inflater.inflate(R.layout.fragment_edit, container, false); -// ListView listView = (ListView) layout.findViewById(R.id.list_view); -// -// editViewModel.getWorkJson().observe(getViewLifecycleOwner(), new Observer() { -// @Override -// public void onChanged(@Nullable WorkJson workJson) { -// textView.setText(workJson.getAid().toString()); -// -// aid = (ArrayList) editViewModel.getWorkJson().getValue().getAid(); -// // BaseAdapter を継承したadapterのインスタンスを生成 -// // レイアウトファイル list.xml を activity_main.xml に -// // inflate するためにadapterに引数として渡す -// BaseAdapter adapter = new WorkListViewAdapter(layout.getContext(), -// R.layout.work_list, aid, aid); -// -// // ListViewにadapterをセット -// listView.setAdapter(adapter); -// -// // クリックリスナーをセット -// //listView.setOnItemClickListener(getActivity()); -// } -// }); + } + }); - //return root; - return inflater.inflate(R.layout.fragment_edit, container, false); + return root; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - super.onActivityCreated(savedInstanceState); - Log.d("CreatedActivity", "EditFragment"); + editViewModel = new ViewModelProvider(this).get(EditViewModel.class); - editViewModel = new ViewModelProvider(this).get(EditViewModel.class); + Acanthus acanthus = (Acanthus) getActivity().getApplication(); + Integer uid = 1; + String token = "abc0"; + editViewModel.getWorkList(uid, token); + aid = new ArrayList<>(); + ListView listView = (ListView) getActivity().findViewById(R.id.list_view); - Acanthus acanthus = (Acanthus) getActivity().getApplication(); - Integer uid = 1; - String token = "abc0"; - editViewModel.getWorkList(uid, token); - aid = new ArrayList<>(); - //----------------------------------------------------------------- - //listView - //View layout = inflater.inflate(R.layout.fragment_edit, container, false); - ListView listView = (ListView) getActivity().findViewById(R.id.list_view); -// BaseAdapter adapter = new WorkListViewAdapter(getActivity(), R.layout.work_list); -// listView.setAdapter(adapter); - - editViewModel.getWorkJson().observe(getViewLifecycleOwner(), new Observer() { - @Override - public void onChanged(@Nullable WorkJson workJson) { - //textView.setText(workJson.getAid().toString()); - - aid = (ArrayList) editViewModel.getWorkJson().getValue().getAid(); - //adapter.setAidList(aid); - // BaseAdapter を継承したadapterのインスタンスを生成 - // レイアウトファイル list.xml を activity_main.xml に - // inflate するためにadapterに引数として渡す - BaseAdapter adapter = new WorkListViewAdapter(getActivity(), - R.layout.work_list, aid, aid); -// ArrayAdapter adapter = new ArrayAdapter<>(getActivity(), R.layout.work_list); -// adapter.add("1"); -// adapter.add("2"); -// adapter.add("3"); - - // ListViewにadapterをセット - listView.setAdapter(adapter); - - // クリックリスナーをセット - //listView.setOnItemClickListener(getActivity()); - } - }); + editViewModel.getWorkJson().observe(getViewLifecycleOwner(), new Observer() { + @Override + public void onChanged(@Nullable WorkJson workJson) { + aid = (ArrayList) editViewModel.getWorkJson().getValue().getAid(); + BaseAdapter adapter = new WorkListViewAdapter(getActivity(), + R.layout.work_list, aid, aid); + listView.setAdapter(adapter); + } + }); } -// @Override -// public void onActivityCreated(Bundle savedInstanceState) { -// super.onActivityCreated(savedInstanceState); -// -// Acanthus acanthus = (Acanthus) getActivity().getApplication(); -// Integer uid = 1; -// String token = "abc0"; -// editViewModel.getWorkList(uid, token); -// try { -// aid = (ArrayList) editViewModel.getWorkJson().getValue().getAid(); -// }catch (ArithmeticException e){ -// -// } -// ListView listView = getActivity().findViewById(R.id.list_view); -// BaseAdapter adapter = new WorkListViewAdapter(getActivity().getApplication(), -// R.layout.work_list, aid, aid); -//// ArrayAdapter arrayAdapter = new ArrayAdapter<>(getActivity().getApplicationContext(), android.R.layout., mmItems); -// listView.setAdapter(adapter); -// } - - //----------------------------------------------------------------- - - //----------------------------------------------------------------- - @Override public void onDestroyView() { @@ -160,42 +87,9 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Button appButton = view.findViewById(R.id.Paint_button); - - // ListView listView = (ListView) view.findViewById(R.id.list_view); Integer uid = 1; String token = "abc0"; editViewModel.getWorkList(uid, token); -// aid = (ArrayList) editViewModel.getWorkJson().getValue().getAid(); -// BaseAdapter を継承したadapterのインスタンスを生成 -// レイアウトファイル list.xml を activity_main.xml に -// inflate するためにadapterに引数として渡す - //final WorkListViewAdapter adapter = new WorkListViewAdapter(this.getContext(), R.layout.work_list); - - // ListViewにadapterをセット - // listView.setAdapter(adapter); - - //editViewModel.getWorkJson().observe(getViewLifecycleOwner(), new Observer() { - // @Override - // public void onChanged(@Nullable WorkJson workJson) { -// textView.setText(workJson.getAid().toString()); - - //aid = (ArrayList) workJson.getAid(); - // BaseAdapter を継承したadapterのインスタンスを生成 - // レイアウトファイル list.xml を activity_main.xml に - // inflate するためにadapterに引数として渡す -// BaseAdapter adapter = new WorkListViewAdapter(getActivity().getApplicationContext(), -// R.layout.work_list, aid, aid); -// -// // ListViewにadapterをセット -// listView.setAdapter(adapter); -// adapter.setAnimationName(aid); -// adapter.setLastUpdate(aid); -// adapter.notifyDataSetChanged(); - - // クリックリスナーをセット - //listView.setOnItemClickListener(getActivity()); - // } - //}); appButton.setOnClickListener(v -> { Acanthus acanthus = (Acanthus) getActivity().getApplication();