実装 WIP

This commit is contained in:
r-ca 2024-01-22 01:24:55 +09:00
parent 42f6bc17d3
commit 5f9ea732cf
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -3,6 +3,9 @@ package one.nem.lacerta.feature.library;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -15,6 +18,9 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import java.util.ArrayList;
import java.util.List;
@ -22,6 +28,7 @@ import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.data.Document;
import one.nem.lacerta.data.LacertaLibrary;
import one.nem.lacerta.model.document.DocumentMeta;
import one.nem.lacerta.model.document.tag.DocumentTag;
@ -35,36 +42,15 @@ import one.nem.lacerta.model.document.tag.DocumentTag;
@AndroidEntryPoint
public class LibraryTopFragment extends Fragment {
// @Inject
// Document document;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
@Inject
LacertaLibrary lacertaLibrary;
public LibraryTopFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment LibraryTopFragment.
*/
// TODO: Rename and change types and number of parameters
public static LibraryTopFragment newInstance(String param1, String param2) {
public static LibraryTopFragment newInstance() {
LibraryTopFragment fragment = new LibraryTopFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@ -72,10 +58,6 @@ public class LibraryTopFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@ -84,23 +66,52 @@ public class LibraryTopFragment extends Fragment {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_library_top, container, false);
// Use view.findViewById instead of findViewById
RecyclerView documentRecyclerView = view.findViewById(R.id.document_list);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
documentRecyclerView.setLayoutManager(layoutManager);
//データを取得
// List<DocumentMeta> metas = document.getAllDocumentMetas(100);
// Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
// Create and set the adapter
// DocumentAdapter adapter = new DocumentAdapter(metas);
// documentRecyclerView.setAdapter(adapter);
// Use a LinearLayoutManager to specify the layout
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = view.findViewById(R.id.library_item_recycler_view);
ListItemAdapter listItemAdapter = new ListItemAdapter(documentId -> {
Toast.makeText(getContext(), documentId, Toast.LENGTH_SHORT).show();
});
recyclerView.setAdapter(listItemAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> {
listItemAdapter.setLibraryItemPage(libraryItemPage);
getActivity().runOnUiThread(() -> {
listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size());
});
});
CollapsingToolbarLayout collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar);
Toolbar toolbar = view.findViewById(R.id.toolbar);
// Set the Toolbar
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
// Set the title of the CollapsingToolbarLayout
collapsingToolbarLayout.setTitle("Library");
AppBarLayout appBarLayout = view.findViewById(R.id.app_bar_layout);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) {
// Collapsed
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getActivity(), one.nem.lacerta.shared.ui.R.color.colorSecondaryContainer));
} else if (verticalOffset == 0) {
// Expanded
getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(getActivity(), one.nem.lacerta.shared.ui.R.color.colorSurface));
} else {
// Somewhere in between
// Here you can add a color transition if you want
}
}
});
}
}