aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java153
1 files changed, 0 insertions, 153 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java b/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java
deleted file mode 100644
index dcad94dc..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/twitter/task/Tweets.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package net.lacolaco.smileessence.twitter.task;
-
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.Environment;
-import android.text.TextUtils;
-import net.lacolaco.smileessence.data.Account;
-import net.lacolaco.smileessence.entity.Tweet;
-import net.lacolaco.smileessence.logging.Logger;
-import net.lacolaco.smileessence.util.BackgroundTask;
-import twitter4j.StatusUpdate;
-import twitter4j.TwitterException;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class Tweets {
- public static class GetTask extends BackgroundTask<Tweet, Void> {
- private final Account account;
- private final long id;
-
- public GetTask(Account account, long id) {
- this.account = account;
- this.id = id;
- }
-
- @Override
- protected Tweet doInBackground() throws TwitterException {
- return Tweet.fromTwitter(account.getTwitter().tweets().showStatus(id), account.getUserId());
- }
- }
-
- public static class CreateTask extends BackgroundTask<Tweet, Void> {
- private static final int MEDIA_SIZE_LIMIT = 5 * 1024 * 1024;
- private final Account account;
- private final StatusUpdate update;
- private final String mediaPath;
- private String tempFilePath;
- private boolean resizeFlag;
-
- public CreateTask(Account account, StatusUpdate update, String mediaPath, boolean resize) {
- this.account = account;
- this.update = update;
- this.mediaPath = mediaPath;
- resizeFlag = resize;
- }
-
- private File getMediaFile() {
- File file = new File(mediaPath);
- if (file.length() >= MEDIA_SIZE_LIMIT && resizeFlag) {
- BitmapFactory.Options opt = new BitmapFactory.Options();
- opt.inJustDecodeBounds = true; //decoder is not return bitmap but set option
- BitmapFactory.decodeFile(mediaPath, opt);
- tempFilePath = Environment.getExternalStorageDirectory() + "/temp.jpg";
- File compressedFile = new File(tempFilePath);
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(compressedFile);
- float ratio = (float) file.length() / (float) MEDIA_SIZE_LIMIT;
- BitmapFactory.Options resizeOpt = new BitmapFactory.Options();
- resizeOpt.inPurgeable = true;
- resizeOpt.inSampleSize = (int) Math.ceil(ratio);
- Bitmap bitmap = BitmapFactory.decodeFile(mediaPath, resizeOpt);
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
- bitmap.recycle();
- return compressedFile;
- } catch (Exception e) {
- e.printStackTrace();
- Logger.error(e);
- } finally {
- try {
- if (fos != null) fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- Logger.error(e);
- }
- }
- }
- return file;
- }
-
- @Override
- protected Tweet doInBackground() throws TwitterException {
- try {
- if (!TextUtils.isEmpty(mediaPath)) {
- File mediaFile = getMediaFile();
- if (mediaFile.exists()) {
- update.setMedia(mediaFile);
- }
- }
- return Tweet.fromTwitter(account.getTwitter().tweets().updateStatus(update), account.getUserId());
- } finally {
- if (tempFilePath != null) {
- new File(tempFilePath).delete();
- }
- }
- }
- }
-
- public static class DestroyTask extends BackgroundTask<Tweet, Void> {
- private final Account account;
- private final long statusID;
-
- public DestroyTask(Account account, long statusID) {
- this.account = account;
- this.statusID = statusID;
- }
-
- @Override
- protected Tweet doInBackground() throws TwitterException {
- Tweet t = Tweet.fromTwitter(account.getTwitter().tweets().destroyStatus(statusID), account.getUserId());
- // FIXME: Tweet.remove(t.getId());
- return t;
- }
- }
-
- public static class GetTalkTask extends BackgroundTask<List<Tweet>, Tweet> {
- private final Account account;
- private final long statusId;
-
- public GetTalkTask(Account account, long statusId) {
- this.account = account;
- this.statusId = statusId;
- }
-
- @Override
- protected List<Tweet> doInBackground() {
- ArrayList<Tweet> list = new ArrayList<>();
- long id = statusId;
- while (id != -1) {
- Tweet tweet = Tweet.fetch(id);
- if (tweet == null) {
- try {
- tweet = Tweet.fromTwitter(account.getTwitter().showStatus(id), account.getUserId());
- } catch (TwitterException ignored) {
- }
- }
-
- if (tweet == null) {
- break;
- } else {
- list.add(tweet);
- progress(tweet);
- id = tweet.getInReplyToStatusId();
- }
- }
- return list;
- }
- }
-}