From 2b8b432c421b5a2b4526b089886fd581a91fc788 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Tue, 31 Jul 2018 18:46:55 +0300 Subject: [PATCH] PR merge fix, Fix for vector drawables --- .../activities/topic/TopicActivity.java | 1 + .../mthmmy/activities/topic/TopicAdapter.java | 103 ++++++++---------- .../layout/activity_topic_overflow_menu.xml | 1 - 3 files changed, 46 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index 3da39de4..e2f92054 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -7,6 +7,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.Rect; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; 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 c4d0e71b..1bc85acc 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 @@ -350,40 +350,36 @@ class TopicAdapter extends RecyclerView.Adapter { holder.header.setOnClickListener(null); holder.userExtraInfo.setOnClickListener(null); } - - holder.overflowButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - //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); - - //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); - - TextView shareButton = popUpContent.findViewById(R.id.post_share_button); - Drawable shareStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_share_white_24dp); - shareButton.setCompoundDrawablesRelativeWithIntrinsicBounds(shareStartDrawable, null, null, null); - shareButton.setOnClickListener(new View.OnClickListener() { - @Override - 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(); - } - }); + + holder.overflowButton.setOnClickListener(view -> { + //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); + + //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); + + TextView shareButton = popUpContent.findViewById(R.id.post_share_button); + Drawable shareStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_share_white_24dp); + shareButton.setCompoundDrawablesRelativeWithIntrinsicBounds(shareStartDrawable, null, null, null); + shareButton.setOnClickListener(v -> { + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.setType("text/plain"); + sendIntent.putExtra(Intent.EXTRA_TEXT, currentPost.getPostURL()); + context.startActivity(Intent.createChooser(sendIntent, "Share via")); + popUp.dismiss(); + }); final TextView editPostButton = popUpContent.findViewById(R.id.edit_post); + Drawable editStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_edit_white_24dp); + editPostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(editStartDrawable, null, null, null); if (viewModel.isEditingPost() || currentPost.getPostEditURL() == null || currentPost.getPostEditURL().equals("")) { editPostButton.setVisibility(View.GONE); @@ -393,33 +389,24 @@ class TopicAdapter extends RecyclerView.Adapter { popUp.dismiss(); }); } - - TextView deletePostButton = popUpContent.findViewById(R.id.delete_post); - - if (currentPost.getPostDeleteURL() == null || currentPost.getPostDeleteURL().equals("")) { - deletePostButton.setVisibility(View.GONE); - } else { - Drawable deleteStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_delete_white_24dp); - deletePostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(deleteStartDrawable, null, null, null); - 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(); - } - }); - } + + TextView deletePostButton = popUpContent.findViewById(R.id.delete_post); + + if (currentPost.getPostDeleteURL() == null || currentPost.getPostDeleteURL().equals("")) { + deletePostButton.setVisibility(View.GONE); + } else { + Drawable deleteStartDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_delete_white_24dp); + deletePostButton.setCompoundDrawablesRelativeWithIntrinsicBounds(deleteStartDrawable, null, null, null); + popUpContent.findViewById(R.id.delete_post).setOnClickListener(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, (dialog, whichButton) -> viewModel.deletePost(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/layout/activity_topic_overflow_menu.xml b/app/src/main/res/layout/activity_topic_overflow_menu.xml index 95492862..192e3e58 100644 --- a/app/src/main/res/layout/activity_topic_overflow_menu.xml +++ b/app/src/main/res/layout/activity_topic_overflow_menu.xml @@ -38,7 +38,6 @@ android:layout_height="35dp" android:background="?android:attr/selectableItemBackground" android:drawablePadding="5dp" - android:drawableStart="@drawable/ic_edit_white_24dp" android:gravity="center_vertical" android:paddingBottom="6dp" android:paddingEnd="12dp"