Some cleanup
This commit is contained in:
parent
30bda8f7c6
commit
0e9d85e7ae
9 changed files with 64 additions and 329 deletions
|
@ -1,5 +1,24 @@
|
|||
package org.linphone.call;
|
||||
|
||||
/*
|
||||
CallHistoryAdapter.java
|
||||
Copyright (C) 2018 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.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -57,10 +76,8 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
this.listener = listener;
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
//Thoses methods are caught up by the fragment
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
|
@ -80,7 +97,6 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
void onItemClicked(int position);
|
||||
boolean onItemLongClicked(int position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<CallLog> mLogs;
|
||||
|
@ -110,8 +126,6 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
|
||||
}
|
||||
|
||||
//Links datas, visibility and listeners of inner items from the adapter to the ViewHolder
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
|
||||
final CallLog log= mLogs.get(position);
|
||||
|
@ -125,7 +139,6 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
holder.select.setVisibility(isEditionEnabled() ? View.VISIBLE : View.GONE);
|
||||
holder.select.setChecked(isSelected(position));
|
||||
|
||||
|
||||
if (position > 0) {
|
||||
CallLog previousLog = mLogs.get(position-1);
|
||||
long previousTimestamp = previousLog.getStartDate() * 1000;
|
||||
|
@ -141,7 +154,6 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
holder.separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
if (log.getDir() == Call.Dir.Incoming) {
|
||||
address = log.getFromAddress();
|
||||
if (log.getStatus() == Call.Status.Missed) {
|
||||
|
@ -170,8 +182,6 @@ public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.Vie
|
|||
holder.contact.setText(displayName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
holder.detail.setVisibility(isEditionEnabled() ? View.INVISIBLE : View.VISIBLE);
|
||||
holder.detail.setOnClickListener(!isEditionEnabled() ?
|
||||
new View.OnClickListener() {
|
||||
|
|
|
@ -52,10 +52,6 @@ import java.util.List;
|
|||
|
||||
import static org.linphone.fragments.FragmentsAvailable.CHAT_LIST;
|
||||
|
||||
/*
|
||||
* Main sources: Linphone + https://enoent.fr/blog/2015/01/18/recyclerview-basics/
|
||||
* */
|
||||
|
||||
public class ChatListFragment extends Fragment implements ContactsUpdatedListener, ChatRoomsAdapter.ChatRoomViewHolder.ClickListener, SelectableHelper.DeleteListener {
|
||||
|
||||
private RecyclerView mChatRoomsList;
|
||||
|
@ -97,56 +93,14 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||
mChatRoomsList.setLayoutManager(layoutManager);
|
||||
|
||||
|
||||
//Divider between items
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mChatRoomsList.getContext(),
|
||||
((LinearLayoutManager) layoutManager).getOrientation());
|
||||
dividerItemDecoration.setDrawable(getActivity().getApplicationContext().getResources().getDrawable(R.drawable.divider));
|
||||
mChatRoomsList.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
|
||||
mWaitLayout.setVisibility(View.GONE);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//All commentend code below, from line 123 to line 148, have to be uncommented to allow swipe actions.
|
||||
|
||||
//Actions allowed by swipe buttons
|
||||
|
||||
// final SwipeController swipeController = new SwipeController(new SwipeControllerActions() {
|
||||
//// @Override
|
||||
//// public void onLeftClicked(int position) {
|
||||
//// super.onLeftClicked(position);
|
||||
//// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRightClicked(int position) {
|
||||
// mChatRoomsAdapter.removeItem(position);
|
||||
// mChatRoomsAdapter.notifyDataSetChanged();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// //Initialize swipe detection
|
||||
//
|
||||
//
|
||||
// ItemTouchHelper itemTouchHelper = new ItemTouchHelper(swipeController);
|
||||
// itemTouchHelper.attachToRecyclerView(mChatRoomsList);
|
||||
//
|
||||
// //Add swipe buttons
|
||||
// mChatRoomsList.addItemDecoration(new RecyclerView.ItemDecoration() {
|
||||
// @Override
|
||||
// public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
// swipeController.onDraw(c);
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
// Buttons onClickListeners definitions
|
||||
|
||||
|
||||
|
||||
mNewDiscussionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -161,7 +115,6 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
//Update ChatRoomsList on change
|
||||
mListener = new CoreListenerStub() {
|
||||
@Override
|
||||
|
@ -203,8 +156,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
public void onItemClicked(int position) {
|
||||
if (mChatRoomsAdapter.isEditionEnabled()) {
|
||||
mChatRoomsAdapter.toggleSelection(position);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
ChatRoom room = (ChatRoom) mChatRoomsAdapter.getItem(position);
|
||||
LinphoneActivity.instance().goToChat(room.getPeerAddress().asString(),null);
|
||||
}
|
||||
|
@ -212,7 +164,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
|
||||
@Override
|
||||
public boolean onItemLongClicked(int position) {
|
||||
if (mChatRoomsAdapter.isEditionEnabled()!=true) {
|
||||
if (!mChatRoomsAdapter.isEditionEnabled()) {
|
||||
//Start selection mode
|
||||
mSelectionHelper.enterEditionMode();
|
||||
}
|
||||
|
@ -220,10 +172,6 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Existing functions before RecyclerView conversion
|
||||
|
||||
private void refreshChatRoomsList() {
|
||||
mChatRoomsAdapter.refresh();
|
||||
//mNoChatHistory.setVisibility(mChatRoomsAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
|
@ -303,7 +251,7 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void onContactsUpdated() {
|
||||
if (!LinphoneActivity.isInstanciated() || LinphoneActivity.instance().getCurrentFragment() != CHAT_LIST)
|
||||
return;
|
||||
|
@ -313,8 +261,4 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,24 @@
|
|||
package org.linphone.contacts;
|
||||
|
||||
/*
|
||||
ContactsListAdapter.java
|
||||
Copyright (C) 2018 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.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -52,7 +71,6 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
this.listener= listener;
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +78,6 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
if (listener != null) {
|
||||
listener.onItemClicked(getAdapterPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean onLongClick(View v) {
|
||||
|
@ -74,7 +91,6 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
void onItemClicked(int position);
|
||||
boolean onItemLongClicked(int position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<LinphoneContact> contacts;
|
||||
|
@ -92,8 +108,6 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
this.clickListener = clickListener;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
@ -140,8 +154,6 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
return contacts.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Object getItem(int position) {
|
||||
if (position >= getItemCount()) return null;
|
||||
return contacts.get(position);
|
||||
|
@ -154,8 +166,6 @@ public class ContactsListAdapter extends SelectableAdapter<ContactsListAdapter.V
|
|||
return position;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void updateDataSet(List<LinphoneContact> contactsList) {
|
||||
contacts = contactsList;
|
||||
|
||||
|
|
|
@ -114,8 +114,6 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
newContact.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -163,18 +161,12 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
layoutManager = new LinearLayoutManager(mContext);
|
||||
contactsList.setLayoutManager(layoutManager);
|
||||
|
||||
|
||||
|
||||
//Divider between items
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(contactsList.getContext(),
|
||||
layoutManager.getOrientation());
|
||||
dividerItemDecoration.setDrawable(getContext().getResources().getDrawable(R.drawable.divider));
|
||||
dividerItemDecoration.setDrawable(getActivity().getResources().getDrawable(R.drawable.divider));
|
||||
contactsList.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ContactsManager.getInstance().fetchContactsAsync();
|
||||
|
||||
return view;
|
||||
|
@ -249,7 +241,6 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
isEditionEnabled=true;
|
||||
}
|
||||
|
||||
|
||||
mContactAdapter = new ContactsListAdapter(mContext, listContact, this, mSelectionHelper);
|
||||
|
||||
mSelectionHelper.setAdapter(mContactAdapter);
|
||||
|
@ -301,7 +292,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
if (mContactAdapter.isEditionEnabled()) {
|
||||
mContactAdapter.toggleSelection(position);
|
||||
|
||||
}else if (editOnClick) {
|
||||
} else if (editOnClick) {
|
||||
editConsumed = true;
|
||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
||||
} else {
|
||||
|
@ -387,7 +378,4 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
}
|
||||
ContactsManager.getInstance().deleteMultipleContactsAtOnce(ids);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -74,8 +74,6 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
|
||||
historyList = (RecyclerView) view.findViewById(R.id.history_list);
|
||||
|
||||
|
||||
|
||||
layoutManager = new LinearLayoutManager(mContext);
|
||||
historyList.setLayoutManager(layoutManager);
|
||||
//Divider between items
|
||||
|
@ -228,8 +226,6 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onDeleteSelection(Object[] objectsToDelete) {
|
||||
int size = mhistoryAdapter.getSelectedItemCount();
|
||||
|
@ -240,12 +236,11 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
}
|
||||
}
|
||||
|
||||
//ClickListeners bound to items
|
||||
@Override
|
||||
public void onItemClicked(int position) {
|
||||
if (mhistoryAdapter.isEditionEnabled()) {
|
||||
mhistoryAdapter.toggleSelection(position);
|
||||
}else{
|
||||
} else {
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
CallLog log = mLogs.get(position);
|
||||
Address address;
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
package org.linphone.ui;
|
||||
|
||||
/*
|
||||
SelectableAdapter.java
|
||||
Copyright (C) 2018 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.support.v7.widget.RecyclerView;
|
||||
import android.util.SparseBooleanArray;
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import android.widget.LinearLayout;
|
|||
import org.linphone.R;
|
||||
import org.linphone.activities.LinphoneActivity;
|
||||
|
||||
|
||||
public class SelectableHelper {
|
||||
private ImageView mEditButton, mSelectAllButton, mDeselectAllButton, mDeleteSelectionButton, mCancelButton;
|
||||
private LinearLayout mEditTopBar, mTopBar;
|
||||
|
@ -132,10 +131,7 @@ public class SelectableHelper {
|
|||
mAdapter=adapter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void updateSelectionButtons(boolean isSelectionEmpty, boolean isSelectionFull) {
|
||||
|
||||
//Delete button availability
|
||||
if (isSelectionEmpty) {
|
||||
mDeleteSelectionButton.setEnabled(false);
|
||||
|
|
|
@ -1,220 +0,0 @@
|
|||
package org.linphone.ui;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper.Callback;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import static android.support.v7.widget.helper.ItemTouchHelper.ACTION_STATE_SWIPE;
|
||||
import static android.support.v7.widget.helper.ItemTouchHelper.LEFT;
|
||||
|
||||
enum ButtonsState {
|
||||
GONE,
|
||||
// LEFT_VISIBLE,
|
||||
RIGHT_VISIBLE
|
||||
}
|
||||
/*
|
||||
* Taken from https://github.com/FanFataL/swipe-controller-demo
|
||||
* https://codeburst.io/android-swipe-menu-with-recyclerview-8f28a235ff28
|
||||
* */
|
||||
|
||||
|
||||
/*
|
||||
* All commented code is meant to preserve left swipe behaviour for future work
|
||||
* */
|
||||
|
||||
public class SwipeController extends Callback {
|
||||
|
||||
private boolean swipeBack = false;
|
||||
private ButtonsState buttonShowedState = ButtonsState.GONE;
|
||||
private RectF buttonInstance = null;
|
||||
private RecyclerView.ViewHolder currentItemViewHolder = null;
|
||||
private SwipeControllerActions buttonsActions = null;
|
||||
private static final float buttonWidth = 300;
|
||||
|
||||
|
||||
public SwipeController(SwipeControllerActions buttonsActions) {
|
||||
this.buttonsActions = buttonsActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
return makeMovementFlags(0, LEFT);
|
||||
// return makeMovementFlags(0, LEFT | RIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int convertToAbsoluteDirection(int flags, int layoutDirection) {
|
||||
if (swipeBack) {
|
||||
swipeBack = false;
|
||||
return 0;
|
||||
}
|
||||
return super.convertToAbsoluteDirection(flags, layoutDirection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildDraw(Canvas c,
|
||||
RecyclerView recyclerView,
|
||||
RecyclerView.ViewHolder viewHolder,
|
||||
float dX, float dY,
|
||||
int actionState, boolean isCurrentlyActive) {
|
||||
|
||||
if (actionState == ACTION_STATE_SWIPE) {
|
||||
if (buttonShowedState != ButtonsState.GONE) {
|
||||
// if (buttonShowedState == ButtonsState.LEFT_VISIBLE) dX = Math.max(dX, buttonWidth);
|
||||
if (buttonShowedState == ButtonsState.RIGHT_VISIBLE) dX = Math.min(dX, -buttonWidth);
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
}else {
|
||||
setTouchListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
}
|
||||
}
|
||||
if (buttonShowedState == ButtonsState.GONE) {
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
}
|
||||
currentItemViewHolder = viewHolder;
|
||||
// drawButtons(c, viewHolder);
|
||||
}
|
||||
|
||||
private void drawButtons(Canvas c, RecyclerView.ViewHolder viewHolder) {
|
||||
float buttonWidthWithoutPadding = buttonWidth - 20;
|
||||
float corners = 16;
|
||||
|
||||
View itemView = viewHolder.itemView;
|
||||
Paint p = new Paint();
|
||||
|
||||
// RectF leftButton = new RectF(itemView.getLeft(), itemView.getTop(), itemView.getLeft() + buttonWidthWithoutPadding, itemView.getBottom());
|
||||
// p.setColor(Color.BLUE);
|
||||
// c.drawRoundRect(leftButton, corners, corners, p);
|
||||
// drawText("EDIT", c, leftButton, p);
|
||||
|
||||
RectF rightButton = new RectF(itemView.getRight() - buttonWidthWithoutPadding, itemView.getTop(), itemView.getRight(), itemView.getBottom());
|
||||
p.setColor(Color.RED);
|
||||
c.drawRoundRect(rightButton, corners, corners, p);
|
||||
drawText("DELETE", c, rightButton, p);
|
||||
|
||||
buttonInstance = null;
|
||||
/* if (buttonShowedState == ButtonsState.LEFT_VISIBLE) {
|
||||
buttonInstance = leftButton;
|
||||
}
|
||||
else */if (buttonShowedState == ButtonsState.RIGHT_VISIBLE) {
|
||||
buttonInstance = rightButton;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void drawText(String text, Canvas c, RectF button, Paint p) {
|
||||
float textSize = 60;
|
||||
p.setColor(Color.WHITE);
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(textSize);
|
||||
|
||||
float textWidth = p.measureText(text);
|
||||
c.drawText(text, button.centerX()-(textWidth/2), button.centerY()+(textSize/2), p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void setTouchListener(final Canvas c,
|
||||
final RecyclerView recyclerView,
|
||||
final RecyclerView.ViewHolder viewHolder,
|
||||
final float dX, final float dY,
|
||||
final int actionState, final boolean isCurrentlyActive) {
|
||||
|
||||
recyclerView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
swipeBack = event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP;
|
||||
if (swipeBack) {
|
||||
if (dX < -buttonWidth) buttonShowedState = ButtonsState.RIGHT_VISIBLE;
|
||||
// else if (dX > buttonWidth) buttonShowedState = ButtonsState.LEFT_VISIBLE;
|
||||
|
||||
if (buttonShowedState != ButtonsState.GONE) {
|
||||
setTouchDownListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
setItemsClickable(recyclerView, false);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setTouchDownListener(final Canvas c,
|
||||
final RecyclerView recyclerView,
|
||||
final RecyclerView.ViewHolder viewHolder,
|
||||
final float dX, final float dY,
|
||||
final int actionState, final boolean isCurrentlyActive) {
|
||||
recyclerView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
setTouchUpListener(c, recyclerView, viewHolder, dX, dY,
|
||||
actionState, isCurrentlyActive);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setTouchUpListener(final Canvas c, final RecyclerView recyclerView,
|
||||
final RecyclerView.ViewHolder viewHolder,
|
||||
final float dX, final float dY,
|
||||
final int actionState, final boolean isCurrentlyActive) {
|
||||
recyclerView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
SwipeController.super.onChildDraw(c, recyclerView, viewHolder, 0F, dY, actionState, isCurrentlyActive);
|
||||
recyclerView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
setItemsClickable(recyclerView, true);
|
||||
swipeBack = false;
|
||||
if (buttonsActions != null && buttonInstance != null && buttonInstance.contains(event.getX(), event.getY())) {
|
||||
/*if (buttonShowedState == ButtonsState.LEFT_VISIBLE) {
|
||||
buttonsActions.onLeftClicked(viewHolder.getAdapterPosition());
|
||||
}
|
||||
else */if (buttonShowedState == ButtonsState.RIGHT_VISIBLE) {
|
||||
buttonsActions.onRightClicked(viewHolder.getAdapterPosition());
|
||||
}
|
||||
}
|
||||
|
||||
buttonShowedState = ButtonsState.GONE;
|
||||
currentItemViewHolder = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setItemsClickable(RecyclerView recyclerView, boolean isClickable) {
|
||||
for (int i = 0; i < recyclerView.getChildCount(); ++i) {
|
||||
recyclerView.getChildAt(i).setClickable(isClickable);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDraw(Canvas c) {
|
||||
if (currentItemViewHolder != null) {
|
||||
drawButtons(c, currentItemViewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package org.linphone.ui;
|
||||
|
||||
public abstract class SwipeControllerActions {
|
||||
// public void onLeftClicked(int position) {}
|
||||
|
||||
public void onRightClicked(int position) {}
|
||||
}
|
Loading…
Reference in a new issue