Fix share
This commit is contained in:
parent
6d02982da9
commit
66beb3bc37
|
@ -40,6 +40,7 @@ import app.fedilab.nitterizeme.helpers.Utils;
|
|||
import app.fedilab.nitterizeme.sqlite.DefaultAppDAO;
|
||||
import app.fedilab.nitterizeme.sqlite.Sqlite;
|
||||
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.INTENT_ACTION;
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.KILL_ACTIVITY;
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.URL_APP_PICKER;
|
||||
|
||||
|
@ -48,6 +49,7 @@ public class AppsPickerActivity extends Activity {
|
|||
|
||||
|
||||
private String url;
|
||||
private String action;
|
||||
private String appToUse;
|
||||
private String appName;
|
||||
|
||||
|
@ -64,19 +66,27 @@ public class AppsPickerActivity extends Activity {
|
|||
}
|
||||
if (b != null) {
|
||||
url = b.getString(URL_APP_PICKER, null);
|
||||
action = b.getString(INTENT_ACTION, null);
|
||||
}
|
||||
if (url == null) {
|
||||
|
||||
if (url == null || action == null) {
|
||||
finish();
|
||||
}
|
||||
//At this point we are sure that url is not null
|
||||
Intent stopMainActivity = new Intent(KILL_ACTIVITY);
|
||||
sendBroadcast(stopMainActivity);
|
||||
|
||||
Intent delegate = new Intent(Intent.ACTION_VIEW);
|
||||
Intent delegate = new Intent(action);
|
||||
delegate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
delegate.setData(Uri.parse(url));
|
||||
|
||||
if (action.compareTo(Intent.ACTION_VIEW) == 0) {
|
||||
delegate.setData(Uri.parse(url));
|
||||
} else {
|
||||
delegate.putExtra(Intent.EXTRA_TEXT, url);
|
||||
delegate.setType("text/plain");
|
||||
}
|
||||
List<ResolveInfo> activities = getPackageManager().queryIntentActivities(delegate, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
RelativeLayout blank = findViewById(R.id.blank);
|
||||
blank.setOnClickListener(v -> finish());
|
||||
|
@ -108,7 +118,7 @@ public class AppsPickerActivity extends Activity {
|
|||
urlText.setText(url);
|
||||
|
||||
if (defaultApp != null) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
Intent intent = new Intent(action, Uri.parse(url));
|
||||
intent.setPackage(defaultApp);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
|
@ -147,16 +157,32 @@ public class AppsPickerActivity extends Activity {
|
|||
if (val > 0) {
|
||||
Toast.makeText(AppsPickerActivity.this, getString(R.string.default_app_indication, appName), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
if (action.compareTo(Intent.ACTION_VIEW) == 0) {
|
||||
Intent intent = new Intent(action, Uri.parse(url));
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
intent.setType("text/plain");
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
});
|
||||
|
||||
once.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
if (action.compareTo(Intent.ACTION_VIEW) == 0) {
|
||||
Intent intent = new Intent(action, Uri.parse(url));
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(action);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
intent.setType("text/plain");
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ import static app.fedilab.nitterizeme.activities.CheckAppActivity.youtube_domain
|
|||
import static app.fedilab.nitterizeme.activities.MainActivity.SET_BIBLIOGRAM_ENABLED;
|
||||
import static app.fedilab.nitterizeme.activities.MainActivity.SET_INVIDIOUS_ENABLED;
|
||||
import static app.fedilab.nitterizeme.activities.MainActivity.SET_NITTER_ENABLED;
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.INTENT_ACTION;
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.KILL_ACTIVITY;
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.URL_APP_PICKER;
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.ampExtract;
|
||||
|
@ -312,7 +313,12 @@ public class TransformActivity extends Activity {
|
|||
|
||||
Intent app_picker = new Intent(TransformActivity.this, AppsPickerActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString(URL_APP_PICKER, i.getDataString());
|
||||
if (Objects.requireNonNull(i.getAction()).compareTo(Intent.ACTION_VIEW) == 0) {
|
||||
b.putString(URL_APP_PICKER, i.getDataString());
|
||||
} else {
|
||||
b.putString(URL_APP_PICKER, i.getStringExtra(Intent.EXTRA_TEXT));
|
||||
}
|
||||
b.putString(INTENT_ACTION, i.getAction());
|
||||
app_picker.putExtras(b);
|
||||
startActivity(app_picker);
|
||||
finish();
|
||||
|
@ -356,7 +362,7 @@ public class TransformActivity extends Activity {
|
|||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, extraText);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
forwardToBrowser(sendIntent);
|
||||
return;
|
||||
}
|
||||
Uri url_r = Uri.parse(url);
|
||||
|
@ -484,7 +490,7 @@ public class TransformActivity extends Activity {
|
|||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, newExtraText);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
forwardToBrowser(sendIntent);
|
||||
} else if (invidious_enabled && Arrays.asList(youtube_domains).contains(host)) {
|
||||
Matcher matcher = youtubePattern.matcher(notShortnedURLDialog.get(notShortnedURLDialog.size() - 1));
|
||||
String newUrlFinal = notShortnedURLDialog.get(notShortnedURLDialog.size() - 1);
|
||||
|
@ -502,7 +508,7 @@ public class TransformActivity extends Activity {
|
|||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, newExtraText);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
forwardToBrowser(sendIntent);
|
||||
} else if (osm_enabled && notShortnedURLDialog.get(notShortnedURLDialog.size() - 1).contains("/maps/place/")) {
|
||||
String newUrlFinal = notShortnedURLDialog.get(notShortnedURLDialog.size() - 1);
|
||||
Matcher matcher = maps.matcher(notShortnedURLDialog.get(notShortnedURLDialog.size() - 1));
|
||||
|
@ -527,14 +533,14 @@ public class TransformActivity extends Activity {
|
|||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, newExtraText);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
forwardToBrowser(sendIntent);
|
||||
} else {
|
||||
String newExtraText = finalExtraText.replaceAll(Pattern.quote(finalUrl), Matcher.quoteReplacement(notShortnedURLDialog.get(notShortnedURLDialog.size() - 1)));
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, newExtraText);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
forwardToBrowser(sendIntent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -550,7 +556,7 @@ public class TransformActivity extends Activity {
|
|||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, extraText);
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
forwardToBrowser(sendIntent);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ public class Utils {
|
|||
|
||||
public static final String KILL_ACTIVITY = "kill_activity";
|
||||
public static final String URL_APP_PICKER = "url_app_picker";
|
||||
public static final String INTENT_ACTION = "intent_action";
|
||||
public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)");
|
||||
public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)");
|
||||
public static final Pattern bibliogramPostPattern = Pattern.compile("(m\\.|www\\.)?instagram.com(/p/[\\w-/]+)");
|
||||
|
|
Loading…
Reference in New Issue