Manages accounts in context
This commit is contained in:
parent
7112b45dfc
commit
6439090493
|
@ -101,10 +101,13 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import cz.msebera.android.httpclient.Header;
|
import cz.msebera.android.httpclient.Header;
|
||||||
|
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.PostStatusAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.PostStatusAsyncTask;
|
||||||
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsForReplyAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAccountsAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAccountsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.UploadActionAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.UploadActionAsyncTask;
|
||||||
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||||
|
@ -121,6 +124,7 @@ import fr.gouv.etalab.mastodon.drawers.TagsListAdapter;
|
||||||
import fr.gouv.etalab.mastodon.drawers.TagsSearchAdapter;
|
import fr.gouv.etalab.mastodon.drawers.TagsSearchAdapter;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnPostStatusActionInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnPostStatusActionInterface;
|
||||||
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsReplyInterface;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAttachmentInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAttachmentInterface;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface;
|
||||||
|
@ -139,7 +143,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
* Toot activity class
|
* Toot activity class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostStatusActionInterface, OnRetrieveSearchInterface {
|
public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface, OnRetrieveAttachmentInterface, OnPostStatusActionInterface, OnRetrieveSearchInterface, OnRetrieveAccountsReplyInterface {
|
||||||
|
|
||||||
|
|
||||||
private String visibility;
|
private String visibility;
|
||||||
|
@ -766,6 +770,12 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
alert.setPositiveButton(R.string.accounts, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
new RetrieveAccountsForReplyAsyncTask(getApplicationContext(), tootReply, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
alert.show();
|
alert.show();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_microphone:
|
case R.id.action_microphone:
|
||||||
|
@ -1529,4 +1539,38 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRetrieveAccountsReply(ArrayList<Mention> mentions) {
|
||||||
|
ArrayList<Account> accounts = new ArrayList<>();
|
||||||
|
for(Mention mention: mentions) {
|
||||||
|
Account account = new Account();
|
||||||
|
account.setAcct(mention.getAcct());
|
||||||
|
account.setAvatar(mention.getUrl());
|
||||||
|
account.setUsername(mention.getUsername());
|
||||||
|
}
|
||||||
|
AlertDialog.Builder builderSingle = new AlertDialog.Builder(TootActivity.this);
|
||||||
|
builderSingle.setTitle(getString(R.string.choose_accounts));
|
||||||
|
final AccountsSearchAdapter accountsSearchAdapter = new AccountsSearchAdapter(getApplicationContext(), accounts, false);
|
||||||
|
final Account[] accountArray = new Account[accounts.size()];
|
||||||
|
int i = 0;
|
||||||
|
for(Account account: accounts){
|
||||||
|
accountArray[i] = account;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builderSingle.setAdapter(accountsSearchAdapter, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Account selectedAccount = accountArray[which];
|
||||||
|
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builderSingle.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/* Copyright 2017 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Mastalab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package fr.gouv.etalab.mastodon.asynctasks;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
||||||
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsReplyInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 25/10/2017.
|
||||||
|
* Retrieves accounts which are involved in a conversation
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RetrieveAccountsForReplyAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
private fr.gouv.etalab.mastodon.client.Entities.Status status;
|
||||||
|
private OnRetrieveAccountsReplyInterface listener;
|
||||||
|
private ArrayList<Mention> mentions;
|
||||||
|
private ArrayList<String> addedAccounts;
|
||||||
|
|
||||||
|
public RetrieveAccountsForReplyAsyncTask(Context context, fr.gouv.etalab.mastodon.client.Entities.Status status, OnRetrieveAccountsReplyInterface onRetrieveAccountsReplyInterface){
|
||||||
|
this.context = context;
|
||||||
|
this.status = status;
|
||||||
|
this.listener = onRetrieveAccountsReplyInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
API api = new API(context);
|
||||||
|
fr.gouv.etalab.mastodon.client.Entities.Context statusContext = api.getStatusContext(status.getId());
|
||||||
|
mentions = new ArrayList<>();
|
||||||
|
addedAccounts = new ArrayList<>();
|
||||||
|
//Retrieves the first toot
|
||||||
|
if( statusContext.getAncestors().size() > 0 ) {
|
||||||
|
fr.gouv.etalab.mastodon.client.Entities.Status statusFirst = statusContext.getAncestors().get(0);
|
||||||
|
statusContext = api.getStatusContext(statusContext.getAncestors().get(0).getId());
|
||||||
|
}
|
||||||
|
if( status != null){
|
||||||
|
for(Mention mention : status.getMentions()){
|
||||||
|
if( canBeAdded(mention.getAcct())){
|
||||||
|
mentions.add(mention);
|
||||||
|
addedAccounts.add(mention.getAcct());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( statusContext != null && statusContext.getDescendants().size() > 0){
|
||||||
|
for(fr.gouv.etalab.mastodon.client.Entities.Status status : statusContext.getDescendants())
|
||||||
|
for(Mention mention : status.getMentions()){
|
||||||
|
if( canBeAdded(mention.getAcct())){
|
||||||
|
mentions.add(mention);
|
||||||
|
addedAccounts.add(mention.getAcct());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( statusContext != null && statusContext.getAncestors().size() > 0){
|
||||||
|
for(fr.gouv.etalab.mastodon.client.Entities.Status status : statusContext.getAncestors())
|
||||||
|
for(Mention mention : status.getMentions()){
|
||||||
|
if( canBeAdded(mention.getAcct())){
|
||||||
|
mentions.add(mention);
|
||||||
|
addedAccounts.add(mention.getAcct());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canBeAdded(String acct){
|
||||||
|
return acct != null && !acct.equals(status.getAccount().getAcct()) && !addedAccounts.contains(acct);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void result) {
|
||||||
|
listener.onRetrieveAccountsReply(mentions);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -36,6 +36,7 @@ import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||||
|
@ -67,7 +68,6 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
|
||||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||||
this.owner = false;
|
this.owner = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountsSearchAdapter(Context context, List<Account> accounts, boolean owner){
|
public AccountsSearchAdapter(Context context, List<Account> accounts, boolean owner){
|
||||||
super(context, android.R.layout.simple_list_item_1, accounts);
|
super(context, android.R.layout.simple_list_item_1, accounts);
|
||||||
this.accounts = accounts;
|
this.accounts = accounts;
|
||||||
|
@ -81,6 +81,7 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return accounts.size();
|
return accounts.size();
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* Copyright 2017 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Mastalab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
package fr.gouv.etalab.mastodon.interfaces;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 25/10/2017.
|
||||||
|
* Interface when accounts of a conversation have been retrieved
|
||||||
|
*/
|
||||||
|
public interface OnRetrieveAccountsReplyInterface {
|
||||||
|
void onRetrieveAccountsReply(ArrayList<Mention> mentions);
|
||||||
|
}
|
Loading…
Reference in New Issue