mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-07 15:48:39 +01:00
fixed login handling, fixed database crash
This commit is contained in:
parent
17a64d4aa9
commit
0ac38c8293
@ -45,7 +45,7 @@ public class AccountAdapter extends Adapter<AccountHolder> implements OnHolderCl
|
||||
@NonNull
|
||||
@Override
|
||||
public AccountHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
final AccountHolder holder = new AccountHolder(parent, settings, picasso);
|
||||
AccountHolder holder = new AccountHolder(parent, settings, picasso);
|
||||
holder.setOnAccountClickListener(this);
|
||||
return holder;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class ImageAdapter extends Adapter<ViewHolder> implements OnHolderClickLi
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, int viewType) {
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_IMAGE) {
|
||||
ImageHolder item = new ImageHolder(parent, settings);
|
||||
item.setOnImageClickListener(this);
|
||||
|
@ -87,11 +87,11 @@ public class MessageAdapter extends Adapter<ViewHolder> implements OnItemClickLi
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == TYPE_MESSAGE) {
|
||||
final MessageHolder holder = new MessageHolder(parent, settings, picasso);
|
||||
MessageHolder holder = new MessageHolder(parent, settings, picasso);
|
||||
holder.setOnMessageClickListener(this);
|
||||
return holder;
|
||||
} else {
|
||||
final PlaceHolder placeHolder = new PlaceHolder(parent, settings, false);
|
||||
PlaceHolder placeHolder = new PlaceHolder(parent, settings, false);
|
||||
placeHolder.setOnHolderClickListener(this);
|
||||
return placeHolder;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class NotificationAdapter extends Adapter<ViewHolder> implements OnHolder
|
||||
holder.setOnStatusClickListener(this);
|
||||
return holder;
|
||||
} else if (viewType == TYPE_USER) {
|
||||
final UserHolder holder = new UserHolder(parent, settings, picasso);
|
||||
UserHolder holder = new UserHolder(parent, settings, picasso);
|
||||
holder.setOnUserClickListener(this);
|
||||
return holder;
|
||||
} else {
|
||||
|
@ -51,7 +51,7 @@ public class TrendAdapter extends Adapter<ViewHolder> implements OnHolderClickLi
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
final TrendHolder vh = new TrendHolder(parent, settings);
|
||||
TrendHolder vh = new TrendHolder(parent, settings);
|
||||
vh.setOnTrendClickListener(this);
|
||||
return vh;
|
||||
}
|
||||
|
@ -101,6 +101,12 @@ public class MastodonAccount implements Account {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean usingDefaultTokens() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -3,6 +3,7 @@ package org.nuclearfog.twidda.backend.api.twitter;
|
||||
import android.content.Context;
|
||||
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
import org.nuclearfog.twidda.model.Account;
|
||||
|
||||
import io.michaelrocks.paranoid.Obfuscate;
|
||||
|
||||
@ -59,9 +60,10 @@ public class Tokens {
|
||||
* @return consumer API key
|
||||
*/
|
||||
public String getConsumerKey(boolean forceDefault) {
|
||||
if (settings.isCustomApiSet() && !forceDefault)
|
||||
return settings.getLogin().getConsumerToken();
|
||||
return CONSUMER_TOKEN;
|
||||
Account login = settings.getLogin();
|
||||
if (login.usingDefaultTokens() || forceDefault)
|
||||
return CONSUMER_TOKEN;
|
||||
return login.getConsumerToken();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,8 +73,9 @@ public class Tokens {
|
||||
* @return consumer secret API key
|
||||
*/
|
||||
public String getConsumerSecret(boolean forceDefault) {
|
||||
if (settings.isCustomApiSet() && !forceDefault)
|
||||
return settings.getLogin().getConsumerSecret();
|
||||
return TOKEN_SECRET;
|
||||
Account login = settings.getLogin();
|
||||
if (login.usingDefaultTokens() || forceDefault)
|
||||
return TOKEN_SECRET;
|
||||
return login.getConsumerSecret();
|
||||
}
|
||||
}
|
@ -107,6 +107,12 @@ public class TwitterAccount implements Account {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean usingDefaultTokens() {
|
||||
return consumerToken == null || consumerToken.isEmpty() || consumerSecret == null || consumerSecret.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -103,9 +103,9 @@ public final class ErrorHandler {
|
||||
case ConnectionException.APP_SUSPENDED:
|
||||
case ConnectionException.ERROR_API_ACCESS_DENIED:
|
||||
GlobalSettings settings = GlobalSettings.getInstance(context);
|
||||
if (settings.isCustomApiSet())
|
||||
return context.getString(R.string.error_api_access_denied);
|
||||
return context.getString(R.string.error_api_key_expired);
|
||||
if (settings.getLogin().usingDefaultTokens())
|
||||
return context.getString(R.string.error_api_key_expired);
|
||||
return context.getString(R.string.error_api_access_denied);
|
||||
|
||||
case ConnectionException.ERROR_NOT_DEFINED:
|
||||
return error.getMessage();
|
||||
|
@ -212,12 +212,9 @@ public class AppDatabase {
|
||||
|
||||
/**
|
||||
* SQL query to get notifications
|
||||
* todo find a better way to query notification, statuses and users with one command
|
||||
*/
|
||||
private static final String NOTIFICATION_QUERY = "SELECT * FROM " + NotificationTable.NAME
|
||||
+ " LEFT JOIN (SELECT * FROM " + USER_SUBQUERY + ") " + UserTable.NAME
|
||||
+ " ON " + UserTable.NAME + "." + UserTable.ID + "=" + NotificationTable.NAME + "." + NotificationTable.ITEM
|
||||
+ " LEFT JOIN (SELECT * FROM " + STATUS_SUBQUERY + ") " + StatusTable.NAME
|
||||
+ " ON " + StatusTable.NAME + "." + StatusTable.ID + "=" + NotificationTable.NAME + "." + NotificationTable.ITEM
|
||||
+ " WHERE " + NotificationTable.NAME + "." + NotificationTable.OWNER + "=?"
|
||||
+ " ORDER BY " + NotificationTable.ID + " DESC LIMIT ?;";
|
||||
|
||||
@ -324,7 +321,7 @@ public class AppDatabase {
|
||||
public void saveHomeTimeline(List<Status> home) {
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
for (Status status : home)
|
||||
saveStatus(status, HOME_TIMELINE_MASK, db);
|
||||
saveStatus(status, db, HOME_TIMELINE_MASK);
|
||||
commit(db);
|
||||
}
|
||||
|
||||
@ -336,7 +333,7 @@ public class AppDatabase {
|
||||
public void saveUserTimeline(List<Status> stats) {
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
for (Status status : stats)
|
||||
saveStatus(status, USER_TIMELINE_MASK, db);
|
||||
saveStatus(status, db, USER_TIMELINE_MASK);
|
||||
commit(db);
|
||||
}
|
||||
|
||||
@ -350,7 +347,7 @@ public class AppDatabase {
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
removeOldFavorites(db, ownerId);
|
||||
for (Status status : fav) {
|
||||
saveStatus(status, 0, db);
|
||||
saveStatus(status, db, 0);
|
||||
saveFavorite(status.getId(), ownerId, db);
|
||||
}
|
||||
commit(db);
|
||||
@ -364,7 +361,7 @@ public class AppDatabase {
|
||||
public void saveReplyTimeline(List<Status> replies) {
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
for (Status status : replies)
|
||||
saveStatus(status, STATUS_REPLY_MASK, db);
|
||||
saveStatus(status, db, STATUS_REPLY_MASK);
|
||||
commit(db);
|
||||
}
|
||||
|
||||
@ -397,7 +394,7 @@ public class AppDatabase {
|
||||
if (status.getEmbeddedStatus() != null)
|
||||
status = status.getEmbeddedStatus();
|
||||
SQLiteDatabase db = getDbWrite();
|
||||
saveStatus(status, 0, db);
|
||||
saveStatus(status, db, 0);
|
||||
saveFavorite(status.getId(), settings.getLogin().getId(), db);
|
||||
commit(db);
|
||||
}
|
||||
@ -414,13 +411,14 @@ public class AppDatabase {
|
||||
column.put(NotificationTable.TYPE, notification.getType());
|
||||
column.put(NotificationTable.OWNER, settings.getLogin().getId());
|
||||
if (notification.getStatus() != null) {
|
||||
saveStatus(notification.getStatus(), NOTIFICATION_MASK, db);
|
||||
saveStatus(notification.getStatus(), db, NOTIFICATION_MASK);
|
||||
column.put(NotificationTable.ITEM, notification.getStatus().getId());
|
||||
db.insertWithOnConflict(NotificationTable.NAME, null, column, CONFLICT_REPLACE);
|
||||
} else if (notification.getUser() != null) {
|
||||
saveUser(notification.getUser());
|
||||
saveUser(notification.getUser(), db, CONFLICT_REPLACE);
|
||||
column.put(NotificationTable.ITEM, notification.getUser().getId());
|
||||
db.insertWithOnConflict(NotificationTable.NAME, null, column, CONFLICT_REPLACE);
|
||||
}
|
||||
db.insertWithOnConflict(NotificationTable.NAME, null, column, CONFLICT_REPLACE);
|
||||
}
|
||||
commit(db);
|
||||
}
|
||||
@ -513,8 +511,12 @@ public class AppDatabase {
|
||||
*/
|
||||
@Nullable
|
||||
public User getUser(long userId) {
|
||||
String[] args = {Long.toString(userId)};
|
||||
SQLiteDatabase db = getDbRead();
|
||||
return getUser(userId, db);
|
||||
Cursor cursor = db.rawQuery(SINGLE_USER_QUERY, args);
|
||||
User user = getUser(cursor);
|
||||
cursor.close();
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -551,8 +553,7 @@ public class AppDatabase {
|
||||
List<Status> result = new LinkedList<>();
|
||||
Cursor cursor = db.rawQuery(REPLY_QUERY, args);
|
||||
if (cursor.moveToFirst()) {
|
||||
do
|
||||
{
|
||||
do {
|
||||
Status status = getStatus(cursor);
|
||||
result.add(status);
|
||||
} while (cursor.moveToNext());
|
||||
@ -572,8 +573,7 @@ public class AppDatabase {
|
||||
List<Notification> result = new LinkedList<>();
|
||||
Cursor cursor = db.rawQuery(NOTIFICATION_QUERY, args);
|
||||
if (cursor.moveToFirst()) {
|
||||
do
|
||||
{
|
||||
do {
|
||||
NotificationImpl notification = new NotificationImpl(cursor);
|
||||
switch (notification.getType()) {
|
||||
case Notification.TYPE_FAVORITE:
|
||||
@ -582,18 +582,20 @@ public class AppDatabase {
|
||||
case Notification.TYPE_POLL:
|
||||
case Notification.TYPE_STATUS:
|
||||
case Notification.TYPE_UPDATE:
|
||||
Status status = getStatus(cursor);
|
||||
Status status = getStatus(notification.getItemId());
|
||||
notification.addStatus(status);
|
||||
break;
|
||||
|
||||
case Notification.TYPE_FOLLOW:
|
||||
case Notification.TYPE_REQUEST:
|
||||
User user = getUser(cursor);
|
||||
User user = getUser(notification.getItemId());
|
||||
notification.addUser(user);
|
||||
break;
|
||||
|
||||
}
|
||||
result.add(notification);
|
||||
if (notification.getUser() != null || notification.getStatus() != null) {
|
||||
result.add(notification);
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
cursor.close();
|
||||
@ -715,8 +717,7 @@ public class AppDatabase {
|
||||
SQLiteDatabase db = getDbRead();
|
||||
Cursor cursor = db.rawQuery(MESSAGE_QUERY, args);
|
||||
if (cursor.moveToFirst()) {
|
||||
do
|
||||
{
|
||||
do {
|
||||
result.add(new MessageImpl(cursor, currentId));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
@ -731,8 +732,12 @@ public class AppDatabase {
|
||||
* @return true if found
|
||||
*/
|
||||
public boolean containsStatus(long id) {
|
||||
String[] args = {Long.toString(id)};
|
||||
SQLiteDatabase db = getDbRead();
|
||||
return statusExists(id, db);
|
||||
Cursor c = db.query(StatusTable.NAME, null, STATUS_SELECT, args, null, null, SINGLE_ITEM);
|
||||
boolean result = c.moveToFirst();
|
||||
c.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -812,20 +817,6 @@ public class AppDatabase {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* get user information from table
|
||||
*
|
||||
* @param userId Id of the user
|
||||
* @param db SQLITE DB
|
||||
* @return user instance
|
||||
*/
|
||||
@Nullable
|
||||
private User getUser(long userId, SQLiteDatabase db) {
|
||||
String[] args = {Long.toString(userId)};
|
||||
Cursor cursor = db.rawQuery(SINGLE_USER_QUERY, args);
|
||||
return getUser(cursor);
|
||||
}
|
||||
|
||||
/**
|
||||
* get user from cursor
|
||||
*
|
||||
@ -834,11 +825,9 @@ public class AppDatabase {
|
||||
*/
|
||||
@Nullable
|
||||
private User getUser(Cursor cursor) {
|
||||
User user = null;
|
||||
if (cursor.moveToFirst())
|
||||
user = new UserImpl(cursor, settings.getLogin().getId());
|
||||
cursor.close();
|
||||
return user;
|
||||
return new UserImpl(cursor, settings.getLogin().getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -894,12 +883,12 @@ public class AppDatabase {
|
||||
* @param statusFlags predefined status status register or zero if there isn't one
|
||||
* @param db SQLite database
|
||||
*/
|
||||
private void saveStatus(Status status, int statusFlags, SQLiteDatabase db) {
|
||||
private void saveStatus(Status status, SQLiteDatabase db, int statusFlags) {
|
||||
User user = status.getAuthor();
|
||||
Status rtStat = status.getEmbeddedStatus();
|
||||
long rtId = -1L;
|
||||
if (rtStat != null) {
|
||||
saveStatus(rtStat, 0, db);
|
||||
saveStatus(rtStat, db, 0);
|
||||
rtId = rtStat.getId();
|
||||
}
|
||||
statusFlags |= getStatusRegister(db, status.getId());
|
||||
@ -1074,22 +1063,6 @@ public class AppDatabase {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if status exists in database
|
||||
*
|
||||
* @param id status ID
|
||||
* @param db database instance
|
||||
* @return true if found
|
||||
*/
|
||||
private boolean statusExists(long id, SQLiteDatabase db) {
|
||||
String[] args = {Long.toString(id)};
|
||||
|
||||
Cursor c = db.query(StatusTable.NAME, null, STATUS_SELECT, args, null, null, SINGLE_ITEM);
|
||||
boolean result = c.moveToFirst();
|
||||
c.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQLite instance for reading database
|
||||
*
|
||||
|
@ -118,7 +118,6 @@ public class GlobalSettings {
|
||||
private static final String ENABLE_LIKE = "like_enable";
|
||||
private static final String ENABLE_TWITTER_ALT = "twitter_alt_set";
|
||||
private static final String FILTER_RESULTS = "filter_results";
|
||||
private static final String CUSTOM_CONSUMER_KEYS = "custom_api_keys";
|
||||
private static final String CONSUMER_TOKEN = "api_key1";
|
||||
private static final String CONSUMER_SECRET = "api_key2";
|
||||
private static final String BEARER_TOKEN = "bearer";
|
||||
@ -166,7 +165,6 @@ public class GlobalSettings {
|
||||
private boolean isProxyEnabled;
|
||||
private boolean isProxyAuthSet;
|
||||
private boolean ignoreProxyWarning;
|
||||
private boolean customAPIKey;
|
||||
private boolean toolbarOverlap;
|
||||
private boolean linkPreview;
|
||||
private boolean tweetIndicators;
|
||||
@ -959,15 +957,6 @@ public class GlobalSettings {
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if custom API consumer keys are set
|
||||
*
|
||||
* @return true if custom API keys are set
|
||||
*/
|
||||
public boolean isCustomApiSet() {
|
||||
return customAPIKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* get login information
|
||||
*
|
||||
@ -987,9 +976,7 @@ public class GlobalSettings {
|
||||
Editor e = settings.edit();
|
||||
if (account == null) {
|
||||
loggedIn = false;
|
||||
customAPIKey = false;
|
||||
e.remove(LOGGED_IN);
|
||||
e.remove(CUSTOM_CONSUMER_KEYS);
|
||||
e.remove(CURRENT_ID);
|
||||
e.remove(OAUTH_TOKEN);
|
||||
e.remove(OAUTH_SECRET);
|
||||
@ -1000,9 +987,7 @@ public class GlobalSettings {
|
||||
} else {
|
||||
this.account = account;
|
||||
loggedIn = true;
|
||||
customAPIKey = !account.getConsumerToken().isEmpty() && !account.getConsumerToken().isEmpty();
|
||||
e.putBoolean(LOGGED_IN, true);
|
||||
e.putBoolean(CUSTOM_CONSUMER_KEYS, customAPIKey);
|
||||
e.putLong(CURRENT_ID, account.getId());
|
||||
e.putString(OAUTH_TOKEN, account.getOauthToken());
|
||||
e.putString(OAUTH_SECRET, account.getOauthSecret());
|
||||
@ -1070,7 +1055,6 @@ public class GlobalSettings {
|
||||
linkPreview = settings.getBoolean(LINK_PREVIEW, false);
|
||||
filterResults = settings.getBoolean(FILTER_RESULTS, true);
|
||||
enableLike = settings.getBoolean(ENABLE_LIKE, false);
|
||||
customAPIKey = settings.getBoolean(CUSTOM_CONSUMER_KEYS, false);
|
||||
twitterAlt = settings.getBoolean(ENABLE_TWITTER_ALT, false);
|
||||
proxyHost = settings.getString(PROXY_ADDR, "");
|
||||
proxyPort = settings.getString(PROXY_PORT, "");
|
||||
|
@ -38,7 +38,6 @@ public class AccountImpl implements Account {
|
||||
private String consumerToken, consumerSecret;
|
||||
private String bearerToken;
|
||||
private String host;
|
||||
|
||||
private User user;
|
||||
|
||||
/**
|
||||
@ -125,12 +124,21 @@ public class AccountImpl implements Account {
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getApiType() {
|
||||
return apiType;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean usingDefaultTokens() {
|
||||
if (apiType != API_TWITTER)
|
||||
return false;
|
||||
return consumerToken == null || consumerToken.isEmpty() || consumerSecret == null || consumerSecret.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -18,7 +18,7 @@ public class NotificationImpl implements Notification {
|
||||
|
||||
private static final long serialVersionUID = 436155941776152806L;
|
||||
|
||||
private long id, timestamp;
|
||||
private long id, timestamp, itemId;
|
||||
private int type;
|
||||
|
||||
private User user;
|
||||
@ -29,6 +29,7 @@ public class NotificationImpl implements Notification {
|
||||
*/
|
||||
public NotificationImpl(Cursor cursor) {
|
||||
id = cursor.getLong(cursor.getColumnIndexOrThrow(NotificationTable.ID));
|
||||
itemId = cursor.getLong(cursor.getColumnIndexOrThrow(NotificationTable.ITEM));
|
||||
type = cursor.getInt(cursor.getColumnIndexOrThrow(NotificationTable.TYPE));
|
||||
timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(NotificationTable.DATE));
|
||||
}
|
||||
@ -81,4 +82,13 @@ public class NotificationImpl implements Notification {
|
||||
public void addStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* get ID of the attached item (user/status ID)
|
||||
*
|
||||
* @return item ID
|
||||
*/
|
||||
public long getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
}
|
@ -10,7 +10,8 @@ import android.database.Cursor;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.database.DatabaseAdapter;
|
||||
import org.nuclearfog.twidda.database.DatabaseAdapter.UserRegisterTable;
|
||||
import org.nuclearfog.twidda.database.DatabaseAdapter.UserTable;
|
||||
import org.nuclearfog.twidda.model.User;
|
||||
|
||||
/**
|
||||
@ -43,20 +44,20 @@ public class UserImpl implements User {
|
||||
|
||||
|
||||
public UserImpl(Cursor cursor, long currentUserId) {
|
||||
id = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.ID));
|
||||
username = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.USERNAME));
|
||||
screenName = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.SCREENNAME));
|
||||
profileImg = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.IMAGE));
|
||||
bio = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.DESCRIPTION));
|
||||
link = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.LINK));
|
||||
location = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.LOCATION));
|
||||
bannerImg = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.BANNER));
|
||||
created = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.SINCE));
|
||||
following = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.FRIENDS));
|
||||
follower = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.FOLLOWER));
|
||||
statusCount = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.STATUSES));
|
||||
favorCount = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserTable.FAVORITS));
|
||||
int register = cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseAdapter.UserRegisterTable.REGISTER));
|
||||
id = cursor.getLong(cursor.getColumnIndexOrThrow(UserTable.ID));
|
||||
username = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.USERNAME));
|
||||
screenName = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.SCREENNAME));
|
||||
profileImg = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.IMAGE));
|
||||
bio = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.DESCRIPTION));
|
||||
link = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.LINK));
|
||||
location = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.LOCATION));
|
||||
bannerImg = cursor.getString(cursor.getColumnIndexOrThrow(UserTable.BANNER));
|
||||
created = cursor.getLong(cursor.getColumnIndexOrThrow(UserTable.SINCE));
|
||||
following = cursor.getInt(cursor.getColumnIndexOrThrow(UserTable.FRIENDS));
|
||||
follower = cursor.getInt(cursor.getColumnIndexOrThrow(UserTable.FOLLOWER));
|
||||
statusCount = cursor.getInt(cursor.getColumnIndexOrThrow(UserTable.STATUSES));
|
||||
favorCount = cursor.getInt(cursor.getColumnIndexOrThrow(UserTable.FAVORITS));
|
||||
int register = cursor.getInt(cursor.getColumnIndexOrThrow(UserRegisterTable.REGISTER));
|
||||
isVerified = (register & VERIFIED_MASK) != 0;
|
||||
isLocked = (register & LOCKED_MASK) != 0;
|
||||
followReqSent = (register & FOLLOW_REQUEST_MASK) != 0;
|
||||
|
@ -70,4 +70,12 @@ public interface Account {
|
||||
* @return type of the ID {@link #API_TWITTER}
|
||||
*/
|
||||
int getApiType();
|
||||
|
||||
/**
|
||||
* return true if the account uses the app default API tokens
|
||||
* currently only used by Twitter logins
|
||||
*
|
||||
* @return true if this account uses default app integrated API tokens
|
||||
*/
|
||||
boolean usingDefaultTokens();
|
||||
}
|
@ -114,41 +114,25 @@ public class LoginActivity extends AppCompatActivity implements OnClickListener,
|
||||
settings = GlobalSettings.getInstance(this);
|
||||
toolbar.setTitle(R.string.login_info);
|
||||
setSupportActionBar(toolbar);
|
||||
pinInput.setCompoundDrawablesWithIntrinsicBounds(R.drawable.key, 0, 0, 0);
|
||||
//pinInput.setCompoundDrawablesWithIntrinsicBounds(R.drawable.key, 0, 0, 0);
|
||||
NetworkAdapter adapter = new NetworkAdapter(this);
|
||||
hostSelector.setAdapter(adapter);
|
||||
hostSelector.setSelection(0);
|
||||
|
||||
if (settings.isCustomApiSet() || !Tokens.USE_DEFAULT_KEYS) {
|
||||
apiSwitch.setCheckedImmediately(true);
|
||||
// force using custom API tokens
|
||||
if (!Tokens.USE_DEFAULT_KEYS) {
|
||||
apiSwitch.setVisibility(View.GONE);
|
||||
switchLabel.setVisibility(View.GONE);
|
||||
}
|
||||
// use custom API tokens if there were set in a previously login
|
||||
Account login = settings.getLogin();
|
||||
if (login.getApiType() == Account.API_TWITTER) {
|
||||
apiKey1.setText(login.getConsumerToken());
|
||||
apiKey2.setText(login.getConsumerSecret());
|
||||
}
|
||||
} else {
|
||||
apiKey1.setVisibility(View.INVISIBLE);
|
||||
apiKey2.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
AppStyles.setTheme(root, settings.getBackgroundColor());
|
||||
|
||||
linkButton.setOnClickListener(this);
|
||||
loginButton.setOnClickListener(this);
|
||||
hostSelector.setOnItemSelectedListener(this);
|
||||
apiSwitch.setOnCheckedChangeListener(this);
|
||||
|
||||
apiKey1.addTextChangedListener(this);
|
||||
apiKey2.addTextChangedListener(this);
|
||||
apiHost.addTextChangedListener(this);
|
||||
|
||||
// set default result code
|
||||
setResult(RESULT_CANCELED);
|
||||
// set input layout
|
||||
setInput();
|
||||
}
|
||||
|
||||
|
||||
@ -316,34 +300,7 @@ public class LoginActivity extends AppCompatActivity implements OnClickListener,
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
// reset login link after provider change
|
||||
loginLink = null;
|
||||
// twitter selected
|
||||
if (id == NetworkAdapter.ID_TWITTER) {
|
||||
apiHost.setVisibility(View.GONE);
|
||||
pinInput.setInputType(EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||
if (Tokens.USE_DEFAULT_KEYS) {
|
||||
apiSwitch.setVisibility(View.VISIBLE);
|
||||
switchLabel.setVisibility(View.VISIBLE);
|
||||
if (apiSwitch.isChecked()) {
|
||||
apiKey1.setVisibility(View.VISIBLE);
|
||||
apiKey2.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
apiKey1.setVisibility(View.INVISIBLE);
|
||||
apiKey2.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
} else {
|
||||
apiKey1.setVisibility(View.VISIBLE);
|
||||
apiKey2.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
// mastodon selected
|
||||
else if (id == NetworkAdapter.ID_MASTODON) {
|
||||
pinInput.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
apiSwitch.setVisibility(View.GONE);
|
||||
switchLabel.setVisibility(View.GONE);
|
||||
apiKey1.setVisibility(View.GONE);
|
||||
apiKey2.setVisibility(View.GONE);
|
||||
apiHost.setVisibility(View.VISIBLE);
|
||||
}
|
||||
setInput();
|
||||
}
|
||||
|
||||
|
||||
@ -403,4 +360,51 @@ public class LoginActivity extends AppCompatActivity implements OnClickListener,
|
||||
Toast.makeText(this, R.string.error_open_link, LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setInput() {
|
||||
long id = hostSelector.getSelectedItemId();
|
||||
if (id == NetworkAdapter.ID_TWITTER) {
|
||||
// disable Mastodon input
|
||||
apiHost.setVisibility(View.GONE);
|
||||
pinInput.setInputType(EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||
// check if app contains default API keys
|
||||
if (Tokens.USE_DEFAULT_KEYS) {
|
||||
apiSwitch.setVisibility(View.VISIBLE);
|
||||
switchLabel.setVisibility(View.VISIBLE);
|
||||
// set key input visibility depending on API switch
|
||||
if (apiSwitch.isChecked()) {
|
||||
apiKey1.setVisibility(View.VISIBLE);
|
||||
apiKey2.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
apiKey1.setVisibility(View.INVISIBLE);
|
||||
apiKey2.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
// if not, force Twitter API key input
|
||||
else {
|
||||
apiKey1.setVisibility(View.VISIBLE);
|
||||
apiKey2.setVisibility(View.VISIBLE);
|
||||
apiSwitch.setVisibility(View.GONE);
|
||||
switchLabel.setVisibility(View.GONE);
|
||||
}
|
||||
// add API keys from previous Twitter login if exists
|
||||
Account login = settings.getLogin();
|
||||
if (!login.usingDefaultTokens()) {
|
||||
apiKey1.setText(login.getConsumerToken());
|
||||
apiKey2.setText(login.getConsumerSecret());
|
||||
}
|
||||
}
|
||||
// mastodon selected
|
||||
else if (id == NetworkAdapter.ID_MASTODON) {
|
||||
// setup Mastodon input
|
||||
pinInput.setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
apiHost.setVisibility(View.VISIBLE);
|
||||
// disable Twitter input
|
||||
apiSwitch.setVisibility(View.GONE);
|
||||
switchLabel.setVisibility(View.GONE);
|
||||
apiKey1.setVisibility(View.GONE);
|
||||
apiKey2.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
@ -187,6 +187,7 @@
|
||||
android:maxLines="1"
|
||||
android:layout_marginEnd="@dimen/loginpage_layout_margin"
|
||||
android:ellipsize="end"
|
||||
android:drawableStart="@drawable/key"
|
||||
app:layout_constraintWidth_percent="0.5"
|
||||
app:layout_constraintStart_toEndOf="@id/login_third_opt"
|
||||
app:layout_constraintTop_toBottomOf="@id/login_get_link"
|
||||
|
Loading…
x
Reference in New Issue
Block a user