2020-02-02 12:44:16 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2020-02-02 17:21:26 +00:00
|
|
|
import android.graphics.Color
|
|
|
|
import android.graphics.drawable.GradientDrawable
|
2020-02-02 12:44:16 +00:00
|
|
|
import android.net.Uri
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.provider.MediaStore.Images.Media
|
2020-02-02 17:21:26 +00:00
|
|
|
import android.view.MenuItem
|
2020-02-02 12:44:16 +00:00
|
|
|
import androidx.core.view.drawToBitmap
|
|
|
|
import code.name.monkey.appthemehelper.ThemeStore
|
2020-02-02 17:21:26 +00:00
|
|
|
import code.name.monkey.appthemehelper.util.ColorUtil
|
|
|
|
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
2020-02-02 12:44:16 +00:00
|
|
|
import code.name.monkey.retromusic.R
|
|
|
|
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
2020-02-02 17:21:26 +00:00
|
|
|
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
|
2020-02-02 12:44:16 +00:00
|
|
|
import code.name.monkey.retromusic.glide.SongGlideRequest
|
|
|
|
import code.name.monkey.retromusic.model.Song
|
|
|
|
import code.name.monkey.retromusic.util.Share
|
2020-05-05 19:44:59 +00:00
|
|
|
import code.name.monkey.retromusic.util.color.MediaNotificationProcessor
|
2020-02-02 12:44:16 +00:00
|
|
|
import com.bumptech.glide.Glide
|
2020-02-26 16:49:24 +00:00
|
|
|
import kotlinx.android.synthetic.main.activity_share_instagram.*
|
2020-02-02 12:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by hemanths on 2020-02-02.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ShareInstagramStory : AbsBaseActivity() {
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val EXTRA_SONG = "extra_song"
|
|
|
|
}
|
|
|
|
|
2020-02-02 17:21:26 +00:00
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
if (item.itemId == android.R.id.home) {
|
|
|
|
onBackPressed()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
|
2020-02-02 12:44:16 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
setDrawUnderStatusBar()
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_share_instagram)
|
2020-02-02 17:21:26 +00:00
|
|
|
setStatusbarColor(Color.TRANSPARENT)
|
|
|
|
setNavigationbarColor(Color.BLACK)
|
2020-02-02 12:44:16 +00:00
|
|
|
|
2020-02-02 17:21:26 +00:00
|
|
|
toolbar.setBackgroundColor(Color.TRANSPARENT)
|
2020-02-02 12:44:16 +00:00
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
|
|
|
|
val song = intent.extras?.getParcelable<Song>(EXTRA_SONG)
|
|
|
|
song?.let { songFinal ->
|
|
|
|
SongGlideRequest.Builder.from(Glide.with(this), songFinal)
|
2020-02-02 17:21:26 +00:00
|
|
|
.checkIgnoreMediaStore(this@ShareInstagramStory)
|
|
|
|
.generatePalette(this@ShareInstagramStory)
|
2020-02-02 12:44:16 +00:00
|
|
|
.build()
|
2020-02-02 17:21:26 +00:00
|
|
|
.into(object : RetroMusicColoredTarget(image) {
|
2020-05-05 19:44:59 +00:00
|
|
|
override fun onColorReady(colors: MediaNotificationProcessor) {
|
|
|
|
val isColorLight = ColorUtil.isColorLight(colors.backgroundColor)
|
|
|
|
setColors(isColorLight, colors.backgroundColor)
|
2020-02-02 17:21:26 +00:00
|
|
|
}
|
|
|
|
})
|
2020-02-02 12:44:16 +00:00
|
|
|
|
|
|
|
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)
|
2020-02-02 17:39:16 +00:00
|
|
|
Share.shareStoryToSocial(
|
2020-02-02 12:44:16 +00:00
|
|
|
this@ShareInstagramStory,
|
|
|
|
uri
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-02-02 17:21:26 +00:00
|
|
|
shareButton.setTextColor(
|
|
|
|
MaterialValueHelper.getPrimaryTextColor(
|
|
|
|
this,
|
|
|
|
ColorUtil.isColorLight(ThemeStore.accentColor(this))
|
|
|
|
)
|
|
|
|
)
|
2020-02-02 12:44:16 +00:00
|
|
|
shareButton.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
|
|
|
}
|
2020-02-02 17:21:26 +00:00
|
|
|
|
|
|
|
private fun setColors(colorLight: Boolean, color: Int) {
|
2020-02-04 08:09:10 +00:00
|
|
|
setLightStatusbar(colorLight)
|
2020-02-26 16:49:24 +00:00
|
|
|
toolbar.setTitleTextColor(
|
|
|
|
MaterialValueHelper.getPrimaryTextColor(
|
|
|
|
this@ShareInstagramStory,
|
|
|
|
colorLight
|
|
|
|
)
|
|
|
|
)
|
2020-02-05 04:40:47 +00:00
|
|
|
toolbar.navigationIcon?.setTintList(
|
|
|
|
ColorStateList.valueOf(
|
|
|
|
MaterialValueHelper.getPrimaryTextColor(
|
|
|
|
this@ShareInstagramStory,
|
|
|
|
colorLight
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2020-02-02 17:21:26 +00:00
|
|
|
mainContent.background =
|
2020-02-26 16:49:24 +00:00
|
|
|
GradientDrawable(
|
|
|
|
GradientDrawable.Orientation.TOP_BOTTOM,
|
|
|
|
intArrayOf(color, Color.BLACK)
|
|
|
|
)
|
2020-02-02 17:21:26 +00:00
|
|
|
}
|
2020-02-02 12:44:16 +00:00
|
|
|
}
|