Merge pull request #141 from nitta-lab-2021/ryotake
ホームフラグメントからアニメーションアクティビティへの遷移の実装
commit d14223591dfb73346245cf638f6f96f4032692c8
2 parents 9389d72 + 4bd58b7
mifunesyunya authored on 21 Jul 2021
Showing 5 changed files
View
61
app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/home/HomeFragment.java
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;
import android.widget.TextView;
import org.ntlab.acanthus_client.R;
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;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
 
public class HomeFragment extends Fragment {
 
private HomeViewModel homeViewModel;
homeViewModel.getAnimationJson().observe(getViewLifecycleOwner(), new Observer<Collection<AnimationJson>>() {
@Override
public void onChanged(Collection<AnimationJson> animationJsons) {
Collection<AnimationJson> animationJsonList = homeViewModel.getGallery();
BaseAdapter adapter = new ListAnimationViewAdapter(getActivity(), R.layout.animation_home, animationJsonList);
//ソート用宣言
ArrayList<String> createDateList = new ArrayList<>();
ArrayList<AnimationJson> 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) {
// acanthus.setCurrentAnimation(homeViewModel.getAnimation(animationJsonSortList.get(position).getAid()));
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);
}
}
View
6
app/src/main/java/org/ntlab/acanthus_client/views/main_menu_ui/home/ListAnimationViewAdapter.java
this.itemLayoutId = itemLayoutId;
for(AnimationJson animationJson: animationJsons){
this.titles.add(animationJson.getAnimationName());
ArrayList<String> editors = new ArrayList<>();
// for(Editor editor: animationJson.getEditor()){
// editors.add(editor.getEditorAccount().getName());
// }
for(String editor: animationJson.getEditorNames()){
editors.add(editor);
}
animationEditors.add(editors);
this.createdDates.add(animationJson.getCreatedDate());
}
}
View
12
app/src/main/res/layout/activity_main.xml
<?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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
 
<fragment
android:id="@+id/nav_host_fragment_activity_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="412dp"
android:layout_height="666dp"
android:layout_marginBottom="4dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
app:navGraph="@navigation/mobile_navigation" />
 
</androidx.constraintlayout.widget.ConstraintLayout>
View
app/src/main/res/layout/animation_home.xml
View
app/src/main/res/layout/fragment_home.xml