Added instagram story

main
h4h13 2020-02-02 22:51:26 +05:30
parent 8e387264d5
commit ddc1edfc82
5 changed files with 150 additions and 82 deletions

View File

@ -16,15 +16,19 @@ package code.name.monkey.retromusic.activities
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore.Images.Media import android.provider.MediaStore.Images.Media
import android.view.MenuItem
import androidx.core.view.drawToBitmap import androidx.core.view.drawToBitmap
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsBaseActivity import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
import code.name.monkey.retromusic.glide.SongGlideRequest import code.name.monkey.retromusic.glide.SongGlideRequest
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.Share import code.name.monkey.retromusic.util.Share
@ -46,25 +50,37 @@ class ShareInstagramStory : AbsBaseActivity() {
const val EXTRA_SONG = "extra_song" const val EXTRA_SONG = "extra_song"
} }
private lateinit var colorString: String
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setDrawUnderStatusBar() setDrawUnderStatusBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_share_instagram) setContentView(R.layout.activity_share_instagram)
setStatusbarColorAuto() setStatusbarColor(Color.TRANSPARENT)
setNavigationbarColorAuto() setNavigationbarColor(Color.BLACK)
setLightNavigationBar(true)
val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface) toolbar.setBackgroundColor(Color.TRANSPARENT)
toolbar.setBackgroundColor(toolbarColor)
ToolbarContentTintHelper.colorBackButton(toolbar)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
val song = intent.extras?.getParcelable<Song>(EXTRA_SONG) val song = intent.extras?.getParcelable<Song>(EXTRA_SONG)
song?.let { songFinal -> song?.let { songFinal ->
SongGlideRequest.Builder.from(Glide.with(this), songFinal) SongGlideRequest.Builder.from(Glide.with(this), songFinal)
.asBitmap() .checkIgnoreMediaStore(this@ShareInstagramStory)
.generatePalette(this@ShareInstagramStory)
.build() .build()
.into(image) .into(object : RetroMusicColoredTarget(image) {
override fun onColorReady(color: Int) {
val isColorLight = ColorUtil.isColorLight(color)
setColors(isColorLight, color)
}
})
shareTitle.text = songFinal.title shareTitle.text = songFinal.title
shareText.text = songFinal.artistName shareText.text = songFinal.artistName
@ -77,11 +93,24 @@ class ShareInstagramStory : AbsBaseActivity() {
val uri = Uri.parse(path) val uri = Uri.parse(path)
Share.shareFileToInstagram( Share.shareFileToInstagram(
this@ShareInstagramStory, this@ShareInstagramStory,
songFinal,
uri uri
) )
} }
} }
shareButton.setTextColor(
MaterialValueHelper.getPrimaryTextColor(
this,
ColorUtil.isColorLight(ThemeStore.accentColor(this))
)
)
shareButton.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this)) shareButton.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
} }
private fun setColors(colorLight: Boolean, color: Int) {
setLightStatusbar(ColorUtil.isColorLight(color))
toolbar.setTitleTextColor(MaterialValueHelper.getPrimaryTextColor(this@ShareInstagramStory, colorLight))
toolbar.navigationIcon?.setTintList(ColorStateList.valueOf(Color.WHITE))
mainContent.background =
GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, intArrayOf(color, Color.BLACK))
}
} }

View File

@ -19,7 +19,6 @@ import android.content.Intent
import android.net.Uri import android.net.Uri
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song
/** /**
* Created by hemanths on 2020-02-02. * Created by hemanths on 2020-02-02.
@ -28,22 +27,24 @@ import code.name.monkey.retromusic.model.Song
object Share { object Share {
private const val INSTAGRAM_PACKAGE_NAME = "com.instagram.android" private const val INSTAGRAM_PACKAGE_NAME = "com.instagram.android"
private const val MEDIA_TYPE_JPEG = "jpg"
fun shareFileToInstagram(context: Context, song: Song, uri: Uri) { fun shareFileToInstagram(context: Context, uri: Uri) {
val feedIntent = Intent(Intent.ACTION_SEND) val feedIntent = Intent(Intent.ACTION_SEND)
feedIntent.type = "image/*" feedIntent.type = "image/*"
feedIntent.putExtra(Intent.EXTRA_TITLE, song.title)
feedIntent.putExtra(Intent.EXTRA_TEXT, song.artistName)
feedIntent.putExtra(Intent.EXTRA_STREAM, uri) feedIntent.putExtra(Intent.EXTRA_STREAM, uri)
feedIntent.setPackage(INSTAGRAM_PACKAGE_NAME) feedIntent.setPackage(INSTAGRAM_PACKAGE_NAME)
feedIntent.putExtra("top_background_color", "#33FF33")
feedIntent.putExtra("bottom_background_color", "#FF00FF")
val storiesIntent = Intent("com.instagram.share.ADD_TO_STORY") val storiesIntent = Intent("com.instagram.share.ADD_TO_STORY")
storiesIntent.setDataAndType(uri, "jpg") //storiesIntent.setDataAndType(uri, MEDIA_TYPE_JPEG)
storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
storiesIntent.setPackage(INSTAGRAM_PACKAGE_NAME) storiesIntent.setPackage(INSTAGRAM_PACKAGE_NAME)
storiesIntent.putExtra(Intent.EXTRA_TITLE, song.title) storiesIntent.type = MEDIA_TYPE_JPEG
storiesIntent.putExtra(Intent.EXTRA_TEXT, song.artistName) storiesIntent.putExtra("top_background_color", "#33FF33")
context.grantUriPermission("com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) storiesIntent.putExtra("bottom_background_color", "#0000FF")
storiesIntent.putExtra("content_url", "https://www.google.com")
val chooserIntent = Intent.createChooser(feedIntent, context.getString(R.string.social_instagram)) val chooserIntent = Intent.createChooser(feedIntent, context.getString(R.string.social_instagram))
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(storiesIntent)) chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(storiesIntent))
ActivityCompat.startActivity(context, chooserIntent, null) ActivityCompat.startActivity(context, chooserIntent, null)

View File

@ -0,0 +1,21 @@
<?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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="@color/transparent"
android:startColor="@color/md_red_500" />
</shape>

View File

@ -11,54 +11,37 @@
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ See the GNU General Public License for more details. ~ See the GNU General Public License for more details.
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical"> android:orientation="vertical">
<code.name.monkey.retromusic.views.StatusBarView <LinearLayout
android:id="@+id/status_bar" android:id="@+id/mainContent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="wrap_content"
android:background="?attr/colorSurface" android:background="@drawable/instagram_story_background"
tools:ignore="UnusedAttribute" /> android:gravity="center"
android:minHeight="1080dp"
android:orientation="vertical"
<androidx.coordinatorlayout.widget.CoordinatorLayout app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/content" app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent" app:layout_constraintTop_toTopOf="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 <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mainContent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="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 <code.name.monkey.retromusic.views.WidthFitSquareCardView
android:id="@+id/imageContainerCard" android:id="@+id/imageContainerCard"
android:layout_width="320dp" android:layout_width="290dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="24dp" app:cardCornerRadius="16dp"
app:cardCornerRadius="8dp"
app:layout_constraintDimensionRatio="1:1" app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -74,44 +57,77 @@
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/shareTitle" android:id="@+id/shareTitle"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:gravity="center" 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:textAppearance="@style/TextViewHeadline6"
android:textColor="@color/md_white_1000" android:textColor="@color/md_white_1000"
android:textStyle="bold" android:textStyle="bold"
app:layout_constrainedWidth="true" app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="@+id/imageContainerCard"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="@+id/imageContainerCard"
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="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="@style/TextViewSubtitle1"
android:textColor="@color/md_grey_400"
android:textStyle="bold"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="@+id/imageContainerCard"
app:layout_constraintStart_toStartOf="@+id/imageContainerCard"
app:layout_constraintTop_toBottomOf="@id/shareTitle" app:layout_constraintTop_toBottomOf="@id/shareTitle"
tools:text="@tools:sample/full_names" /> tools:text="@tools:sample/full_names" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/shareButton" android:id="@+id/shareButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="16dp"
android:paddingStart="24dp"
android:paddingTop="14dp"
android:paddingEnd="24dp"
android:paddingBottom="14dp"
android:text="@string/share_to_stories"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/mainContent" />
<LinearLayout
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" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal" android:background="@color/transparent"
android:layout_margin="16dp" android:elevation="0dp"
android:text="Instagram Stories" app:elevation="0dp">
app:layout_constraintBottom_toBottomOf="@+id/appCompatImageView"
app:layout_constraintEnd_toEndOf="parent" <com.google.android.material.appbar.MaterialToolbar
app:layout_constraintStart_toStartOf="parent" android:id="@+id/toolbar"
app:layout_constraintTop_toBottomOf="@id/mainContent" /> android:layout_width="match_parent"
</androidx.coordinatorlayout.widget.CoordinatorLayout> android:layout_height="wrap_content"
</LinearLayout> app:navigationIcon="@drawable/ic_keyboard_backspace_black_24dp"
app:title="@string/social_instagram"
app:titleTextAppearance="@style/ToolbarTextAppearanceNormal" />
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -822,4 +822,5 @@
<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> <string name="social_instagram">Instagram story</string>
<string name="share_to_stories">Share to Stories</string>
</resources> </resources>