From d6dcf28d8926a34a828c5b88b61c689001614bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Tue, 11 Dec 2018 13:22:39 +0100 Subject: [PATCH] Share+Delete Button --- android/.idea/assetWizardSettings.xml | 4 +- .../simplecloudnotifier/SCNApp.java | 2 - .../model/SCNSettings.java | 2 +- .../view/MessageAdapter.java | 62 +++++++++++++++---- .../view/NotificationsFragment.java | 23 ++++--- .../src/main/res/drawable/ic_share_small.xml | 10 +++ .../src/main/res/drawable/ic_trash_small.xml | 16 +++++ .../app/src/main/res/layout/activity_main.xml | 6 +- .../src/main/res/layout/fragment_account.xml | 12 +++- .../src/main/res/layout/fragment_settings.xml | 4 +- .../app/src/main/res/layout/message_card.xml | 37 +++++++++++ android/app/src/main/res/values/styles.xml | 4 +- 12 files changed, 146 insertions(+), 36 deletions(-) create mode 100644 android/app/src/main/res/drawable/ic_share_small.xml create mode 100644 android/app/src/main/res/drawable/ic_trash_small.xml diff --git a/android/.idea/assetWizardSettings.xml b/android/.idea/assetWizardSettings.xml index 48cc759..84ee715 100644 --- a/android/.idea/assetWizardSettings.xml +++ b/android/.idea/assetWizardSettings.xml @@ -67,8 +67,8 @@ diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java index 8851225..6721fb0 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/SCNApp.java @@ -100,7 +100,5 @@ public class SCNApp extends Application implements LifecycleObserver } } -//TODO: Share button on expand -//TODO: Delete button on expand //TODO: Config for collapsed line count //TODO: Sometimes ads but promode diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java index aeceb4d..029d1ce 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/model/SCNSettings.java @@ -52,7 +52,7 @@ public class SCNSettings public boolean Enabled = true; public int LocalCacheSize = 500; - public boolean EnableDeleteSwipe = true; + public boolean EnableDeleteSwipe = false; public final NotificationSettings PriorityLow = new NotificationSettings(PriorityEnum.LOW); public final NotificationSettings PriorityNorm = new NotificationSettings(PriorityEnum.NORMAL); diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java index 834e98e..21cb332 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/MessageAdapter.java @@ -1,5 +1,6 @@ package com.blackforestbytes.simplecloudnotifier.view; +import android.content.Intent; import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; @@ -9,8 +10,10 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.blackforestbytes.simplecloudnotifier.R; +import com.blackforestbytes.simplecloudnotifier.SCNApp; import com.blackforestbytes.simplecloudnotifier.model.CMessage; import com.blackforestbytes.simplecloudnotifier.model.CMessageList; +import com.google.android.material.button.MaterialButton; import java.lang.ref.WeakReference; import java.util.Collections; @@ -53,7 +56,7 @@ public class MessageAdapter extends RecyclerView.Adapter { CMessage msg = CMessageList.inst().tryGetFromBack(position); MessagePresenter view = (MessagePresenter) holder; - view.setMessage(msg); + view.setMessage(msg, position); viewHolders.put(view, true); } @@ -110,7 +113,11 @@ public class MessageAdapter extends RecyclerView.Adapter public RelativeLayout viewForeground; public RelativeLayout viewBackground; + public MaterialButton btnShare; + public MaterialButton btnDelete; + private CMessage data; + private int datapos; MessagePresenter(View itemView) { @@ -121,6 +128,8 @@ public class MessageAdapter extends RecyclerView.Adapter ivPriority = itemView.findViewById(R.id.ivPriority); viewForeground = itemView.findViewById(R.id.layoutFront); viewBackground = itemView.findViewById(R.id.layoutBack); + btnShare = itemView.findViewById(R.id.btnShare); + btnDelete = itemView.findViewById(R.id.btnDelete); itemView.setOnClickListener(this); tvTimestamp.setOnClickListener(this); @@ -128,16 +137,27 @@ public class MessageAdapter extends RecyclerView.Adapter tvMessage.setOnClickListener(this); ivPriority.setOnClickListener(this); viewForeground.setOnClickListener(this); + + btnShare.setOnClickListener(v -> + { + if (data == null) return; + Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); + sharingIntent.setType("text/plain"); + sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, data.Title); + sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, data.Content); + SCNApp.getMainActivity().startActivity(Intent.createChooser(sharingIntent, "Share message")); + + }); + btnDelete.setOnClickListener(v -> { if (data != null) SCNApp.getMainActivity().adpTabs.tab1.deleteMessage(datapos); }); + } - void setMessage(CMessage msg) + void setMessage(CMessage msg, int pos) { tvTimestamp.setText(msg.formatTimestamp()); tvTitle.setText(msg.Title); tvMessage.setText(msg.Content); - tvMessage.setMaxLines(msg.IsExpandedInAdapter ? 999 : 6); - switch (msg.Priority) { case LOW: @@ -157,6 +177,28 @@ public class MessageAdapter extends RecyclerView.Adapter } data = msg; + datapos = pos; + + if (msg.IsExpandedInAdapter) expand(true); else collapse(true); + } + + private void expand(boolean force) + { + if (data != null && data.IsExpandedInAdapter && !force) return; + if (data != null) data.IsExpandedInAdapter = true; + if (tvMessage != null) tvMessage.setMaxLines(999); + if (btnDelete != null) btnDelete.setVisibility(View.VISIBLE); + if (btnShare != null) btnShare.setVisibility(View.VISIBLE); + + } + + private void collapse(boolean force) + { + if (data != null && !data.IsExpandedInAdapter && !force) return; + if (data != null) data.IsExpandedInAdapter = false; + if (tvMessage != null) tvMessage.setMaxLines(6); + if (btnDelete != null) btnDelete.setVisibility(View.GONE); + if (btnShare != null) btnShare.setVisibility(View.GONE); } @Override @@ -164,8 +206,7 @@ public class MessageAdapter extends RecyclerView.Adapter { if (data.IsExpandedInAdapter) { - data.IsExpandedInAdapter=false; - tvMessage.setMaxLines(6); + collapse(false); return; } @@ -173,15 +214,10 @@ public class MessageAdapter extends RecyclerView.Adapter { if (holder == null) continue; if (holder == this) continue; - if (holder.tvMessage == null) continue; - if (!holder.data.IsExpandedInAdapter) continue; - - holder.data.IsExpandedInAdapter=false; - holder.tvMessage.setMaxLines(6); + holder.collapse(false); } - data.IsExpandedInAdapter=true; - tvMessage.setMaxLines(9999); + expand(false); } } } diff --git a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java index d9b0c51..839b6c1 100644 --- a/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java +++ b/android/app/src/main/java/com/blackforestbytes/simplecloudnotifier/view/NotificationsFragment.java @@ -66,18 +66,23 @@ public class NotificationsFragment extends Fragment implements MessageAdapterTou { if (viewHolder instanceof MessageAdapter.MessagePresenter) { - final int deletedIndex = viewHolder.getAdapterPosition(); - - final CMessage deletedItem = adpMessages.removeItem(viewHolder.getAdapterPosition()); - String name = deletedItem.Title; - - Snackbar snackbar = Snackbar.make(SCNApp.getMainActivity().layoutRoot, name + " removed", Snackbar.LENGTH_LONG); - snackbar.setAction("UNDO", view -> adpMessages.restoreItem(deletedItem, deletedIndex)); - snackbar.setActionTextColor(Color.YELLOW); - snackbar.show(); + deleteMessage(viewHolder.getAdapterPosition()); } } + public void deleteMessage(int pos) + { + final int deletedIndex = pos; + + final CMessage deletedItem = adpMessages.removeItem(pos); + String name = deletedItem.Title; + + Snackbar snackbar = Snackbar.make(SCNApp.getMainActivity().layoutRoot, name + " removed", Snackbar.LENGTH_LONG); + snackbar.setAction("UNDO", view -> adpMessages.restoreItem(deletedItem, deletedIndex)); + snackbar.setActionTextColor(Color.YELLOW); + snackbar.show(); + } + public void updateDeleteSwipeEnabled() { if (touchHelper != null) touchHelper.updateEnabled(); diff --git a/android/app/src/main/res/drawable/ic_share_small.xml b/android/app/src/main/res/drawable/ic_share_small.xml new file mode 100644 index 0000000..e50133f --- /dev/null +++ b/android/app/src/main/res/drawable/ic_share_small.xml @@ -0,0 +1,10 @@ + + + diff --git a/android/app/src/main/res/drawable/ic_trash_small.xml b/android/app/src/main/res/drawable/ic_trash_small.xml new file mode 100644 index 0000000..6c2b5b9 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_trash_small.xml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index 71dc8ea..7742e58 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -12,8 +12,7 @@ android:layout_alignParentTop="true" android:background="?attr/colorPrimary" android:elevation="6dp" - android:minHeight="?attr/actionBarSize" - android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> + android:minHeight="?attr/actionBarSize" /> + android:minHeight="?attr/actionBarSize" /> -