146 lines
5.4 KiB
Java
146 lines
5.4 KiB
Java
package fr.gouv.etalab.mastodon.client;
|
|
/* Copyright 2017 Thomas Schneider
|
|
*
|
|
* This file is a part of Mastalab
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
* Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.os.Bundle;
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.IOException;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URLEncoder;
|
|
import java.security.KeyManagementException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.text.ParseException;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import fr.gouv.etalab.mastodon.R;
|
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveOpenCollectiveAsyncTask;
|
|
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Application;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Card;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Filters;
|
|
import fr.gouv.etalab.mastodon.client.Entities.HowToVideo;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Instance;
|
|
import fr.gouv.etalab.mastodon.client.Entities.InstanceNodeInfo;
|
|
import fr.gouv.etalab.mastodon.client.Entities.InstanceSocial;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
|
import fr.gouv.etalab.mastodon.client.Entities.NodeInfo;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Schedule;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
|
import fr.gouv.etalab.mastodon.client.Entities.StoredStatus;
|
|
import fr.gouv.etalab.mastodon.client.Entities.Tag;
|
|
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|
|
|
|
|
/**
|
|
* Created by Curtis on 13/02/2019.
|
|
* Manage custom sharing of status metadata to remote content aggregator
|
|
*/
|
|
|
|
public class CustomSharing {
|
|
|
|
private Context context;
|
|
private Results results;
|
|
private CustomSharingResponse customSharingResponse;
|
|
private Error CustomSharingError;
|
|
|
|
public CustomSharing(Context context) {
|
|
this.context = context;
|
|
if( context == null) {
|
|
CustomSharingError = new Error();
|
|
return;
|
|
}
|
|
customSharingResponse = new CustomSharingResponse();
|
|
CustomSharingError = null;
|
|
}
|
|
|
|
/***
|
|
* pass status metadata to remote content aggregator *synchronously*
|
|
* @return CustomSharingResponse
|
|
*/
|
|
public CustomSharingResponse customShare(String encodedCustomSharingURL) {
|
|
String HTTPResponse = "";
|
|
try {
|
|
HTTPResponse = new HttpsConnection(context).get(encodedCustomSharingURL);
|
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
|
e.printStackTrace();
|
|
setError(e.getStatusCode(), e);
|
|
} catch (NoSuchAlgorithmException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} catch (KeyManagementException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return customSharingResponse;
|
|
}
|
|
|
|
public Error getError(){
|
|
return CustomSharingError;
|
|
}
|
|
|
|
|
|
/**
|
|
* Set the error message
|
|
* @param statusCode int code
|
|
* @param error Throwable error
|
|
*/
|
|
private void setError(int statusCode, Throwable error){
|
|
CustomSharingError = new Error();
|
|
CustomSharingError.setStatusCode(statusCode);
|
|
String message = statusCode + " - " + error.getMessage();
|
|
try {
|
|
JSONObject jsonObject = new JSONObject(error.getMessage());
|
|
String errorM = jsonObject.get("error").toString();
|
|
message = "Error " + statusCode + " : " + errorM;
|
|
} catch (JSONException e) {
|
|
if(error.getMessage().split(".").length > 0) {
|
|
String errorM = error.getMessage().split(".")[0];
|
|
message = "Error " + statusCode + " : " + errorM;
|
|
}
|
|
}
|
|
CustomSharingError.setError(message);
|
|
customSharingResponse.setError(CustomSharingError);
|
|
}
|
|
}
|