Add token management to custom share feature

This commit is contained in:
stom79 2019-02-21 15:09:35 +01:00
parent bc74338b11
commit 6da8084aab
4 changed files with 33 additions and 27 deletions

View File

@ -24,6 +24,7 @@ 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.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; 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.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.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;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
@ -119,19 +121,25 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
Helper.loadGiF(getApplicationContext(), url, pp_actionBar); Helper.loadGiF(getApplicationContext(), url, pp_actionBar);
Bundle b = getIntent().getExtras(); Bundle b = getIntent().getExtras();
Status status = null;
if(b != null) { if(b != null) {
bundle_url = b.getString("url"); status = b.getParcelable("status");
bundle_id = b.getString("id");
bundle_source = b.getString("source");
bundle_tags = b.getString("tags");
bundle_content = b.getString("content");
} }
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_title = findViewById(R.id.set_custom_sharing_title);
set_custom_sharing_description = findViewById(R.id.set_custom_sharing_description); 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_keywords = findViewById(R.id.set_custom_sharing_keywords);
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
System.out.println("Content: " + bundle_content);
String[] lines = bundle_content.split("\n"); String[] lines = bundle_content.split("\n");
String newTitle = ""; String newTitle = "";
if (lines[0].length() > 60) { if (lines[0].length() > 60) {
@ -183,12 +191,14 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
return; return;
} }
String response = customSharingResponse.getResponse(); String response = customSharingResponse.getResponse();
Log.v(Helper.TAG,"response: " + response);
Toasty.success(getApplicationContext(), response, Toast.LENGTH_LONG).show(); Toasty.success(getApplicationContext(), response, Toast.LENGTH_LONG).show();
finish(); finish();
} }
public String encodeCustomSharingURL(String custom_sharing_url, String bundle_url, String bundle_id, String bundle_source, String title, String description, String keywords) { 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_user = "";
String url_token = "";
String url_param_url = ""; String url_param_url = "";
String url_param_title = ""; String url_param_title = "";
String url_param_source = ""; String url_param_source = "";
@ -207,6 +217,9 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
if (param_name.equals("user")) { if (param_name.equals("user")) {
url_user = uri.getQueryParameter("user"); url_user = uri.getQueryParameter("user");
} }
if (param_name.equals("token")) {
url_token = uri.getQueryParameter("token");
}
String param_value = uri.getQueryParameter(param_name); String param_value = uri.getQueryParameter(param_name);
switch(param_value) { switch(param_value) {
case "${url}": case "${url}":
@ -233,9 +246,12 @@ public class CustomSharingActivity extends BaseActivity implements OnCustomShari
builder.scheme(protocol) builder.scheme(protocol)
.authority(server) .authority(server)
.appendPath(path); .appendPath(path);
if (!url_user.equals("")) { if (!url_user.equals("") ) {
builder.appendQueryParameter("user", url_user); builder.appendQueryParameter("user", url_user);
} }
if (!url_token.equals("") ) {
builder.appendQueryParameter("token", url_token);
}
if (!url_param_url.equals("")) { if (!url_param_url.equals("")) {
builder.appendQueryParameter(url_param_url, bundle_url); builder.appendQueryParameter(url_param_url, bundle_url);
} }

View File

@ -15,14 +15,18 @@ package fr.gouv.etalab.mastodon.client;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.content.Context; import android.content.Context;
import android.util.Log;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Results; 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) { public CustomSharingResponse customShare(String encodedCustomSharingURL) {
String HTTPResponse = ""; String HTTPResponse = "";
Log.v(Helper.TAG,"encodedCustomSharingURL: " + encodedCustomSharingURL);
try { try {
HTTPResponse = new HttpsConnection(context).get(encodedCustomSharingURL); HTTPResponse = new HttpsConnection(context).get(encodedCustomSharingURL);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {

View File

@ -804,17 +804,10 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class);
Bundle bCustomSharing = new Bundle(); Bundle bCustomSharing = new Bundle();
if (status.getReblog() != null) { if (status.getReblog() != null) {
bCustomSharing.putString("url", status.getReblog().getUrl()); bCustomSharing.putParcelable("status", status.getReblog());
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());
} else { } else {
bCustomSharing.putString("url", status.getUrl()); bCustomSharing.putParcelable("status", status);
bCustomSharing.putString("source", status.getAccount().getDisplay_name());
bCustomSharing.putString("id", status.getId());
bCustomSharing.putString("tags", status.getTagsString());
bCustomSharing.putString("content", status.getContent());
} }
intentCustomSharing.putExtras(bCustomSharing); intentCustomSharing.putExtras(bCustomSharing);
context.startActivity(intentCustomSharing); context.startActivity(intentCustomSharing);

View File

@ -2255,17 +2255,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class);
Bundle bCustomSharing = new Bundle(); Bundle bCustomSharing = new Bundle();
if (status.getReblog() != null) { if (status.getReblog() != null) {
bCustomSharing.putString("url", status.getReblog().getUrl()); bCustomSharing.putParcelable("status", status.getReblog());
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());
} else { } else {
bCustomSharing.putString("url", status.getUrl()); bCustomSharing.putParcelable("status", status);
bCustomSharing.putString("source", status.getAccount().getDisplay_name());
bCustomSharing.putString("id", status.getId());
bCustomSharing.putString("tags", status.getTagsString());
bCustomSharing.putString("content", status.getContentSpan().toString());
} }
intentCustomSharing.putExtras(bCustomSharing); intentCustomSharing.putExtras(bCustomSharing);
context.startActivity(intentCustomSharing); context.startActivity(intentCustomSharing);