bug fix, code cleanup
This commit is contained in:
parent
a3d8201d97
commit
0c37236116
|
@ -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 "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -813,7 +813,7 @@ public class AppDatabase {
|
||||||
* get status/message media
|
* get status/message media
|
||||||
*
|
*
|
||||||
* @param key media key
|
* @param key media key
|
||||||
* @param db database read instance
|
* @param db database read instance
|
||||||
* @return media item or null
|
* @return media item or null
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -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();
|
||||||
|
@ -995,7 +995,7 @@ public class AppDatabase {
|
||||||
* save media information
|
* save media information
|
||||||
*
|
*
|
||||||
* @param medias media to save
|
* @param medias media to save
|
||||||
* @param db database write instance
|
* @param db database write instance
|
||||||
*/
|
*/
|
||||||
private void saveMedia(Media[] medias, SQLiteDatabase db) {
|
private void saveMedia(Media[] medias, SQLiteDatabase db) {
|
||||||
for (Media media : medias) {
|
for (Media media : medias) {
|
||||||
|
@ -1012,7 +1012,7 @@ public class AppDatabase {
|
||||||
* save location information
|
* save location information
|
||||||
*
|
*
|
||||||
* @param location location information to save
|
* @param location location information to save
|
||||||
* @param db database write instance
|
* @param db database write instance
|
||||||
*/
|
*/
|
||||||
private void saveLocation(Location location, SQLiteDatabase db) {
|
private void saveLocation(Location location, SQLiteDatabase db) {
|
||||||
ContentValues locationColumn = new ContentValues(4);
|
ContentValues locationColumn = new ContentValues(4);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -35,8 +35,8 @@ public class LocationImpl implements Location {
|
||||||
private String place = "";
|
private String place = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name place name
|
* @param name place name
|
||||||
* @param id world id
|
* @param id world id
|
||||||
*/
|
*/
|
||||||
public LocationImpl(long id, String name) {
|
public LocationImpl(long id, String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue