Fix issue when adding mentions

This commit is contained in:
tom79 2019-10-17 18:20:21 +02:00
parent 51f1280d99
commit 6f6208be59
3 changed files with 15 additions and 10 deletions

View File

@ -1682,7 +1682,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
this.checkedValues.add(toot_content.getText().toString().contains("@" + account.getAcct())); this.checkedValues.add(toot_content.getText().toString().contains("@" + account.getAcct()));
} }
this.loader.setVisibility(View.GONE); this.loader.setVisibility(View.GONE);
AccountsReplyAdapter contactAdapter = new AccountsReplyAdapter(this.contacts, this.checkedValues); AccountsReplyAdapter contactAdapter = new AccountsReplyAdapter(new WeakReference<>(PixelfedComposeActivity.this), this.contacts, this.checkedValues);
this.lv_accounts_search.setAdapter(contactAdapter); this.lv_accounts_search.setAdapter(contactAdapter);
} }

View File

@ -58,6 +58,7 @@ import android.text.Html;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.util.Patterns; import android.util.Patterns;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -2895,7 +2896,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
this.checkedValues.add(toot_content.getText().toString().contains("@" + account.getAcct())); this.checkedValues.add(toot_content.getText().toString().contains("@" + account.getAcct()));
} }
this.loader.setVisibility(View.GONE); this.loader.setVisibility(View.GONE);
AccountsReplyAdapter contactAdapter = new AccountsReplyAdapter(this.contacts, this.checkedValues); AccountsReplyAdapter contactAdapter = new AccountsReplyAdapter(new WeakReference<>(TootActivity.this),this.contacts, this.checkedValues);
this.lv_accounts_search.setAdapter(contactAdapter); this.lv_accounts_search.setAdapter(contactAdapter);
} }
@ -4029,7 +4030,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
i++; i++;
} }
final AlertDialog.Builder builderSingle = new AlertDialog.Builder(TootActivity.this, style); final AlertDialog.Builder builderSingle = new AlertDialog.Builder(TootActivity.this, style);
AccountsReplyAdapter accountsReplyAdapter = new AccountsReplyAdapter(accounts, checkedValues); AccountsReplyAdapter accountsReplyAdapter = new AccountsReplyAdapter(new WeakReference<>(TootActivity.this), accounts, checkedValues);
builderSingle.setTitle(getString(R.string.select_accounts)).setAdapter(accountsReplyAdapter, null); builderSingle.setTitle(getString(R.string.select_accounts)).setAdapter(accountsReplyAdapter, null);
builderSingle.setNegativeButton(R.string.validate, new DialogInterface.OnClickListener() { builderSingle.setNegativeButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override @Override
@ -4042,6 +4043,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
} }
public void changeAccountReply(boolean isChecked, String acct) { public void changeAccountReply(boolean isChecked, String acct) {
Log.v(Helper.TAG,isChecked + " -> " + acct );
if (isChecked) { if (isChecked) {
if (!toot_content.getText().toString().contains(acct)) if (!toot_content.getText().toString().contains(acct))
toot_content.setText(String.format("%s %s", acct, toot_content.getText())); toot_content.setText(String.format("%s %s", acct, toot_content.getText()));

View File

@ -15,6 +15,7 @@ package app.fedilab.android.drawers;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -31,6 +32,7 @@ import android.widget.TextView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
import app.fedilab.android.client.Entities.Account; import app.fedilab.android.client.Entities.Account;
@ -45,22 +47,23 @@ import app.fedilab.android.activities.TootActivity;
public class AccountsReplyAdapter extends BaseAdapter { public class AccountsReplyAdapter extends BaseAdapter {
private List<Account> accounts; private List<Account> accounts;
private LayoutInflater layoutInflater;
private boolean[] checked; private boolean[] checked;
private Context context; private WeakReference<Activity> activityWeakReference;
public AccountsReplyAdapter(List<Account> accounts, boolean[] checked) { public AccountsReplyAdapter(WeakReference<Activity> activityWeakReference, List<Account> accounts, boolean[] checked) {
this.accounts = accounts; this.accounts = accounts;
this.checked = checked; this.checked = checked;
this.activityWeakReference = activityWeakReference;
} }
public AccountsReplyAdapter(List<Account> accounts, List<Boolean> checked) { public AccountsReplyAdapter(WeakReference<Activity> activityWeakReference, List<Account> accounts, List<Boolean> checked) {
this.accounts = accounts; this.accounts = accounts;
this.checked = new boolean[checked.size()]; this.checked = new boolean[checked.size()];
int index = 0; int index = 0;
for (Boolean val : checked) { for (Boolean val : checked) {
this.checked[index++] = val; this.checked[index++] = val;
} }
this.activityWeakReference = activityWeakReference;
} }
@Override @Override
@ -82,8 +85,7 @@ public class AccountsReplyAdapter extends BaseAdapter {
@NonNull @NonNull
@Override @Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) { public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
context = parent.getContext(); LayoutInflater layoutInflater = LayoutInflater.from(activityWeakReference.get());
layoutInflater = LayoutInflater.from(context);
final Account account = accounts.get(position); final Account account = accounts.get(position);
final ViewHolder holder; final ViewHolder holder;
if (convertView == null) { if (convertView == null) {
@ -102,9 +104,10 @@ public class AccountsReplyAdapter extends BaseAdapter {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
try { try {
((TootActivity) context).changeAccountReply(isChecked, "@" + account.getAcct()); ((TootActivity) activityWeakReference.get()).changeAccountReply(isChecked, "@" + account.getAcct());
checked[position] = isChecked; checked[position] = isChecked;
} catch (Exception ignored) { } catch (Exception ignored) {
ignored.printStackTrace();
} }
} }
}); });