mirror of
				https://framagit.org/tom79/fedilab-tube
				synced 2025-06-05 21:09:11 +02:00 
			
		
		
		
	About page
This commit is contained in:
		| @@ -9,8 +9,4 @@ | |||||||
|         <item name="colorAccent">@color/colorAccent</item> |         <item name="colorAccent">@color/colorAccent</item> | ||||||
|     </style> |     </style> | ||||||
|  |  | ||||||
|  |  | ||||||
|     <!-- Base application theme. --> |  | ||||||
|  |  | ||||||
|  |  | ||||||
| </resources> | </resources> | ||||||
| @@ -25,17 +25,6 @@ import android.os.Looper; | |||||||
| import android.text.Html; | import android.text.Html; | ||||||
| import android.text.SpannableString; | import android.text.SpannableString; | ||||||
|  |  | ||||||
| import net.gotev.uploadservice.MultipartUploadRequest; |  | ||||||
| import net.gotev.uploadservice.ServerResponse; |  | ||||||
| import net.gotev.uploadservice.UploadInfo; |  | ||||||
| import net.gotev.uploadservice.UploadNotificationConfig; |  | ||||||
| import net.gotev.uploadservice.UploadStatusDelegate; |  | ||||||
|  |  | ||||||
| import org.apache.poi.util.IOUtils; |  | ||||||
|  |  | ||||||
| import java.io.File; |  | ||||||
| import java.io.FileNotFoundException; |  | ||||||
| import java.io.FileOutputStream; |  | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.io.OutputStream; | import java.io.OutputStream; | ||||||
| @@ -79,13 +68,12 @@ public class HttpsConnection { | |||||||
|     private String since_id, max_id; |     private String since_id, max_id; | ||||||
|     private Context context; |     private Context context; | ||||||
|     private int CHUNK_SIZE = 4096; |     private int CHUNK_SIZE = 4096; | ||||||
|     private SharedPreferences sharedpreferences; |  | ||||||
|     private Proxy proxy; |     private Proxy proxy; | ||||||
|  |  | ||||||
|  |  | ||||||
|     public HttpsConnection(Context context) { |     public HttpsConnection(Context context) { | ||||||
|         this.context = context; |         this.context = context; | ||||||
|         sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); |         SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); | ||||||
|         boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false); |         boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false); | ||||||
|         int type = sharedpreferences.getInt(Helper.SET_PROXY_TYPE, 0); |         int type = sharedpreferences.getInt(Helper.SET_PROXY_TYPE, 0); | ||||||
|         proxy = null; |         proxy = null; | ||||||
| @@ -493,141 +481,6 @@ public class HttpsConnection { | |||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void uploadMedia(String urlConnection, InputStream avatar, InputStream header, String filename) { |  | ||||||
|         UploadNotificationConfig uploadConfig = new UploadNotificationConfig(); |  | ||||||
|         uploadConfig.getCompleted().autoClear = true; |  | ||||||
|         final File file = new File(context.getCacheDir() + "/" + filename); |  | ||||||
|         OutputStream outputStream; |  | ||||||
|         try { |  | ||||||
|             outputStream = new FileOutputStream(file); |  | ||||||
|             if (avatar != null) { |  | ||||||
|                 IOUtils.copy(avatar, outputStream); |  | ||||||
|             } else { |  | ||||||
|                 IOUtils.copy(header, outputStream); |  | ||||||
|             } |  | ||||||
|         } catch (IOException e) { |  | ||||||
|             e.printStackTrace(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         try { |  | ||||||
|             String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); |  | ||||||
|             MultipartUploadRequest m = new MultipartUploadRequest(context, urlConnection) |  | ||||||
|                     .setMethod("PATCH"); |  | ||||||
|             if (avatar != null) { |  | ||||||
|                 m.addFileToUpload(file.getPath(), "avatar"); |  | ||||||
|             } else { |  | ||||||
|                 m.addFileToUpload(file.getPath(), "header"); |  | ||||||
|             } |  | ||||||
|             m.addParameter("name", filename) |  | ||||||
|                     .addHeader("Authorization", "Bearer " + token) |  | ||||||
|                     .setNotificationConfig(uploadConfig) |  | ||||||
|                     .setDelegate(new UploadStatusDelegate() { |  | ||||||
|                         @Override |  | ||||||
|                         public void onProgress(Context context, UploadInfo uploadInfo) { |  | ||||||
|                             // your code here |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         @Override |  | ||||||
|                         public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, |  | ||||||
|                                             Exception exception) { |  | ||||||
|                             //noinspection ResultOfMethodCallIgnored |  | ||||||
|                             file.delete(); |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         @Override |  | ||||||
|                         public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { |  | ||||||
|                             //noinspection ResultOfMethodCallIgnored |  | ||||||
|                             file.delete(); |  | ||||||
|                         } |  | ||||||
|  |  | ||||||
|                         @Override |  | ||||||
|                         public void onCancelled(Context context, UploadInfo uploadInfo) { |  | ||||||
|                             //noinspection ResultOfMethodCallIgnored |  | ||||||
|                             file.delete(); |  | ||||||
|                         } |  | ||||||
|                     }) |  | ||||||
|                     .startUpload(); |  | ||||||
|         } catch (MalformedURLException | FileNotFoundException e) { |  | ||||||
|             e.printStackTrace(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @SuppressWarnings("SameParameterValue") |  | ||||||
|     public String patch(String urlConnection, int timeout, HashMap<String, String> paramaters, InputStream avatar, String avatarName, InputStream header, String headerName, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException { |  | ||||||
|  |  | ||||||
|         URL url = new URL(urlConnection); |  | ||||||
|         Map<String, Object> params = new LinkedHashMap<>(); |  | ||||||
|         if (paramaters != null) { |  | ||||||
|             Iterator<Map.Entry<String, String>> it = paramaters.entrySet().iterator(); |  | ||||||
|             while (it.hasNext()) { |  | ||||||
|                 Map.Entry<String, String> pair = it.next(); |  | ||||||
|                 params.put(pair.getKey(), pair.getValue()); |  | ||||||
|                 it.remove(); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         StringBuilder postData = new StringBuilder(); |  | ||||||
|         for (Map.Entry<String, Object> param : params.entrySet()) { |  | ||||||
|             if (postData.length() != 0) postData.append('&'); |  | ||||||
|             postData.append(param.getKey()); |  | ||||||
|             postData.append('='); |  | ||||||
|             postData.append(param.getValue()); |  | ||||||
|         } |  | ||||||
|         byte[] postDataBytes = (postData.toString()).getBytes(StandardCharsets.UTF_8); |  | ||||||
|  |  | ||||||
|         if (proxy != null) |  | ||||||
|             httpsURLConnection = (HttpsURLConnection) url.openConnection(proxy); |  | ||||||
|         else |  | ||||||
|             httpsURLConnection = (HttpsURLConnection) url.openConnection(); |  | ||||||
|         httpsURLConnection.setConnectTimeout(timeout * 1000); |  | ||||||
|         httpsURLConnection.setSSLSocketFactory(new TLSSocketFactory()); |  | ||||||
|         httpsURLConnection.setRequestMethod("PATCH"); |  | ||||||
|         if (token != null) |  | ||||||
|             httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token); |  | ||||||
|         httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); |  | ||||||
|         httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); |  | ||||||
|         httpsURLConnection.setDoOutput(true); |  | ||||||
|  |  | ||||||
|         String response; |  | ||||||
|         OutputStream outputStream = httpsURLConnection.getOutputStream(); |  | ||||||
|         outputStream.write(postDataBytes); |  | ||||||
|         if (avatar != null) { |  | ||||||
|             uploadMedia(urlConnection, avatar, null, avatarName); |  | ||||||
|         } |  | ||||||
|         if (header != null) { |  | ||||||
|             uploadMedia(urlConnection, null, header, headerName); |  | ||||||
|         } |  | ||||||
|         if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) { |  | ||||||
|             response = converToString(httpsURLConnection.getInputStream()); |  | ||||||
|         } else { |  | ||||||
|             String error = null; |  | ||||||
|             if (httpsURLConnection.getErrorStream() != null) { |  | ||||||
|                 InputStream stream = httpsURLConnection.getErrorStream(); |  | ||||||
|                 if (stream == null) { |  | ||||||
|                     stream = httpsURLConnection.getInputStream(); |  | ||||||
|                 } |  | ||||||
|                 try (Scanner scanner = new Scanner(stream)) { |  | ||||||
|                     scanner.useDelimiter("\\Z"); |  | ||||||
|                     if (scanner.hasNext()) { |  | ||||||
|                         error = scanner.next(); |  | ||||||
|                     } |  | ||||||
|                 } catch (Exception e) { |  | ||||||
|                     e.printStackTrace(); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             int responseCode = httpsURLConnection.getResponseCode(); |  | ||||||
|             try { |  | ||||||
|                 httpsURLConnection.getInputStream().close(); |  | ||||||
|             } catch (Exception ignored) { |  | ||||||
|             } |  | ||||||
|             try { |  | ||||||
|                 httpsURLConnection.getInputStream().close(); |  | ||||||
|             } catch (Exception ignored) { |  | ||||||
|             } |  | ||||||
|             throw new HttpsConnectionException(responseCode, error); |  | ||||||
|         } |  | ||||||
|         httpsURLConnection.getInputStream().close(); |  | ||||||
|         return response; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public String put(String urlConnection, int timeout, HashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException { |     public String put(String urlConnection, int timeout, HashMap<String, String> paramaters, String token) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException { | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user