mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-07 06:23:48 +01:00
poll fix, added new poll endpoint (Mastodon), renamed database classes
This commit is contained in:
parent
4d1d9c94cb
commit
2483df74c8
@ -522,6 +522,14 @@ public interface Connection {
|
|||||||
*/
|
*/
|
||||||
List<Emoji> getEmojis() throws ConnectionException;
|
List<Emoji> getEmojis() throws ConnectionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get poll of a status
|
||||||
|
*
|
||||||
|
* @param id ID of the poll
|
||||||
|
* @return poll instance
|
||||||
|
*/
|
||||||
|
Poll getPoll(long id) throws ConnectionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* send a vote to a poll
|
* send a vote to a poll
|
||||||
*
|
*
|
||||||
@ -529,7 +537,7 @@ public interface Connection {
|
|||||||
* @param selection selected poll choices
|
* @param selection selected poll choices
|
||||||
* @return updated poll
|
* @return updated poll
|
||||||
*/
|
*/
|
||||||
Poll vote(Poll poll, int[] selection) throws ConnectionException;
|
Poll votePoll(Poll poll, int[] selection) throws ConnectionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a list of blocked user IDs
|
* returns a list of blocked user IDs
|
||||||
|
@ -757,7 +757,23 @@ public class Mastodon implements Connection {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Poll vote(Poll poll, int[] selection) throws ConnectionException {
|
public Poll getPoll(long id) throws ConnectionException {
|
||||||
|
try {
|
||||||
|
Response response = get(ENDPOINT_POLL + id, new ArrayList<>());
|
||||||
|
ResponseBody body = response.body();
|
||||||
|
if (response.code() == 200 && body != null) {
|
||||||
|
JSONObject json = new JSONObject(body.string());
|
||||||
|
return new MastodonPoll(json);
|
||||||
|
}
|
||||||
|
throw new MastodonException(response);
|
||||||
|
} catch (IOException | JSONException e) {
|
||||||
|
throw new MastodonException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Poll votePoll(Poll poll, int[] selection) throws ConnectionException {
|
||||||
List<String> params = new ArrayList<>();
|
List<String> params = new ArrayList<>();
|
||||||
for (int choice : selection) {
|
for (int choice : selection) {
|
||||||
params.add("choices[]=" + choice);
|
params.add("choices[]=" + choice);
|
||||||
|
@ -119,12 +119,16 @@ public class MastodonPoll implements Poll {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder optionsBuf = new StringBuilder(" options=(");
|
StringBuilder optionsBuf = new StringBuilder();
|
||||||
|
optionsBuf.append("id=").append(id).append(" voted=").append(voted);
|
||||||
|
if (options.length > 0) {
|
||||||
|
optionsBuf.append(" options=(");
|
||||||
for (Option option : options) {
|
for (Option option : options) {
|
||||||
optionsBuf.append(option).append(',');
|
optionsBuf.append(option).append(',');
|
||||||
}
|
}
|
||||||
optionsBuf.deleteCharAt(optionsBuf.length() - 1).append(')');
|
optionsBuf.deleteCharAt(optionsBuf.length() - 1).append(')');
|
||||||
return "id=" + id + " expired=" + expired + " options=" + optionsBuf;
|
}
|
||||||
|
return optionsBuf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -927,7 +927,13 @@ public class TwitterV1 implements Connection {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Poll vote(Poll poll, int[] choices) throws ConnectionException {
|
public Poll getPoll(long id) throws ConnectionException {
|
||||||
|
throw new TwitterException("not supported!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Poll votePoll(Poll poll, int[] choices) throws ConnectionException {
|
||||||
throw new TwitterException("not supported!");
|
throw new TwitterException("not supported!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.nuclearfog.twidda.BuildConfig;
|
import org.nuclearfog.twidda.BuildConfig;
|
||||||
|
import org.nuclearfog.twidda.backend.api.ConnectionException;
|
||||||
import org.nuclearfog.twidda.backend.api.twitter.TwitterException;
|
import org.nuclearfog.twidda.backend.api.twitter.TwitterException;
|
||||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v1.TwitterV1;
|
import org.nuclearfog.twidda.backend.api.twitter.impl.v1.TwitterV1;
|
||||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.LocationV2Map;
|
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.LocationV2Map;
|
||||||
@ -17,6 +18,7 @@ import org.nuclearfog.twidda.backend.helper.ConnectionConfig;
|
|||||||
import org.nuclearfog.twidda.backend.helper.Users;
|
import org.nuclearfog.twidda.backend.helper.Users;
|
||||||
import org.nuclearfog.twidda.backend.utils.StringTools;
|
import org.nuclearfog.twidda.backend.utils.StringTools;
|
||||||
import org.nuclearfog.twidda.model.Account;
|
import org.nuclearfog.twidda.model.Account;
|
||||||
|
import org.nuclearfog.twidda.model.Poll;
|
||||||
import org.nuclearfog.twidda.model.Status;
|
import org.nuclearfog.twidda.model.Status;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -108,6 +110,12 @@ public class TwitterV2 extends TwitterV1 {
|
|||||||
return replies;
|
return replies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Poll getPoll(long id) throws ConnectionException {
|
||||||
|
return null; // todo implement this
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mute a status from conversation
|
* mute a status from conversation
|
||||||
*
|
*
|
||||||
|
@ -33,14 +33,21 @@ public class VoteUpdater extends AsyncExecutor<VoteUpdater.VoteParam, VoteUpdate
|
|||||||
@Override
|
@Override
|
||||||
protected VoteResult doInBackground(VoteParam param) {
|
protected VoteResult doInBackground(VoteParam param) {
|
||||||
try {
|
try {
|
||||||
Poll poll = connection.vote(param.poll, param.selection);
|
switch (param.mode) {
|
||||||
return new VoteResult(poll, null);
|
case VoteParam.LOAD:
|
||||||
|
Poll poll = connection.getPoll(param.poll.getId());
|
||||||
|
return new VoteResult(VoteResult.LOAD, poll, null);
|
||||||
|
|
||||||
|
case VoteParam.VOTE:
|
||||||
|
poll = connection.votePoll(param.poll, param.selection);
|
||||||
|
return new VoteResult(VoteResult.VOTE, poll, null);
|
||||||
|
}
|
||||||
} catch (ConnectionException exception) {
|
} catch (ConnectionException exception) {
|
||||||
return new VoteResult(null, exception);
|
return new VoteResult(VoteResult.ERROR, null, exception);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return new VoteResult(null, null);
|
return new VoteResult(VoteResult.ERROR, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,10 +55,15 @@ public class VoteUpdater extends AsyncExecutor<VoteUpdater.VoteParam, VoteUpdate
|
|||||||
*/
|
*/
|
||||||
public static class VoteParam {
|
public static class VoteParam {
|
||||||
|
|
||||||
|
public static final int LOAD = 1;
|
||||||
|
public static final int VOTE = 2;
|
||||||
|
|
||||||
|
public final int mode;
|
||||||
public final Poll poll;
|
public final Poll poll;
|
||||||
public final int[] selection;
|
public final int[] selection;
|
||||||
|
|
||||||
public VoteParam(Poll poll, int[] selection) {
|
public VoteParam(int mode, Poll poll, int[] selection) {
|
||||||
|
this.mode = mode;
|
||||||
this.poll = poll;
|
this.poll = poll;
|
||||||
this.selection = Arrays.copyOf(selection, selection.length);
|
this.selection = Arrays.copyOf(selection, selection.length);
|
||||||
}
|
}
|
||||||
@ -62,12 +74,18 @@ public class VoteUpdater extends AsyncExecutor<VoteUpdater.VoteParam, VoteUpdate
|
|||||||
*/
|
*/
|
||||||
public static class VoteResult {
|
public static class VoteResult {
|
||||||
|
|
||||||
|
public static final int ERROR = -1;
|
||||||
|
public static final int LOAD = 3;
|
||||||
|
public static final int VOTE = 4;
|
||||||
|
|
||||||
|
public final int mode;
|
||||||
@Nullable
|
@Nullable
|
||||||
public final Poll poll;
|
public final Poll poll;
|
||||||
@Nullable
|
@Nullable
|
||||||
public final ConnectionException exception;
|
public final ConnectionException exception;
|
||||||
|
|
||||||
VoteResult(@Nullable Poll poll, @Nullable ConnectionException exception) {
|
VoteResult(int mode, @Nullable Poll poll, @Nullable ConnectionException exception) {
|
||||||
|
this.mode = mode;
|
||||||
this.poll = poll;
|
this.poll = poll;
|
||||||
this.exception = exception;
|
this.exception = exception;
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ import androidx.annotation.ColorInt;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.nuclearfog.twidda.database.impl.AccountImpl;
|
import org.nuclearfog.twidda.config.impl.ConfigAccount;
|
||||||
import org.nuclearfog.twidda.database.impl.LocationImpl;
|
import org.nuclearfog.twidda.config.impl.ConfigLocation;
|
||||||
import org.nuclearfog.twidda.model.Account;
|
import org.nuclearfog.twidda.model.Account;
|
||||||
import org.nuclearfog.twidda.model.Location;
|
import org.nuclearfog.twidda.model.Location;
|
||||||
|
|
||||||
@ -538,7 +538,7 @@ public class GlobalSettings {
|
|||||||
return location;
|
return location;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new LocationImpl(-1L, "");
|
return new ConfigLocation(-1L, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -918,7 +918,7 @@ public class GlobalSettings {
|
|||||||
e.remove(BEARER_TOKEN);
|
e.remove(BEARER_TOKEN);
|
||||||
e.remove(HOSTNAME);
|
e.remove(HOSTNAME);
|
||||||
} else {
|
} else {
|
||||||
AccountImpl account = new AccountImpl(login);
|
ConfigAccount account = new ConfigAccount(login);
|
||||||
this.account = account;
|
this.account = account;
|
||||||
loggedIn = true;
|
loggedIn = true;
|
||||||
// setup alternative Twitter host
|
// setup alternative Twitter host
|
||||||
@ -1002,7 +1002,7 @@ public class GlobalSettings {
|
|||||||
proxyPass = settings.getString(PROXY_PASS, "");
|
proxyPass = settings.getString(PROXY_PASS, "");
|
||||||
String place = settings.getString(TREND_LOC, DEFAULT_LOCATION_NAME);
|
String place = settings.getString(TREND_LOC, DEFAULT_LOCATION_NAME);
|
||||||
long woeId = settings.getLong(TREND_ID, DEFAULT_LOCATION_ID);
|
long woeId = settings.getLong(TREND_ID, DEFAULT_LOCATION_ID);
|
||||||
location = new LocationImpl(woeId, place);
|
location = new ConfigLocation(woeId, place);
|
||||||
// login informations
|
// login informations
|
||||||
initLogin();
|
initLogin();
|
||||||
}
|
}
|
||||||
@ -1021,7 +1021,7 @@ public class GlobalSettings {
|
|||||||
long userId = settings.getLong(CURRENT_ID, 0);
|
long userId = settings.getLong(CURRENT_ID, 0);
|
||||||
if ((apiId == Account.API_TWITTER_1 || apiId == Account.API_TWITTER_2) && twitterAlt)
|
if ((apiId == Account.API_TWITTER_1 || apiId == Account.API_TWITTER_2) && twitterAlt)
|
||||||
hostname = TWITTER_ALT_HOST;
|
hostname = TWITTER_ALT_HOST;
|
||||||
account = new AccountImpl(userId, oauthToken, oauthSecret, consumerToken, consumerSecret, bearerToken, hostname, apiId);
|
account = new ConfigAccount(userId, oauthToken, oauthSecret, consumerToken, consumerSecret, bearerToken, hostname, apiId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,166 @@
|
|||||||
|
package org.nuclearfog.twidda.config.impl;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.nuclearfog.twidda.config.Configuration;
|
||||||
|
import org.nuclearfog.twidda.model.Account;
|
||||||
|
import org.nuclearfog.twidda.model.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {link Account} implementation used by app settings
|
||||||
|
*
|
||||||
|
* @author nuclearfog
|
||||||
|
*/
|
||||||
|
public class ConfigAccount implements Account {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7526554312489208096L;
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private long timestamp;
|
||||||
|
private int type;
|
||||||
|
private String oauthToken, tokenSecret, bearerToken;
|
||||||
|
private String consumerToken, consumerSecret, hostname;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ConfigAccount(Account account) {
|
||||||
|
id = account.getId();
|
||||||
|
oauthToken = account.getOauthToken();
|
||||||
|
tokenSecret = account.getOauthSecret();
|
||||||
|
consumerToken = account.getConsumerToken();
|
||||||
|
consumerSecret = account.getConsumerSecret();
|
||||||
|
bearerToken = account.getBearerToken();
|
||||||
|
hostname = account.getHostname();
|
||||||
|
|
||||||
|
switch (account.getConfiguration()) {
|
||||||
|
case TWITTER1:
|
||||||
|
type = API_TWITTER_1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TWITTER2:
|
||||||
|
type = API_TWITTER_2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MASTODON:
|
||||||
|
type = API_MASTODON;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
type = API_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public ConfigAccount(long id, String oauthToken, String tokenSecret, String consumerToken, String consumerSecret, String bearerToken, String hostname, int type) {
|
||||||
|
this.id = id;
|
||||||
|
this.oauthToken = oauthToken;
|
||||||
|
this.tokenSecret = tokenSecret;
|
||||||
|
this.consumerToken = consumerToken;
|
||||||
|
this.consumerSecret = consumerSecret;
|
||||||
|
this.bearerToken = bearerToken;
|
||||||
|
this.hostname = hostname;
|
||||||
|
this.type = type;
|
||||||
|
timestamp = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public User getUser() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConsumerToken() {
|
||||||
|
return consumerToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConsumerSecret() {
|
||||||
|
return consumerSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOauthToken() {
|
||||||
|
return oauthToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getOauthSecret() {
|
||||||
|
return tokenSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBearerToken() {
|
||||||
|
return bearerToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHostname() {
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration getConfiguration() {
|
||||||
|
switch (type) {
|
||||||
|
case API_TWITTER_1:
|
||||||
|
return Configuration.TWITTER1;
|
||||||
|
|
||||||
|
case API_TWITTER_2:
|
||||||
|
return Configuration.TWITTER2;
|
||||||
|
|
||||||
|
case API_MASTODON:
|
||||||
|
return Configuration.MASTODON;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return Configuration.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean usingDefaultTokens() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "date=" + timestamp + " host=\"" + hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* override hostname
|
||||||
|
*
|
||||||
|
* @param hostname new hostname
|
||||||
|
*/
|
||||||
|
public void setHost(String hostname) {
|
||||||
|
this.hostname = hostname;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package org.nuclearfog.twidda.config.impl;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import org.nuclearfog.twidda.model.Location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Location} implementation for app settings
|
||||||
|
*
|
||||||
|
* @author nuclearfog
|
||||||
|
*/
|
||||||
|
public class ConfigLocation implements Location {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 917895381491189806L;
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name place name
|
||||||
|
* @param id world id
|
||||||
|
*/
|
||||||
|
public ConfigLocation(long id, String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCountry() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPlace() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCoordinates() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Location o) {
|
||||||
|
return Long.compare(id, o.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "id=" + id + " name=\"" + name + "\"";
|
||||||
|
}
|
||||||
|
}
|
@ -26,15 +26,15 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import org.nuclearfog.twidda.backend.helper.Messages;
|
import org.nuclearfog.twidda.backend.helper.Messages;
|
||||||
import org.nuclearfog.twidda.config.GlobalSettings;
|
import org.nuclearfog.twidda.config.GlobalSettings;
|
||||||
import org.nuclearfog.twidda.database.impl.AccountImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseAccount;
|
||||||
import org.nuclearfog.twidda.database.impl.EmojiImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseEmoji;
|
||||||
import org.nuclearfog.twidda.database.impl.LocationImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseLocation;
|
||||||
import org.nuclearfog.twidda.database.impl.MediaImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseMedia;
|
||||||
import org.nuclearfog.twidda.database.impl.MessageImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseMessage;
|
||||||
import org.nuclearfog.twidda.database.impl.NotificationImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseNotification;
|
||||||
import org.nuclearfog.twidda.database.impl.StatusImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseStatus;
|
||||||
import org.nuclearfog.twidda.database.impl.TrendImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseTrend;
|
||||||
import org.nuclearfog.twidda.database.impl.UserImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseUser;
|
||||||
import org.nuclearfog.twidda.model.Account;
|
import org.nuclearfog.twidda.model.Account;
|
||||||
import org.nuclearfog.twidda.model.Emoji;
|
import org.nuclearfog.twidda.model.Emoji;
|
||||||
import org.nuclearfog.twidda.model.Location;
|
import org.nuclearfog.twidda.model.Location;
|
||||||
@ -693,7 +693,7 @@ public class AppDatabase {
|
|||||||
Cursor cursor = db.rawQuery(SINGLE_USER_QUERY, args);
|
Cursor cursor = db.rawQuery(SINGLE_USER_QUERY, args);
|
||||||
User user = null;
|
User user = null;
|
||||||
if (cursor.moveToFirst())
|
if (cursor.moveToFirst())
|
||||||
user = new UserImpl(cursor, account);
|
user = new DatabaseUser(cursor, account);
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
@ -746,7 +746,7 @@ public class AppDatabase {
|
|||||||
Cursor cursor = db.rawQuery(NOTIFICATION_QUERY, args);
|
Cursor cursor = db.rawQuery(NOTIFICATION_QUERY, args);
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
NotificationImpl notification = new NotificationImpl(cursor, login);
|
DatabaseNotification notification = new DatabaseNotification(cursor, login);
|
||||||
switch (notification.getType()) {
|
switch (notification.getType()) {
|
||||||
case Notification.TYPE_FAVORITE:
|
case Notification.TYPE_FAVORITE:
|
||||||
case Notification.TYPE_REPOST:
|
case Notification.TYPE_REPOST:
|
||||||
@ -892,11 +892,11 @@ public class AppDatabase {
|
|||||||
public List<Trend> getTrends() {
|
public List<Trend> getTrends() {
|
||||||
String[] args = {Long.toString(settings.getTrendLocation().getId())};
|
String[] args = {Long.toString(settings.getTrendLocation().getId())};
|
||||||
SQLiteDatabase db = getDbRead();
|
SQLiteDatabase db = getDbRead();
|
||||||
Cursor cursor = db.query(TrendTable.NAME, TrendImpl.COLUMNS, TREND_SELECT, args, null, null, null);
|
Cursor cursor = db.query(TrendTable.NAME, DatabaseTrend.COLUMNS, TREND_SELECT, args, null, null, null);
|
||||||
List<Trend> trends = new LinkedList<>();
|
List<Trend> trends = new LinkedList<>();
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
trends.add(new TrendImpl(cursor));
|
trends.add(new DatabaseTrend(cursor));
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
@ -918,7 +918,7 @@ public class AppDatabase {
|
|||||||
Cursor cursor = db.rawQuery(MESSAGE_QUERY, args);
|
Cursor cursor = db.rawQuery(MESSAGE_QUERY, args);
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
MessageImpl item = new MessageImpl(cursor, login);
|
DatabaseMessage item = new DatabaseMessage(cursor, login);
|
||||||
result.add(item);
|
result.add(item);
|
||||||
if (item.getMediaKeys().length > 0) {
|
if (item.getMediaKeys().length > 0) {
|
||||||
List<Media> medias = new LinkedList<>();
|
List<Media> medias = new LinkedList<>();
|
||||||
@ -1026,11 +1026,11 @@ public class AppDatabase {
|
|||||||
ArrayList<Account> result = new ArrayList<>();
|
ArrayList<Account> result = new ArrayList<>();
|
||||||
|
|
||||||
SQLiteDatabase db = getDbRead();
|
SQLiteDatabase db = getDbRead();
|
||||||
Cursor cursor = db.query(AccountTable.NAME, AccountImpl.COLUMNS, null, null, null, null, SORT_BY_CREATION);
|
Cursor cursor = db.query(AccountTable.NAME, DatabaseAccount.COLUMNS, null, null, null, null, SORT_BY_CREATION);
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
result.ensureCapacity(cursor.getCount());
|
result.ensureCapacity(cursor.getCount());
|
||||||
do {
|
do {
|
||||||
AccountImpl account = new AccountImpl(cursor);
|
DatabaseAccount account = new DatabaseAccount(cursor);
|
||||||
account.addUser(getUser(account.getId(), account));
|
account.addUser(getUser(account.getId(), account));
|
||||||
result.add(account);
|
result.add(account);
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
@ -1047,7 +1047,7 @@ public class AppDatabase {
|
|||||||
*/
|
*/
|
||||||
private Status getStatus(Cursor cursor, SQLiteDatabase db) {
|
private Status getStatus(Cursor cursor, SQLiteDatabase db) {
|
||||||
Account login = settings.getLogin();
|
Account login = settings.getLogin();
|
||||||
StatusImpl result = new StatusImpl(cursor, login);
|
DatabaseStatus result = new DatabaseStatus(cursor, login);
|
||||||
// check if there is an embedded status
|
// check if there is an embedded status
|
||||||
if (result.getEmbeddedStatusId() > 1L) {
|
if (result.getEmbeddedStatusId() > 1L) {
|
||||||
result.setEmbeddedStatus(getStatus(result.getEmbeddedStatusId()));
|
result.setEmbeddedStatus(getStatus(result.getEmbeddedStatusId()));
|
||||||
@ -1113,10 +1113,10 @@ public class AppDatabase {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Media getMedia(SQLiteDatabase db, String key) {
|
private Media getMedia(SQLiteDatabase db, String key) {
|
||||||
String[] args = {key};
|
String[] args = {key};
|
||||||
Cursor c = db.query(MediaTable.NAME, MediaImpl.PROJECTION, MEDIA_SELECT, args, null, null, null, SINGLE_ITEM);
|
Cursor c = db.query(MediaTable.NAME, DatabaseMedia.PROJECTION, MEDIA_SELECT, args, null, null, null, SINGLE_ITEM);
|
||||||
Media result = null;
|
Media result = null;
|
||||||
if (c.moveToFirst())
|
if (c.moveToFirst())
|
||||||
result = new MediaImpl(c);
|
result = new DatabaseMedia(c);
|
||||||
c.close();
|
c.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1131,10 +1131,10 @@ public class AppDatabase {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Emoji getEmoji(SQLiteDatabase db, String key) {
|
private Emoji getEmoji(SQLiteDatabase db, String key) {
|
||||||
String[] args = {key};
|
String[] args = {key};
|
||||||
Cursor c = db.query(EmojiTable.NAME, EmojiImpl.PROJECTION, EMOJI_SELECT, args, null, null, null, SINGLE_ITEM);
|
Cursor c = db.query(EmojiTable.NAME, DatabaseEmoji.PROJECTION, EMOJI_SELECT, args, null, null, null, SINGLE_ITEM);
|
||||||
Emoji result = null;
|
Emoji result = null;
|
||||||
if (c.moveToFirst())
|
if (c.moveToFirst())
|
||||||
result = new EmojiImpl(c);
|
result = new DatabaseEmoji(c);
|
||||||
c.close();
|
c.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1149,10 +1149,10 @@ public class AppDatabase {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Location getLocation(SQLiteDatabase db, long id) {
|
private Location getLocation(SQLiteDatabase db, long id) {
|
||||||
String[] args = {Long.toString(id)};
|
String[] args = {Long.toString(id)};
|
||||||
Cursor c = db.query(LocationTable.NAME, LocationImpl.PROJECTION, LOCATION_SELECT, args, null, null, null, SINGLE_ITEM);
|
Cursor c = db.query(LocationTable.NAME, DatabaseLocation.PROJECTION, LOCATION_SELECT, args, null, null, null, SINGLE_ITEM);
|
||||||
Location result = null;
|
Location result = null;
|
||||||
if (c.moveToFirst())
|
if (c.moveToFirst())
|
||||||
result = new LocationImpl(c);
|
result = new DatabaseLocation(c);
|
||||||
c.close();
|
c.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import org.nuclearfog.twidda.model.User;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class AccountImpl implements Account {
|
public class DatabaseAccount implements Account {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2276274593772105348L;
|
private static final long serialVersionUID = -2276274593772105348L;
|
||||||
|
|
||||||
@ -43,56 +43,10 @@ public class AccountImpl implements Account {
|
|||||||
private String host;
|
private String host;
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public AccountImpl(Account account) {
|
|
||||||
userId = account.getId();
|
|
||||||
accessToken = account.getOauthToken();
|
|
||||||
tokenSecret = account.getOauthSecret();
|
|
||||||
consumerToken = account.getConsumerToken();
|
|
||||||
consumerSecret = account.getConsumerSecret();
|
|
||||||
bearerToken = account.getBearerToken();
|
|
||||||
host = account.getHostname();
|
|
||||||
|
|
||||||
switch (account.getConfiguration()) {
|
|
||||||
case TWITTER1:
|
|
||||||
apiType = API_TWITTER_1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TWITTER2:
|
|
||||||
apiType = API_TWITTER_2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MASTODON:
|
|
||||||
apiType = API_MASTODON;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
apiType = API_NONE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public AccountImpl(long userId, String accessToken, String tokenSecret, String consumerToken, String consumerSecret, String bearerToken, String host, int apiType) {
|
|
||||||
this.userId = userId;
|
|
||||||
this.accessToken = accessToken;
|
|
||||||
this.tokenSecret = tokenSecret;
|
|
||||||
this.consumerToken = consumerToken;
|
|
||||||
this.consumerSecret = consumerSecret;
|
|
||||||
this.bearerToken = bearerToken;
|
|
||||||
this.host = host;
|
|
||||||
this.apiType = apiType;
|
|
||||||
loginDate = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cursor database cursor using this {@link #COLUMNS}
|
* @param cursor database cursor using this {@link #COLUMNS}
|
||||||
*/
|
*/
|
||||||
public AccountImpl(Cursor cursor) {
|
public DatabaseAccount(Cursor cursor) {
|
||||||
userId = cursor.getLong(0);
|
userId = cursor.getLong(0);
|
||||||
loginDate = cursor.getLong(1);
|
loginDate = cursor.getLong(1);
|
||||||
accessToken = cursor.getString(2);
|
accessToken = cursor.getString(2);
|
||||||
@ -200,13 +154,4 @@ public class AccountImpl implements Account {
|
|||||||
public void addUser(@Nullable User user) {
|
public void addUser(@Nullable User user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* override hostname
|
|
||||||
*
|
|
||||||
* @param hostname new hostname
|
|
||||||
*/
|
|
||||||
public void setHost(String hostname) {
|
|
||||||
this.host = hostname;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ import org.nuclearfog.twidda.model.Emoji;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class EmojiImpl implements Emoji {
|
public class DatabaseEmoji implements Emoji {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4915542258264850899L;
|
private static final long serialVersionUID = 4915542258264850899L;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ public class EmojiImpl implements Emoji {
|
|||||||
/**
|
/**
|
||||||
* @param cursor database cursor
|
* @param cursor database cursor
|
||||||
*/
|
*/
|
||||||
public EmojiImpl(Cursor cursor) {
|
public DatabaseEmoji(Cursor cursor) {
|
||||||
code = cursor.getString(0);
|
code = cursor.getString(0);
|
||||||
url = cursor.getString(1);
|
url = cursor.getString(1);
|
||||||
category = cursor.getString(2);
|
category = cursor.getString(2);
|
@ -13,7 +13,7 @@ import org.nuclearfog.twidda.model.Location;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class LocationImpl implements Location {
|
public class DatabaseLocation implements Location {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3719416358210741464L;
|
private static final long serialVersionUID = 3719416358210741464L;
|
||||||
|
|
||||||
@ -30,21 +30,12 @@ public class LocationImpl implements Location {
|
|||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
private String name;
|
private String name;
|
||||||
private String coordinates = "";
|
private String coordinates;
|
||||||
private String country = "";
|
private String country;
|
||||||
private String place = "";
|
private String place;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name place name
|
|
||||||
* @param id world id
|
|
||||||
*/
|
|
||||||
public LocationImpl(long id, String name) {
|
|
||||||
this.name = name;
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public LocationImpl(Cursor cursor) {
|
public DatabaseLocation(Cursor cursor) {
|
||||||
id = cursor.getLong(0);
|
id = cursor.getLong(0);
|
||||||
place = cursor.getString(1);
|
place = cursor.getString(1);
|
||||||
country = cursor.getString(2);
|
country = cursor.getString(2);
|
@ -12,7 +12,7 @@ import org.nuclearfog.twidda.model.Media;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class MediaImpl implements Media {
|
public class DatabaseMedia implements Media {
|
||||||
|
|
||||||
private static final long serialVersionUID = 8895107738679315263L;
|
private static final long serialVersionUID = 8895107738679315263L;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class MediaImpl implements Media {
|
|||||||
/**
|
/**
|
||||||
* @param cursor database cursor containing media table
|
* @param cursor database cursor containing media table
|
||||||
*/
|
*/
|
||||||
public MediaImpl(Cursor cursor) {
|
public DatabaseMedia(Cursor cursor) {
|
||||||
key = cursor.getString(0);
|
key = cursor.getString(0);
|
||||||
url = cursor.getString(1);
|
url = cursor.getString(1);
|
||||||
preview = cursor.getString(2);
|
preview = cursor.getString(2);
|
@ -18,7 +18,7 @@ import java.util.regex.Pattern;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class MessageImpl implements Message {
|
public class DatabaseMessage implements Message {
|
||||||
|
|
||||||
private static final long serialVersionUID = 4089879784295312386L;
|
private static final long serialVersionUID = 4089879784295312386L;
|
||||||
|
|
||||||
@ -36,8 +36,8 @@ public class MessageImpl implements Message {
|
|||||||
* @param cursor database cursor containing UserTable column
|
* @param cursor database cursor containing UserTable column
|
||||||
* @param account current user information
|
* @param account current user information
|
||||||
*/
|
*/
|
||||||
public MessageImpl(Cursor cursor, Account account) {
|
public DatabaseMessage(Cursor cursor, Account account) {
|
||||||
sender = new UserImpl(cursor, account);
|
sender = new DatabaseUser(cursor, account);
|
||||||
text = cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.MESSAGE));
|
text = cursor.getString(cursor.getColumnIndexOrThrow(MessageTable.MESSAGE));
|
||||||
time = cursor.getLong(cursor.getColumnIndexOrThrow(MessageTable.TIME));
|
time = cursor.getLong(cursor.getColumnIndexOrThrow(MessageTable.TIME));
|
||||||
id = cursor.getLong(cursor.getColumnIndexOrThrow(MessageTable.ID));
|
id = cursor.getLong(cursor.getColumnIndexOrThrow(MessageTable.ID));
|
@ -16,7 +16,7 @@ import org.nuclearfog.twidda.model.User;
|
|||||||
*
|
*
|
||||||
* @author nuclerfog
|
* @author nuclerfog
|
||||||
*/
|
*/
|
||||||
public class NotificationImpl implements Notification {
|
public class DatabaseNotification implements Notification {
|
||||||
|
|
||||||
private static final long serialVersionUID = 436155941776152806L;
|
private static final long serialVersionUID = 436155941776152806L;
|
||||||
|
|
||||||
@ -31,8 +31,8 @@ public class NotificationImpl implements Notification {
|
|||||||
* @param cursor database cursor containing Notification table column
|
* @param cursor database cursor containing Notification table column
|
||||||
* @param account current user information
|
* @param account current user information
|
||||||
*/
|
*/
|
||||||
public NotificationImpl(Cursor cursor, Account account) {
|
public DatabaseNotification(Cursor cursor, Account account) {
|
||||||
user = new UserImpl(cursor, account);
|
user = new DatabaseUser(cursor, account);
|
||||||
id = cursor.getLong(cursor.getColumnIndexOrThrow(NotificationTable.ID));
|
id = cursor.getLong(cursor.getColumnIndexOrThrow(NotificationTable.ID));
|
||||||
itemId = cursor.getLong(cursor.getColumnIndexOrThrow(NotificationTable.ITEM));
|
itemId = cursor.getLong(cursor.getColumnIndexOrThrow(NotificationTable.ITEM));
|
||||||
type = cursor.getInt(cursor.getColumnIndexOrThrow(NotificationTable.TYPE));
|
type = cursor.getInt(cursor.getColumnIndexOrThrow(NotificationTable.TYPE));
|
@ -31,7 +31,7 @@ import java.util.regex.Pattern;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class StatusImpl implements Status {
|
public class DatabaseStatus implements Status {
|
||||||
|
|
||||||
private static final long serialVersionUID = -5957556706939766801L;
|
private static final long serialVersionUID = -5957556706939766801L;
|
||||||
|
|
||||||
@ -70,8 +70,8 @@ public class StatusImpl implements Status {
|
|||||||
* @param cursor database cursor
|
* @param cursor database cursor
|
||||||
* @param account current user login information
|
* @param account current user login information
|
||||||
*/
|
*/
|
||||||
public StatusImpl(Cursor cursor, Account account) {
|
public DatabaseStatus(Cursor cursor, Account account) {
|
||||||
author = new UserImpl(cursor, account);
|
author = new DatabaseUser(cursor, account);
|
||||||
time = cursor.getLong(cursor.getColumnIndexOrThrow(StatusTable.TIME));
|
time = cursor.getLong(cursor.getColumnIndexOrThrow(StatusTable.TIME));
|
||||||
text = cursor.getString(cursor.getColumnIndexOrThrow(StatusTable.TEXT));
|
text = cursor.getString(cursor.getColumnIndexOrThrow(StatusTable.TEXT));
|
||||||
repostCount = cursor.getInt(cursor.getColumnIndexOrThrow(StatusTable.REPOST));
|
repostCount = cursor.getInt(cursor.getColumnIndexOrThrow(StatusTable.REPOST));
|
@ -12,7 +12,7 @@ import org.nuclearfog.twidda.model.Trend;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class TrendImpl implements Trend {
|
public class DatabaseTrend implements Trend {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1799880502954768985L;
|
private static final long serialVersionUID = 1799880502954768985L;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class TrendImpl implements Trend {
|
|||||||
/**
|
/**
|
||||||
* @param cursor database cursor using this {@link #COLUMNS} projection
|
* @param cursor database cursor using this {@link #COLUMNS} projection
|
||||||
*/
|
*/
|
||||||
public TrendImpl(Cursor cursor) {
|
public DatabaseTrend(Cursor cursor) {
|
||||||
name = cursor.getString(0);
|
name = cursor.getString(0);
|
||||||
popularity = cursor.getInt(1);
|
popularity = cursor.getInt(1);
|
||||||
rank = cursor.getInt(2);
|
rank = cursor.getInt(2);
|
@ -21,7 +21,7 @@ import org.nuclearfog.twidda.model.User;
|
|||||||
*
|
*
|
||||||
* @author nuclearfog
|
* @author nuclearfog
|
||||||
*/
|
*/
|
||||||
public class UserImpl implements User {
|
public class DatabaseUser implements User {
|
||||||
|
|
||||||
private static final long serialVersionUID = 2367055336838212570L;
|
private static final long serialVersionUID = 2367055336838212570L;
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ public class UserImpl implements User {
|
|||||||
* @param cursor database cursor containing user column
|
* @param cursor database cursor containing user column
|
||||||
* @param account current user login
|
* @param account current user login
|
||||||
*/
|
*/
|
||||||
public UserImpl(Cursor cursor, Account account) {
|
public DatabaseUser(Cursor cursor, Account account) {
|
||||||
id = cursor.getLong(cursor.getColumnIndexOrThrow(UserTable.ID));
|
id = cursor.getLong(cursor.getColumnIndexOrThrow(UserTable.ID));
|
||||||
username = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.USERNAME));
|
username = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.USERNAME));
|
||||||
screenName = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.SCREENNAME));
|
screenName = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.SCREENNAME));
|
@ -71,7 +71,7 @@ import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
|||||||
import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
|
import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
|
||||||
import org.nuclearfog.twidda.backend.utils.StringTools;
|
import org.nuclearfog.twidda.backend.utils.StringTools;
|
||||||
import org.nuclearfog.twidda.config.GlobalSettings;
|
import org.nuclearfog.twidda.config.GlobalSettings;
|
||||||
import org.nuclearfog.twidda.database.impl.UserImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseUser;
|
||||||
import org.nuclearfog.twidda.model.Relation;
|
import org.nuclearfog.twidda.model.Relation;
|
||||||
import org.nuclearfog.twidda.model.User;
|
import org.nuclearfog.twidda.model.User;
|
||||||
import org.nuclearfog.twidda.ui.adapter.FragmentAdapter;
|
import org.nuclearfog.twidda.ui.adapter.FragmentAdapter;
|
||||||
@ -251,7 +251,7 @@ public class ProfileActivity extends AppCompatActivity implements ActivityResult
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
UserParam param = new UserParam(UserParam.DATABASE, userId);
|
UserParam param = new UserParam(UserParam.DATABASE, userId);
|
||||||
userLoader.execute(param, this::setUserResult);
|
userLoader.execute(param, this::setUserResult);
|
||||||
} else if (user instanceof UserImpl) {
|
} else if (user instanceof DatabaseUser) {
|
||||||
UserParam param = new UserParam(UserParam.ONLINE, userId);
|
UserParam param = new UserParam(UserParam.ONLINE, userId);
|
||||||
userLoader.execute(param, this::setUserResult);
|
userLoader.execute(param, this::setUserResult);
|
||||||
setUser(user);
|
setUser(user);
|
||||||
|
@ -65,7 +65,7 @@ import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
|
|||||||
import org.nuclearfog.twidda.backend.utils.StringTools;
|
import org.nuclearfog.twidda.backend.utils.StringTools;
|
||||||
import org.nuclearfog.twidda.config.Configuration;
|
import org.nuclearfog.twidda.config.Configuration;
|
||||||
import org.nuclearfog.twidda.config.GlobalSettings;
|
import org.nuclearfog.twidda.config.GlobalSettings;
|
||||||
import org.nuclearfog.twidda.database.impl.StatusImpl;
|
import org.nuclearfog.twidda.database.impl.DatabaseStatus;
|
||||||
import org.nuclearfog.twidda.model.Card;
|
import org.nuclearfog.twidda.model.Card;
|
||||||
import org.nuclearfog.twidda.model.Location;
|
import org.nuclearfog.twidda.model.Location;
|
||||||
import org.nuclearfog.twidda.model.Media;
|
import org.nuclearfog.twidda.model.Media;
|
||||||
@ -274,12 +274,18 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
|
|||||||
if (status == null) {
|
if (status == null) {
|
||||||
StatusParam param = new StatusParam(StatusParam.ONLINE, id);
|
StatusParam param = new StatusParam(StatusParam.ONLINE, id);
|
||||||
statusAsync.execute(param, this::onStatusResult);
|
statusAsync.execute(param, this::onStatusResult);
|
||||||
} else if (status instanceof StatusImpl) {
|
} else {
|
||||||
|
if (status instanceof DatabaseStatus) {
|
||||||
|
setStatus(status);
|
||||||
StatusParam param = new StatusParam(StatusParam.ONLINE, status.getId());
|
StatusParam param = new StatusParam(StatusParam.ONLINE, status.getId());
|
||||||
statusAsync.execute(param, this::onStatusResult);
|
statusAsync.execute(param, this::onStatusResult);
|
||||||
setStatus(status);
|
|
||||||
} else {
|
} else {
|
||||||
setStatus(status);
|
setStatus(status);
|
||||||
|
if (status.getPoll() != null) {
|
||||||
|
VoteParam param = new VoteParam(VoteParam.LOAD, status.getPoll(), new int[0]);
|
||||||
|
voteAsync.execute(param, this::setPollResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,8 +677,8 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onVoteClick(Poll poll, int[] selection) {
|
public void onVoteClick(Poll poll, int[] selection) {
|
||||||
if (voteAsync == null || voteAsync.isIdle()) {
|
if (voteAsync.isIdle()) {
|
||||||
VoteParam param = new VoteParam(poll, selection);
|
VoteParam param = new VoteParam(VoteParam.VOTE, poll, selection);
|
||||||
voteAsync.execute(param, this::setPollResult);
|
voteAsync.execute(param, this::setPollResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -891,12 +897,24 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
|
|||||||
* @param result poll result
|
* @param result poll result
|
||||||
*/
|
*/
|
||||||
public void setPollResult(VoteResult result) {
|
public void setPollResult(VoteResult result) {
|
||||||
|
switch (result.mode) {
|
||||||
|
case VoteResult.LOAD:
|
||||||
|
if (result.poll != null) {
|
||||||
|
adapter.updatePoll(result.poll);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VoteResult.VOTE:
|
||||||
if (result.poll != null) {
|
if (result.poll != null) {
|
||||||
adapter.updatePoll(result.poll);
|
adapter.updatePoll(result.poll);
|
||||||
Toast.makeText(getApplicationContext(), R.string.info_poll_voted, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), R.string.info_poll_voted, Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VoteResult.ERROR:
|
||||||
String message = ErrorHandler.getErrorMessage(this, result.exception);
|
String message = ErrorHandler.getErrorMessage(this, result.exception);
|
||||||
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -76,12 +76,14 @@ public class PollHolder extends ViewHolder implements OnClickListener {
|
|||||||
public void setContent(Poll poll) {
|
public void setContent(Poll poll) {
|
||||||
if (poll.closed()) {
|
if (poll.closed()) {
|
||||||
votesCount.setText(R.string.poll_finished);
|
votesCount.setText(R.string.poll_finished);
|
||||||
} else if (poll.voted()) {
|
|
||||||
voteButton.setVisibility(View.INVISIBLE);
|
voteButton.setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
votesCount.setText(R.string.poll_total_votes);
|
votesCount.setText(R.string.poll_total_votes);
|
||||||
|
if (poll.voted()) {
|
||||||
|
voteButton.setVisibility(View.INVISIBLE);
|
||||||
} else if (poll.getLimit() > 0) {
|
} else if (poll.getLimit() > 0) {
|
||||||
voteButton.setVisibility(View.VISIBLE);
|
voteButton.setVisibility(View.VISIBLE);
|
||||||
votesCount.setText(R.string.poll_total_votes);
|
}
|
||||||
}
|
}
|
||||||
votesCount.append(StringTools.NUMBER_FORMAT.format(poll.voteCount()));
|
votesCount.append(StringTools.NUMBER_FORMAT.format(poll.voteCount()));
|
||||||
adapter.addAll(poll);
|
adapter.addAll(poll);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user