bug fix, code cleanup

This commit is contained in:
nuclearfog 2022-12-22 16:06:16 +01:00
parent a3d8201d97
commit 0c37236116
No known key found for this signature in database
GPG Key ID: 03488A185C476379
7 changed files with 52 additions and 21 deletions

View File

@ -36,9 +36,9 @@ public class MastodonStatus implements Status {
private String text, source, mentions; private String text, source, mentions;
private User author; private User author;
private Card[] cards;
private Media[] medias;
private Poll poll; private Poll poll;
private Card[] cards = {};
private Media[] medias = {};
/** /**
* @param json Mastodon status json object * @param json Mastodon status json object
@ -92,8 +92,6 @@ public class MastodonStatus implements Status {
} }
if (cardJson != null) { if (cardJson != null) {
cards = new Card[]{new MastodonCard(cardJson)}; cards = new Card[]{new MastodonCard(cardJson)};
} else {
cards = new Card[0];
} }
try { try {
id = Long.parseLong(idStr); id = Long.parseLong(idStr);
@ -232,7 +230,7 @@ public class MastodonStatus implements Status {
@Override @Override
public String getLinkPath() { public String getLinkPath() {
if (!author.getScreenname().isEmpty()) { if (!author.getScreenname().isEmpty()) {
return '/' + author.getScreenname() + id; return '/' + author.getScreenname() + '/' + id;
} }
return ""; return "";
} }

View File

@ -980,7 +980,7 @@ public class AppDatabase {
if (status.getMedia().length > 0) { if (status.getMedia().length > 0) {
StringBuilder mediaBuf = new StringBuilder(); StringBuilder mediaBuf = new StringBuilder();
saveMedia(status.getMedia(), db); saveMedia(status.getMedia(), db);
for (Media media: status.getMedia()) { for (Media media : status.getMedia()) {
mediaBuf.append(media.getKey()).append(';'); mediaBuf.append(media.getKey()).append(';');
} }
String mediaKeys = mediaBuf.deleteCharAt(mediaBuf.length() - 1).toString(); String mediaKeys = mediaBuf.deleteCharAt(mediaBuf.length() - 1).toString();

View File

@ -554,7 +554,7 @@ public class GlobalSettings {
public Location getTrendLocation() { public Location getTrendLocation() {
if (account.getApiType() == Account.API_TWITTER) if (account.getApiType() == Account.API_TWITTER)
return location; return location;
return new LocationImpl( -1L, ""); return new LocationImpl(-1L, "");
} }
/** /**
@ -896,12 +896,12 @@ public class GlobalSettings {
/** /**
* save login information * save login information
* *
* @param account account information * @param login account information
* @param notify true to notify that settings changed * @param notify true to notify that settings changed
*/ */
public void setLogin(@Nullable Account account, boolean notify) { public void setLogin(@Nullable Account login, boolean notify) {
Editor e = settings.edit(); Editor e = settings.edit();
if (account == null) { if (login == null) {
loggedIn = false; loggedIn = false;
e.remove(LOGGED_IN); e.remove(LOGGED_IN);
e.remove(CURRENT_ID); e.remove(CURRENT_ID);
@ -912,18 +912,22 @@ public class GlobalSettings {
e.remove(BEARER_TOKEN); e.remove(BEARER_TOKEN);
e.remove(HOSTNAME); e.remove(HOSTNAME);
} else { } else {
this.account = account; AccountImpl account = new AccountImpl(login);
loggedIn = true; // setup alternative Twitter host
twitterAlt = false; if (account.getApiType() == Account.API_TWITTER && twitterAlt) {
e.putBoolean(LOGGED_IN, true); account.setHost(TWITTER_ALT_HOST);
}
e.putString(HOSTNAME, account.getHostname());
e.putLong(CURRENT_ID, account.getId()); e.putLong(CURRENT_ID, account.getId());
e.putString(OAUTH_TOKEN, account.getOauthToken()); e.putString(OAUTH_TOKEN, account.getOauthToken());
e.putString(OAUTH_SECRET, account.getOauthSecret()); e.putString(OAUTH_SECRET, account.getOauthSecret());
e.putString(CONSUMER_TOKEN, account.getConsumerToken()); e.putString(CONSUMER_TOKEN, account.getConsumerToken());
e.putString(CONSUMER_SECRET, account.getConsumerSecret()); e.putString(CONSUMER_SECRET, account.getConsumerSecret());
e.putString(BEARER_TOKEN, account.getBearerToken()); e.putString(BEARER_TOKEN, account.getBearerToken());
e.putString(HOSTNAME, account.getHostname());
e.putInt(CURRENT_API, account.getApiType()); e.putInt(CURRENT_API, account.getApiType());
e.putBoolean(LOGGED_IN, true);
this.account = account;
loggedIn = true;
} }
e.apply(); e.apply();
if (notify) { if (notify) {

View File

@ -42,6 +42,20 @@ 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();
apiType = account.getApiType();
}
/** /**
* *
*/ */
@ -155,4 +169,13 @@ 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;
}
} }

View File

@ -17,6 +17,7 @@ public class MediaImpl implements Media {
private static final long serialVersionUID = 8895107738679315263L; private static final long serialVersionUID = 8895107738679315263L;
/** /**
*
*/ */
public static final String[] PROJECTION = { public static final String[] PROJECTION = {
MediaTable.KEY, MediaTable.KEY,

View File

@ -41,26 +41,31 @@ public class TrendImpl implements Trend {
id = cursor.getLong(3); id = cursor.getLong(3);
} }
@Override @Override
public String getName() { public String getName() {
return name; return name;
} }
@Override @Override
public long getLocationId() { public long getLocationId() {
return id; return id;
} }
@Override @Override
public int getRank() { public int getRank() {
return rank; return rank;
} }
@Override @Override
public int getPopularity() { public int getPopularity() {
return range; return range;
} }
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {