From 792e3cc3d2eab8c89cc980bdf9d94b0b75f16acc Mon Sep 17 00:00:00 2001 From: benjamin stephan Date: Fri, 27 Nov 2015 15:36:02 +0100 Subject: [PATCH] Integrated longclick-handling on NewsReaderList-Items --- .../SubscriptionExpandableListAdapter.java | 42 ++++++++++++++----- .../NewsReaderListActivity.java | 15 +++++++ .../NewsReaderListFragment.java | 39 ++++++++++++++++- .../interfaces/ExpListTextClicked.java | 1 + 4 files changed, 84 insertions(+), 13 deletions(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java index 3f4bc8dd..ceb57f1b 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java @@ -249,25 +249,40 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter viewHolder = (GroupHolder) convertView.getTag(); } - viewHolder.txt_Summary.setText(group.header); viewHolder.listItemLayout.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { + @Override + public void onClick(View v) { - long idFeed = group.id_database; - boolean skipFireEvent = false; + long idFeed = group.id_database; + boolean skipFireEvent = false; - if(group instanceof ConcreteFeedItem) { + if (group instanceof ConcreteFeedItem) { fireListTextClicked(idFeed, false, (long) ITEMS_WITHOUT_FOLDER.getValue()); skipFireEvent = true; - } + } - if(!skipFireEvent) - fireListTextClicked(idFeed, true, ((FolderSubscribtionItem) group).idFolder); - } - }); + if (!skipFireEvent) + fireListTextClicked(idFeed, true, ((FolderSubscribtionItem) group).idFolder); + } + }); + + viewHolder.listItemLayout.setOnLongClickListener(new View.OnLongClickListener() { + + @Override + public boolean onLongClick(View v) { + + long idFeed = group.id_database; + + if (group instanceof ConcreteFeedItem) { + fireListTextLongClicked(idFeed, false, (long) ITEMS_WITHOUT_FOLDER.getValue()); + } else { + fireListTextLongClicked(idFeed, true, ((FolderSubscribtionItem) group).idFolder); + } + return true; //consume event + } + }); viewHolder.txt_UnreadCount.setText(""); @@ -609,4 +624,9 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter if(eListTextClickHandler != null) eListTextClickHandler.onTextClicked(idFeed, isFolder, optional_folder_id); } + protected void fireListTextLongClicked(long idFeed, boolean isFolder, Long optional_folder_id) + { + if(eListTextClickHandler != null) + eListTextClickHandler.onTextLongClicked(idFeed, isFolder, optional_folder_id); + } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index adbc2888..3098cabf 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -583,6 +583,21 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements StartDetailFragment(idFeed, false, optional_folder_id, true); } + @Override + public void onTopItemLongClicked(long idFeed, boolean isFolder, Long optional_folder_id) { + if(isFolder) { + //top-folder long-clicked + } else { + //top-item long-clicked + } + } + + @Override + public void onChildItemLongClicked(long idFeed, Long optional_folder_id) { + //child-item long-clicked + + } + private NewsReaderDetailFragment StartDetailFragment(long id, Boolean folder, Long optional_folder_id, boolean updateListView) { if(menuItemDownloadMoreItems != null) { diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java index 8b7f9a4a..1e99dd6e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java @@ -31,6 +31,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnCreateContextMenuListener; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.ImageView; @@ -95,6 +96,8 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM */ void onChildItemClicked(long idFeed, Long optional_folder_id); void onTopItemClicked(long idFeed, boolean isFolder, Long optional_folder_id); + void onChildItemLongClicked(long idFeed, Long optional_folder_id); + void onTopItemLongClicked(long idFeed, boolean isFolder, Long optional_folder_id); } @@ -131,8 +134,10 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM eListView.setGroupIndicator(null); eListView.setOnChildClickListener(onChildClickListener); + eListView.setOnItemLongClickListener(onItemLongClickListener); eListView.setClickable(true); + eListView.setLongClickable(true); eListView.setAdapter(lvAdapter); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); @@ -178,9 +183,15 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM @Override public void onTextClicked(long idFeed, boolean isFolder, Long optional_folder_id) { - mCallbacks.onTopItemClicked(idFeed, isFolder, optional_folder_id); + mCallbacks.onTopItemClicked(idFeed, isFolder, optional_folder_id); } - }; + + @Override + public void onTextLongClicked(long idFeed, boolean isFolder, Long optional_folder_id) { + mCallbacks.onTopItemLongClicked(idFeed, isFolder, optional_folder_id); + } + + }; OnChildClickListener onChildClickListener = new OnChildClickListener() { @@ -200,4 +211,28 @@ public class NewsReaderListFragment extends Fragment implements OnCreateContextM return false; } }; + + AdapterView.OnItemLongClickListener onItemLongClickListener = new AdapterView.OnItemLongClickListener() { + + @Override + public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { + if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { + + int groupPosition = ExpandableListView.getPackedPositionGroup(id); + int childPosition = ExpandableListView.getPackedPositionChild(id); + + long idItem = lvAdapter.getChildId(groupPosition, childPosition); + + Long optional_id_folder = null; + FolderSubscribtionItem groupItem = (FolderSubscribtionItem) lvAdapter.getGroup(groupPosition); + if(groupItem != null) + optional_id_folder = groupItem.id_database; + + mCallbacks.onChildItemLongClicked(idItem, optional_id_folder); + } + + return false; + } + }; + } \ No newline at end of file diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/ExpListTextClicked.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/ExpListTextClicked.java index 904b4b96..10a20595 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/ExpListTextClicked.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/interfaces/ExpListTextClicked.java @@ -23,4 +23,5 @@ package de.luhmer.owncloudnewsreader.interfaces; public interface ExpListTextClicked { void onTextClicked(long idFeed, boolean isFolder, Long optional_folder_id); + void onTextLongClicked(long idFeed, boolean isFolder, Long optional_folder_id); }