From 0e9d85e7ae8b79312846e34ced167cee23518810 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 3 Sep 2018 10:56:12 +0200 Subject: [PATCH] Some cleanup --- .../org/linphone/call/CallHistoryAdapter.java | 28 ++- .../org/linphone/chat/ChatListFragment.java | 64 +---- .../contacts/ContactsListAdapter.java | 28 ++- .../contacts/ContactsListFragment.java | 16 +- .../fragments/HistoryListFragment.java | 7 +- .../org/linphone/ui/SelectableAdapter.java | 19 ++ .../org/linphone/ui/SelectableHelper.java | 4 - .../org/linphone/ui/SwipeController.java | 220 ------------------ .../linphone/ui/SwipeControllerActions.java | 7 - 9 files changed, 64 insertions(+), 329 deletions(-) delete mode 100644 src/android/org/linphone/ui/SwipeController.java delete mode 100644 src/android/org/linphone/ui/SwipeControllerActions.java diff --git a/src/android/org/linphone/call/CallHistoryAdapter.java b/src/android/org/linphone/call/CallHistoryAdapter.java index c55137f0e..c0cf045d0 100644 --- a/src/android/org/linphone/call/CallHistoryAdapter.java +++ b/src/android/org/linphone/call/CallHistoryAdapter.java @@ -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 mLogs; @@ -110,8 +126,6 @@ public class CallHistoryAdapter extends SelectableAdapter 0) { CallLog previousLog = mLogs.get(position-1); long previousTimestamp = previousLog.getStartDate() * 1000; @@ -141,7 +154,6 @@ public class CallHistoryAdapter extends SelectableAdapter contacts; @@ -92,8 +108,6 @@ public class ContactsListAdapter extends SelectableAdapter= getItemCount()) return null; return contacts.get(position); @@ -154,8 +166,6 @@ public class ContactsListAdapter extends SelectableAdapter contactsList) { contacts = contactsList; diff --git a/src/android/org/linphone/contacts/ContactsListFragment.java b/src/android/org/linphone/contacts/ContactsListFragment.java index 3e2aa6f15..017099c20 100644 --- a/src/android/org/linphone/contacts/ContactsListFragment.java +++ b/src/android/org/linphone/contacts/ContactsListFragment.java @@ -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); } - - - } diff --git a/src/android/org/linphone/fragments/HistoryListFragment.java b/src/android/org/linphone/fragments/HistoryListFragment.java index 8371f5f1e..af8c16fa0 100644 --- a/src/android/org/linphone/fragments/HistoryListFragment.java +++ b/src/android/org/linphone/fragments/HistoryListFragment.java @@ -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; diff --git a/src/android/org/linphone/ui/SelectableAdapter.java b/src/android/org/linphone/ui/SelectableAdapter.java index cd3dc26ee..d94e18b8d 100644 --- a/src/android/org/linphone/ui/SelectableAdapter.java +++ b/src/android/org/linphone/ui/SelectableAdapter.java @@ -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; diff --git a/src/android/org/linphone/ui/SelectableHelper.java b/src/android/org/linphone/ui/SelectableHelper.java index 33af0296a..ef853b99e 100644 --- a/src/android/org/linphone/ui/SelectableHelper.java +++ b/src/android/org/linphone/ui/SelectableHelper.java @@ -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); diff --git a/src/android/org/linphone/ui/SwipeController.java b/src/android/org/linphone/ui/SwipeController.java deleted file mode 100644 index 20e1458c4..000000000 --- a/src/android/org/linphone/ui/SwipeController.java +++ /dev/null @@ -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); - } - } - -} diff --git a/src/android/org/linphone/ui/SwipeControllerActions.java b/src/android/org/linphone/ui/SwipeControllerActions.java deleted file mode 100644 index d34dd0e64..000000000 --- a/src/android/org/linphone/ui/SwipeControllerActions.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.linphone.ui; - -public abstract class SwipeControllerActions { -// public void onLeftClicked(int position) {} - - public void onRightClicked(int position) {} -}