mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-30 19:05:02 +01:00
bug fix, database fix, restructured api package
This commit is contained in:
parent
d3a56ddf2a
commit
24df192a09
@ -6,8 +6,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.backend.api.mastodon.Mastodon;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v1.TwitterV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.TwitterV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.TwitterV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.TwitterV2;
|
||||
import org.nuclearfog.twidda.config.Configuration;
|
||||
import org.nuclearfog.twidda.config.GlobalSettings;
|
||||
import org.nuclearfog.twidda.config.GlobalSettings.OnSettingsChangeListener;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
@ -14,6 +14,15 @@ import org.nuclearfog.twidda.backend.api.Connection;
|
||||
import org.nuclearfog.twidda.backend.api.ConnectionException;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.Tokens;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.TwitterException;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.AccountV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.LocationV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.MessageV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.NotificationV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.RelationV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.TrendV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.TweetV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.UserListV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.UserV1;
|
||||
import org.nuclearfog.twidda.backend.helper.ConnectionConfig;
|
||||
import org.nuclearfog.twidda.backend.helper.MediaStatus;
|
||||
import org.nuclearfog.twidda.backend.helper.Messages;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import android.util.Patterns;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -6,6 +6,7 @@ import androidx.annotation.Nullable;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.MediaV1;
|
||||
import org.nuclearfog.twidda.model.Media;
|
||||
import org.nuclearfog.twidda.model.Message;
|
||||
import org.nuclearfog.twidda.model.User;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v1;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
|
||||
|
||||
import android.util.Patterns;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
@ -9,11 +9,17 @@ import org.json.JSONObject;
|
||||
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.impl.v1.TwitterV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.LocationV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.MediaV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.PollV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.UserV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.TwitterV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.AccountV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.LocationV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.MediaV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.PollV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.TweetV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.UserV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.LocationV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.MediaV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.PollV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.UserV2Map;
|
||||
import org.nuclearfog.twidda.backend.helper.ConnectionConfig;
|
||||
import org.nuclearfog.twidda.backend.helper.Users;
|
||||
import org.nuclearfog.twidda.backend.utils.StringTools;
|
@ -1,6 +1,6 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v1.AccountV1;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v1.impl.AccountV1;
|
||||
import org.nuclearfog.twidda.config.Configuration;
|
||||
import org.nuclearfog.twidda.model.Account;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import android.util.Patterns;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -6,10 +6,10 @@ import androidx.annotation.Nullable;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.LocationV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.MediaV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.PollV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps.UserV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.LocationV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.MediaV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.PollV2Map;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.maps.UserV2Map;
|
||||
import org.nuclearfog.twidda.backend.utils.StringTools;
|
||||
import org.nuclearfog.twidda.model.Card;
|
||||
import org.nuclearfog.twidda.model.Emoji;
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import android.util.Patterns;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
|
||||
|
||||
import android.util.Patterns;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.maps;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.LocationV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.LocationV2;
|
||||
import org.nuclearfog.twidda.model.Location;
|
||||
|
||||
import java.util.TreeMap;
|
@ -1,11 +1,11 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.maps;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.MediaV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.MediaV2;
|
||||
import org.nuclearfog.twidda.model.Media;
|
||||
|
||||
import java.util.TreeMap;
|
@ -1,11 +1,11 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.maps;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.PollV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.PollV2;
|
||||
import org.nuclearfog.twidda.model.Poll;
|
||||
|
||||
import java.util.TreeMap;
|
@ -1,11 +1,11 @@
|
||||
package org.nuclearfog.twidda.backend.api.twitter.impl.v2.maps;
|
||||
package org.nuclearfog.twidda.backend.api.twitter.v2.maps;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.impl.v2.UserV2;
|
||||
import org.nuclearfog.twidda.backend.api.twitter.v2.impl.UserV2;
|
||||
import org.nuclearfog.twidda.model.User;
|
||||
|
||||
import java.util.TreeMap;
|
@ -12,10 +12,11 @@ import org.nuclearfog.twidda.config.Configuration;
|
||||
public class ConnectionConfig {
|
||||
|
||||
private Configuration apiConfig;
|
||||
private String consumerKey = "";
|
||||
private String consumerSecret = "";
|
||||
private String hostname = "";
|
||||
private String tempOauth = "";
|
||||
// these attributes below may be changed by another (background) thread
|
||||
private volatile String consumerKey = "";
|
||||
private volatile String consumerSecret = "";
|
||||
private volatile String tempOauth = "";
|
||||
|
||||
/**
|
||||
* get host url used by the API
|
||||
|
@ -293,7 +293,7 @@ public class DatabaseAdapter {
|
||||
/**
|
||||
* singleton instance
|
||||
*/
|
||||
private static final DatabaseAdapter INSTANCE = new DatabaseAdapter();
|
||||
private static DatabaseAdapter instance;
|
||||
|
||||
/**
|
||||
* path to the database file
|
||||
@ -305,41 +305,16 @@ public class DatabaseAdapter {
|
||||
*/
|
||||
private SQLiteDatabase db;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private DatabaseAdapter() {
|
||||
}
|
||||
|
||||
private volatile boolean lock = false;
|
||||
|
||||
/**
|
||||
* get database adapter instance
|
||||
*
|
||||
* @param context application context
|
||||
* @return database instance
|
||||
*/
|
||||
public static DatabaseAdapter getInstance(@NonNull Context context) {
|
||||
if (INSTANCE.db == null) {
|
||||
try {
|
||||
INSTANCE.init(context.getApplicationContext());
|
||||
} catch (SQLiteException e) {
|
||||
// if database is corrupted, clear and create a new one
|
||||
e.printStackTrace();
|
||||
SQLiteDatabase.deleteDatabase(INSTANCE.databasePath);
|
||||
INSTANCE.init(context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize databases
|
||||
*
|
||||
* @param c application context
|
||||
*/
|
||||
private void init(Context c) {
|
||||
private DatabaseAdapter(Context context) {
|
||||
// fetch database information
|
||||
databasePath = c.getDatabasePath(DB_NAME);
|
||||
db = c.openOrCreateDatabase(databasePath.toString(), MODE_PRIVATE, null);
|
||||
databasePath = context.getDatabasePath(DB_NAME);
|
||||
db = context.openOrCreateDatabase(databasePath.toString(), MODE_PRIVATE, null);
|
||||
// create tables if not exist
|
||||
db.execSQL(TABLE_USER);
|
||||
db.execSQL(TABLE_STATUS);
|
||||
@ -405,12 +380,40 @@ public class DatabaseAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get database adapter instance
|
||||
*
|
||||
* @param context application context
|
||||
* @return database instance
|
||||
*/
|
||||
public static DatabaseAdapter getInstance(@NonNull Context context) {
|
||||
if (instance == null) {
|
||||
try {
|
||||
instance = new DatabaseAdapter(context.getApplicationContext());
|
||||
} catch (SQLiteException e) {
|
||||
// if database is corrupted, clear and create a new one
|
||||
e.printStackTrace();
|
||||
SQLiteDatabase.deleteDatabase(instance.databasePath);
|
||||
instance = new DatabaseAdapter(context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SQLite instance for reading database
|
||||
*
|
||||
* @return SQLite instance
|
||||
*/
|
||||
SQLiteDatabase getDbRead() {
|
||||
int wait = 0;
|
||||
while (lock && wait++ < 10) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
if (!db.isOpen())
|
||||
db = SQLiteDatabase.openOrCreateDatabase(databasePath, null);
|
||||
return db;
|
||||
@ -422,8 +425,8 @@ public class DatabaseAdapter {
|
||||
* @return SQLite instance
|
||||
*/
|
||||
SQLiteDatabase getDbWrite() {
|
||||
if (!db.isOpen()) // todo implement database lock
|
||||
db = SQLiteDatabase.openOrCreateDatabase(databasePath, null);
|
||||
SQLiteDatabase db = getDbRead();
|
||||
lock = true;
|
||||
db.beginTransaction();
|
||||
return db;
|
||||
}
|
||||
@ -434,6 +437,7 @@ public class DatabaseAdapter {
|
||||
void commit() {
|
||||
db.setTransactionSuccessful();
|
||||
db.endTransaction();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,13 +78,6 @@ public class AccountAdapter extends Adapter<AccountHolder> implements OnHolderCl
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if adapter doesn't contain any items
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return accounts.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets login data
|
||||
*
|
||||
|
@ -152,13 +152,6 @@ public class MessageAdapter extends Adapter<ViewHolder> implements OnItemClickLi
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if adapter doesn't contain any items
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return messages.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* set messages
|
||||
*
|
||||
|
@ -207,13 +207,6 @@ public class UserAdapter extends Adapter<ViewHolder> implements OnHolderClickLis
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if adapter doesn't contain any items
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return users.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* disable placeholder view loading animation
|
||||
*/
|
||||
|
@ -187,13 +187,6 @@ public class UserlistAdapter extends Adapter<ViewHolder> implements OnHolderClic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if adapter doesn't contain any items
|
||||
*/
|
||||
public boolean isEmtpy() {
|
||||
return userlists.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* disable placeholder view loading animation
|
||||
*/
|
||||
|
@ -30,8 +30,8 @@ import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
|
||||
*/
|
||||
public class AccountFragment extends ListFragment implements OnAccountClickListener, OnConfirmListener, AsyncCallback<AccountResult> {
|
||||
|
||||
private AccountLoader loginTask;
|
||||
private DatabaseAction databaseAsync;
|
||||
private AccountLoader accountLoader;
|
||||
private DatabaseAction databaseAction;
|
||||
private GlobalSettings settings;
|
||||
private AccountAdapter adapter;
|
||||
private ConfirmDialog dialog;
|
||||
@ -45,27 +45,21 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
|
||||
dialog = new ConfirmDialog(requireContext());
|
||||
settings = GlobalSettings.getInstance(requireContext());
|
||||
adapter = new AccountAdapter(requireContext(), this);
|
||||
loginTask = new AccountLoader(requireContext());
|
||||
databaseAsync = new DatabaseAction(requireContext());
|
||||
accountLoader = new AccountLoader(requireContext());
|
||||
databaseAction = new DatabaseAction(requireContext());
|
||||
|
||||
setAdapter(adapter);
|
||||
dialog.setConfirmListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (adapter.isEmpty()) {
|
||||
setRefresh(true);
|
||||
load(AccountParameter.LOAD);
|
||||
}
|
||||
load(AccountParameter.LOAD);
|
||||
setRefresh(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
loginTask.cancel();
|
||||
accountLoader.cancel();
|
||||
databaseAction.cancel();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -86,7 +80,7 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
|
||||
@Override
|
||||
public void onAccountClick(Account account) {
|
||||
settings.setLogin(account, true);
|
||||
databaseAsync.execute(new DatabaseParam(DatabaseParam.DELETE), this::onDatabaseResult);
|
||||
databaseAction.execute(new DatabaseParam(DatabaseParam.DELETE), this::onDatabaseResult);
|
||||
if (account.getUser() != null) {
|
||||
String message = getString(R.string.info_account_selected, account.getUser().getScreenname());
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
|
||||
@ -147,6 +141,6 @@ public class AccountFragment extends ListFragment implements OnAccountClickListe
|
||||
*/
|
||||
public void load(int mode) {
|
||||
AccountParameter request = new AccountParameter(mode, selectedId);
|
||||
loginTask.execute(request, this);
|
||||
accountLoader.execute(request, this);
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ import java.util.List;
|
||||
*/
|
||||
public class MessageFragment extends ListFragment implements OnMessageClickListener, OnConfirmListener, AsyncCallback<MessageLoaderResult> {
|
||||
|
||||
private MessageLoader messageTask;
|
||||
private MessageLoader messageLoader;
|
||||
private MessageAdapter adapter;
|
||||
private ConfirmDialog confirmDialog;
|
||||
|
||||
@ -57,32 +57,28 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
confirmDialog = new ConfirmDialog(requireContext());
|
||||
adapter = new MessageAdapter(requireContext(), this);
|
||||
messageTask = new MessageLoader(requireContext());
|
||||
messageLoader = new MessageLoader(requireContext());
|
||||
setAdapter(adapter);
|
||||
|
||||
confirmDialog.setConfirmListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (adapter.isEmpty()) {
|
||||
loadMessages(false, null);
|
||||
}
|
||||
loadMessages(false, null);
|
||||
setRefresh(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onReset() {
|
||||
adapter = new MessageAdapter(requireContext(), this);
|
||||
setAdapter(adapter);
|
||||
loadMessages(false, null);
|
||||
setRefresh(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
messageTask.cancel();
|
||||
messageLoader.cancel();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -138,7 +134,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
|
||||
break;
|
||||
|
||||
case DELETE:
|
||||
if (!confirmDialog.isShowing() && messageTask.isIdle()) {
|
||||
if (!confirmDialog.isShowing() && messageLoader.isIdle()) {
|
||||
deleteId = message.getId();
|
||||
confirmDialog.show(ConfirmDialog.MESSAGE_DELETE);
|
||||
}
|
||||
@ -167,7 +163,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
|
||||
|
||||
@Override
|
||||
public boolean onPlaceholderClick(String cursor) {
|
||||
if (messageTask.isIdle()) {
|
||||
if (messageLoader.isIdle()) {
|
||||
loadMessages(false, cursor);
|
||||
return true;
|
||||
}
|
||||
@ -179,7 +175,7 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
|
||||
public void onConfirm(int type, boolean rememberChoice) {
|
||||
if (type == ConfirmDialog.MESSAGE_DELETE) {
|
||||
MessageLoaderParam param = new MessageLoaderParam(MessageLoaderParam.DELETE, deleteId, "");
|
||||
messageTask.execute(param, this);
|
||||
messageLoader.execute(param, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +217,6 @@ public class MessageFragment extends ListFragment implements OnMessageClickListe
|
||||
private void loadMessages(boolean local, String cursor) {
|
||||
int mode = local ? MessageLoaderParam.DATABASE : MessageLoaderParam.ONLINE;
|
||||
MessageLoaderParam param = new MessageLoaderParam(mode, 0L, cursor);
|
||||
messageTask.execute(param, this);
|
||||
setRefresh(true);
|
||||
messageLoader.execute(param, this);
|
||||
}
|
||||
}
|
@ -43,16 +43,9 @@ public class NotificationFragment extends ListFragment implements OnNotification
|
||||
adapter = new NotificationAdapter(requireContext(), this);
|
||||
notificationAsync = new NotificationLoader(requireContext());
|
||||
setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (adapter.isEmpty()) {
|
||||
load(0L, 0L, 0);
|
||||
setRefresh(true);
|
||||
}
|
||||
load(0L, 0L, 0);
|
||||
setRefresh(true);
|
||||
}
|
||||
|
||||
|
||||
@ -69,6 +62,7 @@ public class NotificationFragment extends ListFragment implements OnNotification
|
||||
if (!adapter.isEmpty())
|
||||
sinceId = adapter.getItemId(0);
|
||||
load(sinceId, 0L, 0);
|
||||
setRefresh(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
||||
|
||||
private ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), this);
|
||||
|
||||
private StatusLoader statusAsync;
|
||||
private StatusLoader statusLoader;
|
||||
private StatusAdapter adapter;
|
||||
|
||||
private String search = "";
|
||||
@ -130,19 +130,12 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
||||
id = param.getLong(KEY_STATUS_FRAGMENT_ID, 0);
|
||||
search = param.getString(KEY_STATUS_FRAGMENT_SEARCH, "");
|
||||
}
|
||||
statusAsync = new StatusLoader(requireContext());
|
||||
statusLoader = new StatusLoader(requireContext());
|
||||
adapter = new StatusAdapter(requireContext(), this);
|
||||
setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (adapter.isEmpty()) {
|
||||
load(0L, 0L, CLEAR_LIST);
|
||||
setRefresh(true);
|
||||
}
|
||||
load(0L, 0L, CLEAR_LIST);
|
||||
setRefresh(true);
|
||||
}
|
||||
|
||||
|
||||
@ -157,7 +150,7 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
statusAsync.cancel();
|
||||
statusLoader.cancel();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -205,7 +198,7 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
||||
|
||||
@Override
|
||||
public boolean onPlaceholderClick(long minId, long maxId, int pos) {
|
||||
if (statusAsync.isIdle()) {
|
||||
if (statusLoader.isIdle()) {
|
||||
load(minId, maxId, pos);
|
||||
return true;
|
||||
}
|
||||
@ -226,7 +219,6 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
||||
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
|
||||
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
|
||||
adapter.disableLoading();
|
||||
setRefresh(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,6 +270,6 @@ public class StatusFragment extends ListFragment implements StatusSelectListener
|
||||
default:
|
||||
return;
|
||||
}
|
||||
statusAsync.execute(request, this);
|
||||
statusLoader.execute(request, this);
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ public class TrendFragment extends ListFragment implements TrendClickListener, A
|
||||
*/
|
||||
public static final String KEY_HASHTAG_SEARCH = "trend_search_hashtags";
|
||||
|
||||
private TrendLoader trendTask;
|
||||
private TrendLoader trendLoader;
|
||||
private TrendAdapter adapter;
|
||||
|
||||
private String search = "";
|
||||
@ -42,22 +42,15 @@ public class TrendFragment extends ListFragment implements TrendClickListener, A
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
adapter = new TrendAdapter(settings, this);
|
||||
trendTask = new TrendLoader(requireContext());
|
||||
trendLoader = new TrendLoader(requireContext());
|
||||
setAdapter(adapter);
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
search = args.getString(KEY_HASHTAG_SEARCH, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (adapter.isEmpty()) {
|
||||
load();
|
||||
setRefresh(true);
|
||||
}
|
||||
setRefresh(true);
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +65,7 @@ public class TrendFragment extends ListFragment implements TrendClickListener, A
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
trendTask.cancel();
|
||||
trendLoader.cancel();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -104,7 +97,6 @@ public class TrendFragment extends ListFragment implements TrendClickListener, A
|
||||
} else if (getContext() != null) {
|
||||
String message = ErrorHandler.getErrorMessage(getContext(), result.exception);
|
||||
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
|
||||
setRefresh(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,6 +111,6 @@ public class TrendFragment extends ListFragment implements TrendClickListener, A
|
||||
param = new TrendParameter(TrendLoader.DATABASE, search);
|
||||
else
|
||||
param = new TrendParameter(TrendLoader.ONLINE, search);
|
||||
trendTask.execute(param, this);
|
||||
trendLoader.execute(param, this);
|
||||
}
|
||||
}
|
@ -139,7 +139,7 @@ public class UserFragment extends ListFragment implements UserClickListener, Asy
|
||||
|
||||
private ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), this);
|
||||
|
||||
private UsersLoader userAsync;
|
||||
private UsersLoader userLoader;
|
||||
private UserAdapter adapter;
|
||||
|
||||
private String search = "";
|
||||
@ -158,19 +158,12 @@ public class UserFragment extends ListFragment implements UserClickListener, Asy
|
||||
search = param.getString(KEY_FRAG_USER_SEARCH, "");
|
||||
delUser = param.getBoolean(KEY_FRAG_DEL_USER, false);
|
||||
}
|
||||
userAsync = new UsersLoader(requireContext());
|
||||
userLoader = new UsersLoader(requireContext());
|
||||
adapter = new UserAdapter(requireContext(), this, delUser);
|
||||
setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (adapter.isEmpty()) {
|
||||
setRefresh(true);
|
||||
load(-1L);
|
||||
}
|
||||
setRefresh(true);
|
||||
load(-1L);
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +176,7 @@ public class UserFragment extends ListFragment implements UserClickListener, Asy
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
userAsync.cancel();
|
||||
userLoader.cancel();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -219,7 +212,7 @@ public class UserFragment extends ListFragment implements UserClickListener, Asy
|
||||
|
||||
@Override
|
||||
public boolean onPlaceholderClick(long cursor) {
|
||||
if (userAsync.isIdle()) {
|
||||
if (userLoader.isIdle()) {
|
||||
load(cursor);
|
||||
return true;
|
||||
}
|
||||
@ -314,6 +307,6 @@ public class UserFragment extends ListFragment implements UserClickListener, Asy
|
||||
default:
|
||||
return;
|
||||
}
|
||||
userAsync.execute(param, this);
|
||||
userLoader.execute(param, this);
|
||||
}
|
||||
}
|
@ -63,7 +63,7 @@ public class UserListFragment extends ListFragment implements ListClickListener,
|
||||
|
||||
private ActivityResultLauncher<Intent> activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), this);
|
||||
|
||||
private ListLoader listTask;
|
||||
private ListLoader userlistLoader;
|
||||
private UserlistAdapter adapter;
|
||||
|
||||
private long id = 0;
|
||||
@ -78,32 +78,25 @@ public class UserListFragment extends ListFragment implements ListClickListener,
|
||||
id = param.getLong(KEY_FRAG_LIST_OWNER_ID, -1L);
|
||||
type = param.getInt(KEY_FRAG_LIST_LIST_TYPE);
|
||||
}
|
||||
listTask = new ListLoader(requireContext());
|
||||
userlistLoader = new ListLoader(requireContext());
|
||||
adapter = new UserlistAdapter(requireContext(), this);
|
||||
setAdapter(adapter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (adapter.isEmtpy()) {
|
||||
setRefresh(true);
|
||||
load(-1L);
|
||||
}
|
||||
setRefresh(true);
|
||||
load(-1L);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onReset() {
|
||||
load(-1L);
|
||||
setRefresh(true);
|
||||
load(-1L);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
listTask.cancel();
|
||||
userlistLoader.cancel();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -153,7 +146,7 @@ public class UserListFragment extends ListFragment implements ListClickListener,
|
||||
|
||||
@Override
|
||||
public boolean onPlaceholderClick(long cursor) {
|
||||
if (listTask.isIdle()) {
|
||||
if (userlistLoader.isIdle()) {
|
||||
load(cursor);
|
||||
return true;
|
||||
}
|
||||
@ -197,6 +190,6 @@ public class UserListFragment extends ListFragment implements ListClickListener,
|
||||
default:
|
||||
return;
|
||||
}
|
||||
listTask.execute(param, this);
|
||||
userlistLoader.execute(param, this);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user