2017-01-20 09:09:10 +01:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 02:12:31 +02:00
|
|
|
* This file is a part of Tusky.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02: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 09:09:10 +01:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 02:12:31 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-20 09:09:10 +01:00
|
|
|
*
|
2017-04-10 02:12:31 +02: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 09:09:10 +01:00
|
|
|
|
2017-01-07 23:24:02 +01:00
|
|
|
package com.keylesspalace.tusky;
|
|
|
|
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.Manifest;
|
2017-11-16 19:18:11 +01:00
|
|
|
import android.annotation.SuppressLint;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.app.ProgressDialog;
|
2018-09-03 20:26:35 +02:00
|
|
|
import android.arch.lifecycle.Lifecycle;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.content.ContentResolver;
|
2017-06-19 04:10:50 +02:00
|
|
|
import android.content.Context;
|
2017-01-18 19:35:07 +01:00
|
|
|
import android.content.DialogInterface;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.content.Intent;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.content.SharedPreferences;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.content.pm.PackageManager;
|
2017-03-04 02:44:44 +01:00
|
|
|
import android.content.res.AssetFileDescriptor;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.graphics.Bitmap;
|
2018-04-13 22:37:21 +02:00
|
|
|
import android.graphics.PorterDuff;
|
2017-03-27 00:26:47 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
2018-07-26 23:31:20 +02:00
|
|
|
import android.os.Build;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.os.Bundle;
|
2017-04-15 17:43:26 +02:00
|
|
|
import android.os.Environment;
|
2017-02-04 01:53:33 +01:00
|
|
|
import android.os.Parcel;
|
2017-02-17 23:56:31 +01:00
|
|
|
import android.os.Parcelable;
|
2017-11-27 20:11:31 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2017-04-15 17:43:26 +02:00
|
|
|
import android.provider.MediaStore;
|
2018-04-13 22:37:21 +02:00
|
|
|
import android.support.annotation.ColorInt;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.support.annotation.NonNull;
|
2017-06-19 05:34:48 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2017-11-16 19:18:11 +01:00
|
|
|
import android.support.annotation.Px;
|
2017-02-22 20:13:51 +01:00
|
|
|
import android.support.annotation.StringRes;
|
2018-04-13 22:37:21 +02:00
|
|
|
import android.support.design.widget.BottomSheetBehavior;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.support.design.widget.Snackbar;
|
2018-04-13 22:37:21 +02:00
|
|
|
import android.support.transition.TransitionManager;
|
2017-03-04 02:44:44 +01:00
|
|
|
import android.support.v13.view.inputmethod.InputConnectionCompat;
|
|
|
|
import android.support.v13.view.inputmethod.InputContentInfoCompat;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-04-15 17:43:26 +02:00
|
|
|
import android.support.v4.content.FileProvider;
|
2018-04-13 22:37:21 +02:00
|
|
|
import android.support.v4.view.ViewCompat;
|
|
|
|
import android.support.v4.widget.TextViewCompat;
|
2017-03-07 14:09:33 +01:00
|
|
|
import android.support.v7.app.ActionBar;
|
2017-07-28 04:40:58 +02:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2017-04-03 01:10:07 +02:00
|
|
|
import android.support.v7.content.res.AppCompatResources;
|
2018-04-13 22:37:21 +02:00
|
|
|
import android.support.v7.widget.GridLayoutManager;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2017-03-07 14:09:33 +01:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.text.Editable;
|
2017-10-23 22:55:43 +02:00
|
|
|
import android.text.InputType;
|
2017-05-16 10:43:32 +02:00
|
|
|
import android.text.TextUtils;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.text.TextWatcher;
|
2018-05-16 19:14:26 +02:00
|
|
|
import android.text.style.URLSpan;
|
2018-08-15 20:47:36 +02:00
|
|
|
import android.util.DisplayMetrics;
|
2017-05-23 21:34:31 +02:00
|
|
|
import android.util.Log;
|
2017-03-07 14:09:33 +01:00
|
|
|
import android.view.MenuItem;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.view.View;
|
2018-04-13 22:37:21 +02:00
|
|
|
import android.view.ViewGroup;
|
2018-01-08 23:16:21 +01:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.webkit.MimeTypeMap;
|
2017-03-10 18:38:49 +01:00
|
|
|
import android.widget.Button;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.widget.EditText;
|
2017-03-10 18:38:49 +01:00
|
|
|
import android.widget.ImageButton;
|
2017-01-16 19:15:42 +01:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
2018-01-08 23:16:21 +01:00
|
|
|
import android.widget.PopupMenu;
|
2017-01-07 23:24:02 +01:00
|
|
|
import android.widget.TextView;
|
2017-06-29 17:56:58 +02:00
|
|
|
import android.widget.Toast;
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2017-07-05 16:36:14 +02:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
2018-04-13 22:37:21 +02:00
|
|
|
import com.keylesspalace.tusky.adapter.EmojiAdapter;
|
2017-11-16 19:18:11 +01:00
|
|
|
import com.keylesspalace.tusky.adapter.MentionAutoCompleteAdapter;
|
2018-04-13 22:37:21 +02:00
|
|
|
import com.keylesspalace.tusky.adapter.OnEmojiSelectedListener;
|
2018-02-03 22:45:14 +01:00
|
|
|
import com.keylesspalace.tusky.db.AccountEntity;
|
2018-05-27 10:22:12 +02:00
|
|
|
import com.keylesspalace.tusky.db.AppDatabase;
|
2018-04-22 10:35:46 +02:00
|
|
|
import com.keylesspalace.tusky.db.InstanceEntity;
|
2018-03-27 19:47:00 +02:00
|
|
|
import com.keylesspalace.tusky.di.Injectable;
|
2017-06-19 04:10:50 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Account;
|
2017-11-30 20:12:09 +01:00
|
|
|
import com.keylesspalace.tusky.entity.Attachment;
|
2018-04-13 22:37:21 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Emoji;
|
2018-04-22 10:35:46 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Instance;
|
2017-03-09 00:27:37 +01:00
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
2018-03-27 19:47:00 +02:00
|
|
|
import com.keylesspalace.tusky.network.MastodonApi;
|
2017-10-29 22:18:45 +01:00
|
|
|
import com.keylesspalace.tusky.network.ProgressRequestBody;
|
2018-04-13 22:37:21 +02:00
|
|
|
import com.keylesspalace.tusky.service.SendTootService;
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.util.CountUpDownLatch;
|
2017-05-16 10:43:32 +02:00
|
|
|
import com.keylesspalace.tusky.util.DownsizeImageTask;
|
2017-07-12 03:49:46 +02:00
|
|
|
import com.keylesspalace.tusky.util.ListUtils;
|
2017-05-16 10:43:32 +02:00
|
|
|
import com.keylesspalace.tusky.util.MediaUtils;
|
2017-06-19 04:10:50 +02:00
|
|
|
import com.keylesspalace.tusky.util.MentionTokenizer;
|
2018-04-13 22:37:21 +02:00
|
|
|
import com.keylesspalace.tusky.util.SaveTootHelper;
|
2018-05-16 19:14:26 +02:00
|
|
|
import com.keylesspalace.tusky.util.SpanUtilsKt;
|
2017-07-02 22:34:10 +02:00
|
|
|
import com.keylesspalace.tusky.util.StringUtils;
|
2017-05-05 00:55:34 +02:00
|
|
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
2018-04-13 22:37:21 +02:00
|
|
|
import com.keylesspalace.tusky.view.ComposeOptionsListener;
|
|
|
|
import com.keylesspalace.tusky.view.ComposeOptionsView;
|
2017-05-16 10:43:32 +02:00
|
|
|
import com.keylesspalace.tusky.view.EditTextTyped;
|
2017-10-29 22:18:45 +01:00
|
|
|
import com.keylesspalace.tusky.view.ProgressImageView;
|
2018-04-13 22:37:21 +02:00
|
|
|
import com.keylesspalace.tusky.view.TootButton;
|
|
|
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
|
|
|
import com.mikepenz.iconics.IconicsDrawable;
|
2018-01-08 23:16:21 +01:00
|
|
|
import com.squareup.picasso.Picasso;
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
2017-04-15 17:43:26 +02:00
|
|
|
import java.io.File;
|
2017-01-16 19:15:42 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.ArrayList;
|
2017-11-01 20:59:29 +01:00
|
|
|
import java.util.Collection;
|
2018-04-22 10:35:46 +02:00
|
|
|
import java.util.Collections;
|
2017-01-16 19:15:42 +01:00
|
|
|
import java.util.Date;
|
2017-01-18 19:35:07 +01:00
|
|
|
import java.util.Iterator;
|
2017-01-16 19:15:42 +01:00
|
|
|
import java.util.List;
|
2017-03-06 01:58:36 +01:00
|
|
|
import java.util.Locale;
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2018-03-27 19:47:00 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2018-07-30 15:36:22 +02:00
|
|
|
import at.connyduck.sparkbutton.helpers.Utils;
|
2018-09-03 20:26:35 +02: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;
|
2017-03-09 16:59:18 +01:00
|
|
|
import okhttp3.MediaType;
|
|
|
|
import okhttp3.MultipartBody;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2017-05-04 02:27:59 +02:00
|
|
|
import retrofit2.Response;
|
2017-03-09 16:59:18 +01:00
|
|
|
|
2018-09-03 20:26:35 +02:00
|
|
|
import static com.uber.autodispose.AutoDispose.autoDisposable;
|
|
|
|
import static com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from;
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
public final class ComposeActivity
|
|
|
|
extends BaseActivity
|
|
|
|
implements ComposeOptionsListener,
|
2018-03-27 19:47:00 +02:00
|
|
|
MentionAutoCompleteAdapter.AccountSearchProvider,
|
2018-04-13 22:37:21 +02:00
|
|
|
OnEmojiSelectedListener,
|
|
|
|
Injectable, InputConnectionCompat.OnCommitContentListener {
|
|
|
|
|
2017-03-10 00:20:08 +01:00
|
|
|
private static final String TAG = "ComposeActivity"; // logging tag
|
2018-04-29 10:08:25 +02:00
|
|
|
static final int STATUS_CHARACTER_LIMIT = 500;
|
2018-09-06 22:48:19 +02: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-16 19:15:42 +01:00
|
|
|
private static final int MEDIA_PICK_RESULT = 1;
|
2017-04-15 17:43:26 +02:00
|
|
|
private static final int MEDIA_TAKE_PHOTO_RESULT = 2;
|
2017-01-16 19:15:42 +01:00
|
|
|
private static final int PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
|
2017-11-01 20:59:29 +01: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-08-23 20:50:50 +02:00
|
|
|
private static final String SAVED_TOOT_VISIBILITY_EXTRA = "saved_toot_visibility";
|
2017-11-01 20:59:29 +01: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-16 19:14:26 +02:00
|
|
|
// Mastodon only counts URLs as this long in terms of status character limits
|
|
|
|
static final int MAXIMUM_URL_LENGTH = 23;
|
2017-11-16 19:18:11 +01:00
|
|
|
|
2018-03-27 19:47:00 +02:00
|
|
|
@Inject
|
|
|
|
public MastodonApi mastodonApi;
|
2018-05-27 10:22:12 +02:00
|
|
|
@Inject
|
|
|
|
public AppDatabase database;
|
2018-03-27 19:47:00 +02:00
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
private TextView replyTextView;
|
2017-11-01 20:59:29 +01:00
|
|
|
private TextView replyContentTextView;
|
2017-06-22 20:59:12 +02:00
|
|
|
private EditTextTyped textEditor;
|
|
|
|
private LinearLayout mediaPreviewBar;
|
|
|
|
private View contentWarningBar;
|
|
|
|
private EditText contentWarningEditor;
|
|
|
|
private TextView charactersLeft;
|
2018-04-13 22:37:21 +02:00
|
|
|
private TootButton tootButton;
|
2017-07-28 04:40:58 +02:00
|
|
|
private ImageButton pickButton;
|
2018-04-13 22:37:21 +02:00
|
|
|
private ImageButton visibilityButton;
|
|
|
|
private Button contentWarningButton;
|
|
|
|
private ImageButton emojiButton;
|
2017-07-27 06:56:53 +02:00
|
|
|
private ImageButton hideMediaToggle;
|
2018-04-13 22:37:21 +02:00
|
|
|
|
|
|
|
private ComposeOptionsView composeOptionsView;
|
|
|
|
private BottomSheetBehavior composeOptionsBehavior;
|
|
|
|
private BottomSheetBehavior addMediaBehavior;
|
|
|
|
private BottomSheetBehavior emojiBehavior;
|
|
|
|
private RecyclerView emojiView;
|
|
|
|
|
2017-06-22 20:59:12 +02:00
|
|
|
// this only exists when a status is trying to be sent, but uploads are still occurring
|
|
|
|
private ProgressDialog finishingUploadDialog;
|
2017-01-20 05:59:21 +01:00
|
|
|
private String inReplyToId;
|
2018-03-09 22:02:32 +01:00
|
|
|
private List<QueuedMedia> mediaQueued = new ArrayList<>();
|
2017-01-16 19:15:42 +01:00
|
|
|
private CountUpDownLatch waitForMediaLatch;
|
2017-11-16 19:18:11 +01:00
|
|
|
private Status.Visibility statusVisibility; // The current values of the options that will be applied
|
2017-02-04 01:53:33 +01:00
|
|
|
private boolean statusMarkSensitive; // to the status being composed.
|
2017-11-16 19:18:11 +01:00
|
|
|
private boolean statusHideText;
|
2018-04-22 21:04:19 +02:00
|
|
|
private String startingText = "";
|
|
|
|
private String startingContentWarning = "";
|
2017-03-04 02:44:44 +01:00
|
|
|
private InputContentInfoCompat currentInputContentInfo;
|
|
|
|
private int currentFlags;
|
2017-04-15 17:43:26 +02:00
|
|
|
private Uri photoUploadUri;
|
2017-07-07 12:32:47 +02:00
|
|
|
private int savedTootUid = 0;
|
2018-04-22 10:35:46 +02:00
|
|
|
private List<Emoji> emojiList;
|
|
|
|
private int maximumTootCharacters = STATUS_CHARACTER_LIMIT;
|
2018-07-23 21:55:09 +02:00
|
|
|
private @Px int thumbnailViewSize;
|
2017-06-28 19:33:54 +02:00
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
private SaveTootHelper saveTootHelper;
|
|
|
|
|
2017-01-07 23:24:02 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2018-07-30 15:31:35 +02: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-07 23:24:02 +01:00
|
|
|
setContentView(R.layout.activity_compose);
|
2017-06-22 20:59:12 +02:00
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
replyTextView = findViewById(R.id.composeReplyView);
|
|
|
|
replyContentTextView = findViewById(R.id.composeReplyContentView);
|
|
|
|
textEditor = findViewById(R.id.composeEditField);
|
2017-10-18 00:20:26 +02:00
|
|
|
mediaPreviewBar = findViewById(R.id.compose_media_preview_bar);
|
2018-04-13 22:37:21 +02: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 10:35:46 +02:00
|
|
|
emojiList = Collections.emptyList();
|
2018-04-13 22:37:21 +02:00
|
|
|
|
2018-05-27 10:22:12 +02:00
|
|
|
saveTootHelper = new SaveTootHelper(database.tootDao(), this);
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2017-05-03 00:17:54 +02:00
|
|
|
// Setup the toolbar.
|
2017-10-18 00:20:26 +02:00
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
2017-03-07 14:09:33 +01:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setTitle(null);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setDisplayShowHomeEnabled(true);
|
2017-04-03 01:10:07 +02:00
|
|
|
Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
|
2017-03-29 06:22:14 +02:00
|
|
|
ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
|
|
|
|
actionBar.setHomeAsUpIndicator(closeIcon);
|
2017-03-07 14:09:33 +01:00
|
|
|
}
|
|
|
|
|
2018-02-25 15:41:45 +01:00
|
|
|
// setup the account image
|
2018-03-27 19:47:00 +02:00
|
|
|
final AccountEntity activeAccount = accountManager.getActiveAccount();
|
2018-02-25 15:41:45 +01:00
|
|
|
|
2018-03-05 22:43:13 +01:00
|
|
|
if (activeAccount != null) {
|
2018-02-25 15:41:45 +01:00
|
|
|
ImageView composeAvatar = findViewById(R.id.composeAvatar);
|
|
|
|
|
2018-03-05 22:43:13 +01:00
|
|
|
if (TextUtils.isEmpty(activeAccount.getProfilePictureUrl())) {
|
2018-02-25 15:41:45 +01: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 10:35:46 +02: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-04-23 09:26:03 +02:00
|
|
|
setEmojiList(emojiList);
|
2018-04-22 10:35:46 +02: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-25 15:41:45 +01:00
|
|
|
} else {
|
|
|
|
// do not do anything when not logged in, activity will be finished in super.onCreate() anyway
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02: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-17 22:39:55 +02:00
|
|
|
enableButton(emojiButton, false, false);
|
|
|
|
|
2017-05-03 00:17:54 +02:00
|
|
|
// Setup the interface buttons.
|
2018-04-13 22:37:21 +02:00
|
|
|
tootButton.setOnClickListener(v -> onSendClicked());
|
2017-11-27 20:11:31 +01:00
|
|
|
pickButton.setOnClickListener(v -> openPickDialog());
|
2018-04-13 22:37:21 +02:00
|
|
|
visibilityButton.setOnClickListener(v -> showComposeOptions());
|
|
|
|
contentWarningButton.setOnClickListener(v-> onContentWarningChanged());
|
|
|
|
emojiButton.setOnClickListener(v -> showEmojis());
|
2017-11-27 20:11:31 +01:00
|
|
|
hideMediaToggle.setOnClickListener(v -> toggleHideMedia());
|
2017-03-07 14:09:33 +01:00
|
|
|
|
2018-04-13 22:37:21 +02: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);
|
|
|
|
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(actionPhotoTake, cameraIcon, null, null, null);
|
|
|
|
|
|
|
|
Drawable imageIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_image).color(textColor).sizeDp(18);
|
|
|
|
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(actionPhotoPick, imageIcon, null, null, null);
|
|
|
|
|
|
|
|
actionPhotoTake.setOnClickListener(v -> initiateCameraApp());
|
|
|
|
actionPhotoPick.setOnClickListener(v -> onMediaPick());
|
2017-10-23 22:55:43 +02:00
|
|
|
|
2018-07-23 21:55:09 +02:00
|
|
|
thumbnailViewSize = getResources().getDimensionPixelSize(R.dimen.compose_media_preview_size);
|
|
|
|
|
2017-05-03 00:17:54 +02:00
|
|
|
/* Initialise all the state, or restore it from a previous run, to determine a "starting"
|
|
|
|
* state. */
|
2017-11-27 20:11:31 +01:00
|
|
|
Status.Visibility startingVisibility = Status.Visibility.UNKNOWN;
|
2017-03-27 01:37:32 +02:00
|
|
|
boolean startingHideText;
|
2017-02-17 23:56:31 +01:00
|
|
|
ArrayList<SavedQueuedMedia> savedMediaQueued = null;
|
|
|
|
if (savedInstanceState != null) {
|
2017-11-16 19:18:11 +01:00
|
|
|
startingVisibility = Status.Visibility.byNum(
|
|
|
|
savedInstanceState.getInt("statusVisibility",
|
|
|
|
Status.Visibility.PUBLIC.getNum())
|
|
|
|
);
|
2017-02-17 23:56:31 +01:00
|
|
|
statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
|
2017-03-27 01:37:32 +02:00
|
|
|
startingHideText = savedInstanceState.getBoolean("statusHideText");
|
2017-02-17 23:56:31 +01:00
|
|
|
// Keep these until everything needed to put them in the queue is finished initializing.
|
|
|
|
savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
|
2017-03-04 02:44:44 +01: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-02 23:45:13 +02:00
|
|
|
photoUploadUri = savedInstanceState.getParcelable("photoUploadUri");
|
2017-02-17 23:56:31 +01:00
|
|
|
} else {
|
|
|
|
statusMarkSensitive = false;
|
2017-03-27 01:37:32 +02:00
|
|
|
startingHideText = false;
|
2017-07-02 23:45:13 +02:00
|
|
|
photoUploadUri = null;
|
2017-02-17 23:56:31 +01:00
|
|
|
}
|
|
|
|
|
2017-05-03 00:17:54 +02: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-10 18:38:49 +01:00
|
|
|
|
2017-01-20 05:59:21 +01:00
|
|
|
String[] mentionedUsernames = null;
|
2017-07-08 04:56:07 +02:00
|
|
|
ArrayList<String> loadedDraftMediaUris = null;
|
2017-03-26 23:21:18 +02:00
|
|
|
inReplyToId = null;
|
2017-01-20 05:59:21 +01:00
|
|
|
if (intent != null) {
|
2017-11-27 20:11:31 +01:00
|
|
|
|
2018-01-08 23:16:21 +01:00
|
|
|
if (startingVisibility == Status.Visibility.UNKNOWN) {
|
2018-05-09 23:04:00 +02:00
|
|
|
Status.Visibility preferredVisibility = Status.Visibility.byString(
|
|
|
|
preferences.getString("defaultPostPrivacy",
|
|
|
|
Status.Visibility.PUBLIC.serverString()));
|
2017-11-27 20:11:31 +01:00
|
|
|
Status.Visibility replyVisibility = Status.Visibility.byNum(
|
|
|
|
intent.getIntExtra(REPLY_VISIBILITY_EXTRA, Status.Visibility.UNKNOWN.getNum()));
|
|
|
|
|
2018-05-09 23:04:00 +02:00
|
|
|
startingVisibility = Status.Visibility.byNum(Math.max(preferredVisibility.getNum(), replyVisibility.getNum()));
|
2017-11-27 20:11:31 +01:00
|
|
|
}
|
|
|
|
|
2017-11-01 20:59:29 +01:00
|
|
|
inReplyToId = intent.getStringExtra(IN_REPLY_TO_ID_EXTRA);
|
2017-03-14 14:31:52 +01:00
|
|
|
|
2017-11-01 20:59:29 +01:00
|
|
|
mentionedUsernames = intent.getStringArrayExtra(MENTIONED_USERNAMES_EXTRA);
|
2017-04-07 20:37:27 +02:00
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
String contentWarning = intent.getStringExtra(CONTENT_WARNING_EXTRA);
|
|
|
|
if (contentWarning != null) {
|
|
|
|
startingHideText = !contentWarning.isEmpty();
|
2017-05-03 00:17:54 +02:00
|
|
|
if (startingHideText) {
|
2017-11-16 19:18:11 +01:00
|
|
|
startingContentWarning = contentWarning;
|
2017-07-08 04:56:07 +02:00
|
|
|
}
|
2017-04-07 20:37:27 +02:00
|
|
|
}
|
2017-07-05 16:36:14 +02:00
|
|
|
|
2017-07-08 04:56:07 +02:00
|
|
|
// If come from SavedTootActivity
|
2017-11-01 20:59:29 +01:00
|
|
|
String savedTootText = intent.getStringExtra(SAVED_TOOT_TEXT_EXTRA);
|
2017-07-05 16:36:14 +02:00
|
|
|
if (!TextUtils.isEmpty(savedTootText)) {
|
2018-04-22 21:04:19 +02:00
|
|
|
startingText = savedTootText;
|
|
|
|
textEditor.setText(savedTootText);
|
2017-07-05 16:36:14 +02:00
|
|
|
}
|
|
|
|
|
2017-11-01 20:59:29 +01:00
|
|
|
String savedJsonUrls = intent.getStringExtra(SAVED_JSON_URLS_EXTRA);
|
2017-07-05 16:36:14 +02:00
|
|
|
if (!TextUtils.isEmpty(savedJsonUrls)) {
|
|
|
|
// try to redo a list of media
|
2017-07-08 04:56:07 +02:00
|
|
|
loadedDraftMediaUris = new Gson().fromJson(savedJsonUrls,
|
2017-10-29 22:18:45 +01:00
|
|
|
new TypeToken<ArrayList<String>>() {
|
|
|
|
}.getType());
|
2017-07-07 12:32:47 +02:00
|
|
|
}
|
2017-07-05 16:36:14 +02:00
|
|
|
|
2017-11-01 20:59:29 +01:00
|
|
|
int savedTootUid = intent.getIntExtra(SAVED_TOOT_UID_EXTRA, 0);
|
2017-07-07 12:32:47 +02:00
|
|
|
if (savedTootUid != 0) {
|
|
|
|
this.savedTootUid = savedTootUid;
|
2017-07-05 16:36:14 +02:00
|
|
|
}
|
2017-11-01 20:59:29 +01:00
|
|
|
|
2018-08-23 20:50:50 +02: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-01 20:59:29 +01: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-13 22:37:21 +02:00
|
|
|
Drawable arrowDownIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_down).sizeDp(12);
|
|
|
|
|
|
|
|
ThemeUtils.setDrawableTint(this, arrowDownIcon, android.R.attr.textColorTertiary);
|
|
|
|
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowDownIcon, null);
|
|
|
|
|
2017-11-27 20:11:31 +01:00
|
|
|
replyTextView.setOnClickListener(v -> {
|
2018-04-13 22:37:21 +02:00
|
|
|
TransitionManager.beginDelayedTransition((ViewGroup)replyContentTextView.getParent());
|
|
|
|
|
2017-11-27 20:11:31 +01:00
|
|
|
if (replyContentTextView.getVisibility() != View.VISIBLE) {
|
|
|
|
replyContentTextView.setVisibility(View.VISIBLE);
|
2018-04-13 22:37:21 +02:00
|
|
|
Drawable arrowUpIcon = new IconicsDrawable(this, GoogleMaterial.Icon.gmd_arrow_drop_up).sizeDp(12);
|
|
|
|
|
|
|
|
ThemeUtils.setDrawableTint(this, arrowUpIcon, android.R.attr.textColorTertiary);
|
|
|
|
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowUpIcon, null);
|
2017-11-27 20:11:31 +01:00
|
|
|
} else {
|
|
|
|
replyContentTextView.setVisibility(View.GONE);
|
2018-04-13 22:37:21 +02:00
|
|
|
|
|
|
|
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(replyTextView, null, null, arrowDownIcon, null);
|
2017-11-01 20:59:29 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intent.hasExtra(REPLYING_STATUS_CONTENT_EXTRA)) {
|
|
|
|
replyContentTextView.setText(intent.getStringExtra(REPLYING_STATUS_CONTENT_EXTRA));
|
|
|
|
}
|
2017-01-20 05:59:21 +01:00
|
|
|
}
|
2017-05-03 00:17:54 +02:00
|
|
|
|
|
|
|
// After the starting state is finalised, the interface can be set to reflect this state.
|
2017-11-27 20:11:31 +01:00
|
|
|
setStatusVisibility(startingVisibility);
|
2017-11-16 19:18:11 +01:00
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
updateHideMediaToggle();
|
2017-07-15 00:18:29 +02:00
|
|
|
updateVisibleCharactersLeft();
|
2017-01-20 05:59:21 +01:00
|
|
|
|
2017-05-03 00:17:54 +02:00
|
|
|
// Setup the main text field.
|
2018-04-13 22:37:21 +02:00
|
|
|
textEditor.setOnCommitContentListener(this);
|
2018-05-16 19:14:26 +02:00
|
|
|
final int mentionColour = textEditor.getLinkTextColors().getDefaultColor();
|
|
|
|
SpanUtilsKt.highlightSpans(textEditor.getText(), mentionColour);
|
2017-03-21 13:52:15 +01:00
|
|
|
textEditor.addTextChangedListener(new TextWatcher() {
|
2017-01-07 23:24:02 +01:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-16 10:43:32 +02:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
2017-01-07 23:24:02 +01:00
|
|
|
|
|
|
|
@Override
|
2017-01-20 05:59:21 +01:00
|
|
|
public void afterTextChanged(Editable editable) {
|
2018-05-16 19:14:26 +02:00
|
|
|
SpanUtilsKt.highlightSpans(editable, mentionColour);
|
|
|
|
updateVisibleCharactersLeft();
|
2017-01-20 05:59:21 +01:00
|
|
|
}
|
2017-03-21 13:52:15 +01:00
|
|
|
});
|
2017-01-07 23:24:02 +01:00
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
textEditor.setAdapter(
|
|
|
|
new MentionAutoCompleteAdapter(this, R.layout.item_autocomplete, this));
|
2017-06-19 04:10:50 +02:00
|
|
|
textEditor.setTokenizer(new MentionTokenizer());
|
|
|
|
|
2017-05-03 00:17:54 +02:00
|
|
|
// Add any mentions to the text field when a reply is first composed.
|
2017-01-20 05:59:21 +01:00
|
|
|
if (mentionedUsernames != null) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
for (String name : mentionedUsernames) {
|
|
|
|
builder.append('@');
|
|
|
|
builder.append(name);
|
|
|
|
builder.append(' ');
|
|
|
|
}
|
2018-04-22 21:04:19 +02:00
|
|
|
startingText = builder.toString();
|
|
|
|
textEditor.setText(startingText);
|
2017-01-20 05:59:21 +01:00
|
|
|
textEditor.setSelection(textEditor.length());
|
|
|
|
}
|
|
|
|
|
2018-07-26 23:31:20 +02: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 00:17:54 +02:00
|
|
|
// Initialise the content warning editor.
|
2017-03-20 03:38:39 +01:00
|
|
|
contentWarningEditor.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
2017-05-16 10:43:32 +02:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
2017-03-20 03:38:39 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
2017-04-10 19:34:33 +02:00
|
|
|
updateVisibleCharactersLeft();
|
2017-03-20 03:38:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-16 10:43:32 +02:00
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
}
|
2017-03-20 03:38:39 +01:00
|
|
|
});
|
2017-03-27 01:37:32 +02:00
|
|
|
showContentWarning(startingHideText);
|
2017-05-16 10:43:32 +02:00
|
|
|
if (startingContentWarning != null) {
|
2017-04-07 20:37:27 +02:00
|
|
|
contentWarningEditor.setText(startingContentWarning);
|
|
|
|
}
|
|
|
|
|
2017-05-03 00:17:54 +02:00
|
|
|
// Initialise the empty media queue state.
|
|
|
|
waitForMediaLatch = new CountUpDownLatch();
|
2017-01-16 19:15:42 +01:00
|
|
|
|
2017-03-07 14:09:33 +01:00
|
|
|
// These can only be added after everything affected by the media queue is initialized.
|
2017-10-29 22:18:45 +01:00
|
|
|
if (!ListUtils.isEmpty(loadedDraftMediaUris)) {
|
2017-07-08 04:56:07 +02:00
|
|
|
for (String uriString : loadedDraftMediaUris) {
|
|
|
|
Uri uri = Uri.parse(uriString);
|
|
|
|
long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri);
|
|
|
|
pickMedia(uri, mediaSize);
|
|
|
|
}
|
2017-07-12 03:49:46 +02:00
|
|
|
} else if (savedMediaQueued != null) {
|
2017-03-07 14:09:33 +01:00
|
|
|
for (SavedQueuedMedia item : savedMediaQueued) {
|
2018-07-23 21:55:09 +02:00
|
|
|
Bitmap preview = MediaUtils.getImageThumbnail(getContentResolver(), item.uri, thumbnailViewSize);
|
2018-05-06 13:02:02 +02:00
|
|
|
addMediaToQueue(item.id, item.type, preview, item.uri, item.mediaSize, item.readyStage, item.description);
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
2017-04-06 07:11:44 +02:00
|
|
|
} else if (intent != null && savedInstanceState == null) {
|
2017-04-05 22:35:22 +02: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 07:11:44 +02:00
|
|
|
if (type != null) {
|
|
|
|
if (type.startsWith("image/")) {
|
|
|
|
List<Uri> uriList = new ArrayList<>();
|
2017-11-16 19:18:11 +01: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 07:11:44 +02:00
|
|
|
}
|
2017-11-16 19:18:11 +01: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 07:11:44 +02:00
|
|
|
}
|
2017-04-05 22:35:22 +02:00
|
|
|
}
|
2017-11-16 19:18:11 +01:00
|
|
|
break;
|
2017-04-05 22:35:22 +02:00
|
|
|
}
|
2017-04-06 07:11:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Uri uri : uriList) {
|
2017-07-02 22:34:10 +02:00
|
|
|
long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri);
|
2017-04-06 07:11:44 +02:00
|
|
|
pickMedia(uri, mediaSize);
|
|
|
|
}
|
|
|
|
} 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-05 22:35:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 14:09:33 +01:00
|
|
|
}
|
2017-11-01 20:59:29 +01:00
|
|
|
|
2018-03-05 22:43:13 +01:00
|
|
|
textEditor.requestFocus();
|
2017-03-07 14:09:33 +01:00
|
|
|
}
|
2017-01-16 19:15:42 +01:00
|
|
|
|
2017-05-03 00:17:54 +02:00
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
ArrayList<SavedQueuedMedia> savedMediaQueued = new ArrayList<>();
|
|
|
|
for (QueuedMedia item : mediaQueued) {
|
2018-05-06 13:02:02 +02:00
|
|
|
savedMediaQueued.add(new SavedQueuedMedia(item.id, item.type, item.uri,
|
2018-01-08 23:16:21 +01:00
|
|
|
item.mediaSize, item.readyStage, item.description));
|
2017-05-03 00:17:54 +02: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-02 23:45:13 +02:00
|
|
|
outState.putParcelable("photoUploadUri", photoUploadUri);
|
2017-11-27 20:11:31 +01:00
|
|
|
outState.putInt("statusVisibility", statusVisibility.getNum());
|
2017-05-03 00:17:54 +02:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void doErrorDialog(@StringRes int descriptionId, @StringRes int actionId,
|
2017-07-30 23:16:32 +02:00
|
|
|
View.OnClickListener listener) {
|
2017-05-03 00:17:54 +02:00
|
|
|
Snackbar bar = Snackbar.make(findViewById(R.id.activity_compose), getString(descriptionId),
|
|
|
|
Snackbar.LENGTH_SHORT);
|
|
|
|
bar.setAction(actionId, listener);
|
2018-04-13 22:37:21 +02:00
|
|
|
//necessary so snackbar is shown over everything
|
|
|
|
ViewCompat.setElevation(bar.getView(), getResources().getDimensionPixelSize(R.dimen.compose_activity_snackbar_elevation));
|
2017-05-03 00:17:54 +02:00
|
|
|
bar.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void displayTransientError(@StringRes int stringId) {
|
2018-04-13 22:37:21 +02:00
|
|
|
Snackbar bar = Snackbar.make(findViewById(R.id.activity_compose), stringId, Snackbar.LENGTH_LONG);
|
|
|
|
//necessary so snackbar is shown over everything
|
|
|
|
ViewCompat.setElevation(bar.getView(), getResources().getDimensionPixelSize(R.dimen.compose_activity_snackbar_elevation));
|
|
|
|
bar.show();
|
2017-05-03 00:17:54 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 20:16:03 +02:00
|
|
|
private void toggleHideMedia() {
|
2017-03-10 18:38:49 +01:00
|
|
|
statusMarkSensitive = !statusMarkSensitive;
|
2018-04-13 22:37:21 +02:00
|
|
|
updateHideMediaToggle();
|
2017-03-29 06:22:14 +02:00
|
|
|
}
|
2017-03-10 18:38:49 +01:00
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
private void updateHideMediaToggle() {
|
|
|
|
TransitionManager.beginDelayedTransition((ViewGroup)hideMediaToggle.getParent());
|
|
|
|
|
|
|
|
@ColorInt int color;
|
|
|
|
if(mediaQueued.size() == 0) {
|
|
|
|
hideMediaToggle.setVisibility(View.GONE);
|
2017-03-10 18:38:49 +01:00
|
|
|
} else {
|
2018-04-13 22:37:21 +02: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);
|
|
|
|
color = ContextCompat.getColor(this, R.color.primary);
|
|
|
|
}
|
|
|
|
} 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-10 18:38:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-15 17:52:21 +02:00
|
|
|
private void disableButtons() {
|
2017-07-28 04:40:58 +02:00
|
|
|
pickButton.setClickable(false);
|
2018-04-13 22:37:21 +02:00
|
|
|
visibilityButton.setClickable(false);
|
|
|
|
emojiButton.setClickable(false);
|
2017-07-27 06:56:53 +02:00
|
|
|
hideMediaToggle.setClickable(false);
|
2018-04-13 22:37:21 +02:00
|
|
|
tootButton.setEnabled(false);
|
2017-04-15 17:52:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void enableButtons() {
|
2017-07-28 04:40:58 +02:00
|
|
|
pickButton.setClickable(true);
|
2018-04-13 22:37:21 +02:00
|
|
|
visibilityButton.setClickable(true);
|
|
|
|
emojiButton.setClickable(true);
|
2017-07-27 06:56:53 +02:00
|
|
|
hideMediaToggle.setClickable(true);
|
2018-04-13 22:37:21 +02:00
|
|
|
tootButton.setEnabled(true);
|
2017-07-12 08:09:07 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
private void setStatusVisibility(Status.Visibility visibility) {
|
2017-03-27 00:26:47 +02:00
|
|
|
statusVisibility = visibility;
|
2018-04-13 22:37:21 +02:00
|
|
|
composeOptionsView.setStatusVisibility(visibility);
|
|
|
|
tootButton.setStatusVisibility(visibility);
|
|
|
|
|
2017-03-27 00:26:47 +02:00
|
|
|
switch (visibility) {
|
2017-11-16 19:18:11 +01:00
|
|
|
case PUBLIC: {
|
2017-04-21 07:50:59 +02:00
|
|
|
Drawable globe = AppCompatResources.getDrawable(this, R.drawable.ic_public_24dp);
|
|
|
|
if (globe != null) {
|
2018-04-13 22:37:21 +02:00
|
|
|
visibilityButton.setImageDrawable(globe);
|
2017-04-21 07:50:59 +02:00
|
|
|
}
|
2017-03-27 00:26:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-11-16 19:18:11 +01:00
|
|
|
case PRIVATE: {
|
2017-04-21 07:50:59 +02:00
|
|
|
Drawable lock = AppCompatResources.getDrawable(this,
|
|
|
|
R.drawable.ic_lock_outline_24dp);
|
2017-04-03 01:10:07 +02:00
|
|
|
if (lock != null) {
|
2018-04-13 22:37:21 +02:00
|
|
|
visibilityButton.setImageDrawable(lock);
|
2017-04-03 01:10:07 +02:00
|
|
|
}
|
2017-03-27 00:26:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-11-16 19:18:11 +01:00
|
|
|
case DIRECT: {
|
2017-04-21 07:50:59 +02:00
|
|
|
Drawable envelope = AppCompatResources.getDrawable(this, R.drawable.ic_email_24dp);
|
|
|
|
if (envelope != null) {
|
2018-04-13 22:37:21 +02:00
|
|
|
visibilityButton.setImageDrawable(envelope);
|
2017-04-21 07:50:59 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-11-16 19:18:11 +01:00
|
|
|
case UNLISTED:
|
2017-03-27 00:26:47 +02:00
|
|
|
default: {
|
2018-04-13 22:37:21 +02:00
|
|
|
Drawable openLock = AppCompatResources.getDrawable(this, R.drawable.ic_lock_open_24dp);
|
2017-04-21 07:50:59 +02:00
|
|
|
if (openLock != null) {
|
2018-04-13 22:37:21 +02:00
|
|
|
visibilityButton.setImageDrawable(openLock);
|
2017-04-21 07:50:59 +02:00
|
|
|
}
|
2017-03-27 00:26:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 14:09:33 +01:00
|
|
|
private void showComposeOptions() {
|
2018-04-13 22:37:21 +02: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-17 22:39:55 +02: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-13 22:37:21 +02:00
|
|
|
}
|
2018-04-17 22:39:55 +02:00
|
|
|
|
2018-04-13 22:37:21 +02: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-07 14:09:33 +01:00
|
|
|
}
|
2017-02-17 23:56:31 +01:00
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
@Override
|
2018-04-13 22:37:21 +02:00
|
|
|
public void onVisibilityChanged(@NonNull Status.Visibility visibility) {
|
|
|
|
composeOptionsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
2017-04-05 04:29:15 +02:00
|
|
|
setStatusVisibility(visibility);
|
|
|
|
}
|
|
|
|
|
2018-07-10 19:39:52 +02:00
|
|
|
int calculateTextLength() {
|
2018-05-16 19:14:26 +02: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-10 19:39:52 +02:00
|
|
|
int length = textEditor.length() - offset;
|
2017-04-10 19:34:33 +02:00
|
|
|
if (statusHideText) {
|
2018-07-10 19:39:52 +02:00
|
|
|
length += contentWarningEditor.length();
|
2017-04-10 19:34:33 +02:00
|
|
|
}
|
2018-07-10 19:39:52 +02:00
|
|
|
return length;
|
2018-05-16 19:14:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVisibleCharactersLeft() {
|
2018-07-10 19:39:52 +02:00
|
|
|
this.charactersLeft.setText(String.format(Locale.getDefault(), "%d", maximumTootCharacters - calculateTextLength()));
|
2017-04-10 19:34:33 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
private void onContentWarningChanged() {
|
|
|
|
boolean showWarning = contentWarningBar.getVisibility() != View.VISIBLE;
|
|
|
|
showContentWarning(showWarning);
|
2017-04-10 19:34:33 +02:00
|
|
|
updateVisibleCharactersLeft();
|
2017-04-05 04:29:15 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 02:27:59 +02:00
|
|
|
private void onSendClicked() {
|
2018-04-13 22:37:21 +02:00
|
|
|
disableButtons();
|
2017-05-04 02:27:59 +02:00
|
|
|
readyStatus(statusVisibility, statusMarkSensitive);
|
2017-02-17 23:56:31 +01:00
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
|
2017-03-04 02:44:44 +01:00
|
|
|
try {
|
|
|
|
if (currentInputContentInfo != null) {
|
|
|
|
currentInputContentInfo.releasePermission();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(TAG, "InputContentInfoCompat#releasePermission() failed." + e.getMessage());
|
|
|
|
} finally {
|
|
|
|
currentInputContentInfo = null;
|
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
// Verify the returned content's type is of the correct MIME type
|
|
|
|
boolean supported = inputContentInfo.getDescription().hasMimeType("image/*");
|
2017-03-04 02:44:44 +01: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-25 17:21:11 +02:00
|
|
|
Log.d(TAG, Log.getStackTraceString(e));
|
2017-03-04 02:44:44 +01: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 {
|
2017-07-02 22:34:10 +02:00
|
|
|
mediaSize = MediaUtils.MEDIA_SIZE_UNKNOWN;
|
2017-03-04 02:44:44 +01:00
|
|
|
}
|
|
|
|
pickMedia(uri, mediaSize);
|
|
|
|
|
|
|
|
currentInputContentInfo = inputContentInfo;
|
|
|
|
currentFlags = flags;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
private void sendStatus(String content, Status.Visibility visibility, boolean sensitive,
|
2017-10-29 22:18:45 +01:00
|
|
|
String spoilerText) {
|
2017-03-14 01:49:12 +01:00
|
|
|
ArrayList<String> mediaIds = new ArrayList<>();
|
2018-06-28 22:22:29 +02:00
|
|
|
ArrayList<Uri> mediaUris = new ArrayList<>();
|
2017-03-09 16:59:18 +01:00
|
|
|
for (QueuedMedia item : mediaQueued) {
|
|
|
|
mediaIds.add(item.id);
|
2018-06-28 22:22:29 +02:00
|
|
|
mediaUris.add(item.uri);
|
2017-01-20 05:59:21 +01:00
|
|
|
}
|
2017-03-09 16:59:18 +01:00
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
Intent sendIntent = SendTootService.sendTootIntent(this, content, spoilerText,
|
|
|
|
visibility, sensitive, mediaIds, mediaUris, inReplyToId,
|
|
|
|
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 05:59:21 +01:00
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
startService(sendIntent);
|
2017-11-02 21:18:39 +01:00
|
|
|
|
2018-08-07 23:08:53 +02:00
|
|
|
finishWithoutSlideOutAnimation();
|
2017-11-16 19:18:11 +01:00
|
|
|
|
2017-02-04 01:53:33 +01:00
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
private void readyStatus(final Status.Visibility visibility, final boolean sensitive) {
|
2017-03-04 02:44:44 +01:00
|
|
|
finishingUploadDialog = ProgressDialog.show(
|
2017-02-07 08:05:50 +01:00
|
|
|
this, getString(R.string.dialog_title_finishing_media_upload),
|
|
|
|
getString(R.string.dialog_message_uploading_media), true, true);
|
2017-11-16 19:18:11 +01:00
|
|
|
@SuppressLint("StaticFieldLeak") final AsyncTask<Void, Void, Boolean> waitForMediaTask =
|
2017-01-20 05:59:21 +01: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 02:44:44 +01:00
|
|
|
finishingUploadDialog.dismiss();
|
|
|
|
finishingUploadDialog = null;
|
2017-01-20 05:59:21 +01:00
|
|
|
if (successful) {
|
2017-05-04 02:27:59 +02:00
|
|
|
onReadySuccess(visibility, sensitive);
|
2017-01-20 05:59:21 +01:00
|
|
|
} else {
|
2017-05-04 02:27:59 +02:00
|
|
|
onReadyFailure(visibility, sensitive);
|
2017-01-20 05:59:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCancelled() {
|
|
|
|
removeAllMediaFromQueue();
|
2018-04-13 22:37:21 +02:00
|
|
|
enableButtons();
|
2017-01-20 05:59:21 +01:00
|
|
|
super.onCancelled();
|
|
|
|
}
|
|
|
|
};
|
2017-11-27 20:11:31 +01: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 05:59:21 +01:00
|
|
|
});
|
|
|
|
waitForMediaTask.execute();
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
private void onReadySuccess(Status.Visibility visibility, boolean sensitive) {
|
2018-07-10 19:39:52 +02:00
|
|
|
/* Validate the status meets the character limit. */
|
2017-05-04 02:27:59 +02:00
|
|
|
String contentText = textEditor.getText().toString();
|
|
|
|
String spoilerText = "";
|
|
|
|
if (statusHideText) {
|
|
|
|
spoilerText = contentWarningEditor.getText().toString();
|
|
|
|
}
|
2018-07-10 19:39:52 +02:00
|
|
|
int characterCount = calculateTextLength();
|
2018-04-13 22:37:21 +02:00
|
|
|
if (characterCount <= 0 && mediaQueued.size()==0) {
|
2017-05-04 02:27:59 +02:00
|
|
|
textEditor.setError(getString(R.string.error_empty));
|
2018-04-13 22:37:21 +02:00
|
|
|
enableButtons();
|
2018-04-22 10:35:46 +02:00
|
|
|
} else if (characterCount <= maximumTootCharacters) {
|
2018-04-13 22:37:21 +02:00
|
|
|
sendStatus(contentText, visibility, sensitive, spoilerText);
|
|
|
|
|
2017-05-04 02:27:59 +02:00
|
|
|
} else {
|
|
|
|
textEditor.setError(getString(R.string.error_compose_character_limit));
|
2018-04-13 22:37:21 +02:00
|
|
|
enableButtons();
|
2017-05-04 02:27:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
private void onReadyFailure(final Status.Visibility visibility, final boolean sensitive) {
|
2017-01-20 05:59:21 +01:00
|
|
|
doErrorDialog(R.string.error_media_upload_sending, R.string.action_retry,
|
2017-11-27 20:11:31 +01:00
|
|
|
v -> readyStatus(visibility, sensitive));
|
2018-04-13 22:37:21 +02:00
|
|
|
enableButtons();
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
|
2017-10-29 22:18:45 +01:00
|
|
|
@NonNull int[] grantResults) {
|
2017-01-16 19:15:42 +01: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-27 20:11:31 +01:00
|
|
|
v -> onMediaPick());
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-02 23:45:13 +02:00
|
|
|
@NonNull
|
2017-04-15 17:43:26 +02:00
|
|
|
private File createNewImageFile() throws IOException {
|
|
|
|
// Create an image file name
|
2018-09-07 19:57:25 +02:00
|
|
|
String randomId = StringUtils.randomAlphanumericString(12);
|
|
|
|
String imageFileName = "Tusky_" + randomId + "_";
|
2017-04-15 17:43:26 +02:00
|
|
|
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
2017-04-21 07:50:59 +02:00
|
|
|
return File.createTempFile(
|
2017-04-15 17:43:26 +02:00
|
|
|
imageFileName, /* prefix */
|
|
|
|
".jpg", /* suffix */
|
|
|
|
storageDir /* directory */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initiateCameraApp() {
|
2018-04-13 22:37:21 +02:00
|
|
|
addMediaBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
|
|
|
|
2017-04-15 17:43:26 +02: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-13 22:37:21 +02:00
|
|
|
BuildConfig.APPLICATION_ID+".fileprovider",
|
2017-04-15 17:43:26 +02:00
|
|
|
photoFile);
|
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUploadUri);
|
|
|
|
startActivityForResult(intent, MEDIA_TAKE_PHOTO_RESULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 19:15:42 +01:00
|
|
|
private void initiateMediaPicking() {
|
2018-06-28 22:22:29 +02:00
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
2017-01-16 19:15:42 +01:00
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
2018-04-14 13:56:48 +02:00
|
|
|
|
|
|
|
String[] mimeTypes = new String[]{"image/*", "video/*"};
|
|
|
|
intent.setType("*/*");
|
|
|
|
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
|
2017-01-16 19:15:42 +01:00
|
|
|
startActivityForResult(intent, MEDIA_PICK_RESULT);
|
|
|
|
}
|
|
|
|
|
2018-04-17 22:39:55 +02: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-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
|
2018-05-06 13:02:02 +02:00
|
|
|
private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
|
|
|
|
addMediaToQueue(null, type, preview, uri, mediaSize, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addMediaToQueue(@Nullable String id, QueuedMedia.Type type, Bitmap preview, Uri uri,
|
|
|
|
long mediaSize, QueuedMedia.ReadyStage readyStage, @Nullable String description) {
|
2018-01-08 23:16:21 +01:00
|
|
|
final QueuedMedia item = new QueuedMedia(type, uri, new ProgressImageView(this),
|
|
|
|
mediaSize, description);
|
2018-05-06 13:02:02 +02:00
|
|
|
item.id = id;
|
2017-10-28 22:24:26 +02:00
|
|
|
item.readyStage = readyStage;
|
2017-02-16 19:52:55 +01:00
|
|
|
ImageView view = item.preview;
|
2017-01-16 19:15:42 +01: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-23 21:55:09 +02:00
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(thumbnailViewSize, thumbnailViewSize);
|
2017-03-10 18:38:49 +01:00
|
|
|
layoutParams.setMargins(margin, 0, margin, marginBottom);
|
2017-01-16 19:15:42 +01:00
|
|
|
view.setLayoutParams(layoutParams);
|
2017-03-15 01:34:27 +01:00
|
|
|
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
|
view.setImageBitmap(preview);
|
2018-01-08 23:16:21 +01:00
|
|
|
view.setOnClickListener(v -> onMediaClick(item, v));
|
2017-07-19 04:32:13 +02:00
|
|
|
view.setContentDescription(getString(R.string.action_delete));
|
2017-01-16 19:15:42 +01: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-16 19:52:55 +01:00
|
|
|
if (item.type == QueuedMedia.Type.VIDEO) {
|
2018-04-17 22:39:55 +02:00
|
|
|
enableButton(pickButton, false, false);
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
} else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
|
|
|
|
// Limit the total media attachments, also.
|
2018-04-17 22:39:55 +02:00
|
|
|
enableButton(pickButton, false, false);
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
2018-04-13 22:37:21 +02:00
|
|
|
|
|
|
|
updateHideMediaToggle();
|
|
|
|
|
2017-10-28 22:24:26 +02:00
|
|
|
if (item.readyStage != QueuedMedia.ReadyStage.UPLOADED) {
|
|
|
|
waitForMediaLatch.countUp();
|
2018-06-18 13:26:31 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (type == QueuedMedia.Type.IMAGE &&
|
2018-09-06 22:48:19 +02:00
|
|
|
(mediaSize > STATUS_IMAGE_SIZE_LIMIT || MediaUtils.getImageSquarePixels(getContentResolver(), item.uri) > STATUS_IMAGE_PIXEL_SIZE_LIMIT)) {
|
2018-06-18 13:26:31 +02:00
|
|
|
downsizeMedia(item);
|
|
|
|
} else {
|
|
|
|
uploadMedia(item);
|
|
|
|
}
|
2018-09-07 19:57:25 +02:00
|
|
|
} catch (IOException e) {
|
2018-06-18 13:26:31 +02:00
|
|
|
onUploadFailure(item, false);
|
2017-10-28 22:24:26 +02:00
|
|
|
}
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 23:16:21 +01: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-15 20:47:36 +02:00
|
|
|
|
|
|
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
|
|
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
|
|
|
|
|
2018-09-03 20:26:35 +02:00
|
|
|
Single.fromCallable(() ->
|
|
|
|
MediaUtils.getSampledBitmap(getContentResolver(), item.uri, displayMetrics.widthPixels, displayMetrics.heightPixels))
|
|
|
|
.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-08 23:16:21 +01: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);
|
|
|
|
input.setHint(R.string.hint_describe_for_visually_impaired);
|
|
|
|
dialogLayout.addView(input);
|
|
|
|
((LinearLayout.LayoutParams) input.getLayoutParams()).setMargins(margin, margin, margin, margin);
|
|
|
|
input.setLines(1);
|
|
|
|
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
|
|
|
|
input.setText(item.description);
|
|
|
|
|
2018-03-05 22:43:13 +01:00
|
|
|
DialogInterface.OnClickListener okListener = (dialog, which) -> {
|
|
|
|
mastodonApi.updateMedia(item.id, input.getText().toString())
|
|
|
|
.enqueue(new Callback<Attachment>() {
|
|
|
|
@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 15:20:53 +02:00
|
|
|
item.preview.setChecked(item.description != null && !item.description.isEmpty());
|
2018-03-05 22:43:13 +01:00
|
|
|
dialog.dismiss();
|
|
|
|
} else {
|
|
|
|
showFailedCaptionMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
|
|
|
|
showFailedCaptionMessage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-01-08 23:16:21 +01:00
|
|
|
AlertDialog dialog = new AlertDialog.Builder(this)
|
|
|
|
.setView(dialogLayout)
|
2018-03-05 22:43:13 +01:00
|
|
|
.setPositiveButton(android.R.string.ok, okListener)
|
2018-01-08 23:16:21 +01: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-16 19:15:42 +01:00
|
|
|
private void removeMediaFromQueue(QueuedMedia item) {
|
2017-02-16 19:52:55 +01:00
|
|
|
mediaPreviewBar.removeView(item.preview);
|
2017-01-16 19:15:42 +01:00
|
|
|
mediaQueued.remove(item);
|
|
|
|
if (mediaQueued.size() == 0) {
|
2018-04-13 22:37:21 +02:00
|
|
|
updateHideMediaToggle();
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
2018-04-13 22:37:21 +02:00
|
|
|
|
2018-04-17 22:39:55 +02:00
|
|
|
enableButton(pickButton, true, true);
|
2017-01-16 19:15:42 +01:00
|
|
|
cancelReadyingMedia(item);
|
|
|
|
}
|
|
|
|
|
2017-01-18 19:35:07 +01:00
|
|
|
private void removeAllMediaFromQueue() {
|
2017-05-16 10:43:32 +02:00
|
|
|
for (Iterator<QueuedMedia> it = mediaQueued.iterator(); it.hasNext(); ) {
|
2017-01-18 19:35:07 +01:00
|
|
|
QueuedMedia item = it.next();
|
|
|
|
it.remove();
|
|
|
|
removeMediaFromQueue(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 19:57:25 +02:00
|
|
|
private void downsizeMedia(final QueuedMedia item) throws IOException {
|
2017-02-16 19:52:55 +01:00
|
|
|
item.readyStage = QueuedMedia.ReadyStage.DOWNSIZING;
|
2017-01-16 19:15:42 +01:00
|
|
|
|
2018-09-07 19:57:25 +02:00
|
|
|
new DownsizeImageTask(STATUS_IMAGE_SIZE_LIMIT, getContentResolver(), createNewImageFile(),
|
2017-03-31 23:53:35 +02:00
|
|
|
new DownsizeImageTask.Listener() {
|
|
|
|
@Override
|
2018-09-07 19:57:25 +02:00
|
|
|
public void onSuccess(File tempFile) {
|
|
|
|
item.uri = FileProvider.getUriForFile(
|
|
|
|
ComposeActivity.this,
|
|
|
|
BuildConfig.APPLICATION_ID+".fileprovider",
|
|
|
|
tempFile);
|
2017-03-31 23:53:35 +02:00
|
|
|
uploadMedia(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure() {
|
|
|
|
onMediaDownsizeFailure(item);
|
|
|
|
}
|
2017-05-16 10:43:32 +02:00
|
|
|
}).execute(item.uri);
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onMediaDownsizeFailure(QueuedMedia item) {
|
2018-09-06 22:48:19 +02:00
|
|
|
displayTransientError(R.string.error_image_upload_size);
|
2017-01-16 19:15:42 +01:00
|
|
|
removeMediaFromQueue(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void uploadMedia(final QueuedMedia item) {
|
2017-02-16 19:52:55 +01:00
|
|
|
item.readyStage = QueuedMedia.ReadyStage.UPLOADING;
|
2017-01-16 19:15:42 +01:00
|
|
|
|
2017-10-29 22:18:45 +01:00
|
|
|
String mimeType = getContentResolver().getType(item.uri);
|
2017-01-16 19:15:42 +01: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-02 22:34:10 +02:00
|
|
|
StringUtils.randomAlphanumericString(10),
|
2017-01-16 19:15:42 +01:00
|
|
|
fileExtension);
|
|
|
|
|
2018-09-07 19:57:25 +02:00
|
|
|
InputStream stream;
|
2017-03-09 16:59:18 +01:00
|
|
|
|
2018-09-07 19:57:25 +02:00
|
|
|
try {
|
|
|
|
stream = getContentResolver().openInputStream(item.uri);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
return;
|
2017-03-09 16:59:18 +01:00
|
|
|
}
|
|
|
|
|
2017-10-29 22:18:45 +01:00
|
|
|
if (mimeType == null) mimeType = "multipart/form-data";
|
|
|
|
|
|
|
|
item.preview.setProgress(0);
|
|
|
|
|
2018-09-07 19:57:25 +02:00
|
|
|
ProgressRequestBody fileBody = new ProgressRequestBody(stream, MediaUtils.getMediaSize(getContentResolver(), item.uri), MediaType.parse(mimeType),
|
2017-10-29 22:18:45 +01: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-27 20:11:31 +01:00
|
|
|
runOnUiThread(() -> item.preview.setProgress(percentage));
|
2017-10-29 22:18:45 +01:00
|
|
|
}
|
|
|
|
lastProgress = percentage;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
MultipartBody.Part body = MultipartBody.Part.createFormData("file", filename, fileBody);
|
2017-03-09 16:59:18 +01:00
|
|
|
|
2017-06-22 20:01:25 +02:00
|
|
|
item.uploadRequest = mastodonApi.uploadMedia(body);
|
2017-03-09 16:59:18 +01:00
|
|
|
|
2017-11-30 20:12:09 +01:00
|
|
|
item.uploadRequest.enqueue(new Callback<Attachment>() {
|
2017-01-16 19:15:42 +01:00
|
|
|
@Override
|
2017-11-30 20:12:09 +01:00
|
|
|
public void onResponse(@NonNull Call<Attachment> call, @NonNull retrofit2.Response<Attachment> response) {
|
2017-03-14 01:49:12 +01:00
|
|
|
if (response.isSuccessful()) {
|
2017-05-04 02:27:59 +02:00
|
|
|
onUploadSuccess(item, response.body());
|
2017-03-14 01:49:12 +01:00
|
|
|
} else {
|
|
|
|
Log.d(TAG, "Upload request failed. " + response.message());
|
2017-03-15 01:34:27 +01:00
|
|
|
onUploadFailure(item, call.isCanceled());
|
2017-03-14 01:49:12 +01:00
|
|
|
}
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-30 20:12:09 +01:00
|
|
|
public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
|
2017-07-02 23:55:18 +02:00
|
|
|
Log.d(TAG, "Upload request failed. " + t.getMessage());
|
|
|
|
onUploadFailure(item, call.isCanceled());
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
2017-03-09 16:59:18 +01:00
|
|
|
});
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 20:12:09 +01:00
|
|
|
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
|
2018-03-03 13:24:03 +01:00
|
|
|
item.id = media.getId();
|
2017-10-29 22:18:45 +01:00
|
|
|
item.preview.setProgress(-1);
|
2017-10-28 22:24:26 +02:00
|
|
|
item.readyStage = QueuedMedia.ReadyStage.UPLOADED;
|
2017-05-04 02:27:59 +02:00
|
|
|
|
|
|
|
waitForMediaLatch.countDown();
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:34:27 +01:00
|
|
|
private void onUploadFailure(QueuedMedia item, boolean isCanceled) {
|
2017-03-15 02:25:47 +01:00
|
|
|
if (!isCanceled) {
|
2017-03-15 01:34:27 +01: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-07 15:01:20 +01:00
|
|
|
if (finishingUploadDialog != null && finishingUploadDialog.isShowing()) {
|
2017-03-04 02:44:44 +01:00
|
|
|
finishingUploadDialog.cancel();
|
|
|
|
}
|
2017-07-02 23:55:18 +02:00
|
|
|
if (!isCanceled) {
|
|
|
|
// If it is canceled, it's already been removed, otherwise do it.
|
|
|
|
removeMediaFromQueue(item);
|
|
|
|
}
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void cancelReadyingMedia(QueuedMedia item) {
|
2017-02-16 19:52:55 +01:00
|
|
|
if (item.readyStage == QueuedMedia.ReadyStage.UPLOADING) {
|
2017-02-17 23:56:31 +01: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-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-13 22:37:21 +02: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();
|
2017-07-02 22:34:10 +02:00
|
|
|
long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri);
|
2017-03-04 02:44:44 +01:00
|
|
|
pickMedia(uri, mediaSize);
|
2017-07-02 23:45:13 +02:00
|
|
|
} else if (resultCode == RESULT_OK && requestCode == MEDIA_TAKE_PHOTO_RESULT) {
|
2017-07-02 22:34:10 +02:00
|
|
|
long mediaSize = MediaUtils.getMediaSize(getContentResolver(), photoUploadUri);
|
2017-04-21 07:50:59 +02:00
|
|
|
pickMedia(photoUploadUri, mediaSize);
|
2017-03-04 02:44:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-20 23:54:41 +02:00
|
|
|
|
2017-03-04 02:44:44 +01:00
|
|
|
private void pickMedia(Uri uri, long mediaSize) {
|
2017-07-02 22:34:10 +02:00
|
|
|
if (mediaSize == MediaUtils.MEDIA_SIZE_UNKNOWN) {
|
2017-03-04 02:44:44 +01:00
|
|
|
displayTransientError(R.string.error_media_upload_opening);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-05 21:48:17 +01:00
|
|
|
ContentResolver contentResolver = getContentResolver();
|
2017-03-04 02:44:44 +01:00
|
|
|
String mimeType = contentResolver.getType(uri);
|
|
|
|
if (mimeType != null) {
|
|
|
|
String topLevelType = mimeType.substring(0, mimeType.indexOf('/'));
|
|
|
|
switch (topLevelType) {
|
|
|
|
case "video": {
|
2018-09-06 22:48:19 +02:00
|
|
|
if (mediaSize > STATUS_VIDEO_SIZE_LIMIT) {
|
|
|
|
displayTransientError(R.string.error_image_upload_size);
|
2017-03-04 02:44:44 +01:00
|
|
|
return;
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
2017-03-04 02:44:44 +01:00
|
|
|
if (mediaQueued.size() > 0
|
|
|
|
&& mediaQueued.get(0).type == QueuedMedia.Type.IMAGE) {
|
|
|
|
displayTransientError(R.string.error_media_upload_image_or_video);
|
|
|
|
return;
|
|
|
|
}
|
2018-07-23 21:55:09 +02:00
|
|
|
Bitmap bitmap = MediaUtils.getVideoThumbnail(this, uri, thumbnailViewSize);
|
2017-07-20 23:54:41 +02:00
|
|
|
if (bitmap != null) {
|
2018-05-06 13:02:02 +02:00
|
|
|
addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize);
|
2017-07-20 23:54:41 +02:00
|
|
|
} else {
|
2017-07-19 06:28:36 +02:00
|
|
|
displayTransientError(R.string.error_media_upload_opening);
|
|
|
|
}
|
2017-03-04 02:44:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "image": {
|
2018-07-23 21:55:09 +02:00
|
|
|
Bitmap bitmap = MediaUtils.getImageThumbnail(contentResolver, uri, thumbnailViewSize);
|
2017-07-20 23:54:41 +02:00
|
|
|
if (bitmap != null) {
|
2018-05-06 13:02:02 +02:00
|
|
|
addMediaToQueue(QueuedMedia.Type.IMAGE, bitmap, uri, mediaSize);
|
2017-07-20 23:54:41 +02:00
|
|
|
} else {
|
2017-03-04 02:44:44 +01:00
|
|
|
displayTransientError(R.string.error_media_upload_opening);
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
2017-03-04 02:44:44 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
displayTransientError(R.string.error_media_upload_type);
|
|
|
|
break;
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-04 02:44:44 +01:00
|
|
|
} else {
|
|
|
|
displayTransientError(R.string.error_media_upload_type);
|
2017-01-16 19:15:42 +01:00
|
|
|
}
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|
2017-02-04 01:53:33 +01:00
|
|
|
|
2017-07-08 04:56:07 +02:00
|
|
|
private void showContentWarning(boolean show) {
|
2017-02-04 01:53:33 +01:00
|
|
|
statusHideText = show;
|
2018-04-13 22:37:21 +02:00
|
|
|
TransitionManager.beginDelayedTransition((ViewGroup)contentWarningBar.getParent());
|
2017-02-04 01:53:33 +01:00
|
|
|
if (show) {
|
2018-04-13 22:37:21 +02:00
|
|
|
statusMarkSensitive = true;
|
2017-02-04 01:53:33 +01:00
|
|
|
contentWarningBar.setVisibility(View.VISIBLE);
|
2018-04-13 22:37:21 +02:00
|
|
|
contentWarningButton.setTextColor(ContextCompat.getColor(this, R.color.primary));
|
2017-02-04 01:53:33 +01:00
|
|
|
} else {
|
|
|
|
contentWarningBar.setVisibility(View.GONE);
|
2018-04-13 22:37:21 +02:00
|
|
|
contentWarningButton.setTextColor(ThemeUtils.getColor(this, android.R.attr.textColorTertiary));
|
2017-02-04 01:53:33 +01:00
|
|
|
}
|
2018-04-13 22:37:21 +02:00
|
|
|
updateHideMediaToggle();
|
|
|
|
|
2017-02-04 01:53:33 +01:00
|
|
|
}
|
2017-03-07 14:09:33 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2018-03-05 22:43:13 +01:00
|
|
|
case android.R.id.home:
|
|
|
|
handleCloseButton();
|
2017-03-07 14:09:33 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2017-05-16 10:43:32 +02:00
|
|
|
|
2018-03-05 22:43:13 +01:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
// Acting like a teen: deliberately ignoring parent.
|
|
|
|
handleCloseButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleCloseButton() {
|
2018-04-22 21:04:19 +02: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-05 22:43:13 +01:00
|
|
|
new AlertDialog.Builder(this)
|
2018-04-13 22:37:21 +02:00
|
|
|
.setMessage(R.string.compose_save_draft)
|
|
|
|
.setPositiveButton(R.string.action_save, (d, w) -> saveDraftAndFinish())
|
2018-08-07 23:08:53 +02:00
|
|
|
.setNegativeButton(R.string.action_delete, (d, w) -> finishWithoutSlideOutAnimation())
|
2018-03-05 22:43:13 +01:00
|
|
|
.show();
|
|
|
|
} else {
|
2018-08-07 23:08:53 +02:00
|
|
|
finishWithoutSlideOutAnimation();
|
2018-03-05 22:43:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
private void saveDraftAndFinish() {
|
|
|
|
ArrayList<String> mediaUris = new ArrayList<>();
|
|
|
|
for (QueuedMedia item : mediaQueued) {
|
|
|
|
mediaUris.add(item.uri.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
saveTootHelper.saveToot(textEditor.getText().toString(),
|
|
|
|
contentWarningEditor.getText().toString(),
|
|
|
|
getIntent().getStringExtra("saved_json_urls"),
|
|
|
|
mediaUris,
|
|
|
|
savedTootUid,
|
|
|
|
inReplyToId,
|
|
|
|
getIntent().getStringExtra(REPLYING_STATUS_CONTENT_EXTRA),
|
|
|
|
getIntent().getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA),
|
|
|
|
statusVisibility);
|
2018-08-23 20:57:51 +02:00
|
|
|
finishWithoutSlideOutAnimation();
|
2018-04-13 22:37:21 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
@Override
|
|
|
|
public List<Account> searchAccounts(String mention) {
|
2017-06-19 05:34:48 +02:00
|
|
|
ArrayList<Account> resultList = new ArrayList<>();
|
2017-06-19 04:10:50 +02:00
|
|
|
try {
|
2017-06-22 20:01:25 +02:00
|
|
|
List<Account> accountList = mastodonApi.searchAccounts(mention, false, 40)
|
2017-06-19 04:10:50 +02:00
|
|
|
.execute()
|
|
|
|
.body();
|
2017-06-19 05:34:48 +02:00
|
|
|
if (accountList != null) {
|
|
|
|
resultList.addAll(accountList);
|
2017-06-19 04:10:50 +02:00
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.e(TAG, String.format("Autocomplete search for %s failed.", mention));
|
|
|
|
}
|
|
|
|
return resultList;
|
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
@Override
|
|
|
|
public void onEmojiSelected(@NotNull String shortcode) {
|
|
|
|
textEditor.getText().insert(textEditor.getSelectionStart(), ":"+shortcode+": ");
|
|
|
|
}
|
|
|
|
|
2018-04-22 21:04:19 +02:00
|
|
|
private void loadCachedInstanceMetadata(@NotNull AccountEntity activeAccount) {
|
2018-05-27 10:22:12 +02:00
|
|
|
InstanceEntity instanceEntity = database.instanceDao()
|
|
|
|
.loadMetadataForInstance(activeAccount.getDomain());
|
2018-04-22 10:35:46 +02:00
|
|
|
|
|
|
|
if(instanceEntity != null) {
|
|
|
|
Integer max = instanceEntity.getMaximumTootCharacters();
|
2018-04-22 21:04:19 +02:00
|
|
|
maximumTootCharacters = (max == null ? STATUS_CHARACTER_LIMIT : max);
|
2018-04-22 10:35:46 +02:00
|
|
|
emojiList = instanceEntity.getEmojiList();
|
2018-04-23 09:26:03 +02: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 10:35:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 09:26:03 +02:00
|
|
|
private void cacheInstanceMetadata(@NotNull AccountEntity activeAccount) {
|
2018-04-22 10:35:46 +02:00
|
|
|
InstanceEntity instanceEntity = new InstanceEntity(activeAccount.getDomain(), emojiList, maximumTootCharacters);
|
2018-05-27 10:22:12 +02:00
|
|
|
database.instanceDao().insertOrReplace(instanceEntity);
|
2018-04-22 10:35:46 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 10:08:25 +02:00
|
|
|
// Accessors for testing, hence package scope
|
|
|
|
int getMaximumTootCharacters()
|
|
|
|
{
|
|
|
|
return maximumTootCharacters;
|
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
public static final class QueuedMedia {
|
2017-05-16 10:43:32 +02:00
|
|
|
Type type;
|
2017-10-29 22:18:45 +01:00
|
|
|
ProgressImageView preview;
|
2017-05-16 10:43:32 +02:00
|
|
|
Uri uri;
|
|
|
|
String id;
|
2017-11-30 20:12:09 +01:00
|
|
|
Call<Attachment> uploadRequest;
|
2017-05-16 10:43:32 +02:00
|
|
|
ReadyStage readyStage;
|
|
|
|
long mediaSize;
|
2018-01-08 23:16:21 +01:00
|
|
|
String description;
|
2017-05-16 10:43:32 +02:00
|
|
|
|
2018-01-08 23:16:21 +01:00
|
|
|
QueuedMedia(Type type, Uri uri, ProgressImageView preview, long mediaSize,
|
|
|
|
String description) {
|
2017-05-16 10:43:32 +02:00
|
|
|
this.type = type;
|
|
|
|
this.uri = uri;
|
|
|
|
this.preview = preview;
|
|
|
|
this.mediaSize = mediaSize;
|
2018-01-08 23:16:21 +01:00
|
|
|
this.description = description;
|
2017-05-16 10:43:32 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 22:37:21 +02:00
|
|
|
public enum Type {
|
2017-05-16 10:43:32 +02:00
|
|
|
IMAGE,
|
|
|
|
VIDEO
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ReadyStage {
|
|
|
|
DOWNSIZING,
|
2017-10-28 22:24:26 +02:00
|
|
|
UPLOADING,
|
|
|
|
UPLOADED
|
2017-05-16 10:43:32 +02: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 13:02:02 +02:00
|
|
|
String id;
|
2017-05-16 10:43:32 +02:00
|
|
|
QueuedMedia.Type type;
|
|
|
|
Uri uri;
|
|
|
|
long mediaSize;
|
2017-10-28 22:24:26 +02:00
|
|
|
QueuedMedia.ReadyStage readyStage;
|
2018-01-08 23:16:21 +01:00
|
|
|
String description;
|
2017-05-16 10:43:32 +02:00
|
|
|
|
2018-05-06 13:02:02 +02:00
|
|
|
SavedQueuedMedia(String id, QueuedMedia.Type type, Uri uri, long mediaSize, QueuedMedia.ReadyStage readyStage, String description) {
|
|
|
|
this.id = id;
|
2017-05-16 10:43:32 +02:00
|
|
|
this.type = type;
|
|
|
|
this.uri = uri;
|
|
|
|
this.mediaSize = mediaSize;
|
2017-10-28 22:24:26 +02:00
|
|
|
this.readyStage = readyStage;
|
2018-01-08 23:16:21 +01:00
|
|
|
this.description = description;
|
2017-05-16 10:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SavedQueuedMedia(Parcel parcel) {
|
2018-05-06 13:02:02 +02:00
|
|
|
id = parcel.readString();
|
2017-05-16 10:43:32 +02:00
|
|
|
type = (QueuedMedia.Type) parcel.readSerializable();
|
|
|
|
uri = parcel.readParcelable(Uri.class.getClassLoader());
|
|
|
|
mediaSize = parcel.readLong();
|
2017-10-28 22:24:26 +02:00
|
|
|
readyStage = QueuedMedia.ReadyStage.valueOf(parcel.readString());
|
2018-01-08 23:16:21 +01:00
|
|
|
description = parcel.readString();
|
2017-05-16 10:43:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
2018-05-06 13:02:02 +02:00
|
|
|
dest.writeString(id);
|
2017-05-16 10:43:32 +02:00
|
|
|
dest.writeSerializable(type);
|
|
|
|
dest.writeParcelable(uri, flags);
|
|
|
|
dest.writeLong(mediaSize);
|
2017-10-28 22:24:26 +02:00
|
|
|
dest.writeString(readyStage.name());
|
2018-01-08 23:16:21 +01:00
|
|
|
dest.writeString(description);
|
2017-05-16 10:43:32 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-19 04:10:50 +02:00
|
|
|
|
2017-11-01 20:59:29 +01:00
|
|
|
public static final class IntentBuilder {
|
|
|
|
@Nullable
|
|
|
|
private Integer savedTootUid;
|
|
|
|
@Nullable
|
|
|
|
private String savedTootText;
|
|
|
|
@Nullable
|
|
|
|
private String savedJsonUrls;
|
|
|
|
@Nullable
|
|
|
|
private Collection<String> mentionedUsernames;
|
|
|
|
@Nullable
|
|
|
|
private String inReplyToId;
|
|
|
|
@Nullable
|
2017-11-16 19:18:11 +01:00
|
|
|
private Status.Visibility replyVisibility;
|
2017-11-01 20:59:29 +01:00
|
|
|
@Nullable
|
2018-08-23 20:50:50 +02:00
|
|
|
private Status.Visibility savedVisibility;
|
|
|
|
@Nullable
|
2017-11-01 20:59:29 +01:00
|
|
|
private String contentWarning;
|
|
|
|
@Nullable
|
2017-11-16 19:18:11 +01:00
|
|
|
private String replyingStatusAuthor;
|
2017-11-01 20:59:29 +01: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-08-23 20:50:50 +02:00
|
|
|
public IntentBuilder savedVisibility(Status.Visibility savedVisibility) {
|
|
|
|
this.savedVisibility = savedVisibility;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-11-01 20:59:29 +01:00
|
|
|
public IntentBuilder mentionedUsernames(Collection<String> mentionedUsernames) {
|
|
|
|
this.mentionedUsernames = mentionedUsernames;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntentBuilder inReplyToId(String inReplyToId) {
|
|
|
|
this.inReplyToId = inReplyToId;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
public IntentBuilder replyVisibility(Status.Visibility replyVisibility) {
|
2017-11-01 20:59:29 +01:00
|
|
|
this.replyVisibility = replyVisibility;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IntentBuilder contentWarning(String contentWarning) {
|
|
|
|
this.contentWarning = contentWarning;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
public IntentBuilder repyingStatusAuthor(String username) {
|
|
|
|
this.replyingStatusAuthor = username;
|
2017-11-01 20:59:29 +01: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);
|
|
|
|
}
|
|
|
|
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-16 19:18:11 +01:00
|
|
|
intent.putExtra(REPLY_VISIBILITY_EXTRA, replyVisibility.getNum());
|
2017-11-01 20:59:29 +01:00
|
|
|
}
|
2018-08-23 20:50:50 +02:00
|
|
|
if (savedVisibility != null) {
|
|
|
|
intent.putExtra(SAVED_TOOT_VISIBILITY_EXTRA, savedVisibility.getNum());
|
|
|
|
}
|
2017-11-01 20:59:29 +01: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-16 19:18:11 +01:00
|
|
|
intent.putExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA, replyingStatusAuthor);
|
2017-11-01 20:59:29 +01:00
|
|
|
}
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
}
|
2017-01-07 23:24:02 +01:00
|
|
|
}
|