Fix cross actions

This commit is contained in:
Thomas 2023-01-27 10:33:41 +01:00
parent e4affdc9d7
commit 8103bf4a16
3 changed files with 41 additions and 3 deletions

View file

@ -426,7 +426,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
headerMainBinding.ownerAccounts.setImageResource(R.drawable.ic_baseline_arrow_drop_up_24);
new Thread(() -> {
try {
List<BaseAccount> accounts = new Account(activity).getCrossAccounts();
List<BaseAccount> accounts = new Account(activity).getOtherAccounts();
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
navigationView.getMenu().clear();

View file

@ -358,7 +358,7 @@ public class Account extends BaseAccount implements Serializable {
*
* @return BaseAccount List<{@link BaseAccount}>
*/
public List<BaseAccount> getCrossAccounts() throws DBException {
public List<BaseAccount> getOtherAccounts() throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
@ -370,6 +370,23 @@ public class Account extends BaseAccount implements Serializable {
}
}
/**
* Returns all accounts that allows cross-account actions
*
* @return BaseAccount List<{@link BaseAccount}>
*/
public List<BaseAccount> getCrossAccounts() throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
try {
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, null, null, null, null, null, null);
return cursorToListMastodonUser(c);
} catch (Exception e) {
return null;
}
}
/**
* Returns all accounts
*
@ -455,6 +472,27 @@ public class Account extends BaseAccount implements Serializable {
return accountList;
}
private List<BaseAccount> cursorToListMastodonUser(Cursor c) {
//No element found
if (c.getCount() == 0) {
c.close();
return null;
}
List<BaseAccount> accountList = new ArrayList<>();
while (c.moveToNext()) {
BaseAccount account = convertCursorToAccount(c);
//We don't add in the list the current connected account
if (account.mastodon_account != null) {
accountList.add(account);
}
}
//Close the cursor
c.close();
return accountList;
}
private List<BaseAccount> cursorToListUserWithOwner(Cursor c) {
//No element found
if (c.getCount() == 0) {

View file

@ -401,7 +401,7 @@ public class CrossActionHelper {
public static void doCrossShare(final Context context, final Bundle bundle) {
List<BaseAccount> accounts;
try {
accounts = new Account(context).getAll();
accounts = new Account(context).getCrossAccounts();
List<app.fedilab.android.mastodon.client.entities.api.Account> accountList = new ArrayList<>();
for (BaseAccount account : accounts) {
account.mastodon_account.acct += "@" + account.instance;