Improve disable feature

This commit is contained in:
Thomas 2020-01-29 08:13:14 +01:00
parent 5b5cf355dc
commit 26e3e91012
2 changed files with 47 additions and 10 deletions

View File

@ -13,14 +13,20 @@ 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.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -54,8 +60,14 @@ public class TransformActivity extends AppCompatActivity {
String nitterHost = sharedpreferences.getString(MainActivity.SET_NITTER_HOST, MainActivity.DEFAULT_NITTER_HOST).toLowerCase();
newUrl = "https://" + nitterHost + nitter_directory;
}
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 {
newUrl = url;
forwardToBrowser(intent);
}
}else{ //Youtube URL
boolean invidious_enabled = sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true);
@ -70,20 +82,44 @@ public class TransformActivity extends AppCompatActivity {
newUrl = "https://" + invidiousHost + "/" + youtubeId + "&local=true";
}
}
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{
newUrl = url;
forwardToBrowser(intent);
}
}
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);
}
}
}
private void forwardToBrowser(Intent i) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(i.getData(), i.getType());
List<ResolveInfo> activities = getPackageManager().queryIntentActivities(intent, 0);
ArrayList<Intent> targetIntents = new ArrayList<>();
String thisPackageName = getApplicationContext().getPackageName();
for (ResolveInfo currentInfo : activities) {
String packageName = currentInfo.activityInfo.packageName;
if (!thisPackageName.equals(packageName)) {
Intent targetIntent = new Intent(android.content.Intent.ACTION_VIEW);
targetIntent.setDataAndType(intent.getData(), intent.getType());
targetIntent.setPackage(intent.getPackage());
targetIntent.setComponent(new ComponentName(packageName, currentInfo.activityInfo.name));
targetIntents.add(targetIntent);
}
}
if (targetIntents.size() > 0) {
Intent chooserIntent = Intent.createChooser(targetIntents.remove(0), getString(R.string.open_with));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
finish();
}
}
}

View File

@ -20,4 +20,5 @@
<string name="error">Error</string>
<string name="valid">Valid</string>
<string name="icon_of_the_app">Icon of the app</string>
<string name="open_with">Open with</string>
</resources>