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

72 lines
3.1 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
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-03-04 03:55:09 +00:00
2019-05-15 20:55:57 +00:00
class SongShareDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
2019-08-04 10:08:34 +00:00
val song: Song? = arguments!!.getParcelable("song")
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))
2019-05-15 20:55:57 +00:00
.title(R.string.what_do_you_want_to_share)
.show {
2019-09-17 19:36:13 +00:00
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
2019-05-15 20:55:57 +00:00
listItems(items = listOf(getString(code.name.monkey.retromusic.R.string.the_audio_file), "\u201C" + currentlyListening + "\u201D")) { dialog, index, text ->
when (index) {
0 -> {
2019-08-04 10:08:34 +00:00
startActivity(Intent.createChooser(song?.let { MusicUtil.createShareSongFileIntent(it, context) }, null))
2019-05-15 20:55:57 +00:00
}
1 -> {
activity!!.startActivity(
Intent.createChooser(
Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
.setType("text/plain"),
null
)
)
}
}
}
}
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
}
}
}