Browse Source

Post overflow improvements and fixes

pull/27/head
Apostolos Fanakis 7 years ago
parent
commit
9a7ab9f678
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  2. 85
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 0
      app/src/main/res/drawable-hdpi/ic_delete_accent.png
  4. BIN
      app/src/main/res/drawable-hdpi/ic_delete_white.png
  5. 0
      app/src/main/res/drawable-mdpi/ic_delete_accent.png
  6. BIN
      app/src/main/res/drawable-mdpi/ic_delete_white.png
  7. 0
      app/src/main/res/drawable-xhdpi/ic_delete_accent.png
  8. BIN
      app/src/main/res/drawable-xhdpi/ic_delete_white.png
  9. 0
      app/src/main/res/drawable-xxhdpi/ic_delete_accent.png
  10. BIN
      app/src/main/res/drawable-xxhdpi/ic_delete_white.png
  11. 0
      app/src/main/res/drawable-xxxhdpi/ic_delete_accent.png
  12. BIN
      app/src/main/res/drawable-xxxhdpi/ic_delete_white.png
  13. 37
      app/src/main/res/layout/activity_topic_overflow_menu.xml
  14. 2
      app/src/main/res/layout/fragment_bookmarks_board_row.xml
  15. 2
      app/src/main/res/layout/fragment_bookmarks_topic_row.xml
  16. 19
      app/src/main/res/menu/post_menu.xml

2
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;

85
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<RecyclerView.ViewHolder> {
}
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);
}
});

0
app/src/main/res/drawable-hdpi/ic_delete.png → app/src/main/res/drawable-hdpi/ic_delete_accent.png

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 198 B

BIN
app/src/main/res/drawable-hdpi/ic_delete_white.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

0
app/src/main/res/drawable-mdpi/ic_delete.png → app/src/main/res/drawable-mdpi/ic_delete_accent.png

Before

Width:  |  Height:  |  Size: 132 B

After

Width:  |  Height:  |  Size: 132 B

BIN
app/src/main/res/drawable-mdpi/ic_delete_white.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

0
app/src/main/res/drawable-xhdpi/ic_delete.png → app/src/main/res/drawable-xhdpi/ic_delete_accent.png

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

BIN
app/src/main/res/drawable-xhdpi/ic_delete_white.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

0
app/src/main/res/drawable-xxhdpi/ic_delete.png → app/src/main/res/drawable-xxhdpi/ic_delete_accent.png

Before

Width:  |  Height:  |  Size: 279 B

After

Width:  |  Height:  |  Size: 279 B

BIN
app/src/main/res/drawable-xxhdpi/ic_delete_white.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

0
app/src/main/res/drawable-xxxhdpi/ic_delete.png → app/src/main/res/drawable-xxxhdpi/ic_delete_accent.png

Before

Width:  |  Height:  |  Size: 357 B

After

Width:  |  Height:  |  Size: 357 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_delete_white.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

37
app/src/main/res/layout/activity_topic_overflow_menu.xml

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/post_share_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="?android:attr/selectableItemBackground"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_share"
android:gravity="center_vertical"
android:paddingBottom="6dp"
android:paddingEnd="12dp"
android:paddingStart="12dp"
android:paddingTop="6dp"
android:text="@string/post_share_button"
android:textColor="@color/primary_text" />
<TextView
android:id="@+id/delete_post"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:background="?android:attr/selectableItemBackground"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_delete_white"
android:gravity="center_vertical"
android:paddingBottom="6dp"
android:paddingEnd="12dp"
android:paddingStart="12dp"
android:paddingTop="6dp"
android:text="@string/post_delete_button"
android:textColor="@color/primary_text" />
</LinearLayout>

2
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"/>
</LinearLayout>

2
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"/>
</LinearLayout>

19
app/src/main/res/menu/post_menu.xml

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activities.topic.TopicActivity">
<item
android:id="@+id/post_share_button"
android:icon="@drawable/ic_share"
android:title="@string/post_share_button"
app:showAsAction="never" />
<item
android:id="@+id/delete_post"
android:icon="@drawable/ic_delete"
android:title="@string/post_delete_button"
app:showAsAction="never" />
</menu>
Loading…
Cancel
Save