From b8a1a1fe8ef6f96b0376ded4088dde236d31878c Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 4 Oct 2017 13:44:32 +0200 Subject: [PATCH] Some fixes --- .../drawers/AccountsSearchAdapter.java | 25 ++++++++++++++-- .../mastodon/drawers/StatusListAdapter.java | 12 ++------ .../etalab/mastodon/helper/CrossActions.java | 30 ++++++++++++------- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java index d216f216a..ed49a0e63 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/AccountsSearchAdapter.java @@ -48,6 +48,7 @@ public class AccountsSearchAdapter extends ArrayAdapter implements Filt private LayoutInflater layoutInflater; private ImageLoader imageLoader; private DisplayImageOptions options; + private boolean owner; public AccountsSearchAdapter(Context context, List accounts){ super(context, android.R.layout.simple_list_item_1, accounts); @@ -58,6 +59,19 @@ public class AccountsSearchAdapter extends ArrayAdapter 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 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 implements Filt } else { holder = (ViewHolder) convertView.getTag(); } - holder.account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true)); - holder.account_un.setText(String.format("@%s",account.getUsername())); + + 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_dn.setVisibility(View.VISIBLE); + } //Profile picture imageLoader.displayImage(account.getAvatar(), holder.account_pp, options); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index bce727e06..b4d6be68b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -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 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); } }); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java index 533fa2963..9aa3a1e90 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java @@ -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 - favouriteAction(context, status, baseAdapter, onPostActionInterface); + 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 ){ - status.setReblogged(true); - }else if( doAction == API.StatusAction.FAVOURITE ){ - status.setReblogged(true); - }else if( doAction == API.StatusAction.PIN ){ - status.setPinned(true); + 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) { + status.setReblogged(true); + } else if (doAction == API.StatusAction.PIN) { + status.setPinned(true); + } + baseAdapter.notifyDataSetChanged(); } - baseAdapter.notifyDataSetChanged(); dialog.dismiss(); } });