Skip to content

Commit

Permalink
added multiple account push support, screenshot update
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Oct 26, 2023
1 parent 13d841c commit 410ed0d
Show file tree
Hide file tree
Showing 24 changed files with 556 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Account))
return false;
Account account = (Account) obj;
if (account.getUser() != null && getUser() != null)
return getUser().equals(account.getUser());
return false;
return account.getId() == getId() && account.getHostname().equals(getHostname());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean alertMentionEnabled() {


@Override
public boolean alertStatusPostEnabled() {
public boolean alertNewStatusEnabled() {
return newPostAlert;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,63 @@

import androidx.annotation.NonNull;

import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.database.AppDatabase;
import org.nuclearfog.twidda.model.Account;
import org.nuclearfog.twidda.model.WebPush;

/**
* @author nuclearfog
*/
public class AccountAction extends AsyncExecutor<AccountAction.Param, AccountAction.Result> {

private AppDatabase db;
private AppDatabase database;
private GlobalSettings settings;

/**
*
*/
public AccountAction(Context context) {
db = new AppDatabase(context);
database = new AppDatabase(context);
settings = GlobalSettings.get(context);
}


@Override
protected Result doInBackground(@NonNull Param param) {
db.removeLogin(param.id);
return new Result(param.id);
switch (param.mode) {
case Param.SELECT:
WebPush webPush = database.getWebPush(param.account);
settings.setLogin(param.account, true);
if (webPush != null) {
settings.setPushEnabled(true);
settings.setWebPush(webPush);
} else {
settings.setPushEnabled(false);
}
return new Result(Result.SELECT, param.account);

case Param.REMOVE:
database.removeLogin(param.account);
return new Result(Result.REMOVE, param.account);
}
return null;
}

/**
*
*/
public static class Param {

final long id;
public static final int SELECT = 1;
public static final int REMOVE = 2;

public Param(long id) {
this.id = id;
final Account account;
final int mode;

public Param(int mode, Account account) {
this.mode = mode;
this.account = account;
}
}

Expand All @@ -44,10 +69,15 @@ public Param(long id) {
*/
public static class Result {

public final long id;
public static final int SELECT = 10;
public static final int REMOVE = 20;

public final Account account;
public final int mode;

Result(long id) {
this.id = id;
Result(int mode, Account account) {
this.mode = mode;
this.account = account;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected Result doInBackground(@NonNull Param param) {
return new Result(Result.DELETE);

case Param.LOGOUT:
db.removeLogin(settings.getLogin().getId());
db.removeLogin(settings.getLogin());
return new Result(Result.LOGOUT);

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.nuclearfog.twidda.backend.api.ConnectionManager;
import org.nuclearfog.twidda.backend.helper.update.PushUpdate;
import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.database.AppDatabase;
import org.nuclearfog.twidda.model.WebPush;

/**
Expand All @@ -20,13 +21,15 @@ public class PushUpdater extends AsyncExecutor<PushUpdate, PushUpdater.Result> {

private Connection connection;
private GlobalSettings settings;
private AppDatabase database;

/**
*
*/
public PushUpdater(Context context) {
connection = ConnectionManager.getDefaultConnection(context);
settings = GlobalSettings.get(context);
database = new AppDatabase(context);
}


Expand All @@ -35,6 +38,7 @@ protected Result doInBackground(@NonNull PushUpdate param) {
try {
WebPush webpush = connection.updatePush(param);
settings.setWebPush(webpush);
database.savePushSubscription(webpush);
return new Result(webpush, null);
} catch (ConnectionException e) {
return new Result(null, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PushUpdate(WebPush webPush, String host) {
this.host = host;
}
notifyMention = webPush.alertMentionEnabled();
notifyStatus = webPush.alertStatusPostEnabled();
notifyStatus = webPush.alertNewStatusEnabled();
notifyFollowRequest = webPush.alertFollowRequestEnabled();
notifyFollow = webPush.alertFollowingEnabled();
notifyFavorite = webPush.alertFavoriteEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public void setWebPush(WebPush webPush) {
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_POST, webPush.alertNewStatusEnabled());
edit.putBoolean(PUSH_ALERT_STATUS_EDIT, webPush.alertStatusChangeEnabled());
edit.putBoolean(PUSH_ALERT_POLL, webPush.alertPollEnabled());
edit.apply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Account))
return false;
Account account = (Account) obj;
if (account.getUser() != null && getUser() != null)
return getUser().equals(account.getUser());
return false;
return account.getId() == getId() && account.getHostname().equals(getHostname());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ConfigPush(WebPush webPush) {
favorits = webPush.alertFavoriteEnabled();
following = webPush.alertFollowingEnabled();
follow_request = webPush.alertFollowRequestEnabled();
status_post = webPush.alertStatusPostEnabled();
status_post = webPush.alertNewStatusEnabled();
status_change = webPush.alertStatusChangeEnabled();
poll_finished = webPush.alertPollEnabled();
policy = webPush.getPolicy();
Expand Down Expand Up @@ -105,7 +105,7 @@ public boolean alertMentionEnabled() {


@Override
public boolean alertStatusPostEnabled() {
public boolean alertNewStatusEnabled() {
return status_post;
}

Expand Down
Loading

0 comments on commit 410ed0d

Please sign in to comment.