From 9a7ab9f678263deac7617a910cd7588b7cdc3d38 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Mon, 9 Jul 2018 00:54:31 +0300 Subject: [PATCH] Post overflow improvements and fixes --- .../activities/settings/SettingsFragment.java | 2 - .../mthmmy/activities/topic/TopicAdapter.java | 85 ++++++++++-------- .../{ic_delete.png => ic_delete_accent.png} | Bin .../res/drawable-hdpi/ic_delete_white.png | Bin 0 -> 189 bytes .../{ic_delete.png => ic_delete_accent.png} | Bin .../res/drawable-mdpi/ic_delete_white.png | Bin 0 -> 129 bytes .../{ic_delete.png => ic_delete_accent.png} | Bin .../res/drawable-xhdpi/ic_delete_white.png | Bin 0 -> 192 bytes .../{ic_delete.png => ic_delete_accent.png} | Bin .../res/drawable-xxhdpi/ic_delete_white.png | Bin 0 -> 277 bytes .../{ic_delete.png => ic_delete_accent.png} | Bin .../res/drawable-xxxhdpi/ic_delete_white.png | Bin 0 -> 353 bytes .../layout/activity_topic_overflow_menu.xml | 37 ++++++++ .../layout/fragment_bookmarks_board_row.xml | 2 +- .../layout/fragment_bookmarks_topic_row.xml | 2 +- app/src/main/res/menu/post_menu.xml | 19 ---- 16 files changed, 88 insertions(+), 59 deletions(-) rename app/src/main/res/drawable-hdpi/{ic_delete.png => ic_delete_accent.png} (100%) create mode 100644 app/src/main/res/drawable-hdpi/ic_delete_white.png rename app/src/main/res/drawable-mdpi/{ic_delete.png => ic_delete_accent.png} (100%) create mode 100644 app/src/main/res/drawable-mdpi/ic_delete_white.png rename app/src/main/res/drawable-xhdpi/{ic_delete.png => ic_delete_accent.png} (100%) create mode 100644 app/src/main/res/drawable-xhdpi/ic_delete_white.png rename app/src/main/res/drawable-xxhdpi/{ic_delete.png => ic_delete_accent.png} (100%) create mode 100644 app/src/main/res/drawable-xxhdpi/ic_delete_white.png rename app/src/main/res/drawable-xxxhdpi/{ic_delete.png => ic_delete_accent.png} (100%) create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_delete_white.png create mode 100644 app/src/main/res/layout/activity_topic_overflow_menu.xml delete mode 100644 app/src/main/res/menu/post_menu.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java index cd34473e..c0cf9c3b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java @@ -12,11 +12,9 @@ import android.support.annotation.NonNull; import android.support.v7.preference.ListPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceFragmentCompat; -import android.util.Log; import android.view.View; import java.util.ArrayList; -import java.util.Arrays; import gr.thmmy.mthmmy.R; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index c1516327..345f9c5b 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.activities.topic; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.graphics.Typeface; @@ -11,19 +12,13 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.view.menu.MenuBuilder; -import android.support.v7.view.menu.MenuPopupHelper; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.AppCompatImageButton; -import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; -import android.view.Gravity; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; @@ -34,6 +29,7 @@ import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.PopupWindow; import android.widget.RelativeLayout; import android.widget.TextView; @@ -422,43 +418,60 @@ class TopicAdapter extends RecyclerView.Adapter { } holder.overflowButton.setOnClickListener(new View.OnClickListener() { - @SuppressLint("RestrictedApi") @Override public void onClick(View view) { - //Inflates menu - PopupMenu popup = new PopupMenu(holder.overflowButton.getContext(), holder.overflowButton, Gravity.END); - MenuInflater inflater = popup.getMenuInflater(); - inflater.inflate(R.menu.post_menu, popup.getMenu()); - - Menu popupMenu = popup.getMenu(); - if(currentPost.getPostDeleteURL() == null || currentPost.getPostDeleteURL().equals("")){ - popupMenu.findItem(R.id.delete_post).setEnabled(false); - popupMenu.findItem(R.id.delete_post).setVisible(false); + //Inflates the popup menu content + LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + if (layoutInflater == null) { + return; } + View popUpContent = layoutInflater.inflate(R.layout.activity_topic_overflow_menu, null); - MenuPopupHelper optionsMenu = new MenuPopupHelper(holder.overflowButton.getContext() - , new MenuBuilder(holder.overflowButton.getContext()), holder.overflowButton); - optionsMenu.setForceShowIcon(true); + //Creates the PopupWindow + final PopupWindow popUp = new PopupWindow(holder.overflowButton.getContext()); + popUp.setContentView(popUpContent); + popUp.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT); + popUp.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT); + popUp.setFocusable(true); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + popUpContent.findViewById(R.id.post_share_button).setOnClickListener(new View.OnClickListener() { @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.post_share_button: - Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); - sendIntent.setType("text/plain"); - sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, currentPost.getPostURL()); - context.startActivity(Intent.createChooser(sendIntent, "Share via")); - return true; - case R.id.delete_post: - deleteTask.execute(currentPost.getPostDeleteURL()); - return true; - default: - } - return false; + public void onClick(View v) { + Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); + sendIntent.setType("text/plain"); + sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, currentPost.getPostURL()); + context.startActivity(Intent.createChooser(sendIntent, "Share via")); + popUp.dismiss(); } }); - popup.show(); + + TextView deletePostButton = popUpContent.findViewById(R.id.delete_post); + + if (currentPost.getPostDeleteURL() == null || currentPost.getPostDeleteURL().equals("")) { + deletePostButton.setVisibility(View.GONE); + } else { + popUpContent.findViewById(R.id.delete_post).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new AlertDialog.Builder(holder.overflowButton.getContext()) + .setTitle("Delete post") + .setMessage("Do you really want to delete this post?") + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int whichButton) { + deleteTask.execute(currentPost.getPostDeleteURL()); + } + }) + .setNegativeButton(android.R.string.no, null).show(); + popUp.dismiss(); + } + }); + } + + //Displays the popup + popUp.showAsDropDown(holder.overflowButton); } }); diff --git a/app/src/main/res/drawable-hdpi/ic_delete.png b/app/src/main/res/drawable-hdpi/ic_delete_accent.png similarity index 100% rename from app/src/main/res/drawable-hdpi/ic_delete.png rename to app/src/main/res/drawable-hdpi/ic_delete_accent.png diff --git a/app/src/main/res/drawable-hdpi/ic_delete_white.png b/app/src/main/res/drawable-hdpi/ic_delete_white.png new file mode 100644 index 0000000000000000000000000000000000000000..5e89821e2af31cfdba2c634963a9da8e16f7d532 GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbBT0C7GLn>~)y|IzA!9bw(q4r%z zb;0sYzLm+T9EB1auYP9QCe(3W;DhX+yPfgMDqS-@y*VB08B60nd|6oVK7?_pxa(A($Hd7@j#ag)w9}HmT*;H{RSMSX(T+XXk^2 i`SV`>{NB7ED)uqcqs8pc7+QetVeoYIb6Mw<&;$TT;YFta literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_delete.png b/app/src/main/res/drawable-mdpi/ic_delete_accent.png similarity index 100% rename from app/src/main/res/drawable-mdpi/ic_delete.png rename to app/src/main/res/drawable-mdpi/ic_delete_accent.png diff --git a/app/src/main/res/drawable-mdpi/ic_delete_white.png b/app/src/main/res/drawable-mdpi/ic_delete_white.png new file mode 100644 index 0000000000000000000000000000000000000000..8d48b838421fabf12a517dfcf6d199a029d915e2 GIT binary patch literal 129 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`Gj9-c0aAr-fhfBgS%&#Y^BxMPC@ zV~6~o<1G9Oic%sS^dxM=E~xTpl>J@7x>&3y${>qTRHwqV>7o9KjR)jA;)ODIyg#vS cvgRR%){Bkmxw=1(0L^6ZboFyt=akR{0D*!lZU6uP literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_delete.png b/app/src/main/res/drawable-xhdpi/ic_delete_accent.png similarity index 100% rename from app/src/main/res/drawable-xhdpi/ic_delete.png rename to app/src/main/res/drawable-xhdpi/ic_delete_accent.png diff --git a/app/src/main/res/drawable-xhdpi/ic_delete_white.png b/app/src/main/res/drawable-xhdpi/ic_delete_white.png new file mode 100644 index 0000000000000000000000000000000000000000..3c9e171869415b851787451c4478683af11260be GIT binary patch literal 192 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUtc25__kcwMxZ#Z%_81T4UoU^Rr z%)J#a4!T^ZU9+HC+gIu#d)oD*Hc=WbA))_d7=bz()Fbcv_pxPY-WR=CbfcPqp@Z## zdYV_o?42%$|BzZo3TBA~9ds XvW#Wx(i!q6Kn8fa`njxgN@xNA9}hlj literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_delete.png b/app/src/main/res/drawable-xxhdpi/ic_delete_accent.png similarity index 100% rename from app/src/main/res/drawable-xxhdpi/ic_delete.png rename to app/src/main/res/drawable-xxhdpi/ic_delete_accent.png diff --git a/app/src/main/res/drawable-xxhdpi/ic_delete_white.png b/app/src/main/res/drawable-xxhdpi/ic_delete_white.png new file mode 100644 index 0000000000000000000000000000000000000000..5d2e8ea3b964d302f8490b809af9783495795b09 GIT binary patch literal 277 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!cRXDjLn>~)y=}c6k6>e7 zW5ccvhv^Ou%R3x)-!W!5XM5d^Maue#+|VASw*aSW-r_4dwL-X;Tvw#2+0 zJcX`h0m_#pmLJ&B8Mi|9An%qh&lM}zAFJu#IOkTYfYsaSf(#4-3=B*R4h#$&KqEMk zfBZFOx{?1UM=(mt-n-@6vGaTn<>jM(GXt%G14ae~28LI*QyAeQ)L=A-G2CPA|G$dy zL8QTf80G_86B>ef8IIowdhp|Qxm*@Q#B44Wi{&@eL=PyI>1X_jUbCL_LAOEbzw#|P z`~TQo)vLZUb>}?J={J(A&z^o5T6~Z1j^bB2J^#{TJqECYSr{6Co^2@m#jrL;=-j66 R)>9x?d%F6$taD0e0su-yVuAnw literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_topic_overflow_menu.xml b/app/src/main/res/layout/activity_topic_overflow_menu.xml new file mode 100644 index 00000000..9ea4b0d2 --- /dev/null +++ b/app/src/main/res/layout/activity_topic_overflow_menu.xml @@ -0,0 +1,37 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bookmarks_board_row.xml b/app/src/main/res/layout/fragment_bookmarks_board_row.xml index 621f218e..3f381a91 100644 --- a/app/src/main/res/layout/fragment_bookmarks_board_row.xml +++ b/app/src/main/res/layout/fragment_bookmarks_board_row.xml @@ -33,5 +33,5 @@ android:layout_marginEnd="12dp" android:background="@android:color/transparent" android:contentDescription="@string/remove_bookmark" - android:src="@drawable/ic_delete"/> + android:src="@drawable/ic_delete_accent"/> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bookmarks_topic_row.xml b/app/src/main/res/layout/fragment_bookmarks_topic_row.xml index 2708318e..c2d9ce68 100644 --- a/app/src/main/res/layout/fragment_bookmarks_topic_row.xml +++ b/app/src/main/res/layout/fragment_bookmarks_topic_row.xml @@ -46,5 +46,5 @@ android:layout_marginEnd="12dp" android:background="@android:color/transparent" android:contentDescription="@string/remove_bookmark" - android:src="@drawable/ic_delete"/> + android:src="@drawable/ic_delete_accent"/> \ No newline at end of file diff --git a/app/src/main/res/menu/post_menu.xml b/app/src/main/res/menu/post_menu.xml deleted file mode 100644 index fcfb9322..00000000 --- a/app/src/main/res/menu/post_menu.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - \ No newline at end of file