RealmRecyclerViewAdapter + фильтруется на адаптере разделения экрана, не вызывая onCreateViewHolder

RealmRecyclerViewAdapter + Filterable на разделенном экране адаптер не вызывает onCreateViewHolder

Это мой класс адаптера. Я не могу понять, почему адаптер не может вызвать onCreateViewHolder после того, как я разделил экран или изменил разрешение от фона, он работает нормально, когда я запускаю активность с заставки

 package com.invoqhealth.relay.adapter;

    import android.content.Context;
    import android.graphics.Typeface;
    import android.support.annotation.Nullable;
    import android.support.v7.widget.RecyclerView;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Filter;
    import android.widget.Filterable;
    import android.widget.LinearLayout;
    import android.widget.TextView;

    import com.invoqhealth.relay.Preferences.MyPreferenceManager;
    import com.invoqhealth.relay.R;
    import com.invoqhealth.relay.database.entity.PatientEntity;
    import com.invoqhealth.relay.utils.CommonUtils;
    import com.invoqhealth.relay.viewmodel.ChatViewModel;
    import com.invoqhealth.relay.viewmodel.PatientListViewModel;

    import io.realm.OrderedRealmCollection;
    import io.realm.RealmRecyclerViewAdapter;

    /**
     * Created by shaikhshakil on 24/01/18.
     */

    public class OtherPatientAdapter extends RealmRecyclerViewAdapter<PatientEntity, OtherPatientAdapter.ItemViewHolder> implements Filterable{

        public final static String TAG = OtherPatientAdapter.class.getName();
        public Context mContext;
        CustomFilter filter;
        PatientListViewModel viewModel;
        ChatViewModel chatViewModel;

        public OtherPatientAdapter(OrderedRealmCollection<PatientEntity> itemList, PatientListViewModel viewModel, ChatViewModel chatViewModel) {
            super(itemList, true);
            this.viewModel=viewModel;
            this.chatViewModel = chatViewModel;
            Log.d(TAG,"OtherPatientAdapter Constructor:"+itemList.size());
        }

        @Override
        public OtherPatientAdapter.ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            mContext = parent.getContext();
            View view = inflater.inflate(R.layout.patient_adapter_design, parent, false);
            ItemViewHolder itemViewHolder = new ItemViewHolder(view,mContext);
            Log.d(TAG,"OtherPatientAdapter onCreateViewHolder");
            return itemViewHolder;
        }

        @Override
        public int getItemCount() {
            return super.getItemCount();
        }

        @Override
        public void onViewRecycled(ItemViewHolder holder) {
            super.onViewRecycled(holder);
        }

        @Override
        public void onBindViewHolder(OtherPatientAdapter.ItemViewHolder holder, int position) {
            PatientEntity item = getData().get(position);
            ItemViewHolder itemViewHolder = holder;
            chatViewModel.init(item.getPatientId());
            itemViewHolder.loadItem(item,chatViewModel);
            Log.d(TAG,"OtherPatientAdapter onBindViewHolder");
        }

        @Override
        public long getItemId(int position) {
            return super.getItemId(position);
        }

        @Nullable
        @Override
        public PatientEntity getItem(int index) {
            return super.getItem(index);
        }

        @Override
        public Filter getFilter() {
            if(filter==null)
            {
                filter=new CustomFilter(this);
            }
            return filter;
        }

        public void filterResults(String text) {
                text = text == null ? null : text.toLowerCase().trim();
                updateData(viewModel.getOtherPatientsBySearchText(text));
        }


        public static class ItemViewHolder extends RecyclerView.ViewHolder {

            /*TextView*/
            TextView patient_name, date, ageAndDisease, status, message_count, age, disease,docter_name,message_new;
            /*LinearLayout*/
            /*LinearLayout*/
            LinearLayout patient_click;
            Context mContext;
            View view_layout;
            public ItemViewHolder(View itemView,Context context) {
                super(itemView);
                mContext=context;
                patient_name = itemView.findViewById(R.id.patient_name);
                date = itemView.findViewById(R.id.date);
                ageAndDisease = itemView.findViewById(R.id.patient_age_disease);
                status = itemView.findViewById(R.id.status);
                message_count = itemView.findViewById(R.id.message_count);
                patient_click = itemView.findViewById(R.id.linearLayout_patient_item);
                //patient_parent_layout = (LinearLayout)itemView.findViewById(R.id.patient_parent_layout);
                docter_name = itemView.findViewById(R.id.docter_name);
                docter_name.setVisibility(View.VISIBLE);
                message_new = itemView.findViewById(R.id.new_message);
                message_new.setVisibility(View.GONE );
                view_layout = itemView.findViewById(R.id.view_layout);

                itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // send the text to the listener, i.e Activity.
                        mListener.onItemClicked(patient_name.getTag().toString());
                        date.setTextColor(mContext.getResources().getColor(R.color.search_text));
                        message_count.setVisibility(View.GONE);
                    }
                });
                itemView.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        // patient_click.setBackgroundColor(mContext.getColor(R.color.error));
                        if(mListenerLong!=null && patient_name!=null && patient_name.getTag()!=null)
                            mListenerLong.onItemLongClicked(patient_name.getTag().toString());

                        date.setTextColor(mContext.getResources().getColor(R.color.search_text));
                        message_count.setVisibility(View.GONE);
                        return false;
                    }
                });

            }


            // Gson gson = new Gson();
            public void loadItem(PatientEntity item, ChatViewModel chatViewModel) {

                patient_name.setText(item.getFullName());
                patient_name.setTag(item.getPatientId());

                if (CommonUtils.formatedChatDateOrTime(item.getRecordUpdatedAt()) != null)
                    date.setText(CommonUtils.formatedChatDateOrTime(item.getRecordUpdatedAt()).toString());
    //            else
    //                date.setVisibility(View.GONE);

                ageAndDisease.setText(item.getAge() + ", " + chatViewModel.getDiagnosis());
                patient_name.setTypeface(Typeface.DEFAULT_BOLD);
                message_count.setVisibility(View.VISIBLE);
               // docter_name.setText("Dr Kalpan Singh");
                docter_name.setText("Dr "+chatViewModel.getPhysicianName(item.getPhysicianId()));

                if(MyPreferenceManager.getUnreadCount(mContext,item.getRecordId())>0)
                {
                    message_count.setVisibility(View.VISIBLE);
                    date.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
                    patient_name.setTypeface(Typeface.DEFAULT_BOLD);
                    //message_count.setText(MyPreferenceManager.getUnreadCount(mContext,item.getRecordId()));
                    int count = MyPreferenceManager.getUnreadCount(mContext,item.getRecordId());
                    message_count.setText(count+"");

                }
                else
                {
                    message_count.setVisibility(View.GONE);
                    date.setTextColor(mContext.getResources().getColor(R.color.search_text));
                    patient_name.setTypeface(Typeface.DEFAULT);
                }

            }
        }

        // Define listener member variable
        private static OnRecyclerViewItemClickListener mListener;
        private static OnRecyclerViewItemLongClickListener mListenerLong;

        public interface OnRecyclerViewItemLongClickListener {
            void onItemLongClicked(String text);
        }

        // Define the listener interface
        public interface OnRecyclerViewItemClickListener {
            void onItemClicked(String text);
        }

        // Define the method that allows the parent activity or fragment to define the listener.
        public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener listener) {
            mListener = listener;
        }

        public void setOnRecyclerViewItemLongClickListener(OnRecyclerViewItemLongClickListener listener) {
            mListenerLong = listener;
        }

        public class CustomFilter extends Filter {

            OtherPatientAdapter adapter;

            public CustomFilter(OtherPatientAdapter adapter)
            {
                this.adapter=adapter;
            }

            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                return new FilterResults();
            }

            @Override
            protected void publishResults(CharSequence constraint, FilterResults results) {
                adapter.filterResults(constraint.toString());
            }
        }
    }

0 ответов

Другие вопросы по тегам