From cef225e65a9c0f553f2bcc0a91e953e4c67f6c5b Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Sun, 11 Jun 2023 23:30:42 +0200 Subject: [PATCH] bug fix --- .../backend/helper/update/PushUpdate.java | 18 +++++++++ .../twidda/notification/PushNotification.java | 1 - .../twidda/ui/activities/StatusActivity.java | 22 +++++------ .../ui/adapter/holder/PreviewHolder.java | 38 ++++++++++--------- .../twidda/ui/dialogs/WebPushDialog.java | 4 ++ 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/PushUpdate.java b/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/PushUpdate.java index e840d1b2..7c6c1c07 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/PushUpdate.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/helper/update/PushUpdate.java @@ -1,5 +1,7 @@ package org.nuclearfog.twidda.backend.helper.update; +import androidx.annotation.NonNull; + import org.nuclearfog.twidda.model.WebPush; import java.io.Serializable; @@ -61,6 +63,15 @@ public class PushUpdate implements Serializable { return host; } + /** + * set hostname of the push server + * + * @param host hostname url + */ + public void setHost(String host) { + this.host = host; + } + /** * @return true if push-notification for mentions is enabled */ @@ -204,4 +215,11 @@ public class PushUpdate implements Serializable { public void setPolicy(int policy) { this.policy = policy; } + + + @NonNull + @Override + public String toString() { + return "host=\"" + host + "\""; + } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/notification/PushNotification.java b/app/src/main/java/org/nuclearfog/twidda/notification/PushNotification.java index 5d5cf149..b0fc5b31 100644 --- a/app/src/main/java/org/nuclearfog/twidda/notification/PushNotification.java +++ b/app/src/main/java/org/nuclearfog/twidda/notification/PushNotification.java @@ -61,7 +61,6 @@ public class PushNotification { * @param notifications new notifications */ public void createNotification(Notifications notifications) { - // todo update existing notification and prevent recreating notification if (!notifications.isEmpty()) { String title = settings.getLogin().getConfiguration().getName(); String content; diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/activities/StatusActivity.java b/app/src/main/java/org/nuclearfog/twidda/ui/activities/StatusActivity.java index 3f82619f..54272317 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/activities/StatusActivity.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/activities/StatusActivity.java @@ -190,7 +190,7 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener private Status status; @Nullable private Notification notification; - private boolean hidden; + private boolean hidden, translated; @Override @@ -613,7 +613,12 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener } // translate status text else if (v.getId() == R.id.page_status_text_translate) { - if (translationLoader.isIdle()) { + if (translated) { + Spannable spannableText = Tagger.makeTextWithLinks(status.getText(), settings.getHighlightColor(), this); + translate_text.setText(R.string.status_translate_text); + status_text.setText(spannableText); + translated = false; + } else if (translationLoader.isIdle()) { translationLoader.execute(status.getId(), translationResult); } } @@ -779,6 +784,7 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener */ private void setStatus(@NonNull Status status) { this.status = status; + translated = false; if (status.getEmbeddedStatus() != null) { repost_name_button.setVisibility(View.VISIBLE); repost_name_button.setText(status.getAuthor().getScreenname()); @@ -1107,20 +1113,14 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener */ private void onTranslationResult(@NonNull TranslationResult result) { if (result.translation != null) { - if (status_text.getLineCount() > status_text.getMaxLines()) { - int y = status_text.getLayout().getLineTop(status_text.getLineCount()); - status_text.scrollTo(0, y); - } - // build translation string - String text = "\n...\n" + result.translation.getText() + "\n..."; - Spannable textSpan = Tagger.makeTextWithLinks(text, settings.getHighlightColor(), this); + Spannable textSpan = Tagger.makeTextWithLinks(result.translation.getText(), settings.getHighlightColor(), this); // append translation - status_text.append(textSpan); + status_text.setText(textSpan); translate_text.setText(R.string.status_translate_source); translate_text.append(result.translation.getSource() + ", "); translate_text.append(getString(R.string.status_translate_source_language)); translate_text.append(result.translation.getOriginalLanguage()); - translate_text.setOnClickListener(null); // disable link to translation + translated = true; } else { Toast.makeText(getApplicationContext(), R.string.error_translating_status, Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/PreviewHolder.java b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/PreviewHolder.java index 458a1793..2b7ea63d 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/PreviewHolder.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/adapter/holder/PreviewHolder.java @@ -18,7 +18,6 @@ import com.squareup.picasso.RequestCreator; import org.nuclearfog.twidda.R; import org.nuclearfog.twidda.config.GlobalSettings; -import org.nuclearfog.twidda.database.impl.DatabaseMedia; import org.nuclearfog.twidda.model.Media; import jp.wasabeef.picasso.transformations.BlurTransformation; @@ -41,6 +40,8 @@ public class PreviewHolder extends ViewHolder implements OnClickListener { private GlobalSettings settings; private OnHolderClickListener listener; + private Media media; + public PreviewHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso, OnHolderClickListener listener) { super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_preview, parent, false)); @@ -71,23 +72,26 @@ public class PreviewHolder extends ViewHolder implements OnClickListener { * @param media media content */ public void setContent(Media media, boolean blurImage) { - Drawable placeholder = new ColorDrawable(EMPTY_COLOR); - if (!(media instanceof DatabaseMedia) && settings.imagesEnabled() && media.getMediaType() != Media.AUDIO - && media.getMediaType() != Media.UNDEFINED && !media.getPreviewUrl().trim().isEmpty()) { - RequestCreator picassoBuilder = picasso.load(media.getPreviewUrl()); - if (blurImage) { - BlurTransformation blurTransformation = new BlurTransformation(previewImage.getContext(), 30); - picassoBuilder.transform(blurTransformation); + // skip if same media is already set + if (!media.equals(this.media)) { + Drawable placeholder = new ColorDrawable(EMPTY_COLOR); + if (settings.imagesEnabled() && media.getMediaType() != Media.AUDIO && media.getMediaType() != Media.UNDEFINED && !media.getPreviewUrl().trim().isEmpty()) { + RequestCreator picassoBuilder = picasso.load(media.getPreviewUrl()); + if (blurImage) { + BlurTransformation blurTransformation = new BlurTransformation(previewImage.getContext(), 30); + picassoBuilder.transform(blurTransformation); + } + picassoBuilder.networkPolicy(NetworkPolicy.NO_STORE).memoryPolicy(MemoryPolicy.NO_STORE).placeholder(placeholder).into(previewImage); + } else { + previewImage.setImageDrawable(placeholder); } - picassoBuilder.networkPolicy(NetworkPolicy.NO_STORE).memoryPolicy(MemoryPolicy.NO_STORE).placeholder(placeholder).into(previewImage); - } else { - previewImage.setImageDrawable(placeholder); - } - // set 'play video' button - if (media.getMediaType() == Media.VIDEO || media.getMediaType() == Media.GIF || media.getMediaType() == Media.AUDIO) { - playIcon.setVisibility(View.VISIBLE); - } else { - playIcon.setVisibility(View.GONE); + // set 'play video' button + if (media.getMediaType() == Media.VIDEO || media.getMediaType() == Media.GIF || media.getMediaType() == Media.AUDIO) { + playIcon.setVisibility(View.VISIBLE); + } else { + playIcon.setVisibility(View.GONE); + } + this.media = media; } } } \ No newline at end of file diff --git a/app/src/main/java/org/nuclearfog/twidda/ui/dialogs/WebPushDialog.java b/app/src/main/java/org/nuclearfog/twidda/ui/dialogs/WebPushDialog.java index ced65902..72843819 100644 --- a/app/src/main/java/org/nuclearfog/twidda/ui/dialogs/WebPushDialog.java +++ b/app/src/main/java/org/nuclearfog/twidda/ui/dialogs/WebPushDialog.java @@ -117,6 +117,10 @@ public class WebPushDialog extends Dialog implements OnCheckedChangeListener, On public void onClick(View v) { if (v.getId() == R.id.dialog_push_apply) { if (updater.isIdle()) { + // fix: setting host url if empty + if (update.getHost().isEmpty()) { + update.setHost(settings.getWebPush().getHost()); + } updater.execute(update, this); } }