Allow to delegate to another application
This commit is contained in:
parent
4d668273f7
commit
731af9893e
|
@ -15,34 +15,39 @@ package app.fedilab.nitterizeme.activities;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import app.fedilab.nitterizeme.R;
|
||||
import app.fedilab.nitterizeme.adapters.AppPickerAdapter;
|
||||
import app.fedilab.nitterizeme.entities.AppPicker;
|
||||
|
||||
import static app.fedilab.nitterizeme.activities.CheckAppActivity.invidious_instances;
|
||||
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.getPackageInfo;
|
||||
import static app.fedilab.nitterizeme.helpers.Utils.isAppInstalled;
|
||||
|
||||
|
||||
public class AppsPickerActivity extends Activity {
|
||||
|
||||
|
||||
private GridView gridView;
|
||||
private String url;
|
||||
private String appToUse;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -85,6 +90,7 @@ public class AppsPickerActivity extends Activity {
|
|||
String thisPackageName = getApplicationContext().getPackageName();
|
||||
ArrayList<String> packages = new ArrayList<>();
|
||||
List<AppPicker> appPickers = new ArrayList<>();
|
||||
int i = 0;
|
||||
for (ResolveInfo currentInfo : activities) {
|
||||
String packageName = currentInfo.activityInfo.packageName;
|
||||
if (!thisPackageName.equals(packageName) && !packages.contains(packageName)) {
|
||||
|
@ -92,23 +98,55 @@ public class AppsPickerActivity extends Activity {
|
|||
appPicker.setIcon(currentInfo.activityInfo.loadIcon(getPackageManager()));
|
||||
appPicker.setName(String.valueOf(currentInfo.loadLabel(getPackageManager())));
|
||||
appPicker.setPackageName(packageName);
|
||||
if (i == 0) {
|
||||
appPicker.setSelected(true);
|
||||
appToUse = packageName;
|
||||
}
|
||||
appPickers.add(appPicker);
|
||||
packages.add(packageName);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (isAppInstalled(AppsPickerActivity.this, "org.schabi.newpipe") && Arrays.asList(invidious_instances).contains(Objects.requireNonNull(Uri.parse(url)).getHost()) && !packages.contains("org.schabi.newpipe")) {
|
||||
PackageInfo packageInfo = getPackageInfo(AppsPickerActivity.this, "org.schabi.newpipe");
|
||||
if (packageInfo != null) {
|
||||
AppPicker appPicker = new AppPicker();
|
||||
appPicker.setIcon(packageInfo.applicationInfo.loadIcon(getPackageManager()));
|
||||
appPicker.setName(String.valueOf(packageInfo.applicationInfo.loadLabel(getPackageManager())));
|
||||
appPicker.setPackageName(packageInfo.applicationInfo.packageName);
|
||||
appPickers.add(appPicker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GridView gridView = findViewById(R.id.app_list);
|
||||
AppPickerAdapter appPickerAdapter = new AppPickerAdapter(appPickers);
|
||||
gridView.setAdapter(appPickerAdapter);
|
||||
gridView.setNumColumns(3);
|
||||
gridView.setOnItemClickListener((parent, view1, position, id) -> {
|
||||
for(AppPicker ap: appPickers){
|
||||
for (AppPicker ap : appPickers) {
|
||||
ap.setSelected(false);
|
||||
}
|
||||
appPickers.get(position).setSelected(true);
|
||||
appToUse = appPickers.get(position).getPackageName();
|
||||
appPickerAdapter.notifyDataSetChanged();
|
||||
});
|
||||
|
||||
|
||||
Button always = findViewById(R.id.always);
|
||||
Button once = findViewById(R.id.once);
|
||||
|
||||
always.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
});
|
||||
|
||||
once.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
intent.setPackage(appToUse);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,6 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -334,66 +333,6 @@ public class TransformActivity extends Activity {
|
|||
app_picker.putExtras(b);
|
||||
startActivity(app_picker);
|
||||
finish();
|
||||
|
||||
/* Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
String type = i.getType();
|
||||
if (type == null) {
|
||||
type = "text/html";
|
||||
}
|
||||
intent.setDataAndType(i.getData(), type);
|
||||
List<ResolveInfo> activities = getPackageManager().queryIntentActivities(intent, 0);
|
||||
ArrayList<Intent> targetIntents = new ArrayList<>();
|
||||
|
||||
String thisPackageName = getApplicationContext().getPackageName();
|
||||
ArrayList<String> packages = new ArrayList<>();
|
||||
for (ResolveInfo currentInfo : activities) {
|
||||
String packageName = currentInfo.activityInfo.packageName;
|
||||
if (!thisPackageName.equals(packageName) && !packages.contains(packageName)) {
|
||||
Intent targetIntent = new Intent(Intent.ACTION_VIEW);
|
||||
targetIntent.setDataAndType(intent.getData(), intent.getType());
|
||||
targetIntent.setPackage(intent.getPackage());
|
||||
targetIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
targetIntent.setComponent(new ComponentName(packageName, currentInfo.activityInfo.name));
|
||||
targetIntents.add(targetIntent);
|
||||
packages.add(packageName);
|
||||
}
|
||||
}
|
||||
//NewPipe has to be manually added
|
||||
if (isNewPipeInstalled() && Arrays.asList(invidious_instances).contains(Objects.requireNonNull(i.getData()).getHost()) && !packages.contains("org.schabi.newpipe")) {
|
||||
Intent targetIntent = new Intent(Intent.ACTION_VIEW);
|
||||
targetIntent.setDataAndType(intent.getData(), intent.getType());
|
||||
targetIntent.setPackage(intent.getPackage());
|
||||
targetIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
targetIntent.setComponent(new ComponentName("org.schabi.newpipe", "org.schabi.newpipe.RouterActivity"));
|
||||
targetIntents.add(0, targetIntent);
|
||||
}
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(MainActivity.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean embedded_player = sharedpreferences.getBoolean(SET_EMBEDDED_PLAYER, false);
|
||||
|
||||
if (Arrays.asList(invidious_instances).contains(Objects.requireNonNull(i.getData()).getHost()) && embedded_player) {
|
||||
if (!i.getData().toString().contains("videoplayback") && !i.getData().toString().contains("/channel/")) {
|
||||
Intent intentPlayer = new Intent(TransformActivity.this, WebviewPlayerActivity.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
intentPlayer.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
}
|
||||
intentPlayer.putExtra("url", i.getData().toString());
|
||||
startActivity(intentPlayer);
|
||||
} else {
|
||||
Intent intentStreamingUrl = new Intent(Utils.RECEIVE_STREAMING_URL);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("streaming_url", i.getData().toString());
|
||||
intentStreamingUrl.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intentStreamingUrl);
|
||||
}
|
||||
} else if (targetIntents.size() > 0) {
|
||||
Intent chooserIntent = Intent.createChooser(targetIntents.get(0), getString(R.string.open_with));
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetIntents.toArray(new Parcelable[]{}));
|
||||
startActivity(chooserIntent);
|
||||
}
|
||||
finish();*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -623,17 +562,5 @@ public class TransformActivity extends Activity {
|
|||
startActivity(sendIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if NewPipe is installed
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean isNewPipeInstalled() {
|
||||
try {
|
||||
getPackageManager().getPackageInfo("org.schabi.newpipe", 0);
|
||||
return true;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,9 +79,9 @@ public class AppPickerAdapter extends BaseAdapter {
|
|||
holder.app_name.setText(appPicker.getName());
|
||||
|
||||
|
||||
if( appPicker.isSelected()) {
|
||||
if (appPicker.isSelected()) {
|
||||
holder.app_container.setBackgroundResource(R.drawable.rounded_selector);
|
||||
}else{
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
holder.app_container.setBackground(null);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AppPicker {
|
|||
private Drawable icon;
|
||||
private String name;
|
||||
private String packageName;
|
||||
private boolean selected;
|
||||
private boolean selected = false;
|
||||
|
||||
public Drawable getIcon() {
|
||||
return icon;
|
||||
|
|
|
@ -18,6 +18,8 @@ package app.fedilab.nitterizeme.helpers;
|
|||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
|
||||
|
@ -337,4 +339,33 @@ public class Utils {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an app is installed
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isAppInstalled(Context context, String packageName) {
|
||||
try {
|
||||
context.getPackageManager().getPackageInfo(packageName, 0);
|
||||
return true;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PackageInfo for an app
|
||||
*
|
||||
* @return PackageInfo
|
||||
*/
|
||||
public static PackageInfo getPackageInfo(Context context, String packageName) {
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return packageInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<stroke android:width="1dp" android:color="@color/colorAccent" />
|
||||
<corners android:radius="10dp"/>
|
||||
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
|
||||
<solid android:color="@android:color/transparent" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/colorAccent" />
|
||||
<corners android:radius="10dp" />
|
||||
<padding
|
||||
android:bottom="0dp"
|
||||
android:left="0dp"
|
||||
android:right="0dp"
|
||||
android:top="0dp" />
|
||||
</shape>
|
|
@ -15,76 +15,80 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
-->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/main_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activities.AppsPickerActivity">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/blank"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/app_container"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/app_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:background="@color/colorPrimary"
|
||||
>
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
<TextView
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:id="@+id/indication"
|
||||
android:text="@string/continue_with"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:drawableStart="@drawable/ic_app_logo"
|
||||
android:drawableLeft="@drawable/ic_app_logo"
|
||||
android:drawablePadding="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textSize="16sp"
|
||||
android:drawableStart="@drawable/ic_app_logo"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:drawableLeft="@drawable/ic_app_logo" />
|
||||
<GridView
|
||||
android:paddingTop="10dp"
|
||||
android:text="@string/continue_with"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<GridView
|
||||
android:id="@+id/app_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:stretchMode="columnWidth"
|
||||
android:gravity="center"
|
||||
app:layout_constraintTop_toBottomOf="@+id/indication"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:paddingTop="10dp"
|
||||
android:stretchMode="columnWidth"
|
||||
app:layout_constraintBottom_toTopOf="@+id/once"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/once"/>
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/indication" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/once"
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:text="@string/just_once"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:text="@string/just_once"
|
||||
android:textColor="@color/colorAccent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/always"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/always"
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:text="@string/always"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@+id/app_list"
|
||||
app:layout_constraintStart_toEndOf="@+id/once"
|
||||
android:text="@string/always"
|
||||
android:textColor="@color/colorAccent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
app:layout_constraintStart_toEndOf="@+id/once"
|
||||
app:layout_constraintTop_toBottomOf="@+id/app_list" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,29 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/app_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:paddingTop="5dp"
|
||||
android:id="@+id/app_icon"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:contentDescription="@string/icon_of_the_app"
|
||||
android:paddingTop="5dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/app_name"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:paddingBottom="5dp"
|
||||
android:id="@+id/app_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="5dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
Loading…
Reference in New Issue