2017-01-20 19:09:10 +11:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This file is a part of Tusky.
|
2017-01-20 19:09:10 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* 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.
|
2017-01-20 19:09:10 +11:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 10:12:31 +10:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-20 19:09:10 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-20 19:09:10 +11:00
|
|
|
|
2017-01-08 09:24:02 +11:00
|
|
|
package com.keylesspalace.tusky;
|
|
|
|
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.Manifest;
|
2017-11-17 05:18:11 +11:00
|
|
|
import android.annotation.SuppressLint;
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.ContentResolver;
|
2017-06-19 12:10:50 +10:00
|
|
|
import android.content.Context;
|
2017-01-19 05:35:07 +11:00
|
|
|
import android.content.DialogInterface;
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.content.Intent;
|
2017-01-08 09:24:02 +11:00
|
|
|
import android.content.SharedPreferences;
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.content.pm.PackageManager;
|
2017-03-04 12:44:44 +11:00
|
|
|
import android.content.res.AssetFileDescriptor;
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.graphics.Bitmap;
|
2018-04-14 06:37:21 +10:00
|
|
|
import android.graphics.PorterDuff;
|
2017-03-27 09:26:47 +11:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
2018-07-27 07:31:20 +10:00
|
|
|
import android.os.Build;
|
2017-01-08 09:24:02 +11:00
|
|
|
import android.os.Bundle;
|
2017-04-16 01:43:26 +10:00
|
|
|
import android.os.Environment;
|
2017-02-04 11:53:33 +11:00
|
|
|
import android.os.Parcel;
|
2017-02-18 09:56:31 +11:00
|
|
|
import android.os.Parcelable;
|
2017-11-28 06:11:31 +11:00
|
|
|
import android.preference.PreferenceManager;
|
2017-04-16 01:43:26 +10:00
|
|
|
import android.provider.MediaStore;
|
2017-01-08 09:24:02 +11:00
|
|
|
import android.text.Editable;
|
2018-11-12 05:25:45 +11:00
|
|
|
import android.text.InputFilter;
|
2017-10-24 07:55:43 +11:00
|
|
|
import android.text.InputType;
|
2017-05-16 18:43:32 +10:00
|
|
|
import android.text.TextUtils;
|
2017-01-08 09:24:02 +11:00
|
|
|
import android.text.TextWatcher;
|
2018-05-17 03:14:26 +10:00
|
|
|
import android.text.style.URLSpan;
|
2018-08-16 04:47:36 +10:00
|
|
|
import android.util.DisplayMetrics;
|
2017-05-24 05:34:31 +10:00
|
|
|
import android.util.Log;
|
2017-03-08 00:09:33 +11:00
|
|
|
import android.view.MenuItem;
|
2017-01-08 09:24:02 +11:00
|
|
|
import android.view.View;
|
2018-04-14 06:37:21 +10:00
|
|
|
import android.view.ViewGroup;
|
2018-01-09 09:16:21 +11:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.webkit.MimeTypeMap;
|
2017-03-11 04:38:49 +11:00
|
|
|
import android.widget.Button;
|
2017-01-08 09:24:02 +11:00
|
|
|
import android.widget.EditText;
|
2017-03-11 04:38:49 +11:00
|
|
|
import android.widget.ImageButton;
|
2017-01-17 05:15:42 +11:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
2018-01-09 09:16:21 +11:00
|
|
|
import android.widget.PopupMenu;
|
2017-01-08 09:24:02 +11:00
|
|
|
import android.widget.TextView;
|
2017-06-30 01:56:58 +10:00
|
|
|
import android.widget.Toast;
|
2017-01-08 09:24:02 +11:00
|
|
|
|
2019-01-28 21:04:05 +11:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
2017-07-06 00:36:14 +10:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.adapter.EmojiAdapter;
|
2019-01-28 21:04:05 +11:00
|
|
|
import com.keylesspalace.tusky.adapter.MentionTagAutoCompleteAdapter;
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener;
|
2018-02-04 08:45:14 +11:00
|
|
|
import com.keylesspalace.tusky.db.AccountEntity;
|
2018-05-27 18:22:12 +10:00
|
|
|
import com.keylesspalace.tusky.db.AppDatabase;
|
2018-04-22 18:35:46 +10:00
|
|
|
import com.keylesspalace.tusky.db.InstanceEntity;
|
2018-03-28 04:47:00 +11:00
|
|
|
import com.keylesspalace.tusky.di.Injectable;
|
2017-06-19 12:10:50 +10:00
|
|
|
import com.keylesspalace.tusky.entity.Account;
|
2017-12-01 06:12:09 +11:00
|
|
|
import com.keylesspalace.tusky.entity.Attachment;
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.entity.Emoji;
|
2018-04-22 18:35:46 +10:00
|
|
|
import com.keylesspalace.tusky.entity.Instance;
|
2019-01-28 21:04:05 +11:00
|
|
|
import com.keylesspalace.tusky.entity.SearchResults;
|
2017-03-09 10:27:37 +11:00
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
2018-03-28 04:47:00 +11:00
|
|
|
import com.keylesspalace.tusky.network.MastodonApi;
|
2017-10-30 08:18:45 +11:00
|
|
|
import com.keylesspalace.tusky.network.ProgressRequestBody;
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.service.SendTootService;
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.util.CountUpDownLatch;
|
2017-05-16 18:43:32 +10:00
|
|
|
import com.keylesspalace.tusky.util.DownsizeImageTask;
|
2017-07-12 11:49:46 +10:00
|
|
|
import com.keylesspalace.tusky.util.ListUtils;
|
2019-01-28 21:04:05 +11:00
|
|
|
import com.keylesspalace.tusky.util.MentionTagTokenizer;
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.util.SaveTootHelper;
|
2018-05-17 03:14:26 +10:00
|
|
|
import com.keylesspalace.tusky.util.SpanUtilsKt;
|
2017-07-03 06:34:10 +10:00
|
|
|
import com.keylesspalace.tusky.util.StringUtils;
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.view.ComposeOptionsListener;
|
|
|
|
import com.keylesspalace.tusky.view.ComposeOptionsView;
|
2017-05-16 18:43:32 +10:00
|
|
|
import com.keylesspalace.tusky.view.EditTextTyped;
|
2017-10-30 08:18:45 +11:00
|
|
|
import com.keylesspalace.tusky.view.ProgressImageView;
|
2018-04-14 06:37:21 +10:00
|
|
|
import com.keylesspalace.tusky.view.TootButton;
|
|
|
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
|
|
|
import com.mikepenz.iconics.IconicsDrawable;
|
2018-01-09 09:16:21 +11:00
|
|
|
import com.squareup.picasso.Picasso;
|
2017-01-08 09:24:02 +11:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
2017-04-16 01:43:26 +10:00
|
|
|
import java.io.File;
|
2017-01-17 05:15:42 +11:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.ArrayList;
|
2017-11-02 06:59:29 +11:00
|
|
|
import java.util.Collection;
|
2018-04-22 18:35:46 +10:00
|
|
|
import java.util.Collections;
|
2017-01-17 05:15:42 +11:00
|
|
|
import java.util.Date;
|
2017-01-19 05:35:07 +11:00
|
|
|
import java.util.Iterator;
|
2017-01-17 05:15:42 +11:00
|
|
|
import java.util.List;
|
2017-03-06 11:58:36 +11:00
|
|
|
import java.util.Locale;
|
2017-01-08 09:24:02 +11:00
|
|
|
|
2018-03-28 04:47:00 +11:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2019-01-28 21:04:05 +11:00
|
|
|
import androidx.annotation.ColorInt;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.Px;
|
|
|
|
import androidx.annotation.StringRes;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.content.res.AppCompatResources;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
import androidx.core.content.FileProvider;
|
|
|
|
import androidx.core.view.inputmethod.InputConnectionCompat;
|
|
|
|
import androidx.core.view.inputmethod.InputContentInfoCompat;
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.transition.TransitionManager;
|
2018-07-30 23:36:22 +10:00
|
|
|
import at.connyduck.sparkbutton.helpers.Utils;
|
2018-09-04 04:26:35 +10:00
|
|
|
import io.reactivex.Single;
|
|
|
|
import io.reactivex.SingleObserver;
|
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
import io.reactivex.disposables.Disposable;
|
|
|
|
import io.reactivex.schedulers.Schedulers;
|
2019-01-28 21:04:05 +11:00
|
|
|
import kotlin.collections.CollectionsKt;
|
2017-03-10 02:59:18 +11:00
|
|
|
import okhttp3.MediaType;
|
|
|
|
import okhttp3.MultipartBody;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2017-05-04 10:27:59 +10:00
|
|
|
import retrofit2.Response;
|
2017-03-10 02:59:18 +11:00
|
|
|
|
2018-10-01 19:50:17 +10:00
|
|
|
import static com.keylesspalace.tusky.util.MediaUtilsKt.MEDIA_SIZE_UNKNOWN;
|
|
|
|
import static com.keylesspalace.tusky.util.MediaUtilsKt.getImageSquarePixels;
|
|
|
|
import static com.keylesspalace.tusky.util.MediaUtilsKt.getImageThumbnail;
|
|
|
|
import static com.keylesspalace.tusky.util.MediaUtilsKt.getMediaSize;
|
|
|
|
import static com.keylesspalace.tusky.util.MediaUtilsKt.getSampledBitmap;
|
|
|
|
import static com.keylesspalace.tusky.util.MediaUtilsKt.getVideoThumbnail;
|
2018-09-04 04:26:35 +10:00
|
|
|
import static com.uber.autodispose.AutoDispose.autoDisposable;
|
|
|
|
import static com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from;
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
public final class ComposeActivity
|
|
|
|
extends BaseActivity
|
|
|
|
implements ComposeOptionsListener,
|
2019-01-28 21:04:05 +11:00
|
|
|
MentionTagAutoCompleteAdapter.AutocompletionProvider,
|
2018-04-14 06:37:21 +10:00
|
|
|
OnEmojiSelectedListener,
|
|
|
|
Injectable, InputConnectionCompat.OnCommitContentListener {
|
|
|
|
|
2017-03-10 10:20:08 +11:00
|
|
|
private static final String TAG = "ComposeActivity"; // logging tag
|
2018-04-29 18:08:25 +10:00
|
|
|
static final int STATUS_CHARACTER_LIMIT = 500;
|
2018-09-07 06:48:19 +10:00
|
|
|
private static final int STATUS_IMAGE_SIZE_LIMIT = 8388608; // 8MiB
|
|
|
|
private static final int STATUS_VIDEO_SIZE_LIMIT = 41943040; // 40MiB
|
|
|
|
private static final int STATUS_IMAGE_PIXEL_SIZE_LIMIT = 16777216; // 4096^2 Pixels
|
2017-01-17 05:15:42 +11:00
|
|
|
private static final int MEDIA_PICK_RESULT = 1;
|
2017-04-16 01:43:26 +10:00
|
|
|
private static final int MEDIA_TAKE_PHOTO_RESULT = 2;
|
2017-01-17 05:15:42 +11:00
|
|
|
private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
|
2017-11-02 06:59:29 +11:00
|
|
|
|
|
|
|
private static final String SAVED_TOOT_UID_EXTRA = "saved_toot_uid";
|
|
|
|
private static final String SAVED_TOOT_TEXT_EXTRA = "saved_toot_text";
|
|
|
|
private static final String SAVED_JSON_URLS_EXTRA = "saved_json_urls";
|
2018-11-12 05:25:45 +11:00
|
|
|
private static final String SAVED_JSON_DESCRIPTIONS_EXTRA = "saved_json_descriptions";
|
2018-08-24 04:50:50 +10:00
|
|
|
private static final String SAVED_TOOT_VISIBILITY_EXTRA = "saved_toot_visibility";
|
2017-11-02 06:59:29 +11:00
|
|
|
private static final String IN_REPLY_TO_ID_EXTRA = "in_reply_to_id";
|
|
|
|
private static final String REPLY_VISIBILITY_EXTRA = "reply_visibilty";
|
|
|
|
private static final String CONTENT_WARNING_EXTRA = "content_warning";
|
|
|
|
private static final String MENTIONED_USERNAMES_EXTRA = "netnioned_usernames";
|
|
|
|
private static final String REPLYING_STATUS_AUTHOR_USERNAME_EXTRA = "replying_author_nickname_extra";
|
|
|
|
private static final String REPLYING_STATUS_CONTENT_EXTRA = "replying_status_content";
|
2018-05-17 03:14:26 +10:00
|
|
|
// Mastodon only counts URLs as this long in terms of status character limits
|
|
|
|
static final int MAXIMUM_URL_LENGTH = 23;
|
2018-11-12 05:25:45 +11:00
|
|
|
// https://github.com/tootsuite/mastodon/blob/1656663/app/models/media_attachment.rb#L94
|
|
|
|
private static final int MEDIA_DESCRIPTION_CHARACTER_LIMIT = 420;
|
2017-11-17 05:18:11 +11:00
|
|
|
|
2018-03-28 04:47:00 +11:00
|
|
|
@Inject
|
|
|
|
public MastodonApi mastodonApi;
|
2018-05-27 18:22:12 +10:00
|
|
|
@Inject
|
|
|
|
public AppDatabase database;
|
2018-03-28 04:47:00 +11:00
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
private TextView replyTextView;
|
2017-11-02 06:59:29 +11:00
|
|
|
private TextView replyContentTextView;
|
2017-06-23 04:59:12 +10:00
|
|
|
private EditTextTyped textEditor;
|
|
|
|
private LinearLayout mediaPreviewBar;
|
|
|
|
private View contentWarningBar;
|
|
|
|
private EditText contentWarningEditor;
|
|
|
|
private TextView charactersLeft;
|
2018-04-14 06:37:21 +10:00
|
|
|
private TootButton tootButton;
|
2017-07-28 12:40:58 +10:00
|
|
|
private ImageButton pickButton;
|
2018-04-14 06:37:21 +10:00
|
|
|
private ImageButton visibilityButton;
|
|
|
|
private Button contentWarningButton;
|
|
|
|
private ImageButton emojiButton;
|
2017-07-27 14:56:53 +10:00
|
|
|
private ImageButton hideMediaToggle;
|
2018-04-14 06:37:21 +10:00
|
|
|
|
|
|
|
private ComposeOptionsView composeOptionsView;
|
|
|
|
private BottomSheetBehavior composeOptionsBehavior;
|
|
|
|
private BottomSheetBehavior addMediaBehavior;
|
|
|
|
private BottomSheetBehavior emojiBehavior;
|
|
|
|
private RecyclerView emojiView;
|
|
|
|
|
2017-06-23 04:59:12 +10:00
|
|
|
// this only exists when a status is trying to be sent, but uploads are still occurring
|
|
|
|
private ProgressDialog finishingUploadDialog;
|
2017-01-20 15:59:21 +11:00
|
|
|
private String inReplyToId;
|
2018-03-10 08:02:32 +11:00
|
|
|
private List<QueuedMedia> mediaQueued = new ArrayList<>();
|
2017-01-17 05:15:42 +11:00
|
|
|
private CountUpDownLatch waitForMediaLatch;
|
2017-11-17 05:18:11 +11:00
|
|
|
private Status.Visibility statusVisibility; // The current values of the options that will be applied
|
2017-02-04 11:53:33 +11:00
|
|
|
private boolean statusMarkSensitive; // to the status being composed.
|
2017-11-17 05:18:11 +11:00
|
|
|
private boolean statusHideText;
|
2018-04-23 05:04:19 +10:00
|
|
|
private String startingText = "";
|
|
|
|
private String startingContentWarning = "";
|
2017-03-04 12:44:44 +11:00
|
|
|
private InputContentInfoCompat currentInputContentInfo;
|
|
|
|
private int currentFlags;
|
2017-04-16 01:43:26 +10:00
|
|
|
private Uri photoUploadUri;
|
2017-07-07 20:32:47 +10:00
|
|
|
private int savedTootUid = 0;
|
2018-04-22 18:35:46 +10:00
|
|
|
private List<Emoji> emojiList;
|
|
|
|
private int maximumTootCharacters = STATUS_CHARACTER_LIMIT;
|
2019-01-28 21:04:05 +11:00
|
|
|
private @Px
|
|
|
|
int thumbnailViewSize;
|
2017-06-29 03:33:54 +10:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
private SaveTootHelper saveTootHelper;
|
2018-11-12 05:25:45 +11:00
|
|
|
private Gson gson = new Gson();
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2017-01-08 09:24:02 +11:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2018-07-30 23:31:35 +10:00
|
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
String theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT);
|
|
|
|
if (theme.equals("black")) {
|
|
|
|
setTheme(R.style.TuskyDialogActivityBlackTheme);
|
|
|
|
}
|
2017-01-08 09:24:02 +11:00
|
|
|
setContentView(R.layout.activity_compose);
|
2017-06-23 04:59:12 +10:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
replyTextView = findViewById(R.id.composeReplyView);
|
|
|
|
replyContentTextView = findViewById(R.id.composeReplyContentView);
|
|
|
|
textEditor = findViewById(R.id.composeEditField);
|
2017-10-18 09:20:26 +11:00
|
|
|
mediaPreviewBar = findViewById(R.id.compose_media_preview_bar);
|
2018-04-14 06:37:21 +10:00
|
|
|
contentWarningBar = findViewById(R.id.composeContentWarningBar);
|
|
|
|
contentWarningEditor = findViewById(R.id.composeContentWarningField);
|
|
|
|
charactersLeft = findViewById(R.id.composeCharactersLeftView);
|
|
|
|
tootButton = findViewById(R.id.composeTootButton);
|
|
|
|
pickButton = findViewById(R.id.composeAddMediaButton);
|
|
|
|
visibilityButton = findViewById(R.id.composeToggleVisibilityButton);
|
|
|
|
contentWarningButton = findViewById(R.id.composeContentWarningButton);
|
|
|
|
emojiButton = findViewById(R.id.composeEmojiButton);
|
|
|
|
hideMediaToggle = findViewById(R.id.composeHideMediaButton);
|
|
|
|
emojiView = findViewById(R.id.emojiView);
|
2018-04-22 18:35:46 +10:00
|
|
|
emojiList = Collections.emptyList();
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2018-05-27 18:22:12 +10:00
|
|
|
saveTootHelper = new SaveTootHelper(database.tootDao(), this);
|
2017-01-08 09:24:02 +11:00
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
// Setup the toolbar.
|
2017-10-18 09:20:26 +11:00
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
2017-03-08 00:09:33 +11:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setTitle(null);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setDisplayShowHomeEnabled(true);
|
2017-04-03 09:10:07 +10:00
|
|
|
Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
|
2017-03-29 15:22:14 +11:00
|
|
|
ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
|
|
|
|
actionBar.setHomeAsUpIndicator(closeIcon);
|
2017-03-08 00:09:33 +11:00
|
|
|
}
|
|
|
|
|
2018-02-26 01:41:45 +11:00
|
|
|
// setup the account image
|
2018-03-28 04:47:00 +11:00
|
|
|
final AccountEntity activeAccount = accountManager.getActiveAccount();
|
2018-02-26 01:41:45 +11:00
|
|
|
|
2018-03-06 08:43:13 +11:00
|
|
|
if (activeAccount != null) {
|
2018-02-26 01:41:45 +11:00
|
|
|
ImageView composeAvatar = findViewById(R.id.composeAvatar);
|
|
|
|
|
2018-03-06 08:43:13 +11:00
|
|
|
if (TextUtils.isEmpty(activeAccount.getProfilePictureUrl())) {
|
2018-02-26 01:41:45 +11:00
|
|
|
composeAvatar.setImageResource(R.drawable.avatar_default);
|
|
|
|
} else {
|
|
|
|
Picasso.with(this).load(activeAccount.getProfilePictureUrl())
|
|
|
|
.error(R.drawable.avatar_default)
|
|
|
|
.placeholder(R.drawable.avatar_default)
|
|
|
|
.into(composeAvatar);
|
|
|
|
}
|
|
|
|
|
|
|
|
composeAvatar.setContentDescription(
|
|
|
|
getString(R.string.compose_active_account_description,
|
|
|
|
activeAccount.getFullName()));
|
|
|
|
|
2018-04-22 18:35:46 +10:00
|
|
|
mastodonApi.getInstance().enqueue(new Callback<Instance>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<Instance> call, @NonNull Response<Instance> response) {
|
|
|
|
if (response.isSuccessful() && response.body().getMaxTootChars() != null) {
|
|
|
|
maximumTootCharacters = response.body().getMaxTootChars();
|
|
|
|
updateVisibleCharactersLeft();
|
|
|
|
cacheInstanceMetadata(activeAccount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Instance> call, @NonNull Throwable t) {
|
|
|
|
Log.w(TAG, "error loading instance data", t);
|
|
|
|
loadCachedInstanceMetadata(activeAccount);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mastodonApi.getCustomEmojis().enqueue(new Callback<List<Emoji>>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<List<Emoji>> call, @NonNull Response<List<Emoji>> response) {
|
|
|
|
emojiList = response.body();
|
2018-11-28 07:07:15 +11:00
|
|
|
if(emojiList == null) {
|
|
|
|
emojiList = Collections.emptyList();
|
|
|
|
}
|
2018-12-13 06:28:05 +11:00
|
|
|
Collections.sort(emojiList, (a, b) ->
|
|
|
|
a.getShortcode().toLowerCase(Locale.ROOT).compareTo(
|
|
|
|
b.getShortcode().toLowerCase(Locale.ROOT)));
|
2018-04-23 17:26:03 +10:00
|
|
|
setEmojiList(emojiList);
|
2018-04-22 18:35:46 +10:00
|
|
|
cacheInstanceMetadata(activeAccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<List<Emoji>> call, @NonNull Throwable t) {
|
|
|
|
Log.w(TAG, "error loading custom emojis", t);
|
|
|
|
loadCachedInstanceMetadata(activeAccount);
|
|
|
|
}
|
|
|
|
});
|
2018-02-26 01:41:45 +11:00
|
|
|
} else {
|
|
|
|
// do not do anything when not logged in, activity will be finished in super.onCreate() anyway
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
composeOptionsView = findViewById(R.id.composeOptionsBottomSheet);
|
|
|
|
composeOptionsView.setListener(this);
|
|
|
|
|
|
|
|
composeOptionsBehavior = BottomSheetBehavior.from(composeOptionsView);
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
|
|
|
|
addMediaBehavior = BottomSheetBehavior.from(findViewById(R.id.addMediaBottomSheet));
|
|
|
|
|
|
|
|
emojiBehavior = BottomSheetBehavior.from(emojiView);
|
|
|
|
|
|
|
|
emojiView.setLayoutManager(new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false));
|
|
|
|
|
2018-04-18 06:39:55 +10:00
|
|
|
enableButton(emojiButton, false, false);
|
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
// Setup the interface buttons.
|
2018-04-14 06:37:21 +10:00
|
|
|
tootButton.setOnClickListener(v -> onSendClicked());
|
2017-11-28 06:11:31 +11:00
|
|
|
pickButton.setOnClickListener(v -> openPickDialog());
|
2018-04-14 06:37:21 +10:00
|
|
|
visibilityButton.setOnClickListener(v -> showComposeOptions());
|
|
|
|
contentWarningButton.setOnClickListener(v-> onContentWarningChanged());
|
|
|
|
emojiButton.setOnClickListener(v -> showEmojis());
|
2017-11-28 06:11:31 +11:00
|
|
|
hideMediaToggle.setOnClickListener(v -> toggleHideMedia());
|
2017-03-08 00:09:33 +11:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
TextView actionPhotoTake = findViewById(R.id.action_photo_take);
|
|
|
|
TextView actionPhotoPick = findViewById(R.id.action_photo_pick);
|
|
|
|
|
|
|
|
int textColor = ThemeUtils.getColor(this, android.R.attr.textColorTertiary);
|
|
|
|
|
|
|
|
Drawable cameraIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_camera_alt).color(textColor).sizeDp(18);
|
2018-12-03 21:22:57 +11:00
|
|
|
actionPhotoTake.setCompoundDrawablesRelativeWithIntrinsicBounds(cameraIcon, null, null, null);
|
2018-04-14 06:37:21 +10:00
|
|
|
|
|
|
|
Drawable imageIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_image).color(textColor).sizeDp(18);
|
2018-12-03 21:22:57 +11:00
|
|
|
actionPhotoPick.setCompoundDrawablesRelativeWithIntrinsicBounds(imageIcon, null, null, null);
|
2018-04-14 06:37:21 +10:00
|
|
|
|
|
|
|
actionPhotoTake.setOnClickListener(v -> initiateCameraApp());
|
|
|
|
actionPhotoPick.setOnClickListener(v -> onMediaPick());
|
2017-10-24 07:55:43 +11:00
|
|
|
|
2018-07-24 05:55:09 +10:00
|
|
|
thumbnailViewSize = getResources().getDimensionPixelSize(R.dimen.compose_media_preview_size);
|
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
/* Initialise all the state, or restore it from a previous run, to determine a "starting"
|
|
|
|
* state. */
|
2017-11-28 06:11:31 +11:00
|
|
|
Status.Visibility startingVisibility = Status.Visibility.UNKNOWN;
|
2017-03-27 10:37:32 +11:00
|
|
|
boolean startingHideText;
|
2017-02-18 09:56:31 +11:00
|
|
|
ArrayList<SavedQueuedMedia> savedMediaQueued = null;
|
|
|
|
if (savedInstanceState != null) {
|
2017-11-17 05:18:11 +11:00
|
|
|
startingVisibility = Status.Visibility.byNum(
|
|
|
|
savedInstanceState.getInt("statusVisibility",
|
|
|
|
Status.Visibility.PUBLIC.getNum())
|
|
|
|
);
|
2017-02-18 09:56:31 +11:00
|
|
|
statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
|
2017-03-27 10:37:32 +11:00
|
|
|
startingHideText = savedInstanceState.getBoolean("statusHideText");
|
2017-02-18 09:56:31 +11:00
|
|
|
// Keep these until everything needed to put them in the queue is finished initializing.
|
|
|
|
savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
|
2017-03-04 12:44:44 +11:00
|
|
|
// These are for restoring an in-progress commit content operation.
|
|
|
|
InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat.wrap(
|
|
|
|
savedInstanceState.getParcelable("commitContentInputContentInfo"));
|
|
|
|
int previousFlags = savedInstanceState.getInt("commitContentFlags");
|
|
|
|
if (previousInputContentInfo != null) {
|
|
|
|
onCommitContentInternal(previousInputContentInfo, previousFlags);
|
|
|
|
}
|
2017-07-03 07:45:13 +10:00
|
|
|
photoUploadUri = savedInstanceState.getParcelable("photoUploadUri");
|
2017-02-18 09:56:31 +11:00
|
|
|
} else {
|
2018-11-13 07:09:39 +11:00
|
|
|
statusMarkSensitive = activeAccount.getDefaultMediaSensitivity();
|
2017-03-27 10:37:32 +11:00
|
|
|
startingHideText = false;
|
2017-07-03 07:45:13 +10:00
|
|
|
photoUploadUri = null;
|
2017-02-18 09:56:31 +11:00
|
|
|
}
|
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
/* If the composer is started up as a reply to another post, override the "starting" state
|
|
|
|
* based on what the intent from the reply request passes. */
|
|
|
|
Intent intent = getIntent();
|
2017-03-11 04:38:49 +11:00
|
|
|
|
2017-01-20 15:59:21 +11:00
|
|
|
String[] mentionedUsernames = null;
|
2017-07-08 12:56:07 +10:00
|
|
|
ArrayList<String> loadedDraftMediaUris = null;
|
2018-11-12 05:25:45 +11:00
|
|
|
ArrayList<String> loadedDraftMediaDescriptions = null;
|
2017-03-27 08:21:18 +11:00
|
|
|
inReplyToId = null;
|
2017-01-20 15:59:21 +11:00
|
|
|
if (intent != null) {
|
2017-11-28 06:11:31 +11:00
|
|
|
|
2018-01-09 09:16:21 +11:00
|
|
|
if (startingVisibility == Status.Visibility.UNKNOWN) {
|
2018-11-13 07:09:39 +11:00
|
|
|
Status.Visibility preferredVisibility = activeAccount.getDefaultPostPrivacy();
|
2017-11-28 06:11:31 +11:00
|
|
|
Status.Visibility replyVisibility = Status.Visibility.byNum(
|
|
|
|
intent.getIntExtra(REPLY_VISIBILITY_EXTRA, Status.Visibility.UNKNOWN.getNum()));
|
|
|
|
|
2018-05-10 07:04:00 +10:00
|
|
|
startingVisibility = Status.Visibility.byNum(Math.max(preferredVisibility.getNum(), replyVisibility.getNum()));
|
2017-11-28 06:11:31 +11:00
|
|
|
}
|
|
|
|
|
2017-11-02 06:59:29 +11:00
|
|
|
inReplyToId = intent.getStringExtra(IN_REPLY_TO_ID_EXTRA);
|
2017-03-15 00:31:52 +11:00
|
|
|
|
2017-11-02 06:59:29 +11:00
|
|
|
mentionedUsernames = intent.getStringArrayExtra(MENTIONED_USERNAMES_EXTRA);
|
2017-04-08 04:37:27 +10:00
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
String contentWarning = intent.getStringExtra(CONTENT_WARNING_EXTRA);
|
|
|
|
if (contentWarning != null) {
|
|
|
|
startingHideText = !contentWarning.isEmpty();
|
2017-05-03 08:17:54 +10:00
|
|
|
if (startingHideText) {
|
2017-11-17 05:18:11 +11:00
|
|
|
startingContentWarning = contentWarning;
|
2017-07-08 12:56:07 +10:00
|
|
|
}
|
2017-04-08 04:37:27 +10:00
|
|
|
}
|
2017-07-06 00:36:14 +10:00
|
|
|
|
2017-07-08 12:56:07 +10:00
|
|
|
// If come from SavedTootActivity
|
2017-11-02 06:59:29 +11:00
|
|
|
String savedTootText = intent.getStringExtra(SAVED_TOOT_TEXT_EXTRA);
|
2017-07-06 00:36:14 +10:00
|
|
|
if (!TextUtils.isEmpty(savedTootText)) {
|
2018-04-23 05:04:19 +10:00
|
|
|
startingText = savedTootText;
|
|
|
|
textEditor.setText(savedTootText);
|
2017-07-06 00:36:14 +10:00
|
|
|
}
|
|
|
|
|
2018-11-12 05:25:45 +11:00
|
|
|
// try to redo a list of media
|
2017-11-02 06:59:29 +11:00
|
|
|
String savedJsonUrls = intent.getStringExtra(SAVED_JSON_URLS_EXTRA);
|
2018-11-12 05:25:45 +11:00
|
|
|
String savedJsonDescriptions = intent.getStringExtra(SAVED_JSON_DESCRIPTIONS_EXTRA);
|
2017-07-06 00:36:14 +10:00
|
|
|
if (!TextUtils.isEmpty(savedJsonUrls)) {
|
2018-11-12 05:25:45 +11:00
|
|
|
loadedDraftMediaUris = gson.fromJson(savedJsonUrls,
|
|
|
|
new TypeToken<ArrayList<String>>() {
|
|
|
|
}.getType());
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(savedJsonDescriptions)) {
|
|
|
|
loadedDraftMediaDescriptions = gson.fromJson(savedJsonDescriptions,
|
2017-10-30 08:18:45 +11:00
|
|
|
new TypeToken<ArrayList<String>>() {
|
|
|
|
}.getType());
|
2017-07-07 20:32:47 +10:00
|
|
|
}
|
2017-07-06 00:36:14 +10:00
|
|
|
|
2017-11-02 06:59:29 +11:00
|
|
|
int savedTootUid = intent.getIntExtra(SAVED_TOOT_UID_EXTRA, 0);
|
2017-07-07 20:32:47 +10:00
|
|
|
if (savedTootUid != 0) {
|
|
|
|
this.savedTootUid = savedTootUid;
|
2017-07-06 00:36:14 +10:00
|
|
|
}
|
2017-11-02 06:59:29 +11:00
|
|
|
|
2018-08-24 04:50:50 +10:00
|
|
|
int savedTootVisibility = intent.getIntExtra(SAVED_TOOT_VISIBILITY_EXTRA, Status.Visibility.UNKNOWN.getNum());
|
|
|
|
if (savedTootVisibility != Status.Visibility.UNKNOWN.getNum()) {
|
|
|
|
startingVisibility = Status.Visibility.byNum(savedTootVisibility);
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:59:29 +11:00
|
|
|
if (intent.hasExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA)) {
|
|
|
|
replyTextView.setVisibility(View.VISIBLE);
|
|
|
|
String username = intent.getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA);
|
|
|
|
replyTextView.setText(getString(R.string.replying_to, username));
|
2018-04-14 06:37:21 +10:00
|
|
|
Drawable arrowDownIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_down).sizeDp(12);
|
|
|
|
|
|
|
|
ThemeUtils.setDrawableTint(this, arrowDownIcon, android.R.attr.textColorTertiary);
|
2018-12-03 21:22:57 +11:00
|
|
|
replyTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, arrowDownIcon, null);
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2017-11-28 06:11:31 +11:00
|
|
|
replyTextView.setOnClickListener(v -> {
|
2018-04-14 06:37:21 +10:00
|
|
|
TransitionManager.beginDelayedTransition((ViewGroup)replyContentTextView.getParent());
|
|
|
|
|
2017-11-28 06:11:31 +11:00
|
|
|
if (replyContentTextView.getVisibility() != View.VISIBLE) {
|
|
|
|
replyContentTextView.setVisibility(View.VISIBLE);
|
2018-04-14 06:37:21 +10:00
|
|
|
Drawable arrowUpIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_up).sizeDp(12);
|
|
|
|
|
|
|
|
ThemeUtils.setDrawableTint(this, arrowUpIcon, android.R.attr.textColorTertiary);
|
2018-12-03 21:22:57 +11:00
|
|
|
replyTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, arrowUpIcon, null);
|
2017-11-28 06:11:31 +11:00
|
|
|
} else {
|
|
|
|
replyContentTextView.setVisibility(View.GONE);
|
2018-12-03 21:22:57 +11:00
|
|
|
replyTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, arrowDownIcon, null);
|
2017-11-02 06:59:29 +11:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intent.hasExtra(REPLYING_STATUS_CONTENT_EXTRA)) {
|
|
|
|
replyContentTextView.setText(intent.getStringExtra(REPLYING_STATUS_CONTENT_EXTRA));
|
|
|
|
}
|
2017-01-20 15:59:21 +11:00
|
|
|
}
|
2017-05-03 08:17:54 +10:00
|
|
|
|
|
|
|
// After the starting state is finalised, the interface can be set to reflect this state.
|
2017-11-28 06:11:31 +11:00
|
|
|
setStatusVisibility(startingVisibility);
|
2017-11-17 05:18:11 +11:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
updateHideMediaToggle();
|
2017-07-15 08:18:29 +10:00
|
|
|
updateVisibleCharactersLeft();
|
2017-01-20 15:59:21 +11:00
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
// Setup the main text field.
|
2018-04-14 06:37:21 +10:00
|
|
|
textEditor.setOnCommitContentListener(this);
|
2018-05-17 03:14:26 +10:00
|
|
|
final int mentionColour = textEditor.getLinkTextColors().getDefaultColor();
|
|
|
|
SpanUtilsKt.highlightSpans(textEditor.getText(), mentionColour);
|
2017-03-21 23:52:15 +11:00
|
|
|
textEditor.addTextChangedListener(new TextWatcher() {
|
2017-01-08 09:24:02 +11:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-16 18:43:32 +10:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
2017-01-08 09:24:02 +11:00
|
|
|
|
|
|
|
@Override
|
2017-01-20 15:59:21 +11:00
|
|
|
public void afterTextChanged(Editable editable) {
|
2018-05-17 03:14:26 +10:00
|
|
|
SpanUtilsKt.highlightSpans(editable, mentionColour);
|
|
|
|
updateVisibleCharactersLeft();
|
2017-01-20 15:59:21 +11:00
|
|
|
}
|
2017-03-21 23:52:15 +11:00
|
|
|
});
|
2017-01-08 09:24:02 +11:00
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
textEditor.setAdapter(
|
2019-01-28 21:04:05 +11:00
|
|
|
new MentionTagAutoCompleteAdapter(this));
|
|
|
|
textEditor.setTokenizer(new MentionTagTokenizer());
|
2017-06-19 12:10:50 +10:00
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
// Add any mentions to the text field when a reply is first composed.
|
2017-01-20 15:59:21 +11:00
|
|
|
if (mentionedUsernames != null) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
for (String name : mentionedUsernames) {
|
|
|
|
builder.append('@');
|
|
|
|
builder.append(name);
|
|
|
|
builder.append(' ');
|
|
|
|
}
|
2018-04-23 05:04:19 +10:00
|
|
|
startingText = builder.toString();
|
|
|
|
textEditor.setText(startingText);
|
2017-01-20 15:59:21 +11:00
|
|
|
textEditor.setSelection(textEditor.length());
|
|
|
|
}
|
|
|
|
|
2018-07-27 07:31:20 +10:00
|
|
|
// work around Android platform bug -> https://issuetracker.google.com/issues/67102093
|
|
|
|
if(Build.VERSION.SDK_INT == Build.VERSION_CODES.O || Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1 ) {
|
|
|
|
textEditor.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
|
|
|
}
|
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
// Initialise the content warning editor.
|
2017-03-20 13:38:39 +11:00
|
|
|
contentWarningEditor.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
2017-05-16 18:43:32 +10:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
2017-03-20 13:38:39 +11:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
2017-04-11 03:34:33 +10:00
|
|
|
updateVisibleCharactersLeft();
|
2017-03-20 13:38:39 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-16 18:43:32 +10:00
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
}
|
2017-03-20 13:38:39 +11:00
|
|
|
});
|
2017-03-27 10:37:32 +11:00
|
|
|
showContentWarning(startingHideText);
|
2017-05-16 18:43:32 +10:00
|
|
|
if (startingContentWarning != null) {
|
2017-04-08 04:37:27 +10:00
|
|
|
contentWarningEditor.setText(startingContentWarning);
|
|
|
|
}
|
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
// Initialise the empty media queue state.
|
|
|
|
waitForMediaLatch = new CountUpDownLatch();
|
2017-01-17 05:15:42 +11:00
|
|
|
|
2017-03-08 00:09:33 +11:00
|
|
|
// These can only be added after everything affected by the media queue is initialized.
|
2017-10-30 08:18:45 +11:00
|
|
|
if (!ListUtils.isEmpty(loadedDraftMediaUris)) {
|
2018-11-12 05:25:45 +11:00
|
|
|
for (int mediaIndex = 0; mediaIndex < loadedDraftMediaUris.size(); ++mediaIndex) {
|
|
|
|
Uri uri = Uri.parse(loadedDraftMediaUris.get(mediaIndex));
|
2018-10-01 19:50:17 +10:00
|
|
|
long mediaSize = getMediaSize(getContentResolver(), uri);
|
2018-11-12 05:25:45 +11:00
|
|
|
String description = null;
|
|
|
|
if (loadedDraftMediaDescriptions != null && mediaIndex < loadedDraftMediaDescriptions.size()) {
|
|
|
|
description = loadedDraftMediaDescriptions.get(mediaIndex);
|
|
|
|
}
|
|
|
|
pickMedia(uri, mediaSize, description);
|
2017-07-08 12:56:07 +10:00
|
|
|
}
|
2017-07-12 11:49:46 +10:00
|
|
|
} else if (savedMediaQueued != null) {
|
2017-03-08 00:09:33 +11:00
|
|
|
for (SavedQueuedMedia item : savedMediaQueued) {
|
2018-10-01 19:50:17 +10:00
|
|
|
Bitmap preview = getImageThumbnail(getContentResolver(), item.uri, thumbnailViewSize);
|
2018-05-06 21:02:02 +10:00
|
|
|
addMediaToQueue(item.id, item.type, preview, item.uri, item.mediaSize, item.readyStage, item.description);
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
2017-04-06 15:11:44 +10:00
|
|
|
} else if (intent != null && savedInstanceState == null) {
|
2017-04-06 06:35:22 +10:00
|
|
|
/* Get incoming images being sent through a share action from another app. Only do this
|
|
|
|
* when savedInstanceState is null, otherwise both the images from the intent and the
|
|
|
|
* instance state will be re-queued. */
|
|
|
|
String type = intent.getType();
|
2017-04-06 15:11:44 +10:00
|
|
|
if (type != null) {
|
2018-09-29 01:11:32 +10:00
|
|
|
if (type.startsWith("image/") || type.startsWith("video/")) {
|
2017-04-06 15:11:44 +10:00
|
|
|
List<Uri> uriList = new ArrayList<>();
|
2017-11-17 05:18:11 +11:00
|
|
|
if (intent.getAction() != null) {
|
|
|
|
switch (intent.getAction()) {
|
|
|
|
case Intent.ACTION_SEND: {
|
|
|
|
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
|
|
|
if (uri != null) {
|
|
|
|
uriList.add(uri);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-06 15:11:44 +10:00
|
|
|
}
|
2017-11-17 05:18:11 +11:00
|
|
|
case Intent.ACTION_SEND_MULTIPLE: {
|
|
|
|
ArrayList<Uri> list = intent.getParcelableArrayListExtra(
|
|
|
|
Intent.EXTRA_STREAM);
|
|
|
|
if (list != null) {
|
|
|
|
for (Uri uri : list) {
|
|
|
|
if (uri != null) {
|
|
|
|
uriList.add(uri);
|
|
|
|
}
|
2017-04-06 15:11:44 +10:00
|
|
|
}
|
2017-04-06 06:35:22 +10:00
|
|
|
}
|
2017-11-17 05:18:11 +11:00
|
|
|
break;
|
2017-04-06 06:35:22 +10:00
|
|
|
}
|
2017-04-06 15:11:44 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Uri uri : uriList) {
|
2018-10-01 19:50:17 +10:00
|
|
|
long mediaSize = getMediaSize(getContentResolver(), uri);
|
2018-11-12 05:25:45 +11:00
|
|
|
pickMedia(uri, mediaSize, null);
|
2017-04-06 15:11:44 +10:00
|
|
|
}
|
|
|
|
} else if (type.equals("text/plain")) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (action != null && action.equals(Intent.ACTION_SEND)) {
|
|
|
|
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
|
|
|
|
if (text != null) {
|
|
|
|
int start = Math.max(textEditor.getSelectionStart(), 0);
|
|
|
|
int end = Math.max(textEditor.getSelectionEnd(), 0);
|
|
|
|
int left = Math.min(start, end);
|
|
|
|
int right = Math.max(start, end);
|
|
|
|
textEditor.getText().replace(left, right, text, 0, text.length());
|
2017-04-06 06:35:22 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-08 00:09:33 +11:00
|
|
|
}
|
2018-11-12 05:25:45 +11:00
|
|
|
for (QueuedMedia item : mediaQueued) {
|
|
|
|
item.preview.setChecked(!TextUtils.isEmpty(item.description));
|
|
|
|
}
|
2017-11-02 06:59:29 +11:00
|
|
|
|
2018-03-06 08:43:13 +11:00
|
|
|
textEditor.requestFocus();
|
2017-03-08 00:09:33 +11:00
|
|
|
}
|
2017-01-17 05:15:42 +11:00
|
|
|
|
2017-05-03 08:17:54 +10:00
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
ArrayList<SavedQueuedMedia> savedMediaQueued = new ArrayList<>();
|
|
|
|
for (QueuedMedia item : mediaQueued) {
|
2018-05-06 21:02:02 +10:00
|
|
|
savedMediaQueued.add(new SavedQueuedMedia(item.id, item.type, item.uri,
|
2018-01-09 09:16:21 +11:00
|
|
|
item.mediaSize, item.readyStage, item.description));
|
2017-05-03 08:17:54 +10:00
|
|
|
}
|
|
|
|
outState.putParcelableArrayList("savedMediaQueued", savedMediaQueued);
|
|
|
|
outState.putBoolean("statusMarkSensitive", statusMarkSensitive);
|
|
|
|
outState.putBoolean("statusHideText", statusHideText);
|
|
|
|
if (currentInputContentInfo != null) {
|
|
|
|
outState.putParcelable("commitContentInputContentInfo",
|
|
|
|
(Parcelable) currentInputContentInfo.unwrap());
|
|
|
|
outState.putInt("commitContentFlags", currentFlags);
|
|
|
|
}
|
|
|
|
currentInputContentInfo = null;
|
|
|
|
currentFlags = 0;
|
2017-07-03 07:45:13 +10:00
|
|
|
outState.putParcelable("photoUploadUri", photoUploadUri);
|
2017-11-28 06:11:31 +11:00
|
|
|
outState.putInt("statusVisibility", statusVisibility.getNum());
|
2017-05-03 08:17:54 +10:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
|
2017-07-31 07:16:32 +10:00
|
|
|
View.OnClickListener listener) {
|
2017-05-03 08:17:54 +10:00
|
|
|
Snackbar bar = Snackbar.make(findViewById(R.id.activity_compose), getString(descriptionId),
|
|
|
|
Snackbar.LENGTH_SHORT);
|
|
|
|
bar.setAction(actionId, listener);
|
2018-04-14 06:37:21 +10:00
|
|
|
//necessary so snackbar is shown over everything
|
2018-12-03 21:22:57 +11:00
|
|
|
bar.getView().setElevation(getResources().getDimensionPixelSize(R.dimen.compose_activity_snackbar_elevation));
|
2017-05-03 08:17:54 +10:00
|
|
|
bar.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayTransientError(@StringRes int stringId) {
|
2018-04-14 06:37:21 +10:00
|
|
|
Snackbar bar = Snackbar.make(findViewById(R.id.activity_compose), stringId, Snackbar.LENGTH_LONG);
|
|
|
|
//necessary so snackbar is shown over everything
|
2018-12-03 21:22:57 +11:00
|
|
|
bar.getView().setElevation(getResources().getDimensionPixelSize(R.dimen.compose_activity_snackbar_elevation));
|
2018-04-14 06:37:21 +10:00
|
|
|
bar.show();
|
2017-05-03 08:17:54 +10:00
|
|
|
}
|
|
|
|
|
2017-06-21 04:16:03 +10:00
|
|
|
private void toggleHideMedia() {
|
2017-03-11 04:38:49 +11:00
|
|
|
statusMarkSensitive = !statusMarkSensitive;
|
2018-04-14 06:37:21 +10:00
|
|
|
updateHideMediaToggle();
|
2017-03-29 15:22:14 +11:00
|
|
|
}
|
2017-03-11 04:38:49 +11:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
private void updateHideMediaToggle() {
|
|
|
|
TransitionManager.beginDelayedTransition((ViewGroup)hideMediaToggle.getParent());
|
|
|
|
|
|
|
|
@ColorInt int color;
|
|
|
|
if(mediaQueued.size() == 0) {
|
|
|
|
hideMediaToggle.setVisibility(View.GONE);
|
2017-03-11 04:38:49 +11:00
|
|
|
} else {
|
2018-04-14 06:37:21 +10:00
|
|
|
hideMediaToggle.setVisibility(View.VISIBLE);
|
|
|
|
if (statusMarkSensitive) {
|
|
|
|
hideMediaToggle.setImageResource(R.drawable.ic_hide_media_24dp);
|
|
|
|
if (statusHideText) {
|
|
|
|
hideMediaToggle.setClickable(false);
|
|
|
|
color = ContextCompat.getColor(this, R.color.compose_media_visible_button_disabled_blue);
|
|
|
|
} else {
|
|
|
|
hideMediaToggle.setClickable(true);
|
2018-12-18 01:25:35 +11:00
|
|
|
color = ContextCompat.getColor(this, R.color.tusky_blue);
|
2018-04-14 06:37:21 +10:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hideMediaToggle.setClickable(true);
|
|
|
|
hideMediaToggle.setImageResource(R.drawable.ic_eye_24dp);
|
|
|
|
color = ThemeUtils.getColor(this, android.R.attr.textColorTertiary);
|
|
|
|
}
|
|
|
|
hideMediaToggle.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
2017-03-11 04:38:49 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-16 01:52:21 +10:00
|
|
|
private void disableButtons() {
|
2017-07-28 12:40:58 +10:00
|
|
|
pickButton.setClickable(false);
|
2018-04-14 06:37:21 +10:00
|
|
|
visibilityButton.setClickable(false);
|
|
|
|
emojiButton.setClickable(false);
|
2017-07-27 14:56:53 +10:00
|
|
|
hideMediaToggle.setClickable(false);
|
2018-04-14 06:37:21 +10:00
|
|
|
tootButton.setEnabled(false);
|
2017-04-16 01:52:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
private void enableButtons() {
|
2017-07-28 12:40:58 +10:00
|
|
|
pickButton.setClickable(true);
|
2018-04-14 06:37:21 +10:00
|
|
|
visibilityButton.setClickable(true);
|
|
|
|
emojiButton.setClickable(true);
|
2017-07-27 14:56:53 +10:00
|
|
|
hideMediaToggle.setClickable(true);
|
2018-04-14 06:37:21 +10:00
|
|
|
tootButton.setEnabled(true);
|
2017-07-12 16:09:07 +10:00
|
|
|
}
|
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
private void setStatusVisibility(Status.Visibility visibility) {
|
2017-03-27 09:26:47 +11:00
|
|
|
statusVisibility = visibility;
|
2018-04-14 06:37:21 +10:00
|
|
|
composeOptionsView.setStatusVisibility(visibility);
|
|
|
|
tootButton.setStatusVisibility(visibility);
|
|
|
|
|
2017-03-27 09:26:47 +11:00
|
|
|
switch (visibility) {
|
2017-11-17 05:18:11 +11:00
|
|
|
case PUBLIC: {
|
2017-04-21 15:50:59 +10:00
|
|
|
Drawable globe = AppCompatResources.getDrawable(this, R.drawable.ic_public_24dp);
|
|
|
|
if (globe != null) {
|
2018-04-14 06:37:21 +10:00
|
|
|
visibilityButton.setImageDrawable(globe);
|
2017-04-21 15:50:59 +10:00
|
|
|
}
|
2017-03-27 09:26:47 +11:00
|
|
|
break;
|
|
|
|
}
|
2017-11-17 05:18:11 +11:00
|
|
|
case PRIVATE: {
|
2017-04-21 15:50:59 +10:00
|
|
|
Drawable lock = AppCompatResources.getDrawable(this,
|
|
|
|
R.drawable.ic_lock_outline_24dp);
|
2017-04-03 09:10:07 +10:00
|
|
|
if (lock != null) {
|
2018-04-14 06:37:21 +10:00
|
|
|
visibilityButton.setImageDrawable(lock);
|
2017-04-03 09:10:07 +10:00
|
|
|
}
|
2017-03-27 09:26:47 +11:00
|
|
|
break;
|
|
|
|
}
|
2017-11-17 05:18:11 +11:00
|
|
|
case DIRECT: {
|
2017-04-21 15:50:59 +10:00
|
|
|
Drawable envelope = AppCompatResources.getDrawable(this, R.drawable.ic_email_24dp);
|
|
|
|
if (envelope != null) {
|
2018-04-14 06:37:21 +10:00
|
|
|
visibilityButton.setImageDrawable(envelope);
|
2017-04-21 15:50:59 +10:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-17 05:18:11 +11:00
|
|
|
case UNLISTED:
|
2017-03-27 09:26:47 +11:00
|
|
|
default: {
|
2018-04-14 06:37:21 +10:00
|
|
|
Drawable openLock = AppCompatResources.getDrawable(this, R.drawable.ic_lock_open_24dp);
|
2017-04-21 15:50:59 +10:00
|
|
|
if (openLock != null) {
|
2018-04-14 06:37:21 +10:00
|
|
|
visibilityButton.setImageDrawable(openLock);
|
2017-04-21 15:50:59 +10:00
|
|
|
}
|
2017-03-27 09:26:47 +11:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 00:09:33 +11:00
|
|
|
private void showComposeOptions() {
|
2018-04-14 06:37:21 +10:00
|
|
|
if (composeOptionsBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN || composeOptionsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
emojiBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showEmojis() {
|
|
|
|
|
2018-04-18 06:39:55 +10:00
|
|
|
if(emojiView.getAdapter() != null) {
|
|
|
|
if(emojiView.getAdapter().getItemCount() == 0) {
|
|
|
|
String errorMessage = getString(R.string.error_no_custom_emojis, accountManager.getActiveAccount().getDomain());
|
|
|
|
Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show();
|
|
|
|
} else {
|
|
|
|
if (emojiBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN || emojiBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
|
emojiBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
emojiBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
}
|
2018-04-18 06:39:55 +10:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
private void openPickDialog() {
|
|
|
|
if (addMediaBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN || addMediaBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
|
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
emojiBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onMediaPick() {
|
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
|
|
|
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
|
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
|
|
|
ActivityCompat.requestPermissions(this,
|
|
|
|
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
|
|
|
PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
|
|
|
} else {
|
|
|
|
initiateMediaPicking();
|
|
|
|
}
|
2017-03-08 00:09:33 +11:00
|
|
|
}
|
2017-02-18 09:56:31 +11:00
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
@Override
|
2018-04-14 06:37:21 +10:00
|
|
|
public void onVisibilityChanged(@NonNull Status.Visibility visibility) {
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
2017-04-05 12:29:15 +10:00
|
|
|
setStatusVisibility(visibility);
|
|
|
|
}
|
|
|
|
|
2018-07-11 03:39:52 +10:00
|
|
|
int calculateTextLength() {
|
2018-05-17 03:14:26 +10:00
|
|
|
int offset = 0;
|
|
|
|
URLSpan[] urlSpans = textEditor.getUrls();
|
|
|
|
if (urlSpans != null) {
|
|
|
|
for (URLSpan span : urlSpans) {
|
|
|
|
offset += Math.max(0, span.getURL().length() - MAXIMUM_URL_LENGTH);
|
|
|
|
}
|
|
|
|
}
|
2018-07-11 03:39:52 +10:00
|
|
|
int length = textEditor.length() - offset;
|
2017-04-11 03:34:33 +10:00
|
|
|
if (statusHideText) {
|
2018-07-11 03:39:52 +10:00
|
|
|
length += contentWarningEditor.length();
|
2017-04-11 03:34:33 +10:00
|
|
|
}
|
2018-07-11 03:39:52 +10:00
|
|
|
return length;
|
2018-05-17 03:14:26 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVisibleCharactersLeft() {
|
2018-07-11 03:39:52 +10:00
|
|
|
this.charactersLeft.setText(String.format(Locale.getDefault(), "%d", maximumTootCharacters - calculateTextLength()));
|
2017-04-11 03:34:33 +10:00
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
private void onContentWarningChanged() {
|
|
|
|
boolean showWarning = contentWarningBar.getVisibility() != View.VISIBLE;
|
|
|
|
showContentWarning(showWarning);
|
2017-04-11 03:34:33 +10:00
|
|
|
updateVisibleCharactersLeft();
|
2017-04-05 12:29:15 +10:00
|
|
|
}
|
|
|
|
|
2017-05-04 10:27:59 +10:00
|
|
|
private void onSendClicked() {
|
2018-04-14 06:37:21 +10:00
|
|
|
disableButtons();
|
2017-05-04 10:27:59 +10:00
|
|
|
readyStatus(statusVisibility, statusMarkSensitive);
|
2017-02-18 09:56:31 +11:00
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
@Override
|
|
|
|
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
|
2017-03-04 12:44:44 +11:00
|
|
|
try {
|
|
|
|
if (currentInputContentInfo != null) {
|
|
|
|
currentInputContentInfo.releasePermission();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(TAG, "InputContentInfoCompat#releasePermission() failed." + e.getMessage());
|
|
|
|
} finally {
|
|
|
|
currentInputContentInfo = null;
|
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
// Verify the returned content's type is of the correct MIME type
|
|
|
|
boolean supported = inputContentInfo.getDescription().hasMimeType("image/*");
|
2017-03-04 12:44:44 +11:00
|
|
|
|
|
|
|
return supported && onCommitContentInternal(inputContentInfo, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean onCommitContentInternal(InputContentInfoCompat inputContentInfo, int flags) {
|
|
|
|
if ((flags & InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
|
|
|
|
try {
|
|
|
|
inputContentInfo.requestPermission();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(TAG, "InputContentInfoCompat#requestPermission() failed." + e.getMessage());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the file size before putting handing it off to be put in the queue.
|
|
|
|
Uri uri = inputContentInfo.getContentUri();
|
|
|
|
long mediaSize;
|
|
|
|
AssetFileDescriptor descriptor = null;
|
|
|
|
try {
|
|
|
|
descriptor = getContentResolver().openAssetFileDescriptor(uri, "r");
|
|
|
|
} catch (FileNotFoundException e) {
|
2017-05-26 01:21:11 +10:00
|
|
|
Log.d(TAG, Log.getStackTraceString(e));
|
2017-03-04 12:44:44 +11:00
|
|
|
// Eat this exception, having the descriptor be null is sufficient.
|
|
|
|
}
|
|
|
|
if (descriptor != null) {
|
|
|
|
mediaSize = descriptor.getLength();
|
|
|
|
try {
|
|
|
|
descriptor.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// Just eat this exception.
|
|
|
|
}
|
|
|
|
} else {
|
2018-10-01 19:50:17 +10:00
|
|
|
mediaSize = MEDIA_SIZE_UNKNOWN;
|
2017-03-04 12:44:44 +11:00
|
|
|
}
|
2018-11-12 05:25:45 +11:00
|
|
|
pickMedia(uri, mediaSize, null);
|
2017-03-04 12:44:44 +11:00
|
|
|
|
|
|
|
currentInputContentInfo = inputContentInfo;
|
|
|
|
currentFlags = flags;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
private void sendStatus(String content, Status.Visibility visibility, boolean sensitive,
|
2017-10-30 08:18:45 +11:00
|
|
|
String spoilerText) {
|
2017-03-14 11:49:12 +11:00
|
|
|
ArrayList<String> mediaIds = new ArrayList<>();
|
2018-06-29 06:22:29 +10:00
|
|
|
ArrayList<Uri> mediaUris = new ArrayList<>();
|
2018-11-12 05:25:45 +11:00
|
|
|
ArrayList<String> mediaDescriptions = new ArrayList<>();
|
2017-03-10 02:59:18 +11:00
|
|
|
for (QueuedMedia item : mediaQueued) {
|
|
|
|
mediaIds.add(item.id);
|
2018-06-29 06:22:29 +10:00
|
|
|
mediaUris.add(item.uri);
|
2018-11-12 05:25:45 +11:00
|
|
|
mediaDescriptions.add(item.description);
|
2017-01-20 15:59:21 +11:00
|
|
|
}
|
2017-03-10 02:59:18 +11:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
Intent sendIntent = SendTootService.sendTootIntent(this, content, spoilerText,
|
2018-11-12 05:25:45 +11:00
|
|
|
visibility, sensitive, mediaIds, mediaUris, mediaDescriptions, inReplyToId,
|
2018-04-14 06:37:21 +10:00
|
|
|
getIntent().getStringExtra(REPLYING_STATUS_CONTENT_EXTRA),
|
|
|
|
getIntent().getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA),
|
|
|
|
getIntent().getStringExtra(SAVED_JSON_URLS_EXTRA),
|
|
|
|
accountManager.getActiveAccount(), savedTootUid);
|
2017-01-20 15:59:21 +11:00
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
startService(sendIntent);
|
2017-11-03 07:18:39 +11:00
|
|
|
|
2018-08-08 07:08:53 +10:00
|
|
|
finishWithoutSlideOutAnimation();
|
2017-11-17 05:18:11 +11:00
|
|
|
|
2017-02-04 11:53:33 +11:00
|
|
|
}
|
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
private void readyStatus(final Status.Visibility visibility, final boolean sensitive) {
|
2017-03-04 12:44:44 +11:00
|
|
|
finishingUploadDialog = ProgressDialog.show(
|
2017-02-07 18:05:50 +11:00
|
|
|
this, getString(R.string.dialog_title_finishing_media_upload),
|
|
|
|
getString(R.string.dialog_message_uploading_media), true, true);
|
2017-11-17 05:18:11 +11:00
|
|
|
@SuppressLint("StaticFieldLeak") final AsyncTask<Void, Void, Boolean> waitForMediaTask =
|
2017-01-20 15:59:21 +11:00
|
|
|
new AsyncTask<Void, Void, Boolean>() {
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... params) {
|
|
|
|
try {
|
|
|
|
waitForMediaLatch.await();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Boolean successful) {
|
|
|
|
super.onPostExecute(successful);
|
2017-03-04 12:44:44 +11:00
|
|
|
finishingUploadDialog.dismiss();
|
|
|
|
finishingUploadDialog = null;
|
2017-01-20 15:59:21 +11:00
|
|
|
if (successful) {
|
2017-05-04 10:27:59 +10:00
|
|
|
onReadySuccess(visibility, sensitive);
|
2017-01-20 15:59:21 +11:00
|
|
|
} else {
|
2017-05-04 10:27:59 +10:00
|
|
|
onReadyFailure(visibility, sensitive);
|
2017-01-20 15:59:21 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCancelled() {
|
|
|
|
removeAllMediaFromQueue();
|
2018-04-14 06:37:21 +10:00
|
|
|
enableButtons();
|
2017-01-20 15:59:21 +11:00
|
|
|
super.onCancelled();
|
|
|
|
}
|
|
|
|
};
|
2017-11-28 06:11:31 +11:00
|
|
|
finishingUploadDialog.setOnCancelListener(dialog -> {
|
|
|
|
/* Generating an interrupt by passing true here is important because an interrupt
|
|
|
|
* exception is the only thing that will kick the latch out of its waiting loop
|
|
|
|
* early. */
|
|
|
|
waitForMediaTask.cancel(true);
|
2017-01-20 15:59:21 +11:00
|
|
|
});
|
|
|
|
waitForMediaTask.execute();
|
|
|
|
}
|
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
private void onReadySuccess(Status.Visibility visibility, boolean sensitive) {
|
2018-07-11 03:39:52 +10:00
|
|
|
/* Validate the status meets the character limit. */
|
2017-05-04 10:27:59 +10:00
|
|
|
String contentText = textEditor.getText().toString();
|
|
|
|
String spoilerText = "";
|
|
|
|
if (statusHideText) {
|
|
|
|
spoilerText = contentWarningEditor.getText().toString();
|
|
|
|
}
|
2018-07-11 03:39:52 +10:00
|
|
|
int characterCount = calculateTextLength();
|
2019-01-28 21:04:05 +11:00
|
|
|
if (characterCount <= 0 && mediaQueued.size() == 0) {
|
2017-05-04 10:27:59 +10:00
|
|
|
textEditor.setError(getString(R.string.error_empty));
|
2018-04-14 06:37:21 +10:00
|
|
|
enableButtons();
|
2018-04-22 18:35:46 +10:00
|
|
|
} else if (characterCount <= maximumTootCharacters) {
|
2018-04-14 06:37:21 +10:00
|
|
|
sendStatus(contentText, visibility, sensitive, spoilerText);
|
|
|
|
|
2017-05-04 10:27:59 +10:00
|
|
|
} else {
|
|
|
|
textEditor.setError(getString(R.string.error_compose_character_limit));
|
2018-04-14 06:37:21 +10:00
|
|
|
enableButtons();
|
2017-05-04 10:27:59 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
private void onReadyFailure(final Status.Visibility visibility, final boolean sensitive) {
|
2017-01-20 15:59:21 +11:00
|
|
|
doErrorDialog(R.string.error_media_upload_sending, R.string.action_retry,
|
2017-11-28 06:11:31 +11:00
|
|
|
v -> readyStatus(visibility, sensitive));
|
2018-04-14 06:37:21 +10:00
|
|
|
enableButtons();
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
|
2017-10-30 08:18:45 +11:00
|
|
|
@NonNull int[] grantResults) {
|
2017-01-17 05:15:42 +11:00
|
|
|
switch (requestCode) {
|
|
|
|
case PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
|
|
|
|
if (grantResults.length > 0
|
|
|
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
initiateMediaPicking();
|
|
|
|
} else {
|
|
|
|
doErrorDialog(R.string.error_media_upload_permission, R.string.action_retry,
|
2017-11-28 06:11:31 +11:00
|
|
|
v -> onMediaPick());
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 07:45:13 +10:00
|
|
|
@NonNull
|
2017-04-16 01:43:26 +10:00
|
|
|
private File createNewImageFile() throws IOException {
|
|
|
|
// Create an image file name
|
2018-09-08 03:57:25 +10:00
|
|
|
String randomId = StringUtils.randomAlphanumericString(12);
|
|
|
|
String imageFileName = "Tusky_" + randomId + "_";
|
2017-04-16 01:43:26 +10:00
|
|
|
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
2017-04-21 15:50:59 +10:00
|
|
|
return File.createTempFile(
|
2017-04-16 01:43:26 +10:00
|
|
|
imageFileName, /* prefix */
|
|
|
|
".jpg", /* suffix */
|
|
|
|
storageDir /* directory */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initiateCameraApp() {
|
2018-04-14 06:37:21 +10:00
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
|
2017-04-16 01:43:26 +10:00
|
|
|
// We don't need to ask for permission in this case, because the used calls require
|
|
|
|
// android.permission.WRITE_EXTERNAL_STORAGE only on SDKs *older* than Kitkat, which was
|
|
|
|
// way before permission dialogues have been introduced.
|
|
|
|
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
if (intent.resolveActivity(getPackageManager()) != null) {
|
|
|
|
File photoFile = null;
|
|
|
|
try {
|
|
|
|
photoFile = createNewImageFile();
|
|
|
|
} catch (IOException ex) {
|
|
|
|
displayTransientError(R.string.error_media_upload_opening);
|
|
|
|
}
|
|
|
|
// Continue only if the File was successfully created
|
|
|
|
if (photoFile != null) {
|
|
|
|
photoUploadUri = FileProvider.getUriForFile(this,
|
2018-04-14 06:37:21 +10:00
|
|
|
BuildConfig.APPLICATION_ID+".fileprovider",
|
2017-04-16 01:43:26 +10:00
|
|
|
photoFile);
|
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUploadUri);
|
|
|
|
startActivityForResult(intent, MEDIA_TAKE_PHOTO_RESULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 05:15:42 +11:00
|
|
|
private void initiateMediaPicking() {
|
2018-06-29 06:22:29 +10:00
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
2017-01-17 05:15:42 +11:00
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
2018-04-14 21:56:48 +10:00
|
|
|
|
|
|
|
String[] mimeTypes = new String[]{"image/*", "video/*"};
|
|
|
|
intent.setType("*/*");
|
|
|
|
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
|
2017-01-17 05:15:42 +11:00
|
|
|
startActivityForResult(intent, MEDIA_PICK_RESULT);
|
|
|
|
}
|
|
|
|
|
2018-04-18 06:39:55 +10:00
|
|
|
private void enableButton(ImageButton button, boolean clickable, boolean colorActive) {
|
|
|
|
button.setEnabled(clickable);
|
|
|
|
ThemeUtils.setDrawableTint(this, button.getDrawable(),
|
|
|
|
colorActive ? android.R.attr.textColorTertiary : R.attr.compose_media_button_disabled_tint);
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
|
2018-11-12 05:25:45 +11:00
|
|
|
private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize, @Nullable String description) {
|
|
|
|
addMediaToQueue(null, type, preview, uri, mediaSize, null, description);
|
2018-05-06 21:02:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addMediaToQueue(@Nullable String id, QueuedMedia.Type type, Bitmap preview, Uri uri,
|
|
|
|
long mediaSize, QueuedMedia.ReadyStage readyStage, @Nullable String description) {
|
2018-01-09 09:16:21 +11:00
|
|
|
final QueuedMedia item = new QueuedMedia(type, uri, new ProgressImageView(this),
|
|
|
|
mediaSize, description);
|
2018-05-06 21:02:02 +10:00
|
|
|
item.id = id;
|
2017-10-29 07:24:26 +11:00
|
|
|
item.readyStage = readyStage;
|
2017-02-17 05:52:55 +11:00
|
|
|
ImageView view = item.preview;
|
2017-01-17 05:15:42 +11:00
|
|
|
Resources resources = getResources();
|
|
|
|
int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
|
|
|
|
int marginBottom = resources.getDimensionPixelSize(
|
|
|
|
R.dimen.compose_media_preview_margin_bottom);
|
2018-07-24 05:55:09 +10:00
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(thumbnailViewSize, thumbnailViewSize);
|
2017-03-11 04:38:49 +11:00
|
|
|
layoutParams.setMargins(margin, 0, margin, marginBottom);
|
2017-01-17 05:15:42 +11:00
|
|
|
view.setLayoutParams(layoutParams);
|
2017-03-15 11:34:27 +11:00
|
|
|
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
|
view.setImageBitmap(preview);
|
2018-01-09 09:16:21 +11:00
|
|
|
view.setOnClickListener(v -> onMediaClick(item, v));
|
2017-07-19 12:32:13 +10:00
|
|
|
view.setContentDescription(getString(R.string.action_delete));
|
2017-01-17 05:15:42 +11:00
|
|
|
mediaPreviewBar.addView(view);
|
|
|
|
mediaQueued.add(item);
|
|
|
|
int queuedCount = mediaQueued.size();
|
|
|
|
if (queuedCount == 1) {
|
|
|
|
// If there's one video in the queue it is full, so disable the button to queue more.
|
2017-02-17 05:52:55 +11:00
|
|
|
if (item.type == QueuedMedia.Type.VIDEO) {
|
2018-04-18 06:39:55 +10:00
|
|
|
enableButton(pickButton, false, false);
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
} else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
|
|
|
|
// Limit the total media attachments, also.
|
2018-04-18 06:39:55 +10:00
|
|
|
enableButton(pickButton, false, false);
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
2018-04-14 06:37:21 +10:00
|
|
|
|
|
|
|
updateHideMediaToggle();
|
|
|
|
|
2017-10-29 07:24:26 +11:00
|
|
|
if (item.readyStage != QueuedMedia.ReadyStage.UPLOADED) {
|
|
|
|
waitForMediaLatch.countUp();
|
2018-06-18 21:26:31 +10:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (type == QueuedMedia.Type.IMAGE &&
|
2018-10-01 19:50:17 +10:00
|
|
|
(mediaSize > STATUS_IMAGE_SIZE_LIMIT || getImageSquarePixels(getContentResolver(), item.uri) > STATUS_IMAGE_PIXEL_SIZE_LIMIT)) {
|
2018-06-18 21:26:31 +10:00
|
|
|
downsizeMedia(item);
|
|
|
|
} else {
|
|
|
|
uploadMedia(item);
|
|
|
|
}
|
2018-09-08 03:57:25 +10:00
|
|
|
} catch (IOException e) {
|
2018-06-18 21:26:31 +10:00
|
|
|
onUploadFailure(item, false);
|
2017-10-29 07:24:26 +11:00
|
|
|
}
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 09:16:21 +11:00
|
|
|
private void onMediaClick(QueuedMedia item, View view) {
|
|
|
|
PopupMenu popup = new PopupMenu(this, view);
|
|
|
|
final int addCaptionId = 1;
|
|
|
|
final int removeId = 2;
|
|
|
|
popup.getMenu().add(0, addCaptionId, 0, R.string.action_set_caption);
|
|
|
|
popup.getMenu().add(0, removeId, 0, R.string.action_remove_media);
|
|
|
|
popup.setOnMenuItemClickListener(menuItem -> {
|
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
case addCaptionId:
|
|
|
|
makeCaptionDialog(item);
|
|
|
|
break;
|
|
|
|
case removeId:
|
|
|
|
removeMediaFromQueue(item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
popup.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void makeCaptionDialog(QueuedMedia item) {
|
|
|
|
LinearLayout dialogLayout = new LinearLayout(this);
|
|
|
|
int padding = Utils.dpToPx(this, 8);
|
|
|
|
dialogLayout.setPadding(padding, padding, padding, padding);
|
|
|
|
|
|
|
|
dialogLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
ImageView imageView = new ImageView(this);
|
2018-08-16 04:47:36 +10:00
|
|
|
|
|
|
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
|
|
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
|
|
|
|
2018-09-04 04:26:35 +10:00
|
|
|
Single.fromCallable(() ->
|
2018-10-01 19:50:17 +10:00
|
|
|
getSampledBitmap(getContentResolver(), item.uri, displayMetrics.widthPixels, displayMetrics.heightPixels))
|
2018-09-04 04:26:35 +10:00
|
|
|
.subscribeOn(Schedulers.computation())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
|
|
|
.subscribe(new SingleObserver<Bitmap>() {
|
|
|
|
@Override
|
|
|
|
public void onSubscribe(Disposable d) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Bitmap bitmap) {
|
|
|
|
imageView.setImageBitmap(bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(Throwable e) { }
|
|
|
|
});
|
|
|
|
|
2018-01-09 09:16:21 +11:00
|
|
|
|
|
|
|
int margin = Utils.dpToPx(this, 4);
|
|
|
|
dialogLayout.addView(imageView);
|
|
|
|
((LinearLayout.LayoutParams) imageView.getLayoutParams()).weight = 1;
|
|
|
|
imageView.getLayoutParams().height = 0;
|
|
|
|
((LinearLayout.LayoutParams) imageView.getLayoutParams()).setMargins(0, margin, 0, 0);
|
|
|
|
|
|
|
|
EditText input = new EditText(this);
|
2018-11-12 05:25:45 +11:00
|
|
|
input.setHint(getString(R.string.hint_describe_for_visually_impaired, MEDIA_DESCRIPTION_CHARACTER_LIMIT));
|
2018-01-09 09:16:21 +11:00
|
|
|
dialogLayout.addView(input);
|
|
|
|
((LinearLayout.LayoutParams) input.getLayoutParams()).setMargins(margin, margin, margin, margin);
|
2018-11-12 05:25:45 +11:00
|
|
|
input.setLines(2);
|
2018-01-09 09:16:21 +11:00
|
|
|
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
|
|
|
|
input.setText(item.description);
|
2018-11-12 05:25:45 +11:00
|
|
|
input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(MEDIA_DESCRIPTION_CHARACTER_LIMIT) });
|
2018-01-09 09:16:21 +11:00
|
|
|
|
2018-03-06 08:43:13 +11:00
|
|
|
DialogInterface.OnClickListener okListener = (dialog, which) -> {
|
2018-11-12 05:25:45 +11:00
|
|
|
Runnable updateDescription = () -> {
|
|
|
|
mastodonApi.updateMedia(item.id, input.getText().toString()).enqueue(new Callback<Attachment>() {
|
2018-03-06 08:43:13 +11:00
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<Attachment> call, @NonNull Response<Attachment> response) {
|
|
|
|
Attachment attachment = response.body();
|
|
|
|
if (response.isSuccessful() && attachment != null) {
|
|
|
|
item.description = attachment.getDescription();
|
2018-07-30 23:20:53 +10:00
|
|
|
item.preview.setChecked(item.description != null && !item.description.isEmpty());
|
2018-03-06 08:43:13 +11:00
|
|
|
dialog.dismiss();
|
|
|
|
} else {
|
|
|
|
showFailedCaptionMessage();
|
|
|
|
}
|
2018-11-12 05:25:45 +11:00
|
|
|
item.updateDescription = null;
|
2018-03-06 08:43:13 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
|
|
|
|
showFailedCaptionMessage();
|
2018-11-12 05:25:45 +11:00
|
|
|
item.updateDescription = null;
|
2018-03-06 08:43:13 +11:00
|
|
|
}
|
|
|
|
});
|
2018-11-12 05:25:45 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
if (item.readyStage == QueuedMedia.ReadyStage.UPLOADED) {
|
|
|
|
updateDescription.run();
|
|
|
|
} else {
|
|
|
|
// media is still uploading, queue description update for when it finishes
|
|
|
|
item.updateDescription = updateDescription;
|
|
|
|
}
|
2018-03-06 08:43:13 +11:00
|
|
|
};
|
|
|
|
|
2018-01-09 09:16:21 +11:00
|
|
|
AlertDialog dialog = new AlertDialog.Builder(this)
|
|
|
|
.setView(dialogLayout)
|
2018-03-06 08:43:13 +11:00
|
|
|
.setPositiveButton(android.R.string.ok, okListener)
|
2018-01-09 09:16:21 +11:00
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.create();
|
|
|
|
|
|
|
|
Window window = dialog.getWindow();
|
|
|
|
if (window != null) {
|
|
|
|
window.setSoftInputMode(
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showFailedCaptionMessage() {
|
|
|
|
Toast.makeText(this, R.string.error_failed_set_caption, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
2017-01-17 05:15:42 +11:00
|
|
|
private void removeMediaFromQueue(QueuedMedia item) {
|
2017-02-17 05:52:55 +11:00
|
|
|
mediaPreviewBar.removeView(item.preview);
|
2017-01-17 05:15:42 +11:00
|
|
|
mediaQueued.remove(item);
|
|
|
|
if (mediaQueued.size() == 0) {
|
2018-04-14 06:37:21 +10:00
|
|
|
updateHideMediaToggle();
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
2018-04-14 06:37:21 +10:00
|
|
|
|
2018-04-18 06:39:55 +10:00
|
|
|
enableButton(pickButton, true, true);
|
2017-01-17 05:15:42 +11:00
|
|
|
cancelReadyingMedia(item);
|
|
|
|
}
|
|
|
|
|
2017-01-19 05:35:07 +11:00
|
|
|
private void removeAllMediaFromQueue() {
|
2017-05-16 18:43:32 +10:00
|
|
|
for (Iterator<QueuedMedia> it = mediaQueued.iterator(); it.hasNext(); ) {
|
2017-01-19 05:35:07 +11:00
|
|
|
QueuedMedia item = it.next();
|
|
|
|
it.remove();
|
|
|
|
removeMediaFromQueue(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-08 03:57:25 +10:00
|
|
|
private void downsizeMedia(final QueuedMedia item) throws IOException {
|
2017-02-17 05:52:55 +11:00
|
|
|
item.readyStage = QueuedMedia.ReadyStage.DOWNSIZING;
|
2017-01-17 05:15:42 +11:00
|
|
|
|
2018-09-08 03:57:25 +10:00
|
|
|
new DownsizeImageTask(STATUS_IMAGE_SIZE_LIMIT, getContentResolver(), createNewImageFile(),
|
2017-04-01 08:53:35 +11:00
|
|
|
new DownsizeImageTask.Listener() {
|
|
|
|
@Override
|
2018-09-08 03:57:25 +10:00
|
|
|
public void onSuccess(File tempFile) {
|
|
|
|
item.uri = FileProvider.getUriForFile(
|
|
|
|
ComposeActivity.this,
|
|
|
|
BuildConfig.APPLICATION_ID+".fileprovider",
|
|
|
|
tempFile);
|
2017-04-01 08:53:35 +11:00
|
|
|
uploadMedia(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure() {
|
|
|
|
onMediaDownsizeFailure(item);
|
|
|
|
}
|
2017-05-16 18:43:32 +10:00
|
|
|
}).execute(item.uri);
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onMediaDownsizeFailure(QueuedMedia item) {
|
2018-09-07 06:48:19 +10:00
|
|
|
displayTransientError(R.string.error_image_upload_size);
|
2017-01-17 05:15:42 +11:00
|
|
|
removeMediaFromQueue(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void uploadMedia(final QueuedMedia item) {
|
2017-02-17 05:52:55 +11:00
|
|
|
item.readyStage = QueuedMedia.ReadyStage.UPLOADING;
|
2017-01-17 05:15:42 +11:00
|
|
|
|
2017-10-30 08:18:45 +11:00
|
|
|
String mimeType = getContentResolver().getType(item.uri);
|
2017-01-17 05:15:42 +11:00
|
|
|
MimeTypeMap map = MimeTypeMap.getSingleton();
|
|
|
|
String fileExtension = map.getExtensionFromMimeType(mimeType);
|
|
|
|
final String filename = String.format("%s_%s_%s.%s",
|
|
|
|
getString(R.string.app_name),
|
|
|
|
String.valueOf(new Date().getTime()),
|
2017-07-03 06:34:10 +10:00
|
|
|
StringUtils.randomAlphanumericString(10),
|
2017-01-17 05:15:42 +11:00
|
|
|
fileExtension);
|
|
|
|
|
2018-09-08 03:57:25 +10:00
|
|
|
InputStream stream;
|
2017-03-10 02:59:18 +11:00
|
|
|
|
2018-09-08 03:57:25 +10:00
|
|
|
try {
|
|
|
|
stream = getContentResolver().openInputStream(item.uri);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return;
|
2017-03-10 02:59:18 +11:00
|
|
|
}
|
|
|
|
|
2017-10-30 08:18:45 +11:00
|
|
|
if (mimeType == null) mimeType = "multipart/form-data";
|
|
|
|
|
|
|
|
item.preview.setProgress(0);
|
|
|
|
|
2018-10-01 19:50:17 +10:00
|
|
|
ProgressRequestBody fileBody = new ProgressRequestBody(stream, getMediaSize(getContentResolver(), item.uri), MediaType.parse(mimeType),
|
2017-10-30 08:18:45 +11:00
|
|
|
new ProgressRequestBody.UploadCallback() { // may reference activity longer than I would like to
|
|
|
|
int lastProgress = -1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onProgressUpdate(final int percentage) {
|
|
|
|
if (percentage != lastProgress) {
|
2017-11-28 06:11:31 +11:00
|
|
|
runOnUiThread(() -> item.preview.setProgress(percentage));
|
2017-10-30 08:18:45 +11:00
|
|
|
}
|
|
|
|
lastProgress = percentage;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
MultipartBody.Part body = MultipartBody.Part.createFormData("file", filename, fileBody);
|
2017-03-10 02:59:18 +11:00
|
|
|
|
2017-06-23 04:01:25 +10:00
|
|
|
item.uploadRequest = mastodonApi.uploadMedia(body);
|
2017-03-10 02:59:18 +11:00
|
|
|
|
2017-12-01 06:12:09 +11:00
|
|
|
item.uploadRequest.enqueue(new Callback<Attachment>() {
|
2017-01-17 05:15:42 +11:00
|
|
|
@Override
|
2017-12-01 06:12:09 +11:00
|
|
|
public void onResponse(@NonNull Call<Attachment> call, @NonNull retrofit2.Response<Attachment> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (response.isSuccessful()) {
|
2017-05-04 10:27:59 +10:00
|
|
|
onUploadSuccess(item, response.body());
|
2018-11-12 05:25:45 +11:00
|
|
|
if (item.updateDescription != null) {
|
|
|
|
item.updateDescription.run();
|
|
|
|
}
|
2017-03-14 11:49:12 +11:00
|
|
|
} else {
|
|
|
|
Log.d(TAG, "Upload request failed. " + response.message());
|
2017-03-15 11:34:27 +11:00
|
|
|
onUploadFailure(item, call.isCanceled());
|
2017-03-14 11:49:12 +11:00
|
|
|
}
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-12-01 06:12:09 +11:00
|
|
|
public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
|
2017-07-03 07:55:18 +10:00
|
|
|
Log.d(TAG, "Upload request failed. " + t.getMessage());
|
|
|
|
onUploadFailure(item, call.isCanceled());
|
2018-11-12 05:25:45 +11:00
|
|
|
item.updateDescription = null;
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
2017-03-10 02:59:18 +11:00
|
|
|
});
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
|
2017-12-01 06:12:09 +11:00
|
|
|
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
|
2018-03-03 23:24:03 +11:00
|
|
|
item.id = media.getId();
|
2017-10-30 08:18:45 +11:00
|
|
|
item.preview.setProgress(-1);
|
2017-10-29 07:24:26 +11:00
|
|
|
item.readyStage = QueuedMedia.ReadyStage.UPLOADED;
|
2017-05-04 10:27:59 +10:00
|
|
|
|
|
|
|
waitForMediaLatch.countDown();
|
|
|
|
}
|
|
|
|
|
2017-03-15 11:34:27 +11:00
|
|
|
private void onUploadFailure(QueuedMedia item, boolean isCanceled) {
|
2017-03-15 12:25:47 +11:00
|
|
|
if (!isCanceled) {
|
2017-03-15 11:34:27 +11:00
|
|
|
/* if the upload was voluntarily cancelled, such as if the user clicked on it to remove
|
|
|
|
* it from the queue, then don't display this error message. */
|
|
|
|
displayTransientError(R.string.error_media_upload_sending);
|
|
|
|
}
|
2017-11-08 01:01:20 +11:00
|
|
|
if (finishingUploadDialog != null && finishingUploadDialog.isShowing()) {
|
2017-03-04 12:44:44 +11:00
|
|
|
finishingUploadDialog.cancel();
|
|
|
|
}
|
2017-07-03 07:55:18 +10:00
|
|
|
if (!isCanceled) {
|
|
|
|
// If it is canceled, it's already been removed, otherwise do it.
|
|
|
|
removeMediaFromQueue(item);
|
|
|
|
}
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
private void cancelReadyingMedia(QueuedMedia item) {
|
2017-02-17 05:52:55 +11:00
|
|
|
if (item.readyStage == QueuedMedia.ReadyStage.UPLOADING) {
|
2017-02-18 09:56:31 +11:00
|
|
|
item.uploadRequest.cancel();
|
|
|
|
}
|
|
|
|
if (item.id == null) {
|
|
|
|
/* The presence of an upload id is used to detect if it finished uploading or not, to
|
|
|
|
* prevent counting down twice on the same media item. */
|
|
|
|
waitForMediaLatch.countDown();
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-14 06:37:21 +10:00
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, intent);
|
|
|
|
if (resultCode == RESULT_OK && requestCode == MEDIA_PICK_RESULT && intent != null) {
|
|
|
|
Uri uri = intent.getData();
|
2018-10-01 19:50:17 +10:00
|
|
|
long mediaSize = getMediaSize(getContentResolver(), uri);
|
2018-11-12 05:25:45 +11:00
|
|
|
pickMedia(uri, mediaSize, null);
|
2017-07-03 07:45:13 +10:00
|
|
|
} else if (resultCode == RESULT_OK && requestCode == MEDIA_TAKE_PHOTO_RESULT) {
|
2018-10-01 19:50:17 +10:00
|
|
|
long mediaSize = getMediaSize(getContentResolver(), photoUploadUri);
|
2018-11-12 05:25:45 +11:00
|
|
|
pickMedia(photoUploadUri, mediaSize, null);
|
2017-03-04 12:44:44 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 07:54:41 +10:00
|
|
|
|
2018-11-12 05:25:45 +11:00
|
|
|
private void pickMedia(Uri uri, long mediaSize, String description) {
|
2018-10-01 19:50:17 +10:00
|
|
|
if (mediaSize == MEDIA_SIZE_UNKNOWN) {
|
2017-03-04 12:44:44 +11:00
|
|
|
displayTransientError(R.string.error_media_upload_opening);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-06 07:48:17 +11:00
|
|
|
ContentResolver contentResolver = getContentResolver();
|
2017-03-04 12:44:44 +11:00
|
|
|
String mimeType = contentResolver.getType(uri);
|
|
|
|
if (mimeType != null) {
|
|
|
|
String topLevelType = mimeType.substring(0, mimeType.indexOf('/'));
|
|
|
|
switch (topLevelType) {
|
|
|
|
case "video": {
|
2018-09-07 06:48:19 +10:00
|
|
|
if (mediaSize > STATUS_VIDEO_SIZE_LIMIT) {
|
|
|
|
displayTransientError(R.string.error_image_upload_size);
|
2017-03-04 12:44:44 +11:00
|
|
|
return;
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
2017-03-04 12:44:44 +11:00
|
|
|
if (mediaQueued.size() > 0
|
|
|
|
&& mediaQueued.get(0).type == QueuedMedia.Type.IMAGE) {
|
|
|
|
displayTransientError(R.string.error_media_upload_image_or_video);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-01 19:50:17 +10:00
|
|
|
Bitmap bitmap = getVideoThumbnail(this, uri, thumbnailViewSize);
|
2017-07-21 07:54:41 +10:00
|
|
|
if (bitmap != null) {
|
2018-11-12 05:25:45 +11:00
|
|
|
addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize, description);
|
2017-07-21 07:54:41 +10:00
|
|
|
} else {
|
2017-07-19 14:28:36 +10:00
|
|
|
displayTransientError(R.string.error_media_upload_opening);
|
|
|
|
}
|
2017-03-04 12:44:44 +11:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "image": {
|
2018-10-01 19:50:17 +10:00
|
|
|
Bitmap bitmap = getImageThumbnail(contentResolver, uri, thumbnailViewSize);
|
2017-07-21 07:54:41 +10:00
|
|
|
if (bitmap != null) {
|
2018-11-12 05:25:45 +11:00
|
|
|
addMediaToQueue(QueuedMedia.Type.IMAGE, bitmap, uri, mediaSize, description);
|
2017-07-21 07:54:41 +10:00
|
|
|
} else {
|
2017-03-04 12:44:44 +11:00
|
|
|
displayTransientError(R.string.error_media_upload_opening);
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
2017-03-04 12:44:44 +11:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
displayTransientError(R.string.error_media_upload_type);
|
|
|
|
break;
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
|
|
|
}
|
2017-03-04 12:44:44 +11:00
|
|
|
} else {
|
|
|
|
displayTransientError(R.string.error_media_upload_type);
|
2017-01-17 05:15:42 +11:00
|
|
|
}
|
2017-01-08 09:24:02 +11:00
|
|
|
}
|
2017-02-04 11:53:33 +11:00
|
|
|
|
2017-07-08 12:56:07 +10:00
|
|
|
private void showContentWarning(boolean show) {
|
2017-02-04 11:53:33 +11:00
|
|
|
statusHideText = show;
|
2018-04-14 06:37:21 +10:00
|
|
|
TransitionManager.beginDelayedTransition((ViewGroup)contentWarningBar.getParent());
|
2017-02-04 11:53:33 +11:00
|
|
|
if (show) {
|
2018-04-14 06:37:21 +10:00
|
|
|
statusMarkSensitive = true;
|
2017-02-04 11:53:33 +11:00
|
|
|
contentWarningBar.setVisibility(View.VISIBLE);
|
2018-12-18 01:25:35 +11:00
|
|
|
contentWarningButton.setTextColor(ContextCompat.getColor(this, R.color.tusky_blue));
|
2018-10-13 06:53:04 +11:00
|
|
|
contentWarningEditor.setSelection(contentWarningEditor.getText().length());
|
|
|
|
contentWarningEditor.requestFocus();
|
2017-02-04 11:53:33 +11:00
|
|
|
} else {
|
|
|
|
contentWarningBar.setVisibility(View.GONE);
|
2018-04-14 06:37:21 +10:00
|
|
|
contentWarningButton.setTextColor(ThemeUtils.getColor(this, android.R.attr.textColorTertiary));
|
2017-02-04 11:53:33 +11:00
|
|
|
}
|
2018-04-14 06:37:21 +10:00
|
|
|
updateHideMediaToggle();
|
|
|
|
|
2017-02-04 11:53:33 +11:00
|
|
|
}
|
2017-03-08 00:09:33 +11:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2018-03-06 08:43:13 +11:00
|
|
|
case android.R.id.home:
|
|
|
|
handleCloseButton();
|
2017-03-08 00:09:33 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2017-05-16 18:43:32 +10:00
|
|
|
|
2018-03-06 08:43:13 +11:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
// Acting like a teen: deliberately ignoring parent.
|
|
|
|
handleCloseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleCloseButton() {
|
2018-12-08 03:05:02 +11:00
|
|
|
|
|
|
|
if(composeOptionsBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED ||
|
|
|
|
addMediaBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED ||
|
|
|
|
emojiBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED ) {
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
emojiBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-23 05:04:19 +10:00
|
|
|
CharSequence contentText = textEditor.getText();
|
|
|
|
CharSequence contentWarning = contentWarningEditor.getText();
|
|
|
|
|
|
|
|
boolean textChanged = !(TextUtils.isEmpty(contentText) || startingText.startsWith(contentText.toString()));
|
|
|
|
boolean contentWarningChanged = contentWarningBar.getVisibility() == View.VISIBLE &&
|
|
|
|
!TextUtils.isEmpty(contentWarning) && !startingContentWarning.startsWith(contentWarning.toString());
|
|
|
|
boolean mediaChanged = !mediaQueued.isEmpty();
|
|
|
|
|
|
|
|
if (textChanged || contentWarningChanged || mediaChanged) {
|
2018-03-06 08:43:13 +11:00
|
|
|
new AlertDialog.Builder(this)
|
2018-04-14 06:37:21 +10:00
|
|
|
.setMessage(R.string.compose_save_draft)
|
|
|
|
.setPositiveButton(R.string.action_save, (d, w) -> saveDraftAndFinish())
|
2018-08-08 07:08:53 +10:00
|
|
|
.setNegativeButton(R.string.action_delete, (d, w) -> finishWithoutSlideOutAnimation())
|
2018-03-06 08:43:13 +11:00
|
|
|
.show();
|
|
|
|
} else {
|
2018-08-08 07:08:53 +10:00
|
|
|
finishWithoutSlideOutAnimation();
|
2018-03-06 08:43:13 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
private void saveDraftAndFinish() {
|
|
|
|
ArrayList<String> mediaUris = new ArrayList<>();
|
2018-11-12 05:25:45 +11:00
|
|
|
ArrayList<String> mediaDescriptions = new ArrayList<>();
|
2018-04-14 06:37:21 +10:00
|
|
|
for (QueuedMedia item : mediaQueued) {
|
|
|
|
mediaUris.add(item.uri.toString());
|
2018-11-12 05:25:45 +11:00
|
|
|
mediaDescriptions.add(item.description);
|
2018-04-14 06:37:21 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
saveTootHelper.saveToot(textEditor.getText().toString(),
|
|
|
|
contentWarningEditor.getText().toString(),
|
|
|
|
getIntent().getStringExtra("saved_json_urls"),
|
|
|
|
mediaUris,
|
2018-11-12 05:25:45 +11:00
|
|
|
mediaDescriptions,
|
2018-04-14 06:37:21 +10:00
|
|
|
savedTootUid,
|
|
|
|
inReplyToId,
|
|
|
|
getIntent().getStringExtra(REPLYING_STATUS_CONTENT_EXTRA),
|
|
|
|
getIntent().getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA),
|
|
|
|
statusVisibility);
|
2018-08-24 04:57:51 +10:00
|
|
|
finishWithoutSlideOutAnimation();
|
2018-04-14 06:37:21 +10:00
|
|
|
}
|
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
@Override
|
2019-01-28 21:04:05 +11:00
|
|
|
public List<MentionTagAutoCompleteAdapter.AutocompleteResult> search(String token) {
|
2017-06-19 12:10:50 +10:00
|
|
|
try {
|
2019-01-28 21:04:05 +11:00
|
|
|
switch (token.charAt(0)) {
|
|
|
|
case '@':
|
|
|
|
ArrayList<Account> resultList = new ArrayList<>();
|
|
|
|
List<Account> accountList = mastodonApi
|
|
|
|
.searchAccounts(token.substring(1), false, 20)
|
|
|
|
.execute()
|
|
|
|
.body();
|
|
|
|
if (accountList != null) {
|
|
|
|
resultList.addAll(accountList);
|
|
|
|
}
|
|
|
|
return CollectionsKt.map(resultList, MentionTagAutoCompleteAdapter.AccountResult::new);
|
|
|
|
case '#':
|
|
|
|
Response<SearchResults> response = mastodonApi.search(token, false).execute();
|
|
|
|
if (response.isSuccessful() && response.body() != null) {
|
|
|
|
return CollectionsKt.map(
|
|
|
|
response.body().getHashtags(),
|
|
|
|
MentionTagAutoCompleteAdapter.HashtagResult::new
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Log.e(TAG, String.format("Autocomplete search for %s failed.", token));
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
Log.w(TAG, "Unexpected autocompletion token: " + token);
|
|
|
|
return Collections.emptyList();
|
2017-06-19 12:10:50 +10:00
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
2019-01-28 21:04:05 +11:00
|
|
|
Log.e(TAG, String.format("Autocomplete search for %s failed.", token));
|
|
|
|
return Collections.emptyList();
|
2017-06-19 12:10:50 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
@Override
|
|
|
|
public void onEmojiSelected(@NotNull String shortcode) {
|
|
|
|
textEditor.getText().insert(textEditor.getSelectionStart(), ":"+shortcode+": ");
|
|
|
|
}
|
|
|
|
|
2018-04-23 05:04:19 +10:00
|
|
|
private void loadCachedInstanceMetadata(@NotNull AccountEntity activeAccount) {
|
2018-05-27 18:22:12 +10:00
|
|
|
InstanceEntity instanceEntity = database.instanceDao()
|
|
|
|
.loadMetadataForInstance(activeAccount.getDomain());
|
2018-04-22 18:35:46 +10:00
|
|
|
|
|
|
|
if(instanceEntity != null) {
|
|
|
|
Integer max = instanceEntity.getMaximumTootCharacters();
|
2018-04-23 05:04:19 +10:00
|
|
|
maximumTootCharacters = (max == null ? STATUS_CHARACTER_LIMIT : max);
|
2018-04-22 18:35:46 +10:00
|
|
|
emojiList = instanceEntity.getEmojiList();
|
2018-04-23 17:26:03 +10:00
|
|
|
setEmojiList(emojiList);
|
|
|
|
updateVisibleCharactersLeft();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setEmojiList(@Nullable List<Emoji> emojiList) {
|
|
|
|
if (emojiList != null) {
|
|
|
|
emojiView.setAdapter(new EmojiAdapter(emojiList, ComposeActivity.this));
|
|
|
|
enableButton(emojiButton, true, emojiList.size() > 0);
|
2018-04-22 18:35:46 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 17:26:03 +10:00
|
|
|
private void cacheInstanceMetadata(@NotNull AccountEntity activeAccount) {
|
2018-04-22 18:35:46 +10:00
|
|
|
InstanceEntity instanceEntity = new InstanceEntity(activeAccount.getDomain(), emojiList, maximumTootCharacters);
|
2018-05-27 18:22:12 +10:00
|
|
|
database.instanceDao().insertOrReplace(instanceEntity);
|
2018-04-22 18:35:46 +10:00
|
|
|
}
|
|
|
|
|
2018-04-29 18:08:25 +10:00
|
|
|
// Accessors for testing, hence package scope
|
|
|
|
int getMaximumTootCharacters()
|
|
|
|
{
|
|
|
|
return maximumTootCharacters;
|
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
public static final class QueuedMedia {
|
2017-05-16 18:43:32 +10:00
|
|
|
Type type;
|
2017-10-30 08:18:45 +11:00
|
|
|
ProgressImageView preview;
|
2017-05-16 18:43:32 +10:00
|
|
|
Uri uri;
|
|
|
|
String id;
|
2017-12-01 06:12:09 +11:00
|
|
|
Call<Attachment> uploadRequest;
|
2017-05-16 18:43:32 +10:00
|
|
|
ReadyStage readyStage;
|
|
|
|
long mediaSize;
|
2018-01-09 09:16:21 +11:00
|
|
|
String description;
|
2018-11-12 05:25:45 +11:00
|
|
|
Runnable updateDescription;
|
2017-05-16 18:43:32 +10:00
|
|
|
|
2018-01-09 09:16:21 +11:00
|
|
|
QueuedMedia(Type type, Uri uri, ProgressImageView preview, long mediaSize,
|
|
|
|
String description) {
|
2017-05-16 18:43:32 +10:00
|
|
|
this.type = type;
|
|
|
|
this.uri = uri;
|
|
|
|
this.preview = preview;
|
|
|
|
this.mediaSize = mediaSize;
|
2018-01-09 09:16:21 +11:00
|
|
|
this.description = description;
|
2017-05-16 18:43:32 +10:00
|
|
|
}
|
|
|
|
|
2018-04-14 06:37:21 +10:00
|
|
|
public enum Type {
|
2017-05-16 18:43:32 +10:00
|
|
|
IMAGE,
|
|
|
|
VIDEO
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ReadyStage {
|
|
|
|
DOWNSIZING,
|
2017-10-29 07:24:26 +11:00
|
|
|
UPLOADING,
|
|
|
|
UPLOADED
|
2017-05-16 18:43:32 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This saves enough information to re-enqueue an attachment when restoring the activity.
|
|
|
|
*/
|
|
|
|
private static class SavedQueuedMedia implements Parcelable {
|
|
|
|
public static final Parcelable.Creator<SavedQueuedMedia> CREATOR
|
|
|
|
= new Parcelable.Creator<SavedQueuedMedia>() {
|
|
|
|
public SavedQueuedMedia createFromParcel(Parcel in) {
|
|
|
|
return new SavedQueuedMedia(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SavedQueuedMedia[] newArray(int size) {
|
|
|
|
return new SavedQueuedMedia[size];
|
|
|
|
}
|
|
|
|
};
|
2018-05-06 21:02:02 +10:00
|
|
|
String id;
|
2017-05-16 18:43:32 +10:00
|
|
|
QueuedMedia.Type type;
|
|
|
|
Uri uri;
|
|
|
|
long mediaSize;
|
2017-10-29 07:24:26 +11:00
|
|
|
QueuedMedia.ReadyStage readyStage;
|
2018-01-09 09:16:21 +11:00
|
|
|
String description;
|
2017-05-16 18:43:32 +10:00
|
|
|
|
2018-05-06 21:02:02 +10:00
|
|
|
SavedQueuedMedia(String id, QueuedMedia.Type type, Uri uri, long mediaSize, QueuedMedia.ReadyStage readyStage, String description) {
|
|
|
|
this.id = id;
|
2017-05-16 18:43:32 +10:00
|
|
|
this.type = type;
|
|
|
|
this.uri = uri;
|
|
|
|
this.mediaSize = mediaSize;
|
2017-10-29 07:24:26 +11:00
|
|
|
this.readyStage = readyStage;
|
2018-01-09 09:16:21 +11:00
|
|
|
this.description = description;
|
2017-05-16 18:43:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
SavedQueuedMedia(Parcel parcel) {
|
2018-05-06 21:02:02 +10:00
|
|
|
id = parcel.readString();
|
2017-05-16 18:43:32 +10:00
|
|
|
type = (QueuedMedia.Type) parcel.readSerializable();
|
|
|
|
uri = parcel.readParcelable(Uri.class.getClassLoader());
|
|
|
|
mediaSize = parcel.readLong();
|
2017-10-29 07:24:26 +11:00
|
|
|
readyStage = QueuedMedia.ReadyStage.valueOf(parcel.readString());
|
2018-01-09 09:16:21 +11:00
|
|
|
description = parcel.readString();
|
2017-05-16 18:43:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
2018-05-06 21:02:02 +10:00
|
|
|
dest.writeString(id);
|
2017-05-16 18:43:32 +10:00
|
|
|
dest.writeSerializable(type);
|
|
|
|
dest.writeParcelable(uri, flags);
|
|
|
|
dest.writeLong(mediaSize);
|
2017-10-29 07:24:26 +11:00
|
|
|
dest.writeString(readyStage.name());
|
2018-01-09 09:16:21 +11:00
|
|
|
dest.writeString(description);
|
2017-05-16 18:43:32 +10:00
|
|
|
}
|
|
|
|
}
|
2017-06-19 12:10:50 +10:00
|
|
|
|
2017-11-02 06:59:29 +11:00
|
|
|
public static final class IntentBuilder {
|
|
|
|
@Nullable
|
|
|
|
private Integer savedTootUid;
|
|
|
|
@Nullable
|
|
|
|
private String savedTootText;
|
|
|
|
@Nullable
|
|
|
|
private String savedJsonUrls;
|
|
|
|
@Nullable
|
2018-11-12 05:25:45 +11:00
|
|
|
private String savedJsonDescriptions;
|
|
|
|
@Nullable
|
2017-11-02 06:59:29 +11:00
|
|
|
private Collection<String> mentionedUsernames;
|
|
|
|
@Nullable
|
|
|
|
private String inReplyToId;
|
|
|
|
@Nullable
|
2017-11-17 05:18:11 +11:00
|
|
|
private Status.Visibility replyVisibility;
|
2017-11-02 06:59:29 +11:00
|
|
|
@Nullable
|
2018-08-24 04:50:50 +10:00
|
|
|
private Status.Visibility savedVisibility;
|
|
|
|
@Nullable
|
2017-11-02 06:59:29 +11:00
|
|
|
private String contentWarning;
|
|
|
|
@Nullable
|
2017-11-17 05:18:11 +11:00
|
|
|
private String replyingStatusAuthor;
|
2017-11-02 06:59:29 +11:00
|
|
|
@Nullable
|
|
|
|
private String replyingStatusContent;
|
|
|
|
|
|
|
|
public IntentBuilder savedTootUid(int uid) {
|
|
|
|
this.savedTootUid = uid;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntentBuilder savedTootText(String savedTootText) {
|
|
|
|
this.savedTootText = savedTootText;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntentBuilder savedJsonUrls(String jsonUrls) {
|
|
|
|
this.savedJsonUrls = jsonUrls;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-11-12 05:25:45 +11:00
|
|
|
public IntentBuilder savedJsonDescriptions(String jsonDescriptions) {
|
|
|
|
this.savedJsonDescriptions = jsonDescriptions;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-08-24 04:50:50 +10:00
|
|
|
public IntentBuilder savedVisibility(Status.Visibility savedVisibility) {
|
|
|
|
this.savedVisibility = savedVisibility;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:59:29 +11:00
|
|
|
public IntentBuilder mentionedUsernames(Collection<String> mentionedUsernames) {
|
|
|
|
this.mentionedUsernames = mentionedUsernames;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntentBuilder inReplyToId(String inReplyToId) {
|
|
|
|
this.inReplyToId = inReplyToId;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-11-17 05:18:11 +11:00
|
|
|
public IntentBuilder replyVisibility(Status.Visibility replyVisibility) {
|
2017-11-02 06:59:29 +11:00
|
|
|
this.replyVisibility = replyVisibility;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntentBuilder contentWarning(String contentWarning) {
|
|
|
|
this.contentWarning = contentWarning;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-15 07:57:22 +11:00
|
|
|
public IntentBuilder replyingStatusAuthor(String username) {
|
2017-11-17 05:18:11 +11:00
|
|
|
this.replyingStatusAuthor = username;
|
2017-11-02 06:59:29 +11:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntentBuilder replyingStatusContent(String content) {
|
|
|
|
this.replyingStatusContent = content;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Intent build(Context context) {
|
|
|
|
Intent intent = new Intent(context, ComposeActivity.class);
|
|
|
|
|
|
|
|
if (savedTootUid != null) {
|
|
|
|
intent.putExtra(SAVED_TOOT_UID_EXTRA, (int) savedTootUid);
|
|
|
|
}
|
|
|
|
if (savedTootText != null) {
|
|
|
|
intent.putExtra(SAVED_TOOT_TEXT_EXTRA, savedTootText);
|
|
|
|
}
|
|
|
|
if (savedJsonUrls != null) {
|
|
|
|
intent.putExtra(SAVED_JSON_URLS_EXTRA, savedJsonUrls);
|
|
|
|
}
|
2018-11-12 05:25:45 +11:00
|
|
|
if (savedJsonDescriptions != null) {
|
|
|
|
intent.putExtra(SAVED_JSON_DESCRIPTIONS_EXTRA, savedJsonDescriptions);
|
|
|
|
}
|
2017-11-02 06:59:29 +11:00
|
|
|
if (mentionedUsernames != null) {
|
|
|
|
String[] usernames = mentionedUsernames.toArray(new String[0]);
|
|
|
|
intent.putExtra(MENTIONED_USERNAMES_EXTRA, usernames);
|
|
|
|
}
|
|
|
|
if (inReplyToId != null) {
|
|
|
|
intent.putExtra(IN_REPLY_TO_ID_EXTRA, inReplyToId);
|
|
|
|
}
|
|
|
|
if (replyVisibility != null) {
|
2017-11-17 05:18:11 +11:00
|
|
|
intent.putExtra(REPLY_VISIBILITY_EXTRA, replyVisibility.getNum());
|
2017-11-02 06:59:29 +11:00
|
|
|
}
|
2018-08-24 04:50:50 +10:00
|
|
|
if (savedVisibility != null) {
|
|
|
|
intent.putExtra(SAVED_TOOT_VISIBILITY_EXTRA, savedVisibility.getNum());
|
|
|
|
}
|
2017-11-02 06:59:29 +11:00
|
|
|
if (contentWarning != null) {
|
|
|
|
intent.putExtra(CONTENT_WARNING_EXTRA, contentWarning);
|
|
|
|
}
|
|
|
|
if (replyingStatusContent != null) {
|
|
|
|
intent.putExtra(REPLYING_STATUS_CONTENT_EXTRA, replyingStatusContent);
|
|
|
|
}
|
|
|
|
if (replyingStatusAuthor != null) {
|
2017-11-17 05:18:11 +11:00
|
|
|
intent.putExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA, replyingStatusAuthor);
|
2017-11-02 06:59:29 +11:00
|
|
|
}
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
}
|
2017-01-08 09:24:02 +11:00
|
|
|
}
|