Allow to disable the feature

This commit is contained in:
Thomas 2020-01-29 12:58:26 +01:00
parent 26e3e91012
commit 39712fa8e5
5 changed files with 79 additions and 2 deletions

View File

@ -82,6 +82,22 @@
<data android:scheme="https"
android:host="youtube-nocookie.com" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:pathPattern="/maps/.*"
android:host="google.com" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:pathPattern="/maps/.*"
android:host="www.google.com" />
</intent-filter>
</activity>
<activity

View File

@ -52,6 +52,7 @@ public class MainActivity extends AppCompatActivity {
public static String DEFAULT_INVIDIOUS_HOST = "invidio.us";
public static String SET_INVIDIOUS_ENABLED = "set_invidious_enabled";
public static String SET_NITTER_ENABLED = "set_nitter_enabled";
public static String SET_OSM_ENABLED = "set_osm_enabled";
public static final String APP_PREFS = "app_prefs";
//Supported domains
@ -63,7 +64,9 @@ public class MainActivity extends AppCompatActivity {
"youtube.com",
"m.youtube.com",
"youtu.be",
"youtube-nocookie.com"
"youtube-nocookie.com",
"google.com/maps",
"www.google.com/maps"
};
@Override
@ -82,12 +85,15 @@ public class MainActivity extends AppCompatActivity {
SwitchCompat enable_nitter = findViewById(R.id.enable_nitter);
SwitchCompat enable_invidious = findViewById(R.id.enable_invidious);
SwitchCompat enable_osm = findViewById(R.id.enable_osm);
boolean nitter_enabled = sharedpreferences.getBoolean(SET_NITTER_ENABLED, true);
boolean invidious_enabled = sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true);
boolean osm_enabled = sharedpreferences.getBoolean(SET_OSM_ENABLED, true);
enable_nitter.setChecked(nitter_enabled);
enable_invidious.setChecked(invidious_enabled);
enable_osm.setChecked(osm_enabled);
Button button_save = findViewById(R.id.button_save);
RecyclerView list_apps = findViewById(R.id.list_apps);
@ -104,6 +110,11 @@ public class MainActivity extends AppCompatActivity {
editor.putBoolean(SET_NITTER_ENABLED, isChecked);
editor.apply();
});
enable_osm.setOnCheckedChangeListener((buttonView, isChecked) -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(SET_OSM_ENABLED, isChecked);
editor.apply();
});
if(nitterHost!=null) {
nitter_instance.setText(nitterHost);

View File

@ -41,7 +41,7 @@ public class TransformActivity extends AppCompatActivity {
final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)");
final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)");
final Pattern googleMap = Pattern.compile("google\\.com/maps[^@]+@([\\d.,z]{3,}).*");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -69,6 +69,34 @@ public class TransformActivity extends AppCompatActivity {
} else {
forwardToBrowser(intent);
}
}else if( url.contains("google")) {
boolean osm_enabled = sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true);
if(osm_enabled) {
Matcher matcher = googleMap.matcher(url);
while (matcher.find()) {
final String localization = matcher.group(1);
assert localization != null;
String[] data = localization.split(",");
if( data.length > 2 ){
String zoom;
String[] details = data[2].split("\\.");
if( details.length > 0 ) {
zoom = details[0];
}else {
zoom = data[2];
}
newUrl = "https://www.openstreetmap.org/#map="+zoom+"/"+data[0]+"/"+data[1];
}
}
Intent delegate = new Intent(Intent.ACTION_VIEW);
delegate.setData(Uri.parse(newUrl));
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (delegate.resolveActivity(getPackageManager()) != null) {
startActivity(delegate);
}
} else {
forwardToBrowser(intent);
}
}else{ //Youtube URL
boolean invidious_enabled = sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true);
if( invidious_enabled) {

View File

@ -91,6 +91,27 @@
android:id="@+id/enable_invidious"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="30dp"
android:id="@+id/osm_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nitter_container"
android:orientation="horizontal">
<TextView
android:text="@string/redirect_gm_to_osm"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<androidx.appcompat.widget.SwitchCompat
android:layout_margin="5dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/enable_osm"/>
</LinearLayout>
<Button
style="@style/Widget.AppCompat.Button.Colored"

View File

@ -21,4 +21,5 @@
<string name="valid">Valid</string>
<string name="icon_of_the_app">Icon of the app</string>
<string name="open_with">Open with</string>
<string name="redirect_gm_to_osm">Redirect Google Map to OpenStreetMap</string>
</resources>