Skip to content

Commit

Permalink
Merge pull request #76 from team-JMT/feat/backstack_after_register
Browse files Browse the repository at this point in the history
맛집 등록 후 백스택 정리
  • Loading branch information
dogdduddy authored Sep 23, 2023
2 parents ad81982 + 5f864aa commit a7479da
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.gdsc.presentation.view.restaurantregistration

import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.view.LayoutInflater
Expand Down Expand Up @@ -34,7 +33,6 @@ import org.gdsc.presentation.utils.animateShrinkWidth
import org.gdsc.presentation.utils.checkMediaPermissions
import org.gdsc.presentation.view.MainActivity
import org.gdsc.presentation.view.WEB_BASE_URL
import org.gdsc.presentation.view.WebViewActivity
import org.gdsc.presentation.view.custom.FoodCategoryBottomSheetDialog
import org.gdsc.presentation.view.restaurantregistration.adapter.RegisterRestaurantAdapter
import org.gdsc.presentation.view.restaurantregistration.viewmodel.RegisterRestaurantViewModel
Expand Down Expand Up @@ -224,24 +222,24 @@ class RegisterRestaurantFragment : BaseFragment() {

sUri.toUri()
.getCompressedBitmapFromUri(context)
?.saveBitmapToFile(context, "$index.jpg")?.let { imageFile ->
?.saveBitmapToFile(context, "$index.jpg")?.let { imageFile ->

val requestFile =
RequestBody.create(
MediaType.parse("image/png"),
imageFile
)
val requestFile =
RequestBody.create(
MediaType.parse("image/png"),
imageFile
)

val body =
MultipartBody.Part.createFormData(
"pictures",
imageFile.name,
requestFile
)
val body =
MultipartBody.Part.createFormData(
"pictures",
imageFile.name,
requestFile
)

pictures.add(body)
pictures.add(body)

}
}

}

Expand All @@ -251,15 +249,12 @@ class RegisterRestaurantFragment : BaseFragment() {
navArgs.restaurantLocationInfo ?: throw Exception()
) { restaurantId ->

val intent =
Intent(requireContext(), WebViewActivity::class.java)

// 주소는 변경 되어야 함, 현재는 Lucy LocalHost 테스트
intent.putExtra(
"url",
"${WEB_BASE_URL}detail/$restaurantId"
findNavController().navigate(
RegisterRestaurantFragmentDirections
.actionRegisterRestaurantFragmentToSpecificWebViewFragment(
"${WEB_BASE_URL}detail/$restaurantId"
)
)
startActivity(intent)
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.gdsc.presentation.view.webview

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebViewClient
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.navArgs
import dagger.hilt.android.AndroidEntryPoint
import org.gdsc.domain.Empty
import org.gdsc.presentation.databinding.FragmentSpecificWebViewBinding
import org.gdsc.presentation.utils.repeatWhenUiStarted
import org.gdsc.presentation.view.MainActivity
import org.gdsc.presentation.view.WebAppInterface

@AndroidEntryPoint
class SpecificWebViewFragment : Fragment() {

private var _binding: FragmentSpecificWebViewBinding? = null
private val binding get() = _binding!!

private val viewModel: SpecificWebViewViewModel by viewModels()

private val navArgs by navArgs<SpecificWebViewFragmentArgs>()
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentSpecificWebViewBinding.inflate(inflater, container, false)
return binding.root
}

@SuppressLint("SetJavaScriptEnabled")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val parentActivity = requireActivity() as MainActivity
parentActivity.changeToolbarTitle(String.Empty)
parentActivity.changeToolbarVisible(false)

binding.webView.apply {
loadUrl(navArgs.url)

settings.javaScriptEnabled = true
settings.domStorageEnabled = true
webViewClient = WebViewClient()

addJavascriptInterface(WebAppInterface(
requireContext(),
{
parentActivity.slideUpBottomNavigationView()
},
{
parentActivity.slideDownBottomNavigationView()
},
{
parentActivity.navigateToEditRestaurantInfo(it)
},
{
repeatWhenUiStarted {
binding.webView.loadUrl(
"javascript:setAccessToken(\"${viewModel.getAccessToken()}\")"
)
}
}
), "webviewBridge")
}
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.gdsc.presentation.view.webview

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import org.gdsc.domain.usecase.token.GetAccessTokenUseCase
import javax.inject.Inject

@HiltViewModel
class SpecificWebViewViewModel @Inject constructor(
private val getAccessTokenUseCase: GetAccessTokenUseCase,
) : ViewModel() {

suspend fun getAccessToken() = getAccessTokenUseCase.invoke()
}
15 changes: 15 additions & 0 deletions presentation/src/main/res/layout/fragment_specific_web_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<WebView
android:id="@+id/web_view"
android:layout_width="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>
12 changes: 12 additions & 0 deletions presentation/src/main/res/navigation/main_nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
<action
android:id="@+id/action_registerRestaurantFragment_to_multiImagePickerFragment"
app:destination="@id/multiImagePicker_fragment"/>
<action
android:id="@+id/action_registerRestaurant_fragment_to_specificWebViewFragment"
app:destination="@id/specificWebViewFragment"
app:popUpTo="@id/home_fragment"/>

</fragment>
<fragment
Expand Down Expand Up @@ -135,5 +139,13 @@
tools:layout="@layout/fragment_account_management">

</fragment>
<fragment
android:id="@+id/specificWebViewFragment"
android:name="org.gdsc.presentation.view.webview.SpecificWebViewFragment"
android:label="SpecificWebViewFragment">
<argument
android:name="url"
app:argType="string" />
</fragment>

</navigation>

0 comments on commit a7479da

Please sign in to comment.