Some fixes

This commit is contained in:
tom79 2017-10-04 13:44:32 +02:00
parent a21b26a0ea
commit b8a1a1fe8e
3 changed files with 45 additions and 22 deletions

View File

@ -48,6 +48,7 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
private LayoutInflater layoutInflater;
private ImageLoader imageLoader;
private DisplayImageOptions options;
private boolean owner;
public AccountsSearchAdapter(Context context, List<Account> accounts){
super(context, android.R.layout.simple_list_item_1, accounts);
@ -58,6 +59,19 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
this.owner = false;
}
public AccountsSearchAdapter(Context context, List<Account> accounts, boolean owner){
super(context, android.R.layout.simple_list_item_1, accounts);
this.accounts = accounts;
this.tempAccounts = new ArrayList<>(accounts);
this.suggestions = new ArrayList<>(accounts);
layoutInflater = LayoutInflater.from(context);
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
this.owner = owner;
}
@Override
@ -94,8 +108,15 @@ public class AccountsSearchAdapter extends ArrayAdapter<Account> implements Filt
} else {
holder = (ViewHolder) convertView.getTag();
}
if( owner) {
holder.account_un.setText(String.format("@%s", account.getUsername() + "@" + account.getInstance()));
holder.account_dn.setVisibility(View.GONE);
}else {
holder.account_un.setText(String.format("@%s", account.getUsername()));
holder.account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true));
holder.account_un.setText(String.format("@%s",account.getUsername()));
holder.account_dn.setVisibility(View.VISIBLE);
}
//Profile picture
imageLoader.displayImage(account.getAvatar(), holder.account_pp, options);

View File

@ -93,8 +93,6 @@ import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.interfaces.OnTranslatedInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.translation.GoogleTranslateQuery;
import fr.gouv.etalab.mastodon.translation.YandexQuery;
import mastodon.etalab.gouv.fr.mastodon.R;
@ -119,10 +117,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
private int translator;
private int behaviorWithAttachments;
private StatusListAdapter statusListAdapter;
private final int REBLOG = 1;
private final int FAVOURITE = 2;
private final int PIN = 3;
private final int UNPIN = 4;
private RetrieveFeedsAsyncTask.Type type;
private String targetedId;
private HashMap<String, String> urlConversion;
@ -835,20 +829,20 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.status_favorite_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CrossActions.doCrossAction(context, status, targetedId, status.isFavourited()? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this);
CrossActions.doCrossAction(context, status, targetedId, (status.isFavourited()|| (status.getReblog() != null && status.getReblog().isFavourited()))? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this);
}
});
holder.status_reblog_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CrossActions.doCrossAction(context, status, targetedId, status.isReblogged()? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this);
CrossActions.doCrossAction(context, status, targetedId, (status.isReblogged()|| (status.getReblog() != null && status.getReblog().isReblogged()))? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this);
}
});
holder.status_pin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CrossActions.doCrossAction(context, status, targetedId, status.isPinned()? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this);
CrossActions.doCrossAction(context, status, targetedId, (status.isPinned()|| (status.getReblog() != null && status.getReblog().isPinned()))? API.StatusAction.UNPIN:API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this);
}
});

View File

@ -23,6 +23,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.util.Log;
import android.widget.BaseAdapter;
import java.util.List;
@ -47,18 +48,23 @@ public class CrossActions {
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 );
//Undo actions won't ask for choosing a user
if( accounts.size() == 1 || undoAction) {
boolean confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false);
if (confirmation)
displayConfirmationDialog(context, doAction, status, baseAdapter, onPostActionInterface);
else
else {
if( doAction == API.StatusAction.REBLOG || doAction == API.StatusAction.UNREBLOG)
reblogAction(context, status, baseAdapter, onPostActionInterface);
else if( doAction == API.StatusAction.FAVOURITE || doAction == API.StatusAction.UNFAVOURITE)
favouriteAction(context, status, baseAdapter, onPostActionInterface);
else if ( doAction == API.StatusAction.PIN || doAction == API.StatusAction.UNPIN)
pinAction(context, status, baseAdapter, onPostActionInterface);
}
}else {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
builderSingle.setTitle(context.getString(R.string.choose_accounts));
final AccountsSearchAdapter accountsSearchAdapter = new AccountsSearchAdapter(context, accounts);
final AccountsSearchAdapter accountsSearchAdapter = new AccountsSearchAdapter(context, accounts, true);
final Account[] accountArray = new Account[accounts.size()];
int i = 0;
for(Account account: accounts){
@ -83,14 +89,16 @@ public class CrossActions {
}else{ //Account is from another instance
new PostActionAsyncTask(context, selectedAccount, status, doAction, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
if (doAction == API.StatusAction.REBLOG ){
if( selectedAccount.getInstance().equals(loggedAccount.getInstance()) && selectedAccount.getId().equals(loggedAccount.getId())) {
if (doAction == API.StatusAction.REBLOG) {
status.setReblogged(true);
}else if( doAction == API.StatusAction.FAVOURITE ){
} else if (doAction == API.StatusAction.FAVOURITE) {
status.setReblogged(true);
}else if( doAction == API.StatusAction.PIN ){
} else if (doAction == API.StatusAction.PIN) {
status.setPinned(true);
}
baseAdapter.notifyDataSetChanged();
}
dialog.dismiss();
}
});