This commit is contained in:
nuclearfog 2023-06-11 23:30:42 +02:00
parent c7e79999fd
commit cef225e65a
No known key found for this signature in database
GPG Key ID: 03488A185C476379
5 changed files with 54 additions and 29 deletions

View File

@ -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 + "\"";
}
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}