From 78fccc9578ace80f8b63c92362c267f9febf7f81 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Apr 2025 12:28:30 +0200 Subject: [PATCH 1/3] Fix issue #810 - Wrong preview picture on share from another app --- .../java/app/fedilab/android/mastodon/helper/Helper.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java index 016dc369..6beaa52c 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/Helper.java @@ -1848,7 +1848,6 @@ public class Helper { if (responseCode == HttpURLConnection.HTTP_OK) { String fileName = ""; String disposition = httpURLConnection.getHeaderField("Content-Disposition"); - if (disposition != null) { // extracts file name from header field int index = disposition.indexOf("filename="); @@ -1858,7 +1857,12 @@ public class Helper { } } else { // extracts file name from URL - fileName = downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1); + try { + URL downLoadUrlTmp = new URL(downloadUrl); + fileName = downLoadUrlTmp.getPath().replace("/","_"); + }catch (Exception exception) { + fileName = downloadUrl.substring(downloadUrl.lastIndexOf("/") + 1); + } } fileName = FileNameCleaner.cleanFileName(fileName); // opens input stream from the HTTP connection From 3bde1ae5788662ea48a532754f2e3846cadaae9a Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 9 Apr 2025 15:57:45 +0200 Subject: [PATCH 2/3] Fix a potential crash when translating with MinT --- .../com/github/stom79/mytransl/translate/Translate.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java b/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java index 7c9af07b..2e5c224d 100644 --- a/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java +++ b/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java @@ -373,8 +373,11 @@ public class Translate { //Retrieves the translated content String content; try { - content = URLDecoder.decode(translationJson.getString("translation"), "utf-8"); - } catch (UnsupportedEncodingException e) { + String data = translationJson.getString("translation"); + data = data.replaceAll("%(?![0-9a-fA-F]{2})", "%25"); + data = data.replaceAll("\\+", "%2B"); + content = URLDecoder.decode(data, "utf-8"); + } catch (Exception e) { content = translationJson.getString("translation"); } translate.setTranslatedContent(content); From 578c9b3d6674bfa0ecd23c4932679828d732da10 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 12 Apr 2025 10:49:34 +0200 Subject: [PATCH 3/3] Fix issue #1173 - Refresh and pagination broken for the Trending timeline --- .../timeline/FragmentMastodonTimeline.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java index 8f15fa9b..5d0f2459 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -631,7 +631,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. binding.loader.setVisibility(View.GONE); binding.noAction.setVisibility(View.GONE); binding.swipeContainer.setRefreshing(false); - if (searchCache == null && timelineType != Timeline.TimeLineEnum.TREND_MESSAGE) { + if (searchCache == null ) { binding.swipeContainer.setOnRefreshListener(() -> { binding.swipeContainer.setRefreshing(true); flagLoading = false; @@ -722,7 +722,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. binding.recyclerView.addOnScrollListener(preloader); binding.recyclerView.setItemViewCacheSize(0); - if (timelineType != Timeline.TimeLineEnum.TREND_MESSAGE) { + binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { @@ -759,7 +759,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. if (slug != null /*&& slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0*/ && rememberPosition) { route(DIRECTION.FETCH_NEW, true); } - } + } @@ -1132,7 +1132,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } }); } - } else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.PIXELFED) { + } + else if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.PIXELFED) { if (direction == null) { timelinesVM.getPixelfedDiscoverTrending(remoteInstance) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); @@ -1197,9 +1198,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. accountId[0] = accountTimeline.id; } displayStatuses(direction, accountId[0], tempInstance[0], tempToken[0], fetchStatus); - } else if (search != null) { + } + else if (search != null) { SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class); - if (direction == null) { searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.SEARCH_PER_CALL) .observe(getViewLifecycleOwner(), results -> { @@ -1225,7 +1226,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } else { flagLoading = false; } - } else if (searchCache != null) { + } + else if (searchCache != null) { SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class); searchVM.searchCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, searchCache.trim()) .observe(getViewLifecycleOwner(), results -> { @@ -1238,7 +1240,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_LONG).show(); } }); - } else if (timelineType == Timeline.TimeLineEnum.FAVOURITE_TIMELINE) { + } + else if (timelineType == Timeline.TimeLineEnum.FAVOURITE_TIMELINE) { if (direction == null) { accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); @@ -1248,7 +1251,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } else { flagLoading = false; } - } else if (timelineType == Timeline.TimeLineEnum.BOOKMARK_TIMELINE) { + } + else if (timelineType == Timeline.TimeLineEnum.BOOKMARK_TIMELINE) { if (direction == null) { accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, null, null) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); @@ -1258,17 +1262,28 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } else { flagLoading = false; } - } else if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE) { + } + else if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE) { if (direction == null) { timelinesVM.getStatusTrends(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, null, MastodonHelper.statusesPerCall(requireActivity())) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); } else if (direction == DIRECTION.BOTTOM) { timelinesVM.getStatusTrends(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, max_id, MastodonHelper.statusesPerCall(requireActivity())) .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus)); - } else { + }else if (direction == DIRECTION.TOP) { flagLoading = false; + } else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.FETCH_NEW) { + timelinesVM.getStatusTrends(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, null, MastodonHelper.statusesPerCall(requireActivity())) + .observe(getViewLifecycleOwner(), statusesRefresh -> { + if (statusAdapter != null) { + dealWithPagination(statusesRefresh, direction, true, true, fetchStatus); + } else { + initializeStatusesCommonView(statusesRefresh); + } + }); } - } else if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE_PUBLIC) { + } + else if (timelineType == Timeline.TimeLineEnum.TREND_MESSAGE_PUBLIC) { if (direction == null) { timelinesVM.getStatusTrends(null, publicTrendsDomain, null, MastodonHelper.statusesPerCall(requireActivity())) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);