From d606717808ae3b30004cbfc3b9d1c25dc0cb6421 Mon Sep 17 00:00:00 2001 From: hmalik144 Date: Fri, 10 Jun 2022 00:35:31 +0100 Subject: [PATCH] - Dialog changes added - updated properties retrieval Took 13 minutes --- app/build.gradle | 4 ++-- .../dialog/PermissionsDeclarationDialog.kt | 6 +++++- .../atlas_weather/monoWeather/ui/home/HomeFragment.kt | 11 ++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 40d404b..6d282ab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,8 +26,8 @@ android { buildConfigField "String", "ParamOne", properties.getProperty('WEATHER_API') buildConfigField "String", "ParamTwo", properties.getProperty('SEARCH_API') } else { - buildConfigField "String", "ParamOne", "${WEATHER_API}" - buildConfigField "String", "ParamTwo", "${SEARCH_API}" + buildConfigField "String", "ParamOne", properties.getProperty('WEATHER_API') + buildConfigField "String", "ParamTwo", properties.getProperty('SEARCH_API') } } android { diff --git a/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/dialog/PermissionsDeclarationDialog.kt b/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/dialog/PermissionsDeclarationDialog.kt index 9302dec..e7eeec7 100644 --- a/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/dialog/PermissionsDeclarationDialog.kt +++ b/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/dialog/PermissionsDeclarationDialog.kt @@ -20,7 +20,9 @@ abstract class BaseDeclarationDialog(val context: Context): DeclarationBuilder { abstract override val link: String abstract override val message: String - fun showDialog(agreeCallback: () -> Unit = { }, disagreeCallback: () -> Unit = { Unit }) { + lateinit var dialog: AlertDialog + + fun showDialog(agreeCallback: () -> Unit = { }, disagreeCallback: () -> Unit = { }) { val myMessage = buildMessage() val builder = AlertDialog.Builder(context) @@ -40,5 +42,7 @@ abstract class BaseDeclarationDialog(val context: Context): DeclarationBuilder { val msgTxt = alertDialog.findViewById(android.R.id.message) as TextView? msgTxt?.movementMethod = LinkMovementMethod.getInstance() } + + fun dismiss() = dialog.dismiss() } diff --git a/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/HomeFragment.kt b/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/HomeFragment.kt index a3f09af..fb94923 100644 --- a/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/HomeFragment.kt +++ b/app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/HomeFragment.kt @@ -30,6 +30,8 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { private val viewModel by getFragmentViewModel() + lateinit var dialog: PermissionsDeclarationDialog + @SuppressLint("MissingPermission") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -40,7 +42,9 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { forecast_listview.adapter = recyclerAdapter - PermissionsDeclarationDialog(requireContext()).showDialog(agreeCallback = { + + dialog = PermissionsDeclarationDialog(requireContext()) + dialog.showDialog(agreeCallback = { getPermissionResult(ACCESS_COARSE_LOCATION, LOCATION_PERMISSION_REQUEST) { viewModel.fetchData() } @@ -64,6 +68,11 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { viewModel.operationRefresh.observe(viewLifecycleOwner, refreshObserver(swipe_refresh)) } + override fun onStop() { + super.onStop() + dialog.dismiss() + } + @SuppressLint("MissingPermission") override fun permissionsGranted() { viewModel.fetchData()