2019-03-03 09:20:15 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-12-06 08:52:57 +00:00
|
|
|
package code.name.monkey.retromusic.dialogs
|
|
|
|
|
2019-05-15 20:55:57 +00:00
|
|
|
import android.app.Dialog
|
2018-12-06 08:52:57 +00:00
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
2019-05-15 20:55:57 +00:00
|
|
|
import androidx.fragment.app.DialogFragment
|
2020-05-23 22:26:45 +00:00
|
|
|
import code.name.monkey.retromusic.EXTRA_SONG
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
2020-02-02 12:44:16 +00:00
|
|
|
import code.name.monkey.retromusic.activities.ShareInstagramStory
|
2020-07-19 11:21:15 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.colorButtons
|
2018-12-06 08:52:57 +00:00
|
|
|
import code.name.monkey.retromusic.model.Song
|
|
|
|
import code.name.monkey.retromusic.util.MusicUtil
|
2020-05-23 21:47:23 +00:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
2018-12-06 08:52:57 +00:00
|
|
|
|
2019-05-15 20:55:57 +00:00
|
|
|
class SongShareDialog : DialogFragment() {
|
|
|
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
2020-05-23 22:26:45 +00:00
|
|
|
val song: Song? = requireArguments().getParcelable(EXTRA_SONG)
|
2020-05-23 21:47:23 +00:00
|
|
|
val listening: String =
|
2020-05-23 22:26:45 +00:00
|
|
|
String.format(
|
|
|
|
getString(R.string.currently_listening_to_x_by_x),
|
|
|
|
song?.title,
|
|
|
|
song?.artistName
|
|
|
|
)
|
2020-05-23 21:47:23 +00:00
|
|
|
return MaterialAlertDialogBuilder(
|
|
|
|
requireContext(),
|
|
|
|
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert
|
|
|
|
).setTitle(R.string.what_do_you_want_to_share)
|
|
|
|
.setItems(
|
|
|
|
arrayOf(
|
|
|
|
getString(R.string.the_audio_file),
|
|
|
|
"\u201C" + listening + "\u201D",
|
|
|
|
getString(R.string.social_stories)
|
|
|
|
)
|
|
|
|
) { _, which ->
|
|
|
|
withAction(which, song, listening)
|
|
|
|
}
|
|
|
|
.create()
|
2020-07-19 11:21:15 +00:00
|
|
|
.colorButtons()
|
2020-05-23 21:47:23 +00:00
|
|
|
}
|
2020-05-23 09:27:55 +00:00
|
|
|
|
2020-05-23 21:47:23 +00:00
|
|
|
private fun withAction(
|
|
|
|
which: Int,
|
|
|
|
song: Song?,
|
|
|
|
currentlyListening: String
|
|
|
|
) {
|
|
|
|
when (which) {
|
|
|
|
0 -> {
|
|
|
|
startActivity(Intent.createChooser(song?.let {
|
|
|
|
MusicUtil.createShareSongFileIntent(
|
|
|
|
it,
|
|
|
|
requireContext()
|
|
|
|
)
|
|
|
|
}, null))
|
|
|
|
}
|
|
|
|
1 -> {
|
|
|
|
startActivity(
|
|
|
|
Intent.createChooser(
|
|
|
|
Intent()
|
|
|
|
.setAction(Intent.ACTION_SEND)
|
|
|
|
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
|
|
|
|
.setType("text/plain"),
|
|
|
|
null
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
2 -> {
|
|
|
|
if (song != null) {
|
|
|
|
startActivity(
|
|
|
|
Intent(
|
|
|
|
requireContext(),
|
|
|
|
ShareInstagramStory::class.java
|
|
|
|
).putExtra(
|
|
|
|
ShareInstagramStory.EXTRA_SONG,
|
|
|
|
song
|
|
|
|
)
|
2020-02-01 17:53:26 +00:00
|
|
|
)
|
2019-05-15 20:55:57 +00:00
|
|
|
}
|
2020-02-01 17:53:26 +00:00
|
|
|
}
|
2020-05-23 21:47:23 +00:00
|
|
|
}
|
2018-12-06 08:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
fun create(song: Song): SongShareDialog {
|
|
|
|
val dialog = SongShareDialog()
|
|
|
|
val args = Bundle()
|
2020-05-23 22:26:45 +00:00
|
|
|
args.putParcelable(EXTRA_SONG, song)
|
2018-12-06 08:52:57 +00:00
|
|
|
dialog.arguments = args
|
|
|
|
return dialog
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|