Merge pull request #404 from Adonai/share-button

Implement share action in Library & NowPlaying
This commit is contained in:
Adrian Ulrich 2016-07-23 17:00:40 +02:00 committed by GitHub
commit 89b043015d
5 changed files with 52 additions and 1 deletions

View File

@ -255,6 +255,9 @@
<string name="autoplaylist_playcounts_name" formatted="false">%d лучших </string>
<string name="permission_request_summary">Vanilla Music необходимо разрешение на чтение, чтобы отобразить Вашу музыку в фонотеке</string>
<string name="reverse_sort">в обратном порядке</string>
<string name="share">Поделиться…</string>
<string name="sendto">Отправить…</string>
<string name="no_receiving_apps">Нет подходящих приложений для отправки!</string>
<!--SD Scanner-->
<string name="sdscan_help">Запуск сканирования в Vanilla Music приведёт к перестройке всей базы медиаданных.</string>
<string name="button_start">Начать сканирование</string>

View File

@ -171,7 +171,7 @@ THE SOFTWARE.
<string name="replaygain_untagged_debump_title">Songs without ReplayGain tag</string>
<string name="replaygain_untagged_debump_summary">Decrease volume by</string>
<string name="replaygain_preamp_note_title">Note</string>
<string name="replaygain_preamp_note_content">Android does not allow Vanilla Music to raise the volume to >100%. Setting the Pre-amp to a high value may cause issues if you are listening to \'quiet\' music. \n\nRecommended values are:\n-> -3dB for silent/classical music\n-> +3dB for post-2000 recordings</string>
<string name="replaygain_preamp_note_content">Android does not allow Vanilla Music to raise the volume to >100%. Setting the Pre-amp to a high value may cause issues if you are listening to \'quiet\' music. \n\nRecommended values are:\n-> -3dB for silent/classical music\n-> +3dB for post-2000 recordings</string>
<string name="readahead">Enable readahead</string>
<string name="readahead_summary">Readahead the currently playing song. This option may solve \'audio dropout\' issues. (caused by a slow SD card)</string>
@ -298,6 +298,10 @@ THE SOFTWARE.
<string name="permission_request_summary">Vanilla Music needs read permission to display your music library</string>
<string name="reverse_sort">Reverse sort</string>
<string name="share">Share…</string>
<string name="sendto">Send to…</string>
<string name="no_receiving_apps">No receiving apps found for this media type!</string>
<!-- SD Scanner -->
<string name="sdscan_help">Starting a rescan causes Vanilla Music to trigger a full rebuild of the media database.</string>
<string name="button_start">Start Rescan</string>

View File

@ -307,6 +307,7 @@ public class FullPlaybackActivity extends SlidingPlaybackActivity
menu.add(0, MENU_ENQUEUE_ARTIST, 30, R.string.enqueue_current_artist);
menu.add(0, MENU_ENQUEUE_GENRE, 30, R.string.enqueue_current_genre);
menu.add(0, MENU_ADD_TO_PLAYLIST, 30, R.string.add_to_playlist);
menu.add(0, MENU_SHARE, 30, R.string.share);
mFavorites = menu.add(0, MENU_SONG_FAVORITE, 0, R.string.add_to_favorites).setIcon(R.drawable.btn_rating_star_off_mtrl_alpha).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM);
// ensure that mFavorites is updated
@ -352,6 +353,9 @@ public class FullPlaybackActivity extends SlidingPlaybackActivity
dialog.show(getFragmentManager(), "PlaylistDialog");
}
break;
case MENU_SHARE:
MediaUtils.shareMedia(FullPlaybackActivity.this, MediaUtils.TYPE_SONG, song.id);
break;
case MENU_DELETE:
final PlaybackService playbackService = PlaybackService.get(this);
final PlaybackActivity activity = this;

View File

@ -33,7 +33,11 @@ import java.util.Vector;
import java.util.zip.CRC32;
import junit.framework.Assert;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
@ -42,6 +46,7 @@ import android.text.TextUtils;
import android.database.MatrixCursor;
import android.media.MediaMetadataRetriever;
import android.util.Log;
import android.widget.Toast;
/**
@ -504,6 +509,40 @@ public class MediaUtils {
sAllSongs = null;
}
/**
* Creates and sends share intent across the system. Includes all eligible songs found
* within this type and id (e.g. all songs in album, all songs for this artist etc.)
* @param ctx context to execute resolving on
* @param type media type to look for e.g. {@link MediaUtils#TYPE_SONG}
* @param id id of item to send
*/
public static void shareMedia(Context ctx, int type, long id) {
if (type == TYPE_INVALID || id <= 0) { // invalid
return;
}
ContentResolver resolver = ctx.getContentResolver();
String[] projection = new String [] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA };
Cursor cursor = buildQuery(type, id, projection, null).runQuery(resolver);
if(cursor == null) {
return;
}
try {
while (cursor.moveToNext()) { // for all songs resolved...
File songFile = new File(cursor.getString(1));
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(songFile));
ctx.startActivity(Intent.createChooser(share, ctx.getResources().getString(R.string.sendto)));
}
} catch (ActivityNotFoundException ex) {
Toast.makeText(ctx, R.string.no_receiving_apps, Toast.LENGTH_SHORT).show();
} finally {
cursor.close();
}
}
/**
* Returns the first matching song (or NULL) of given type + id combination
*

View File

@ -375,6 +375,7 @@ public abstract class PlaybackActivity extends Activity
static final int MENU_DELETE = 16;
static final int MENU_EMPTY_QUEUE = 17;
static final int MENU_ADD_TO_PLAYLIST = 18;
static final int MENU_SHARE = 19;
@Override
public boolean onCreateOptionsMenu(Menu menu)