Added Share instagram stories
This commit is contained in:
parent
5d640b59d1
commit
8e387264d5
16 changed files with 320 additions and 228 deletions
|
@ -119,7 +119,7 @@
|
||||||
<activity android:name=".activities.PurchaseActivity" />
|
<activity android:name=".activities.PurchaseActivity" />
|
||||||
<activity android:name=".activities.WhatsNewActivity" />
|
<activity android:name=".activities.WhatsNewActivity" />
|
||||||
<activity android:name=".activities.bugreport.BugReportActivity" />
|
<activity android:name=".activities.bugreport.BugReportActivity" />
|
||||||
|
<activity android:name=".activities.ShareInstagramStory" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.SearchActivity"
|
android:name=".activities.SearchActivity"
|
||||||
android:windowSoftInputMode="stateVisible" />
|
android:windowSoftInputMode="stateVisible" />
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU General Public License v3
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package code.name.monkey.retromusic.activities
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.provider.MediaStore.Images.Media
|
||||||
|
import androidx.core.view.drawToBitmap
|
||||||
|
import code.name.monkey.appthemehelper.ThemeStore
|
||||||
|
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||||
|
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||||
|
import code.name.monkey.retromusic.R
|
||||||
|
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||||
|
import code.name.monkey.retromusic.glide.SongGlideRequest
|
||||||
|
import code.name.monkey.retromusic.model.Song
|
||||||
|
import code.name.monkey.retromusic.util.Share
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import kotlinx.android.synthetic.main.activity_share_instagram.image
|
||||||
|
import kotlinx.android.synthetic.main.activity_share_instagram.mainContent
|
||||||
|
import kotlinx.android.synthetic.main.activity_share_instagram.shareButton
|
||||||
|
import kotlinx.android.synthetic.main.activity_share_instagram.shareText
|
||||||
|
import kotlinx.android.synthetic.main.activity_share_instagram.shareTitle
|
||||||
|
import kotlinx.android.synthetic.main.activity_share_instagram.toolbar
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hemanths on 2020-02-02.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ShareInstagramStory : AbsBaseActivity() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val EXTRA_SONG = "extra_song"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
setDrawUnderStatusBar()
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_share_instagram)
|
||||||
|
setStatusbarColorAuto()
|
||||||
|
setNavigationbarColorAuto()
|
||||||
|
setLightNavigationBar(true)
|
||||||
|
|
||||||
|
val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface)
|
||||||
|
toolbar.setBackgroundColor(toolbarColor)
|
||||||
|
ToolbarContentTintHelper.colorBackButton(toolbar)
|
||||||
|
setSupportActionBar(toolbar)
|
||||||
|
|
||||||
|
val song = intent.extras?.getParcelable<Song>(EXTRA_SONG)
|
||||||
|
song?.let { songFinal ->
|
||||||
|
SongGlideRequest.Builder.from(Glide.with(this), songFinal)
|
||||||
|
.asBitmap()
|
||||||
|
.build()
|
||||||
|
.into(image)
|
||||||
|
|
||||||
|
shareTitle.text = songFinal.title
|
||||||
|
shareText.text = songFinal.artistName
|
||||||
|
shareButton.setOnClickListener {
|
||||||
|
val path: String = Media.insertImage(
|
||||||
|
contentResolver,
|
||||||
|
mainContent.drawToBitmap(Bitmap.Config.ARGB_8888),
|
||||||
|
"Design", null
|
||||||
|
)
|
||||||
|
val uri = Uri.parse(path)
|
||||||
|
Share.shareFileToInstagram(
|
||||||
|
this@ShareInstagramStory,
|
||||||
|
songFinal,
|
||||||
|
uri
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shareButton.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
||||||
|
}
|
||||||
|
}
|
|
@ -306,6 +306,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), AbsPlay
|
||||||
} else if (currentNowPlayingScreen == FULL || currentNowPlayingScreen == CARD || currentNowPlayingScreen == FIT || currentNowPlayingScreen == BLUR || currentNowPlayingScreen == BLUR_CARD) {
|
} else if (currentNowPlayingScreen == FULL || currentNowPlayingScreen == CARD || currentNowPlayingScreen == FIT || currentNowPlayingScreen == BLUR || currentNowPlayingScreen == BLUR_CARD) {
|
||||||
super.setLightStatusbar(false)
|
super.setLightStatusbar(false)
|
||||||
super.setLightNavigationBar(true)
|
super.setLightNavigationBar(true)
|
||||||
|
super.setNavigationbarColor(Color.BLACK)
|
||||||
} else if (currentNowPlayingScreen == COLOR || currentNowPlayingScreen == TINY) {
|
} else if (currentNowPlayingScreen == COLOR || currentNowPlayingScreen == TINY) {
|
||||||
super.setNavigationbarColor(paletteColor)
|
super.setNavigationbarColor(paletteColor)
|
||||||
super.setLightNavigationBar(isColorLight)
|
super.setLightNavigationBar(isColorLight)
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
|
import code.name.monkey.retromusic.activities.ShareInstagramStory
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.util.MusicUtil
|
import code.name.monkey.retromusic.util.MusicUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
|
@ -29,7 +30,7 @@ import com.afollestad.materialdialogs.list.listItems
|
||||||
|
|
||||||
class SongShareDialog : DialogFragment() {
|
class SongShareDialog : DialogFragment() {
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val song: Song? = arguments!!.getParcelable("song")
|
val song: Song? = arguments?.getParcelable("song")
|
||||||
val currentlyListening: String =
|
val currentlyListening: String =
|
||||||
getString(R.string.currently_listening_to_x_by_x, song?.title, song?.artistName)
|
getString(R.string.currently_listening_to_x_by_x, song?.title, song?.artistName)
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ class SongShareDialog : DialogFragment() {
|
||||||
listItems(
|
listItems(
|
||||||
items = listOf(
|
items = listOf(
|
||||||
getString(code.name.monkey.retromusic.R.string.the_audio_file),
|
getString(code.name.monkey.retromusic.R.string.the_audio_file),
|
||||||
"\u201C" + currentlyListening + "\u201D"
|
"\u201C" + currentlyListening + "\u201D",
|
||||||
|
getString(R.string.social_instagram)
|
||||||
)
|
)
|
||||||
) { _, index, _ ->
|
) { _, index, _ ->
|
||||||
when (index) {
|
when (index) {
|
||||||
|
@ -53,7 +55,7 @@ class SongShareDialog : DialogFragment() {
|
||||||
}, null))
|
}, null))
|
||||||
}
|
}
|
||||||
1 -> {
|
1 -> {
|
||||||
activity!!.startActivity(
|
startActivity(
|
||||||
Intent.createChooser(
|
Intent.createChooser(
|
||||||
Intent()
|
Intent()
|
||||||
.setAction(Intent.ACTION_SEND)
|
.setAction(Intent.ACTION_SEND)
|
||||||
|
@ -63,6 +65,16 @@ class SongShareDialog : DialogFragment() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
2 -> {
|
||||||
|
if (song != null) {
|
||||||
|
startActivity(
|
||||||
|
Intent(requireContext(), ShareInstagramStory::class.java).putExtra(
|
||||||
|
ShareInstagramStory.EXTRA_SONG,
|
||||||
|
song
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,15 +76,15 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(),
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_share -> {
|
R.id.action_share -> {
|
||||||
SongShareDialog.create(song).show(requireFragmentManager(), "SHARE_SONG")
|
SongShareDialog.create(song).show(childFragmentManager, "SHARE_SONG")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_delete_from_device -> {
|
R.id.action_delete_from_device -> {
|
||||||
DeleteSongsDialog.create(song).show(requireFragmentManager(), "DELETE_SONGS")
|
DeleteSongsDialog.create(song).show(childFragmentManager, "DELETE_SONGS")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_add_to_playlist -> {
|
R.id.action_add_to_playlist -> {
|
||||||
AddToPlaylistDialog.create(song).show(requireFragmentManager(), "ADD_PLAYLIST")
|
AddToPlaylistDialog.create(song).show(childFragmentManager, "ADD_PLAYLIST")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_clear_playing_queue -> {
|
R.id.action_clear_playing_queue -> {
|
||||||
|
@ -93,7 +93,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(),
|
||||||
}
|
}
|
||||||
R.id.action_save_playing_queue -> {
|
R.id.action_save_playing_queue -> {
|
||||||
CreatePlaylistDialog.create(MusicPlayerRemote.playingQueue)
|
CreatePlaylistDialog.create(MusicPlayerRemote.playingQueue)
|
||||||
.show(requireFragmentManager(), "ADD_TO_PLAYLIST")
|
.show(childFragmentManager, "ADD_TO_PLAYLIST")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_tag_editor -> {
|
R.id.action_tag_editor -> {
|
||||||
|
@ -103,7 +103,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(),
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_details -> {
|
R.id.action_details -> {
|
||||||
SongDetailDialog.create(song).show(requireFragmentManager(), "SONG_DETAIL")
|
SongDetailDialog.create(song).show(childFragmentManager, "SONG_DETAIL")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_go_to_album -> {
|
R.id.action_go_to_album -> {
|
||||||
|
|
|
@ -396,18 +396,27 @@ public class MusicService extends Service implements
|
||||||
|
|
||||||
mediaStoreObserver = new MediaStoreObserver(this, playerHandler);
|
mediaStoreObserver = new MediaStoreObserver(this, playerHandler);
|
||||||
throttledSeekHandler = new ThrottledSeekHandler(this, playerHandler);
|
throttledSeekHandler = new ThrottledSeekHandler(this, playerHandler);
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
getContentResolver()
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
.registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
getContentResolver()
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
.registerContentObserver(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
getContentResolver()
|
||||||
|
.registerContentObserver(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
getContentResolver()
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Albums.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
.registerContentObserver(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Artists.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
getContentResolver()
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Genres.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
.registerContentObserver(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
getContentResolver().registerContentObserver(MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
|
||||||
|
|
||||||
|
getContentResolver()
|
||||||
|
.registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
|
getContentResolver()
|
||||||
|
.registerContentObserver(MediaStore.Audio.Albums.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
|
getContentResolver()
|
||||||
|
.registerContentObserver(MediaStore.Audio.Artists.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
|
getContentResolver()
|
||||||
|
.registerContentObserver(MediaStore.Audio.Genres.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
|
getContentResolver()
|
||||||
|
.registerContentObserver(MediaStore.Audio.Playlists.INTERNAL_CONTENT_URI, true, mediaStoreObserver);
|
||||||
|
|
||||||
PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this);
|
PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this);
|
||||||
|
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* Licensed under the GNU General Public License v3
|
|
||||||
*
|
|
||||||
* This is free software: you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.util
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.os.Environment
|
|
||||||
import java.io.File
|
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by hemanths on 2019-11-05.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class ImageSaver(val context: Context) {
|
|
||||||
private var external: Boolean = false
|
|
||||||
private var directoryName: String = "RetroMusic"
|
|
||||||
private var fileName: String = "profile.png"
|
|
||||||
|
|
||||||
fun setFileName(fileName: String): ImageSaver {
|
|
||||||
this.fileName = fileName
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setDirectoryName(directoryName: String): ImageSaver {
|
|
||||||
this.directoryName = directoryName
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setStoreType(external: Boolean): ImageSaver {
|
|
||||||
this.external = external
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun save(bitmap: Bitmap) {
|
|
||||||
var fileOutputStream: FileOutputStream? = null
|
|
||||||
try {
|
|
||||||
fileOutputStream = FileOutputStream(createFile())
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)
|
|
||||||
} catch (er: Exception) {
|
|
||||||
println(er)
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
fileOutputStream?.close()
|
|
||||||
} catch (er: IOException) {
|
|
||||||
println(er)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFile(): File {
|
|
||||||
return createFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createFile(): File {
|
|
||||||
val directory: File = if (external) {
|
|
||||||
getFileStorePlace(directoryName)
|
|
||||||
} else {
|
|
||||||
context.getDir(directoryName, Context.MODE_PRIVATE)
|
|
||||||
}
|
|
||||||
if (!directory.exists() && !directory.mkdirs()) {
|
|
||||||
println("Error in creating folders $directory")
|
|
||||||
}
|
|
||||||
println("Create file -> $directory/$fileName")
|
|
||||||
return File(directory, fileName)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getFileStorePlace(directoryName: String): File {
|
|
||||||
return File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), directoryName)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun load(): Bitmap? {
|
|
||||||
var inputStream: FileInputStream? = null
|
|
||||||
return try {
|
|
||||||
inputStream = FileInputStream(createFile())
|
|
||||||
BitmapFactory.decodeStream(inputStream)
|
|
||||||
} catch (er: Exception) {
|
|
||||||
try {
|
|
||||||
inputStream?.close()
|
|
||||||
} catch (e: IOException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Hemanth Savarala.
|
|
||||||
*
|
|
||||||
* Licensed under the GNU General Public License v3
|
|
||||||
*
|
|
||||||
* This is free software: you can redistribute it and/or modify it under
|
|
||||||
* the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
||||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU General Public License for more details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package code.name.monkey.retromusic.util;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmAlbum.Album.Image;
|
|
||||||
import code.name.monkey.retromusic.rest.model.LastFmArtist;
|
|
||||||
|
|
||||||
public class LastFMUtil {
|
|
||||||
|
|
||||||
public static String getLargestAlbumImageUrl(List<Image> list) {
|
|
||||||
Map hashMap = new HashMap();
|
|
||||||
for (Image image : list) {
|
|
||||||
Object obj = null;
|
|
||||||
String size = image.getSize();
|
|
||||||
if (size == null) {
|
|
||||||
obj = ImageSize.UNKNOWN;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
obj = ImageSize.valueOf(size.toUpperCase(Locale.ENGLISH));
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (obj != null) {
|
|
||||||
hashMap.put(obj, image.getText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getLargestImageUrl(hashMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLargestArtistImageUrl(List<LastFmArtist.Artist.Image> list) {
|
|
||||||
Map hashMap = new HashMap();
|
|
||||||
for (LastFmArtist.Artist.Image image : list) {
|
|
||||||
Object obj = null;
|
|
||||||
String size = image.getSize();
|
|
||||||
if (size == null) {
|
|
||||||
obj = ImageSize.UNKNOWN;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
obj = ImageSize.valueOf(size.toUpperCase(Locale.ENGLISH));
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (obj != null) {
|
|
||||||
hashMap.put(obj, image.getText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getLargestImageUrl(hashMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getLargestImageUrl(Map<ImageSize, String> map) {
|
|
||||||
return map.containsKey(ImageSize.MEGA) ? map.get(ImageSize.MEGA)
|
|
||||||
: map.containsKey(ImageSize.EXTRALARGE) ? map.get(ImageSize.EXTRALARGE)
|
|
||||||
: map.containsKey(ImageSize.LARGE) ? map.get(ImageSize.LARGE)
|
|
||||||
: map.containsKey(ImageSize.MEDIUM) ? map.get(ImageSize.MEDIUM)
|
|
||||||
: map.containsKey(ImageSize.SMALL) ? map.get(ImageSize.SMALL)
|
|
||||||
: map.containsKey(ImageSize.UNKNOWN) ? map.get(ImageSize.UNKNOWN) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum ImageSize {
|
|
||||||
SMALL,
|
|
||||||
MEDIUM,
|
|
||||||
LARGE,
|
|
||||||
EXTRALARGE,
|
|
||||||
MEGA,
|
|
||||||
UNKNOWN
|
|
||||||
}
|
|
||||||
}
|
|
51
app/src/main/java/code/name/monkey/retromusic/util/Share.kt
Normal file
51
app/src/main/java/code/name/monkey/retromusic/util/Share.kt
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Hemanth Savarala.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU General Public License v3
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package code.name.monkey.retromusic.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import code.name.monkey.retromusic.R
|
||||||
|
import code.name.monkey.retromusic.model.Song
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by hemanths on 2020-02-02.
|
||||||
|
*/
|
||||||
|
|
||||||
|
object Share {
|
||||||
|
|
||||||
|
private const val INSTAGRAM_PACKAGE_NAME = "com.instagram.android"
|
||||||
|
|
||||||
|
fun shareFileToInstagram(context: Context, song: Song, uri: Uri) {
|
||||||
|
val feedIntent = Intent(Intent.ACTION_SEND)
|
||||||
|
feedIntent.type = "image/*"
|
||||||
|
feedIntent.putExtra(Intent.EXTRA_TITLE, song.title)
|
||||||
|
feedIntent.putExtra(Intent.EXTRA_TEXT, song.artistName)
|
||||||
|
feedIntent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
feedIntent.setPackage(INSTAGRAM_PACKAGE_NAME)
|
||||||
|
|
||||||
|
val storiesIntent = Intent("com.instagram.share.ADD_TO_STORY")
|
||||||
|
storiesIntent.setDataAndType(uri, "jpg")
|
||||||
|
storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
storiesIntent.setPackage(INSTAGRAM_PACKAGE_NAME)
|
||||||
|
storiesIntent.putExtra(Intent.EXTRA_TITLE, song.title)
|
||||||
|
storiesIntent.putExtra(Intent.EXTRA_TEXT, song.artistName)
|
||||||
|
context.grantUriPermission("com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
val chooserIntent = Intent.createChooser(feedIntent, context.getString(R.string.social_instagram))
|
||||||
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(storiesIntent))
|
||||||
|
ActivityCompat.startActivity(context, chooserIntent, null)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
>
|
<gradient
|
||||||
<gradient
|
android:angle="90"
|
||||||
android:angle="90"
|
android:endColor="@android:color/transparent"
|
||||||
android:endColor="@android:color/transparent"
|
android:startColor="@color/md_black_1000" />
|
||||||
android:startColor="#000000"/>
|
|
||||||
</shape>
|
</shape>
|
117
app/src/main/res/layout/activity_share_instagram.xml
Normal file
117
app/src/main/res/layout/activity_share_instagram.xml
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
|
~ Copyright (c) 2020 Hemanth Savarala.
|
||||||
|
~
|
||||||
|
~ Licensed under the GNU General Public License v3
|
||||||
|
~
|
||||||
|
~ This is free software: you can redistribute it and/or modify it under
|
||||||
|
~ the terms of the GNU General Public License as published by
|
||||||
|
~ the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||||
|
~
|
||||||
|
~ This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
~ See the GNU General Public License for more details.
|
||||||
|
-->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<code.name.monkey.retromusic.views.StatusBarView
|
||||||
|
android:id="@+id/status_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:background="?attr/colorSurface"
|
||||||
|
tools:ignore="UnusedAttribute" />
|
||||||
|
|
||||||
|
|
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="?attr/colorSurface"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:title="@string/social_instagram" />
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:id="@+id/mainContent"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<code.name.monkey.retromusic.views.WidthFitSquareCardView
|
||||||
|
android:id="@+id/imageContainerCard"
|
||||||
|
android:layout_width="320dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="24dp"
|
||||||
|
app:cardCornerRadius="8dp"
|
||||||
|
app:layout_constraintDimensionRatio="1:1"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
tools:src="@tools:sample/avatars" />
|
||||||
|
</code.name.monkey.retromusic.views.WidthFitSquareCardView>
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/shareTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textAppearance="@style/TextViewHeadline5"
|
||||||
|
android:textColor="@color/md_white_1000"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constrainedWidth="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/imageContainerCard"
|
||||||
|
tools:text="@tools:sample/full_names" />
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/shareText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textAppearance="@style/TextViewHeadline6"
|
||||||
|
android:textColor="@color/md_white_1000"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constrainedWidth="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/shareTitle"
|
||||||
|
tools:text="@tools:sample/full_names" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/shareButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|center_horizontal"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:text="Instagram Stories"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/appCompatImageView"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/mainContent" />
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
</LinearLayout>
|
|
@ -22,7 +22,7 @@
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#C0000000" />
|
android:background="@drawable/shadow_up_full_theme" />
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -39,7 +39,6 @@
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
tools:layout="@layout/fragment_full_player_controls" />
|
tools:layout="@layout/fragment_full_player_controls" />
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -94,6 +93,7 @@
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textAppearance="@style/TextViewSubtitle1"
|
android:textAppearance="@style/TextViewSubtitle1"
|
||||||
android:textColor="@color/md_white_1000"
|
android:textColor="@color/md_white_1000"
|
||||||
|
android:textStyle="bold"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/artistImage"
|
app:layout_constraintEnd_toStartOf="@+id/artistImage"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
@ -128,7 +128,7 @@
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:visibility="visible">
|
tools:visibility="visible">
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/player_lyrics_line1"
|
android:id="@+id/player_lyrics_line1"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -136,11 +136,11 @@
|
||||||
android:shadowColor="@color/md_black_1000"
|
android:shadowColor="@color/md_black_1000"
|
||||||
android:shadowRadius="4"
|
android:shadowRadius="4"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
|
android:textAppearance="@style/TextViewHeadline6"
|
||||||
android:textColor="@color/md_white_1000"
|
android:textColor="@color/md_white_1000"
|
||||||
android:textSize="22sp"
|
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<com.google.android.material.textview.MaterialTextView
|
||||||
android:id="@+id/player_lyrics_line2"
|
android:id="@+id/player_lyrics_line2"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -148,10 +148,9 @@
|
||||||
android:shadowColor="@color/md_black_1000"
|
android:shadowColor="@color/md_black_1000"
|
||||||
android:shadowRadius="4"
|
android:shadowRadius="4"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textColor="@color/md_white_1000"
|
android:textAppearance="@style/TextViewHeadline6"
|
||||||
android:textSize="22sp" />
|
android:textColor="@color/md_white_1000" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/roundSelector"
|
android:background="?attr/roundSelector"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/text"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:srcCompat="@drawable/ic_more_vert_white_24dp" />
|
app:srcCompat="@drawable/ic_more_vert_white_24dp" />
|
||||||
|
@ -45,9 +46,7 @@
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:paddingStart="8dp"
|
android:padding="8dp"
|
||||||
android:paddingTop="12dp"
|
|
||||||
android:paddingEnd="8dp"
|
|
||||||
android:textColor="@color/md_white_1000"
|
android:textColor="@color/md_white_1000"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/progressSlider"
|
app:layout_constraintBottom_toTopOf="@+id/progressSlider"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/playerMenu"
|
app:layout_constraintEnd_toStartOf="@+id/playerMenu"
|
||||||
|
@ -62,9 +61,9 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/roundSelector"
|
android:background="?attr/roundSelector"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/text"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="@+id/title"
|
||||||
app:layout_constraintVertical_bias="0.0"
|
|
||||||
app:srcCompat="@drawable/ic_favorite_border_white_24dp" />
|
app:srcCompat="@drawable/ic_favorite_border_white_24dp" />
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,5 +25,5 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignTop="@id/dummy_statusbar_actionbar"
|
android:layout_alignTop="@id/dummy_statusbar_actionbar"
|
||||||
android:layout_alignBottom="@id/dummy_statusbar_actionbar"
|
android:layout_alignBottom="@id/dummy_statusbar_actionbar"
|
||||||
android:background="@drawable/shadow_down" />
|
android:background="@drawable/shadow_down_strong" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
|
@ -460,7 +460,7 @@
|
||||||
<string name="pick_image_intent_text">Pick image</string>
|
<string name="pick_image_intent_text">Pick image</string>
|
||||||
|
|
||||||
<string name="pinterest_page">Pinterest</string>
|
<string name="pinterest_page">Pinterest</string>
|
||||||
<string name="pinterest_page_summary">Follow Pintrest page for Retro Music design inspiration</string>
|
<string name="pinterest_page_summary">Follow Pinterest page for Retro Music design inspiration</string>
|
||||||
|
|
||||||
<string name="plain">Plain</string>
|
<string name="plain">Plain</string>
|
||||||
|
|
||||||
|
@ -821,4 +821,5 @@
|
||||||
<string name="volume">Volume</string>
|
<string name="volume">Volume</string>
|
||||||
<string name="listeners_label">Listeners</string>
|
<string name="listeners_label">Listeners</string>
|
||||||
<string name="scrobbles_label">Scrobbles</string>
|
<string name="scrobbles_label">Scrobbles</string>
|
||||||
|
<string name="social_instagram">Instagram story</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
<paths>
|
||||||
<external-path name="external_files" path="."/>
|
<external-path
|
||||||
|
name="external_files"
|
||||||
|
path="." />
|
||||||
</paths>
|
</paths>
|
Loading…
Reference in a new issue