Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/share-instagram] Experimental: Instagram Share #407

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions .github/workflows/develop_PR_builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
KEY_ALIAS: ${{ secrets.SENTRY_DSN }}
KEY_PASSWORD: ${{ secrets.SENTRY_DSN }}
STORE_PASSWORD: ${{ secrets.SENTRY_DSN }}
FACEBOOK_APP_ID: ${{ secrets.SENTRY_DSN }}
run: |
echo sentryDsn=\"$SENTRY_DSN\" >> ./local.properties
echo kakaoApiKey=$KAKAO_API_KEY >> ./local.properties
Expand All @@ -53,6 +54,7 @@ jobs:
echo keyAlias=$KEY_ALIAS >> ./local.properties
echo keyPassword=KEY_PASSWORD >> ./local.properties
echo storePassword=$STORE_PASSWORD >> ./local.properties
echo facebookAppId=$FACEBOOK_APP_ID >> ./local.properties

- name: Access Firebase Service
run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > ./app/google-services.json
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<application
android:name=".App"
Expand Down Expand Up @@ -47,6 +49,9 @@
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="${admobAppId}" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="${facebookAppId}" />

<provider
android:name="androidx.startup.InitializationProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AlbumListActivity : AppCompatActivity() {
private val imagePicker =
registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
if (uri != null) {
val intent = albumItem?.let { AddPhotoActivity.getIntent(this, uri.toString(), it) }
val intent = albumItem?.let { AddPhotoActivity.getIntent(this, uri.toString(), it, "PICKER") }
photoCountRefreshLauncher.launch(intent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.teampophory.pophory.feature.home.photo.AddPhotoActivity
import com.teampophory.pophory.feature.qr.QRActivity

class AddPhotoBottomSheet : BottomSheetDialogFragment() {

private val binding by viewBinding(BottomSheetHomeAddPhotoBinding::bind)
private val viewModel by activityViewModels<HomeViewModel>()
private lateinit var imagePicker: ActivityResultLauncher<PickVisualMediaRequest>
Expand All @@ -44,7 +43,7 @@ class AddPhotoBottomSheet : BottomSheetDialogFragment() {
val currentAlbumPosition = viewModel.homeState.value.currentAlbumPosition
val albumItem = viewModel.homeState.value.currentAlbums?.getOrNull(currentAlbumPosition)
if (uri != null && albumItem != null) {
val intent = AddPhotoActivity.getIntent(context, uri.toString(), albumItem)
val intent = AddPhotoActivity.getIntent(context, uri.toString(), albumItem, "PICKER")
addPhotoResultLauncher.launch(intent)
}
}
Expand All @@ -57,7 +56,7 @@ class AddPhotoBottomSheet : BottomSheetDialogFragment() {
val albumItem =
viewModel.homeState.value.currentAlbums?.getOrNull(currentAlbumPosition)
if (uriString != null && albumItem != null) {
val intent = AddPhotoActivity.getIntent(context, uriString, albumItem)
val intent = AddPhotoActivity.getIntent(context, uriString, albumItem, "QR")
addPhotoResultLauncher.launch(intent)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.teampophory.pophory.feature.home.model

enum class RegisterNavigationType {
PICKER, QR, GALLERY
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.teampophory.pophory.feature.home.photo

import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Size
import android.widget.Toast
import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import coil.load
import com.google.android.material.datepicker.CalendarConstraints
import com.google.android.material.datepicker.DateValidatorPointBackward
import com.google.android.material.datepicker.MaterialDatePicker
import com.teampophory.pophory.BuildConfig
import com.teampophory.pophory.R
import com.teampophory.pophory.common.bitmap.capture
import com.teampophory.pophory.common.bitmap.saveToDisk
import com.teampophory.pophory.common.context.colorOf
import com.teampophory.pophory.common.context.snackBar
import com.teampophory.pophory.common.context.toast
Expand All @@ -26,10 +32,12 @@ import com.teampophory.pophory.common.time.systemNow
import com.teampophory.pophory.common.view.setOnSingleClickListener
import com.teampophory.pophory.common.view.viewBinding
import com.teampophory.pophory.databinding.ActivityAddPhotoBinding
import com.teampophory.pophory.feature.home.model.RegisterNavigationType
import com.teampophory.pophory.feature.home.store.model.AlbumItem
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.datetime.Instant
import java.text.SimpleDateFormat
import java.util.Date
Expand Down Expand Up @@ -63,9 +71,9 @@ class AddPhotoActivity : AppCompatActivity() {

private fun loadImageWithAdjustedSize(realImageUri: Uri, adjustedSize: Size) {
val (backgroundResource, imageView) = if (adjustedSize.width >= adjustedSize.height) {
Pair(R.drawable.img_background_width, binding.imgHorizontal)
R.drawable.img_background_width to binding.imgHorizontal
} else {
Pair(R.drawable.img_background_height, binding.imgVertical)
R.drawable.img_background_height to binding.imgVertical
}
binding.imgBackground.setImageResource(backgroundResource)
imageView.load(realImageUri) {
Expand All @@ -74,10 +82,10 @@ class AddPhotoActivity : AppCompatActivity() {
}

private fun initView() {
binding.toolbarAddPhoto.btnBack.setOnClickListener {
binding.btnBack.setOnClickListener {
finish()
}
binding.toolbarAddPhoto.txtToolbarTitle.text = "사진 μΆ”κ°€"
binding.txtToolbarTitle.text = "사진 μΆ”κ°€"
binding.layoutDate.setOnClickListener {
viewModel.onCreatedAtPressed()
}
Expand All @@ -91,6 +99,33 @@ class AddPhotoActivity : AppCompatActivity() {
setResult(Activity.RESULT_CANCELED)
finish()
}
binding.btnShare.setOnSingleClickListener {
lifecycleScope.launch {
val bitmap = binding.layoutImage.capture(this@AddPhotoActivity)
val shareImageUri = bitmap.saveToDisk(this@AddPhotoActivity)
val intent = Intent("com.instagram.share.ADD_TO_STORY").apply {
putExtra("source_application", BuildConfig.FACEBOOK_APP_ID)
type = "image/png"
putExtra("interactive_asset_uri", shareImageUri)
putExtra("top_background_color", "#000000")
putExtra("bottom_background_color", "#000000")
}
grantUriPermission(
"com.instagram.android",
shareImageUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION,
)
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
this@AddPhotoActivity,
"μΈμŠ€νƒ€κ·Έλž¨ 앱이 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.",
Toast.LENGTH_SHORT,
).show()
}
}
}
}

private fun subscribeEvent() {
Expand All @@ -112,7 +147,8 @@ class AddPhotoActivity : AppCompatActivity() {
.setEnd(Instant.systemNow().toEpochMilliseconds()).build(),
)
.setSelection(
currentCreatedAt + TimeZone.getDefault().getOffset(currentCreatedAt),
currentCreatedAt + TimeZone.getDefault()
.getOffset(currentCreatedAt),
)
.build()
picker.show(supportFragmentManager, "datePicker")
Expand Down Expand Up @@ -157,18 +193,30 @@ class AddPhotoActivity : AppCompatActivity() {
binding.txtStudio.setTextColor(colorOf(com.teampophory.pophory.designsystem.R.color.gray_40))
}
}.launchIn(lifecycleScope)
viewModel.type
.flowWithLifecycle(lifecycle)
.onEach {
binding.btnShare.isVisible = it != RegisterNavigationType.PICKER
}.launchIn(lifecycleScope)
}

companion object {
private const val IMAGE_URL_EXTRA = "imageUri"
const val ALBUM_ITEM_EXTRA = "albumItem"
const val IMAGE_MIME_TYPE = "image/*"
private const val TYPE = "type"

@JvmStatic
fun getIntent(context: Context, imageUri: String, albumItem: AlbumItem): Intent =
fun getIntent(
context: Context,
imageUri: String,
albumItem: AlbumItem,
type: String,
): Intent =
Intent(context, AddPhotoActivity::class.java).apply {
putExtra(IMAGE_URL_EXTRA, imageUri)
putExtra(ALBUM_ITEM_EXTRA, albumItem)
putExtra(TYPE, type)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.teampophory.pophory.common.time.systemNow
import com.teampophory.pophory.data.model.photo.Studio
import com.teampophory.pophory.domain.model.S3Image
import com.teampophory.pophory.domain.repository.photo.PhotoRepository
import com.teampophory.pophory.feature.home.model.RegisterNavigationType
import com.teampophory.pophory.feature.home.photo.model.StudioUiModel
import com.teampophory.pophory.feature.home.photo.model.toUiModel
import com.teampophory.pophory.feature.home.store.model.AlbumItem
Expand Down Expand Up @@ -43,6 +44,12 @@ class AddPhotoViewModel @Inject constructor(
private var imageRequestBody: RequestBody? = null
private var currentImageSize: Size? = null
private var currentFileName: String? = null
private val _type = MutableStateFlow(
RegisterNavigationType.valueOf(
savedStateHandle.get<String>("type").orEmpty(),
),
)
val type = _type.asStateFlow()
private val _createdAt = MutableStateFlow(Instant.systemNow().toEpochMilliseconds())
val createdAt = _createdAt.asStateFlow()
private val allStudio = MutableStateFlow<List<Studio>>(emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class StoreFragment : Fragment() {
context = requireContext(),
imageUri = imageUri.toString(),
albumItem = albumItem,
type = "GALLERY",
).let(albumListAddPhotoLauncher::launch)
}
}
Expand Down
53 changes: 48 additions & 5 deletions app/src/main/res/layout/activity_add_photo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,60 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
android:id="@+id/toolbar_add_photo"
layout="@layout/toolbar"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/white"
app:contentInsetStart="0dp"
app:layout_constraintTop_toTopOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/btn_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:contentDescription="back_button"
android:src="@drawable/ic_back"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/txt_toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?textAppearanceHeadlineMedium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="ν•˜μ΄λ£¨" />

<ImageView
android:id="@+id/btn_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:padding="12dp"
android:src="@drawable/ic_share_photo"
app:layout_constraintBottom_toBottomOf="@+id/txt_toolbar_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/txt_toolbar_title" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>

<ScrollView
android:id="@+id/layout_scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_add_photo">
app:layout_constraintTop_toBottomOf="@id/toolbar">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ internal fun Project.configureAndroidCommonPlugin() {
defaultConfig {
val kakaoApiKey = properties["kakaoApiKey"] as? String ?: ""
val pophoryBaseUrl = properties["pophoryBaseUrl"] as? String ?: ""
val facebookAppId = properties["facebookAppId"] as? String ?: ""

manifestPlaceholders["sentryDsn"] = properties["sentryDsn"] as String
manifestPlaceholders["kakaoApiKey"] = properties["kakaoApiKey"] as String
manifestPlaceholders["pophoryBaseUrl"] = properties["pophoryBaseUrl"] as String
manifestPlaceholders["admobAppId"] = properties["admobAppId"] as String
manifestPlaceholders["facebookAppId"] = properties["facebookAppId"] as String

buildConfigField("String", "KAKAO_API_KEY", "\"${kakaoApiKey}\"")
buildConfigField("String", "POPHORY_BASE_URL", "\"${pophoryBaseUrl}\"")
buildConfigField("String", "FACEBOOK_APP_ID", "\"${facebookAppId}\"")
}
buildFeatures.apply {
viewBinding = true
Expand Down
Loading