diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java index 3f6f322e..8ee1764e 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/Twitter.java @@ -10,10 +10,10 @@ import androidx.annotation.NonNull; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.nuclearfog.twidda.backend.api.holder.MediaStream; -import org.nuclearfog.twidda.backend.api.holder.ProfileUpdate; -import org.nuclearfog.twidda.backend.api.holder.TweetUpdate; -import org.nuclearfog.twidda.backend.api.holder.UserlistUpdate; +import org.nuclearfog.twidda.backend.api.update.MediaUpdate; +import org.nuclearfog.twidda.backend.api.update.ProfileUpdate; +import org.nuclearfog.twidda.backend.api.update.TweetUpdate; +import org.nuclearfog.twidda.backend.api.update.UserlistUpdate; import org.nuclearfog.twidda.backend.api.impl.DirectmessageV1; import org.nuclearfog.twidda.backend.api.impl.LocationV1; import org.nuclearfog.twidda.backend.api.impl.RelationV1; @@ -1243,21 +1243,21 @@ public class Twitter implements GlobalSettings.SettingsListener { /** * upload media file to twitter and generate a media ID * - * @param mediaStream inputstream with MIME type of the media + * @param mediaUpdate inputstream with MIME type of the media * @return media ID */ - public long uploadMedia(MediaStream mediaStream) throws TwitterException { + public long uploadMedia(MediaUpdate mediaUpdate) throws TwitterException { List params = new ArrayList<>(); boolean enableChunk; try { // step 1 INIT params.add("command=INIT"); - params.add("media_type=" + mediaStream.getMimeType()); - params.add("total_bytes=" + mediaStream.available()); - if (mediaStream.getMimeType().startsWith("video/")) { + params.add("media_type=" + mediaUpdate.getMimeType()); + params.add("total_bytes=" + mediaUpdate.available()); + if (mediaUpdate.getMimeType().startsWith("video/")) { params.add("media_category=tweet_video"); enableChunk = true; - } else if (mediaStream.getMimeType().startsWith("image/gif")) { + } else if (mediaUpdate.getMimeType().startsWith("image/gif")) { params.add("media_category=tweet_gif"); enableChunk = true; } else { @@ -1272,12 +1272,12 @@ public class Twitter implements GlobalSettings.SettingsListener { // step 2 APPEND int segmentIndex = 0; - while (mediaStream.available() > 0) { + while (mediaUpdate.available() > 0) { params.clear(); params.add("command=APPEND"); params.add("segment_index=" + segmentIndex++); params.add("media_id=" + mediaId); - response = post(MEDIA_UPLOAD, params, mediaStream.getStream(), "media", enableChunk); + response = post(MEDIA_UPLOAD, params, mediaUpdate.getStream(), "media", enableChunk); if (response.code() < 200 || response.code() >= 300) throw new TwitterException(response); } @@ -1304,7 +1304,7 @@ public class Twitter implements GlobalSettings.SettingsListener { * @param link link to the image * @return image bitmap */ - public MediaStream downloadImage(String link) throws TwitterException { + public MediaUpdate downloadImage(String link) throws TwitterException { try { // this type of link requires authentication if (link.startsWith(DOWNLOAD)) { @@ -1314,7 +1314,7 @@ public class Twitter implements GlobalSettings.SettingsListener { if (type != null) { String mime = type.toString(); InputStream stream = response.body().byteStream(); - return new MediaStream(stream, mime); + return new MediaUpdate(stream, mime); } } throw new TwitterException(response); @@ -1328,7 +1328,7 @@ public class Twitter implements GlobalSettings.SettingsListener { if (type != null) { String mime = type.toString(); InputStream stream = response.body().byteStream(); - return new MediaStream(stream, mime); + return new MediaUpdate(stream, mime); } } throw new TwitterException(response); diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/DirectmessageUpdate.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/DirectmessageUpdate.java similarity index 89% rename from app/src/main/java/org/nuclearfog/twidda/backend/api/holder/DirectmessageUpdate.java rename to app/src/main/java/org/nuclearfog/twidda/backend/api/update/DirectmessageUpdate.java index 347308dd..5c9bc5c4 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/DirectmessageUpdate.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/DirectmessageUpdate.java @@ -1,4 +1,4 @@ -package org.nuclearfog.twidda.backend.api.holder; +package org.nuclearfog.twidda.backend.api.update; import android.content.ContentResolver; import android.content.Context; @@ -20,7 +20,7 @@ import java.io.InputStream; public class DirectmessageUpdate { private Uri uri; - private MediaStream mediaStream; + private MediaUpdate mediaUpdate; private String name = ""; private String text = ""; @@ -63,8 +63,8 @@ public class DirectmessageUpdate { * @return input stream */ @Nullable - public MediaStream getMediaStream() { - return mediaStream; + public MediaUpdate getMediaUpdate() { + return mediaUpdate; } /** @@ -111,7 +111,7 @@ public class DirectmessageUpdate { String mimeType = resolver.getType(uri); InputStream fileStream = resolver.openInputStream(uri); if (fileStream != null && mimeType != null && fileStream.available() > 0) { - mediaStream = new MediaStream(fileStream, mimeType); + mediaUpdate = new MediaUpdate(fileStream, mimeType); return true; } } catch (IOException e) { @@ -124,14 +124,14 @@ public class DirectmessageUpdate { * close inputstream of media file */ public void close() { - if (mediaStream != null) { - mediaStream.close(); + if (mediaUpdate != null) { + mediaUpdate.close(); } } @NonNull @Override public String toString() { - return "to:\"" + name + "\" text:\"" + text + "\" media:" + (mediaStream != null); + return "to:\"" + name + "\" text:\"" + text + "\" media:" + (mediaUpdate != null); } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/MediaStream.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/MediaUpdate.java similarity index 88% rename from app/src/main/java/org/nuclearfog/twidda/backend/api/holder/MediaStream.java rename to app/src/main/java/org/nuclearfog/twidda/backend/api/update/MediaUpdate.java index 42422257..e980df24 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/MediaStream.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/MediaUpdate.java @@ -1,4 +1,4 @@ -package org.nuclearfog.twidda.backend.api.holder; +package org.nuclearfog.twidda.backend.api.update; import androidx.annotation.NonNull; @@ -10,7 +10,7 @@ import java.io.InputStream; * * @author nuclearfog */ -public class MediaStream { +public class MediaUpdate { private InputStream inputStream; private String mimeType; @@ -19,7 +19,7 @@ public class MediaStream { * @param inputStream stream of the media (local or online) * @param mimeType MIME type e.g. image/jpeg */ - public MediaStream(InputStream inputStream, String mimeType) { + public MediaUpdate(InputStream inputStream, String mimeType) { this.inputStream = inputStream; this.mimeType = mimeType; } diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/ProfileUpdate.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/ProfileUpdate.java similarity index 98% rename from app/src/main/java/org/nuclearfog/twidda/backend/api/holder/ProfileUpdate.java rename to app/src/main/java/org/nuclearfog/twidda/backend/api/update/ProfileUpdate.java index 45884b2d..3ac4817e 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/ProfileUpdate.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/ProfileUpdate.java @@ -1,4 +1,4 @@ -package org.nuclearfog.twidda.backend.api.holder; +package org.nuclearfog.twidda.backend.api.update; import android.content.ContentResolver; import android.content.Context; diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/TweetUpdate.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/TweetUpdate.java similarity index 89% rename from app/src/main/java/org/nuclearfog/twidda/backend/api/holder/TweetUpdate.java rename to app/src/main/java/org/nuclearfog/twidda/backend/api/update/TweetUpdate.java index 62fd2e20..849cd615 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/TweetUpdate.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/TweetUpdate.java @@ -1,4 +1,4 @@ -package org.nuclearfog.twidda.backend.api.holder; +package org.nuclearfog.twidda.backend.api.update; import android.content.ContentResolver; import android.content.Context; @@ -26,7 +26,7 @@ public class TweetUpdate { private double latitude; private List mediaUris = new ArrayList<>(5); - private MediaStream[] mediaStreams = {}; + private MediaUpdate[] mediaUpdates = {}; private boolean hasLocation = false; /** @@ -97,10 +97,10 @@ public class TweetUpdate { /** * get information about media attached to the tweet * - * @return list of mediastream instances + * @return list of media updates */ - public MediaStream[] getMediaStreams() { - return mediaStreams; + public MediaUpdate[] getMediaUpdates() { + return mediaUpdates; } /** @@ -158,13 +158,13 @@ public class TweetUpdate { return true; try { // open input streams - mediaStreams = new MediaStream[mediaUris.size()]; - for (int i = 0; i < mediaStreams.length; i++) { + mediaUpdates = new MediaUpdate[mediaUris.size()]; + for (int i = 0; i < mediaUpdates.length; i++) { InputStream is = resolver.openInputStream(mediaUris.get(i)); String mime = resolver.getType(mediaUris.get(i)); // check if stream is valid if (is != null && mime != null && is.available() > 0) { - mediaStreams[i] = new MediaStream(is, mime); + mediaUpdates[i] = new MediaUpdate(is, mime); } else { return false; } @@ -180,8 +180,8 @@ public class TweetUpdate { * close all open streams */ public void close() { - for (MediaStream mediaStream : mediaStreams) { - mediaStream.close(); + for (MediaUpdate mediaUpdate : mediaUpdates) { + mediaUpdate.close(); } } diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/UserlistUpdate.java b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/UserlistUpdate.java similarity index 96% rename from app/src/main/java/org/nuclearfog/twidda/backend/api/holder/UserlistUpdate.java rename to app/src/main/java/org/nuclearfog/twidda/backend/api/update/UserlistUpdate.java index 3e440e84..9c482674 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/api/holder/UserlistUpdate.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/api/update/UserlistUpdate.java @@ -1,4 +1,4 @@ -package org.nuclearfog.twidda.backend.api.holder; +package org.nuclearfog.twidda.backend.api.update; import androidx.annotation.NonNull; diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/async/ImageLoader.java b/app/src/main/java/org/nuclearfog/twidda/backend/async/ImageLoader.java index c0f18b74..f27c9118 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/async/ImageLoader.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/async/ImageLoader.java @@ -7,7 +7,7 @@ import androidx.annotation.Nullable; import org.nuclearfog.twidda.backend.api.Twitter; import org.nuclearfog.twidda.backend.api.TwitterException; -import org.nuclearfog.twidda.backend.api.holder.MediaStream; +import org.nuclearfog.twidda.backend.api.update.MediaUpdate; import org.nuclearfog.twidda.backend.utils.ErrorHandler; import org.nuclearfog.twidda.backend.utils.StringTools; import org.nuclearfog.twidda.ui.activities.ImageViewer; @@ -51,9 +51,9 @@ public class ImageLoader extends AsyncTask { // download imaged to a local cache folder for (Uri link : links) { // get input stream - MediaStream mediaStream = twitter.downloadImage(link.toString()); - InputStream input = mediaStream.getStream(); - String mimeType = mediaStream.getMimeType(); + MediaUpdate mediaUpdate = twitter.downloadImage(link.toString()); + InputStream input = mediaUpdate.getStream(); + String mimeType = mediaUpdate.getMimeType(); // create file String ext = '.' + mimeType.substring(mimeType.indexOf('/') + 1); diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/async/ListUpdater.java b/app/src/main/java/org/nuclearfog/twidda/backend/async/ListUpdater.java index 18e1a8e6..3d11c7b8 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/async/ListUpdater.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/async/ListUpdater.java @@ -4,7 +4,7 @@ import android.os.AsyncTask; import org.nuclearfog.twidda.backend.api.Twitter; import org.nuclearfog.twidda.backend.api.TwitterException; -import org.nuclearfog.twidda.backend.api.holder.UserlistUpdate; +import org.nuclearfog.twidda.backend.api.update.UserlistUpdate; import org.nuclearfog.twidda.model.UserList; import org.nuclearfog.twidda.ui.activities.UserlistEditor; diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/async/MessageUpdater.java b/app/src/main/java/org/nuclearfog/twidda/backend/async/MessageUpdater.java index d8b3a987..e17da532 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/async/MessageUpdater.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/async/MessageUpdater.java @@ -6,7 +6,7 @@ import androidx.annotation.NonNull; import org.nuclearfog.twidda.backend.api.Twitter; import org.nuclearfog.twidda.backend.api.TwitterException; -import org.nuclearfog.twidda.backend.api.holder.DirectmessageUpdate; +import org.nuclearfog.twidda.backend.api.update.DirectmessageUpdate; import org.nuclearfog.twidda.backend.utils.ErrorHandler; import org.nuclearfog.twidda.ui.activities.MessageEditor; @@ -46,8 +46,8 @@ public class MessageUpdater extends AsyncTask { long id = twitter.showUser(message.getName()).getId(); // upload media if any long mediaId = -1; - if (message.getMediaStream() != null) { - mediaId = twitter.uploadMedia(message.getMediaStream()); + if (message.getMediaUpdate() != null) { + mediaId = twitter.uploadMedia(message.getMediaUpdate()); } // upload message and media ID if (!isCancelled()) { @@ -57,7 +57,7 @@ public class MessageUpdater extends AsyncTask { } catch (TwitterException exception) { this.exception = exception; } finally { - // close mediastream + // close all streams message.close(); } return false; diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/async/TweetUpdater.java b/app/src/main/java/org/nuclearfog/twidda/backend/async/TweetUpdater.java index 1584d9f3..cab852bc 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/async/TweetUpdater.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/async/TweetUpdater.java @@ -4,8 +4,8 @@ import android.os.AsyncTask; import org.nuclearfog.twidda.backend.api.Twitter; import org.nuclearfog.twidda.backend.api.TwitterException; -import org.nuclearfog.twidda.backend.api.holder.MediaStream; -import org.nuclearfog.twidda.backend.api.holder.TweetUpdate; +import org.nuclearfog.twidda.backend.api.update.MediaUpdate; +import org.nuclearfog.twidda.backend.api.update.TweetUpdate; import org.nuclearfog.twidda.backend.utils.ErrorHandler; import org.nuclearfog.twidda.ui.activities.TweetEditor; @@ -40,11 +40,11 @@ public class TweetUpdater extends AsyncTask { TweetUpdate update = tweets[0]; try { // upload media first - MediaStream[] mediaStreams = update.getMediaStreams(); - long[] mediaIds = new long[mediaStreams.length]; - for (int pos = 0; pos < mediaStreams.length; pos++) { + MediaUpdate[] mediaUpdates = update.getMediaUpdates(); + long[] mediaIds = new long[mediaUpdates.length]; + for (int pos = 0; pos < mediaUpdates.length; pos++) { // upload media file and save media ID - mediaIds[pos] = twitter.uploadMedia(mediaStreams[pos]); + mediaIds[pos] = twitter.uploadMedia(mediaUpdates[pos]); } // upload tweet if (!isCancelled()) { diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/async/UserUpdater.java b/app/src/main/java/org/nuclearfog/twidda/backend/async/UserUpdater.java index ac2f7ca8..b8ebd077 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/async/UserUpdater.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/async/UserUpdater.java @@ -6,7 +6,7 @@ import androidx.annotation.Nullable; import org.nuclearfog.twidda.backend.api.Twitter; import org.nuclearfog.twidda.backend.api.TwitterException; -import org.nuclearfog.twidda.backend.api.holder.ProfileUpdate; +import org.nuclearfog.twidda.backend.api.update.ProfileUpdate; import org.nuclearfog.twidda.backend.utils.ErrorHandler; import org.nuclearfog.twidda.database.AppDatabase; import org.nuclearfog.twidda.model.User; diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/MessageEditor.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/MessageEditor.java index 5644562c..eebebfdc 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/MessageEditor.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/MessageEditor.java @@ -22,7 +22,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import org.nuclearfog.twidda.R; -import org.nuclearfog.twidda.backend.api.holder.DirectmessageUpdate; +import org.nuclearfog.twidda.backend.api.update.DirectmessageUpdate; import org.nuclearfog.twidda.backend.async.MessageUpdater; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.ErrorHandler; diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/ProfileEditor.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/ProfileEditor.java index 3226899d..427e288b 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/ProfileEditor.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/ProfileEditor.java @@ -34,7 +34,7 @@ import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import org.nuclearfog.twidda.R; -import org.nuclearfog.twidda.backend.api.holder.ProfileUpdate; +import org.nuclearfog.twidda.backend.api.update.ProfileUpdate; import org.nuclearfog.twidda.backend.async.UserUpdater; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.ErrorHandler; diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/TweetEditor.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/TweetEditor.java index acdff2ed..7b8986fb 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/TweetEditor.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/TweetEditor.java @@ -25,7 +25,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import org.nuclearfog.twidda.R; -import org.nuclearfog.twidda.backend.api.holder.TweetUpdate; +import org.nuclearfog.twidda.backend.api.update.TweetUpdate; import org.nuclearfog.twidda.backend.async.TweetUpdater; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.ErrorHandler; diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/UserlistEditor.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/UserlistEditor.java index a74db650..6dd015ab 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/UserlistEditor.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/UserlistEditor.java @@ -19,7 +19,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import org.nuclearfog.twidda.R; -import org.nuclearfog.twidda.backend.api.holder.UserlistUpdate; +import org.nuclearfog.twidda.backend.api.update.UserlistUpdate; import org.nuclearfog.twidda.backend.async.ListUpdater; import org.nuclearfog.twidda.backend.utils.AppStyles; import org.nuclearfog.twidda.backend.utils.ErrorHandler; diff --git a/build.gradle b/build.gradle index a3307a43..ddc9859e 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.2.1' + classpath 'com.android.tools.build:gradle:7.2.2' classpath 'io.michaelrocks:paranoid-gradle-plugin:0.3.7' classpath 'gradle.plugin.ru.cleverpumpkin.proguard-dictionaries-generator:plugin:1.0.8' }