diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/home/HomeFragment.java b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/home/HomeFragment.java index e2e4397..9bcef62 100644 --- a/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/home/HomeFragment.java +++ b/app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/home/HomeFragment.java @@ -1,10 +1,12 @@ package org.ntlab.acanthus_client.views.main_menu_ui.home; +import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.ListView; @@ -15,6 +17,8 @@ import org.ntlab.acanthus_client.databinding.FragmentHomeBinding; import org.ntlab.acanthus_client.entities.Animation; import org.ntlab.acanthus_client.entities.AnimationJson; +import org.ntlab.acanthus_client.views.animation.AnimationActivity; +import org.ntlab.acanthus_client.views.paint.PaintActivity; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -24,6 +28,8 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; public class HomeFragment extends Fragment { @@ -71,19 +77,48 @@ @Override public void onChanged(Collection animationJsons) { Collection animationJsonList = homeViewModel.getGallery(); - BaseAdapter adapter = new ListAnimationViewAdapter(getActivity(), R.layout.animation_home, animationJsonList); + //ソート用宣言 + ArrayList createDateList = new ArrayList<>(); + ArrayList animationJsonSortList =new ArrayList<>(); + + //ソート処理 + for (AnimationJson animationJson : animationJsonList){ + createDateList.add(animationJson.getCreatedDate()); + } + Collections.sort(createDateList); + Collections.reverse(createDateList); + for (String createDate : createDateList){ + for (AnimationJson animationJson : animationJsonList){ + if (createDate == animationJson.getCreatedDate()){ + animationJsonSortList.add(animationJson); + } + } + } + BaseAdapter adapter = new ListAnimationViewAdapter(getActivity(), R.layout.animation_home, animationJsonSortList); listView.setAdapter(adapter); + + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int position, long id) { + transitionAnimationActivity(animationJsonSortList.get(position)); + + } + }); } }); } - public void onCreateAnimationView(Animation animation){ - } - @Override public void onDestroyView() { super.onDestroyView(); binding = null; } + + private void transitionAnimationActivity(AnimationJson animationJson) { + Acanthus acanthus = (Acanthus) getActivity().getApplication(); + Intent intent = new Intent(acanthus, AnimationActivity.class); + intent.putExtra("AnimationJsonData", animationJson); + startActivity(intent); + } } \ No newline at end of file