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.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore.Images.Media
import android.view.MenuItem
import androidx.core.view.drawToBitmap
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.R
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.model.Song
import code.name.monkey.retromusic.util.Share
@ -46,25 +50,37 @@ class ShareInstagramStory : AbsBaseActivity() {
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?) {
setDrawUnderStatusBar()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_share_instagram)
setStatusbarColorAuto()
setNavigationbarColorAuto()
setLightNavigationBar(true)
setStatusbarColor(Color.TRANSPARENT)
setNavigationbarColor(Color.BLACK)
val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface)
toolbar.setBackgroundColor(toolbarColor)
ToolbarContentTintHelper.colorBackButton(toolbar)
toolbar.setBackgroundColor(Color.TRANSPARENT)
setSupportActionBar(toolbar)
val song = intent.extras?.getParcelable<Song>(EXTRA_SONG)
song?.let { songFinal ->
SongGlideRequest.Builder.from(Glide.with(this), songFinal)
.asBitmap()
.checkIgnoreMediaStore(this@ShareInstagramStory)
.generatePalette(this@ShareInstagramStory)
.build()
.into(image)
.into(object : RetroMusicColoredTarget(image) {
override fun onColorReady(color: Int) {
val isColorLight = ColorUtil.isColorLight(color)
setColors(isColorLight, color)
}
})
shareTitle.text = songFinal.title
shareText.text = songFinal.artistName
@ -77,11 +93,24 @@ class ShareInstagramStory : AbsBaseActivity() {
val uri = Uri.parse(path)
Share.shareFileToInstagram(
this@ShareInstagramStory,
songFinal,
uri
)
}
}
shareButton.setTextColor(
MaterialValueHelper.getPrimaryTextColor(
this,
ColorUtil.isColorLight(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 androidx.core.app.ActivityCompat
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song
/**
* Created by hemanths on 2020-02-02.
@ -28,22 +27,24 @@ import code.name.monkey.retromusic.model.Song
object Share {
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)
feedIntent.type = "image/*"
feedIntent.putExtra(Intent.EXTRA_TITLE, song.title)
feedIntent.putExtra(Intent.EXTRA_TEXT, song.artistName)
feedIntent.putExtra(Intent.EXTRA_STREAM, uri)
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")
storiesIntent.setDataAndType(uri, "jpg")
//storiesIntent.setDataAndType(uri, MEDIA_TYPE_JPEG)
storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
storiesIntent.setPackage(INSTAGRAM_PACKAGE_NAME)
storiesIntent.putExtra(Intent.EXTRA_TITLE, song.title)
storiesIntent.putExtra(Intent.EXTRA_TEXT, song.artistName)
context.grantUriPermission("com.instagram.android", uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
storiesIntent.type = MEDIA_TYPE_JPEG
storiesIntent.putExtra("top_background_color", "#33FF33")
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))
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(storiesIntent))
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.
~ 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:tools="http://schemas.android.com/tools"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical">
<code.name.monkey.retromusic.views.StatusBarView
android:id="@+id/status_bar"
<LinearLayout
android:id="@+id/mainContent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?attr/colorSurface"
tools:ignore="UnusedAttribute" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/content"
android:layout_width="match_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>
android:layout_height="wrap_content"
android:background="@drawable/instagram_story_background"
android:gravity="center"
android:minHeight="1080dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mainContent"
android:layout_width="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">
android:layout_height="match_parent">
<code.name.monkey.retromusic.views.WidthFitSquareCardView
android:id="@+id/imageContainerCard"
android:layout_width="320dp"
android:layout_width="290dp"
android:layout_height="wrap_content"
android:layout_margin="24dp"
app:cardCornerRadius="8dp"
app:cardCornerRadius="16dp"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -74,44 +57,77 @@
<com.google.android.material.textview.MaterialTextView
android:id="@+id/shareTitle"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
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:textColor="@color/md_white_1000"
android:textStyle="bold"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="@+id/imageContainerCard"
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"
tools:text="@tools:sample/full_names" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/shareButton"
android:layout_width="wrap_content"
<com.google.android.material.button.MaterialButton
android:id="@+id/shareButton"
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_gravity="bottom|center_horizontal"
android:layout_margin="16dp"
android:text="Instagram Stories"
app:layout_constraintBottom_toBottomOf="@+id/appCompatImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/mainContent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout>
android:background="@color/transparent"
android:elevation="0dp"
app:elevation="0dp">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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="scrobbles_label">Scrobbles</string>
<string name="social_instagram">Instagram story</string>
<string name="share_to_stories">Share to Stories</string>
</resources>