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

[feat] WebViewActivity 구현 #34

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
android:theme="@style/Theme.Pingle"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".presentation.ui.common.WebViewActivity"
android:exported="false"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".presentation.ui.onboarding.OnBoardingActivity"
android:exported="false"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />

<activity
android:name=".presentation.ui.dummy.DummyActivity"
android:exported="true"
Expand All @@ -33,19 +37,16 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".presentation.ui.dummy.DummyCustomDEditTextActivity"
android:exported="false"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />

<activity
android:name=".presentation.ui.main.MainActivity"
android:exported="false"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />

<activity
android:name=".presentation.ui.main.plan.PlanActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.sopt.pingle.presentation.ui.common

import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.WebChromeClient
import android.webkit.WebViewClient
import org.sopt.pingle.R
import org.sopt.pingle.databinding.ActivityWebViewBinding
import org.sopt.pingle.util.base.BindingActivity

class WebViewActivity : BindingActivity<ActivityWebViewBinding>(R.layout.activity_web_view) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initLayout()
loadWebView()
}

@SuppressLint("SetJavaScriptEnabled")
private fun initLayout() {
binding.wvWebView.apply {
webViewClient = WebViewClient()
Copy link
Collaborator

Choose a reason for hiding this comment

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

우와 신기해......... 웹뷰는 이런 식으로 연결하는 거군요 존재부터 사용방법까지 하나도 몰랐던 거라 넘 신기하구..

Copy link
Collaborator

Choose a reason for hiding this comment

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

이것만이 정답은 아니고 웹뷰를 띄우는 방법은 여러가지가 있습니다 ~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

마자요 intent의 ACTION_VIEW를 사용할 수도 있구 다른 방법이 많답니당!

webChromeClient = WebChromeClient()

settings.apply {
javaScriptEnabled = true
javaScriptCanOpenWindowsAutomatically = true
loadWithOverviewMode = true
useWideViewPort = true
domStorageEnabled = true
}
}
}

private fun loadWebView() {
intent.getStringExtra(WEB_VIEW_LINK)?.let { binding.wvWebView.loadUrl(it) }
}

companion object {
const val WEB_VIEW_LINK = "WebViewLink"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package org.sopt.pingle.util.context

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import org.sopt.pingle.presentation.ui.common.WebViewActivity
import org.sopt.pingle.presentation.ui.common.WebViewActivity.Companion.WEB_VIEW_LINK

fun Context.showToast(message: String, isShort: Boolean = true) {
val duration = if (isShort) Toast.LENGTH_SHORT else Toast.LENGTH_LONG
Expand All @@ -25,3 +28,7 @@ fun Context.stringOf(@StringRes resId: Int) = getString(resId)
fun Context.colorOf(@ColorRes resId: Int) = ContextCompat.getColor(this, resId)

fun Context.drawableOf(@DrawableRes resId: Int) = ContextCompat.getDrawable(this, resId)

fun Context.navigateToWebView(link: String) = Intent(this, WebViewActivity::class.java).apply {
putExtra(WEB_VIEW_LINK, link)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.sopt.pingle.util.fragment

import android.content.Intent
import android.widget.Toast
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import org.sopt.pingle.presentation.ui.common.WebViewActivity

fun Fragment.showToast(message: String, isShort: Boolean = true) {
val duration = if (isShort) Toast.LENGTH_SHORT else Toast.LENGTH_LONG
Expand All @@ -18,3 +20,8 @@ fun Fragment.colorOf(@ColorRes resId: Int) = ContextCompat.getColor(requireConte

fun Fragment.drawableOf(@DrawableRes resId: Int) =
ContextCompat.getDrawable(requireContext(), resId)

fun Fragment.navigateToWebView(link: String) =
Intent(requireContext(), WebViewActivity::class.java).apply {
putExtra(WebViewActivity.WEB_VIEW_LINK, link)
}
25 changes: 25 additions & 0 deletions app/src/main/res/layout/activity_web_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.ui.common.WebViewActivity">

<WebView
android:id="@+id/wv_web_view"
android:layout_width="0dp"
Copy link
Collaborator

Choose a reason for hiding this comment

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

0dp의 신

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading