mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-01 04:17:21 +01:00
web push fix, added error message
This commit is contained in:
parent
97213b039e
commit
97b7049519
@ -96,6 +96,11 @@ public abstract class ConnectionException extends Exception {
|
||||
*/
|
||||
public static final int HTTP_FORBIDDEN = 15;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final int INVALID_DATA = 16;
|
||||
|
||||
/**
|
||||
* invalid media (wrong format, size)
|
||||
*/
|
||||
|
@ -79,6 +79,10 @@ public class MastodonException extends ConnectionException {
|
||||
errorCode = HTTP_FORBIDDEN;
|
||||
break;
|
||||
|
||||
case 422:
|
||||
errorCode = INVALID_DATA;
|
||||
break;
|
||||
|
||||
case 429:
|
||||
errorCode = RATE_LIMIT_EX;
|
||||
break;
|
||||
|
@ -16,7 +16,6 @@ import org.nuclearfog.twidda.config.GlobalSettings;
|
||||
import org.nuclearfog.twidda.database.AppDatabase;
|
||||
import org.nuclearfog.twidda.model.Account;
|
||||
import org.nuclearfog.twidda.model.Instance;
|
||||
import org.nuclearfog.twidda.model.WebPush;
|
||||
import org.nuclearfog.twidda.ui.activities.LoginActivity;
|
||||
|
||||
/**
|
||||
@ -67,14 +66,11 @@ public class LoginAction extends AsyncExecutor<LoginAction.Param, LoginAction.Re
|
||||
database.saveLogin(account);
|
||||
// save instance information
|
||||
database.saveInstance(instance);
|
||||
// subscripe to web push
|
||||
// transfer push configuration
|
||||
if (settings.pushEnabled()) {
|
||||
try {
|
||||
PushUpdate pushUpdate = new PushUpdate(settings.getWebPush());
|
||||
WebPush webpush = connection.updatePush(pushUpdate);
|
||||
settings.setWebPush(webpush);
|
||||
} catch (ConnectionException e) {
|
||||
// continue without webpush subscription
|
||||
connection.updatePush(new PushUpdate(settings.getWebPush()));
|
||||
} catch (ConnectionException exception) {
|
||||
settings.setPushEnabled(false);
|
||||
}
|
||||
}
|
||||
|
@ -106,6 +106,9 @@ public class ErrorUtils {
|
||||
case ConnectionException.HTTP_FORBIDDEN:
|
||||
return context.getString(R.string.error_forbidden_api_access);
|
||||
|
||||
case ConnectionException.INVALID_DATA:
|
||||
return context.getString(R.string.error_api_error);
|
||||
|
||||
case ConnectionException.INVALID_MEDIA:
|
||||
return context.getString(R.string.error_invalid_media);
|
||||
|
||||
|
@ -549,6 +549,28 @@ public class GlobalSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if push notification is enabled
|
||||
*
|
||||
* @return true if push notification is enabled
|
||||
*/
|
||||
public boolean pushEnabled() {
|
||||
return push_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* enable/disable push notification
|
||||
*
|
||||
* @param enable true to enable notification
|
||||
*/
|
||||
public void setPushEnabled(boolean enable) {
|
||||
push_enabled = enable;
|
||||
|
||||
Editor edit = settings.edit();
|
||||
edit.putBoolean(PUSH_ENABLED, enable);
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* get used web push instance
|
||||
*/
|
||||
@ -562,8 +584,6 @@ public class GlobalSettings {
|
||||
* @param webPush web push information
|
||||
*/
|
||||
public void setWebPush(WebPush webPush) {
|
||||
this.webPush = new ConfigPush(webPush);
|
||||
|
||||
Editor edit = settings.edit();
|
||||
edit.putLong(PUSH_ID, webPush.getId());
|
||||
edit.putString(PUSH_SERVER_KEY, webPush.getServerKey());
|
||||
@ -582,12 +602,20 @@ public class GlobalSettings {
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get push instance url
|
||||
*
|
||||
* @return instance url
|
||||
*/
|
||||
public String getPushInstance() {
|
||||
return pushInstance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* save push instance url
|
||||
*
|
||||
* @param pushInstance instance url
|
||||
*/
|
||||
public void setPushInstance(String pushInstance) {
|
||||
this.pushInstance = pushInstance;
|
||||
|
||||
@ -894,28 +922,6 @@ public class GlobalSettings {
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if push notification is enabled
|
||||
*
|
||||
* @return true if push notification is enabled
|
||||
*/
|
||||
public boolean pushEnabled() {
|
||||
return push_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* enable/disable push notification
|
||||
*
|
||||
* @param enable true to enable notification
|
||||
*/
|
||||
public void setPushEnabled(boolean enable) {
|
||||
push_enabled = enable;
|
||||
|
||||
Editor edit = settings.edit();
|
||||
edit.putBoolean(PUSH_ENABLED, enable);
|
||||
edit.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* get login information
|
||||
*
|
||||
|
@ -210,9 +210,11 @@ public class WebPushDialog extends Dialog implements OnCheckedChangeListener, On
|
||||
public void onResult(@NonNull PushUpdater.Result result) {
|
||||
if (result.push != null) {
|
||||
Toast.makeText(getContext(), R.string.info_webpush_update, Toast.LENGTH_SHORT).show();
|
||||
settings.setPushEnabled(true);
|
||||
dismiss();
|
||||
} else if (result.exception != null) {
|
||||
ErrorUtils.showErrorMessage(getContext(), result.exception);
|
||||
settings.setPushEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -363,4 +363,5 @@
|
||||
<string name="confirm_accept_follow_request">Follow-Anfrage annehmen?</string>
|
||||
<string name="info_follow_request_accepted">Follow-Anfrage angenommen</string>
|
||||
<string name="description_show_timeline">öffentl. Timeline</string>
|
||||
<string name="error_api_error">API Fehler</string>
|
||||
</resources>
|
@ -123,6 +123,7 @@
|
||||
<string name="error_invalid_media">Invalid media file!</string>
|
||||
<string name="error_not_defined">Not specified error!</string>
|
||||
<string name="error_forbidden_api_access">API does not support this operation!</string>
|
||||
<string name="error_api_error">API error</string>
|
||||
<string name="error_adding_media">Error occurred while adding media!</string>
|
||||
<string name="error_media_init">Error while preparing media files for upload!</string>
|
||||
<string name="error_translating_status">Could not translate status</string>
|
||||
|
Loading…
Reference in New Issue
Block a user