show "Open" button when media is installed and viewable

This checks if there is an app that can view the installed media file, and
if so, it shows an "Open" button where the "Run" button is for apps.
This commit is contained in:
Hans-Christoph Steiner committed 2018-08-17 15:32:27 +02:00
1 parent 6b6ab02c9c
commit aead26f02c
7 files changed
+50 -10

No files matched your search

+1 -1
View File
@@ -129,7 +129,7 @@
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/install_history_file_provider"/>
android:resource="@xml/installer_file_provider"/>
</provider>
<activity
@@ -28,7 +28,6 @@ import android.net.Uri;
import android.os.Process;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import org.fdroid.fdroid.BuildConfig;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Apk;
@@ -47,8 +46,7 @@ import java.util.List;
public class InstallHistoryService extends IntentService {
public static final String TAG = "InstallHistoryService";
public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".installer";
public static final Uri LOG_URI = Uri.parse("content://" + AUTHORITY + "/install_history/all");
public static final Uri LOG_URI = Uri.parse("content://" + Installer.AUTHORITY + "/install_history/all");
private static BroadcastReceiver broadcastReceiver;
@@ -31,6 +31,7 @@ import android.os.PatternMatcher;
import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import org.fdroid.fdroid.BuildConfig;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.data.ApkProvider;
@@ -51,6 +52,8 @@ public abstract class Installer {
final Context context;
final Apk apk;
public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".installer";
public static final String ACTION_INSTALL_STARTED = "org.fdroid.fdroid.installer.Installer.action.INSTALL_STARTED";
public static final String ACTION_INSTALL_COMPLETE = "org.fdroid.fdroid.installer.Installer.action.INSTALL_COMPLETE";
public static final String ACTION_INSTALL_INTERRUPTED = "org.fdroid.fdroid.installer.Installer.action.INSTALL_INTERRUPTED";
@@ -7,10 +7,12 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.app.AlertDialog;
@@ -28,6 +30,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -35,6 +38,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.core.ImageLoader;
import org.apache.commons.io.FilenameUtils;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils;
@@ -43,10 +47,12 @@ import org.fdroid.fdroid.data.ApkProvider;
import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.InstalledAppProvider;
import org.fdroid.fdroid.data.RepoProvider;
import org.fdroid.fdroid.installer.Installer;
import org.fdroid.fdroid.privileged.views.AppDiff;
import org.fdroid.fdroid.privileged.views.AppSecurityPermissions;
import org.fdroid.fdroid.views.main.MainActivity;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -512,9 +518,42 @@ public class AppDetailsRecyclerViewAdapter
buttonPrimaryView.setText(R.string.menu_upgrade);
buttonPrimaryView.setOnClickListener(onUpgradeClickListener);
} else {
Apk mediaApk = app.getMediaApkifInstalled(context);
if (context.getPackageManager().getLaunchIntentForPackage(app.packageName) != null) {
buttonPrimaryView.setText(R.string.menu_launch);
buttonPrimaryView.setOnClickListener(onLaunchClickListener);
} else if (!app.isApk && mediaApk != null) {
final File installedFile = new File(mediaApk.getMediaInstallPath(context), mediaApk.apkName);
if (!installedFile.toString().startsWith(context.getApplicationInfo().dataDir)) {
final Intent viewIntent = new Intent(Intent.ACTION_VIEW);
Uri uri = FileProvider.getUriForFile(context, Installer.AUTHORITY, installedFile);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
FilenameUtils.getExtension(installedFile.getName()));
viewIntent.setDataAndType(uri, mimeType);
if (Build.VERSION.SDK_INT < 19) {
viewIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
viewIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
}
if (context.getPackageManager().queryIntentActivities(viewIntent, 0).size() > 0) {
buttonPrimaryView.setText(R.string.menu_open);
buttonPrimaryView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
context.startActivity(viewIntent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
});
} else {
buttonPrimaryView.setVisibility(View.GONE);
}
} else {
buttonPrimaryView.setVisibility(View.GONE);
}
} else {
buttonPrimaryView.setVisibility(View.GONE);
}
+1
View File
@@ -171,6 +171,7 @@ This often occurs with apps installed via Google Play or other sources, if they
<string name="menu_add_repo">New Repository</string>
<string name="menu_launch">Run</string>
<string name="menu_open">Open</string>
<string name="menu_share">Share</string>
<string name="menu_install">Install</string>
<string name="menu_uninstall">Uninstall</string>
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path
name="install_history"
path="install_history" />
</paths>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="install_history" path="install_history"/>
<external-path name="external" path="/"/>
</paths>