Manage geo uri

This commit is contained in:
Thomas 2020-02-17 15:34:09 +01:00
parent 7b6fd39250
commit 327eb719f0
6 changed files with 103 additions and 68 deletions

View File

@ -167,39 +167,23 @@
android:host="youtube-nocookie.com" />
</intent-filter>
<!-- google.com/maps/ -->
<!-- /maps/ -->
<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" />
android:pathPattern="/maps/place/.*"
android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"
android:pathPattern="/maps/.*"
android:host="google.com" />
android:pathPattern="/maps/place/.*"
android:host="*" />
</intent-filter>
<!-- www.google.com/maps/ -->
<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>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"
android:pathPattern="/maps/.*"
android:host="www.google.com" />
</intent-filter>
</activity>

View File

@ -14,7 +14,6 @@ package app.fedilab.nitterizeme;
* You should have received a copy of the GNU General Public License along with NitterizeMe; if not,
* see <http://www.gnu.org/licenses>. */
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@ -89,8 +88,8 @@ public class AppInfoAdapter extends RecyclerView.Adapter {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("nitterizeme","test");
String url = "https://"+appInfo.getDomain();
if( appInfo.getDomain().contains("google.com")) {
url += "/maps/";
if( appInfo.getDomain().contains("/maps/place")) {
url = "https://google.com/maps/place";
}
intent.setData(Uri.parse(url));
context.startActivity(intent);

View File

@ -35,11 +35,15 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import java.util.ArrayList;
import java.util.Objects;
@ -57,6 +61,7 @@ public class MainActivity extends AppCompatActivity {
public static String SET_OSM_ENABLED = "set_osm_enabled";
public static String SET_OSM_HOST = "set_osm_host";
public static String DEFAULT_OSM_HOST = "www.openstreetmap.org";
public static String SET_GEO_URIS = "set_geo_uris";
public static final String APP_PREFS = "app_prefs";
private AppInfoAdapter appInfoAdapter;
private RecyclerView list_apps;
@ -72,8 +77,7 @@ public class MainActivity extends AppCompatActivity {
"m.youtube.com",
"youtu.be",
"youtube-nocookie.com",
"google.com/maps",
"www.google.com/maps"
"maps",
};
@Override
@ -183,6 +187,22 @@ public class MainActivity extends AppCompatActivity {
appInfos.add(appInfo);
}
CheckBox enable_geo_uris = findViewById(R.id.enable_geo_uris);
enable_geo_uris.setOnCheckedChangeListener((buttonView, isChecked) -> {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(SET_GEO_URIS, isChecked);
editor.apply();
TextInputLayout osm_instance_container = findViewById(R.id.osm_instance_container);
TextView osm_indications = findViewById(R.id.osm_indications);
if( isChecked){
osm_instance_container.setVisibility(View.GONE);
osm_indications.setText(R.string.redirect_gm_to_geo_uri);
}else{
osm_instance_container.setVisibility(View.VISIBLE);
osm_indications.setText(R.string.redirect_gm_to_osm);
}
});
appInfoAdapter = new AppInfoAdapter(appInfos);
list_apps.setAdapter(appInfoAdapter);
final LinearLayoutManager mLayoutManager;

View File

@ -42,7 +42,8 @@ public class TransformActivity extends Activity {
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,}).*");
final Pattern maps = Pattern.compile("/maps/place/[^@]+@([\\d.,z]{3,}).*");
final Pattern extractPlace = Pattern.compile("/maps/place/(((?!/data).)*)");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -90,22 +91,32 @@ public class TransformActivity extends Activity {
boolean nitter_enabled = sharedpreferences.getBoolean(SET_NITTER_ENABLED, true);
if(nitter_enabled) {
Intent delegate = new Intent(action);
delegate.setData(Uri.parse(transformUrl(url)));
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (delegate.resolveActivity(getPackageManager()) != null) {
startActivity(delegate);
String transformedURL = transformUrl(url);
if( transformedURL != null) {
delegate.setData(Uri.parse(transformUrl(url)));
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (delegate.resolveActivity(getPackageManager()) != null) {
startActivity(delegate);
}
}else{
forwardToBrowser(intent, action);
}
} else {
forwardToBrowser(intent, action);
}
}else if( url.contains("google")) {
}else if( url.contains("/maps/place")) {
boolean osm_enabled = sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true);
if(osm_enabled) {
Intent delegate = new Intent(action);
delegate.setData(Uri.parse(transformUrl(url)));
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (delegate.resolveActivity(getPackageManager()) != null) {
startActivity(delegate);
String transformedURL = transformUrl(url);
if( transformedURL != null) {
delegate.setData(Uri.parse(transformUrl(url)));
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (delegate.resolveActivity(getPackageManager()) != null) {
startActivity(delegate);
}
}else {
forwardToBrowser(intent, action);
}
} else {
forwardToBrowser(intent, action);
@ -114,10 +125,15 @@ public class TransformActivity extends Activity {
boolean invidious_enabled = sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true);
if( invidious_enabled) {
Intent delegate = new Intent(action);
delegate.setData(Uri.parse(transformUrl(url)));
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (delegate.resolveActivity(getPackageManager()) != null) {
startActivity(delegate);
String transformedURL = transformUrl(url);
if( transformedURL != null) {
delegate.setData(Uri.parse(transformUrl(url)));
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (delegate.resolveActivity(getPackageManager()) != null) {
startActivity(delegate);
}
}else {
forwardToBrowser(intent, action);
}
}else{
forwardToBrowser(intent, action);
@ -171,18 +187,14 @@ public class TransformActivity extends Activity {
String nitterHost = sharedpreferences.getString(MainActivity.SET_NITTER_HOST, MainActivity.DEFAULT_NITTER_HOST).toLowerCase();
newUrl = "https://" + nitterHost + nitter_directory;
}
if( newUrl != null) {
return newUrl;
}else {
return url;
}
return newUrl;
} else {
return url;
}
}else if( url.contains("google")) {
}else if( url.contains("/maps/place")) {
boolean osm_enabled = sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true);
if(osm_enabled) {
Matcher matcher = googleMap.matcher(url);
Matcher matcher = maps.matcher(url);
while (matcher.find()) {
final String localization = matcher.group(1);
assert localization != null;
@ -195,15 +207,24 @@ public class TransformActivity extends Activity {
}else {
zoom = data[2];
}
String osmHost = sharedpreferences.getString(MainActivity.SET_OSM_HOST, MainActivity.DEFAULT_OSM_HOST).toLowerCase();
newUrl = "https://"+osmHost+"/#map="+zoom+"/"+data[0]+"/"+data[1];
boolean geo_uri_enabled = sharedpreferences.getBoolean(MainActivity.SET_GEO_URIS, false);
if(! geo_uri_enabled) {
newUrl = "https://" + osmHost + "/#map=" + zoom + "/" + data[0] + "/" + data[1];
}else{
newUrl = "geo:0,0?q="+data[0]+","+data[1]+",z="+zoom;
}
}
}
if( newUrl != null) {
return newUrl;
}else {
return url;
if( newUrl == null && url.contains("/data=")) {
matcher = extractPlace.matcher(url);
while (matcher.find()) {
final String search = matcher.group(1);
newUrl = "geo:0,0?q="+search;
}
}
return newUrl;
} else {
return url;
}
@ -220,11 +241,7 @@ public class TransformActivity extends Activity {
newUrl = "https://" + invidiousHost + "/" + youtubeId + "&local=true";
}
}
if( newUrl != null) {
return newUrl;
}else {
return url;
}
return newUrl;
}else{
return url;
}
@ -271,10 +288,10 @@ public class TransformActivity extends Activity {
newUrl = "https://" + nitterHost + nitter_directory;
}
}
}else if( url.contains("google")) {
}else if( url.contains("/maps/place/")) {
boolean osm_enabled = sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true);
if(osm_enabled) {
Matcher matcher = googleMap.matcher(url);
Matcher matcher = maps.matcher(url);
while (matcher.find()) {
final String localization = matcher.group(1);
assert localization != null;

View File

@ -140,18 +140,31 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/osm_indications"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:layout_weight="1"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/osm_instance"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/osm_instance_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/osm_instance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/custom_osm"
android:inputType="textUri"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:text="@string/use_geo_uri"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/custom_osm"
android:inputType="textUri"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
android:id="@+id/enable_geo_uris"/>
</LinearLayout>
<androidx.appcompat.widget.SwitchCompat
android:layout_margin="5dp"
android:layout_gravity="center"

View File

@ -25,7 +25,9 @@
<string name="custom_osm">Custom OSM hostname</string>
<string name="redirect_youtube_to_invidious">Redirect YouTube to Invidious</string>
<string name="redirect_twitter_to_nitter">Redirect Twitter to Nitter</string>
<string name="redirect_gm_to_geo_uri">Redirect Google Map to Geo URI</string>
<string name="configure">Configure</string>
<string name="display_supported_links">Display supported links</string>
<string name="hide_supported_links">Hide supported links</string>
<string name="use_geo_uri">Use geo URI</string>
</resources>