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 2d0e7b1..0cfd53c 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 @@ -31,6 +31,13 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.Map;import java.util.Map.Entry; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + public class EditFragment extends Fragment { @@ -39,7 +46,12 @@ private ArrayList aidList; private ArrayList AnimationJsonList; private ArrayList nameList; + private ArrayList lastUpDateList; + private HashMap nameHashMap; + private HashMap lastUpDateHashMap; + private Integer AnimationAid; private String AnimationName; + private String AnimationLastUpDate; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -66,7 +78,11 @@ editViewModel.getWorkList(uid, token); aidList = new ArrayList<>(); nameList = new ArrayList<>(); + lastUpDateList = new ArrayList<>(); AnimationJsonList = new ArrayList<>(); + Map nameHashMap = new HashMap(); + Map lastUpDateHashMap = new HashMap(); + ListView listView = (ListView) getActivity().findViewById(R.id.list_view); editViewModel.getWorkJson().observe(getViewLifecycleOwner(), new Observer() { @@ -83,14 +99,36 @@ //acanthusのAnimationJsonListにとってきたaidが該当するかを探索する if(aidList.contains(AnimationJsonList.get(i).getAid())){ AnimationName = AnimationJsonList.get(i).getAnimationName(); - nameList.add(AnimationName); + AnimationLastUpDate = AnimationJsonList.get(i).getLastUpdate(); + AnimationAid = AnimationJsonList.get(i).getAid(); + nameHashMap.put(AnimationAid, AnimationName); + lastUpDateHashMap.put(AnimationAid, AnimationLastUpDate); + +// nameList.add(AnimationName); +// lastUpDateList.add(AnimationLastUpDate); workList.add(AnimationJsonList.get(i)); } } } + //-------------------------------------------------------------------------------------------------------------------- + //sort + List> list_entries = new ArrayList>(lastUpDateHashMap.entrySet()); + Collections.sort(list_entries, new Comparator>() { + public int compare(Entry obj1, Entry obj2) { + // 降順(昇順はObj1とObj2を変える) + return obj2.getValue().compareTo(obj1.getValue()); + } + }); + for(Entry entry : list_entries) { + lastUpDateList.add(entry.getValue()); + nameList.add(nameHashMap.get(entry.getKey())); + } + //-------------------------------------------------------------------------------------------------------------------- + + BaseAdapter adapter = new WorkListViewAdapter(getActivity(), - R.layout.work_list, nameList, nameList); + R.layout.work_list, nameList, lastUpDateList); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {