Changed long holding a post to an overflow button to view options

captchafix
Florens Douwes 11 years ago
parent d5b3372b1c
commit 78e3fe4763
  1. 109
      Clover/app/src/main/java/org/floens/chan/core/manager/ThreadManager.java
  2. 53
      Clover/app/src/main/java/org/floens/chan/ui/view/PostView.java
  3. BIN
      Clover/app/src/main/res/drawable-hdpi/ic_overflow.png
  4. BIN
      Clover/app/src/main/res/drawable-hdpi/ic_overflow_black.png
  5. BIN
      Clover/app/src/main/res/drawable-mdpi/ic_overflow.png
  6. BIN
      Clover/app/src/main/res/drawable-mdpi/ic_overflow_black.png
  7. BIN
      Clover/app/src/main/res/drawable-xhdpi/ic_overflow.png
  8. BIN
      Clover/app/src/main/res/drawable-xhdpi/ic_overflow_black.png
  9. BIN
      Clover/app/src/main/res/drawable-xxhdpi/ic_overflow.png
  10. BIN
      Clover/app/src/main/res/drawable-xxhdpi/ic_overflow_black.png
  11. 1
      Clover/app/src/main/res/values/strings.xml

@ -28,7 +28,10 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.PopupMenu;
import android.widget.Toast; import android.widget.Toast;
import com.android.volley.VolleyError; import com.android.volley.VolleyError;
@ -52,7 +55,6 @@ import org.floens.chan.utils.Logger;
import org.floens.chan.utils.Utils; import org.floens.chan.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -64,7 +66,7 @@ public class ThreadManager implements Loader.LoaderListener {
private static final String TAG = "ThreadManager"; private static final String TAG = "ThreadManager";
private final Activity activity; private final Activity activity;
private final ThreadManager.ThreadManagerListener threadManagerListener; private final ThreadManagerListener threadManagerListener;
private final List<RepliesPopup> popupQueue = new ArrayList<>(); private final List<RepliesPopup> popupQueue = new ArrayList<>();
private PostRepliesFragment currentPopupFragment; private PostRepliesFragment currentPopupFragment;
private int highlightedPost = -1; private int highlightedPost = -1;
@ -214,31 +216,31 @@ public class ThreadManager implements Loader.LoaderListener {
} }
} }
public void onPostLongClicked(final Post post) { public void showPostOptions(final Post post, PopupMenu popupMenu) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); Menu menu = popupMenu.getMenu();
List<String> options = new ArrayList<>(Arrays.asList(activity.getResources().getStringArray(R.array.post_options))); String[] baseOptions = activity.getResources().getStringArray(R.array.post_options);
for (int i = 0; i < baseOptions.length; i++) {
menu.add(Menu.NONE, i, Menu.NONE, baseOptions[i]);
}
final boolean id = !TextUtils.isEmpty(post.id); if (!TextUtils.isEmpty(post.id)) {
if (id) { menu.add(Menu.NONE, 5, Menu.NONE, activity.getString(R.string.post_highlight_id));
options.add(activity.getString(R.string.post_highlight_id));
} }
// Only add the delete option when the post is a saved reply // Only add the delete option when the post is a saved reply
final boolean delete = ChanApplication.getDatabaseManager().isSavedReply(post.board, post.no); if (ChanApplication.getDatabaseManager().isSavedReply(post.board, post.no)) {
if (delete) { menu.add(Menu.NONE, 6, Menu.NONE, activity.getString(R.string.delete));
options.add(activity.getString(R.string.delete));
} }
final boolean saved = ChanPreferences.getDeveloper(); if (ChanPreferences.getDeveloper()) {
if (saved) { menu.add(Menu.NONE, 7, Menu.NONE, "Make this a saved reply");
options.add("Make this a saved reply");
} }
builder.setItems(options.toArray(new String[options.size()]), new DialogInterface.OnClickListener() { popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public boolean onMenuItemClick(final MenuItem item) {
switch (which) { switch (item.getItemId()) {
case 0: // Quick reply case 0: // Quick reply
openReply(false); openReply(false);
// Pass through // Pass through
@ -254,38 +256,20 @@ public class ThreadManager implements Loader.LoaderListener {
case 4: // Copy text case 4: // Copy text
copyToClipboard(post.comment.toString()); copyToClipboard(post.comment.toString());
break; break;
default: case 5: // Id
// all optional, but with this order, starting at 5: highlightedId = post.id;
// id threadManagerListener.onRefreshView();
// delete break;
// saved case 6: // Delete
deletePost(post);
int idIndex = 5; break;
int deleteIndex = 5; case 7: // Save reply
int savedIndex = 5; ChanApplication.getDatabaseManager().saveReply(new SavedReply(post.board, post.no, "foo"));
break;
if (id) {
deleteIndex++;
savedIndex++;
}
if (delete) {
savedIndex++;
}
if (id && which == idIndex) {
highlightedId = post.id;
threadManagerListener.onRefreshView();
} else if (delete && which == deleteIndex) {
deletePost(post);
} else if (saved && which == savedIndex) {
ChanApplication.getDatabaseManager().saveReply(new SavedReply(post.board, post.no, "foo"));
}
} }
return false;
} }
}); });
builder.create().show();
} }
public void openReply(boolean startInActivity) { public void openReply(boolean startInActivity) {
@ -326,6 +310,7 @@ public class ThreadManager implements Loader.LoaderListener {
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Post text", comment); ClipData clip = ClipData.newPlainText("Post text", comment);
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Toast.makeText(activity, R.string.post_text_copied_to_clipboard, Toast.LENGTH_SHORT).show();
} }
private void showPostInfo(Post post) { private void showPostInfo(Post post) {
@ -369,9 +354,7 @@ public class ThreadManager implements Loader.LoaderListener {
} }
/** /**
* When the user clicks a post: a. when there's one linkable, open the * Show a list of things that can be clicked in a list to the user.
* linkable. b. when there's more than one linkable, show the user multiple
* options to select from.
* *
* @param post The post that was clicked. * @param post The post that was clicked.
*/ */
@ -380,24 +363,20 @@ public class ThreadManager implements Loader.LoaderListener {
final ArrayList<PostLinkable> linkables = post.linkables; final ArrayList<PostLinkable> linkables = post.linkables;
if (linkables.size() > 0) { if (linkables.size() > 0) {
if (linkables.size() == 1) { String[] keys = new String[linkables.size()];
handleLinkableSelected(linkables.get(0)); for (int i = 0; i < linkables.size(); i++) {
} else { keys[i] = linkables.get(i).key;
String[] keys = new String[linkables.size()]; }
for (int i = 0; i < linkables.size(); i++) {
keys[i] = linkables.get(i).key;
}
builder.setItems(keys, new DialogInterface.OnClickListener() { builder.setItems(keys, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
handleLinkableSelected(linkables.get(which)); handleLinkableSelected(linkables.get(which));
} }
}); });
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
dialog.show(); dialog.show();
}
} }
} }

@ -38,6 +38,8 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.android.volley.toolbox.NetworkImageView; import com.android.volley.toolbox.NetworkImageView;
@ -49,10 +51,11 @@ import org.floens.chan.core.manager.ThreadManager;
import org.floens.chan.core.model.Post; import org.floens.chan.core.model.Post;
import org.floens.chan.core.model.PostLinkable; import org.floens.chan.core.model.PostLinkable;
import org.floens.chan.utils.IconCache; import org.floens.chan.utils.IconCache;
import org.floens.chan.utils.ThemeHelper;
import org.floens.chan.utils.Time; import org.floens.chan.utils.Time;
import org.floens.chan.utils.Utils; import org.floens.chan.utils.Utils;
public class PostView extends LinearLayout implements View.OnClickListener, View.OnLongClickListener { public class PostView extends LinearLayout implements View.OnClickListener {
private final static LinearLayout.LayoutParams matchParams = new LinearLayout.LayoutParams( private final static LinearLayout.LayoutParams matchParams = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
private final static LinearLayout.LayoutParams wrapParams = new LinearLayout.LayoutParams( private final static LinearLayout.LayoutParams wrapParams = new LinearLayout.LayoutParams(
@ -78,6 +81,7 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
private ImageView stickyView; private ImageView stickyView;
private ImageView closedView; private ImageView closedView;
private NetworkImageView countryView; private NetworkImageView countryView;
private ImageView optionsView;
private View lastSeen; private View lastSeen;
private int thumbnailBackground; private int thumbnailBackground;
@ -181,7 +185,6 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
} }
commentView.setOnClickListener(this); commentView.setOnClickListener(this);
commentView.setOnLongClickListener(this);
if (manager.getLoadable().isThreadMode()) { if (manager.getLoadable().isThreadMode()) {
post.setLinkableListener(this); post.setLinkableListener(this);
@ -345,9 +348,12 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
int iconHeight = resources.getDimensionPixelSize(R.dimen.post_icon_height); int iconHeight = resources.getDimensionPixelSize(R.dimen.post_icon_height);
int imageSize = resources.getDimensionPixelSize(R.dimen.thumbnail_size); int imageSize = resources.getDimensionPixelSize(R.dimen.thumbnail_size);
RelativeLayout wrapper = new RelativeLayout(context);
wrapper.setLayoutParams(matchParams);
full = new LinearLayout(context); full = new LinearLayout(context);
full.setLayoutParams(matchParams);
full.setOrientation(HORIZONTAL); full.setOrientation(HORIZONTAL);
wrapper.addView(full, matchParams);
// Create thumbnail // Create thumbnail
imageView = new CustomNetworkImageView(context); imageView = new CustomNetworkImageView(context);
@ -375,6 +381,8 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
LinearLayout header = new LinearLayout(context); LinearLayout header = new LinearLayout(context);
header.setOrientation(HORIZONTAL); header.setOrientation(HORIZONTAL);
// 25 padding to give optionsView some space
header.setPadding(0, 0, Utils.dp(25), 0);
titleView = new TextView(context); titleView = new TextView(context);
titleView.setTextSize(14); titleView.setTextSize(14);
@ -424,10 +432,36 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
full.addView(right, matchWrapParams); full.addView(right, matchWrapParams);
addView(full, matchParams); optionsView = new ImageView(context);
optionsView.setImageResource(R.drawable.ic_overflow);
Utils.setPressedDrawable(optionsView);
optionsView.setPadding(Utils.dp(15), Utils.dp(5), Utils.dp(5), Utils.dp(15));
optionsView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
PopupMenu popupMenu = new PopupMenu(context, v);
manager.showPostOptions(post, popupMenu);
popupMenu.show();
if (ThemeHelper.getInstance().getTheme().isLightTheme) {
optionsView.setImageResource(R.drawable.ic_overflow_black);
popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(final PopupMenu menu) {
optionsView.setImageResource(R.drawable.ic_overflow);
}
});
}
}
});
wrapper.addView(optionsView, wrapParams);
RelativeLayout.LayoutParams optionsParams = (RelativeLayout.LayoutParams) optionsView.getLayoutParams();
optionsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
optionsParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
optionsView.setLayoutParams(optionsParams);
addView(wrapper, matchParams);
full.setOnClickListener(this); wrapper.setOnClickListener(this);
full.setOnLongClickListener(this);
} }
public void setOnClickListeners(View.OnClickListener listener) { public void setOnClickListeners(View.OnClickListener listener) {
@ -444,13 +478,6 @@ public class PostView extends LinearLayout implements View.OnClickListener, View
manager.onPostClicked(post); manager.onPostClicked(post);
} }
@Override
public boolean onLongClick(View v) {
manager.onPostLongClicked(post);
return true;
}
private class PostViewMovementMethod extends LinkMovementMethod { private class PostViewMovementMethod extends LinkMovementMethod {
@Override @Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

@ -87,6 +87,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<item>Copy text</item> <item>Copy text</item>
</string-array> </string-array>
<string name="post_highlight_id">Highlight ID</string> <string name="post_highlight_id">Highlight ID</string>
<string name="post_text_copied_to_clipboard">Text copied to clipboard</string>
<string name="reply">Reply to</string> <string name="reply">Reply to</string>
<string name="reply_to_board">Make thread in</string> <string name="reply_to_board">Make thread in</string>

Loading…
Cancel
Save