Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c55be71 authored by 2bllw8's avatar 2bllw8 Committed by Michael W
Browse files

Recorder: Add share selected list items

Change-Id: Idd801a6635627d519f3aad60d80e341553f174cb
parent ec098f98
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import org.lineageos.recorder.utils.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class ListActivity extends AppCompatActivity implements RecordingListCallbacks {
    private static final String TYPE_AUDIO = "audio/*";
@@ -171,7 +172,8 @@ public class ListActivity extends AppCompatActivity implements RecordingListCall
        endSelectionMode();
        // Start action mode
        mActionMode = mToolbar.startActionMode(new ListActionModeCallback(
                this::deleteSelectedRecordings));
                this::deleteSelectedRecordings,
                this::shareSelectedRecordings));
        mAdapter.enterSelectionMode();
    }

@@ -202,6 +204,18 @@ public class ListActivity extends AppCompatActivity implements RecordingListCall
        mListView.setVisibility(isEmpty ? View.GONE : View.VISIBLE);
    }

    private void shareSelectedRecordings() {
        final List<RecordingData> selectedItems = mAdapter.getSelected();
        if (selectedItems.isEmpty()) {
            return;
        }

        final ArrayList<Uri> uris = selectedItems.stream()
                .map(RecordingData::getUri)
                .collect(Collectors.toCollection(ArrayList::new));
        startActivity(LastRecordHelper.getShareIntents(uris, TYPE_AUDIO));
    }

    private void deleteSelectedRecordings() {
        final List<RecordingData> selectedItems = mAdapter.getSelected();
        if (selectedItems.isEmpty()) {
+10 −2
Original line number Diff line number Diff line
@@ -28,9 +28,13 @@ public class ListActionModeCallback implements ActionMode.Callback {

    @NonNull
    private final Runnable mDeleteSelected;
    @NonNull
    private final Runnable mShareSelected;

    public ListActionModeCallback(@NonNull Runnable deleteSelected) {
    public ListActionModeCallback(@NonNull Runnable deleteSelected,
                                  @NonNull Runnable shareSelected) {
        mDeleteSelected = deleteSelected;
        mShareSelected = shareSelected;
    }

    @Override
@@ -47,9 +51,13 @@ public class ListActionModeCallback implements ActionMode.Callback {

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        if (item.getItemId() == R.id.action_delete_selected) {
        int id = item.getItemId();
        if (id == R.id.action_delete_selected) {
            mDeleteSelected.run();
            return true;
        } else if (id == R.id.action_share_selected) {
            mShareSelected.run();
            return true;
        } else {
            return false;
        }
+11 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import androidx.appcompat.app.AlertDialog;
import org.lineageos.recorder.DialogActivity;
import org.lineageos.recorder.R;

import java.util.ArrayList;
import java.util.function.Consumer;

public class LastRecordHelper {
@@ -114,6 +115,16 @@ public class LastRecordHelper {
        return chooserIntent;
    }

    @NonNull
    public static Intent getShareIntents(ArrayList<Uri> uris, String mimeType) {
        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType(mimeType);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        Intent chooserIntent = Intent.createChooser(intent, null);
        chooserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        return chooserIntent;
    }

    @NonNull
    public static Intent getOpenIntent(Uri uri, String mimeType) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
+5 −0
Original line number Diff line number Diff line
@@ -21,4 +21,9 @@
        android:id="@+id/action_delete_selected"
        android:title="@string/delete_selected"
        android:icon="@drawable/ic_delete" />

    <item
        android:id="@+id/action_share_selected"
        android:title="@string/share_selected"
        android:icon="@drawable/ic_share" />
</menu>
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
    <!-- Common actions -->
    <!-- Share action for notification -->
    <string name="share">Share</string>
    <!-- Share selected action -->
    <string name="share_selected">Share selected</string>
    <!-- Stop action for notification -->
    <string name="stop">Stop</string>
    <!-- Play action -->