This commit is contained in:
nuclearfog 2023-05-31 21:51:16 +02:00
parent b633e51967
commit a128002298
No known key found for this signature in database
GPG Key ID: 03488A185C476379
7 changed files with 25 additions and 16 deletions

View File

@ -12,10 +12,8 @@
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" tools:ignore="ScopedStorage" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application <application
android:name=".ClientApplication" android:name=".ClientApplication"

View File

@ -9,6 +9,7 @@ import org.nuclearfog.twidda.backend.api.Connection;
import org.nuclearfog.twidda.backend.api.ConnectionException; import org.nuclearfog.twidda.backend.api.ConnectionException;
import org.nuclearfog.twidda.backend.api.ConnectionManager; import org.nuclearfog.twidda.backend.api.ConnectionManager;
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.model.WebPush; import org.nuclearfog.twidda.model.WebPush;
/** /**
@ -19,12 +20,14 @@ import org.nuclearfog.twidda.model.WebPush;
public class PushUpdater extends AsyncExecutor <PushUpdate, PushUpdater.PushUpdateResult> { public class PushUpdater extends AsyncExecutor <PushUpdate, PushUpdater.PushUpdateResult> {
private Connection connection; private Connection connection;
private GlobalSettings settings;
/** /**
* *
*/ */
public PushUpdater(Context context) { public PushUpdater(Context context) {
connection = ConnectionManager.getDefaultConnection(context); connection = ConnectionManager.getDefaultConnection(context);
settings = GlobalSettings.getInstance(context);
} }
@ -32,6 +35,7 @@ public class PushUpdater extends AsyncExecutor <PushUpdate, PushUpdater.PushUpda
protected PushUpdateResult doInBackground(@NonNull PushUpdate param) { protected PushUpdateResult doInBackground(@NonNull PushUpdate param) {
try { try {
WebPush webpush = connection.updatePush(param); WebPush webpush = connection.updatePush(param);
settings.setWebPush(webpush);
return new PushUpdateResult(webpush, null); return new PushUpdateResult(webpush, null);
} catch (ConnectionException e) { } catch (ConnectionException e) {
return new PushUpdateResult(null, e); return new PushUpdateResult(null, e);

View File

@ -139,7 +139,6 @@ public class GlobalSettings {
private static final int DEFAULT_FW_ICON_COLOR = Color.CYAN; private static final int DEFAULT_FW_ICON_COLOR = Color.CYAN;
private static final long DEFAULT_LOCATION_ID = 1L; private static final long DEFAULT_LOCATION_ID = 1L;
private static final String DEFAULT_LOCATION_NAME = "Worldwide"; private static final String DEFAULT_LOCATION_NAME = "Worldwide";
private static final String DEFAULT_UNIFYPUSH_HOST = "https://ntfy.sh";
private SharedPreferences settings; private SharedPreferences settings;
@ -590,6 +589,14 @@ public class GlobalSettings {
edit.putString(PUSH_PUBLIC_KEY, webPush.getPublicKey()); edit.putString(PUSH_PUBLIC_KEY, webPush.getPublicKey());
edit.putString(PUSH_PRIVATE_KEY, webPush.getPrivateKey()); edit.putString(PUSH_PRIVATE_KEY, webPush.getPrivateKey());
edit.putString(PUSH_AUTH_KEY, webPush.getAuthSecret()); edit.putString(PUSH_AUTH_KEY, webPush.getAuthSecret());
edit.putBoolean(PUSH_ALERT_MENTION, webPush.alertMentionEnabled());
edit.putBoolean(PUSH_ALERT_REPOST, webPush.alertRepostEnabled());
edit.putBoolean(PUSH_ALERT_FAVORITE, webPush.alertFavoriteEnabled());
edit.putBoolean(PUSH_ALERT_FOLLOWING, webPush.alertFollowingEnabled());
edit.putBoolean(PUSH_ALERT_REQUEST_FOLLOW, webPush.alertFollowRequestEnabled());
edit.putBoolean(PUSH_ALERT_STATUS_POST, webPush.alertStatusPostEnabled());
edit.putBoolean(PUSH_ALERT_STATUS_EDIT, webPush.alertStatusChangeEnabled());
edit.putBoolean(PUSH_ALERT_POLL, webPush.alertPollEnabled());
edit.apply(); edit.apply();
} }
@ -1065,7 +1072,7 @@ public class GlobalSettings {
private void initWebpush() { private void initWebpush() {
long pushID = settings.getLong(PUSH_ID, 0L); long pushID = settings.getLong(PUSH_ID, 0L);
String pushServerKey = settings.getString(PUSH_SERVER_KEY, ""); String pushServerKey = settings.getString(PUSH_SERVER_KEY, "");
String pushServerHost = settings.getString(PUSH_SERVER_HOST, DEFAULT_UNIFYPUSH_HOST); String pushServerHost = settings.getString(PUSH_SERVER_HOST, "");
String pushPublicKey = settings.getString(PUSH_PUBLIC_KEY, ""); String pushPublicKey = settings.getString(PUSH_PUBLIC_KEY, "");
String pushPrivateKey = settings.getString(PUSH_PRIVATE_KEY, ""); String pushPrivateKey = settings.getString(PUSH_PRIVATE_KEY, "");
String pushAuthKey = settings.getString(PUSH_AUTH_KEY, ""); String pushAuthKey = settings.getString(PUSH_AUTH_KEY, "");

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,11 +37,9 @@ 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) {
if (instance.equals(ConstantsKt.INSTANCE_DEFAULT)) { PushUpdater pushUpdater = new PushUpdater(context);
PushUpdater pushUpdater = new PushUpdater(context); PushUpdate update = new PushUpdate(endpoint);
PushUpdate update = new PushUpdate(endpoint); pushUpdater.execute(update, null);
pushUpdater.execute(update, null);
}
} }

View File

@ -4,6 +4,7 @@ import android.content.Context;
import org.nuclearfog.twidda.config.GlobalSettings; import org.nuclearfog.twidda.config.GlobalSettings;
import org.unifiedpush.android.connector.ConstantsKt; import org.unifiedpush.android.connector.ConstantsKt;
import org.unifiedpush.android.connector.RegistrationDialogContent;
import org.unifiedpush.android.connector.UnifiedPush; import org.unifiedpush.android.connector.UnifiedPush;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,9 +25,9 @@ public class PushSubscription {
ArrayList<String> features = new ArrayList<>(1); ArrayList<String> features = new ArrayList<>(1);
features.add(UnifiedPush.FEATURE_BYTES_MESSAGE); features.add(UnifiedPush.FEATURE_BYTES_MESSAGE);
if (!settings.getWebPush().getHost().isEmpty()) { if (!settings.getWebPush().getHost().isEmpty()) {
UnifiedPush.registerApp(context.getApplicationContext(), settings.getWebPush().getHost(), features, ""); UnifiedPush.registerAppWithDialog(context, settings.getWebPush().getHost(), new RegistrationDialogContent(), features, "");
} else { } else {
UnifiedPush.registerApp(context.getApplicationContext(), ConstantsKt.INSTANCE_DEFAULT, features, ""); UnifiedPush.registerAppWithDialog(context, ConstantsKt.INSTANCE_DEFAULT, new RegistrationDialogContent(), features, "");
} }
} }
} }
@ -40,4 +41,4 @@ public class PushSubscription {
UnifiedPush.unregisterApp(context.getApplicationContext(), settings.getWebPush().getHost()); UnifiedPush.unregisterApp(context.getApplicationContext(), settings.getWebPush().getHost());
} }
} }
} }

View File

@ -35,7 +35,6 @@ import org.nuclearfog.twidda.model.WebPush;
public class WebPushDialog extends Dialog implements OnCheckedChangeListener, OnClickListener, OnItemSelectedListener, AsyncCallback<PushUpdateResult> { public class WebPushDialog extends Dialog implements OnCheckedChangeListener, OnClickListener, OnItemSelectedListener, AsyncCallback<PushUpdateResult> {
private PushUpdater updater; private PushUpdater updater;
private GlobalSettings settings;
private PushUpdate update; private PushUpdate update;
@ -57,7 +56,7 @@ public class WebPushDialog extends Dialog implements OnCheckedChangeListener, On
Button apply_changes = findViewById(R.id.dialog_push_apply); Button apply_changes = findViewById(R.id.dialog_push_apply);
Spinner policySelector = findViewById(R.id.dialog_push_policy); Spinner policySelector = findViewById(R.id.dialog_push_policy);
settings = GlobalSettings.getInstance(context); GlobalSettings settings = GlobalSettings.getInstance(context);
updater = new PushUpdater(context); updater = new PushUpdater(context);
update = new PushUpdate(settings.getWebPush()); update = new PushUpdate(settings.getWebPush());
mention.setCheckedImmediately(update.mentionsEnabled()); mention.setCheckedImmediately(update.mentionsEnabled());
@ -167,7 +166,6 @@ public class WebPushDialog extends Dialog implements OnCheckedChangeListener, On
public void onResult(@NonNull PushUpdateResult result) { public void onResult(@NonNull PushUpdateResult result) {
if (result.push != null) { if (result.push != null) {
Toast.makeText(getContext(), R.string.info_webpush_update, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.info_webpush_update, Toast.LENGTH_SHORT).show();
settings.setWebPush(result.push);
dismiss(); dismiss();
} }
} }

View File

@ -18,6 +18,7 @@ import org.nuclearfog.twidda.backend.async.DatabaseAction.DatabaseResult;
import org.nuclearfog.twidda.config.GlobalSettings; import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.lists.Accounts; import org.nuclearfog.twidda.model.lists.Accounts;
import org.nuclearfog.twidda.model.Account; import org.nuclearfog.twidda.model.Account;
import org.nuclearfog.twidda.notification.PushSubscription;
import org.nuclearfog.twidda.ui.activities.AccountActivity; import org.nuclearfog.twidda.ui.activities.AccountActivity;
import org.nuclearfog.twidda.ui.adapter.AccountAdapter; import org.nuclearfog.twidda.ui.adapter.AccountAdapter;
import org.nuclearfog.twidda.ui.adapter.AccountAdapter.OnAccountClickListener; import org.nuclearfog.twidda.ui.adapter.AccountAdapter.OnAccountClickListener;
@ -106,6 +107,9 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
public void onAccountClick(Account account) { public void onAccountClick(Account account) {
settings.setLogin(account, true); settings.setLogin(account, true);
databaseAction.execute(new DatabaseParam(DatabaseParam.DELETE), databaseResult); databaseAction.execute(new DatabaseParam(DatabaseParam.DELETE), databaseResult);
if (settings.pushEnabled()) {
PushSubscription.subscripe(requireContext());
}
if (account.getUser() != null) { if (account.getUser() != null) {
String message = getString(R.string.info_account_selected, account.getUser().getScreenname()); String message = getString(R.string.info_account_selected, account.getUser().getScreenname());
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show(); Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();