0

I have converted Adapter code from java to kotlin using IDE and I have an issue with ListFiler class not getting called in Kotlin code.

I have mentioned bellow the java code and equivalent kotlin code

In java it goes from FIRST - SECOND - THIRD

In Koltin code FIRST - SECOND - AND THIRD IS NOT HIT IN DEBUG

Could you please suggest what I might be doing wrong here please

Thanks R

In java bellow is the flow

//FIRST - THIS FUNCTION IS CALLED WHICH GETS TO SECOND

public void applyCurrentFilter(Filter.FilterListener listener) {
    getFilter().filter(null, listener);
}


//SECOND - THIS IS CALLED WHICH GETS TO THIRD
@NonNull
@Override
public Filter getFilter() {
    return new ListFilter();
}



private class ListFilter extends Filter {

    @Override
    protected FilterResults performFiltering(CharSequence constraint) {
    //****THIRD - GETS INSIDE THIS performFiltering METHOD
        FilterResults filterResults = new FilterResults();
        ArrayList<ServiceOrder> tempFilteredObjects = new ArrayList<>();

        if (currentOrderFilter.getServiceTypes().size() == 0 && !currentOrderFilter.isHideClaimed()) {
            tempFilteredObjects.addAll(originalObjects);
        }

        if (currentOrderFilter.getServiceTypes().size() > 0) {
            tempFilteredObjects = filterServiceTypeResults(currentOrderFilter, originalObjects);
        }

        if (currentOrderFilter.isHideClaimed()) {
            tempFilteredObjects = filterOutClaimedOrders(tempFilteredObjects, currentOrderFilter, originalObjects);
        }

        filterResults.values = tempFilteredObjects;
        filterResults.count  = tempFilteredObjects.size();

        return filterResults;
    }

    @Override
    @SuppressWarnings("unchecked")
    protected void publishResults(CharSequence constraint, FilterResults results) {
        if (results != null && results.count > 0) {
            filteredObjects = (List<ServiceOrder>) results.values;
            notifyDataSetChanged();
        } else {
            filteredObjects.clear();
            notifyDataSetInvalidated();
        }
    }
}

In Kotlin

//FIRST - THIS FUNCTION IS CALLED WHICH GETS TO SECOND
fun applyCurrentFilter(listener: FilterListener?) {
    filter.filter(null, listener)
}

//SECOND - THIS IS CALLED WHICH DOES NOT GET TO THIRD
override fun getFilter(): Filter =
    ListFilter()



private inner class ListFilter : Filter() {
    override fun performFiltering(constraint: CharSequence): FilterResults {
    //*****DOES NOT GET HERE
        val filterResults = FilterResults()
        var tempFilteredObjects = ArrayList<ServiceOrder>()
        if (currentOrderFilter.serviceTypes.size == 0 && !currentOrderFilter.isHideClaimed) {
            tempFilteredObjects.addAll(originalObjects)
        }
        if (currentOrderFilter.serviceTypes.size > 0) {
            tempFilteredObjects = filterServiceTypeResults(currentOrderFilter, originalObjects)
        }
        if (currentOrderFilter.isHideClaimed) {
            tempFilteredObjects = filterOutClaimedOrders(tempFilteredObjects,
                currentOrderFilter,
                originalObjects
            )
        }
        filterResults.values = tempFilteredObjects
        filterResults.count = tempFilteredObjects.size
        return filterResults
    }

    override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
        if (results != null && results.count > 0) {
            filteredObjects = (results.values as List<ServiceOrder>).toMutableList()
            notifyDataSetChanged()
        } else {
            filteredObjects.clear()
            notifyDataSetInvalidated()
        }
    }
}

Please share your suggestions

thanks R

1 Answer 1

1

constraint maybe null. try to change method params to below, maybe work

override fun performFiltering(charSequence: CharSequence?): Filter.FilterResults
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.