summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/app/fedilab/android/ui
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/app/fedilab/android/ui')
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java1
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java100
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java13
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java6
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java133
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java176
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.kt138
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonContext.java38
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java6
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java8
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java6
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java4
12 files changed, 402 insertions, 227 deletions
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java
index 2b23a0e5e..c0b378bf7 100644
--- a/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/AccountsReplyAdapter.java
@@ -34,7 +34,6 @@ public class AccountsReplyAdapter extends RecyclerView.Adapter<RecyclerView.View
private final boolean[] checked;
public ActionDone actionDone;
-
public AccountsReplyAdapter(List<Account> accounts, List<Boolean> checked) {
this.accounts = accounts;
this.checked = new boolean[checked.size()];
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java
index c4efd5351..9fdeb6207 100644
--- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java
@@ -80,8 +80,9 @@ import java.lang.ref.WeakReference;
import java.text.Normalizer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
@@ -124,11 +125,52 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
public static boolean autocomplete = false;
public static String[] ALPHA = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", ",", "?",
- ".", "'"};
+ ".", "'", "!", "/", "(", ")", "&", ":", ";", "=", "+", "-", "_",
+ "\"", "$", "@", "¿", "¡"
+ };
public static String[] MORSE = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..",
"--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----",
"..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----", "-.-.--", "--..--",
- "..--..", ".-.-.-", ".----.",};
+ "..--..", ".-.-.-", ".----.", "-.-.--", "-..-.", "-.--.", "-.--.-", ".-...", "---...", "-.-.-.", "-...-", ".-.-.", "-....-", "..--.-",
+ ".-..-.", "...-..-", ".--.-.", "..-.-", "--...-"
+ };
+
+ public static String[] MORSE2 = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..",
+ "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", ".----",
+ "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----", "-.-.--", "--..--",
+ "..--..", ".-.-.-", ".----.", "-.-.--", "-..-.", "-.--.", "-.--.-", ".-...", "---...", "-.-.-.", "-...-", ".-.-.", "-....-", "..--.-",
+ ".-..-.", "...-..-", ".--.-.", "..-.-", "--...-"
+ };
+
+ public static int countMorseChar(String content) {
+ int count_char = 0;
+ for (String morseCode : MORSE2) {
+ if (content.contains(morseCode) && !morseCode.equals(".") && !morseCode.equals("..") && !morseCode.equals("...") && !morseCode.equals("-") && !morseCode.equals("--")) {
+ count_char++;
+ }
+ }
+ return count_char;
+ }
+
+ public static String morseToText(String morseContent) {
+ LinkedHashMap<String, String> ALPHA_TO_MORSE = new LinkedHashMap<>();
+ for (int i = 0; i < ALPHA.length && i < MORSE.length; i++) {
+ ALPHA_TO_MORSE.put(MORSE[i], ALPHA[i]);
+ }
+ List<String> MORSELIST = Arrays.asList(MORSE2);
+ MORSELIST.sort((s1, s2) -> s2.length() - s1.length());
+ LinkedHashMap<String, String> MORSE_TO_ALPHA = new LinkedHashMap<>();
+ for (String s : MORSELIST) {
+ MORSE_TO_ALPHA.put(s, ALPHA_TO_MORSE.get(s));
+ }
+ for (String morseCode : MORSELIST) {
+ if (MORSE_TO_ALPHA.containsKey(morseCode)) {
+ morseContent = morseContent.replaceAll(Pattern.quote(morseCode), MORSE_TO_ALPHA.get(morseCode));
+ }
+ }
+ return morseContent;
+ }
+
private final List<Status> statusList;
private final int TYPE_NORMAL = 0;
private final BaseAccount account;
@@ -142,6 +184,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
private List<Emoji> emojisList = new ArrayList<>();
public promptDraftListener promptDraftListener;
private boolean unlisted_changed = false;
+ public static int currentCursorPosition;
public ComposeAdapter(List<Status> statusList, int statusCount, BaseAccount account, app.fedilab.android.client.entities.api.Account mentionedAccount, String visibility, String editMessageId) {
this.statusList = statusList;
@@ -298,6 +341,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} else {
holder.binding.content.requestFocus();
}
+
}
public void setStatusCount(int count) {
@@ -538,7 +582,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
newContent[0] = Normalizer.normalize(newContent[0], Normalizer.Form.NFD);
newContent[0] = newContent[0].replaceAll("[^\\p{ASCII}]", "");
- HashMap<String, String> ALPHA_TO_MORSE = new HashMap<>();
+ LinkedHashMap<String, String> ALPHA_TO_MORSE = new LinkedHashMap<>();
for (int i = 0; i < ALPHA.length && i < MORSE.length; i++) {
ALPHA_TO_MORSE.put(ALPHA[i], MORSE[i]);
}
@@ -550,7 +594,6 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
String morse = ALPHA_TO_MORSE.get(word.substring(i, i + 1).toLowerCase());
builder.append(morse).append(" ");
}
-
builder.append(" ");
}
newContent[0] = "";
@@ -558,7 +601,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
newContent[0] += mention + " ";
}
newContent[0] += builder.toString();
-
+ newContent[0] = newContent[0].replaceAll("null", "");
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
@@ -590,7 +633,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
return;
}
- String patternh = "^(.|\\s)*(:fedilab_hugs:)$";
+ String patternh = "^(.|\\s)*(:fedilab_hugs:)";
final Pattern hPattern = Pattern.compile(patternh);
Matcher mh = hPattern.matcher((s.toString().substring(currentCursorPosition[0] - searchLength[0], currentCursorPosition[0])));
@@ -599,7 +642,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
return;
}
- String patternM = "^(.|\\s)*(:fedilab_morse:)$";
+ String patternM = "^(.|\\s)*(:fedilab_morse:)";
final Pattern mPattern = Pattern.compile(patternM);
Matcher mm = mPattern.matcher((s.toString().substring(currentCursorPosition[0] - searchLength[0], currentCursorPosition[0])));
if (mm.matches()) {
@@ -852,19 +895,27 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
//It only targets last message in a thread
//Return content of last compose message
public String getLastComposeContent() {
- return statusList.get(statusList.size() - 1).text != null ? statusList.get(statusList.size() - 1).text : "";
+ if (currentCursorPosition < statusList.size()) {
+ return statusList.get(currentCursorPosition).text != null ? statusList.get(currentCursorPosition).text : "";
+ } else return "";
}
//------- end contact ----->
//Used to write contact when composing
public void updateContent(boolean checked, String acct) {
- if (checked) {
- if (!statusList.get(statusList.size() - 1).text.contains(acct))
- statusList.get(statusList.size() - 1).text = String.format("%s %s", acct, statusList.get(statusList.size() - 1).text);
- } else {
- statusList.get(statusList.size() - 1).text = statusList.get(statusList.size() - 1).text.replaceAll("\\s*" + acct, "");
+ if (currentCursorPosition < statusList.size()) {
+ if (checked) {
+ if (statusList.get(currentCursorPosition).text == null) {
+ statusList.get(currentCursorPosition).text = "";
+ }
+ if (!statusList.get(currentCursorPosition).text.contains(acct)) {
+ statusList.get(currentCursorPosition).text = String.format("@%s %s", acct, statusList.get(currentCursorPosition).text);
+ }
+ } else {
+ statusList.get(currentCursorPosition).text = statusList.get(currentCursorPosition).text.replaceAll("@" + acct, "");
+ }
+ notifyItemChanged(currentCursorPosition);
}
- notifyItemChanged(statusList.size() - 1);
}
//Put cursor to the end after changing contacts
@@ -1038,16 +1089,14 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
composeAttachmentItemBinding.preview.setOnClickListener(v -> displayAttachments(holder, position, finalMediaPosition));
if (attachment.description == null || attachment.description.trim().isEmpty()) {
composeAttachmentItemBinding.buttonDescription.setIconResource(R.drawable.ic_baseline_warning_24);
- composeAttachmentItemBinding.buttonDescription.setStrokeColor(ThemeHelper.getNoDescriptionColorStateList(context));
- composeAttachmentItemBinding.buttonDescription.setTextColor(ContextCompat.getColor(context, R.color.no_description));
- Helper.changeDrawableColor(context, R.drawable.ic_baseline_warning_24, ContextCompat.getColor(context, R.color.no_description));
- composeAttachmentItemBinding.buttonDescription.setIconTint(ThemeHelper.getNoDescriptionColorStateList(context));
+ composeAttachmentItemBinding.buttonDescription.setTextColor(ContextCompat.getColor(context, R.color.black));
+ composeAttachmentItemBinding.buttonDescription.setIconTintResource(R.color.black);
+ composeAttachmentItemBinding.buttonDescription.setBackgroundTintList(ThemeHelper.getNoDescriptionColorStateList(context));
} else {
- composeAttachmentItemBinding.buttonDescription.setIconTint(ThemeHelper.getHavingDescriptionColorStateList(context));
composeAttachmentItemBinding.buttonDescription.setIconResource(R.drawable.ic_baseline_check_circle_24);
- composeAttachmentItemBinding.buttonDescription.setTextColor(ContextCompat.getColor(context, R.color.having_description));
- composeAttachmentItemBinding.buttonDescription.setStrokeColor(ThemeHelper.getHavingDescriptionColorStateList(context));
- Helper.changeDrawableColor(context, R.drawable.ic_baseline_check_circle_24, ContextCompat.getColor(context, R.color.having_description));
+ composeAttachmentItemBinding.buttonDescription.setTextColor(ContextCompat.getColor(context, R.color.white));
+ composeAttachmentItemBinding.buttonDescription.setIconTintResource(R.color.white);
+ composeAttachmentItemBinding.buttonDescription.setBackgroundTintList(ThemeHelper.getHavingDescriptionColorStateList(context));
}
holder.binding.attachmentsList.addView(composeAttachmentItemBinding.getRoot());
mediaPosition++;
@@ -1318,6 +1367,11 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
addAttachment(position, uris);
}
});
+ holder.binding.content.setOnFocusChangeListener((view, focused) -> {
+ if (focused) {
+ currentCursorPosition = holder.getLayoutPosition();
+ }
+ });
if (statusDraft.cursorPosition <= holder.binding.content.length()) {
holder.binding.content.setSelection(statusDraft.cursorPosition);
}
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java
index c98b90629..5651ca478 100644
--- a/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java
@@ -60,6 +60,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public FetchMoreCallBack fetchMoreCallBack;
private Context context;
private boolean isExpended = false;
+ private RecyclerView mRecyclerView;
public ConversationAdapter(List<Conversation> conversations) {
if (conversations == null) {
@@ -194,7 +195,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
holder.binding.spoiler.setVisibility(View.VISIBLE);
holder.binding.spoiler.setText(
conversation.last_status.getSpanSpoiler(context,
- new WeakReference<>(holder.binding.spoiler), () -> notifyItemChanged(holder.getBindingAdapterPosition())),
+ new WeakReference<>(holder.binding.spoiler), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))),
TextView.BufferType.SPANNABLE);
} else {
holder.binding.spoiler.setVisibility(View.GONE);
@@ -204,7 +205,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
//--- MAIN CONTENT ---
holder.binding.statusContent.setText(
conversation.last_status.getSpanContent(context,
- new WeakReference<>(holder.binding.statusContent), () -> notifyItemChanged(holder.getBindingAdapterPosition())),
+ new WeakReference<>(holder.binding.statusContent), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))),
TextView.BufferType.SPANNABLE);
//--- DATE ---
holder.binding.lastMessageDate.setText(Helper.dateDiff(context, conversation.last_status.created_at));
@@ -224,6 +225,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
return false;
});
+
displayAttachments(holder, position);
if (holder.timer != null) {
holder.timer.cancel();
@@ -245,6 +247,13 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
applyColorConversation(context, holder);
}
+ @Override
+ public void onAttachedToRecyclerView(RecyclerView recyclerView) {
+ super.onAttachedToRecyclerView(recyclerView);
+
+ mRecyclerView = recyclerView;
+ }
+
private void displayAttachments(ConversationAdapter.ConversationHolder holder, int position) {
if (conversationList.get(position).last_status != null) {
Status status = conversationList.get(position).last_status;
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java
index 12911d4f1..38deccd38 100644
--- a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java
@@ -367,11 +367,9 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} else {
holderStatus.bindingNotification.status.mainContainer.setAlpha(.7f);
- holderStatus.bindingNotification.status.mainContainer.setVisibility(View.VISIBLE);
boolean displayMedia = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_MEDIA_NOTIFICATION), true);
- if (displayMedia && notification.status != null && notification.status.media_attachments != null && notification.status.media_attachments.size() > 0) {
- holderStatus.bindingNotification.status.mediaContainer.setVisibility(View.VISIBLE);
- } else {
+ if (!displayMedia) {
+ holderStatus.bindingNotification.status.attachmentsListContainer.setVisibility(View.GONE);
holderStatus.bindingNotification.status.mediaContainer.setVisibility(View.GONE);
}
String title = "";
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java
index 1bb6e7613..41b29f4b3 100644
--- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java
@@ -395,6 +395,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
boolean confirmBoost = sharedpreferences.getBoolean(context.getString(R.string.SET_NOTIF_VALIDATION), true);
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
boolean displayBookmark = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_BOOKMARK), true);
+ boolean displayTranslate = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_TRANSLATE), false);
boolean displayCounters = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COUNTER_FAV_BOOST), false);
String loadMediaType = sharedpreferences.getString(context.getString(R.string.SET_LOAD_MEDIA_TYPE), "ALWAYS");
@@ -628,6 +629,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else {
holder.binding.actionButtonBookmark.setVisibility(View.GONE);
}
+ if (displayTranslate) {
+ holder.binding.actionButtonTranslate.setVisibility(View.VISIBLE);
+ } else {
+ holder.binding.actionButtonTranslate.setVisibility(View.GONE);
+ }
//--- ACTIONS ---
holder.binding.actionButtonBookmark.setChecked(statusToDeal.bookmarked);
//---> BOOKMARK/UNBOOKMARK
@@ -635,6 +641,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
CrossActionHelper.doCrossAction(context, CrossActionHelper.TypeOfCrossAction.BOOKMARK_ACTION, null, statusToDeal);
return true;
});
+ holder.binding.actionButtonTranslate.setOnClickListener(v -> {
+ translate(context, statusToDeal, holder, adapter);
+ });
holder.binding.actionButtonBookmark.setOnClickListener(v -> {
if (remote) {
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
@@ -887,6 +896,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtonReply.getLayoutParams().width = (int) (normalSize * scaleIcon);
holder.binding.actionButtonReply.getLayoutParams().height = (int) (normalSize * scaleIcon);
holder.binding.actionButtonReply.requestLayout();
+
+ holder.binding.actionButtonTranslate.getLayoutParams().width = (int) (normalSize * scaleIcon);
+ holder.binding.actionButtonTranslate.getLayoutParams().height = (int) (normalSize * scaleIcon);
+ holder.binding.actionButtonTranslate.requestLayout();
+
holder.binding.actionButtonBoost.setImageSize((int) (normalSize * scaleIcon));
holder.binding.actionButtonFavorite.setImageSize((int) (normalSize * scaleIcon));
holder.binding.actionButtonBookmark.setImageSize((int) (normalSize * scaleIcon));
@@ -1453,25 +1467,27 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
return;
}
- if (context instanceof ContextActivity) {
+ if (context instanceof ContextActivity && !remote) {
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_STATUS, statusToDeal);
Fragment fragment = Helper.addFragment(((AppCompatActivity) context).getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, FragmentMastodonContext.class.getName());
((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment);
} else {
if (remote) {
- Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
- searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
- .observe((LifecycleOwner) context, results -> {
- if (results != null && results.statuses != null && results.statuses.size() > 0) {
- Status fetchedStatus = results.statuses.get(0);
- Intent intent = new Intent(context, ContextActivity.class);
- intent.putExtra(Helper.ARG_STATUS, fetchedStatus);
- context.startActivity(intent);
- } else {
- Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
- }
- });
+ if (!(context instanceof ContextActivity)) { //We are not already checking a remote conversation
+ Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
+ searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
+ .observe((LifecycleOwner) context, results -> {
+ if (results != null && results.statuses != null && results.statuses.size() > 0) {
+ Status fetchedStatus = results.statuses.get(0);
+ Intent intent = new Intent(context, ContextActivity.class);
+ intent.putExtra(Helper.ARG_STATUS, fetchedStatus);
+ context.startActivity(intent);
+ } else {
+ Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
+ }
+ });
+ }
} else {
Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal);
@@ -1674,41 +1690,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}));
builderInner.show();
} else if (itemId == R.id.action_translate) {
- MyTransL.translatorEngine et = MyTransL.translatorEngine.LIBRETRANSLATE;
- final MyTransL myTransL = MyTransL.getInstance(et);
- myTransL.setObfuscation(true);
- Params params = new Params();
- params.setSplit_sentences(false);
- params.setFormat(Params.fType.TEXT);
- params.setSource_lang("auto");
- myTransL.setLibretranslateDomain("translate.fedilab.app");
- String statusToTranslate;
- String translate = sharedpreferences.getString(context.getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale());
- if (translate != null && translate.equalsIgnoreCase("default")) {
- translate = MyTransL.getLocale();
- }
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
- statusToTranslate = Html.fromHtml(statusToDeal.content, Html.FROM_HTML_MODE_LEGACY).toString();
- else
- statusToTranslate = Html.fromHtml(statusToDeal.content).toString();
- myTransL.translate(statusToTranslate, translate, params, new Results() {
- @Override
- public void onSuccess(Translate translate) {
- if (translate.getTranslatedContent() != null) {
- statusToDeal.translationShown = true;
- statusToDeal.translationContent = translate.getTranslatedContent();
- adapter.notifyItemChanged(holder.getBindingAdapterPosition());
- } else {
- Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show();
- }
- }
-
- @Override
- public void onFail(HttpsConnectionException httpsConnectionException) {
-
- }
- });
+ translate(context, statusToDeal, holder, adapter);
return true;
} else if (itemId == R.id.action_report) {
Intent intent = new Intent(context, ReportActivity.class);
@@ -1916,6 +1898,56 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
+ private static void translate(Context context, Status statusToDeal,
+ StatusViewHolder holder,
+ RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
+ String statusToTranslate;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ statusToTranslate = Html.fromHtml(statusToDeal.content, Html.FROM_HTML_MODE_LEGACY).toString();
+ else
+ statusToTranslate = Html.fromHtml(statusToDeal.content).toString();
+
+ int countMorseChar = ComposeAdapter.countMorseChar(statusToTranslate);
+ if (countMorseChar < 4) {
+ MyTransL.translatorEngine et = MyTransL.translatorEngine.LIBRETRANSLATE;
+ final MyTransL myTransL = MyTransL.getInstance(et);
+ myTransL.setObfuscation(true);
+ Params params = new Params();
+ params.setSplit_sentences(false);
+ params.setFormat(Params.fType.TEXT);
+ params.setSource_lang("auto");
+ myTransL.setLibretranslateDomain("translate.fedilab.app");
+
+ SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ String translate = sharedpreferences.getString(context.getString(R.string.SET_LIVE_TRANSLATE), MyTransL.getLocale());
+ if (translate != null && translate.equalsIgnoreCase("default")) {
+ translate = MyTransL.getLocale();
+ }
+
+
+ myTransL.translate(statusToTranslate, translate, params, new Results() {
+ @Override
+ public void onSuccess(Translate translate) {
+ if (translate.getTranslatedContent() != null) {
+ statusToDeal.translationShown = true;
+ statusToDeal.translationContent = translate.getTranslatedContent();
+ adapter.notifyItemChanged(holder.getBindingAdapterPosition());
+ } else {
+ Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show();
+ }
+ }
+
+ @Override
+ public void onFail(HttpsConnectionException httpsConnectionException) {
+
+ }
+ });
+ } else {
+ statusToDeal.translationShown = true;
+ statusToDeal.translationContent = ComposeAdapter.morseToText(statusToTranslate);
+ adapter.notifyItemChanged(holder.getBindingAdapterPosition());
+ }
+ }
private static void loadAndAddAttachment(Context context, LayoutMediaBinding layoutMediaBinding,
StatusViewHolder holder,
@@ -2205,6 +2237,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Helper.changeDrawableColor(context, R.drawable.ic_person, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_bot, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_round_reply_24, theme_icons_color);
+ Helper.changeDrawableColor(context, holder.binding.actionButtonTranslate, theme_icons_color);
holder.binding.actionButtonFavorite.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBookmark.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBoost.setInActiveImageTintColor(theme_icons_color);
@@ -2265,8 +2298,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
StatusViewHolder holder = (StatusViewHolder) viewHolder;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
if (sharedpreferences.getBoolean(context.getString(R.string.SET_CARDVIEW), false)) {
- holder.binding.cardviewContainer.setCardElevation(Helper.convertDpToPixel(5, context));
- holder.binding.dividerCard.setVisibility(View.GONE);
+ holder.bindingFilteredHide.cardviewContainer.setCardElevation(Helper.convertDpToPixel(5, context));
+ holder.bindingFilteredHide.dividerCard.setVisibility(View.GONE);
}
if (status.isFetchMore && fetchMoreCallBack != null) {
holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE);
diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java
new file mode 100644
index 000000000..b8be1e3cf
--- /dev/null
+++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentSettingsCategories.java
@@ -0,0 +1,176 @@
+package app.fedilab.android.ui.fragment.settings;
+/* Copyright 2022 Thomas Schneider
+ *
+ * This file is a part of Fedilab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Fedilab; if not,
+ * see <http://www.gnu.org/licenses>. */
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.contract.ActivityResultContracts;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.core.app.ActivityCompat;
+import androidx.navigation.NavController;
+import androidx.navigation.Navigation;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+
+import app.fedilab.android.R;
+import app.fedilab.android.helper.SettingsStorage;
+import es.dmoral.toasty.Toasty;
+
+public class FragmentSettingsCategories extends PreferenceFragmentCompat {
+
+ private static final int REQUEST_CODE = 5412;
+ private static final int PICKUP_FILE = 452;
+
+ @Override
+ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
+ addPreferencesFromResource(R.xml.pref_categories);
+
+
+ Preference pref_category_key_account = findPreference(getString(R.string.pref_category_key_account));
+ if (pref_category_key_account != null) {
+ pref_category_key_account.setOnPreferenceClickListener(preference -> {
+ NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container);
+ navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToAccount());
+ return false;
+ });
+ }
+
+ Preference pref_category_key_timeline = findPreference(getString(R.string.pref_category_key_timeline));
+ if (pref_category_key_timeline != null) {
+ pref_category_key_timeline.setOnPreferenceClickListener(preference -> {
+ NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container);
+ navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToTimelines());
+ return false;
+ });
+ }
+
+ Preference pref_category_key_notifications = findPreference(getString(R.string.pref_category_key_notifications));
+ if (pref_category_key_notifications != null) {
+ pref_category_key_notifications.setOnPreferenceClickListener(preference -> {
+ NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container);
+ navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToNotifications());
+ return false;
+ });
+ }
+
+ Preference pref_category_key_interface = findPreference(getString(R.string.pref_category_key_interface));
+ if (pref_category_key_interface != null) {
+ pref_category_key_interface.setOnPreferenceClickListener(preference -> {
+ NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container);
+ navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToInterface());
+ return false;
+ });
+ }
+
+ Preference pref_category_key_compose = findPreference(getString(R.string.pref_category_key_compose));
+ if (pref_category_key_compose != null) {
+ pref_category_key_compose.setOnPreferenceClickListener(preference -> {
+ NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container);
+ navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToCompose());
+ return false;
+ });
+ }
+
+ Preference pref_category_key_languages = findPreference(getString(R.string.pref_category_key_languages));
+ if (pref_category_key_languages != null) {
+ pref_category_key_languages.setOnPreferenceClickListener(preference -> {
+ NavController navController = Navigation.findNavController(requireActivity(), R.id.fragment_container);
+ navController.navigate(FragmentSettingsCategoriesDirections.Companion.categoriesToLanguage());
+ return false;
+ });
+ }
+
+ Preference pref_category_key_privacy = findPreference(getString(R.string.pref_category_key_privacy));
+ if (pref_category_key_privacy != null) {
+ pref_category_key_privacy.setOnPref