diff --git a/.idea/misc.xml b/.idea/misc.xml index 1de88c4fa..c5ccd8d76 100755 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -45,6 +45,7 @@ + diff --git a/app/src/main/assets/data/common/gradle-plugin.zip b/app/src/main/assets/data/common/gradle-plugin.zip index 4a40be54c..7da414250 100644 Binary files a/app/src/main/assets/data/common/gradle-plugin.zip and b/app/src/main/assets/data/common/gradle-plugin.zip differ diff --git a/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttributeListSheet.java b/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttributeListSheet.java index 6802e4172..c2404f6f9 100644 --- a/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttributeListSheet.java +++ b/app/src/main/java/com/itsaky/androidide/fragments/sheets/AttributeListSheet.java @@ -18,21 +18,26 @@ package com.itsaky.androidide.fragments.sheets; import android.os.Bundle; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; +import androidx.appcompat.widget.SearchView; +import androidx.fragment.app.DialogFragment; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.itsaky.androidide.R; import com.itsaky.androidide.adapters.AttrListAdapter; +import com.itsaky.androidide.databinding.LayoutAddAttrSheetBinding; import com.itsaky.attrinfo.models.Attr; import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; /** * A bottom sheet dialog for showing a simple list of @@ -43,23 +48,53 @@ import java.util.List; */ public class AttributeListSheet extends BottomSheetDialogFragment { - private RecyclerView mList; + private LayoutAddAttrSheetBinding binding; private List mItems; + @Override + public void onCreate (@Nullable Bundle savedInstanceState) { + super.onCreate (savedInstanceState); + setStyle (DialogFragment.STYLE_NORMAL, R.style.AppTheme_SheetAboveKeyboard); + } + @Nullable @Override public View onCreateView (@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - mList = new RecyclerView (inflater.getContext ()); - mList.setLayoutManager (new LinearLayoutManager (inflater.getContext ())); - mList.setLayoutParams (new ViewGroup.LayoutParams (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - return mList; + this.binding = LayoutAddAttrSheetBinding.inflate (inflater, container, false); + return binding.getRoot (); } @Override public void onViewCreated (@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated (view, savedInstanceState); - mList.setAdapter (new AttrListAdapter (mItems)); + binding.searchBar.setOnQueryTextListener (new SearchView.OnQueryTextListener () { + + @Override + public boolean onQueryTextSubmit (String query) { + return filterAttributes (query.trim ()); + } + + @Override + public boolean onQueryTextChange (String newText) { + return filterAttributes (newText.trim ()); + } + }); + binding.attrList.setAdapter (new AttrListAdapter (mItems)); + } + + private boolean filterAttributes (@NonNull String query) { + if (mItems == null || TextUtils.isEmpty (query)) { + update (); + return true; + } + + final var filtered = this.mItems + .stream () + .filter (attr -> attr.name.toLowerCase (Locale.ROOT).contains (query.toLowerCase (Locale.ROOT))) + .collect (Collectors.toList ()); + + update (filtered); + return true; } public void setItems (@Nullable List items) { @@ -72,8 +107,12 @@ public class AttributeListSheet extends BottomSheetDialogFragment { } public void update () { - if (mList != null) { - mList.setAdapter (new AttrListAdapter (mItems)); + update (mItems); + } + + public void update (List items) { + if (binding != null) { + binding.attrList.setAdapter (new AttrListAdapter (items)); } } } diff --git a/app/src/main/res/layout/layout_add_attr_sheet.xml b/app/src/main/res/layout/layout_add_attr_sheet.xml new file mode 100644 index 000000000..26fd6935d --- /dev/null +++ b/app/src/main/res/layout/layout_add_attr_sheet.xml @@ -0,0 +1,48 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c170e16c..8f1e421a0 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -375,4 +375,5 @@ Make the floating text actions appear horizontally (restart required if changed). Unable to start intent for installing APK Add attribute + Search attributes... diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 11c1aee18..0081b33ba 100755 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,100 +1,120 @@ + + + - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +