fix: fixed search functionality

This commit is contained in:
antonio 2023-07-18 10:37:17 +02:00
parent 260e6e9daa
commit 560ac2df68
4 changed files with 13 additions and 13 deletions

View file

@ -12,7 +12,7 @@ import java.util.List;
@Dao
public interface RecentSearchDao {
@Query("SELECT * FROM recent_search ORDER BY search ASC")
@Query("SELECT * FROM recent_search ORDER BY search DESC")
List<String> getRecent();
@Insert(onConflict = OnConflictStrategy.REPLACE)

View file

@ -1,5 +1,7 @@
package com.cappielloantonio.tempo.repository;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
@ -100,6 +102,8 @@ public class SearchingRepository {
LinkedHashSet<String> hashSet = new LinkedHashSet<>(newSuggestions);
ArrayList<String> suggestionsWithoutDuplicates = new ArrayList<>(hashSet);
Log.d("suggestionsWithoutDuplicates", suggestionsWithoutDuplicates.toString());
suggestions.setValue(suggestionsWithoutDuplicates);
}
}

View file

@ -4,6 +4,7 @@ import android.content.ComponentName;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -121,17 +122,11 @@ public class SearchFragment extends Fragment implements ClickCallback {
bind.searchView
.getEditText()
.setOnEditorActionListener((textView, actionId, keyEvent) -> {
String query = bind.searchView.getText().toString();
if (actionId == EditorInfo.IME_ACTION_DONE) {
if (isQueryValid(query)) {
search(bind.searchView.getText().toString());
return true;
} else {
Toast.makeText(requireContext(), getString(R.string.search_info_minimum_characters), Toast.LENGTH_SHORT).show();
return false;
}
if (isQueryValid(query)) {
search(query);
return true;
}
return false;
@ -147,7 +142,7 @@ public class SearchFragment extends Fragment implements ClickCallback {
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
if (count > 1) {
if (start + count > 1) {
setSearchSuggestions(charSequence.toString());
} else {
setRecentSuggestions();
@ -247,6 +242,7 @@ public class SearchFragment extends Fragment implements ClickCallback {
}
private boolean isQueryValid(String query) {
Log.d(TAG, "isQueryValid()");
return !query.equals("") && query.trim().length() > 2;
}

View file

@ -36,8 +36,8 @@
<ImageView
android:id="@+id/search_suggestion_delete_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/ic_close"
app:layout_constraintBottom_toBottomOf="@id/search_suggestion_icon"