Some fixes for #2

pull/17/head
Thomas 2 years ago
parent 207d8d9994
commit 713b5307e2

@ -17,6 +17,8 @@ package app.fedilab.android.activities;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -120,7 +122,9 @@ public class HashTagActivity extends BaseActivity {
} }
} }
if (!canBeAdded) { if (!canBeAdded) {
Toasty.warning(HashTagActivity.this, getString(R.string.tags_already_stored), Toasty.LENGTH_SHORT).show(); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> Toasty.warning(HashTagActivity.this, getString(R.string.tags_already_stored), Toasty.LENGTH_SHORT).show();
mainHandler.post(myRunnable);
return; return;
} }
PinnedTimeline pinnedTimeline = new PinnedTimeline(); PinnedTimeline pinnedTimeline = new PinnedTimeline();

@ -39,6 +39,8 @@ import androidx.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.regex.Matcher;
import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.client.entities.Account; import app.fedilab.android.client.entities.Account;
@ -81,12 +83,12 @@ public class LoginActivity extends BaseActivity {
//That happens when the user wants to use an external browser //That happens when the user wants to use an external browser
if (getIntent() != null && getIntent().getData() != null && getIntent().getData().toString().contains(REDIRECT_CONTENT_WEB + "?code=")) { if (getIntent() != null && getIntent().getData() != null && getIntent().getData().toString().contains(REDIRECT_CONTENT_WEB + "?code=")) {
String url = getIntent().getData().toString(); String url = getIntent().getData().toString();
String[] val = url.split("code="); Matcher matcher = Helper.codePattern.matcher(url);
if (val.length < 2) { if (!matcher.find()) {
Toasty.error(LoginActivity.this, getString(R.string.toast_code_error), Toast.LENGTH_LONG).show(); Toasty.error(LoginActivity.this, getString(R.string.toast_code_error), Toast.LENGTH_LONG).show();
return; return;
} }
String code = val[1]; String code = matcher.group(1);
OauthVM oauthVM = new ViewModelProvider(LoginActivity.this).get(OauthVM.class); OauthVM oauthVM = new ViewModelProvider(LoginActivity.this).get(OauthVM.class);
//We are dealing with a Mastodon API //We are dealing with a Mastodon API
if (api == Account.API.MASTODON) { if (api == Account.API.MASTODON) {

@ -656,7 +656,7 @@ public class ProfileActivity extends BaseActivity {
public boolean onCreateOptionsMenu(@NonNull Menu menu) { public boolean onCreateOptionsMenu(@NonNull Menu menu) {
getMenuInflater().inflate(R.menu.activity_profile, menu); getMenuInflater().inflate(R.menu.activity_profile, menu);
if (account != null) { if (account != null) {
final boolean isOwner = account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0; final boolean isOwner = account.id != null && account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0;
String[] splitAcct = account.acct.split("@"); String[] splitAcct = account.acct.split("@");
//check if user is from the same instance //check if user is from the same instance
if (splitAcct.length <= 1) { //If yes, these entries must be hidden if (splitAcct.length <= 1) { //If yes, these entries must be hidden

@ -42,7 +42,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
@ -50,6 +49,8 @@ import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.util.regex.Matcher;
import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.client.entities.Account; import app.fedilab.android.client.entities.Account;
@ -59,7 +60,6 @@ import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.helper.ThemeHelper;
import app.fedilab.android.viewmodel.mastodon.AccountsVM; import app.fedilab.android.viewmodel.mastodon.AccountsVM;
import app.fedilab.android.viewmodel.mastodon.OauthVM; import app.fedilab.android.viewmodel.mastodon.OauthVM;
import es.dmoral.toasty.Toasty;
public class WebviewConnectActivity extends BaseActivity { public class WebviewConnectActivity extends BaseActivity {
@ -183,15 +183,11 @@ public class WebviewConnectActivity extends BaseActivity {
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url); super.shouldOverrideUrlLoading(view, url);
if (url.contains(Helper.REDIRECT_CONTENT_WEB)) { if (url.contains(Helper.REDIRECT_CONTENT_WEB)) {
String[] val = url.split("code="); Matcher matcher = Helper.codePattern.matcher(url);
if (val.length < 2) { if (!matcher.find()) {
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_code_error), Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(WebviewConnectActivity.this, LoginActivity.class);
startActivity(myIntent);
finish();
return false; return false;
} }
String code = val[1]; String code = matcher.group(1);
OauthVM oauthVM = new ViewModelProvider(WebviewConnectActivity.this).get(OauthVM.class); OauthVM oauthVM = new ViewModelProvider(WebviewConnectActivity.this).get(OauthVM.class);
//API call to get the user token //API call to get the user token
oauthVM.createToken(currentInstance, "authorization_code", BaseMainActivity.client_id, BaseMainActivity.client_secret, Helper.REDIRECT_CONTENT_WEB, Helper.OAUTH_SCOPES, code) oauthVM.createToken(currentInstance, "authorization_code", BaseMainActivity.client_id, BaseMainActivity.client_secret, Helper.REDIRECT_CONTENT_WEB, Helper.OAUTH_SCOPES, code)

@ -53,7 +53,7 @@ public class CommentDecorationHelper {
} }
String targetedComment = null; String targetedComment = null;
for (Status status : statuses) { for (Status status : statuses) {
if (replyToCommentId.compareTo(status.id) == 0) { if (status != null && status.id != null && replyToCommentId.compareTo(status.id) == 0) {
targetedComment = status.in_reply_to_id; targetedComment = status.in_reply_to_id;
break; break;
} }

@ -51,6 +51,7 @@ import android.provider.MediaStore;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -187,6 +188,8 @@ public class Helper {
public static final String ARG_MEDIA_POSITION = "ARG_MEDIA_POSITION"; public static final String ARG_MEDIA_POSITION = "ARG_MEDIA_POSITION";
public static final String ARG_MEDIA_ATTACHMENT = "ARG_MEDIA_ATTACHMENT"; public static final String ARG_MEDIA_ATTACHMENT = "ARG_MEDIA_ATTACHMENT";
public static final String ARG_SHOW_REPLIES = "ARG_SHOW_REPLIES"; public static final String ARG_SHOW_REPLIES = "ARG_SHOW_REPLIES";
public static final String ARG_SHOW_REBLOGS = "ARG_SHOW_REBLOGS";
public static final String ARG_SHOW_PINNED = "ARG_SHOW_PINNED"; public static final String ARG_SHOW_PINNED = "ARG_SHOW_PINNED";
public static final String ARG_SHOW_MEDIA_ONY = "ARG_SHOW_MEDIA_ONY"; public static final String ARG_SHOW_MEDIA_ONY = "ARG_SHOW_MEDIA_ONY";
public static final String ARG_MENTION = "ARG_MENTION"; public static final String ARG_MENTION = "ARG_MENTION";
@ -251,6 +254,8 @@ public class Helper {
public static final Pattern xmppPattern = Pattern.compile("xmpp:[-a-zA-Z0-9+$&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); public static final Pattern xmppPattern = Pattern.compile("xmpp:[-a-zA-Z0-9+$&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
public static final Pattern mediumPattern = Pattern.compile("([\\w@-]*)?\\.?medium.com/@?([/\\w-]+)"); public static final Pattern mediumPattern = Pattern.compile("([\\w@-]*)?\\.?medium.com/@?([/\\w-]+)");
public static final Pattern wikipediaPattern = Pattern.compile("([\\w_-]+)\\.wikipedia.org/(((?!([\"'<])).)*)"); public static final Pattern wikipediaPattern = Pattern.compile("([\\w_-]+)\\.wikipedia.org/(((?!([\"'<])).)*)");
public static final Pattern codePattern = Pattern.compile("code=([\\w-]+)");
// --- Static Map of patterns used in spannable status content // --- Static Map of patterns used in spannable status content
public static final Map<PatternType, Pattern> patternHashMap; public static final Map<PatternType, Pattern> patternHashMap;
public static int counter = 1; public static int counter = 1;
@ -1184,8 +1189,18 @@ public class Helper {
attachment.size = Helper.getRealSizeFromUri(context, uri); attachment.size = Helper.getRealSizeFromUri(context, uri);
ContentResolver cR = context.getApplicationContext().getContentResolver(); ContentResolver cR = context.getApplicationContext().getContentResolver();
attachment.mimeType = cR.getType(uri); attachment.mimeType = cR.getType(uri);
Log.v(Helper.TAG, "uri: " + uri);
Log.v(Helper.TAG, "attachment.mimeType: " + attachment.mimeType);
MimeTypeMap mime = MimeTypeMap.getSingleton(); MimeTypeMap mime = MimeTypeMap.getSingleton();
String extension = mime.getExtensionFromMimeType(cR.getType(uri)); String extension = mime.getExtensionFromMimeType(cR.getType(uri));
Log.v(Helper.TAG, "mime: " + attachment.mimeType);
Log.v(Helper.TAG, "extension: " + attachment.mimeType);
if (uri.toString().endsWith("fedilab_recorded_audio.wav")) {
extension = "wav";
attachment.mimeType = "audio/x-wav";
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_" + counter, Locale.getDefault()); SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_" + counter, Locale.getDefault());
counter++; counter++;
Date now = new Date(); Date now = new Date();

@ -159,7 +159,7 @@ public class MastodonHelper {
return pagination; return pagination;
} }
pagination.max_id = statusList.get(0).id; pagination.max_id = statusList.get(0).id;
pagination.min_id = String.valueOf(Long.parseLong(statusList.get(statusList.size() - 1).id) - 1); pagination.min_id = statusList.get(statusList.size() - 1).id;
return pagination; return pagination;
} }
@ -169,7 +169,7 @@ public class MastodonHelper {
return pagination; return pagination;
} }
pagination.max_id = accountList.get(0).id; pagination.max_id = accountList.get(0).id;
pagination.min_id = String.valueOf(Long.parseLong(accountList.get(accountList.size() - 1).id) - 1); pagination.min_id = accountList.get(accountList.size() - 1).id;
return pagination; return pagination;
} }
@ -179,7 +179,7 @@ public class MastodonHelper {
return pagination; return pagination;
} }
pagination.max_id = scheduledStatusList.get(0).id; pagination.max_id = scheduledStatusList.get(0).id;
pagination.min_id = String.valueOf(Long.parseLong(scheduledStatusList.get(scheduledStatusList.size() - 1).id) - 1); pagination.min_id = scheduledStatusList.get(scheduledStatusList.size() - 1).id;
return pagination; return pagination;
} }
@ -189,7 +189,7 @@ public class MastodonHelper {
return pagination; return pagination;
} }
pagination.max_id = conversationList.get(0).id; pagination.max_id = conversationList.get(0).id;
pagination.min_id = String.valueOf(Long.parseLong(conversationList.get(conversationList.size() - 1).id) - 1); pagination.min_id = conversationList.get(conversationList.size() - 1).id;
return pagination; return pagination;
} }
@ -276,9 +276,10 @@ public class MastodonHelper {
Matcher matcherALink = Patterns.WEB_URL.matcher(contentCount); Matcher matcherALink = Patterns.WEB_URL.matcher(contentCount);
while (matcherALink.find()) { while (matcherALink.find()) {
final String url = matcherALink.group(1); final String url = matcherALink.group(1);
assert url != null; if (url != null) {
contentCount = contentCount.replace(url, "abcdefghijklmnopkrstuvw"); contentCount = contentCount.replace(url, "abcdefghijklmnopkrstuvw");
} }
}
int contentLength = contentCount.length() - countWithEmoji(content); int contentLength = contentCount.length() - countWithEmoji(content);
int cwLength = cwContent.length() - countWithEmoji(cwContent); int cwLength = cwContent.length() - countWithEmoji(cwContent);
return cwLength + contentLength; return cwLength + contentLength;

@ -107,11 +107,15 @@ public class TimelineHelper {
//A security to make sure filters have been fetched before displaying messages //A security to make sure filters have been fetched before displaying messages
List<Notification> notificationToRemove = new ArrayList<>(); List<Notification> notificationToRemove = new ArrayList<>();
if (!BaseMainActivity.filterFetched) { if (!BaseMainActivity.filterFetched) {
try {
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class); AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
accountsVM.getFilters(BaseMainActivity.currentInstance, BaseMainActivity.currentToken).observe((LifecycleOwner) context, filters -> { accountsVM.getFilters(BaseMainActivity.currentInstance, BaseMainActivity.currentToken).observe((LifecycleOwner) context, filters -> {
BaseMainActivity.filterFetched = true; BaseMainActivity.filterFetched = true;
BaseMainActivity.mainFilters = filters; BaseMainActivity.mainFilters = filters;
}); });
} catch (Exception e) {
return notifications;
}
} }
//If there are filters: //If there are filters:
if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0) { if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0) {

@ -300,8 +300,8 @@ public class PostMessageService extends IntentService {
} }
} }
if (scheduledDate == null && token != null) { if (scheduledDate == null && token != null && firstSendMessage != null) {
Account account = null; Account account;
try { try {
account = new Account(PostMessageService.this).getAccountByToken(token); account = new Account(PostMessageService.this).getAccountByToken(token);
final Intent pendingIntent = new Intent(PostMessageService.this, ContextActivity.class); final Intent pendingIntent = new Intent(PostMessageService.this, ContextActivity.class);

@ -102,9 +102,12 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
doAction = ProfileActivity.action.UNFOLLOW; doAction = ProfileActivity.action.UNFOLLOW;
accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_person_remove_24); accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_person_remove_24);
} else if (account.relationShip.requested) { } else if (account.relationShip.requested) {
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.red_1)));
doAction = ProfileActivity.action.NOTHING; doAction = ProfileActivity.action.NOTHING;
accountViewHolder.binding.followAction.setEnabled(false); accountViewHolder.binding.followAction.setEnabled(false);
accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_hourglass_full_24); accountViewHolder.binding.followAction.setIconResource(R.drawable.ic_baseline_hourglass_full_24);
} else {
accountViewHolder.binding.followAction.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(context, R.color.cyanea_accent_dark_reference)));
} }

@ -184,6 +184,9 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
break; break;
} }
} }
if (statusDraft.text == null) {
statusDraft.text = "";
}
//Put other accounts mentioned at the bottom //Put other accounts mentioned at the bottom
boolean capitalize = sharedpreferences.getBoolean(context.getString(R.string.SET_CAPITALIZE), true); boolean capitalize = sharedpreferences.getBoolean(context.getString(R.string.SET_CAPITALIZE), true);
if (inReplyToUser != null) { if (inReplyToUser != null) {
@ -562,6 +565,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
*/ */
private void buttonState(ComposeViewHolder holder) { private void buttonState(ComposeViewHolder holder) {
if (BaseMainActivity.software == null || BaseMainActivity.software.toUpperCase().compareTo("MASTODON") == 0) { if (BaseMainActivity.software == null || BaseMainActivity.software.toUpperCase().compareTo("MASTODON") == 0) {
if (holder.getAdapterPosition() > 0) {
Status statusDraft = statusList.get(holder.getAdapterPosition()); Status statusDraft = statusList.get(holder.getAdapterPosition());
if (statusDraft.poll == null) { if (statusDraft.poll == null) {
holder.binding.buttonAttachImage.setEnabled(true); holder.binding.buttonAttachImage.setEnabled(true);
@ -578,6 +582,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.buttonPoll.setEnabled(statusDraft.media_attachments == null || statusDraft.media_attachments.size() <= 0); holder.binding.buttonPoll.setEnabled(statusDraft.media_attachments == null || statusDraft.media_attachments.size() <= 0);
} }
} }
}
public long getItemId(int position) { public long getItemId(int position) {
return position; return position;
@ -612,17 +617,29 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class); AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class); SearchVM searchVM = new ViewModelProvider((ViewModelStoreOwner) context).get(SearchVM.class);
textw = new TextWatcher() { textw = new TextWatcher() {
private int position;
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} }
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count > 2) {
holder.binding.addRemoveStatus.setVisibility(View.VISIBLE);
}
position = start;
} }
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
int currentLength = MastodonHelper.countLength(holder);
//Copy/past
if (currentLength > instanceInfo.configuration.statusesConf.max_characters + 1) {
holder.binding.content.setText(s.delete(instanceInfo.configuration.statusesConf.max_characters - holder.binding.contentSpoiler.getText().length(), (currentLength - holder.binding.contentSpoiler.getText().length())));
} else if (currentLength > instanceInfo.configuration.statusesConf.max_characters) {
holder.binding.content.setText(s.delete(position, position + 1));
}
statusList.get(holder.getAdapterPosition()).text = s.toString(); statusList.get(holder.getAdapterPosition()).text = s.toString();
if (s.toString().trim().length() < 2) { if (s.toString().trim().length() < 2) {
buttonVisibility(holder); buttonVisibility(holder);
@ -639,7 +656,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
if (s.toString().contains(fedilabHugsTrigger)) { if (s.toString().contains(fedilabHugsTrigger)) {
newContent[0] = s.toString().replaceAll(fedilabHugsTrigger, ""); newContent[0] = s.toString().replaceAll(fedilabHugsTrigger, "");
int currentLength = MastodonHelper.countLength(holder);
int toFill = 500 - currentLength; int toFill = 500 - currentLength;
if (toFill <= 0) { if (toFill <= 0) {
return; return;
@ -720,8 +737,10 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
searchLength[0] = Math.min(currentCursorPosition[0], searchDeep); searchLength[0] = Math.min(currentCursorPosition[0], searchDeep);
if (currentCursorPosition[0] - (searchLength[0] - 1) < 0 || currentCursorPosition[0] == 0 || currentCursorPosition[0] > s.toString().length()) if (currentCursorPosition[0] - (searchLength[0] - 1) < 0 || currentCursorPosition[0] == 0 || currentCursorPosition[0] > s.toString().length()) {
updateCharacterCount(holder);
return; return;
}
String patternh = "^(.|\\s)*(:fedilab_hugs:)$"; String patternh = "^(.|\\s)*(:fedilab_hugs:)$";
final Pattern hPattern = Pattern.compile(patternh); final Pattern hPattern = Pattern.compile(patternh);
@ -741,6 +760,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} }
String[] searchInArray = (s.toString().substring(currentCursorPosition[0] - searchLength[0], currentCursorPosition[0])).split("\\s"); String[] searchInArray = (s.toString().substring(currentCursorPosition[0] - searchLength[0], currentCursorPosition[0])).split("\\s");
if (searchInArray.length < 1) { if (searchInArray.length < 1) {
updateCharacterCount(holder);
return; return;
} }
String searchIn = searchInArray[searchInArray.length - 1]; String searchIn = searchInArray[searchInArray.length - 1];
@ -1099,16 +1119,30 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.buttonPoll.setOnClickListener(v -> displayPollPopup(holder, statusDraft, position)); holder.binding.buttonPoll.setOnClickListener(v -> displayPollPopup(holder, statusDraft, position));
holder.binding.characterProgress.setMax(instanceInfo.configuration.statusesConf.max_characters); holder.binding.characterProgress.setMax(instanceInfo.configuration.statusesConf.max_characters);
holder.binding.contentSpoiler.addTextChangedListener(new TextWatcher() { holder.binding.contentSpoiler.addTextChangedListener(new TextWatcher() {
private int position;
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} }
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
position = start;
if (count > 2) {
holder.binding.addRemoveStatus.setVisibility(View.VISIBLE);
}
} }
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
int currentLength = MastodonHelper.countLength(holder);
if (currentLength > instanceInfo.configuration.statusesConf.max_characters + 1) {
holder.binding.contentSpoiler.setText(s.delete(instanceInfo.configuration.statusesConf.max_characters - holder.binding.content.getText().length(), (currentLength - holder.binding.content.getText().length())));
buttonVisibility(holder);
} else if (currentLength > instanceInfo.configuration.statusesConf.max_characters) {
buttonVisibility(holder);
holder.binding.contentSpoiler.setText(s.delete(position, position + 1));
}
statusList.get(holder.getAdapterPosition()).spoiler_text = s.toString(); statusList.get(holder.getAdapterPosition()).spoiler_text = s.toString();
if (s.toString().trim().length() < 2) { if (s.toString().trim().length() < 2) {
buttonVisibility(holder); buttonVisibility(holder);
@ -1199,11 +1233,10 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} else { } else {
composePollBinding.buttonAddOption.setVisibility(View.VISIBLE); composePollBinding.buttonAddOption.setVisibility(View.VISIBLE);
} }
int childCount = composePollBinding.optionsListContainer.getChildCount(); int childCount = composePollBinding.optionsList.getChildCount();
if (childCount > 2) { for (int i = 0; i < childCount; i++) {
for (int i = 2; i < childCount; i++) { AppCompatEditText title = (composePollBinding.optionsList.getChildAt(i)).findViewById(R.id.text);
((AppCompatEditText) composePollBinding.optionsListContainer.getChildAt(i)).setHint(context.getString(R.string.poll_choice_s, i + 1)); title.setHint(context.getString(R.string.poll_choice_s, i + 1));
}
} }
}); });
@ -1238,9 +1271,9 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} else { } else {
ComposePollItemBinding composePollItemBinding = ComposePollItemBinding.inflate(LayoutInflater.from(context), new LinearLayout(context), false); ComposePollItemBinding composePollItemBinding = ComposePollItemBinding.inflate(LayoutInflater.from(context), new LinearLayout(context), false);
composePollItemBinding.text.setFilters(fArray); composePollItemBinding.text.setFilters(fArray);
composePollItemBinding.text.setHint(context.getString(R.string.poll_choice_s, (pollCountItem[0] + 1))); composePollItemBinding.text.setHint(context.getString(R.string.poll_choice_s, (pollCountItem[0] + 1)));
composePollItemBinding.text.setText(pollItem.title);
composePollBinding.optionsList.addView(composePollItemBinding.getRoot()); composePollBinding.optionsList.addView(composePollItemBinding.getRoot());
composePollItemBinding.buttonRemove.setOnClickListener(view -> { composePollItemBinding.buttonRemove.setOnClickListener(view -> {
composePollBinding.optionsList.removeView(view); composePollBinding.optionsList.removeView(view);
@ -1335,22 +1368,13 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
statusDraft.poll.expire_in = expire; statusDraft.poll.expire_in = expire;
List<Poll.PollItem> pollItems = new ArrayList<>(); List<Poll.PollItem> pollItems = new ArrayList<>();
Poll.PollItem pollOption1 = new Poll.PollItem(); int childCount = composePollBinding.optionsList.getChildCount();
pollOption1.title = choice1; for (int i = 0; i < childCount; i++) {
pollItems.add(pollOption1);
Poll.PollItem pollOption2 = new Poll.PollItem();
pollOption2.title = choice2;
pollItems.add(pollOption2);
int childCount = composePollBinding.optionsListContainer.getChildCount();
if (childCount > 2) {
for (int i = 2; i < childCount; i++) {
Poll.PollItem pollItem = new Poll.PollItem(); Poll.PollItem pollItem = new Poll.PollItem();
pollItem.title = ((AppCompatEditText) composePollBinding.optionsListContainer.getChildAt(i)).getText().toString(); AppCompatEditText title = (composePollBinding.optionsList.getChildAt(i)).findViewById(R.id.text);
pollItem.title = title.getText().toString();
pollItems.add(pollItem); pollItems.add(pollItem);
} }
}
List<String> options = new ArrayList<>(); List<String> options = new ArrayList<>();
boolean doubleTitle = false; boolean doubleTitle = false;
for (Poll.PollItem po : pollItems) { for (Poll.PollItem po : pollItems) {

@ -70,7 +70,7 @@ public class FragmentMastodonTimeline extends Fragment {
private TagTimeline tagTimeline; private TagTimeline tagTimeline;
private LinearLayoutManager mLayoutManager; private LinearLayoutManager mLayoutManager;
private Account accountTimeline; private Account accountTimeline;
private boolean show_replies, show_pinned, media_only, minified; private boolean exclude_replies, exclude_reblogs, show_pinned, media_only, minified;
private String viewModelKey; private String viewModelKey;
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
@ -85,8 +85,9 @@ public class FragmentMastodonTimeline extends Fragment {
searchCache = getArguments().getString(Helper.ARG_SEARCH_KEYWORD_CACHE, null); searchCache = getArguments().getString(Helper.ARG_SEARCH_KEYWORD_CACHE, null);
tagTimeline = (TagTimeline) getArguments().getSerializable(Helper.ARG_TAG_TIMELINE); tagTimeline = (TagTimeline) getArguments().getSerializable(Helper.ARG_TAG_TIMELINE);
accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT); accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT);
show_replies = getArguments().getBoolean(Helper.ARG_SHOW_REPLIES, false); exclude_replies = !getArguments().getBoolean(Helper.ARG_SHOW_REPLIES, true);
show_pinned = getArguments().getBoolean(Helper.ARG_SHOW_PINNED, false); show_pinned = getArguments().getBoolean(Helper.ARG_SHOW_PINNED, false);
exclude_reblogs = !getArguments().getBoolean(Helper.ARG_SHOW_REBLOGS, true);
media_only = getArguments().getBoolean(Helper.ARG_SHOW_MEDIA_ONY, false); media_only = getArguments().getBoolean(Helper.ARG_SHOW_MEDIA_ONY, false);
viewModelKey = getArguments().getString(Helper.ARG_VIEW_MODEL_KEY, ""); viewModelKey = getArguments().getString(Helper.ARG_VIEW_MODEL_KEY, "");
minified = getArguments().getBoolean(Helper.ARG_MINIFIED, false); minified = getArguments().getBoolean(Helper.ARG_MINIFIED, false);
@ -367,17 +368,17 @@ public class FragmentMastodonTimeline extends Fragment {
if (show_pinned) { if (show_pinned) {
//Fetch pinned statuses to display them at the top //Fetch pinned statuses to display them at the top
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, null, null, false, true, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, show_replies, !show_replies, false, false, MastodonHelper.statusesPerCall(requireActivity())) .observe(getViewLifecycleOwner(), pinnedStatuses -> accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), otherStatuses -> { .observe(getViewLifecycleOwner(), otherStatuses -> {
otherStatuses.statuses.addAll(0, pinnedStatuses.statuses); otherStatuses.statuses.addAll(0, pinnedStatuses.statuses);
initializeStatusesCommonView(otherStatuses); initializeStatusesCommonView(otherStatuses);
})); }));
} else { } else {
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, show_replies, !show_replies, media_only, false, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, null, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} }
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, max_id, null, null, show_replies, !show_replies, media_only, false, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM));
} else { } else {
flagLoading = false; flagLoading = false;

@ -60,13 +60,17 @@ public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter {
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
bundle.putSerializable(Helper.ARG_ACCOUNT, account); bundle.putSerializable(Helper.ARG_ACCOUNT, account);
bundle.putBoolean(Helper.ARG_SHOW_PINNED, true); bundle.putBoolean(Helper.ARG_SHOW_PINNED, true);
bundle.putBoolean(Helper.ARG_SHOW_REPLIES, false);
bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, true);
fragmentProfileTimeline.setArguments(bundle); fragmentProfileTimeline.setArguments(bundle);
return fragmentProfileTimeline; return fragmentProfileTimeline;
case 1: case 1:
fragmentProfileTimeline = new FragmentMastodonTimeline(); fragmentProfileTimeline = new FragmentMastodonTimeline();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.ACCOUNT_TIMELINE);
bundle.putSerializable(Helper.ARG_ACCOUNT, account); bundle.putSerializable(Helper.ARG_ACCOUNT, account);
bundle.putBoolean(Helper.ARG_SHOW_PINNED, false);
bundle.putBoolean(Helper.ARG_SHOW_REPLIES, true); bundle.putBoolean(Helper.ARG_SHOW_REPLIES, true);
bundle.putBoolean(Helper.ARG_SHOW_REBLOGS, false);
fragmentProfileTimeline.setArguments(bundle); fragmentProfileTimeline.setArguments(bundle);
return fragmentProfileTimeline; return fragmentProfileTimeline;
case 2: case 2:

@ -86,6 +86,7 @@ public class OauthVM extends AndroidViewModel {
if (tokenCall != null) { if (tokenCall != null) {
try { try {
Response<Token> tokenResponse = tokenCall.execute(); Response<Token> tokenResponse = tokenCall.execute();
if (tokenResponse.isSuccessful()) { if (tokenResponse.isSuccessful()) {
token = tokenResponse.body(); token = tokenResponse.body();
} }

@ -71,7 +71,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="Poll type:" android:text="@string/poll_type"
android:textAlignment="viewEnd" /> android:textAlignment="viewEnd" />
<androidx.appcompat.widget.AppCompatSpinner <androidx.appcompat.widget.AppCompatSpinner
@ -92,7 +92,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="Poll duration:" android:text="@string/poll_duration"
android:textAlignment="viewEnd" /> android:textAlignment="viewEnd" />
<androidx.appcompat.widget.AppCompatSpinner <androidx.appcompat.widget.AppCompatSpinner

@ -1585,6 +1585,8 @@
<string name="types_of_notifications_to_display">Types of notifications to display</string> <string name="types_of_notifications_to_display">Types of notifications to display</string>
<string name="set_unfollow_validation_title">Confirm unfollows</string> <string name="set_unfollow_validation_title">Confirm unfollows</string>
<string name="message_has_been_sent">Message has been sent!</string> <string name="message_has_been_sent">Message has been sent!</string>
<string name="poll_type">Poll type:</string>
<string name="poll_duration">Poll duration:</string>
</resources> </resources>

Loading…
Cancel
Save