From c590ab48f5c2e7e63e7759c263475443dd6044be Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 1 Jan 2023 11:55:32 +0100 Subject: [PATCH] Some cleaning --- .../app/fedilab/android/BaseMainActivity.java | 14 +- .../activities/AccountReportActivity.java | 1 + .../android/activities/ComposeActivity.java | 9 +- .../android/activities/ProfileActivity.java | 3 +- .../android/client/entities/api/Account.java | 60 +++---- .../android/client/entities/api/Status.java | 8 +- .../entities/api/admin/AdminAccount.java | 20 +-- .../client/entities/app/StatusCache.java | 2 +- .../app/fedilab/android/helper/Helper.java | 29 ++-- .../fedilab/android/helper/MediaHelper.java | 20 +-- .../android/helper/PinnedTimelineHelper.java | 1 - .../android/helper/SpannableHelper.java | 6 +- .../fedilab/android/helper/ThemeHelper.java | 2 - .../imageeditor/EditImageActivity.java | 4 +- .../android/ui/drawer/AccountAdapter.java | 2 +- .../android/ui/drawer/ComposeAdapter.java | 148 ++++++++-------- .../ui/drawer/ConversationAdapter.java | 32 ++-- .../android/ui/drawer/FieldAdapter.java | 2 +- .../android/ui/drawer/InstanceRegAdapter.java | 23 ++- .../ui/drawer/NotificationAdapter.java | 88 +++++----- .../android/ui/drawer/StatusAdapter.java | 163 +++++++++--------- .../fragment/admin/FragmentAdminReport.java | 1 - .../ui/fragment/login/FragmentLoginMain.java | 4 +- .../fragment/media/FragmentMediaProfile.java | 4 +- .../settings/FragmentThemingSettings.java | 1 - .../timeline/FragmentMastodonContext.java | 3 +- .../timeline/FragmentMastodonTimeline.java | 6 +- .../timeline/FragmentProfileTimeline.java | 1 + .../FedilabProfilePageAdapter.java | 2 +- .../FedilabProfileTLPageAdapter.java | 2 +- 30 files changed, 320 insertions(+), 341 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index ecfd4c63..dff1f87b 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -165,6 +165,7 @@ import retrofit2.converter.gson.GsonConverterFactory; public abstract class BaseMainActivity extends BaseActivity implements NetworkStateReceiver.NetworkStateReceiverListener, FragmentMastodonTimeline.UpdateCounters, FragmentNotificationContainer.UpdateCounters, FragmentMastodonConversation.UpdateCounters { + private static final int REQUEST_CODE = 5415; public static String currentInstance, currentToken, currentUserID, client_id, client_secret, software; public static HashMap> emojis = new HashMap<>(); public static Account.API api; @@ -297,7 +298,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt }; private NetworkStateReceiver networkStateReceiver; private boolean headerMenuOpen; - private static final int REQUEST_CODE = 5415; @Override protected void onCreate(Bundle savedInstanceState) { @@ -786,7 +786,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt }); - binding.toolbarSearch.setOnSearchClickListener(v -> binding.tabLayout.setVisibility(View.VISIBLE)); //For receiving data from other activities LocalBroadcastManager.getInstance(BaseMainActivity.this).registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA)); @@ -1042,7 +1041,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt String title = ""; String description = ""; - if(titleEl != null) { + if (titleEl != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { title = Html.fromHtml(titleEl.attr("content"), Html.FROM_HTML_MODE_LEGACY).toString(); } else { @@ -1050,7 +1049,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } } - if(descriptionEl != null) { + if (descriptionEl != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { description = Html.fromHtml(descriptionEl.attr("content"), Html.FROM_HTML_MODE_LEGACY).toString(); } else { @@ -1059,13 +1058,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt } String imageUrl = ""; - if(imageUrlEl != null) { + if (imageUrlEl != null) { imageUrl = imageUrlEl.attr("content"); } StringBuilder titleBuilder = new StringBuilder(); - if(!originalUrl.trim().equalsIgnoreCase(sharedText.trim())) { + if (!originalUrl.trim().equalsIgnoreCase(sharedText.trim())) { // If the shared text is not just the URL, add it to the top String toAppend = sharedText.replaceAll("\\s*" + Pattern.quote(originalUrl) + "\\s*", ""); titleBuilder.append(toAppend); @@ -1073,7 +1072,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (title.length() > 0) { // OG title fetched from source - if(titleBuilder.length() > 0) titleBuilder.append("\n\n"); + if (titleBuilder.length() > 0) + titleBuilder.append("\n\n"); titleBuilder.append(title); } diff --git a/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java b/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java index 03fda1b7..384a7698 100644 --- a/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AccountReportActivity.java @@ -320,6 +320,7 @@ public class AccountReportActivity extends BaseBarActivity { } } + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index 5ff370ba..622c3677 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -107,11 +107,6 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana private Status statusReply, statusMention, statusQuoted; private StatusDraft statusDraft; private ComposeAdapter composeAdapter; - private boolean promptSaveDraft; - private boolean restoredDraft; - private List sharedAttachments; - - private final BroadcastReceiver imageReceiver = new BroadcastReceiver() { @Override public void onReceive(android.content.Context context, Intent intent) { @@ -138,7 +133,9 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana } } }; - + private boolean promptSaveDraft; + private boolean restoredDraft; + private List sharedAttachments; private ActivityPaginationBinding binding; private BaseAccount account; private String instance, token; diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index 97b13d76..1edb5385 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -117,8 +117,6 @@ public class ProfileActivity extends BaseActivity { private String mention_str; private WellKnownNodeinfo.NodeInfo nodeInfo; private boolean checkRemotely; - private boolean homeMuted; - private final BroadcastReceiver broadcast_data = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -133,6 +131,7 @@ public class ProfileActivity extends BaseActivity { } } }; + private boolean homeMuted; @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Account.java b/app/src/main/java/app/fedilab/android/client/entities/api/Account.java index 6631be8f..36667aa8 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Account.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Account.java @@ -87,28 +87,6 @@ public class Account implements Serializable { public Account moved; @SerializedName("role") public Role role; - - - public static class Role implements Serializable { - @SerializedName("id") - public String id; - @SerializedName("name") - public String name; - @SerializedName("color") - public String color; - @SerializedName("position") - public int position; - @SerializedName("permissions") - public int permissions; - @SerializedName("highlighted") - public boolean highlighted; - @SerializedName("created_at") - public Date created_at; - @SerializedName("updated_at") - public Date updated_at; - } - - public transient RelationShip relationShip; public synchronized Spannable getSpanDisplayName(Context context, WeakReference viewWeakReference) { @@ -133,6 +111,34 @@ public class Account implements Serializable { return SpannableHelper.convert(context, note, null, this, null, viewWeakReference); } + @Override + public boolean equals(@Nullable Object obj) { + boolean same = false; + if (obj instanceof Account) { + same = this.id.equals(((Account) obj).id); + } + return same; + } + + public static class Role implements Serializable { + @SerializedName("id") + public String id; + @SerializedName("name") + public String name; + @SerializedName("color") + public String color; + @SerializedName("position") + public int position; + @SerializedName("permissions") + public int permissions; + @SerializedName("highlighted") + public boolean highlighted; + @SerializedName("created_at") + public Date created_at; + @SerializedName("updated_at") + public Date updated_at; + } + public static class AccountParams implements Serializable { @SerializedName("discoverable") public boolean discoverable; @@ -150,14 +156,4 @@ public class Account implements Serializable { public LinkedHashMap fields; } - - - @Override - public boolean equals(@Nullable Object obj) { - boolean same = false; - if (obj instanceof Account) { - same = this.id.equals(((Account) obj).id); - } - return same; - } } diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java index ecc2a07e..994a0d39 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java @@ -153,10 +153,6 @@ public class Status implements Serializable, Cloneable { return contentTranslateSpan; } - public interface Callback { - void emojiFetched(); - } - @NonNull public Object clone() throws CloneNotSupportedException { return super.clone(); @@ -167,4 +163,8 @@ public class Status implements Serializable, Cloneable { BOTTOM } + public interface Callback { + void emojiFetched(); + } + } diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/admin/AdminAccount.java b/app/src/main/java/app/fedilab/android/client/entities/api/admin/AdminAccount.java index 26eb86a7..070f91e3 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/admin/AdminAccount.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/admin/AdminAccount.java @@ -25,16 +25,6 @@ import app.fedilab.android.client.entities.api.Account; public class AdminAccount implements Serializable { - @SerializedName("id") - public String id; - @SerializedName("username") - public String username; - @SerializedName("domain") - public String domain; - @SerializedName("created_at") - public Date created_at; - @SerializedName("email") - public String email; public static LinkedHashMap permissions; static { @@ -61,6 +51,16 @@ public class AdminAccount implements Serializable { permissions.put(80000, "Delete User Data"); } + @SerializedName("id") + public String id; + @SerializedName("username") + public String username; + @SerializedName("domain") + public String domain; + @SerializedName("created_at") + public Date created_at; + @SerializedName("email") + public String email; @SerializedName("ip") public String ip; @SerializedName("role") diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java b/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java index 62672258..d60a72ed 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/StatusCache.java @@ -509,7 +509,7 @@ public class StatusCache { try { db.delete(Sqlite.TABLE_STATUS_CACHE, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =? AND " + Sqlite.COL_STATUS + " LIKE ?", - new String[]{userid, instance, "%\"id\":\"" + targetedUser + "\"%" }); + new String[]{userid, instance, "%\"id\":\"" + targetedUser + "\"%"}); } catch (Exception e) { e.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 5af0b727..f8c58819 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -1965,6 +1965,20 @@ public class Helper { return R.style.AppTheme; } + public static void addMutedAccount(app.fedilab.android.client.entities.api.Account target) { + if (MainActivity.filteredAccounts == null) { + MainActivity.filteredAccounts = new ArrayList<>(); + } + if (!MainActivity.filteredAccounts.contains(target)) { + MainActivity.filteredAccounts.add(target); + } + } + + public static void removeMutedAccount(app.fedilab.android.client.entities.api.Account target) { + if (MainActivity.filteredAccounts != null) { + MainActivity.filteredAccounts.remove(target); + } + } //Enum that described actions to replace inside a toot content public enum PatternType { @@ -1996,19 +2010,4 @@ public class Helper { public interface OnFileCopied { void onFileCopied(File file); } - - public static void addMutedAccount(app.fedilab.android.client.entities.api.Account target) { - if (MainActivity.filteredAccounts == null) { - MainActivity.filteredAccounts = new ArrayList<>(); - } - if (!MainActivity.filteredAccounts.contains(target)) { - MainActivity.filteredAccounts.add(target); - } - } - - public static void removeMutedAccount(app.fedilab.android.client.entities.api.Account target) { - if (MainActivity.filteredAccounts != null) { - MainActivity.filteredAccounts.remove(target); - } - } } diff --git a/app/src/main/java/app/fedilab/android/helper/MediaHelper.java b/app/src/main/java/app/fedilab/android/helper/MediaHelper.java index 352075b6..770436b5 100644 --- a/app/src/main/java/app/fedilab/android/helper/MediaHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/MediaHelper.java @@ -409,15 +409,6 @@ public class MediaHelper { return maxHeight; } - //Listener for recording media - public interface ActionRecord { - void onRecorded(String file); - } - - public interface OnSchedule { - void scheduledAt(String scheduledDate); - } - public static void ResizedImageRequestBody(Context context, Uri uri, File targetedFile) { InputStream decodeBitmapInputStream = null; try { @@ -529,7 +520,6 @@ public class MediaHelper { } } - private static long getMaxSize(long maxSize) { if (MainActivity.instanceInfo != null && MainActivity.instanceInfo.configuration != null && MainActivity.instanceInfo.configuration.media_attachments != null) { maxSize = MainActivity.instanceInfo.configuration.media_attachments.image_size_limit; @@ -584,4 +574,14 @@ public class MediaHelper { return null; } + + //Listener for recording media + public interface ActionRecord { + void onRecorded(String file); + } + + public interface OnSchedule { + void scheduledAt(String scheduledDate); + } + } diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index 9457b9c5..125212d3 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -98,7 +98,6 @@ public class PinnedTimelineHelper { } - public synchronized static void redrawTopBarPinned(BaseMainActivity activity, ActivityMainBinding activityMainBinding, Pinned pinned, BottomMenu bottomMenu, List mastodonLists) { //Values must be initialized if there is no records in db if (pinned == null) { diff --git a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java index 2e3ba27a..f27a3593 100644 --- a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java @@ -88,16 +88,13 @@ import es.dmoral.toasty.Toasty; public class SpannableHelper { public static final String CLICKABLE_SPAN = "CLICKABLE_SPAN"; + private static int linkColor; public static Spannable convert(Context context, String text, Status status, Account account, Announcement announcement, WeakReference viewWeakReference) { return convert(context, text, status, account, announcement, viewWeakReference, null); } - - private static int linkColor; - - public static Spannable convert(Context context, String text, Status status, Account account, Announcement announcement, WeakReference viewWeakReference, Status.Callback callback) { @@ -613,7 +610,6 @@ public class SpannableHelper { } - /** * Remove extra carriage returns at the bottom due to

tags in toots * diff --git a/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java b/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java index 15fd4b08..46223b1a 100644 --- a/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java @@ -70,7 +70,6 @@ public class ThemeHelper { } - /** * Animate two views, the current view will be hidden to left * @@ -230,7 +229,6 @@ public class ThemeHelper { } - /** * Allow to set colors for having description on media * diff --git a/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java b/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java index f0d5ea6b..6433e015 100644 --- a/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java +++ b/app/src/main/java/app/fedilab/android/imageeditor/EditImageActivity.java @@ -71,6 +71,8 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList private final ConstraintSet mConstraintSet = new ConstraintSet(); PhotoEditor mPhotoEditor; String path; + CropImageContractOptions cropImageContractOptions; + ActivityResultLauncher cropImageContractOptionsActivityResultLauncher; private PropertiesBSFragment mPropertiesBSFragment; private ShapeBSFragment mShapeBSFragment; private ShapeBuilder mShapeBuilder; @@ -79,8 +81,6 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList private Uri uri; private boolean exit; private ActivityEditImageBinding binding; - CropImageContractOptions cropImageContractOptions; - ActivityResultLauncher cropImageContractOptionsActivityResultLauncher; private static int exifToDegrees(int exifOrientation) { if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java index 3ccea89d..9faa16bc 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java @@ -56,8 +56,8 @@ import es.dmoral.toasty.Toasty; public class AccountAdapter extends RecyclerView.Adapter { private final List accountList; - private Context context; private final boolean home_mute; + private Context context; public AccountAdapter(List accountList, boolean home_mute) { this.accountList = accountList; 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 0a6b23ba..dcfc3147 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 @@ -150,6 +150,30 @@ public class ComposeAdapter extends RecyclerView.Adapter statusList; + private final int TYPE_NORMAL = 0; + private final BaseAccount account; + private final String visibility; + private final app.fedilab.android.client.entities.api.Account mentionedAccount; + private final String editMessageId; + public ManageDrafts manageDrafts; + public promptDraftListener promptDraftListener; + private int statusCount; + private Context context; + private AlertDialog alertDialogEmoji; + private List emojisList = new ArrayList<>(); + private boolean unlisted_changed = false; + + public ComposeAdapter(List statusList, int statusCount, BaseAccount account, app.fedilab.android.client.entities.api.Account mentionedAccount, String visibility, String editMessageId) { + this.statusList = statusList; + this.statusCount = statusCount; + this.account = account; + this.mentionedAccount = mentionedAccount; + this.visibility = visibility; + this.editMessageId = editMessageId; + + } public static int countMorseChar(String content) { int count_char = 0; @@ -180,81 +204,6 @@ public class ComposeAdapter extends RecyclerView.Adapter statusList; - private final int TYPE_NORMAL = 0; - private final BaseAccount account; - private final String visibility; - private final app.fedilab.android.client.entities.api.Account mentionedAccount; - private final String editMessageId; - public ManageDrafts manageDrafts; - private int statusCount; - private Context context; - private AlertDialog alertDialogEmoji; - private List emojisList = new ArrayList<>(); - public promptDraftListener promptDraftListener; - private boolean unlisted_changed = false; - public static int currentCursorPosition; - - public ComposeAdapter(List statusList, int statusCount, BaseAccount account, app.fedilab.android.client.entities.api.Account mentionedAccount, String visibility, String editMessageId) { - this.statusList = statusList; - this.statusCount = statusCount; - this.account = account; - this.mentionedAccount = mentionedAccount; - this.visibility = visibility; - this.editMessageId = editMessageId; - - } - - /** - * Add an attachment from ComposeActivity - * - * @param position int - position of the drawer that added a media - * @param uris List - uris of the media - */ - public void addAttachment(int position, List uris) { - if (position == -1) { - position = statusList.size() - 1; - } - // position = statusCount-1+position; - if (statusList.get(position).media_attachments == null) { - statusList.get(position).media_attachments = new ArrayList<>(); - } - if (promptDraftListener != null) { - promptDraftListener.promptDraft(); - } - int finalPosition = position; - Helper.createAttachmentFromUri(context, uris, attachments -> { - for (Attachment attachment : attachments) { - statusList.get(finalPosition).media_attachments.add(attachment); - } - notifyItemChanged(finalPosition); - }); - } - - - /** - * Add an attachment from ComposeActivity - * - * @param position int - position of the drawer that added a media - * @param attachment Attachment - media attachment - */ - public void addAttachment(int position, Attachment attachment) { - if (position == -1) { - position = statusList.size() - 1; - } - // position = statusCount-1+position; - if (statusList.get(position).media_attachments == null) { - statusList.get(position).media_attachments = new ArrayList<>(); - } - if (promptDraftListener != null) { - promptDraftListener.promptDraft(); - } - int finalPosition = position; - statusList.get(finalPosition).media_attachments.add(attachment); - notifyItemChanged(finalPosition); - - } - private static void updateCharacterCount(ComposeViewHolder composeViewHolder) { int charCount = MastodonHelper.countLength(composeViewHolder); composeViewHolder.binding.characterCount.setText(String.valueOf(charCount)); @@ -285,6 +234,55 @@ public class ComposeAdapter extends RecyclerView.Adapter - uris of the media + */ + public void addAttachment(int position, List uris) { + if (position == -1) { + position = statusList.size() - 1; + } + // position = statusCount-1+position; + if (statusList.get(position).media_attachments == null) { + statusList.get(position).media_attachments = new ArrayList<>(); + } + if (promptDraftListener != null) { + promptDraftListener.promptDraft(); + } + int finalPosition = position; + Helper.createAttachmentFromUri(context, uris, attachments -> { + for (Attachment attachment : attachments) { + statusList.get(finalPosition).media_attachments.add(attachment); + } + notifyItemChanged(finalPosition); + }); + } + + /** + * Add an attachment from ComposeActivity + * + * @param position int - position of the drawer that added a media + * @param attachment Attachment - media attachment + */ + public void addAttachment(int position, Attachment attachment) { + if (position == -1) { + position = statusList.size() - 1; + } + // position = statusCount-1+position; + if (statusList.get(position).media_attachments == null) { + statusList.get(position).media_attachments = new ArrayList<>(); + } + if (promptDraftListener != null) { + promptDraftListener.promptDraft(); + } + int finalPosition = position; + statusList.get(finalPosition).media_attachments.add(attachment); + notifyItemChanged(finalPosition); + + } + //Create text when mentioning a toot public void loadMentions(Status status) { //Get the first draft 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 5651ca47..2defcdb7 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 @@ -69,22 +69,6 @@ public class ConversationAdapter extends RecyclerView.Adapter { private final List fields; - private Context context; private final Account account; + private Context context; public FieldAdapter(List fields, Account account) { this.fields = fields; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java index 82a5703d..f58954cb 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java @@ -40,8 +40,12 @@ import app.fedilab.android.helper.Helper; public class InstanceRegAdapter extends RecyclerView.Adapter { private final List joinMastodonInstanceList; - private Context context; public ActionClick actionClick; + private Context context; + + public InstanceRegAdapter(List joinMastodonInstanceList) { + this.joinMastodonInstanceList = joinMastodonInstanceList; + } @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { @@ -67,11 +71,6 @@ public class InstanceRegAdapter extends RecyclerView.Adapter actionClick.trends(position)); } - - public InstanceRegAdapter(List joinMastodonInstanceList) { - this.joinMastodonInstanceList = joinMastodonInstanceList; - } - public int getCount() { return joinMastodonInstanceList.size(); } @@ -88,12 +87,6 @@ public class InstanceRegAdapter extends RecyclerView.Adapter } - @Override - public void onAttachedToRecyclerView(RecyclerView recyclerView) { - super.onAttachedToRecyclerView(recyclerView); - - mRecyclerView = recyclerView; - } - - /* private static boolean mediaObfuscated(Status status) { - //Media is not sensitive and doesn't have a spoiler text - if (!status.isMediaObfuscated) { - return false; - } - if (!status.sensitive && (status.spoiler_text == null || status.spoiler_text.trim().isEmpty())) { - return false; - } - if (status.isMediaObfuscated && status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) { - return true; - } else { - return status.sensitive; - } - }*/ - /** * Send a broadcast to other open fragments that content a timeline * @@ -2261,68 +2239,20 @@ public class StatusAdapter extends RecyclerView.Adapter LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC); } - - @Override - public int getItemViewType(int position) { - if (timelineType == Timeline.TimeLineEnum.ART) { - return STATUS_ART; + /* private static boolean mediaObfuscated(Status status) { + //Media is not sensitive and doesn't have a spoiler text + if (!status.isMediaObfuscated) { + return false; + } + if (!status.sensitive && (status.spoiler_text == null || status.spoiler_text.trim().isEmpty())) { + return false; + } + if (status.isMediaObfuscated && status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) { + return true; } else { - if (statusList.get(position).filteredByApp != null) { - if (statusList.get(position).filteredByApp.filter_action.equals("warn")) { - return STATUS_FILTERED; - } else { //These messages should not be displayed unless they contain a fetch more button - if (!statusList.get(position).isFetchMore) { - return STATUS_HIDDEN; - } else { - return STATUS_FILTERED_HIDE; - } - } - } else { - return isVisible(timelineType, statusList.get(position)) ? STATUS_VISIBLE : STATUS_HIDDEN; - } - + return status.sensitive; } - } - - @NonNull - @Override - public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - context = parent.getContext(); - if (viewType == STATUS_HIDDEN) { //Hidden statuses - ie: filtered - DrawerStatusHiddenBinding itemBinding = DrawerStatusHiddenBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - return new StatusViewHolder(itemBinding); - } else if (viewType == STATUS_ART) { //Art statuses - DrawerStatusArtBinding itemBinding = DrawerStatusArtBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - return new StatusViewHolder(itemBinding); - } else if (viewType == STATUS_FILTERED) { //Filtered warn - DrawerStatusFilteredBinding itemBinding = DrawerStatusFilteredBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - return new StatusViewHolder(itemBinding); - } else if (viewType == STATUS_FILTERED_HIDE) { //Filtered hide - DrawerStatusFilteredHideBinding itemBinding = DrawerStatusFilteredHideBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - return new StatusViewHolder(itemBinding); - } else { //Classic statuses - if (!minified) { - DrawerStatusBinding itemBinding = DrawerStatusBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - return new StatusViewHolder(itemBinding); - } else { - DrawerStatusReportBinding itemBinding = DrawerStatusReportBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); - return new StatusViewHolder(itemBinding); - } - } - } - - public int getCount() { - return statusList.size(); - } - - public Status getItem(int position) { - return statusList.get(position); - } - - - public long getItemId(int position) { - return position; - } + }*/ public static void applyColor(Context context, StatusViewHolder holder) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -2410,6 +2340,74 @@ public class StatusAdapter extends RecyclerView.Adapter } } + @Override + public void onAttachedToRecyclerView(RecyclerView recyclerView) { + super.onAttachedToRecyclerView(recyclerView); + + mRecyclerView = recyclerView; + } + + @Override + public int getItemViewType(int position) { + if (timelineType == Timeline.TimeLineEnum.ART) { + return STATUS_ART; + } else { + if (statusList.get(position).filteredByApp != null) { + if (statusList.get(position).filteredByApp.filter_action.equals("warn")) { + return STATUS_FILTERED; + } else { //These messages should not be displayed unless they contain a fetch more button + if (!statusList.get(position).isFetchMore) { + return STATUS_HIDDEN; + } else { + return STATUS_FILTERED_HIDE; + } + } + } else { + return isVisible(timelineType, statusList.get(position)) ? STATUS_VISIBLE : STATUS_HIDDEN; + } + + } + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + context = parent.getContext(); + if (viewType == STATUS_HIDDEN) { //Hidden statuses - ie: filtered + DrawerStatusHiddenBinding itemBinding = DrawerStatusHiddenBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new StatusViewHolder(itemBinding); + } else if (viewType == STATUS_ART) { //Art statuses + DrawerStatusArtBinding itemBinding = DrawerStatusArtBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new StatusViewHolder(itemBinding); + } else if (viewType == STATUS_FILTERED) { //Filtered warn + DrawerStatusFilteredBinding itemBinding = DrawerStatusFilteredBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new StatusViewHolder(itemBinding); + } else if (viewType == STATUS_FILTERED_HIDE) { //Filtered hide + DrawerStatusFilteredHideBinding itemBinding = DrawerStatusFilteredHideBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new StatusViewHolder(itemBinding); + } else { //Classic statuses + if (!minified) { + DrawerStatusBinding itemBinding = DrawerStatusBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new StatusViewHolder(itemBinding); + } else { + DrawerStatusReportBinding itemBinding = DrawerStatusReportBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new StatusViewHolder(itemBinding); + } + } + } + + public int getCount() { + return statusList.size(); + } + + public Status getItem(int position) { + return statusList.get(position); + } + + public long getItemId(int position) { + return position; + } + @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { //Nothing to do with hidden statuses @@ -2604,6 +2602,7 @@ public class StatusAdapter extends RecyclerView.Adapter DrawerStatusArtBinding bindingArt; DrawerStatusFilteredBinding bindingFiltered; DrawerStatusFilteredHideBinding bindingFilteredHide; + StatusViewHolder(DrawerStatusBinding itemView) { super(itemView.getRoot()); binding = itemView; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/admin/FragmentAdminReport.java b/app/src/main/java/app/fedilab/android/ui/fragment/admin/FragmentAdminReport.java index 2aad4a37..8f8cc33b 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/admin/FragmentAdminReport.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/admin/FragmentAdminReport.java @@ -200,5 +200,4 @@ public class FragmentAdminReport extends Fragment { } - } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java index 8b4be76d..6840be3a 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java @@ -68,11 +68,11 @@ import es.dmoral.toasty.Toasty; public class FragmentLoginMain extends Fragment { + private static final int REQUEST_CODE = 5412; + private final int PICK_IMPORT = 5557; private FragmentLoginMainBinding binding; private boolean searchInstanceRunning = false; private String oldSearch; - private static final int REQUEST_CODE = 5412; - private final int PICK_IMPORT = 5557; private ActivityResultLauncher permissionLauncher; public View onCreateView(@NonNull LayoutInflater inflater, diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMediaProfile.java b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMediaProfile.java index 2bfc1721..86670549 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMediaProfile.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMediaProfile.java @@ -46,6 +46,8 @@ import es.dmoral.toasty.Toasty; public class FragmentMediaProfile extends Fragment { + String tempToken; + String tempInstance; private FragmentPaginationBinding binding; private AccountsVM accountsVM; private Account accountTimeline; @@ -53,8 +55,6 @@ public class FragmentMediaProfile extends Fragment { private List mediaStatuses; private String max_id; private ImageAdapter imageAdapter; - String tempToken; - String tempInstance; private boolean checkRemotely; private String accountId; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java index b6b407e5..62ca1258 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java @@ -32,7 +32,6 @@ import es.dmoral.toasty.Toasty; public class FragmentThemingSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { - @Override public void onCreatePreferences(Bundle bundle, String s) { createPref(); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonContext.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonContext.java index ffa1d129..0e3352de 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonContext.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonContext.java @@ -50,12 +50,11 @@ import app.fedilab.android.viewmodel.mastodon.StatusesVM; public class FragmentMastodonContext extends Fragment { + public FirstMessage firstMessage; private FragmentPaginationBinding binding; private StatusesVM statusesVM; private List statuses; private StatusAdapter statusAdapter; - public FirstMessage firstMessage; - //Handle actions that can be done in other fragments private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index cc7bdf6f..fd4543cb 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -84,9 +84,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. private StatusAdapter statusAdapter; private Timeline.TimeLineEnum timelineType; private List timelineStatuses; - private boolean checkRemotely; - private String accountIDInRemoteInstance; - //Handle actions that can be done in other fragments private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override @@ -162,6 +159,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } } }; + private boolean checkRemotely; + private String accountIDInRemoteInstance; private boolean isViewInitialized; private Statuses initialStatuses; private String list_id; @@ -180,6 +179,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. private int lockForResumeCall; private boolean isNotPinnedTimeline; private int extraCalls; + //Allow to recreate data when detaching/attaching fragment public void recreate() { initialStatuses = null; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentProfileTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentProfileTimeline.java index 76bec3fb..a7a27092 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentProfileTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentProfileTimeline.java @@ -36,6 +36,7 @@ public class FragmentProfileTimeline extends Fragment { private Account account; private FragmentProfileTimelinesBinding binding; private boolean checkRemotely; + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfilePageAdapter.java b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfilePageAdapter.java index 372f7659..6d7a10e3 100644 --- a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfilePageAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfilePageAdapter.java @@ -30,8 +30,8 @@ import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline; public class FedilabProfilePageAdapter extends FragmentStatePagerAdapter { private final Account account; - private Fragment mCurrentFragment; private final boolean checkRemotely; + private Fragment mCurrentFragment; public FedilabProfilePageAdapter(FragmentManager fm, Account account, boolean remotely) { super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); diff --git a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfileTLPageAdapter.java b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfileTLPageAdapter.java index ca2ebb26..582aa9d4 100644 --- a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfileTLPageAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabProfileTLPageAdapter.java @@ -30,8 +30,8 @@ import app.fedilab.android.ui.fragment.timeline.FragmentProfileTimeline; public class FedilabProfileTLPageAdapter extends FragmentStatePagerAdapter { private final Account account; - private Fragment mCurrentFragment; private final boolean checkRemotely; + private Fragment mCurrentFragment; public FedilabProfileTLPageAdapter(FragmentManager fm, Account account, boolean remotely) { super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);