From 97ebb9c36e813343a1b592ba6826f25139d802f1 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 15 Sep 2022 16:06:05 +0200 Subject: [PATCH] Fix Nitter issues + invalid ssl certificate for onion (no longer supported for Google) --- .../timeline/FragmentMastodonTimeline.java | 9 +++++---- .../android/viewmodel/mastodon/TimelinesVM.java | 16 ++++++++++++---- .../android/webview/FedilabWebViewClient.java | 9 +++++++-- 3 files changed, 24 insertions(+), 10 deletions(-) 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 2ca187c3..b9b0f2ea 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 @@ -589,8 +589,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. if (binding == null || getActivity() == null || !isAdded()) { return; } + boolean nitterInstance = timelineType == Timeline.TimeLineEnum.REMOTE && pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER; QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(BaseMainActivity.currentUserID, BaseMainActivity.currentInstance, timelineType, ident); - if (!fetchingMissing && !binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { + if (!nitterInstance && !fetchingMissing && !binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { Statuses statuses = new Statuses(); statuses.statuses = quickLoad.statuses; statuses.pagination = new Pagination(); @@ -655,15 +656,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. //NITTER TIMELINES if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) { if (direction == null) { - timelinesVM.getNitter(remoteInstance, pinnedTimeline.remoteInstance.host, null) + timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null) .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); } else if (direction == DIRECTION.BOTTOM) { - timelinesVM.getNitter(remoteInstance, pinnedTimeline.remoteInstance.host, max_id) + timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id) .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false)); } else if (direction == DIRECTION.TOP) { flagLoading = false; } else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) { - timelinesVM.getNitter(remoteInstance, pinnedTimeline.remoteInstance.host, null) + timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null) .observe(getViewLifecycleOwner(), statusesRefresh -> { if (statusAdapter != null) { dealWithPagination(statusesRefresh, direction, true); diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index c6c5097f..88731ecd 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -16,6 +16,8 @@ package app.fedilab.android.viewmodel.mastodon; import android.app.Application; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Handler; import android.os.Looper; @@ -23,12 +25,14 @@ import androidx.annotation.NonNull; import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; +import androidx.preference.PreferenceManager; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import app.fedilab.android.BaseMainActivity; +import app.fedilab.android.R; import app.fedilab.android.client.endpoints.MastodonTimelinesService; import app.fedilab.android.client.entities.api.Account; import app.fedilab.android.client.entities.api.Conversation; @@ -210,9 +214,13 @@ public class TimelinesVM extends AndroidViewModel { * @param max_position Return results older than this id * @return {@link LiveData} containing a {@link Statuses} */ - public LiveData getNitter(@NonNull String instance, - String accountsStr, - String max_position) { + public LiveData getNitter( + String accountsStr, + String max_position) { + Context context = getApplication().getApplicationContext(); + SharedPreferences sharedpreferences = PreferenceManager + .getDefaultSharedPreferences(context); + String instance = sharedpreferences.getString(context.getString(R.string.SET_NITTER_HOST), context.getString(R.string.DEFAULT_NITTER_HOST)).toLowerCase(); MastodonTimelinesService mastodonTimelinesService = initInstanceXMLOnly(instance); accountsStr = accountsStr.replaceAll("\\s", ","); statusesMutableLiveData = new MutableLiveData<>(); @@ -229,7 +237,7 @@ public class TimelinesVM extends AndroidViewModel { List statusList = new ArrayList<>(); if (rssResponse != null && rssResponse.mFeedItems != null) { for (Nitter.FeedItem feedItem : rssResponse.mFeedItems) { - if (feedItem.title.startsWith("RT by")) { + if (!feedItem.title.startsWith("RT by")) { Status status = Nitter.convert(getApplication(), instance, feedItem); statusList.add(status); } diff --git a/app/src/main/java/app/fedilab/android/webview/FedilabWebViewClient.java b/app/src/main/java/app/fedilab/android/webview/FedilabWebViewClient.java index 24b0337f..1b2324d1 100644 --- a/app/src/main/java/app/fedilab/android/webview/FedilabWebViewClient.java +++ b/app/src/main/java/app/fedilab/android/webview/FedilabWebViewClient.java @@ -39,6 +39,7 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; +import app.fedilab.android.BuildConfig; import app.fedilab.android.R; import app.fedilab.android.activities.WebviewActivity; @@ -111,8 +112,12 @@ public class FedilabWebViewClient extends WebViewClient { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { - if (view.getUrl() != null && view.getUrl().endsWith(".onion")) { - handler.proceed(); + if (BuildConfig.DONATIONS) { + if (view.getUrl() != null && view.getUrl().endsWith(".onion")) { + handler.proceed(); + } else { + super.onReceivedSslError(view, handler, error); + } } else { super.onReceivedSslError(view, handler, error); }