Merge pull request #79 from lacerta-doc/feature/search/add_ui

Feature/search/add UI
This commit is contained in:
ろむねこ 2024-01-19 14:24:03 +09:00 committed by GitHub
commit abc91b79ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 205 additions and 6 deletions

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">

View File

@ -11,6 +11,11 @@
android:icon="@drawable/folder_24px" android:icon="@drawable/folder_24px"
android:title="Library"/> android:title="Library"/>
<item
android:id="@id/feature_search_navigation"
android:icon="@drawable/search_24px"
android:title="Search"/>
<item <item
android:id="@id/feature_debug_navigation" android:id="@id/feature_debug_navigation"
android:icon="@drawable/developer_mode_24px" android:icon="@drawable/developer_mode_24px"

View File

@ -9,6 +9,7 @@
<include app:graph="@navigation/feature_library_navigation" /> <include app:graph="@navigation/feature_library_navigation" />
<include app:graph="@navigation/feature_home_navigation" /> <include app:graph="@navigation/feature_home_navigation" />
<include app:graph="@navigation/feature_search_navigation" />
</navigation> </navigation>

View File

@ -27,9 +27,17 @@ android {
dependencies { dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1' implementation libs.androidx.appcompat
implementation 'com.google.android.material:material:1.10.0' implementation libs.com.google.android.material
testImplementation 'junit:junit:4.13.2' testImplementation libs.junit
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation libs.androidx.test.espresso.core
// Navigation
implementation libs.navigation.fragment
implementation libs.navigation.ui
implementation libs.navigation.dynamic.features.fragment
// shared
implementation project(':shared:ui')
} }

View File

@ -0,0 +1,142 @@
package one.nem.lacerta.feature.search;
import android.app.LauncherActivity;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SearchView;
import java.util.ArrayList;
/**
* A simple {@link Fragment} subclass.
* Use the {@link SearchTopFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class SearchTopFragment extends Fragment {
private static final String TAG = SearchTopFragment.class.getSimpleName();
private final SearchTopFragment self = this;
private SearchView searchView;
private String searchWord;
// 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 SearchTopFragment() {
// 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 SearchTopFragment.
*/
// TODO: Rename and change types and number of parameters
public static SearchTopFragment newInstance(String param1, String param2) {
SearchTopFragment fragment = new SearchTopFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_search_top, container, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
this.searchView.setIconifiedByDefault(true);
this.searchView.setSubmitButtonEnabled(false);
if (!this.searchWord.equals("")) {
this.searchView.setQuery(this.searchWord, false);
} else {
String queryHint = self.getResources().getString(R.string.hello_blank_fragment);
this.searchView.setQueryHint(queryHint);
}
this.searchView.setOnQueryTextListener(self.onQueryTextListener);
}
private final SearchView.OnQueryTextListener onQueryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return self.setSearchWord(searchWord);
}
@Override
public boolean onQueryTextChange(String query) {
return false;
}
};
private boolean setSearchWord(String query) {
if (searchWord != null && !searchWord.equals("")) {
this.searchWord = searchWord;
}
this.searchView.setIconified(false);
this.searchView.onActionViewCollapsed();
this.searchView.clearFocus();
return false;
}
}
interface LacertaSearch {
ArrayList<LauncherActivity.ListItem> autoSearch(String query, int limit);
ArrayList<LauncherActivity.ListItem> autoSearch(String query, int limit, int offset);
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".SearchTopFragment">
<!-- TODO: Update blank fragment layout -->
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/Search_tool_bar"
android:layout_width="match_parent"
android:layout_height="69dp"
android:background="#E4E8EA"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="" />
<SearchView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation 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/feature_search_navigation"
app:startDestination="@id/searchTopFragment">
<fragment
android:id="@+id/searchTopFragment"
android:name="one.nem.lacerta.feature.search.SearchTopFragment"
android:label="fragment_search_top"
tools:layout="@layout/fragment_search_top" />
</navigation>

View File

@ -0,0 +1,4 @@
<resources>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>