diff --git a/app/build.gradle b/app/build.gradle index 1284a4c..f7907eb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,8 +20,15 @@ android { testInstrumentationRunner "com.appttude.h_mal.atlas_weather.application.TestRunner" vectorDrawables.useSupportLibrary = true - buildConfigField "String", "ParamOne", "${paramOneEndPoint}" - buildConfigField "String", "ParamTwo", "${paramTwoEndPoint}" + Properties properties = new Properties() + if (project.rootProject.file('local.properties').canRead()) { + properties.load(project.rootProject.file('local.properties').newDataInputStream()) + buildConfigField "String", "ParamOne", properties.getProperty('WEATHER_API') + buildConfigField "String", "ParamTwo", properties.getProperty('SEARCH_API') + } else { + buildConfigField "String", "ParamOne", System.getenv('WEATHER_API') + buildConfigField "String", "ParamTwo", System.getenv('SEARCH_API') + } } android { sourceSets{ 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..e00350c 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) @@ -33,12 +35,14 @@ abstract class BaseDeclarationDialog(val context: Context): DeclarationBuilder { .setMessage(myMessage) .setCancelable(false) - val alertDialog = builder.create() - alertDialog.show() + dialog = builder.create() + dialog.show() // Make the textview clickable. Must be called after show() - val msgTxt = alertDialog.findViewById(android.R.id.message) as TextView? + val msgTxt = dialog.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..f3fd1cf 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) @@ -39,12 +41,7 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { }) forecast_listview.adapter = recyclerAdapter - - PermissionsDeclarationDialog(requireContext()).showDialog(agreeCallback = { - getPermissionResult(ACCESS_COARSE_LOCATION, LOCATION_PERMISSION_REQUEST) { - viewModel.fetchData() - } - }) + dialog = PermissionsDeclarationDialog(requireContext()) swipe_refresh.apply { setOnRefreshListener { @@ -64,6 +61,21 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { viewModel.operationRefresh.observe(viewLifecycleOwner, refreshObserver(swipe_refresh)) } + @SuppressLint("MissingPermission") + override fun onStart() { + super.onStart() + dialog.showDialog(agreeCallback = { + getPermissionResult(ACCESS_COARSE_LOCATION, LOCATION_PERMISSION_REQUEST) { + viewModel.fetchData() + } + }) + } + + override fun onStop() { + super.onStop() + dialog.dismiss() + } + @SuppressLint("MissingPermission") override fun permissionsGranted() { viewModel.fetchData() diff --git a/gradle.properties b/gradle.properties index ddd0787..9e6fce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,5 +17,3 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -paramOneEndPoint="ed03070baf705c1185fa40f245bf8cca" -paramTwoEndPoint="WkQ8IlFaKCpn6LfwqpjV2QygC878kSbJ"