Giter Site home page Giter Site logo

Comments (9)

mars885 avatar mars885 commented on September 22, 2024

Hello.

Looks like it is the bug on your side. The method getItemModel() definitely exists in the library that I use for RecyclerView adapters.

Try to redownload the dependency and see if that helps.

from persistent-search-view.

mars885 avatar mars885 commented on September 22, 2024

It looks like the dependencies got mixed up for some odd reason. Nevertheless, I've fixed them and released a new version called v1.1.1. Please take a look at it.

from persistent-search-view.

ranaprathap2 avatar ranaprathap2 commented on September 22, 2024

Having the same issue even after updating dependency from v1.0.0 to v1.1.1 the method getItemModel doesn't exist still..... the only available method for 'getter' was geTrackeyKey() or getLayout() which obfiusly not for picking up the suggestion text

from persistent-search-view.

ranaprathap2 avatar ranaprathap2 commented on September 22, 2024

/*

  • Copyright 2017
  • Paul Rybitskyi, [email protected]
  • Arthur Ivanets, [email protected]
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

package com.paulrybitskyi.persistentsearchview.adapters.model;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.arthurivanets.adapster.Adapter;
import com.arthurivanets.adapster.listeners.ItemClickListener;
import com.arthurivanets.adapster.listeners.OnItemClickListener;
import com.arthurivanets.adapster.model.BaseItem;
import com.arthurivanets.adapster.model.markers.Trackable;
import com.paulrybitskyi.persistentsearchview.R;
import com.paulrybitskyi.persistentsearchview.adapters.resources.SuggestionItemResources;
import com.paulrybitskyi.persistentsearchview.model.Suggestion;
import com.paulrybitskyi.persistentsearchview.utils.Preconditions;
import com.paulrybitskyi.persistentsearchview.utils.Utils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import static com.paulrybitskyi.persistentsearchview.utils.ViewUtils.makeGone;
import static com.paulrybitskyi.persistentsearchview.utils.ViewUtils.makeVisible;

/**

  • A recycler view item for a suggestion.
    */
    public class SuggestionItem extends BaseItem<Suggestion, SuggestionItem.ViewHolder, SuggestionItemResources> implements Trackable {

    /**

    • A constant holding a layout resource ID for the suggestion item.
      */
      public static final int MAIN_LAYOUT_ID = R.layout.persistent_search_view_suggestion_item_layout;

    /**

    • Creates a suggestion item with the specified text.
    • @param suggestionText The suggestion's text
    • @return An instance of a suggestion item
      */
      public static SuggestionItem of(@nonnull String suggestionText) {
      return of(-1L, suggestionText);
      }

    /**

    • Creates a suggestion item with the specified id and text.

    • @param id The suggestion's id

    • @param suggestionText The suggestion's text

    • @return An instance of a suggestion item
      */
      public static SuggestionItem of(long id, @nonnull String suggestionText) {
      Preconditions.nonEmpty(suggestionText);

      return new SuggestionItem(
      new Suggestion()
      .setId(id)
      .setText(suggestionText)
      );
      }

    public SuggestionItem(Suggestion itemModel) {
    super(itemModel);
    }

    @OverRide
    public ViewHolder init(Adapter adapter,
    ViewGroup parent,
    LayoutInflater inflater,
    SuggestionItemResources resources) {
    final View view = inflater.inflate(MAIN_LAYOUT_ID, parent, false);
    return new ViewHolder(view);
    }

    @OverRide
    public void bind(@nullable Adapter adapter,
    @nonnull ViewHolder viewHolder,
    @nullable SuggestionItemResources resources) {
    super.bind(adapter, viewHolder, resources);

     final Suggestion suggestion = getItemModel();
     final boolean isRecentSearchSuggestion = Suggestion.TYPE_RECENT_SEARCH_SUGGESTION.equals(suggestion.getType());
    
     // text related
     viewHolder.mTextTv.setTextColor(resources.getTextColor());
     handleText(viewHolder, resources);
    
     // icon related
     viewHolder.mIconIv.setImageDrawable(Utils.getColoredDrawable(
         viewHolder.mIconIv.getContext(),
         (isRecentSearchSuggestion ? R.drawable.ic_history_black_24dp : R.drawable.ic_magnify_black_24dp),
         (isRecentSearchSuggestion ? resources.getRecentSearchIconColor() : resources.getSearchSuggestionIconColor())
     ));
    
     // remove button related
     if(isRecentSearchSuggestion) {
         viewHolder.mRemoveBtnIv.setImageDrawable(Utils.getColoredDrawable(
             viewHolder.mRemoveBtnIv.getContext(),
             R.drawable.ic_close_black_24dp,
             resources.getIconColor()
         ));
         makeVisible(viewHolder.mRemoveBtnIv);
     } else {
         makeGone(viewHolder.mRemoveBtnIv);
     }
    

    }

    private void handleText(ViewHolder viewHolder, SuggestionItemResources resources) {
    final Suggestion suggestion = getItemModel();
    final String text = suggestion.getText();
    final int startIndex = suggestion.getText().toLowerCase().indexOf(resources.getCurrentQuery().toLowerCase());
    final int endIndex = Math.min(resources.getCurrentQuery().length(), text.length());

     if(!TextUtils.isEmpty(resources.getCurrentQuery())
             && (startIndex != -1)
             && (startIndex <= endIndex)) {
         final SpannableString spannableString = new SpannableString(text);
         spannableString.setSpan(
             new ForegroundColorSpan(resources.getSelectedTextColor()),
             startIndex,
             endIndex,
             Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
         );
    
         viewHolder.mTextTv.setText(spannableString);
     } else {
         viewHolder.mTextTv.setText(text);
     }
    

    }

    /**

    • Sets a listener to invoke when the item is clicked.
    • @param viewHolder The view holder
    • @param onItemClickListener The listener to set
      */
      public void setOnItemClickListener(ViewHolder viewHolder, OnItemClickListener onItemClickListener) {
      viewHolder.itemView.setOnClickListener(new ItemClickListener<>(
      this,
      viewHolder.getAdapterPosition(),
      onItemClickListener
      ));
      }

    /**

    • Sets a listener to invoke when the remove button is clicked.
    • @param viewHolder The view holder
    • @param onItemRemoveButtonClickListener The listener to set
      */
      public void setOnItemRemoveButtonClickListener(ViewHolder viewHolder, OnItemClickListener onItemRemoveButtonClickListener) {
      viewHolder.mRemoveBtnIv.setOnClickListener(new ItemClickListener<>(
      this,
      viewHolder.getAdapterPosition(),
      onItemRemoveButtonClickListener
      ));
      }

    @OverRide
    public int getLayout() {
    return MAIN_LAYOUT_ID;
    }

    @OverRide
    public Long getTrackKey() {
    final Suggestion suggestion = getItemModel();
    return (suggestion.hasValidId() ? suggestion.getId() : ((long) suggestion.getText().hashCode()));
    }

    /**

    • A view holder containing suggestion item related views.
      */
      public static class ViewHolder extends BaseItem.ViewHolder {

      private TextView mTextTv;

      private ImageView mIconIv;
      private ImageView mRemoveBtnIv;

      public ViewHolder(View itemView) {
      super(itemView);

       mTextTv = itemView.findViewById(R.id.textTv);
       mIconIv = itemView.findViewById(R.id.iconIv);
       mRemoveBtnIv = itemView.findViewById(R.id.removeBtnIv);
      

      }

    }

}

from persistent-search-view.

ranaprathap2 avatar ranaprathap2 commented on September 22, 2024

Hello.

Looks like it is the bug on your side. The method getItemModel() definitely exists in the library that I use for RecyclerView adapters.

Try to redownload the dependency and see if that helps.

tried redownloading dependencies too no luck with v1.1.1 still getItemModel() doesn't exist :-(

from persistent-search-view.

mars885 avatar mars885 commented on September 22, 2024

from persistent-search-view.

abhiemanyu87 avatar abhiemanyu87 commented on September 22, 2024

I got the exact same error, there is no itemModel or getItemModel().

from persistent-search-view.

abalta avatar abalta commented on September 22, 2024

I have same error on v1.1.2

from persistent-search-view.

kerem0comert avatar kerem0comert commented on September 22, 2024

Hello,
Still the same issue, after a year. FYI, this is definitely not a "bug on your side".

from persistent-search-view.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.