mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
Add option to share a cached watchface/app to another app
This commit is contained in:
parent
365bb2aea4
commit
65a7ceab82
@ -18,6 +18,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.appmanager;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -46,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
@ -308,6 +310,18 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
} else {
|
||||
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
|
||||
@ -390,6 +404,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
||||
if (!selectedApp.isInCache()) {
|
||||
menu.removeItem(R.id.appmanager_app_edit);
|
||||
menu.removeItem(R.id.appmanager_app_reinstall);
|
||||
menu.removeItem(R.id.appmanager_app_share);
|
||||
menu.removeItem(R.id.appmanager_app_delete_cache);
|
||||
}
|
||||
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());
|
||||
GBApplication.deviceService().onInstallApp(Uri.fromFile(cachePath));
|
||||
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:
|
||||
GBApplication.deviceService().onInstallApp(Uri.parse("fake://health"));
|
||||
return true;
|
||||
|
@ -6,6 +6,9 @@
|
||||
<item
|
||||
android:id="@+id/appmanager_app_reinstall"
|
||||
android:title="@string/appmananger_app_reinstall"/>
|
||||
<item
|
||||
android:id="@+id/appmanager_app_share"
|
||||
android:title="@string/appmanager_app_share"/>
|
||||
<item
|
||||
android:id="@+id/appmanager_app_delete"
|
||||
android:title="@string/appmananger_app_delete"/>
|
||||
|
@ -86,6 +86,7 @@
|
||||
<string name="appmananger_app_delete">Delete</string>
|
||||
<string name="appmananger_app_delete_cache">Delete and remove from cache</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_health_activate">Activate</string>
|
||||
<string name="appmanager_health_deactivate">Deactivate</string>
|
||||
|
Loading…
Reference in New Issue
Block a user