diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/CustomSharingActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/CustomSharingActivity.java index 0f3bacdbb..52cf186e5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/CustomSharingActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/CustomSharingActivity.java @@ -24,6 +24,7 @@ import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; import android.text.TextUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -41,6 +42,7 @@ import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.CustomSharingAsyncTask; import fr.gouv.etalab.mastodon.client.CustomSharingResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnCustomSharingInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; @@ -119,19 +121,25 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari Helper.loadGiF(getApplicationContext(), url, pp_actionBar); Bundle b = getIntent().getExtras(); + Status status = null; if(b != null) { - bundle_url = b.getString("url"); - bundle_id = b.getString("id"); - bundle_source = b.getString("source"); - bundle_tags = b.getString("tags"); - bundle_content = b.getString("content"); + status = b.getParcelable("status"); } + if( status == null){ + finish(); + return; + } + bundle_url = status.getUrl(); + bundle_id = status.getUri(); + bundle_source = status.getAccount().getAcct(); + bundle_tags = status.getTagsString(); + bundle_content = status.getContentSpan().toString(); + set_custom_sharing_title = findViewById(R.id.set_custom_sharing_title); set_custom_sharing_description = findViewById(R.id.set_custom_sharing_description); set_custom_sharing_keywords = findViewById(R.id.set_custom_sharing_keywords); set_custom_sharing_title.setEllipsize(TextUtils.TruncateAt.END); //set text on title, description, and keywords - System.out.println("Content: " + bundle_content); String[] lines = bundle_content.split("\n"); String newTitle = ""; if (lines[0].length() > 60) { @@ -183,12 +191,14 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari return; } String response = customSharingResponse.getResponse(); + Log.v(Helper.TAG,"response: " + response); Toasty.success(getApplicationContext(), response, Toast.LENGTH_LONG).show(); finish(); } public String encodeCustomSharingURL(String custom_sharing_url, String bundle_url, String bundle_id, String bundle_source, String title, String description, String keywords) { String url_user = ""; + String url_token = ""; String url_param_url = ""; String url_param_title = ""; String url_param_source = ""; @@ -207,6 +217,9 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari if (param_name.equals("user")) { url_user = uri.getQueryParameter("user"); } + if (param_name.equals("token")) { + url_token = uri.getQueryParameter("token"); + } String param_value = uri.getQueryParameter(param_name); switch(param_value) { case "${url}": @@ -233,9 +246,12 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari builder.scheme(protocol) .authority(server) .appendPath(path); - if (!url_user.equals("")) { + if (!url_user.equals("") ) { builder.appendQueryParameter("user", url_user); } + if (!url_token.equals("") ) { + builder.appendQueryParameter("token", url_token); + } if (!url_param_url.equals("")) { builder.appendQueryParameter(url_param_url, bundle_url); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/CustomSharing.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/CustomSharing.java index ef7370e3d..f121debe2 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/CustomSharing.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/CustomSharing.java @@ -15,14 +15,18 @@ package fr.gouv.etalab.mastodon.client; * see . */ import android.content.Context; +import android.util.Log; + import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; + import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.client.Entities.Results; +import fr.gouv.etalab.mastodon.helper.Helper; /** @@ -53,6 +57,7 @@ public class CustomSharing { */ public CustomSharingResponse customShare(String encodedCustomSharingURL) { String HTTPResponse = ""; + Log.v(Helper.TAG,"encodedCustomSharingURL: " + encodedCustomSharingURL); try { HTTPResponse = new HttpsConnection(context).get(encodedCustomSharingURL); } catch (HttpsConnection.HttpsConnectionException e) { 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 1652d9fac..e16b9f943 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 @@ -804,17 +804,10 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); Bundle bCustomSharing = new Bundle(); if (status.getReblog() != null) { - bCustomSharing.putString("url", status.getReblog().getUrl()); - bCustomSharing.putString("source", status.getReblog().getAccount().getDisplay_name()); - bCustomSharing.putString("id", status.getReblog().getId()); - bCustomSharing.putString("tags", status.getReblog().getTagsString()); - bCustomSharing.putString("content", status.getReblog().getContent()); + bCustomSharing.putParcelable("status", status.getReblog()); } else { - bCustomSharing.putString("url", status.getUrl()); - bCustomSharing.putString("source", status.getAccount().getDisplay_name()); - bCustomSharing.putString("id", status.getId()); - bCustomSharing.putString("tags", status.getTagsString()); - bCustomSharing.putString("content", status.getContent()); + bCustomSharing.putParcelable("status", status); + } intentCustomSharing.putExtras(bCustomSharing); context.startActivity(intentCustomSharing); 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 f58d8948f..5486b79b4 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 @@ -2255,17 +2255,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); Bundle bCustomSharing = new Bundle(); if (status.getReblog() != null) { - bCustomSharing.putString("url", status.getReblog().getUrl()); - bCustomSharing.putString("source", status.getReblog().getAccount().getDisplay_name()); - bCustomSharing.putString("id", status.getReblog().getId()); - bCustomSharing.putString("tags", status.getReblog().getTagsString()); - bCustomSharing.putString("content", status.getContentSpan().toString()); + bCustomSharing.putParcelable("status", status.getReblog()); } else { - bCustomSharing.putString("url", status.getUrl()); - bCustomSharing.putString("source", status.getAccount().getDisplay_name()); - bCustomSharing.putString("id", status.getId()); - bCustomSharing.putString("tags", status.getTagsString()); - bCustomSharing.putString("content", status.getContentSpan().toString()); + bCustomSharing.putParcelable("status", status); } intentCustomSharing.putExtras(bCustomSharing); context.startActivity(intentCustomSharing);