Search in sources :

Example 6 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by tuskyapp.

the class ComposeActivity method makeCaptionDialog.

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);
    Picasso.with(this).load(item.uri).into(imageView);
    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);
    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();
                    dialog.dismiss();
                } else {
                    showFailedCaptionMessage();
                }
            }

            @Override
            public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
                showFailedCaptionMessage();
            }
        });
    };
    AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogLayout).setPositiveButton(android.R.string.ok, okListener).setNegativeButton(android.R.string.cancel, null).create();
    Window window = dialog.getWindow();
    if (window != null) {
        // noinspection ConstantConditions
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
    dialog.show();
}
Also used : EditText(android.widget.EditText) TootDao(com.keylesspalace.tusky.db.TootDao) Bundle(android.os.Bundle) TypeToken(com.google.gson.reflect.TypeToken) ProgressBar(android.widget.ProgressBar) Uri(android.net.Uri) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) CountUpDownLatch(com.keylesspalace.tusky.util.CountUpDownLatch) Manifest(android.Manifest) MediaStore(android.provider.MediaStore) PopupMenu(android.widget.PopupMenu) AttrRes(android.support.annotation.AttrRes) IOUtils(com.keylesspalace.tusky.util.IOUtils) Log(android.util.Log) MediaType(okhttp3.MediaType) ContextCompat(android.support.v4.content.ContextCompat) MediaUtils(com.keylesspalace.tusky.util.MediaUtils) EditTextTyped(com.keylesspalace.tusky.view.EditTextTyped) ActivityCompat(android.support.v4.app.ActivityCompat) MultipartBody(okhttp3.MultipartBody) Attachment(com.keylesspalace.tusky.entity.Attachment) Snackbar(android.support.design.widget.Snackbar) TextWatcher(android.text.TextWatcher) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Environment(android.os.Environment) SimpleDateFormat(java.text.SimpleDateFormat) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Response(retrofit2.Response) Parcel(android.os.Parcel) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) MentionAutoCompleteAdapter(com.keylesspalace.tusky.adapter.MentionAutoCompleteAdapter) Toast(android.widget.Toast) SpanUtils(com.keylesspalace.tusky.util.SpanUtils) Parcelable(android.os.Parcelable) URLSpan(android.text.style.URLSpan) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) ProgressDialog(android.app.ProgressDialog) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) IOException(java.io.IOException) AppCompatResources(android.support.v7.content.res.AppCompatResources) File(java.io.File) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Callback(retrofit2.Callback) Toolbar(android.support.v7.widget.Toolbar) MastodonApi(com.keylesspalace.tusky.network.MastodonApi) AccountManager(com.keylesspalace.tusky.db.AccountManager) Injectable(com.keylesspalace.tusky.di.Injectable) EditText(android.widget.EditText) ImageButton(android.widget.ImageButton) Utils(com.varunest.sparkbutton.helpers.Utils) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) Px(android.support.annotation.Px) Date(java.util.Date) WindowManager(android.view.WindowManager) FileProvider(android.support.v4.content.FileProvider) Picasso(com.squareup.picasso.Picasso) ContentResolver(android.content.ContentResolver) Gson(com.google.gson.Gson) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) Account(com.keylesspalace.tusky.entity.Account) PreferenceManager(android.preference.PreferenceManager) AsyncTask(android.os.AsyncTask) Collection(java.util.Collection) InputType(android.text.InputType) FileNotFoundException(java.io.FileNotFoundException) ProgressRequestBody(com.keylesspalace.tusky.network.ProgressRequestBody) MentionTokenizer(com.keylesspalace.tusky.util.MentionTokenizer) List(java.util.List) TextView(android.widget.TextView) ProgressImageView(com.keylesspalace.tusky.view.ProgressImageView) RoundedTransformation(com.keylesspalace.tusky.view.RoundedTransformation) Nullable(android.support.annotation.Nullable) Window(android.view.Window) Call(retrofit2.Call) AssetFileDescriptor(android.content.res.AssetFileDescriptor) Context(android.content.Context) Spanned(android.text.Spanned) TootEntity(com.keylesspalace.tusky.db.TootEntity) Status(com.keylesspalace.tusky.entity.Status) Intent(android.content.Intent) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) Build(android.os.Build) ActionBar(android.support.v7.app.ActionBar) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) DialogInterface(android.content.DialogInterface) Iterator(java.util.Iterator) StringUtils(com.keylesspalace.tusky.util.StringUtils) ComposeOptionsFragment(com.keylesspalace.tusky.fragment.ComposeOptionsFragment) InputConnectionCompat(android.support.v13.view.inputmethod.InputConnectionCompat) Bitmap(android.graphics.Bitmap) ListUtils(com.keylesspalace.tusky.util.ListUtils) DownsizeImageTask(com.keylesspalace.tusky.util.DownsizeImageTask) MimeTypeMap(android.webkit.MimeTypeMap) Resources(android.content.res.Resources) InputStream(java.io.InputStream) AlertDialog(android.support.v7.app.AlertDialog) Window(android.view.Window) Call(retrofit2.Call) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) Attachment(com.keylesspalace.tusky.entity.Attachment) SuppressLint(android.annotation.SuppressLint) Response(retrofit2.Response) Callback(retrofit2.Callback) NonNull(android.support.annotation.NonNull) ImageView(android.widget.ImageView) ProgressImageView(com.keylesspalace.tusky.view.ProgressImageView) LinearLayout(android.widget.LinearLayout)

Example 7 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by tuskyapp.

the class ComposeActivity method uploadMedia.

private void uploadMedia(final QueuedMedia item) {
    item.readyStage = QueuedMedia.ReadyStage.UPLOADING;
    String mimeType = getContentResolver().getType(item.uri);
    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()), StringUtils.randomAlphanumericString(10), fileExtension);
    byte[] content = item.content;
    if (content == null) {
        InputStream stream;
        try {
            stream = getContentResolver().openInputStream(item.uri);
        } catch (FileNotFoundException e) {
            Log.d(TAG, Log.getStackTraceString(e));
            return;
        }
        content = MediaUtils.inputStreamGetBytes(stream);
        IOUtils.closeQuietly(stream);
        if (content == null) {
            return;
        }
    }
    if (mimeType == null)
        mimeType = "multipart/form-data";
    item.preview.setProgress(0);
    ProgressRequestBody fileBody = new ProgressRequestBody(content, MediaType.parse(mimeType), // If request body logging is enabled, pass true
    false, new // may reference activity longer than I would like to
    ProgressRequestBody.UploadCallback() {

        int lastProgress = -1;

        @Override
        public void onProgressUpdate(final int percentage) {
            if (percentage != lastProgress) {
                runOnUiThread(() -> item.preview.setProgress(percentage));
            }
            lastProgress = percentage;
        }
    });
    MultipartBody.Part body = MultipartBody.Part.createFormData("file", filename, fileBody);
    item.uploadRequest = mastodonApi.uploadMedia(body);
    item.uploadRequest.enqueue(new Callback<Attachment>() {

        @Override
        public void onResponse(@NonNull Call<Attachment> call, @NonNull retrofit2.Response<Attachment> response) {
            if (response.isSuccessful()) {
                onUploadSuccess(item, response.body());
            } else {
                Log.d(TAG, "Upload request failed. " + response.message());
                onUploadFailure(item, call.isCanceled());
            }
        }

        @Override
        public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
            Log.d(TAG, "Upload request failed. " + t.getMessage());
            onUploadFailure(item, call.isCanceled());
        }
    });
}
Also used : InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Attachment(com.keylesspalace.tusky.entity.Attachment) MimeTypeMap(android.webkit.MimeTypeMap) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) MultipartBody(okhttp3.MultipartBody) ProgressRequestBody(com.keylesspalace.tusky.network.ProgressRequestBody)

Example 8 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by Vavassor.

the class ConversationViewHolder method setupWithConversation.

void setupWithConversation(ConversationEntity conversation) {
    ConversationStatusEntity status = conversation.getLastStatus();
    ConversationAccountEntity account = status.getAccount();
    setupCollapsedState(status.getCollapsible(), status.getCollapsed(), status.getExpanded(), status.getSpoilerText(), listener);
    setDisplayName(account.getDisplayName(), account.getEmojis(), statusDisplayOptions);
    setUsername(account.getUsername());
    setCreatedAt(status.getCreatedAt(), statusDisplayOptions);
    setIsReply(status.getInReplyToId() != null);
    setFavourited(status.getFavourited());
    setBookmarked(status.getBookmarked());
    List<Attachment> attachments = status.getAttachments();
    boolean sensitive = status.getSensitive();
    if (statusDisplayOptions.mediaPreviewEnabled() && hasPreviewableAttachment(attachments)) {
        setMediaPreviews(attachments, sensitive, listener, status.getShowingHiddenContent(), statusDisplayOptions.useBlurhash());
        if (attachments.size() == 0) {
            hideSensitiveMediaWarning();
        }
        // Hide the unused label.
        for (TextView mediaLabel : mediaLabels) {
            mediaLabel.setVisibility(View.GONE);
        }
    } else {
        setMediaLabel(attachments, sensitive, listener, status.getShowingHiddenContent());
        // Hide all unused views.
        mediaPreviews[0].setVisibility(View.GONE);
        mediaPreviews[1].setVisibility(View.GONE);
        mediaPreviews[2].setVisibility(View.GONE);
        mediaPreviews[3].setVisibility(View.GONE);
        hideSensitiveMediaWarning();
    }
    setupButtons(listener, account.getId(), status.getContent().toString(), statusDisplayOptions);
    setSpoilerAndContent(status.getExpanded(), status.getContent(), status.getSpoilerText(), status.getMentions(), status.getEmojis(), PollViewDataKt.toViewData(status.getPoll()), statusDisplayOptions, listener);
    setConversationName(conversation.getAccounts());
    setAvatars(conversation.getAccounts());
}
Also used : Attachment(com.keylesspalace.tusky.entity.Attachment) TextView(android.widget.TextView)

Example 9 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by Vavassor.

the class SFragment method downloadAllMedia.

private void downloadAllMedia(Status status) {
    Toast.makeText(getContext(), R.string.downloading_media, Toast.LENGTH_SHORT).show();
    for (Attachment attachment : status.getAttachments()) {
        String url = attachment.getUrl();
        Uri uri = Uri.parse(url);
        String filename = uri.getLastPathSegment();
        DownloadManager downloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
        downloadManager.enqueue(request);
    }
}
Also used : Attachment(com.keylesspalace.tusky.entity.Attachment) Uri(android.net.Uri) DownloadManager(android.app.DownloadManager)

Aggregations

Attachment (com.keylesspalace.tusky.entity.Attachment)9 TextView (android.widget.TextView)6 Context (android.content.Context)5 SuppressLint (android.annotation.SuppressLint)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 MimeTypeMap (android.webkit.MimeTypeMap)2 ImageView (android.widget.ImageView)2 ProgressRequestBody (com.keylesspalace.tusky.network.ProgressRequestBody)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 MultipartBody (okhttp3.MultipartBody)2 Manifest (android.Manifest)1 DownloadManager (android.app.DownloadManager)1 ProgressDialog (android.app.ProgressDialog)1 ContentResolver (android.content.ContentResolver)1 DialogInterface (android.content.DialogInterface)1