Fix Nitter issues + invalid ssl certificate for onion (no longer supported for Google)

This commit is contained in:
Thomas 2022-09-15 16:06:05 +02:00
parent 1e65074a4b
commit 97ebb9c36e
3 changed files with 24 additions and 10 deletions

View File

@ -589,8 +589,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (binding == null || getActivity() == null || !isAdded()) { if (binding == null || getActivity() == null || !isAdded()) {
return; 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); 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 = new Statuses();
statuses.statuses = quickLoad.statuses; statuses.statuses = quickLoad.statuses;
statuses.pagination = new Pagination(); statuses.pagination = new Pagination();
@ -655,15 +656,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
//NITTER TIMELINES //NITTER TIMELINES
if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) { if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
if (direction == null) { if (direction == null) {
timelinesVM.getNitter(remoteInstance, pinnedTimeline.remoteInstance.host, null) timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } 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)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
flagLoading = false; flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) { } 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 -> { .observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) { if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true); dealWithPagination(statusesRefresh, direction, true);

View File

@ -16,6 +16,8 @@ package app.fedilab.android.viewmodel.mastodon;
import android.app.Application; import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -23,12 +25,14 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.preference.PreferenceManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.client.endpoints.MastodonTimelinesService; import app.fedilab.android.client.endpoints.MastodonTimelinesService;
import app.fedilab.android.client.entities.api.Account; import app.fedilab.android.client.entities.api.Account;
import app.fedilab.android.client.entities.api.Conversation; 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 * @param max_position Return results older than this id
* @return {@link LiveData} containing a {@link Statuses} * @return {@link LiveData} containing a {@link Statuses}
*/ */
public LiveData<Statuses> getNitter(@NonNull String instance, public LiveData<Statuses> getNitter(
String accountsStr, String accountsStr,
String max_position) { 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); MastodonTimelinesService mastodonTimelinesService = initInstanceXMLOnly(instance);
accountsStr = accountsStr.replaceAll("\\s", ","); accountsStr = accountsStr.replaceAll("\\s", ",");
statusesMutableLiveData = new MutableLiveData<>(); statusesMutableLiveData = new MutableLiveData<>();
@ -229,7 +237,7 @@ public class TimelinesVM extends AndroidViewModel {
List<Status> statusList = new ArrayList<>(); List<Status> statusList = new ArrayList<>();
if (rssResponse != null && rssResponse.mFeedItems != null) { if (rssResponse != null && rssResponse.mFeedItems != null) {
for (Nitter.FeedItem feedItem : rssResponse.mFeedItems) { 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); Status status = Nitter.convert(getApplication(), instance, feedItem);
statusList.add(status); statusList.add(status);
} }

View File

@ -39,6 +39,7 @@ import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import app.fedilab.android.BuildConfig;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.WebviewActivity; import app.fedilab.android.activities.WebviewActivity;
@ -111,8 +112,12 @@ public class FedilabWebViewClient extends WebViewClient {
@Override @Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
if (view.getUrl() != null && view.getUrl().endsWith(".onion")) { if (BuildConfig.DONATIONS) {
handler.proceed(); if (view.getUrl() != null && view.getUrl().endsWith(".onion")) {
handler.proceed();
} else {
super.onReceivedSslError(view, handler, error);
}
} else { } else {
super.onReceivedSslError(view, handler, error); super.onReceivedSslError(view, handler, error);
} }