Skip to content

Commit

Permalink
resources: instant search (fixes #2547) (#2552)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Oct 4, 2023
1 parent e77f59d commit ea1c4e4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1072
versionName "0.10.72"
versionCode 1073
versionName "0.10.73"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@


import android.app.AlertDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
Expand All @@ -26,7 +25,6 @@
import org.ole.planet.myplanet.callback.TagClickListener;
import org.ole.planet.myplanet.model.RealmCourseProgress;
import org.ole.planet.myplanet.model.RealmMyCourse;
import org.ole.planet.myplanet.model.RealmMyLibrary;
import org.ole.planet.myplanet.model.RealmRating;
import org.ole.planet.myplanet.model.RealmSearchActivity;
import org.ole.planet.myplanet.model.RealmTag;
Expand All @@ -45,7 +43,6 @@
public class CourseFragment extends BaseRecyclerFragment<RealmMyCourse> implements OnCourseItemSelected, TagClickListener {
TextView tvAddToLib, tvMessage, tvSelected;
EditText etSearch;
ImageView imgSearch;
AdapterCourses adapterCourses;
Button btnRemove, orderByDate, orderByTitle;
CheckBox selectAll;
Expand Down Expand Up @@ -85,10 +82,20 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
btnRemove.setVisibility(View.VISIBLE);
}

imgSearch.setOnClickListener(view -> {
adapterCourses.setCourseList(filterCourseByTag(etSearch.getText().toString(), searchTags));
showNoData(tvMessage, adapterCourses.getItemCount());
KeyboardUtils.hideSoftKeyboard(getActivity());
etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
adapterCourses.setCourseList(filterCourseByTag(etSearch.getText().toString(), searchTags));
showNoData(tvMessage, adapterCourses.getItemCount());
}

@Override
public void afterTextChanged(Editable s) {
}
});

btnRemove.setOnClickListener(V -> new AlertDialog.Builder(this.getContext())
Expand All @@ -98,7 +105,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
if (adapterCourses.getCourseList().size() == 0) {
selectAll.setVisibility(View.GONE);
etSearch.setVisibility(View.GONE);
imgSearch.setVisibility(View.GONE);
tvAddToLib.setVisibility(View.GONE);
getView().findViewById(R.id.filter).setVisibility(View.GONE);
spn.setVisibility(View.GONE);
Expand Down Expand Up @@ -159,7 +165,6 @@ private void initializeView() {
if (adapterCourses.getCourseList().size() == 0) {
selectAll.setVisibility(View.GONE);
etSearch.setVisibility(View.GONE);
imgSearch.setVisibility(View.GONE);
tvAddToLib.setVisibility(View.GONE);
getView().findViewById(R.id.filter).setVisibility(View.GONE);
spn.setVisibility(View.GONE);
Expand All @@ -173,7 +178,6 @@ private void initializeView() {
btnRemove = getView().findViewById(R.id.btn_remove);
spnGrade = getView().findViewById(R.id.spn_grade);
spnSubject = getView().findViewById(R.id.spn_subject);
imgSearch = getView().findViewById(R.id.img_search);
tvMessage = getView().findViewById(R.id.tv_message);
getView().findViewById(R.id.tl_tags).setVisibility(View.GONE);
tvFragmentInfo = getView().findViewById(R.id.tv_fragment_info);
Expand All @@ -183,7 +187,6 @@ private void initializeView() {
if (adapterCourses.getCourseList().size() == 0) {
selectAll.setVisibility(View.GONE);
etSearch.setVisibility(View.GONE);
imgSearch.setVisibility(View.GONE);
tvAddToLib.setVisibility(View.GONE);
getView().findViewById(R.id.filter).setVisibility(View.GONE);
spn.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

import android.app.AlertDialog;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

Expand Down Expand Up @@ -51,7 +52,6 @@
public class LibraryFragment extends BaseRecyclerFragment<RealmMyLibrary> implements OnLibraryItemSelected, ChipDeletedListener, TagClickListener, OnFilterListener {
TextView tvAddToLib, tvSelected;
EditText etSearch, etTags;
ImageView imgSearch;
AdapterLibrary adapterLibrary;
FlexboxLayout flexBoxTags;
List<RealmTag> searchTags;
Expand Down Expand Up @@ -90,7 +90,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
etTags = getView().findViewById(R.id.et_tags);
clearTags = getView().findViewById(R.id.btn_clear_tags);
tvSelected = getView().findViewById(R.id.tv_selected);
imgSearch = getView().findViewById(R.id.img_search);
flexBoxTags = getView().findViewById(R.id.flexbox_tags);
selectAll = getView().findViewById(R.id.selectAll);
tvDelete = getView().findViewById(R.id.tv_delete);
Expand All @@ -117,11 +116,22 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
})
.setNegativeButton(R.string.no, null).show());

imgSearch.setOnClickListener(view -> {
adapterLibrary.setLibraryList(applyFilter(filterLibraryByTag(etSearch.getText().toString().trim(), searchTags)));
showNoData(tvMessage, adapterLibrary.getItemCount());
KeyboardUtils.hideSoftKeyboard(getActivity());
etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
adapterLibrary.setLibraryList(applyFilter(filterLibraryByTag(etSearch.getText().toString().trim(), searchTags)));
showNoData(tvMessage, adapterLibrary.getItemCount());
}

@Override
public void afterTextChanged(Editable s) {
}
});

getView().findViewById(R.id.btn_collections).setOnClickListener(view -> {
CollectionsFragment f = CollectionsFragment.getInstance(searchTags, "resources");
f.setListener(LibraryFragment.this);
Expand Down Expand Up @@ -167,7 +177,6 @@ private void checkList() {
if (adapterLibrary.getLibraryList().size() == 0) {
selectAll.setVisibility(View.GONE);
etSearch.setVisibility(View.GONE);
imgSearch.setVisibility(View.GONE);
tvAddToLib.setVisibility(View.GONE);
spn.setVisibility(View.GONE);
tvSelected.setVisibility(View.GONE);
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/layout/layout_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,5 @@
android:maxLines="1"
android:padding="@dimen/padding_normal" />
</com.google.android.material.textfield.TextInputLayout>

<ImageView
android:id="@+id/img_search"
android:layout_width="30dp"
android:layout_height="@dimen/layout_height"
android:layout_gravity="center"
android:background="?attr/selectableItemBackground"
android:src="@drawable/ic_search" />
</LinearLayout>

</LinearLayout>

0 comments on commit ea1c4e4

Please sign in to comment.