1
0
mirror of https://framagit.org/tom79/nitterizeme synced 2024-12-25 07:52:45 +01:00

Add logic to Wikiless #61

This commit is contained in:
Thomas 2021-10-25 17:23:14 +02:00
parent a86f8e0925
commit b9ae945002
2 changed files with 66 additions and 3 deletions

View File

@ -86,6 +86,7 @@ public class MainActivity extends AppCompatActivity {
private String bibliogramHost;
private String tedditHost;
private String scriberipHost;
private String wikilessHost;
private String osmHost;
private ContentMainBinding binding;
@ -109,6 +110,7 @@ public class MainActivity extends AppCompatActivity {
boolean bibliogram_enabled = sharedpreferences.getBoolean(SET_BIBLIOGRAM_ENABLED, true);
boolean teddit_enabled = sharedpreferences.getBoolean(SET_TEDDIT_ENABLED, true);
boolean scriberip_enabled = sharedpreferences.getBoolean(SET_SCRIBERIP_ENABLED, true);
boolean wikiless_enabled = sharedpreferences.getBoolean(SET_WIKILESS_ENABLED, true);
boolean geouri_enabled = sharedpreferences.getBoolean(SET_GEO_URIS, false);
boolean embedded_player = sharedpreferences.getBoolean(SET_EMBEDDED_PLAYER, false);
@ -117,6 +119,7 @@ public class MainActivity extends AppCompatActivity {
binding.enableBibliogram.setChecked(bibliogram_enabled);
binding.enableTeddit.setChecked(teddit_enabled);
binding.enableScriberip.setChecked(scriberip_enabled);
binding.enableWikiless.setChecked(wikiless_enabled);
binding.enableOsm.setChecked(osm_enabled);
@ -126,6 +129,7 @@ public class MainActivity extends AppCompatActivity {
bibliogramHost = sharedpreferences.getString(SET_BIBLIOGRAM_HOST, null);
tedditHost = sharedpreferences.getString(SET_TEDDIT_HOST, null);
scriberipHost = sharedpreferences.getString(SET_SCRIBERIP_HOST, null);
wikilessHost = sharedpreferences.getString(SET_WIKILESS_HOST, null);
osmHost = sharedpreferences.getString(SET_OSM_HOST, null);
binding.groupCurrentInvidious.setVisibility(invidious_enabled ? View.VISIBLE : View.GONE);
@ -133,6 +137,7 @@ public class MainActivity extends AppCompatActivity {
binding.groupCurrentBibliogram.setVisibility(bibliogram_enabled ? View.VISIBLE : View.GONE);
binding.groupCurrentTeddit.setVisibility(bibliogram_enabled ? View.VISIBLE : View.GONE);
binding.groupCurrentScriberip.setVisibility(scriberip_enabled ? View.VISIBLE : View.GONE);
binding.groupCurrentWikiless.setVisibility(wikiless_enabled ? View.VISIBLE : View.GONE);
binding.groupCurrentOsm.setVisibility((osm_enabled && geouri_enabled) ? View.VISIBLE : View.GONE);
binding.enableGeoUris.setVisibility(osm_enabled ? View.VISIBLE : View.GONE);
binding.enableEmbedPlayer.setVisibility(invidious_enabled ? View.VISIBLE : View.GONE);
@ -178,6 +183,14 @@ public class MainActivity extends AppCompatActivity {
binding.groupCustomScriberip.setVisibility(View.GONE);
binding.buttonExpandInstanceScriberip.setRotation(0);
});
binding.enableWikiless.setOnCheckedChangeListener((buttonView, isChecked) -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(SET_WIKILESS_ENABLED, isChecked);
editor.apply();
binding.groupCurrentWikiless.setVisibility(isChecked ? View.VISIBLE : View.GONE);
binding.groupCustomWikiless.setVisibility(View.GONE);
binding.buttonExpandInstanceWikiless.setRotation(0);
});
binding.enableOsm.setOnCheckedChangeListener((buttonView, isChecked) -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(SET_OSM_ENABLED, isChecked);
@ -279,6 +292,21 @@ public class MainActivity extends AppCompatActivity {
binding.scriberipInstance.setText("");
}
});
binding.buttonExpandInstanceWikiless.setOnClickListener(v -> {
boolean custom_instance_visibility = binding.groupCustomWikiless.getVisibility() == View.VISIBLE;
if (custom_instance_visibility) {
binding.buttonExpandInstanceWikiless.setRotation(0f);
binding.groupCustomWikiless.setVisibility(View.GONE);
} else {
binding.buttonExpandInstanceWikiless.setRotation(180f);
binding.groupCustomWikiless.setVisibility(View.VISIBLE);
}
if (wikilessHost != null) {
binding.wikilessInstance.setText(wikilessHost);
} else {
binding.wikilessInstance.setText("");
}
});
binding.buttonExpandInstanceOsm.setOnClickListener(v -> {
boolean custom_instance_visibility = binding.groupCustomOsm.getVisibility() == View.VISIBLE;
if (custom_instance_visibility) {
@ -327,6 +355,12 @@ public class MainActivity extends AppCompatActivity {
} else {
binding.currentInstanceScriberip.setText(DEFAULT_SCRIBERIP_HOST);
}
if (wikilessHost != null) {
binding.wikilessInstance.setText(wikilessHost);
binding.currentInstanceWikiless.setText(wikilessHost);
} else {
binding.currentInstanceWikiless.setText(DEFAULT_WIKILESS_HOST);
}
if (osmHost != null) {
binding.osmInstance.setText(osmHost);
binding.currentInstanceOsm.setText(osmHost);
@ -404,6 +438,18 @@ public class MainActivity extends AppCompatActivity {
}
editor.apply();
});
binding.buttonSaveInstanceWikiless.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
if (binding.wikilessInstance.getText() != null && binding.wikilessInstance.getText().toString().trim().length() > 0) {
String custom_instance = binding.wikilessInstance.getText().toString().toLowerCase().trim();
editor.putString(SET_WIKILESS_HOST, custom_instance);
binding.currentInstanceWikiless.setText(custom_instance);
} else {
editor.putString(SET_WIKILESS_HOST, null);
binding.currentInstanceWikiless.setText(DEFAULT_WIKILESS_HOST);
}
editor.apply();
});
binding.buttonSaveInstanceOsm.setOnClickListener(v -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
if (binding.osmInstance.getText() != null && binding.osmInstance.getText().toString().trim().length() > 0) {
@ -502,6 +548,15 @@ public class MainActivity extends AppCompatActivity {
binding.currentInstanceScriberip.setText(DEFAULT_SCRIBERIP_HOST);
binding.buttonExpandInstanceScriberip.setRotation(0f);
break;
case SET_WIKILESS_HOST:
wikilessHost = sharedpreferences.getString(SET_WIKILESS_HOST, null);
binding.groupCustomWikiless.setVisibility(View.GONE);
if (wikilessHost != null && wikilessHost.trim().length() > 0)
binding.currentInstanceWikiless.setText(wikilessHost);
else
binding.currentInstanceWikiless.setText(DEFAULT_WIKILESS_HOST);
binding.buttonExpandInstanceWikiless.setRotation(0f);
break;
case SET_OSM_HOST:
osmHost = sharedpreferences.getString(SET_OSM_HOST, null);
binding.groupCustomOsm.setVisibility(View.GONE);
@ -576,6 +631,7 @@ public class MainActivity extends AppCompatActivity {
String bibliogramHost = sharedpreferences.getString(SET_BIBLIOGRAM_HOST, null);
String tedditHost = sharedpreferences.getString(SET_TEDDIT_HOST, null);
String scriberipHost = sharedpreferences.getString(SET_SCRIBERIP_HOST, null);
String wikilessHost = sharedpreferences.getString(SET_WIKILESS_HOST, null);
if (nitterHost != null) {
binding.nitterInstance.setText(nitterHost);
binding.currentInstanceNitter.setText(nitterHost);
@ -596,6 +652,10 @@ public class MainActivity extends AppCompatActivity {
binding.scriberipInstance.setText(scriberipHost);
binding.currentInstanceScriberip.setText(scriberipHost);
}
if (wikilessHost != null) {
binding.wikilessInstance.setText(wikilessHost);
binding.currentInstanceWikiless.setText(wikilessHost);
}
if (BuildConfig.fullLinks) {
List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(new Intent(Intent.ACTION_VIEW, Uri.parse("https://fedilab.app")), PackageManager.MATCH_DEFAULT_ONLY);
String thisPackageName = getApplicationContext().getPackageName();

View File

@ -97,6 +97,7 @@ import static app.fedilab.nitterizeme.activities.MainActivity.SET_NITTER_ENABLED
import static app.fedilab.nitterizeme.activities.MainActivity.SET_SCRIBERIP_ENABLED;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_TEDDIT_ENABLED;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_TEDDIT_HOST;
import static app.fedilab.nitterizeme.activities.MainActivity.SET_WIKILESS_ENABLED;
public class Utils {
@ -112,8 +113,7 @@ public class Utils {
public static final Pattern scriberipSubdomainPattern = Pattern.compile("([\\w_-]+)\\.medium.com/(((?!([\"'<])).)*)");
public static final Pattern wikilessPattern = Pattern.compile("(www\\.)?wikipedia.org/(((?!([\"'<])).)*)");
public static final Pattern wikilessSubdomainPattern = Pattern.compile("([\\w_-]+)\\.wikipedia.org/(((?!([\"'<])).)*)");
public static final Pattern wikilessPattern = Pattern.compile("([\\w_-]+)\\.wikipedia.org/(((?!([\"'<])).)*)");
public static final Pattern bibliogramAccountPattern = Pattern.compile("(m\\.|www\\.)?instagram.com(((?!/p/).)+)");
public static final Pattern maps = Pattern.compile("/maps/place/([^@]+@)?([\\d.,z]+).*");
@ -1256,7 +1256,8 @@ public class Utils {
return Arrays.asList(twitter_domains).contains(host) || Arrays.asList(nitter_instances).contains(host) || Arrays.asList(reddit_domains).contains(host)
|| Arrays.asList(instagram_domains).contains(host) || Arrays.asList(bibliogram_instances).contains(host)
|| url.contains("/maps/place") || url.contains("/amp/s/") || (host != null && host.contains(outlook_safe_domain))
|| Arrays.asList(youtube_domains).contains(host) || Arrays.asList(invidious_instances).contains(host) || (host != null && host.endsWith(medium_domains[0]));
|| Arrays.asList(youtube_domains).contains(host) || Arrays.asList(invidious_instances).contains(host)
|| (host != null && host.endsWith(medium_domains[0]) || (host != null && host.endsWith(wikipedi_domains[0])));
}
public static boolean routerEnabledForHost(Context context, String url) {
@ -1282,6 +1283,8 @@ public class Utils {
return sharedpreferences.getBoolean(SET_TEDDIT_ENABLED, true);
} else if (host != null && host.endsWith(medium_domains[0])) {
return sharedpreferences.getBoolean(SET_SCRIBERIP_ENABLED, true);
} else if (host != null && host.endsWith(wikipedi_domains[0])) {
return sharedpreferences.getBoolean(SET_WIKILESS_ENABLED, true);
} else
return url.contains("/amp/s/") || (host != null && host.contains(outlook_safe_domain));
}