diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index 4bc402d09..6ca095180 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -29,12 +29,14 @@ import android.os.Build; import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v7.widget.CardView; +import android.support.v7.widget.PopupMenu; import android.text.Html; import android.text.SpannableString; import android.text.method.LinkMovementMethod; import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -509,10 +511,163 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio holder.notification_account_username.setText( String.format("@%s",notification.getAccount().getUsername())); final View finalConvertView = convertView; + final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); holder.status_more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - moreOptionDialog(status, finalConvertView); + + holder.status_more.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + PopupMenu popup = new PopupMenu(context, holder.status_more); + final boolean isOwner = status.getAccount().getId().equals(userId); + popup.getMenuInflater() + .inflate(R.menu.option_toot, popup.getMenu()); + if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){ + popup.getMenu().findItem(R.id.action_mention).setVisible(false); + } + if( isOwner) { + popup.getMenu().findItem(R.id.action_block).setVisible(false); + popup.getMenu().findItem(R.id.action_mute).setVisible(false); + popup.getMenu().findItem(R.id.action_report).setVisible(false); + }else { + popup.getMenu().findItem(R.id.action_remove).setVisible(false); + } + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + AlertDialog.Builder builderInner; + String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); + final API.StatusAction doAction; + switch (item.getItemId()) { + case R.id.action_remove: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_mute: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.MUTE; + break; + case R.id.action_block: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[1]); + doAction = API.StatusAction.BLOCK; + break; + case R.id.action_report: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[2]); + doAction = API.StatusAction.REPORT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_copy: + ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + String content; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); + else + //noinspection deprecation + content = Html.fromHtml(status.getContent()).toString(); + ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); + clipboard.setPrimaryClip(clip); + Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); + return true; + case R.id.action_share: + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); + sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); + sendIntent.setType("text/plain"); + context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); + return true; + case R.id.action_mention: + status.setTakingScreenShot(true); + notificationsListAdapter.notifyDataSetChanged(); + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + + @Override + public void run() { + Bitmap bitmap = Helper.convertTootIntoBitmap(context, finalConvertView); + status.setTakingScreenShot(false); + notificationsListAdapter.notifyDataSetChanged(); + Intent intent = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + String fname = "tootmention_" + status.getId() +".jpg"; + File file = new File (context.getCacheDir() + "/", fname); + if (file.exists ()) //noinspection ResultOfMethodCallIgnored + file.delete (); + try { + FileOutputStream out = new FileOutputStream(file); + bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); + out.flush(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + b.putString("fileMention", fname); + b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); + b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); + intent.putExtras(b); + context.startActivity(intent); + } + + }, 1000); + return true; + default: + return true; + } + + //Text for report + EditText input = null; + if( doAction == API.StatusAction.REPORT){ + input = new EditText(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + builderInner.setView(input); + } + builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + dialog.dismiss(); + } + }); + final EditText finalInput = input; + builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + if(doAction == API.StatusAction.UNSTATUS ){ + String targetedId = status.getId(); + new PostActionAsyncTask(context, doAction, targetedId, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else if(doAction == API.StatusAction.REPORT ){ + String comment = null; + if( finalInput.getText() != null) + comment = finalInput.getText().toString(); + new PostActionAsyncTask(context, doAction, status.getId(), status, comment, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else{ + String targetedId = status.getAccount().getId(); + new PostActionAsyncTask(context, doAction, targetedId, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + dialog.dismiss(); + } + }); + builderInner.show(); + return true; + } + }); + popup.show(); + } + }); } }); @@ -830,244 +985,4 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio ImageView status_privacy; } - - - /** - * More option for status (report / remove status / Mute / Block) - * @param status Status current status - */ - private void moreOptionDialog(final Status status, final View view){ - - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - final boolean isOwner = status.getAccount().getId().equals(userId); - AlertDialog.Builder builderSingle = new AlertDialog.Builder(context); - //builderSingle.setTitle(R.string.make_a_choice); - final String[] stringArray, stringArrayConf; - final API.StatusAction[] doAction; - if( isOwner) { - if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){ - String[] stringArraytmp = context.getResources().getStringArray(R.array.more_action_owner); - List list = new ArrayList<>(Arrays.asList(stringArraytmp)); - list.remove(3); - stringArray = list.toArray(new String[0]); - String[] stringArrayConftmp = context.getResources().getStringArray(R.array.more_action_owner_confirm); - list = new ArrayList<>(Arrays.asList(stringArrayConftmp)); - list.remove(3); - stringArrayConf = list.toArray(new String[0]); - doAction = new API.StatusAction[]{API.StatusAction.UNSTATUS}; - }else { - stringArray = context.getResources().getStringArray(R.array.more_action_owner); - stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); - doAction = new API.StatusAction[]{API.StatusAction.UNSTATUS}; - } - }else { - if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){ - String[] stringArraytmp = context.getResources().getStringArray(R.array.more_action); - List list = new ArrayList<>(Arrays.asList(stringArraytmp)); - list.remove(5); - stringArray = list.toArray(new String[0]); - String[] stringArrayConftmp = context.getResources().getStringArray(R.array.more_action_confirm); - list = new ArrayList<>(Arrays.asList(stringArrayConftmp)); - list.remove(5); - stringArrayConf = list.toArray(new String[0]); - doAction = new API.StatusAction[]{API.StatusAction.MUTE, API.StatusAction.BLOCK, API.StatusAction.REPORT}; - }else { - stringArray = context.getResources().getStringArray(R.array.more_action); - stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm); - doAction = new API.StatusAction[]{API.StatusAction.MUTE, API.StatusAction.BLOCK, API.StatusAction.REPORT}; - } - } - final ArrayAdapter arrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, stringArray); - builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - - builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - AlertDialog.Builder builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[which]); - if( isOwner) { - if( which == 0) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - }else if( which == 1){ - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - String content; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - //noinspection deprecation - content = Html.fromHtml(status.getContent()).toString(); - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); - clipboard.setPrimaryClip(clip); - Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); - dialog.dismiss(); - return; - }else if( which == 2) { - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - return; - }else if (which == 3){ - status.setTakingScreenShot(true); - notificationsListAdapter.notifyDataSetChanged(); - - - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - - @Override - public void run() { - Bitmap bitmap = Helper.convertTootIntoBitmap(context, view); - status.setTakingScreenShot(false); - notificationsListAdapter.notifyDataSetChanged(); - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - String fname = "tootmention_" + status.getId() +".jpg"; - File file = new File (context.getCacheDir() + "/", fname); - if (file.exists ()) //noinspection ResultOfMethodCallIgnored - file.delete (); - try { - FileOutputStream out = new FileOutputStream(file); - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); - out.flush(); - out.close(); - } catch (Exception e) { - e.printStackTrace(); - } - b.putString("fileMention", fname); - b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); - b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); - intent.putExtras(b); - context.startActivity(intent); - } - - }, 1000); - return; - } - }else { - if( which < 2 ){ - builderInner.setMessage(status.getAccount().getAcct()); - }else if( which == 2) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - }else if( which == 3 ){ - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - String content; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - //noinspection deprecation - content = Html.fromHtml(status.getContent()).toString(); - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); - clipboard.setPrimaryClip(clip); - Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); - dialog.dismiss(); - return; - }else if (which == 4){ - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - return; - }else if (which == 5){ - status.setTakingScreenShot(true); - notificationsListAdapter.notifyDataSetChanged(); - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - - @Override - public void run() { - Bitmap bitmap = Helper.convertTootIntoBitmap(context, view); - status.setTakingScreenShot(false); - notificationsListAdapter.notifyDataSetChanged(); - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - String fname = "tootmention_" + status.getId() +".jpg"; - File file = new File (context.getCacheDir() + "/", fname); - if (file.exists ()) //noinspection ResultOfMethodCallIgnored - file.delete (); - try { - FileOutputStream out = new FileOutputStream(file); - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); - out.flush(); - out.close(); - } catch (Exception e) { - e.printStackTrace(); - } - b.putString("fileMention", fname); - b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); - b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); - intent.putExtras(b); - context.startActivity(intent); - } - - }, 1000); - return; - } - } - //Text for report - EditText input = null; - final int position = which; - if( doAction[which] == API.StatusAction.REPORT){ - input = new EditText(context); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - input.setLayoutParams(lp); - builderInner.setView(input); - } - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - dialog.dismiss(); - } - }); - final EditText finalInput = input; - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - API.StatusAction statusAction = doAction[position]; - if(statusAction == API.StatusAction.REPORT || statusAction == API.StatusAction.CREATESTATUS){ - String comment = null; - if( finalInput != null && finalInput.getText() != null) - comment = finalInput.getText().toString(); - new PostActionAsyncTask(context, statusAction, status.getId(), status, comment, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - }else{ - String targetedId; - if( doAction[position] == API.StatusAction.FAVOURITE || - doAction[position] == API.StatusAction.UNFAVOURITE || - doAction[position] == API.StatusAction.REBLOG || - doAction[position] == API.StatusAction.UNREBLOG || - doAction[position] == API.StatusAction.UNSTATUS - ) - targetedId = status.getId(); - else - targetedId = status.getAccount().getId(); - new PostActionAsyncTask(context, statusAction, targetedId, NotificationsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - dialog.dismiss(); - } - }); - builderInner.show(); - } - }); - builderSingle.create().requestWindowFeature(Window.FEATURE_NO_TITLE); - builderSingle.show(); - } - } \ No newline at end of file diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 64276c87e..cc040b914 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -866,225 +866,150 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf public void onClick(View v) { PopupMenu popup = new PopupMenu(context, holder.status_more); final boolean isOwner = status.getAccount().getId().equals(userId); - if( isOwner) { - popup.getMenuInflater() - .inflate(R.menu.option_toot_owner, popup.getMenu()); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - AlertDialog.Builder builderInner; - String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); - final API.StatusAction doAction; - switch (item.getItemId()) { - case R.id.action_remove: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[0]); - doAction = API.StatusAction.UNSTATUS; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_copy: - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - String content; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - //noinspection deprecation - content = Html.fromHtml(status.getContent()).toString(); - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); - clipboard.setPrimaryClip(clip); - Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); - return true; - case R.id.action_share: - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - return true; - case R.id.action_mention: - status.setTakingScreenShot(true); - statusListAdapter.notifyDataSetChanged(); - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - - @Override - public void run() { - Bitmap bitmap = Helper.convertTootIntoBitmap(context, finalConvertView); - status.setTakingScreenShot(false); - statusListAdapter.notifyDataSetChanged(); - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - String fname = "tootmention_" + status.getId() +".jpg"; - File file = new File (context.getCacheDir() + "/", fname); - if (file.exists ()) //noinspection ResultOfMethodCallIgnored - file.delete (); - try { - FileOutputStream out = new FileOutputStream(file); - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); - out.flush(); - out.close(); - } catch (Exception e) { - e.printStackTrace(); - } - b.putString("fileMention", fname); - b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); - b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); - intent.putExtras(b); - context.startActivity(intent); - } - - }, 1000); - return true; - default: - return true; - } - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - dialog.dismiss(); - } - }); - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - if(doAction == API.StatusAction.UNSTATUS ){ - String targetedId = status.getId(); - new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - dialog.dismiss(); - } - }); - builderInner.show(); - return true; - } - }); - }else { - popup.getMenuInflater() - .inflate(R.menu.option_toot, popup.getMenu()); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - AlertDialog.Builder builderInner; - String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm); - final API.StatusAction doAction; - switch (item.getItemId()) { - case R.id.action_mute: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[0]); - doAction = API.StatusAction.MUTE; - break; - case R.id.action_block: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[1]); - doAction = API.StatusAction.BLOCK; - break; - case R.id.action_report: - builderInner = new AlertDialog.Builder(context); - builderInner.setTitle(stringArrayConf[2]); - doAction = API.StatusAction.REPORT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_copy: - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - String content; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - //noinspection deprecation - content = Html.fromHtml(status.getContent()).toString(); - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); - clipboard.setPrimaryClip(clip); - Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); - return true; - case R.id.action_share: - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - return true; - case R.id.action_mention: - status.setTakingScreenShot(true); - statusListAdapter.notifyDataSetChanged(); - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - - @Override - public void run() { - Bitmap bitmap = Helper.convertTootIntoBitmap(context, finalConvertView); - status.setTakingScreenShot(false); - statusListAdapter.notifyDataSetChanged(); - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - String fname = "tootmention_" + status.getId() +".jpg"; - File file = new File (context.getCacheDir() + "/", fname); - if (file.exists ()) //noinspection ResultOfMethodCallIgnored - file.delete (); - try { - FileOutputStream out = new FileOutputStream(file); - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); - out.flush(); - out.close(); - } catch (Exception e) { - e.printStackTrace(); - } - b.putString("fileMention", fname); - b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); - b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); - intent.putExtras(b); - context.startActivity(intent); - } - - }, 1000); - return true; - default: - return true; - } - //Text for report - EditText input = null; - if( doAction == API.StatusAction.REPORT){ - input = new EditText(context); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - input.setLayoutParams(lp); - builderInner.setView(input); - } - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - dialog.dismiss(); - } - }); - - final EditText finalInput = input; - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog,int which) { - if(doAction == API.StatusAction.REPORT ){ - String comment = null; - if( finalInput.getText() != null) - comment = finalInput.getText().toString(); - new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - }else{ - String targetedId = status.getAccount().getId(); - new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - dialog.dismiss(); - } - }); - builderInner.show(); - return true; - } - }); + popup.getMenuInflater() + .inflate(R.menu.option_toot, popup.getMenu()); + if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){ + popup.getMenu().findItem(R.id.action_mention).setVisible(false); } + if( isOwner) { + popup.getMenu().findItem(R.id.action_block).setVisible(false); + popup.getMenu().findItem(R.id.action_mute).setVisible(false); + popup.getMenu().findItem(R.id.action_report).setVisible(false); + }else { + popup.getMenu().findItem(R.id.action_remove).setVisible(false); + } + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + AlertDialog.Builder builderInner; + String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); + final API.StatusAction doAction; + switch (item.getItemId()) { + case R.id.action_remove: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_mute: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.MUTE; + break; + case R.id.action_block: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[1]); + doAction = API.StatusAction.BLOCK; + break; + case R.id.action_report: + builderInner = new AlertDialog.Builder(context); + builderInner.setTitle(stringArrayConf[2]); + doAction = API.StatusAction.REPORT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_copy: + ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + String content; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); + else + //noinspection deprecation + content = Html.fromHtml(status.getContent()).toString(); + ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); + clipboard.setPrimaryClip(clip); + Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show(); + return true; + case R.id.action_share: + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); + sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); + sendIntent.setType("text/plain"); + context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); + return true; + case R.id.action_mention: + status.setTakingScreenShot(true); + statusListAdapter.notifyDataSetChanged(); + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + Bitmap bitmap = Helper.convertTootIntoBitmap(context, finalConvertView); + status.setTakingScreenShot(false); + statusListAdapter.notifyDataSetChanged(); + Intent intent = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + String fname = "tootmention_" + status.getId() +".jpg"; + File file = new File (context.getCacheDir() + "/", fname); + if (file.exists ()) //noinspection ResultOfMethodCallIgnored + file.delete (); + try { + FileOutputStream out = new FileOutputStream(file); + bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); + out.flush(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + b.putString("fileMention", fname); + b.putString("tootMention", (status.getReblog() != null)?status.getReblog().getAccount().getAcct():status.getAccount().getAcct()); + b.putString("urlMention", (status.getReblog() != null)?status.getReblog().getUrl():status.getUrl()); + intent.putExtras(b); + context.startActivity(intent); + } + + }, 1000); + return true; + default: + return true; + } + + //Text for report + EditText input = null; + if( doAction == API.StatusAction.REPORT){ + input = new EditText(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + builderInner.setView(input); + } + builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + dialog.dismiss(); + } + }); + final EditText finalInput = input; + builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog,int which) { + if(doAction == API.StatusAction.UNSTATUS ){ + String targetedId = status.getId(); + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else if(doAction == API.StatusAction.REPORT ){ + String comment = null; + if( finalInput.getText() != null) + comment = finalInput.getText().toString(); + new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else{ + String targetedId = status.getAccount().getId(); + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + dialog.dismiss(); + } + }); + builderInner.show(); + return true; + } + }); popup.show(); } }); diff --git a/app/src/main/res/menu/option_toot.xml b/app/src/main/res/menu/option_toot.xml index 3ce39f88f..eb8ccd95d 100644 --- a/app/src/main/res/menu/option_toot.xml +++ b/app/src/main/res/menu/option_toot.xml @@ -14,15 +14,19 @@ android:title="@string/more_action_3" app:showAsAction="never" /> + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c5c1b1f4e..8083a0d37 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -105,16 +105,10 @@ Stummschalten Blockieren Melden - Kopieren - Teilen - Erwähnen - - - Entfernen - Kopieren - Teilen - Erwähnen - + Entfernen + Kopieren + Teilen + Erwähnen diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f54791599..25bec6926 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -102,14 +102,11 @@ Masquer Bloquer Signaler - Copier - Partager - Mentionner + Supprimer + Copier + Partager + Mentionner - Supprimer - Copier - Partager - Mentionner diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5ebcf5b7a..438166a5f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -113,9 +113,10 @@ Mute Block Report - Copy - Share - Mention + Remove + Copy + Share + Mention Mute this account? Block this account? @@ -123,10 +124,6 @@ - Remove - Copy - Share - Mention Remove this toot?