Fixes some behaviors
This commit is contained in:
parent
db41068207
commit
ecb4d2255d
|
@ -168,6 +168,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
private String initialContent;
|
||||
private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 754;
|
||||
private BroadcastReceiver receive_picture;
|
||||
private Account accountReply;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -259,6 +260,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
restored = -1;
|
||||
if(b != null) {
|
||||
tootReply = b.getParcelable("tootReply");
|
||||
accountReply = b.getParcelable("accountReply");
|
||||
tootMention = b.getString("tootMention", null);
|
||||
urlMention = b.getString("urlMention", null);
|
||||
fileMention = b.getString("fileMention", null);
|
||||
|
@ -297,7 +299,12 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
setTitle(R.string.toot_title);
|
||||
}
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String userId;
|
||||
if( accountReply == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
else
|
||||
userId = accountReply.getId();
|
||||
|
||||
if( tootMention != null && urlMention != null && fileMention != null) {
|
||||
Bitmap pictureMention = BitmapFactory.decodeFile(getCacheDir() + "/" + fileMention);
|
||||
if (pictureMention != null) {
|
||||
|
@ -314,8 +321,12 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
toot_content.setText(String.format("\n\nvia @%s\n\n%s\n\n", tootMention, urlMention));
|
||||
toot_space_left.setText(String.valueOf(toot_content.length()));
|
||||
}
|
||||
Account account;
|
||||
if( accountReply == null)
|
||||
account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||
else
|
||||
account = accountReply;
|
||||
|
||||
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
|
||||
String url = account.getAvatar();
|
||||
if( url.startsWith("/") ){
|
||||
url = "https://" + Helper.getLiveInstance(getApplicationContext()) + account.getAvatar();
|
||||
|
@ -484,8 +495,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
if( tootReply != null)
|
||||
toot.setIn_reply_to_id(tootReply.getId());
|
||||
toot.setContent(toot_content.getText().toString().trim());
|
||||
|
||||
new PostStatusAsyncTask(getApplicationContext(), toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new PostStatusAsyncTask(getApplicationContext(), accountReply, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -1310,7 +1320,11 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
title.setText(getString(R.string.toot_title_reply));
|
||||
else
|
||||
setTitle(R.string.toot_title_reply);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String userId;
|
||||
if( accountReply == null)
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
else
|
||||
userId = accountReply.getId();
|
||||
|
||||
switch (tootReply.getVisibility()){
|
||||
case "public":
|
||||
|
|
|
@ -16,9 +16,12 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostStatusActionInterface;
|
||||
|
||||
|
||||
|
@ -33,16 +36,22 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private OnPostStatusActionInterface listener;
|
||||
private APIResponse apiResponse;
|
||||
private fr.gouv.etalab.mastodon.client.Entities.Status status;
|
||||
private Account account;
|
||||
|
||||
public PostStatusAsyncTask(Context context, fr.gouv.etalab.mastodon.client.Entities.Status status, OnPostStatusActionInterface onPostStatusActionInterface){
|
||||
public PostStatusAsyncTask(Context context, Account account, fr.gouv.etalab.mastodon.client.Entities.Status status, OnPostStatusActionInterface onPostStatusActionInterface){
|
||||
this.context = context;
|
||||
this.listener = onPostStatusActionInterface;
|
||||
this.status = status;
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
apiResponse = new API(context).postStatusAction(status);
|
||||
if( account == null)
|
||||
apiResponse = new API(context).postStatusAction(status);
|
||||
else
|
||||
apiResponse = new API(context, account.getInstance(), account.getToken()).postStatusAction(status);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ package fr.gouv.etalab.mastodon.drawers;
|
|||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.annotation.NonNull;;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -35,6 +37,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
|
||||
|
@ -49,10 +53,12 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
|
|||
private ImageLoader imageLoader;
|
||||
private DisplayImageOptions options;
|
||||
private boolean owner;
|
||||
private Context context;
|
||||
|
||||
public AccountsSearchAdapter(Context context, List<Account> accounts){
|
||||
super(context, android.R.layout.simple_list_item_1, accounts);
|
||||
this.accounts = accounts;
|
||||
this.context = context;
|
||||
this.tempAccounts = new ArrayList<>(accounts);
|
||||
this.suggestions = new ArrayList<>(accounts);
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
|
@ -65,6 +71,7 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
|
|||
public AccountsSearchAdapter(Context context, List<Account> accounts, boolean owner){
|
||||
super(context, android.R.layout.simple_list_item_1, accounts);
|
||||
this.accounts = accounts;
|
||||
this.context = context;
|
||||
this.tempAccounts = new ArrayList<>(accounts);
|
||||
this.suggestions = new ArrayList<>(accounts);
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
|
@ -110,7 +117,12 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
|
|||
}
|
||||
|
||||
if( owner) {
|
||||
holder.account_un.setText(String.format("@%s", account.getUsername() + "@" + account.getInstance()));
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
String instance = (account.getInstance() !=null)?account.getInstance():currentAccount.getInstance();
|
||||
holder.account_un.setText(String.format("@%s", account.getUsername() + "@" + instance));
|
||||
holder.account_dn.setVisibility(View.GONE);
|
||||
}else {
|
||||
holder.account_un.setText(String.format("@%s", account.getUsername()));
|
||||
|
|
|
@ -741,7 +741,8 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
}else if( statusAction == API.StatusAction.UNREBLOG){
|
||||
for(Notification notification: notifications){
|
||||
if( notification.getStatus().getId().equals(targetedId)) {
|
||||
notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() - 1);
|
||||
if( notification.getStatus().getReblogs_count() - 1 >= 0 )
|
||||
notification.getStatus().setReblogs_count(notification.getStatus().getReblogs_count() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -757,7 +758,8 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
|
|||
}else if( statusAction == API.StatusAction.UNFAVOURITE){
|
||||
for(Notification notification: notifications){
|
||||
if( notification.getStatus().getId().equals(targetedId)) {
|
||||
notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() - 1);
|
||||
if( notification.getStatus().getFavourites_count() - 1 >= 0 )
|
||||
notification.getStatus().setFavourites_count(notification.getStatus().getFavourites_count() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -681,21 +681,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
holder.status_reply.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, TootActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
if( status.getReblog() != null )
|
||||
b.putParcelable("tootReply", status.getReblog());
|
||||
else
|
||||
b.putParcelable("tootReply", status);
|
||||
intent.putExtras(b); //Put your id to your next Intent
|
||||
context.startActivity(intent);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){
|
||||
try {
|
||||
//Avoid to open multi activities when replying in a conversation
|
||||
((ShowConversationActivity)context).finish();
|
||||
}catch (Exception ignored){}
|
||||
|
||||
}
|
||||
CrossActions.doCrossReply(context, status, type);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1207,7 +1193,8 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
}else if( statusAction == API.StatusAction.UNREBLOG){
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(targetedId)) {
|
||||
status.setReblogs_count(status.getReblogs_count() - 1);
|
||||
if( status.getReblogs_count() - 1 >= 0)
|
||||
status.setReblogs_count(status.getReblogs_count() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1223,7 +1210,8 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
}else if( statusAction == API.StatusAction.UNFAVOURITE){
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(targetedId)) {
|
||||
status.setFavourites_count(status.getFavourites_count() - 1);
|
||||
if( status.getFavourites_count() - 1 >= 0)
|
||||
status.setFavourites_count(status.getFavourites_count() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,18 +17,26 @@ package fr.gouv.etalab.mastodon.helper;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.widget.BaseAdapter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.TootActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Mention;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
|
@ -42,7 +50,7 @@ import mastodon.etalab.gouv.fr.mastodon.R;
|
|||
public class CrossActions {
|
||||
|
||||
public static void doCrossAction(final Context context, final Status status, final API.StatusAction doAction, final BaseAdapter baseAdapter, final OnPostActionInterface onPostActionInterface){
|
||||
List<Account> accounts = connectedAccounts(context);
|
||||
List<Account> accounts = connectedAccounts(context, null);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
|
||||
boolean undoAction = (doAction == API.StatusAction.UNPIN || doAction == API.StatusAction.UNREBLOG || doAction == API.StatusAction.UNFAVOURITE );
|
||||
|
@ -104,6 +112,67 @@ public class CrossActions {
|
|||
}
|
||||
}
|
||||
|
||||
public static void doCrossReply(final Context context, final Status status, final RetrieveFeedsAsyncTask.Type type){
|
||||
List<Account> accounts = connectedAccounts(context, status);
|
||||
|
||||
if( accounts.size() == 1) {
|
||||
Intent intent = new Intent(context, TootActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
if( status.getReblog() != null )
|
||||
b.putParcelable("tootReply", status.getReblog());
|
||||
else
|
||||
b.putParcelable("tootReply", status);
|
||||
intent.putExtras(b); //Put your id to your next Intent
|
||||
context.startActivity(intent);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){
|
||||
try {
|
||||
//Avoid to open multi activities when replying in a conversation
|
||||
((ShowConversationActivity)context).finish();
|
||||
}catch (Exception ignored){}
|
||||
|
||||
}
|
||||
}else {
|
||||
AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
|
||||
builderSingle.setTitle(context.getString(R.string.choose_accounts));
|
||||
final AccountsSearchAdapter accountsSearchAdapter = new AccountsSearchAdapter(context, accounts, true);
|
||||
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 account = accountArray[which];
|
||||
Intent intent = new Intent(context, TootActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
if( status.getReblog() != null )
|
||||
b.putParcelable("tootReply", status.getReblog());
|
||||
else
|
||||
b.putParcelable("tootReply", status);
|
||||
b.putParcelable("accountReply", account);
|
||||
intent.putExtras(b); //Put your id to your next Intent
|
||||
context.startActivity(intent);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT ){
|
||||
try {
|
||||
//Avoid to open multi activities when replying in a conversation
|
||||
((ShowConversationActivity)context).finish();
|
||||
}catch (Exception ignored){}
|
||||
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builderSingle.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -215,15 +284,48 @@ public class CrossActions {
|
|||
* @param context Context
|
||||
* @return List<Account>
|
||||
*/
|
||||
private static List<Account> connectedAccounts(Context context){
|
||||
private static List<Account> connectedAccounts(Context context, Status status){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<Account> accounts = new AccountDAO(context, db).getAllAccount();
|
||||
if( sharedpreferences.getBoolean(Helper.SET_ALLOW_CROSS_ACTIONS, true) && accounts.size() > 1 ){
|
||||
List<Account> accountstmp = new AccountDAO(context, db).getAllAccount();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
if( sharedpreferences.getBoolean(Helper.SET_ALLOW_CROSS_ACTIONS, true) && accountstmp.size() > 1 ){
|
||||
//It's for a reply
|
||||
if( status != null){
|
||||
//Status is private or direct
|
||||
if( status.getVisibility().equals("private") || status.getVisibility().equals("direct") ){
|
||||
//Retrieves mentioned accounts and compares them to the list of accounts in the device.
|
||||
List<Mention> mentions = status.getMentions();
|
||||
List<String> addedAccount = new ArrayList<>();
|
||||
//Adds the owner
|
||||
accounts.add(currentAccount);
|
||||
addedAccount.add(currentAccount.getId() + "|" + currentAccount.getAcct());
|
||||
for(Mention mention: mentions){
|
||||
for(Account account: accountstmp){
|
||||
String mentionAcct = (mention.getAcct().contains("@"))?mention.getAcct():mention.getAcct()+"@"+currentAccount.getInstance();
|
||||
if( (account.getAcct() + "@" + account.getInstance()).equals(mentionAcct) && !addedAccount.contains(account.getId() + "|" + account.getAcct())) {
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(Account account: accountstmp){
|
||||
Account tootOwner = status.getAccount();
|
||||
String mentionAcct = (tootOwner.getAcct().contains("@"))?tootOwner.getAcct():tootOwner.getAcct()+"@"+currentAccount.getInstance();
|
||||
if( (account.getAcct() + "@" + account.getInstance()).equals(mentionAcct) && !addedAccount.contains(account.getId() + "|" + account.getAcct())) {
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
accounts = accountstmp;
|
||||
}
|
||||
}else {
|
||||
accounts = accountstmp;
|
||||
}
|
||||
return accounts;
|
||||
}else {
|
||||
List<Account> oneAccount = new ArrayList<>();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
oneAccount.add(account);
|
||||
return oneAccount;
|
||||
|
|
Loading…
Reference in New Issue