Support teddit
This commit is contained in:
parent
39b183d2dc
commit
2c5bb5aa58
|
@ -63,13 +63,16 @@ public class InstanceActivity extends AppCompatActivity {
|
||||||
String invidiousHost = sharedpreferences.getString(MainActivity.SET_INVIDIOUS_HOST, MainActivity.DEFAULT_INVIDIOUS_HOST);
|
String invidiousHost = sharedpreferences.getString(MainActivity.SET_INVIDIOUS_HOST, MainActivity.DEFAULT_INVIDIOUS_HOST);
|
||||||
String nitterHost = sharedpreferences.getString(MainActivity.SET_NITTER_HOST, MainActivity.DEFAULT_NITTER_HOST);
|
String nitterHost = sharedpreferences.getString(MainActivity.SET_NITTER_HOST, MainActivity.DEFAULT_NITTER_HOST);
|
||||||
String bibliogramHost = sharedpreferences.getString(MainActivity.SET_BIBLIOGRAM_HOST, MainActivity.DEFAULT_BIBLIOGRAM_HOST);
|
String bibliogramHost = sharedpreferences.getString(MainActivity.SET_BIBLIOGRAM_HOST, MainActivity.DEFAULT_BIBLIOGRAM_HOST);
|
||||||
|
String tedditHost = sharedpreferences.getString(MainActivity.SET_TEDDIT_HOST, MainActivity.DEFAULT_TEDDIT_HOST);
|
||||||
|
|
||||||
ArrayList<Instance> invidiousInstances = new ArrayList<>();
|
ArrayList<Instance> invidiousInstances = new ArrayList<>();
|
||||||
ArrayList<Instance> nitterInstances = new ArrayList<>();
|
ArrayList<Instance> nitterInstances = new ArrayList<>();
|
||||||
ArrayList<Instance> bibliogramInstances = new ArrayList<>();
|
ArrayList<Instance> bibliogramInstances = new ArrayList<>();
|
||||||
|
ArrayList<Instance> tedditInstances = new ArrayList<>();
|
||||||
boolean customInvidiousInstance = true;
|
boolean customInvidiousInstance = true;
|
||||||
boolean customNitterInstance = true;
|
boolean customNitterInstance = true;
|
||||||
boolean customBibliogramInstance = true;
|
boolean customBibliogramInstance = true;
|
||||||
|
boolean customTedditInstance = true;
|
||||||
for (Instance instance : result) {
|
for (Instance instance : result) {
|
||||||
if (instance.getType() == Instance.instanceType.INVIDIOUS) {
|
if (instance.getType() == Instance.instanceType.INVIDIOUS) {
|
||||||
invidiousInstances.add(instance);
|
invidiousInstances.add(instance);
|
||||||
|
@ -86,6 +89,11 @@ public class InstanceActivity extends AppCompatActivity {
|
||||||
if (bibliogramHost != null && bibliogramHost.trim().toLowerCase().compareTo(instance.getDomain()) == 0) {
|
if (bibliogramHost != null && bibliogramHost.trim().toLowerCase().compareTo(instance.getDomain()) == 0) {
|
||||||
customBibliogramInstance = false;
|
customBibliogramInstance = false;
|
||||||
}
|
}
|
||||||
|
} else if (instance.getType() == Instance.instanceType.TEDDIT) {
|
||||||
|
tedditInstances.add(instance);
|
||||||
|
if (tedditHost != null && tedditHost.trim().toLowerCase().compareTo(instance.getDomain()) == 0) {
|
||||||
|
customTedditInstance = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Check if custom instances are also added
|
//Check if custom instances are also added
|
||||||
|
@ -110,6 +118,13 @@ public class InstanceActivity extends AppCompatActivity {
|
||||||
instance.setLocale("--");
|
instance.setLocale("--");
|
||||||
bibliogramInstances.add(0, instance);
|
bibliogramInstances.add(0, instance);
|
||||||
}
|
}
|
||||||
|
if (customTedditInstance) {
|
||||||
|
Instance instance = new Instance();
|
||||||
|
instance.setChecked(true);
|
||||||
|
instance.setDomain(tedditHost);
|
||||||
|
instance.setLocale("--");
|
||||||
|
tedditInstances.add(0, instance);
|
||||||
|
}
|
||||||
binding.instanceContainer.setVisibility(View.VISIBLE);
|
binding.instanceContainer.setVisibility(View.VISIBLE);
|
||||||
binding.loader.setVisibility(View.GONE);
|
binding.loader.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
@ -132,6 +147,14 @@ public class InstanceActivity extends AppCompatActivity {
|
||||||
binding.bibliogramInstances.setLayoutManager(bLayoutManager);
|
binding.bibliogramInstances.setLayoutManager(bLayoutManager);
|
||||||
binding.bibliogramInstances.setNestedScrollingEnabled(false);
|
binding.bibliogramInstances.setNestedScrollingEnabled(false);
|
||||||
|
|
||||||
|
|
||||||
|
final LinearLayoutManager tLayoutManager = new LinearLayoutManager(this);
|
||||||
|
InstanceAdapter tedditAdapter = new InstanceAdapter(tedditInstances);
|
||||||
|
binding.tedditInstances.setAdapter(tedditAdapter);
|
||||||
|
binding.tedditInstances.setLayoutManager(tLayoutManager);
|
||||||
|
binding.tedditInstances.setNestedScrollingEnabled(false);
|
||||||
|
|
||||||
|
|
||||||
binding.latencyTest.setOnClickListener(v -> {
|
binding.latencyTest.setOnClickListener(v -> {
|
||||||
invidiousAdapter.evalLatency();
|
invidiousAdapter.evalLatency();
|
||||||
nitterAdapter.evalLatency();
|
nitterAdapter.evalLatency();
|
||||||
|
|
|
@ -74,6 +74,7 @@ public class Instance {
|
||||||
public enum instanceType {
|
public enum instanceType {
|
||||||
INVIDIOUS,
|
INVIDIOUS,
|
||||||
NITTER,
|
NITTER,
|
||||||
BIBLIOGRAM
|
BIBLIOGRAM,
|
||||||
|
TEDDIT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -673,6 +673,21 @@ public class Utils {
|
||||||
return timeDifference;
|
return timeDifference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove unwanted redirects from Google - recursive removal
|
||||||
|
*
|
||||||
|
* @param url String initial url
|
||||||
|
* @return String url without Google redirects
|
||||||
|
*/
|
||||||
|
private static String removeGoogleRedirects(String url) {
|
||||||
|
Matcher matcher = googleRedirect.matcher(url);
|
||||||
|
if (matcher.find()) {
|
||||||
|
return remove_tracking_param(matcher.group(5));
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean URLs from utm parameters
|
* Clean URLs from utm parameters
|
||||||
*
|
*
|
||||||
|
@ -689,14 +704,7 @@ public class Utils {
|
||||||
url = url.replaceAll("#" + utm + "=" + urlRegex, "");
|
url = url.replaceAll("#" + utm + "=" + urlRegex, "");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Matcher matcher = googleRedirect.matcher(url);
|
url = removeGoogleRedirects(url);
|
||||||
if (matcher.find()) {
|
|
||||||
url = matcher.group(5);
|
|
||||||
}
|
|
||||||
matcher = googleRedirect.matcher(url);
|
|
||||||
if (matcher.find()) {
|
|
||||||
url = matcher.group(5);
|
|
||||||
}
|
|
||||||
URL redirectURL = new URL(url);
|
URL redirectURL = new URL(url);
|
||||||
String host = redirectURL.getHost();
|
String host = redirectURL.getHost();
|
||||||
if (host != null) {
|
if (host != null) {
|
||||||
|
@ -984,7 +992,7 @@ public class Utils {
|
||||||
if (Objects.requireNonNull(matcher.group(2)).compareTo("preview.redd.it") == 0 ||
|
if (Objects.requireNonNull(matcher.group(2)).compareTo("preview.redd.it") == 0 ||
|
||||||
Objects.requireNonNull(matcher.group(2)).compareTo("i.redd.it") == 0
|
Objects.requireNonNull(matcher.group(2)).compareTo("i.redd.it") == 0
|
||||||
) {
|
) {
|
||||||
newUrlFinal = scheme + tedditHost + "/pics/w:null_" + redditPath.split("\\?")[0];
|
newUrlFinal = scheme + tedditHost + "/pics/w:null_" + (redditPath != null ? redditPath.split("\\?|%26")[0] : "null");
|
||||||
} else {
|
} else {
|
||||||
newUrlFinal = scheme + tedditHost + "/" + redditPath;
|
newUrlFinal = scheme + tedditHost + "/" + redditPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,11 @@ import static app.fedilab.nitterizeme.activities.MainActivity.APP_PREFS;
|
||||||
import static app.fedilab.nitterizeme.activities.MainActivity.DEFAULT_BIBLIOGRAM_HOST;
|
import static app.fedilab.nitterizeme.activities.MainActivity.DEFAULT_BIBLIOGRAM_HOST;
|
||||||
import static app.fedilab.nitterizeme.activities.MainActivity.DEFAULT_INVIDIOUS_HOST;
|
import static app.fedilab.nitterizeme.activities.MainActivity.DEFAULT_INVIDIOUS_HOST;
|
||||||
import static app.fedilab.nitterizeme.activities.MainActivity.DEFAULT_NITTER_HOST;
|
import static app.fedilab.nitterizeme.activities.MainActivity.DEFAULT_NITTER_HOST;
|
||||||
|
import static app.fedilab.nitterizeme.activities.MainActivity.DEFAULT_TEDDIT_HOST;
|
||||||
import static app.fedilab.nitterizeme.activities.MainActivity.SET_BIBLIOGRAM_HOST;
|
import static app.fedilab.nitterizeme.activities.MainActivity.SET_BIBLIOGRAM_HOST;
|
||||||
import static app.fedilab.nitterizeme.activities.MainActivity.SET_INVIDIOUS_HOST;
|
import static app.fedilab.nitterizeme.activities.MainActivity.SET_INVIDIOUS_HOST;
|
||||||
import static app.fedilab.nitterizeme.activities.MainActivity.SET_NITTER_HOST;
|
import static app.fedilab.nitterizeme.activities.MainActivity.SET_NITTER_HOST;
|
||||||
|
import static app.fedilab.nitterizeme.activities.MainActivity.SET_TEDDIT_HOST;
|
||||||
|
|
||||||
public class SearchInstanceVM extends AndroidViewModel {
|
public class SearchInstanceVM extends AndroidViewModel {
|
||||||
private MutableLiveData<List<Instance>> instancesMLD;
|
private MutableLiveData<List<Instance>> instancesMLD;
|
||||||
|
@ -100,12 +102,14 @@ public class SearchInstanceVM extends AndroidViewModel {
|
||||||
SharedPreferences sharedpreferences = getApplication().getApplicationContext().getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = getApplication().getApplicationContext().getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
|
||||||
String defaultInvidious = sharedpreferences.getString(SET_INVIDIOUS_HOST, DEFAULT_INVIDIOUS_HOST);
|
String defaultInvidious = sharedpreferences.getString(SET_INVIDIOUS_HOST, DEFAULT_INVIDIOUS_HOST);
|
||||||
String defaultNitter = sharedpreferences.getString(SET_NITTER_HOST, DEFAULT_NITTER_HOST);
|
String defaultNitter = sharedpreferences.getString(SET_NITTER_HOST, DEFAULT_NITTER_HOST);
|
||||||
|
String defaultTeddit = sharedpreferences.getString(SET_TEDDIT_HOST, DEFAULT_TEDDIT_HOST);
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(response);
|
JSONObject jsonObject = new JSONObject(response);
|
||||||
JSONArray jsonArrayInvidious = jsonObject.getJSONArray("invidious");
|
JSONArray jsonArrayInvidious = jsonObject.getJSONArray("invidious");
|
||||||
JSONArray jsonArrayNitter = jsonObject.getJSONArray("nitter");
|
JSONArray jsonArrayNitter = jsonObject.getJSONArray("nitter");
|
||||||
|
JSONArray jsonArrayTeddit = jsonObject.getJSONArray("teddit");
|
||||||
for (int i = 0; i < jsonArrayInvidious.length(); i++) {
|
for (int i = 0; i < jsonArrayInvidious.length(); i++) {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
String domain = jsonArrayInvidious.getJSONObject(i).getString("domain");
|
String domain = jsonArrayInvidious.getJSONObject(i).getString("domain");
|
||||||
|
@ -134,6 +138,20 @@ public class SearchInstanceVM extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
instances.add(instance);
|
instances.add(instance);
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < jsonArrayTeddit.length(); i++) {
|
||||||
|
Instance instance = new Instance();
|
||||||
|
String domain = jsonArrayTeddit.getJSONObject(i).getString("domain");
|
||||||
|
boolean cloudFlare = jsonArrayTeddit.getJSONObject(i).getBoolean("cloudflare");
|
||||||
|
String locale = jsonArrayTeddit.getJSONObject(i).getString("locale");
|
||||||
|
instance.setDomain(domain);
|
||||||
|
instance.setCloudflare(cloudFlare);
|
||||||
|
instance.setLocale(locale);
|
||||||
|
instance.setType(Instance.instanceType.TEDDIT);
|
||||||
|
if (defaultTeddit != null && domain.compareTo(defaultTeddit) == 0) {
|
||||||
|
instance.setChecked(true);
|
||||||
|
}
|
||||||
|
instances.add(instance);
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,19 @@
|
||||||
android:id="@+id/bibliogram_instances"
|
android:id="@+id/bibliogram_instances"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="@string/teddit_instances"
|
||||||
|
android:textColor="@color/colorAccent"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/teddit_instances"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
android:id="@+id/locale"
|
android:id="@+id/locale"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginEnd="2dp"
|
android:layout_marginEnd="5dp"
|
||||||
android:layout_marginRight="2dp"
|
android:layout_marginRight="5dp"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:textAllCaps="true"
|
android:textAllCaps="true"
|
||||||
app:layout_constraintBottom_toTopOf="@id/barrier_latency_top"
|
app:layout_constraintBottom_toTopOf="@id/barrier_latency_top"
|
||||||
|
|
|
@ -64,6 +64,7 @@
|
||||||
<string name="invidious_instances">Invidious instances</string>
|
<string name="invidious_instances">Invidious instances</string>
|
||||||
<string name="nitter_instances">Nitter instances</string>
|
<string name="nitter_instances">Nitter instances</string>
|
||||||
<string name="bibliogram_instances">Bibliogram instances</string>
|
<string name="bibliogram_instances">Bibliogram instances</string>
|
||||||
|
<string name="teddit_instances">Teddit instances</string>
|
||||||
<string name="latency">Latency</string>
|
<string name="latency">Latency</string>
|
||||||
<string name="error_message_internet">Check your Internet connection</string>
|
<string name="error_message_internet">Check your Internet connection</string>
|
||||||
<string name="instance_label">Instance:</string>
|
<string name="instance_label">Instance:</string>
|
||||||
|
|
Loading…
Reference in New Issue