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 00000000..5e89821e Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_delete_white.png differ 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 00000000..8d48b838 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_delete_white.png differ 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 00000000..3c9e1718 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_delete_white.png differ 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 00000000..5d2e8ea3 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_delete_white.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_delete.png b/app/src/main/res/drawable-xxxhdpi/ic_delete_accent.png similarity index 100% rename from app/src/main/res/drawable-xxxhdpi/ic_delete.png rename to app/src/main/res/drawable-xxxhdpi/ic_delete_accent.png diff --git a/app/src/main/res/drawable-xxxhdpi/ic_delete_white.png b/app/src/main/res/drawable-xxxhdpi/ic_delete_white.png new file mode 100644 index 00000000..e7b2514d Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_delete_white.png differ 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