1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Add option to share a cached watchface/app to another app

This commit is contained in:
Arjan Schrijver 2022-07-20 09:42:47 +02:00
parent 365bb2aea4
commit 65a7ceab82
3 changed files with 39 additions and 0 deletions

View File

@ -18,6 +18,7 @@
package nodomain.freeyourgadget.gadgetbridge.activities.appmanager; package nodomain.freeyourgadget.gadgetbridge.activities.appmanager;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -46,6 +47,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
@ -308,6 +310,18 @@ public abstract class AbstractAppManagerFragment extends Fragment {
} else { } else {
refreshList(); refreshList();
} }
try {
File appCacheDir = mCoordinator.getAppCacheDir();
File appTempDir = new File(appCacheDir, "temp_sharing");
if (appTempDir.isDirectory()) {
for (File child : appTempDir.listFiles())
child.delete();
appTempDir.delete();
}
} catch (IOException e) {
LOG.warn("Could not delete temporary app cache directory", e);
}
} }
@Override @Override
@ -390,6 +404,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
if (!selectedApp.isInCache()) { if (!selectedApp.isInCache()) {
menu.removeItem(R.id.appmanager_app_edit); menu.removeItem(R.id.appmanager_app_edit);
menu.removeItem(R.id.appmanager_app_reinstall); menu.removeItem(R.id.appmanager_app_reinstall);
menu.removeItem(R.id.appmanager_app_share);
menu.removeItem(R.id.appmanager_app_delete_cache); menu.removeItem(R.id.appmanager_app_delete_cache);
} }
if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) { if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) {
@ -489,6 +504,26 @@ public abstract class AbstractAppManagerFragment extends Fragment {
File cachePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension()); File cachePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
GBApplication.deviceService().onInstallApp(Uri.fromFile(cachePath)); GBApplication.deviceService().onInstallApp(Uri.fromFile(cachePath));
return true; return true;
case R.id.appmanager_app_share:
File origFilePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
File appTempDir = new File(appCacheDir, "temp_sharing");
File sharedAppFile = new File(appTempDir, selectedApp.getName() + mCoordinator.getAppFileExtension());
try {
appTempDir.mkdirs();
FileUtils.copyFile(origFilePath, sharedAppFile);
} catch (IOException e) {
return true;
}
Uri contentUri = FileProvider.getUriForFile(getContext(),getContext().getApplicationContext().getPackageName() + ".screenshot_provider", sharedAppFile);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
shareIntent.setType("*/*");
try {
startActivity(Intent.createChooser(shareIntent, null));
} catch (ActivityNotFoundException e) {
LOG.warn("Sharing watchface failed", e);
}
return true;
case R.id.appmanager_health_activate: case R.id.appmanager_health_activate:
GBApplication.deviceService().onInstallApp(Uri.parse("fake://health")); GBApplication.deviceService().onInstallApp(Uri.parse("fake://health"));
return true; return true;

View File

@ -6,6 +6,9 @@
<item <item
android:id="@+id/appmanager_app_reinstall" android:id="@+id/appmanager_app_reinstall"
android:title="@string/appmananger_app_reinstall"/> android:title="@string/appmananger_app_reinstall"/>
<item
android:id="@+id/appmanager_app_share"
android:title="@string/appmanager_app_share"/>
<item <item
android:id="@+id/appmanager_app_delete" android:id="@+id/appmanager_app_delete"
android:title="@string/appmananger_app_delete"/> android:title="@string/appmananger_app_delete"/>

View File

@ -86,6 +86,7 @@
<string name="appmananger_app_delete">Delete</string> <string name="appmananger_app_delete">Delete</string>
<string name="appmananger_app_delete_cache">Delete and remove from cache</string> <string name="appmananger_app_delete_cache">Delete and remove from cache</string>
<string name="appmananger_app_reinstall">Reinstall</string> <string name="appmananger_app_reinstall">Reinstall</string>
<string name="appmanager_app_share">Share</string>
<string name="appmanager_app_openinstore">Search in Pebble appstore</string> <string name="appmanager_app_openinstore">Search in Pebble appstore</string>
<string name="appmanager_health_activate">Activate</string> <string name="appmanager_health_activate">Activate</string>
<string name="appmanager_health_deactivate">Deactivate</string> <string name="appmanager_health_deactivate">Deactivate</string>