Minimizes the code for popups
This commit is contained in:
parent
07a1026f76
commit
6276d90a0b
|
@ -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<String> 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<String> 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<String> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -14,15 +14,19 @@
|
|||
android:title="@string/more_action_3"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_copy"
|
||||
android:id="@+id/action_remove"
|
||||
android:title="@string/more_action_4"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:id="@+id/action_copy"
|
||||
android:title="@string/more_action_5"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_mention"
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/more_action_6"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_mention"
|
||||
android:title="@string/more_action_7"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
|
|
|
@ -105,16 +105,10 @@
|
|||
<string name="more_action_1">Stummschalten</string>
|
||||
<string name="more_action_2">Blockieren</string>
|
||||
<string name="more_action_3">Melden</string>
|
||||
<string name="more_action_4">Kopieren</string>
|
||||
<string name="more_action_5">Teilen</string>
|
||||
<string name="more_action_6">Erwähnen</string>
|
||||
|
||||
|
||||
<string name="more_action_owner_1">Entfernen</string>
|
||||
<string name="more_action_owner_2">Kopieren</string>
|
||||
<string name="more_action_owner_3">Teilen</string>
|
||||
<string name="more_action_owner_4">Erwähnen</string>
|
||||
|
||||
<string name="more_action_4">Entfernen</string>
|
||||
<string name="more_action_5">Kopieren</string>
|
||||
<string name="more_action_6">Teilen</string>
|
||||
<string name="more_action_7">Erwähnen</string>
|
||||
|
||||
|
||||
<string-array name="more_action_confirm">
|
||||
|
|
|
@ -102,14 +102,11 @@
|
|||
<string name="more_action_1">Masquer</string>
|
||||
<string name="more_action_2">Bloquer</string>
|
||||
<string name="more_action_3">Signaler</string>
|
||||
<string name="more_action_4">Copier</string>
|
||||
<string name="more_action_5">Partager</string>
|
||||
<string name="more_action_6">Mentionner</string>
|
||||
<string name="more_action_4">Supprimer</string>
|
||||
<string name="more_action_5">Copier</string>
|
||||
<string name="more_action_6">Partager</string>
|
||||
<string name="more_action_7">Mentionner</string>
|
||||
|
||||
<string name="more_action_owner_1">Supprimer</string>
|
||||
<string name="more_action_owner_2">Copier</string>
|
||||
<string name="more_action_owner_3">Partager</string>
|
||||
<string name="more_action_owner_4">Mentionner</string>
|
||||
|
||||
|
||||
<string-array name="more_action_confirm">
|
||||
|
|
|
@ -113,9 +113,10 @@
|
|||
<string name="more_action_1">Mute</string>
|
||||
<string name="more_action_2">Block</string>
|
||||
<string name="more_action_3">Report</string>
|
||||
<string name="more_action_4">Copy</string>
|
||||
<string name="more_action_5">Share</string>
|
||||
<string name="more_action_6">Mention</string>
|
||||
<string name="more_action_4">Remove</string>
|
||||
<string name="more_action_5">Copy</string>
|
||||
<string name="more_action_6">Share</string>
|
||||
<string name="more_action_7">Mention</string>
|
||||
<string-array name="more_action_confirm">
|
||||
<item>Mute this account?</item>
|
||||
<item>Block this account?</item>
|
||||
|
@ -123,10 +124,6 @@
|
|||
</string-array>
|
||||
|
||||
|
||||
<string name="more_action_owner_1">Remove</string>
|
||||
<string name="more_action_owner_2">Copy</string>
|
||||
<string name="more_action_owner_3">Share</string>
|
||||
<string name="more_action_owner_4">Mention</string>
|
||||
<string-array name="more_action_owner_confirm">
|
||||
<item>Remove this toot?</item>
|
||||
</string-array>
|
||||
|
|
Loading…
Reference in New Issue