mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +00:00
Use runWithPlugin helper in SharePlugin
Summary: Depends on D16472 Test Plan: Share file via app Share file from external app Share file via direct Share Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: albertvaka, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D16473
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.kde.kdeconnect.Plugins.SharePlugin;
|
||||
|
||||
@@ -31,7 +31,6 @@ import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.UserInterface.ThemeUtil;
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
|
||||
@@ -89,15 +88,7 @@ public class SendFileActivity extends AppCompatActivity {
|
||||
if (uris.isEmpty()) {
|
||||
Log.w("SendFileActivity", "No files to send?");
|
||||
} else {
|
||||
BackgroundService.RunCommand(this, service -> {
|
||||
Device device = service.getDevice(mDeviceId);
|
||||
if (device == null) {
|
||||
Log.e("SendFileActivity", "Device is null");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
SharePlugin.queuedSendUriList(getApplicationContext(), device, uris);
|
||||
});
|
||||
BackgroundService.runWithPlugin(this, mDeviceId, SharePlugin.class, plugin -> plugin.queuedSendUriList(uris));
|
||||
}
|
||||
}
|
||||
finish();
|
||||
|
@@ -25,7 +25,6 @@ import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -113,7 +112,7 @@ public class ShareActivity extends AppCompatActivity {
|
||||
list.setOnItemClickListener((adapterView, view, i, l) -> {
|
||||
|
||||
Device device = devicesList.get(i - 1); //NOTE: -1 because of the title!
|
||||
SharePlugin.share(intent, device);
|
||||
BackgroundService.runWithPlugin(this, device.getDeviceId(), SharePlugin.class, plugin -> plugin.share(intent));
|
||||
finish();
|
||||
});
|
||||
});
|
||||
@@ -148,12 +147,8 @@ public class ShareActivity extends AppCompatActivity {
|
||||
|
||||
if (deviceId != null) {
|
||||
|
||||
BackgroundService.RunCommand(this, service -> {
|
||||
Log.d("DirectShare", "sharing to " + service.getDevice(deviceId).getName());
|
||||
Device device = service.getDevice(deviceId);
|
||||
if (device.isReachable() && device.isPaired()) {
|
||||
SharePlugin.share(intent, device);
|
||||
}
|
||||
BackgroundService.runWithPlugin(this, deviceId, SharePlugin.class, plugin -> {
|
||||
plugin.share(intent);
|
||||
finish();
|
||||
});
|
||||
} else {
|
||||
|
@@ -282,7 +282,7 @@ public class SharePlugin extends Plugin {
|
||||
parentActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
static void queuedSendUriList(Context context, final Device device, final ArrayList<Uri> uriList) {
|
||||
void queuedSendUriList(final ArrayList<Uri> uriList) {
|
||||
|
||||
//Read all the data early, as we only have permissions to do it while the activity is alive
|
||||
final ArrayList<NetworkPacket> toSend = new ArrayList<>();
|
||||
@@ -388,7 +388,7 @@ public class SharePlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
public static void share(Intent intent, Device device) {
|
||||
public void share(Intent intent) {
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras != null) {
|
||||
if (extras.containsKey(Intent.EXTRA_STREAM)) {
|
||||
@@ -404,7 +404,7 @@ public class SharePlugin extends Plugin {
|
||||
uriList.add(uri);
|
||||
}
|
||||
|
||||
SharePlugin.queuedSendUriList(device.getContext(), device, uriList);
|
||||
queuedSendUriList(uriList);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("ShareActivity", "Exception");
|
||||
|
Reference in New Issue
Block a user