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

View File

@ -813,7 +813,7 @@ public class AppDatabase {
* get status/message media
*
* @param key media key
* @param db database read instance
* @param db database read instance
* @return media item or null
*/
@Nullable
@ -980,7 +980,7 @@ public class AppDatabase {
if (status.getMedia().length > 0) {
StringBuilder mediaBuf = new StringBuilder();
saveMedia(status.getMedia(), db);
for (Media media: status.getMedia()) {
for (Media media : status.getMedia()) {
mediaBuf.append(media.getKey()).append(';');
}
String mediaKeys = mediaBuf.deleteCharAt(mediaBuf.length() - 1).toString();
@ -995,7 +995,7 @@ public class AppDatabase {
* save media information
*
* @param medias media to save
* @param db database write instance
* @param db database write instance
*/
private void saveMedia(Media[] medias, SQLiteDatabase db) {
for (Media media : medias) {
@ -1012,7 +1012,7 @@ public class AppDatabase {
* save location information
*
* @param location location information to save
* @param db database write instance
* @param db database write instance
*/
private void saveLocation(Location location, SQLiteDatabase db) {
ContentValues locationColumn = new ContentValues(4);

View File

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

View File

@ -42,6 +42,20 @@ public class AccountImpl implements Account {
private String host;
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) {
this.user = user;
}
/**
* override hostname
*
* @param hostname new hostname
*/
public void setHost(String hostname) {
this.host = hostname;
}
}

View File

@ -35,8 +35,8 @@ public class LocationImpl implements Location {
private String place = "";
/**
* @param name place name
* @param id world id
* @param name place name
* @param id world id
*/
public LocationImpl(long id, String name) {
this.name = name;

View File

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

View File

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