Fixes an ugly listener

This commit is contained in:
stom79 2017-12-25 18:28:56 +01:00
parent 5e7fbb9af1
commit 9a3ceada13
1 changed files with 143 additions and 149 deletions

View File

@ -596,160 +596,154 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
holder.status_more.setOnClickListener(new View.OnClickListener() { holder.status_more.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
PopupMenu popup = new PopupMenu(context, attached);
holder.status_more.setOnClickListener(new View.OnClickListener() { assert status != null;
@Override final boolean isOwner = status.getAccount().getId().equals(userId);
public void onClick(View v) { popup.getMenuInflater()
PopupMenu popup = new PopupMenu(context, attached); .inflate(R.menu.option_toot, popup.getMenu());
assert status != null; if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){
final boolean isOwner = status.getAccount().getId().equals(userId); popup.getMenu().findItem(R.id.action_mention).setVisible(false);
popup.getMenuInflater() }
.inflate(R.menu.option_toot, popup.getMenu()); final String[] stringArrayConf;
if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){ if( isOwner) {
popup.getMenu().findItem(R.id.action_mention).setVisible(false); popup.getMenu().findItem(R.id.action_block).setVisible(false);
} popup.getMenu().findItem(R.id.action_mute).setVisible(false);
final String[] stringArrayConf; popup.getMenu().findItem(R.id.action_report).setVisible(false);
if( isOwner) { stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
popup.getMenu().findItem(R.id.action_block).setVisible(false); }else {
popup.getMenu().findItem(R.id.action_mute).setVisible(false); popup.getMenu().findItem(R.id.action_remove).setVisible(false);
popup.getMenu().findItem(R.id.action_report).setVisible(false); stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); }
}else { popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
popup.getMenu().findItem(R.id.action_remove).setVisible(false); public boolean onMenuItemClick(MenuItem item) {
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm); AlertDialog.Builder builderInner;
} final API.StatusAction doAction;
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { switch (item.getItemId()) {
public boolean onMenuItemClick(MenuItem item) { case R.id.action_remove:
AlertDialog.Builder builderInner; builderInner = new AlertDialog.Builder(context);
final API.StatusAction doAction; builderInner.setTitle(stringArrayConf[0]);
switch (item.getItemId()) { doAction = API.StatusAction.UNSTATUS;
case R.id.action_remove: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner = new AlertDialog.Builder(context); builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
builderInner.setTitle(stringArrayConf[0]); else
doAction = API.StatusAction.UNSTATUS; //noinspection deprecation
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) builderInner.setMessage(Html.fromHtml(status.getContent()));
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); break;
else case R.id.action_mute:
//noinspection deprecation builderInner = new AlertDialog.Builder(context);
builderInner.setMessage(Html.fromHtml(status.getContent())); builderInner.setTitle(stringArrayConf[0]);
break; doAction = API.StatusAction.MUTE;
case R.id.action_mute: break;
builderInner = new AlertDialog.Builder(context); case R.id.action_block:
builderInner.setTitle(stringArrayConf[0]); builderInner = new AlertDialog.Builder(context);
doAction = API.StatusAction.MUTE; builderInner.setTitle(stringArrayConf[1]);
break; doAction = API.StatusAction.BLOCK;
case R.id.action_block: break;
builderInner = new AlertDialog.Builder(context); case R.id.action_report:
builderInner.setTitle(stringArrayConf[1]); builderInner = new AlertDialog.Builder(context);
doAction = API.StatusAction.BLOCK; builderInner.setTitle(stringArrayConf[2]);
break; doAction = API.StatusAction.REPORT;
case R.id.action_report: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner = new AlertDialog.Builder(context); builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
builderInner.setTitle(stringArrayConf[2]); else
doAction = API.StatusAction.REPORT; //noinspection deprecation
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) builderInner.setMessage(Html.fromHtml(status.getContent()));
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); break;
else case R.id.action_copy:
//noinspection deprecation ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
builderInner.setMessage(Html.fromHtml(status.getContent())); String content;
break; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
case R.id.action_copy: content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); else
String content; //noinspection deprecation
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) content = Html.fromHtml(status.getContent()).toString();
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
else assert clipboard != null;
//noinspection deprecation clipboard.setPrimaryClip(clip);
content = Html.fromHtml(status.getContent()).toString(); Toast.makeText(context,R.string.clipboard,Toast.LENGTH_LONG).show();
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
assert clipboard != null;
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, holder.getView());
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 ignored) {}
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);
}
}, 500);
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; 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, holder.getView());
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 ignored) {}
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);
}
}, 500);
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();
} }
}); });
popup.show(); 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();
} }
}); });