Merge pull request #84 from lacerta-doc/feature/home/fix

ホーム画面改修
This commit is contained in:
ろむねこ 2024-01-20 15:06:00 +09:00 committed by GitHub
commit a7b92120ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 239 additions and 60 deletions

View File

@ -45,6 +45,9 @@ public class MainActivity extends AppCompatActivity {
} }
// Set navigation bar color // Set navigation bar color
getWindow().setNavigationBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSurfaceVariant)); getWindow().setNavigationBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSecondaryContainer));
// Set status bar color
getWindow().setStatusBarColor(ContextCompat.getColor(this, one.nem.lacerta.shared.ui.R.color.colorSurface));
} }
} }

View File

@ -24,6 +24,11 @@
android:id="@+id/bottom_nav" android:id="@+id/bottom_nav"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorSecondaryContainer"
app:itemIconTint="@color/colorOnSecondaryContainer"
app:itemTextColor="@color/colorOnSecondaryContainer"
app:itemActiveIndicatorStyle="@style/Lacerta.Custom.Indicator"
app:labelVisibilityMode="selected"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

View File

@ -32,4 +32,6 @@ dependencies {
testImplementation libs.junit testImplementation libs.junit
androidTestImplementation libs.androidx.test.ext.junit androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation libs.androidx.test.espresso.core androidTestImplementation libs.androidx.test.espresso.core
implementation project(':shared:ui')
} }

View File

@ -0,0 +1,55 @@
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<ImageView
android:id="@+id/item_icon"
android:layout_width="32dp"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_text_container"
app:srcCompat="@drawable/description_24px"
android:contentDescription="icon" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/item_text_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/item_icon"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/item_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginEnd="8dp"
android:text="Placeholder Title"
android:textColor="@color/colorOnSurface"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/item_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="Placeholder Description"
android:textColor="@color/colorOnSurface"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/item_title" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -11,6 +11,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="16sp" android:textSize="16sp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:text="Placeholder Title"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -19,6 +20,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="14sp" android:textSize="14sp"
android:text="Placeholder Description"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/debug_menu_item_title" /> app:layout_constraintTop_toBottomOf="@+id/debug_menu_item_title" />

View File

@ -55,4 +55,6 @@ dependencies {
implementation project(':model') implementation project(':model')
implementation "androidx.recyclerview:recyclerview:1.3.2" implementation "androidx.recyclerview:recyclerview:1.3.2"
implementation project(':component:common')
} }

View File

@ -3,13 +3,24 @@ package one.nem.lacerta.feature.home;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -34,34 +45,13 @@ public class HomeTopFragment extends Fragment {
@Inject @Inject
LacertaLibrary lacertaLibrary; LacertaLibrary lacertaLibrary;
// 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;
public HomeTopFragment() { public HomeTopFragment() {
// Required empty public constructor // Required empty public constructor
} }
/** public static HomeTopFragment newInstance() {
* 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 HomeTopFragment.
*/
// TODO: Rename and change types and number of parameters
public static HomeTopFragment newInstance(String param1, String param2) {
HomeTopFragment fragment = new HomeTopFragment(); HomeTopFragment fragment = new HomeTopFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
} }
@ -70,49 +60,58 @@ public class HomeTopFragment extends Fragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home_top, container, false); View view = inflater.inflate(R.layout.fragment_home_top, container, false);
// List<DocumentMeta> metas = document.getAllDocumentMetas(100); ArrayList<ListItem> recentDocument = lacertaLibrary.getRecentDocument(10);
ArrayList<ListItem> listItems = lacertaLibrary.getRecentDocument(100); Log.d("docs", Integer.toString(recentDocument.size()));
Log.d("docs", Integer.toString(listItems.size())); RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view);
RecyclerView recyclerView = view.findViewById(R.id.item_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
MyAdapter myAdapter = new MyAdapter(listItems); ListItemAdapter listItemAdapter = new ListItemAdapter(recentDocument);
recyclerView.setAdapter(myAdapter); recyclerView.setAdapter(listItemAdapter);
return view; return view;
} }
String pageTitle;
String pageId;
ArrayList listItems;
String title; @Override
String description; public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
String itemId; 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("Lacerta");
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
}
}
});
}
} }

View File

@ -0,0 +1,59 @@
package one.nem.lacerta.feature.home;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import one.nem.lacerta.model.ListItem;
public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListItemViewHolder>{
ArrayList<ListItem> listItems;
public ListItemAdapter(ArrayList<ListItem> listItems){
this.listItems = listItems;
}
@NonNull
@Override
public ListItemAdapter.ListItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(one.nem.lacerta.component.common.R.layout.common_library_list_item, parent, false);
return new ListItemViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ListItemAdapter.ListItemViewHolder holder, int position) {
ListItem listItem = listItems.get(position);
holder.icon.setImageResource(listItem.getItemType().getIconId());
holder.icon.setColorFilter(one.nem.lacerta.shared.ui.R.color.colorOnSurface);
holder.title.setText(listItem.getTitle());
holder.description.setText(listItem.getDescription());
}
@Override
public int getItemCount() {
return listItems.size();
}
public static class ListItemViewHolder extends RecyclerView.ViewHolder{
ImageView icon;
TextView title;
TextView description;
public ListItemViewHolder(@NonNull View itemView) {
super(itemView);
icon = itemView.findViewById(one.nem.lacerta.component.common.R.id.item_icon);
title = itemView.findViewById(one.nem.lacerta.component.common.R.id.item_title);
description = itemView.findViewById(one.nem.lacerta.component.common.R.id.item_description);
}
}
}

View File

@ -1,21 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".HomeTopFragment" android:background="@color/colorSurface">
tools:ignore="ExtraText">
<androidx.coordinatorlayout.widget.CoordinatorLayout
<!-- TODO: Update blank fragment layout -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/item_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView> <com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
app:contentScrim="@color/colorSecondaryContainer"
android:background="@color/colorSurface"
android:layout_width="match_parent"
android:layout_height="160dp"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:collapsedTitleGravity="start|center_vertical"
app:expandedTitleGravity="start|bottom"
app:expandedTitleMarginBottom="16dp"
app:expandedTitleMarginStart="16dp"
app:expandedTitleTextAppearance="@style/TextAppearance.MaterialComponents.Headline4"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="HOGE" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_item_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</FrameLayout> </FrameLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/item_placeholder"
android:icon="@drawable/developer_mode_24px"
android:title="@string/placeholder" />
</menu>

View File

@ -30,6 +30,7 @@
<item name="colorOnBackground">@color/colorOnBackground</item> <item name="colorOnBackground">@color/colorOnBackground</item>
<item name="android:windowLightNavigationBar">false</item> <item name="android:windowLightNavigationBar">false</item>
<item name="android:windowLightStatusBar">false</item>
</style> </style>
</resources> </resources>

View File

@ -25,4 +25,7 @@
<color name="colorSurfaceVariant">@color/material_dynamic_neutral_variant90</color> <color name="colorSurfaceVariant">@color/material_dynamic_neutral_variant90</color>
<color name="colorOnSurfaceVariant">@color/material_dynamic_neutral_variant30</color> <color name="colorOnSurfaceVariant">@color/material_dynamic_neutral_variant30</color>
<color name="colorSurfaceInverse">@color/material_dynamic_neutral20</color> <color name="colorSurfaceInverse">@color/material_dynamic_neutral20</color>
<!-- indicator icon background -->
<color name="colorIndicator">@color/material_dynamic_secondary70</color>
</resources> </resources>

View File

@ -24,4 +24,7 @@
<color name="colorSurfaceVariant">@color/material_dynamic_neutral_variant90</color> <color name="colorSurfaceVariant">@color/material_dynamic_neutral_variant90</color>
<color name="colorOnSurfaceVariant">@color/material_dynamic_neutral_variant30</color> <color name="colorOnSurfaceVariant">@color/material_dynamic_neutral_variant30</color>
<color name="colorSurfaceInverse">@color/material_dynamic_neutral20</color> <color name="colorSurfaceInverse">@color/material_dynamic_neutral20</color>
<!-- indicator icon background -->
<color name="colorIndicator">@color/material_dynamic_secondary80</color>
</resources> </resources>

View File

@ -30,6 +30,7 @@
<item name="colorOnBackground">@color/colorOnBackground</item> <item name="colorOnBackground">@color/colorOnBackground</item>
<item name="android:windowLightNavigationBar">true</item> <item name="android:windowLightNavigationBar">true</item>
<item name="android:windowLightStatusBar">true</item>
</style> </style>
</resources> </resources>

View File

@ -25,4 +25,6 @@
<color name="colorSurfaceInverse">#31312B</color> <color name="colorSurfaceInverse">#31312B</color>
<color name="colorOnSurfaceInverse">#F3F1E8</color> <color name="colorOnSurfaceInverse">#F3F1E8</color>
<color name="colorPrimaryInverse">#B8D321</color> <color name="colorPrimaryInverse">#B8D321</color>
<!-- indicator icon background -->
<color name="colorIndicator">#d2d4bc</color>
</resources> </resources>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Lacerta.Custom.Indicator" parent="Widget.Material3.BottomNavigationView.ActiveIndicator">
<item name="android:color">@color/colorIndicator</item>
</style>
</resources>

View File

@ -15,4 +15,5 @@
<!-- common --> <!-- common -->
<string name="placeholder">Placeholder(TODO: Replace)</string>
</resources> </resources>

View File

@ -28,8 +28,6 @@
<item name="colorOutline">@color/colorOutline</item> <item name="colorOutline">@color/colorOutline</item>
<item name="colorOnBackground">@color/colorOnBackground</item> <item name="colorOnBackground">@color/colorOnBackground</item>
<item name="android:windowLightNavigationBar">true</item>
</style> </style>
<style name="Theme.Lacerta" parent="Base.Theme.Lacerta" > <style name="Theme.Lacerta" parent="Base.Theme.Lacerta" >