fixed push notification, fixed language selector, layout fix

This commit is contained in:
nuclearfog 2023-06-08 15:55:52 +02:00
parent ae2bfc02b4
commit 367366ee78
No known key found for this signature in database
GPG Key ID: 03488A185C476379
10 changed files with 44 additions and 40 deletions

View File

@ -650,7 +650,7 @@ public class Mastodon implements Connection {
params.add("spoiler_text=true");
if (update.getText() != null)
params.add("status=" + StringUtils.encode(update.getText()));
if (update.getLanguageCode() != null)
if (!update.getLanguageCode().isEmpty())
params.add("language=" + update.getLanguageCode());
if (update.getReplyId() != 0)
params.add("in_reply_to_id=" + update.getReplyId());

View File

@ -41,8 +41,8 @@ public class StatusUpdate implements Serializable, Closeable {
private boolean sensitive = false;
private boolean spoiler = false;
private int visibility = Status.VISIBLE_PUBLIC;
private String languageCode = "";
private String text;
private String languageCode;
// attachment attributes
private List<MediaStatus> mediaStatuses = new ArrayList<>(5);
@ -52,10 +52,10 @@ public class StatusUpdate implements Serializable, Closeable {
private LocationUpdate location;
// helper attributes
@Nullable
private Instance instance;
private TreeSet<String> supportedFormats = new TreeSet<>();
private boolean attachmentLimitReached = false;
@Nullable
private Instance instance;
/**
* close all open streams
@ -118,9 +118,9 @@ public class StatusUpdate implements Serializable, Closeable {
/**
* add status language
*
* @param languageCode ISO 639 language code
* @param languageCode ISO 639 language code or empty string to remove language
*/
public void addLanguage(String languageCode) {
public void addLanguage(@NonNull String languageCode) {
this.languageCode = languageCode;
}
@ -269,7 +269,7 @@ public class StatusUpdate implements Serializable, Closeable {
*
* @return ISO 639 language code
*/
@Nullable
@NonNull
public String getLanguageCode() {
return languageCode;
}

View File

@ -11,7 +11,6 @@ import org.nuclearfog.twidda.backend.async.NotificationLoader.NotificationLoader
import org.nuclearfog.twidda.backend.async.PushUpdater;
import org.nuclearfog.twidda.backend.helper.update.PushUpdate;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.unifiedpush.android.connector.ConstantsKt;
import org.unifiedpush.android.connector.MessagingReceiver;
/**
@ -38,13 +37,8 @@ public class PushNotificationReceiver extends MessagingReceiver implements Async
@Override
public void onNewEndpoint(@NonNull Context context, @NonNull String endpoint, @NonNull String instance) {
PushUpdate update;
GlobalSettings settings = GlobalSettings.getInstance(context);
if (instance.equals(ConstantsKt.INSTANCE_DEFAULT)) {
update = new PushUpdate(settings.getWebPush(), endpoint);
} else {
update = new PushUpdate(settings.getWebPush(), instance);
}
PushUpdate update = new PushUpdate(settings.getWebPush(), endpoint);
PushUpdater pushUpdater = new PushUpdater(context);
pushUpdater.execute(update, null);
}

View File

@ -22,6 +22,7 @@ public class PushSubscription {
public static void subscripe(Context context) {
GlobalSettings settings = GlobalSettings.getInstance(context);
if (settings.isLoggedIn() && settings.getLogin().getConfiguration().isWebpushSupported()) {
try {
ArrayList<String> features = new ArrayList<>(1);
features.add(UnifiedPush.FEATURE_BYTES_MESSAGE);
if (!settings.getWebPush().getHost().isEmpty()) {
@ -29,6 +30,9 @@ public class PushSubscription {
} else {
UnifiedPush.registerAppWithDialog(context, ConstantsKt.INSTANCE_DEFAULT, new RegistrationDialogContent(), features, "");
}
} catch (RuntimeException exception) {
// thrown when ntfy-app was not found
}
}
}
@ -38,7 +42,11 @@ public class PushSubscription {
public static void unsubscripe(Context context) {
GlobalSettings settings = GlobalSettings.getInstance(context);
if (settings.isLoggedIn() && settings.getLogin().getConfiguration().isWebpushSupported() && settings.pushEnabled()) {
try {
UnifiedPush.unregisterApp(context.getApplicationContext(), settings.getWebPush().getHost());
} catch (RuntimeException exception) {
// thrown when ntfy-app was not found
}
}
}
}

View File

@ -20,6 +20,8 @@ import org.nuclearfog.twidda.model.Status;
import org.nuclearfog.twidda.ui.adapter.DropdownAdapter;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
/**
* status editor preference dialog used to set additional status information
@ -32,7 +34,7 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
private StatusUpdate statusUpdate;
private Locale[] languages;
private String[] languageCodes;
/**
* @param statusUpdate status information from status editor
@ -59,14 +61,18 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
visibilitySelector.setSelection(0, false);
visibilitySelector.setSelected(false);
languages = Locale.getAvailableLocales();
String[] language_names = new String[languages.length + 1];
language_names[0] = context.getString(R.string.dialog_status_language_empty);
for (int i = 0; i < languages.length; i++) {
language_names[i + 1] = languages[i].getDisplayLanguage() + " " + languages[i].getCountry();
// initialize language selector
Map<String, String> languages = new TreeMap<>();
languages.put("", "");
Locale[] locales = Locale.getAvailableLocales();
for (Locale locale : locales) {
languages.put(locale.getDisplayLanguage(), locale.getLanguage());
}
language_adapter.setItems(language_names);
languageCodes = languages.values().toArray(new String[0]);
String[] languageNames = languages.keySet().toArray(new String[0]);
language_adapter.setItems(languageNames);
// enable/disable functions
if (!settings.getLogin().getConfiguration().statusVisibilitySupported()) {
statusVisibility.setVisibility(View.GONE);
}
@ -138,8 +144,7 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
}
} else if (parent.getId() == R.id.dialog_status_language) {
if (position > 0) {
Locale language = languages[position - 1];
statusUpdate.addLanguage(language.getLanguage());
statusUpdate.addLanguage(languageCodes[position]);
}
}
}

View File

@ -12,6 +12,7 @@
android:layout_height="wrap_content"
android:text="@string/dialog_push_title"
android:textSize="@dimen/dialog_push_title_textsize"
android:lines="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

View File

@ -7,7 +7,6 @@
android:id="@+id/dropdown_textitem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dropdown_layout_margin"
android:padding="@dimen/dropdown_padding"
android:maxLines="2"
android:textSize="@dimen/dropdown_text_size"

View File

@ -313,7 +313,7 @@
<string name="dialog_push_edit_status">bei Statusänderungen</string>
<string name="dialog_push_new_follower">bei neuen Followern</string>
<string name="dialog_push_follow_request">bei neuen Follow-Anfragen</string>
<string name="dialog_push_title">Pushbenachrichtigungen</string>
<string name="dialog_push_title">Benachrichtigunen</string>
<string name="dialog_push_apply">Änderungen anwenden</string>
<string name="settings_enable_push_label">aktiviere Push-Benachrichtigung\n(ntfy-App erforderlich)</string>
<string name="notification_favorite">%1$s hat einen Status favorisiert</string>
@ -326,5 +326,4 @@
<string name="notification_mention">%1$s hat dich erwähnt</string>
<string name="notification_new">Neue Benachrichtigungen</string>
<string name="dialog_status_language">Sprache</string>
<string name="dialog_status_language_empty">keine Auswahl</string>
</resources>

View File

@ -183,9 +183,8 @@
<dimen name="loaditem_button_size">36sp</dimen>
<!-- dimens of item_dropdown-->
<dimen name="dropdown_padding">2dp</dimen>
<dimen name="dropdown_layout_margin">2dp</dimen>
<dimen name="dropdown_text_size">16sp</dimen>
<dimen name="dropdown_padding">4dp</dimen>
<dimen name="dropdown_text_size">14sp</dimen>
<!--dimens of page_media.xml-->
<dimen name="mediapage_toolbar_height">@dimen/toolbar_height</dimen>
@ -300,7 +299,7 @@
<dimen name="dialog_status_textsize_small">11sp</dimen>
<dimen name="dialog_status_layout_padding">10dp</dimen>
<dimen name="dialog_status_layout_margins">5dp</dimen>
<dimen name="dialog_status_dropdown_height">22sp</dimen>
<dimen name="dialog_status_dropdown_height">28sp</dimen>
<!--dimens of dialog_audio_player.xml-->
<dimen name="dialog_audio_player_drawable_padding">5dp</dimen>
@ -324,7 +323,7 @@
<dimen name="item_domain_button_padding">7dp</dimen>
<!--dimens of dialog_push-->
<dimen name="dialog_push_title_textsize">22sp</dimen>
<dimen name="dialog_push_title_textsize">20sp</dimen>
<dimen name="dialog_push_label_textsize">11sp</dimen>
<dimen name="dialog_push_button_height">28sp</dimen>
<dimen name="dialog_push_button_padding">5dp</dimen>

View File

@ -329,7 +329,6 @@
<string name="dialog_status_spoiler">mark content as spoiler</string>
<string name="dialog_status_visibility">Visibility</string>
<string name="dialog_status_language">Language</string>
<string name="dialog_status_language_empty">nothing selected</string>
<string name="dialog_push_repost">on repost</string>
<string name="dialog_push_favorite">on favorite</string>
<string name="dialog_push_mention">on mention</string>
@ -338,7 +337,7 @@
<string name="dialog_push_edit_status">on status edit</string>
<string name="dialog_push_new_follower">new follower</string>
<string name="dialog_push_follow_request">on follow request</string>
<string name="dialog_push_title">Push notifications</string>
<string name="dialog_push_title">Notifications</string>
<string name="dialog_push_apply">apply changes</string>
<string name="settings_enable_push_label">enable push notification\n(requires ntfy app)</string>
<string name="notification_favorite">%1$s favorited your status</string>