Fix mentions / DM from profiles

This commit is contained in:
Thomas 2022-05-01 16:32:37 +02:00
parent ca9c9cfcab
commit b15fdabc90
4 changed files with 42 additions and 7 deletions

View file

@ -97,6 +97,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
private String instance, token;
private Uri photoFileUri;
private ScheduledStatus scheduledStatus;
private String visibility;
private app.fedilab.android.client.mastodon.entities.Account accountMention;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -124,6 +126,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
account = (Account) b.getSerializable(Helper.ARG_ACCOUNT);
instance = b.getString(Helper.ARG_INSTANCE, BaseMainActivity.currentInstance);
token = b.getString(Helper.ARG_TOKEN, BaseMainActivity.currentToken);
visibility = b.getString(Helper.ARG_VISIBILITY, null);
accountMention = (app.fedilab.android.client.mastodon.entities.Account) b.getSerializable(Helper.ARG_ACCOUNT_MENTION);
}
binding.toolbar.setPopupTheme(Helper.popupStyle());
//Edit a scheduled status from server
@ -177,7 +181,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
}
int statusCount = statusList.size();
statusList.addAll(statusDraft.statusDraftList);
composeAdapter = new ComposeAdapter(statusList, statusCount, account);
composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility);
composeAdapter.manageDrafts = this;
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this);
binding.recyclerView.setLayoutManager(mLayoutManager);
@ -218,7 +222,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
}
//StatusDraftList at this point should only have one element
statusList.addAll(statusDraftList);
composeAdapter = new ComposeAdapter(statusList, statusCount, account);
composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility);
composeAdapter.manageDrafts = this;
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this);
binding.recyclerView.setLayoutManager(mLayoutManager);
@ -231,7 +235,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
} else {
//Compose without replying
statusList.addAll(statusDraftList);
composeAdapter = new ComposeAdapter(statusList, 0, account);
composeAdapter = new ComposeAdapter(statusList, 0, account, accountMention, visibility);
composeAdapter.manageDrafts = this;
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this);
binding.recyclerView.setLayoutManager(mLayoutManager);

View file

@ -834,7 +834,7 @@ public class ProfileActivity extends BaseActivity {
} else if (itemId == R.id.action_direct_message) {
Intent intent = new Intent(ProfileActivity.this, ComposeActivity.class);
Bundle b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, account);
b.putSerializable(Helper.ARG_ACCOUNT_MENTION, account);
b.putString(Helper.ARG_VISIBILITY, "direct");
intent.putExtras(b);
startActivity(intent);
@ -908,7 +908,7 @@ public class ProfileActivity extends BaseActivity {
Bundle b;
intent = new Intent(ProfileActivity.this, ComposeActivity.class);
b = new Bundle();
b.putSerializable(Helper.ARG_ACCOUNT, account.acct);
b.putSerializable(Helper.ARG_ACCOUNT_MENTION, account);
intent.putExtras(b);
startActivity(intent);
return true;

View file

@ -57,6 +57,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
@ -176,6 +177,7 @@ public class Helper {
public static final String ARG_STATUS_DRAFT_ID = "ARG_STATUS_DRAFT_ID";
public static final String ARG_STATUS_REPLY = "ARG_STATUS_REPLY";
public static final String ARG_ACCOUNT = "ARG_ACCOUNT";
public static final String ARG_ACCOUNT_MENTION = "ARG_ACCOUNT_MENTION";
public static final String ARG_MINIFIED = "ARG_MINIFIED";
public static final String ARG_STATUS_REPORT = "ARG_STATUS_REPORT";
public static final String ARG_STATUS_MENTION = "ARG_STATUS_MENTION";
@ -1411,4 +1413,10 @@ public class Helper {
}).start();
}
}
public static void showKeyboard(Context context, View view) {
view.requestFocus();
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}

View file

@ -121,11 +121,16 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
private int statusCount;
private Context context;
private AlertDialog alertDialogEmoji;
private final String visibility;
private final app.fedilab.android.client.mastodon.entities.Account mentionedAccount;
public ComposeAdapter(List<Status> statusList, int statusCount, Account account) {
public ComposeAdapter(List<Status> statusList, int statusCount, Account account, app.fedilab.android.client.mastodon.entities.Account mentionedAccount, String visibility) {
this.statusList = statusList;
this.statusCount = statusCount;
this.account = account;
this.mentionedAccount = mentionedAccount;
this.visibility = visibility;
}
private static void updateCharacterCount(ComposeViewHolder composeViewHolder) {
@ -214,6 +219,21 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.content.setSelection(statusDraft.cursorPosition); //Put cursor at the end
buttonVisibility(holder);
});
} else if (mentionedAccount != null) {
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean capitalize = sharedpreferences.getBoolean(context.getString(R.string.SET_CAPITALIZE), true);
if (capitalize) {
statusDraft.text = mentionedAccount.acct + "\n";
} else {
statusDraft.text = mentionedAccount.acct + " ";
}
holder.binding.content.setText(statusDraft.text);
updateCharacterCount(holder);
holder.binding.content.requestFocus();
holder.binding.content.post(() -> {
buttonVisibility(holder);
holder.binding.content.setSelection(statusDraft.text.length()); //Put cursor at the end
});
} else {
holder.binding.content.requestFocus();
}
@ -1025,6 +1045,10 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.attachmentChoicesPanel.setVisibility(View.GONE);
pickupMedia(ComposeActivity.mediaType.ALL, position);
});
//Used for DM
if (visibility != null) {
statusDraft.visibility = visibility;
}
if (statusDraft.visibility == null) {
if (position > 0) {
statusDraft.visibility = statusList.get(position - 1).visibility;
@ -1092,7 +1116,6 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
});
displayAttachments(holder, position, -1);
manageMentions(context, statusDraft, holder);
//For some instances this value can be null, we have to transform the html content
if (statusDraft.text == null && statusDraft.content != null) {