Attempt for fix issue that happens sometimes in RecyclerView: Invalid item position 0
This commit is contained in:
parent
3e95ed8ed4
commit
b21625995e
8 changed files with 65 additions and 6 deletions
|
@ -100,6 +100,10 @@ public abstract class MainActivity extends LinphoneGenericActivity
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (!LinphoneService.isReady()) {
|
||||
finish();
|
||||
}
|
||||
|
||||
setContentView(R.layout.main);
|
||||
|
||||
mOnBackPressGoHome = true;
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.linphone.core.SearchResult;
|
|||
import org.linphone.core.tools.Log;
|
||||
import org.linphone.settings.LinphonePreferences;
|
||||
import org.linphone.views.ContactSelectView;
|
||||
import org.linphone.views.LinphoneLinearLayoutManager;
|
||||
|
||||
public class ChatRoomCreationFragment extends Fragment
|
||||
implements View.OnClickListener,
|
||||
|
@ -220,7 +221,7 @@ public class ChatRoomCreationFragment extends Fragment
|
|||
}
|
||||
|
||||
LinearLayoutManager layoutManager =
|
||||
new LinearLayoutManager(getActivity().getApplicationContext());
|
||||
new LinphoneLinearLayoutManager(getActivity().getApplicationContext());
|
||||
|
||||
mContactsList.setAdapter(mSearchAdapter);
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.linphone.core.CoreListenerStub;
|
|||
import org.linphone.core.ProxyConfig;
|
||||
import org.linphone.utils.LinphoneUtils;
|
||||
import org.linphone.utils.SelectableHelper;
|
||||
import org.linphone.views.LinphoneLinearLayoutManager;
|
||||
|
||||
public class ChatRoomsFragment extends Fragment
|
||||
implements ContactsUpdatedListener,
|
||||
|
@ -94,7 +95,7 @@ public class ChatRoomsFragment extends Fragment
|
|||
mSelectionHelper.setAdapter(mChatRoomsAdapter);
|
||||
mSelectionHelper.setDialogMessage(R.string.chat_room_delete_dialog);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||
LinearLayoutManager layoutManager = new LinphoneLinearLayoutManager(getActivity());
|
||||
mChatRoomsList.setLayoutManager(layoutManager);
|
||||
|
||||
DividerItemDecoration dividerItemDecoration =
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.linphone.core.Factory;
|
|||
import org.linphone.core.Participant;
|
||||
import org.linphone.core.tools.Log;
|
||||
import org.linphone.utils.LinphoneUtils;
|
||||
import org.linphone.views.LinphoneLinearLayoutManager;
|
||||
|
||||
public class GroupInfoFragment extends Fragment {
|
||||
private ImageView mConfirmButton;
|
||||
|
@ -130,7 +131,7 @@ public class GroupInfoFragment extends Fragment {
|
|||
});
|
||||
mParticipantsList.setAdapter(mAdapter);
|
||||
mAdapter.setChatRoom(mChatRoom);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||
LinearLayoutManager layoutManager = new LinphoneLinearLayoutManager(getActivity());
|
||||
mParticipantsList.setLayoutManager(layoutManager);
|
||||
|
||||
// Divider between items
|
||||
|
|
|
@ -40,6 +40,7 @@ import java.util.List;
|
|||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.R;
|
||||
import org.linphone.utils.SelectableHelper;
|
||||
import org.linphone.views.LinphoneLinearLayoutManager;
|
||||
|
||||
public class ContactsFragment extends Fragment
|
||||
implements OnItemClickListener,
|
||||
|
@ -166,7 +167,7 @@ public class ContactsFragment extends Fragment
|
|||
}
|
||||
});
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(mContext);
|
||||
mLayoutManager = new LinphoneLinearLayoutManager(mContext);
|
||||
mContactsList.setLayoutManager(mLayoutManager);
|
||||
|
||||
DividerItemDecoration dividerItemDecoration =
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.linphone.core.Call;
|
|||
import org.linphone.core.CallLog;
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.utils.SelectableHelper;
|
||||
import org.linphone.views.LinphoneLinearLayoutManager;
|
||||
|
||||
public class HistoryFragment extends Fragment
|
||||
implements OnClickListener,
|
||||
|
@ -71,7 +72,7 @@ public class HistoryFragment extends Fragment
|
|||
|
||||
mHistoryList = view.findViewById(R.id.history_list);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||
LinearLayoutManager layoutManager = new LinphoneLinearLayoutManager(getActivity());
|
||||
mHistoryList.setLayoutManager(layoutManager);
|
||||
// Divider between items
|
||||
DividerItemDecoration dividerItemDecoration =
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.linphone.R;
|
|||
import org.linphone.activities.MainActivity;
|
||||
import org.linphone.utils.FileUtils;
|
||||
import org.linphone.utils.SelectableHelper;
|
||||
import org.linphone.views.LinphoneLinearLayoutManager;
|
||||
|
||||
public class RecordingsActivity extends MainActivity
|
||||
implements SelectableHelper.DeleteListener, RecordingViewHolder.ClickListener {
|
||||
|
@ -81,7 +82,7 @@ public class RecordingsActivity extends MainActivity
|
|||
mRecordingList = findViewById(R.id.recording_list);
|
||||
mNoRecordings = findViewById(R.id.no_recordings);
|
||||
|
||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
|
||||
LinearLayoutManager mLayoutManager = new LinphoneLinearLayoutManager(this);
|
||||
mRecordingList.setLayoutManager(mLayoutManager);
|
||||
|
||||
// Divider between items
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.linphone.views;
|
||||
/*
|
||||
LinphoneLinearLayoutManager.java
|
||||
Copyright (C) 2019 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
/* https://stackoverflow.com/questions/30220771/recyclerview-inconsistency-detected-invalid-item-position */
|
||||
public class LinphoneLinearLayoutManager extends LinearLayoutManager {
|
||||
/**
|
||||
* Disable predictive animations. There is a bug in RecyclerView which causes views that are
|
||||
* being reloaded to pull invalid ViewHolders from the internal recycler stack if the adapter
|
||||
* size has decreased since the ViewHolder was recycled.
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsPredictiveItemAnimations() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public LinphoneLinearLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public LinphoneLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
|
||||
super(context, orientation, reverseLayout);
|
||||
}
|
||||
|
||||
public LinphoneLinearLayoutManager(
|
||||
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue