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/#946] WebView에 사진 다운로드 기능 추가 #947

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<queries>
<package android:name="com.android.chrome" />
Expand All @@ -41,6 +42,7 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SOPT"
Expand Down
42 changes: 21 additions & 21 deletions app/src/main/java/org/sopt/official/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ import javax.inject.Inject

@HiltAndroidApp
class App : Application() {
@Inject
lateinit var dataStore: SoptDataStore
private val lifecycleOwner: LifecycleOwner
get() = ProcessLifecycleOwner.get()
@Inject
lateinit var dataStore: SoptDataStore
private val lifecycleOwner: LifecycleOwner
get() = ProcessLifecycleOwner.get()

override fun onCreate() {
super.onCreate()
appContext = this.applicationContext
override fun onCreate() {
super.onCreate()
appContext = this.applicationContext

initFlipper()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
runCatching {
FirebaseMessaging.getInstance().token.await()
}.onSuccess {
dataStore.pushToken = it
}.onFailure(Timber::e)
}
initFlipper()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
runCatching {
FirebaseMessaging.getInstance().token.await()
}.onSuccess {
dataStore.pushToken = it
}.onFailure(Timber::e)
}
}
}
}

private fun initFlipper() {
FlipperInitializer.init(this)
}
private fun initFlipper() {
FlipperInitializer.init(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10996,8 +10996,6 @@ PLandroidx/profileinstaller/ProfileVerifier;->setCompilationStatus(IZZZ)Landroid
PLandroidx/profileinstaller/ProfileVerifier;->writeProfileVerification(Landroid/content/Context;Z)Landroidx/profileinstaller/ProfileVerifier$CompilationStatus;
PLandroidx/profileinstaller/ProfileVerifier$Api33Impl;->getPackageInfo(Landroid/content/pm/PackageManager;Landroid/content/Context;)Landroid/content/pm/PackageInfo;
PLandroidx/profileinstaller/ProfileVerifier$Cache;-><init>(IIJJ)V
PLandroidx/profileinstaller/ProfileVerifier$Cache;->equals(Ljava/lang/Object;)Z
PLandroidx/profileinstaller/ProfileVerifier$Cache;->readFromFile(Ljava/io/File;)Landroidx/profileinstaller/ProfileVerifier$Cache;
PLandroidx/profileinstaller/ProfileVerifier$Cache;->writeOnFile(Ljava/io/File;)V
PLandroidx/profileinstaller/ProfileVerifier$CompilationStatus;-><init>(IZZZ)V
Landroidx/savedstate/R$id;
Expand Down
2 changes: 0 additions & 2 deletions app/src/release/generated/baselineProfiles/startup-prof.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10996,8 +10996,6 @@ PLandroidx/profileinstaller/ProfileVerifier;->setCompilationStatus(IZZZ)Landroid
PLandroidx/profileinstaller/ProfileVerifier;->writeProfileVerification(Landroid/content/Context;Z)Landroidx/profileinstaller/ProfileVerifier$CompilationStatus;
PLandroidx/profileinstaller/ProfileVerifier$Api33Impl;->getPackageInfo(Landroid/content/pm/PackageManager;Landroid/content/Context;)Landroid/content/pm/PackageInfo;
PLandroidx/profileinstaller/ProfileVerifier$Cache;-><init>(IIJJ)V
PLandroidx/profileinstaller/ProfileVerifier$Cache;->equals(Ljava/lang/Object;)Z
PLandroidx/profileinstaller/ProfileVerifier$Cache;->readFromFile(Ljava/io/File;)Landroidx/profileinstaller/ProfileVerifier$Cache;
PLandroidx/profileinstaller/ProfileVerifier$Cache;->writeOnFile(Ljava/io/File;)V
PLandroidx/profileinstaller/ProfileVerifier$CompilationStatus;-><init>(IZZZ)V
Landroidx/savedstate/R$id;
Expand Down
1 change: 1 addition & 0 deletions core/webview/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ dependencies {
implementation(libs.material)
implementation(libs.constraintlayout)
implementation(libs.swipe.refresh.layout)
implementation(libs.mozilla.component.utils)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,28 @@
package org.sopt.official.webview.view

import android.app.Activity
import android.app.DownloadManager
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.webkit.CookieManager
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebView
import androidx.activity.addCallback
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import com.airbnb.deeplinkdispatch.DeepLink
import dagger.hilt.android.AndroidEntryPoint
import mozilla.components.support.utils.DownloadUtils
import org.sopt.official.common.util.viewBinding
import org.sopt.official.common.view.toast
import org.sopt.official.webview.databinding.ActivityWebViewBinding
import java.net.URLDecoder

@AndroidEntryPoint
@DeepLink("sopt://web")
Expand All @@ -55,6 +63,13 @@ class WebViewActivity : AppCompatActivity() {
filePathCallback = null
}
}
private val permissionRequestLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted ->
if (!isGranted) {
toast("권한을 받아오지 못했습니다.")
}
}
Comment on lines +66 to +72
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 홈에서 알림 권한 얻어올 때도 쓰던데 따로 분리할 수 있을까요?


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -75,6 +90,37 @@ class WebViewActivity : AppCompatActivity() {
return true
}
}
binding.webView.setDownloadListener { url, userAgent, contentDisposition, mimetype, _ ->
if (ContextCompat.checkSelfPermission(
this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
) == android.content.pm.PackageManager.PERMISSION_GRANTED
Comment on lines +93 to +97
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 부분 아래 함수들(~handle)과 달리 따로 함수화하지 않은 이유가 있으실까요?

) {
val fileName = DownloadUtils.guessFileName(
contentDisposition = URLDecoder.decode(contentDisposition, "utf-8"),
null,
url = url,
mimeType = mimetype
)
val downloadManager = getSystemService<DownloadManager>() ?: return@setDownloadListener
val request = DownloadManager.Request(Uri.parse(url))
.setMimeType(mimetype)
.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url))
.addRequestHeader("User-Agent", userAgent)
.setTitle(fileName)
.apply {
allowScanningByMediaScanner()
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
fileName
)
}
downloadManager.enqueue(request)
} else {
permissionRequestLauncher.launch(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
}
}
Comment on lines +119 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 특정 횟수(아마 3회) 이상 요청하면 더이상 팝업 안뜨는걸로 아는데 그거 관련 로직 추가하는건 어떨까요??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 제 기기에서 테스트가 안되는데 ㅋㅋㅋ 어카죠..

handleLinkUrl()
handleOnBackPressed()
handleOnPullToRefresh()
Expand Down
30 changes: 16 additions & 14 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ coil = "2.7.0"
lottie = "6.6.2"
dotsindicator = "5.1.0"
deepLinkDispatch = "6.2.2"
mozilla-component-utils = "107.0.3"

google-services = "4.4.2"
crashlytics = "3.0.2"
Expand Down Expand Up @@ -183,23 +184,24 @@ profileinstaller = { group = "androidx.profileinstaller", name = "profileinstall
dotsindicator = { module = "com.tbuonomo:dotsindicator", version.ref = "dotsindicator" }
deeplink-dispatch = { group = "com.airbnb", name = "deeplinkdispatch", version.ref = "deepLinkDispatch" }
deeplink-dispatch-processor = { group = "com.airbnb", name = "deeplinkdispatch-processor", version.ref = "deepLinkDispatch" }
mozilla-component-utils = { module = "org.mozilla.components:support-utils", version.ref = "mozilla-component-utils" }

[bundles]
compose = [
"compose-ui",
"compose-foundation",
"compose-ui-tooling",
"compose-activity",
"compose-animation",
"compose-viewmodel",
"compose-material",
"compose-material-three",
"compose-material-icons-extended",
"compose-material-icons",
"compose-runtime",
"compose-ui-tooling-preview",
"compose-hilt-navigation",
"compose-lottie",
"compose-ui",
"compose-foundation",
"compose-ui-tooling",
"compose-activity",
"compose-animation",
"compose-viewmodel",
"compose-material",
"compose-material-three",
"compose-material-icons-extended",
"compose-material-icons",
"compose-runtime",
"compose-ui-tooling-preview",
"compose-hilt-navigation",
"compose-lottie",
]
compose-test = ["compose-junit"]
compose-android-test = ["compose-ui-test"]
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencyResolutionManagement {
mavenCentral()
gradlePluginPortal()
maven { setUrl("https://jitpack.io") }
maven { setUrl("https://maven.mozilla.org/maven2") }
}
}
rootProject.name = "SOPT"
Expand Down
Loading