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"); params.add("spoiler_text=true");
if (update.getText() != null) if (update.getText() != null)
params.add("status=" + StringUtils.encode(update.getText())); params.add("status=" + StringUtils.encode(update.getText()));
if (update.getLanguageCode() != null) if (!update.getLanguageCode().isEmpty())
params.add("language=" + update.getLanguageCode()); params.add("language=" + update.getLanguageCode());
if (update.getReplyId() != 0) if (update.getReplyId() != 0)
params.add("in_reply_to_id=" + update.getReplyId()); 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 sensitive = false;
private boolean spoiler = false; private boolean spoiler = false;
private int visibility = Status.VISIBLE_PUBLIC; private int visibility = Status.VISIBLE_PUBLIC;
private String languageCode = "";
private String text; private String text;
private String languageCode;
// attachment attributes // attachment attributes
private List<MediaStatus> mediaStatuses = new ArrayList<>(5); private List<MediaStatus> mediaStatuses = new ArrayList<>(5);
@ -52,10 +52,10 @@ public class StatusUpdate implements Serializable, Closeable {
private LocationUpdate location; private LocationUpdate location;
// helper attributes // helper attributes
@Nullable
private Instance instance;
private TreeSet<String> supportedFormats = new TreeSet<>(); private TreeSet<String> supportedFormats = new TreeSet<>();
private boolean attachmentLimitReached = false; private boolean attachmentLimitReached = false;
@Nullable
private Instance instance;
/** /**
* close all open streams * close all open streams
@ -118,9 +118,9 @@ public class StatusUpdate implements Serializable, Closeable {
/** /**
* add status language * 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; this.languageCode = languageCode;
} }
@ -269,7 +269,7 @@ public class StatusUpdate implements Serializable, Closeable {
* *
* @return ISO 639 language code * @return ISO 639 language code
*/ */
@Nullable @NonNull
public String getLanguageCode() { public String getLanguageCode() {
return languageCode; 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.async.PushUpdater;
import org.nuclearfog.twidda.backend.helper.update.PushUpdate; import org.nuclearfog.twidda.backend.helper.update.PushUpdate;
import org.nuclearfog.twidda.config.GlobalSettings; import org.nuclearfog.twidda.config.GlobalSettings;
import org.unifiedpush.android.connector.ConstantsKt;
import org.unifiedpush.android.connector.MessagingReceiver; import org.unifiedpush.android.connector.MessagingReceiver;
/** /**
@ -38,13 +37,8 @@ public class PushNotificationReceiver extends MessagingReceiver implements Async
@Override @Override
public void onNewEndpoint(@NonNull Context context, @NonNull String endpoint, @NonNull String instance) { public void onNewEndpoint(@NonNull Context context, @NonNull String endpoint, @NonNull String instance) {
PushUpdate update;
GlobalSettings settings = GlobalSettings.getInstance(context); GlobalSettings settings = GlobalSettings.getInstance(context);
if (instance.equals(ConstantsKt.INSTANCE_DEFAULT)) { PushUpdate update = new PushUpdate(settings.getWebPush(), endpoint);
update = new PushUpdate(settings.getWebPush(), endpoint);
} else {
update = new PushUpdate(settings.getWebPush(), instance);
}
PushUpdater pushUpdater = new PushUpdater(context); PushUpdater pushUpdater = new PushUpdater(context);
pushUpdater.execute(update, null); pushUpdater.execute(update, null);
} }

View File

@ -22,12 +22,16 @@ public class PushSubscription {
public static void subscripe(Context context) { public static void subscripe(Context context) {
GlobalSettings settings = GlobalSettings.getInstance(context); GlobalSettings settings = GlobalSettings.getInstance(context);
if (settings.isLoggedIn() && settings.getLogin().getConfiguration().isWebpushSupported()) { if (settings.isLoggedIn() && settings.getLogin().getConfiguration().isWebpushSupported()) {
ArrayList<String> features = new ArrayList<>(1); try {
features.add(UnifiedPush.FEATURE_BYTES_MESSAGE); ArrayList<String> features = new ArrayList<>(1);
if (!settings.getWebPush().getHost().isEmpty()) { features.add(UnifiedPush.FEATURE_BYTES_MESSAGE);
UnifiedPush.registerAppWithDialog(context, settings.getWebPush().getHost(), new RegistrationDialogContent(), features, ""); if (!settings.getWebPush().getHost().isEmpty()) {
} else { UnifiedPush.registerAppWithDialog(context, settings.getWebPush().getHost(), new RegistrationDialogContent(), features, "");
UnifiedPush.registerAppWithDialog(context, ConstantsKt.INSTANCE_DEFAULT, new RegistrationDialogContent(), features, ""); } 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) { public static void unsubscripe(Context context) {
GlobalSettings settings = GlobalSettings.getInstance(context); GlobalSettings settings = GlobalSettings.getInstance(context);
if (settings.isLoggedIn() && settings.getLogin().getConfiguration().isWebpushSupported() && settings.pushEnabled()) { if (settings.isLoggedIn() && settings.getLogin().getConfiguration().isWebpushSupported() && settings.pushEnabled()) {
UnifiedPush.unregisterApp(context.getApplicationContext(), settings.getWebPush().getHost()); 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 org.nuclearfog.twidda.ui.adapter.DropdownAdapter;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
/** /**
* status editor preference dialog used to set additional status information * 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 StatusUpdate statusUpdate;
private Locale[] languages; private String[] languageCodes;
/** /**
* @param statusUpdate status information from status editor * @param statusUpdate status information from status editor
@ -59,14 +61,18 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
visibilitySelector.setSelection(0, false); visibilitySelector.setSelection(0, false);
visibilitySelector.setSelected(false); visibilitySelector.setSelected(false);
languages = Locale.getAvailableLocales(); // initialize language selector
String[] language_names = new String[languages.length + 1]; Map<String, String> languages = new TreeMap<>();
language_names[0] = context.getString(R.string.dialog_status_language_empty); languages.put("", "");
for (int i = 0; i < languages.length; i++) { Locale[] locales = Locale.getAvailableLocales();
language_names[i + 1] = languages[i].getDisplayLanguage() + " " + languages[i].getCountry(); 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()) { if (!settings.getLogin().getConfiguration().statusVisibilitySupported()) {
statusVisibility.setVisibility(View.GONE); statusVisibility.setVisibility(View.GONE);
} }
@ -138,8 +144,7 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
} }
} else if (parent.getId() == R.id.dialog_status_language) { } else if (parent.getId() == R.id.dialog_status_language) {
if (position > 0) { if (position > 0) {
Locale language = languages[position - 1]; statusUpdate.addLanguage(languageCodes[position]);
statusUpdate.addLanguage(language.getLanguage());
} }
} }
} }

View File

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

View File

@ -7,7 +7,6 @@
android:id="@+id/dropdown_textitem" android:id="@+id/dropdown_textitem"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dropdown_layout_margin"
android:padding="@dimen/dropdown_padding" android:padding="@dimen/dropdown_padding"
android:maxLines="2" android:maxLines="2"
android:textSize="@dimen/dropdown_text_size" 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_edit_status">bei Statusänderungen</string>
<string name="dialog_push_new_follower">bei neuen Followern</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_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="dialog_push_apply">Änderungen anwenden</string>
<string name="settings_enable_push_label">aktiviere Push-Benachrichtigung\n(ntfy-App erforderlich)</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> <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_mention">%1$s hat dich erwähnt</string>
<string name="notification_new">Neue Benachrichtigungen</string> <string name="notification_new">Neue Benachrichtigungen</string>
<string name="dialog_status_language">Sprache</string> <string name="dialog_status_language">Sprache</string>
<string name="dialog_status_language_empty">keine Auswahl</string>
</resources> </resources>

View File

@ -183,9 +183,8 @@
<dimen name="loaditem_button_size">36sp</dimen> <dimen name="loaditem_button_size">36sp</dimen>
<!-- dimens of item_dropdown--> <!-- dimens of item_dropdown-->
<dimen name="dropdown_padding">2dp</dimen> <dimen name="dropdown_padding">4dp</dimen>
<dimen name="dropdown_layout_margin">2dp</dimen> <dimen name="dropdown_text_size">14sp</dimen>
<dimen name="dropdown_text_size">16sp</dimen>
<!--dimens of page_media.xml--> <!--dimens of page_media.xml-->
<dimen name="mediapage_toolbar_height">@dimen/toolbar_height</dimen> <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_textsize_small">11sp</dimen>
<dimen name="dialog_status_layout_padding">10dp</dimen> <dimen name="dialog_status_layout_padding">10dp</dimen>
<dimen name="dialog_status_layout_margins">5dp</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--> <!--dimens of dialog_audio_player.xml-->
<dimen name="dialog_audio_player_drawable_padding">5dp</dimen> <dimen name="dialog_audio_player_drawable_padding">5dp</dimen>
@ -324,7 +323,7 @@
<dimen name="item_domain_button_padding">7dp</dimen> <dimen name="item_domain_button_padding">7dp</dimen>
<!--dimens of dialog_push--> <!--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_label_textsize">11sp</dimen>
<dimen name="dialog_push_button_height">28sp</dimen> <dimen name="dialog_push_button_height">28sp</dimen>
<dimen name="dialog_push_button_padding">5dp</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_spoiler">mark content as spoiler</string>
<string name="dialog_status_visibility">Visibility</string> <string name="dialog_status_visibility">Visibility</string>
<string name="dialog_status_language">Language</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_repost">on repost</string>
<string name="dialog_push_favorite">on favorite</string> <string name="dialog_push_favorite">on favorite</string>
<string name="dialog_push_mention">on mention</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_edit_status">on status edit</string>
<string name="dialog_push_new_follower">new follower</string> <string name="dialog_push_new_follower">new follower</string>
<string name="dialog_push_follow_request">on follow request</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="dialog_push_apply">apply changes</string>
<string name="settings_enable_push_label">enable push notification\n(requires ntfy app)</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> <string name="notification_favorite">%1$s favorited your status</string>