Merge branch 'custom_sharing_improvements' into develop

This commit is contained in:
tom79 2019-02-23 16:29:50 +01:00
commit f699f03ad8
2 changed files with 72 additions and 42 deletions

View File

@ -20,9 +20,11 @@ import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -34,6 +36,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.List;
import java.util.Set; import java.util.Set;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
@ -41,6 +44,7 @@ import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.CustomSharingAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.CustomSharingAsyncTask;
import fr.gouv.etalab.mastodon.client.CustomSharingResponse; import fr.gouv.etalab.mastodon.client.CustomSharingResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnCustomSharingInterface; import fr.gouv.etalab.mastodon.interfaces.OnCustomSharingInterface;
@ -61,7 +65,7 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
private Button set_custom_sharing_save; private Button set_custom_sharing_save;
private ImageView pp_actionBar; private ImageView pp_actionBar;
private String title, description, keywords, custom_sharing_url, encodedCustomSharingURL; private String title, description, keywords, custom_sharing_url, encodedCustomSharingURL;
private String bundle_url, bundle_source, bundle_id, bundle_tags, bundle_content; private String bundle_url, bundle_source, bundle_id, bundle_tags, bundle_content, bundle_thumbnailurl, bundle_creator;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -128,20 +132,17 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
finish(); finish();
return; return;
} }
bundle_content = status.getContentSpan().toString();
if (status.getReblog() != null) {
bundle_url = status.getReblog().getUrl();
bundle_id = status.getReblog().getUri();
bundle_source = status.getReblog().getAccount().getAcct();
bundle_tags = status.getReblog().getTagsString();
} else {
bundle_url = status.getUrl();
bundle_id = status.getUri();
bundle_source = status.getAccount().getAcct();
bundle_tags = status.getTagsString();
}
bundle_creator = status.getAccount().getAcct();
bundle_url = status.getUrl();
bundle_id = status.getUri();
bundle_source = status.getAccount().getAcct();
bundle_tags = status.getTagsString();
bundle_content = formatedContent(status.getContent(), status.getEmojis());
if( status.getCard() != null && status.getCard().getImage() != null)
bundle_thumbnailurl = status.getCard().getImage();
else
bundle_thumbnailurl = status.getAccount().getAvatar();
if (!bundle_source.contains("@")) { if (!bundle_source.contains("@")) {
bundle_source = bundle_source + "@" + account.getInstance(); bundle_source = bundle_source + "@" + account.getInstance();
} }
@ -151,6 +152,12 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
set_custom_sharing_title.setEllipsize(TextUtils.TruncateAt.END); set_custom_sharing_title.setEllipsize(TextUtils.TruncateAt.END);
//set text on title, description, and keywords //set text on title, description, and keywords
String[] lines = bundle_content.split("\n"); String[] lines = bundle_content.split("\n");
//Remove tags in title
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
lines[0] = Html.fromHtml( lines[0], Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
lines[0] = Html.fromHtml(lines[0]).toString();
String newTitle = ""; String newTitle = "";
if (lines[0].length() > 60) { if (lines[0].length() > 60) {
newTitle = lines[0].substring(0, 60) + '…'; newTitle = lines[0].substring(0, 60) + '…';
@ -218,40 +225,58 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
.authority(server) .authority(server)
.appendPath(path); .appendPath(path);
Set<String> args = uri.getQueryParameterNames(); Set<String> args = uri.getQueryParameterNames();
Boolean paramFound = false; boolean paramFound;
for (String param_name : args) { for (String param_name : args) {
paramFound = false; paramFound = false;
String param_value = uri.getQueryParameter(param_name); String param_value = uri.getQueryParameter(param_name);
switch(param_value) { if(param_value != null)
case "${url}": switch(param_value) {
paramFound = true; case "${url}":
builder.appendQueryParameter(param_name, bundle_url); paramFound = true;
break; builder.appendQueryParameter(param_name, bundle_url);
case "${title}": break;
paramFound = true; case "${title}":
builder.appendQueryParameter(param_name, title); paramFound = true;
break; builder.appendQueryParameter(param_name, title);
case "${source}": break;
paramFound = true; case "${source}":
builder.appendQueryParameter(param_name, bundle_source); paramFound = true;
break; builder.appendQueryParameter(param_name, bundle_source);
case "${id}": break;
paramFound = true; case "${id}":
builder.appendQueryParameter(param_name, bundle_id); paramFound = true;
break; builder.appendQueryParameter(param_name, bundle_id);
case "${description}": break;
paramFound = true; case "${description}":
builder.appendQueryParameter(param_name, description); paramFound = true;
break; builder.appendQueryParameter(param_name, description);
case "${keywords}": break;
paramFound = true; case "${keywords}":
builder.appendQueryParameter(param_name, keywords); paramFound = true;
break; builder.appendQueryParameter(param_name, keywords);
} break;
}
if (bundle_thumbnailurl != null)
builder.appendQueryParameter("thumbnailurl", bundle_thumbnailurl);
builder.appendQueryParameter("creator", bundle_creator);
if (!paramFound) { if (!paramFound) {
builder.appendQueryParameter(param_name, param_value); builder.appendQueryParameter(param_name, param_value);
} }
} }
return builder.build().toString(); return builder.build().toString();
} }
private String formatedContent(String content, List<Emojis> emojis){
//Avoid null content
if( content == null)
return "";
if( emojis == null || emojis.size() == 0)
return content;
for (Emojis emoji : emojis) {
content = content.replaceAll(":"+emoji.getShortcode()+":","<img src='"+emoji.getUrl()+"' width=20 alt='"+emoji.getShortcode()+"'/>");
}
return content;
}
} }

View File

@ -2259,7 +2259,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
case R.id.action_custom_sharing: case R.id.action_custom_sharing:
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class);
Bundle bCustomSharing = new Bundle(); Bundle bCustomSharing = new Bundle();
bCustomSharing.putParcelable("status", status); if (status.getReblog() != null) {
bCustomSharing.putParcelable("status", status.getReblog());
} else {
bCustomSharing.putParcelable("status", status);
}
intentCustomSharing.putExtras(bCustomSharing); intentCustomSharing.putExtras(bCustomSharing);
context.startActivity(intentCustomSharing); context.startActivity(intentCustomSharing);
return true; return true;