PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt

94 lines
3.8 KiB
Kotlin
Raw Normal View History

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
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
2018-12-06 08:52:57 +00:00
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil
2019-09-17 19:36:13 +00:00
import code.name.monkey.retromusic.util.PreferenceUtil
import com.afollestad.materialdialogs.LayoutMode
2019-05-15 20:55:57 +00:00
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
import com.afollestad.materialdialogs.list.listItems
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-02-02 12:44:16 +00:00
val song: Song? = arguments?.getParcelable("song")
2020-02-01 17:53:26 +00:00
val currentlyListening: String =
getString(R.string.currently_listening_to_x_by_x, song?.title, song?.artistName)
2019-02-17 17:01:35 +00:00
2019-09-17 19:36:13 +00:00
return MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT))
2020-02-01 17:53:26 +00:00
.title(R.string.what_do_you_want_to_share)
.show {
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
listItems(
items = listOf(
getString(code.name.monkey.retromusic.R.string.the_audio_file),
2020-02-02 12:44:16 +00:00
"\u201C" + currentlyListening + "\u201D",
2020-02-02 17:39:16 +00:00
getString(R.string.social_stories)
2020-02-01 17:53:26 +00:00
)
) { _, index, _ ->
when (index) {
0 -> {
startActivity(Intent.createChooser(song?.let {
MusicUtil.createShareSongFileIntent(
it,
context
)
}, null))
}
1 -> {
2020-02-02 12:44:16 +00:00
startActivity(
2020-02-01 17:53:26 +00:00
Intent.createChooser(
Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
.setType("text/plain"),
null
2019-05-15 20:55:57 +00:00
)
2020-02-01 17:53:26 +00:00
)
2019-05-15 20:55:57 +00:00
}
2020-02-02 12:44:16 +00:00
2 -> {
if (song != null) {
startActivity(
Intent(requireContext(), ShareInstagramStory::class.java).putExtra(
ShareInstagramStory.EXTRA_SONG,
song
)
)
}
}
2019-05-15 20:55:57 +00:00
}
}
2020-02-01 17:53:26 +00:00
}
2018-12-06 08:52:57 +00:00
}
companion object {
fun create(song: Song): SongShareDialog {
val dialog = SongShareDialog()
val args = Bundle()
args.putParcelable("song", song)
dialog.arguments = args
return dialog
}
}
}