- Removal of kotlin synthetics

- Upgrade gradle to 8.0.0
 - Change dependency versioning
This commit is contained in:
2024-06-24 18:30:31 +01:00
parent b63caaa9cd
commit 2561b6ddf9
22 changed files with 270 additions and 166 deletions

View File

@@ -1,7 +1,6 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs'
}
@@ -13,14 +12,12 @@ def relKeyAlias = System.getenv("RELEASE_KEY_ALIAS")
def keystorePath = System.getenv('PWD') + "/app/keystore.jks"
def keystore = file(keystorePath).exists() ? file(keystorePath) : null
android {
lintOptions {
abortOnError false
}
namespace 'com.appttude.h_mal.atlas_weather'
compileSdk 33
defaultConfig {
applicationId "com.appttude.h_mal.atlas_weather"
compileSdk 33
minSdkVersion 26
targetSdkVersion 33
minSdkVersion MIN_SDK_VERSION
targetSdkVersion TARGET_SDK_VERSION
versionCode 5
versionName "3.0"
testInstrumentationRunner "com.appttude.h_mal.atlas_weather.application.TestRunner"
@@ -78,7 +75,7 @@ android {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += [
'-Xjvm-default=enable'
'-Xjvm-default=all-compatibility'
]
}
@@ -91,7 +88,6 @@ android {
}
monoWeather {
applicationId "com.appttude.h_mal.monoWeather"
versionCode 7
versionName "4.2.0"
}
@@ -108,105 +104,90 @@ android {
}
}
}
lint {
abortOnError false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.fragment:fragment:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation "androidx.appcompat:appcompat:$MATERIAL_VERSION"
implementation "com.google.android.material:material:$MATERIAL_VERSION"
implementation "androidx.constraintlayout:constraintlayout:$CONSTR_LAYOUT_VERSION"
implementation "androidx.fragment:fragment:$FRAGMENT_VERSION"
implementation "androidx.legacy:legacy-support-v4:$LEGACY_SUPPORT_VERSION"
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation "com.google.android.gms:play-services-location:21.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.google.android.gms:play-services-location:$GOOGLE_PLAY_SERVICE"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
implementation 'androidx.preference:preference:1.2.1'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES"
implementation "androidx.preference:preference:$PREFERENCES_VERSION"
/ * Unit testing * /
testImplementation 'junit:junit:4.13.2'
androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation "junit:junit:$JUNIT_VERSION"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION"
implementation "org.jetbrains.kotlin:kotlin-test:$KOTLIN_VERSION"
androidTestImplementation "junit:junit:$JUNIT_VERSION"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$KOTLINX_COROUTINES"
/ * Fragment Navigation * /
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation "androidx.navigation:navigation-fragment-ktx:$NAVIGATION_VERSION"
implementation "androidx.navigation:navigation-ui-ktx:$NAVIGATION_VERSION"
/ * android unit testing and espresso * /
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation "androidx.test:core:1.5.0"
/ * Android Espresso * /
def testJunitVersion = "1.1.5"
def testRunnerVersion = "1.5.2"
def espressoVersion = "3.5.1"
androidTestImplementation "androidx.test.ext:junit:$testJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$espressoVersion"
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
androidTestImplementation "androidx.test:runner:$testRunnerVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "org.hamcrest:hamcrest:2.2"
androidTestImplementation "androidx.test:rules:$TEST_KTX_VERSION"
androidTestImplementation 'androidx.test:core:1.5.0'
androidTestImplementation 'androidx.test:monitor:1.6.1'
androidTestImplementation "androidx.test.ext:junit:$TEST_JUNIT_VERSION"
androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION"
androidTestImplementation "androidx.test.espresso:espresso-core:$ESPRESSO_VERSION"
implementation "androidx.test.espresso:espresso-idling-resource:$ESPRESSO_VERSION"
androidTestImplementation "androidx.test:runner:$TEST_RUNNER_VERSION"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$ESPRESSO_VERSION"
androidTestImplementation "androidx.test.espresso:espresso-intents:$ESPRESSO_VERSION"
androidTestImplementation "org.hamcrest:hamcrest:$HAMCREST_VERSION"
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES"
/ * Universal Image loader */
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
/ * mock websever for testing retrofit responses * /
testImplementation "com.squareup.okhttp3:mockwebserver:4.6.0"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
/ * mockito and livedata testing * /
testImplementation 'org.mockito:mockito-inline:2.13.0'
implementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation "org.mockito:mockito-inline:$MOKITO_INLINE_VERSION"
testImplementation "androidx.arch.core:core-testing:$CORE_TEST_VERSION"
testImplementation 'org.mockito:mockito-core:2.19.0'
androidTestImplementation 'org.mockito:mockito-core:2.19.0'
androidTestImplementation "androidx.arch.core:core-testing:$CORE_TEST_VERSION"
/ * MockK * /
def mockk_ver = "1.10.5"
testImplementation "io.mockk:mockk:$mockk_ver"
androidTestImplementation "io.mockk:mockk-android:$mockk_ver"
testImplementation "io.mockk:mockk:$MOCKK_VERSION"
androidTestImplementation "io.mockk:mockk-android:$MOCKK_VERSION"
/ * Retrofit * /
def retrofit_ver = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit_ver"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_ver"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
/ * Shared prefs * /
def prefs_ver = "1.2.0"
implementation "androidx.preference:preference-ktx:$prefs_ver"
/ *Kodein Dependency Injection * /
def kodein_version = "6.2.1"
implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
implementation "org.kodein.di:kodein-di-framework-android-x:$kodein_version"
implementation "androidx.preference:preference-ktx:$PREFERENCES_VERSION"
/ * Kodein Dependency Injection * /
implementation "org.kodein.di:kodein-di-generic-jvm:$KODEIN_VERSION"
implementation "org.kodein.di:kodein-di-framework-android-x:$KODEIN_VERSION"
/ * Room database * /
def room_version = "2.4.3"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
runtimeOnly "androidx.room:room-runtime:$ROOM_VERSION"
kapt "androidx.room:room-compiler:$ROOM_VERSION"
implementation "androidx.room:room-ktx:$ROOM_VERSION"
/ * Picasso * /
implementation 'com.squareup.picasso:picasso:2.71828'
/ * coroutine * /
def coroutine_version = "1.3.9"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$KOTLINX_COROUTINES"
/ * tomtom search * /
def tomtom_version = "2.4771"
implementation "com.tomtom.online:sdk-search:$tomtom_version"
implementation "com.tomtom.online:sdk-maps:2.4807"
implementation "com.tomtom.online:sdk-search:$TOMTOM_VERSION"
implementation "com.tomtom.online:sdk-maps:$TOMTOM_VERSION"
/ * coroutines support for firebase operations * /
def coroutines_google_ver = "1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutines_google_ver"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$KOTLINX_COROUTINES"
/ * Picasso * /
implementation 'com.squareup.picasso:picasso:2.71828'
/ * screenshot library * /
androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
/ * Permissions dispatcher * /
def dispatcher_ver = "4.9.2"
implementation "com.github.permissions-dispatcher:permissionsdispatcher:${dispatcher_ver}"
kapt "com.github.permissions-dispatcher:permissionsdispatcher-processor:${dispatcher_ver}"
implementation "com.github.permissions-dispatcher:permissionsdispatcher:$PERMISSIONS_DISPATCHER"
kapt "com.github.permissions-dispatcher:permissionsdispatcher-processor:$PERMISSIONS_DISPATCHER"
}

View File

@@ -1,6 +1,5 @@
package com.appttude.h_mal.atlas_weather.application
import MonoApp
import androidx.room.Room
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.idling.CountingIdlingResource

View File

@@ -6,11 +6,12 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
import com.appttude.h_mal.atlas_weather.ui.home.adapter.WeatherRecyclerAdapter
import com.appttude.h_mal.atlas_weather.utils.navigateTo
import kotlinx.android.synthetic.main.fragment_home.*
class WorldItemFragment : Fragment() {
@@ -40,7 +41,7 @@ class WorldItemFragment : Fragment() {
param1?.let { recyclerAdapter.addCurrent(it) }
forecast_listview.apply {
view.findViewById<RecyclerView>(R.id.forecast_listview).apply {
layoutManager = LinearLayoutManager(context)
adapter = recyclerAdapter
}

View File

@@ -4,10 +4,11 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.model.forecast.Forecast
import kotlinx.android.synthetic.main.activity_further_info.*
private const val WEATHER = "param1"
@@ -36,14 +37,12 @@ class FurtherInfoFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
maxtemp.text = param1?.mainTemp
averagetemp.text = param1?.averageTemp
minimumtemp.text = param1?.minorTemp
windtext.text = param1?.windText
preciptext.text = param1?.precipitation
humiditytext.text = param1?.humidity
uvtext.text = param1?.uvi
sunrisetext.text = param1?.sunrise
sunsettext.text = param1?.sunset
view.findViewById<TextView>(R.id.maxtemp).text = param1?.mainTemp
view.findViewById<TextView>(R.id.averagetemp).text = param1?.averageTemp
view.findViewById<TextView>(R.id.minimumtemp).text = param1?.minorTemp
view.findViewById<TextView>(R.id.windtext).text = param1?.windText
view.findViewById<TextView>(R.id.preciptext).text = param1?.precipitation
view.findViewById<TextView>(R.id.sunrisetext).text = param1?.sunrise
view.findViewById<TextView>(R.id.sunsettext).text = param1?.sunset
}
}

View File

@@ -12,6 +12,8 @@ import android.view.View
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation.findNavController
import androidx.navigation.ui.onNavDestinationSelected
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.application.AtlasApp
import com.appttude.h_mal.atlas_weather.base.BaseFragment
@@ -22,7 +24,7 @@ import com.appttude.h_mal.atlas_weather.ui.home.adapter.WeatherRecyclerAdapter
import com.appttude.h_mal.atlas_weather.utils.displayToast
import com.appttude.h_mal.atlas_weather.utils.navigateTo
import com.appttude.h_mal.atlas_weather.viewmodel.MainViewModel
import kotlinx.android.synthetic.main.fragment_home.*
import permissions.dispatcher.NeedsPermission
import permissions.dispatcher.OnNeverAskAgain
import permissions.dispatcher.OnPermissionDenied
@@ -38,14 +40,15 @@ import permissions.dispatcher.RuntimePermissions
@RuntimePermissions
class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
lateinit var recyclerAdapter: WeatherRecyclerAdapter
private lateinit var recyclerAdapter: WeatherRecyclerAdapter
private lateinit var swipeRefresh: SwipeRefreshLayout
@SuppressLint("MissingPermission")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setHasOptionsMenu(true)
swipe_refresh.apply {
swipeRefresh = view.findViewById<SwipeRefreshLayout>(R.id.swipe_refresh).apply {
setOnRefreshListener {
showLocationWithPermissionCheck()
isRefreshing = true
@@ -56,7 +59,7 @@ class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
navigateToFurtherDetails(it)
})
forecast_listview.adapter = recyclerAdapter
view.findViewById<RecyclerView>(R.id.forecast_listview).adapter = recyclerAdapter
scheduleNotification()
}
@@ -69,7 +72,7 @@ class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
override fun onSuccess(data: Any?) {
super.onSuccess(data)
swipe_refresh.isRefreshing = false
swipeRefresh.isRefreshing = false
if (data is WeatherDisplay) {
recyclerAdapter.addCurrent(data)
@@ -78,7 +81,7 @@ class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
override fun onFailure(error: Any?) {
super.onFailure(error)
swipe_refresh.isRefreshing = false
swipeRefresh.isRefreshing = false
}
private fun navigateToFurtherDetails(forecast: Forecast) {
@@ -96,6 +99,7 @@ class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
return item.onNavDestinationSelected(navController) || super.onOptionsItemSelected(item)
}
@Deprecated("Deprecated in Java")
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
// NOTE: delegate the permission handling to generated method

View File

@@ -2,13 +2,13 @@ package com.appttude.h_mal.atlas_weather.ui.world
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.base.BaseFragment
import com.appttude.h_mal.atlas_weather.utils.displayToast
import com.appttude.h_mal.atlas_weather.utils.goBack
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
import kotlinx.android.synthetic.main.activity_add_forecast.location_name_tv
import kotlinx.android.synthetic.main.activity_add_forecast.submit
class AddLocationFragment : BaseFragment<WorldViewModel>(R.layout.activity_add_forecast) {
@@ -16,8 +16,11 @@ class AddLocationFragment : BaseFragment<WorldViewModel>(R.layout.activity_add_f
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val submit = view.findViewById<Button>(R.id.submit)
submit.setOnClickListener {
val locationName = location_name_tv.text?.trim()?.toString()
val locationName =
view.findViewById<TextView>(R.id.location_name_tv).text?.trim()?.toString()
if (locationName.isNullOrBlank()) {
submit.error = "Location cannot be blank"
return@setOnClickListener

View File

@@ -4,13 +4,13 @@ import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.base.BaseFragment
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
import com.appttude.h_mal.atlas_weather.utils.navigateTo
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
import kotlinx.android.synthetic.atlasWeather.fragment_add_location.floatingActionButton
import kotlinx.android.synthetic.atlasWeather.fragment_add_location.world_recycler
import com.google.android.material.floatingactionbutton.FloatingActionButton
/**
@@ -29,12 +29,12 @@ class WorldFragment : BaseFragment<WorldViewModel>(R.layout.fragment_add_locatio
navigateTo(direction)
}
world_recycler.apply {
view.findViewById<RecyclerView>(R.id.world_recycler).apply {
layoutManager = LinearLayoutManager(context)
adapter = recyclerAdapter
}
floatingActionButton.setOnClickListener {
view.findViewById<FloatingActionButton>(R.id.floatingActionButton).setOnClickListener {
navigateTo(R.id.action_worldFragment_to_addLocationFragment)
}
}

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.appttude.h_mal.atlas_weather">
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

View File

@@ -77,6 +77,7 @@ abstract class BaseActivity : AppCompatActivity(), KodeinAware {
}
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
loadingView?.hide()
super.onBackPressed()

View File

@@ -10,7 +10,7 @@ import androidx.navigation.ui.setupWithNavController
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.base.BaseActivity
import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.android.synthetic.main.activity_main_navigation.toolbar
class MainActivity : BaseActivity() {
@@ -21,7 +21,7 @@ class MainActivity : BaseActivity() {
setContentView(R.layout.activity_main_navigation)
val navView: BottomNavigationView = findViewById(R.id.nav_view)
setSupportActionBar(toolbar)
setSupportActionBar(findViewById(R.id.toolbar))
navHost = supportFragmentManager
.findFragmentById(R.id.container) as NavHostFragment

View File

@@ -2,6 +2,7 @@ package com.appttude.h_mal.atlas_weather.utils
import android.app.Activity
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -11,7 +12,12 @@ import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.Toast
import androidx.annotation.AnimRes
import androidx.annotation.IdRes
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.recyclerview.widget.RecyclerView
import com.appttude.h_mal.atlas_weather.R
import com.squareup.picasso.Picasso
@@ -55,4 +61,63 @@ fun View.triggerAnimation(@AnimRes id: Int, complete: (View) -> Unit) {
override fun onAnimationRepeat(a: Animation?) {}
})
startAnimation(animation)
}
class BindViewDelegate<T>(
private val createView: () -> T,
private val getLifecycle: () -> Lifecycle
) : Lazy<T>, LifecycleObserver {
private var view: T? = null
private val lifecycle: Lifecycle?
get() = try {
getLifecycle()
} catch (e: IllegalStateException) {
e.message?.let { Log.e("BindViewDelegate", it) }
null
}
override val value: T
get() {
if (view == null) {
lifecycle?.removeObserver(this)
view = createView()
lifecycle?.addObserver(this)
}
@Suppress("UNCHECKED_CAST")
return view as T
}
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() {
reset()
}
private fun reset() {
lifecycle?.removeObserver(this)
view = null
}
override fun isInitialized(): Boolean = view != null
}
fun <T : View> Fragment.bindView(@IdRes resource: Int): Lazy<T> = BindViewDelegate(
createView = { requireView().findViewById<T>(resource) },
getLifecycle = { viewLifecycleOwner.lifecycle }
)
fun <T : View> Activity.bindView(@IdRes res: Int): Lazy<T> {
@Suppress("UNCHECKED_CAST")
return lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(res) }
}
fun <T : View> View.bindView(@IdRes res: Int): Lazy<T> {
@Suppress("UNCHECKED_CAST")
return lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(res) }
}
fun <T : View> RecyclerView.ViewHolder.bindView(@IdRes res: Int): Lazy<T> {
@Suppress("UNCHECKED_CAST")
return lazy(LazyThreadSafetyMode.NONE) { itemView.findViewById<T>(res) }
}

View File

@@ -1,9 +1,8 @@
import com.appttude.h_mal.atlas_weather.application.AppClass
import com.appttude.h_mal.atlas_weather.application.ApplicationViewModelFactory
package com.appttude.h_mal.atlas_weather.application
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.provider
import org.kodein.di.generic.singleton
open class MonoApp : AppClass() {

View File

@@ -4,14 +4,16 @@ package com.appttude.h_mal.monoWeather.ui
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
import com.appttude.h_mal.atlas_weather.base.BaseFragment
import com.appttude.h_mal.atlas_weather.utils.navigateTo
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
import com.appttude.h_mal.monoWeather.ui.home.adapter.WeatherRecyclerAdapter
import kotlinx.android.synthetic.main.fragment_home.forecast_listview
import kotlinx.android.synthetic.main.fragment_home.swipe_refresh
class WorldItemFragment : BaseFragment<WorldViewModel>(R.layout.fragment_home) {
@@ -19,6 +21,7 @@ class WorldItemFragment : BaseFragment<WorldViewModel>(R.layout.fragment_home) {
private var retrievedLocationName: String? = null
private lateinit var recyclerAdapter: WeatherRecyclerAdapter
private lateinit var swipeRefresh: SwipeRefreshLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -35,12 +38,12 @@ class WorldItemFragment : BaseFragment<WorldViewModel>(R.layout.fragment_home) {
navigateTo(directions)
}
forecast_listview.apply {
view.findViewById<RecyclerView>(R.id.forecast_listview).apply {
layoutManager = LinearLayoutManager(context)
adapter = recyclerAdapter
}
swipe_refresh.apply {
swipeRefresh = view.findViewById<SwipeRefreshLayout>(R.id.swipe_refresh).apply {
setOnRefreshListener {
retrievedLocationName?.let {
viewModel.fetchDataForSingleLocation(it)
@@ -57,11 +60,11 @@ class WorldItemFragment : BaseFragment<WorldViewModel>(R.layout.fragment_home) {
recyclerAdapter.addCurrent(data)
}
super.onSuccess(data)
swipe_refresh.isRefreshing = false
swipeRefresh.isRefreshing = false
}
override fun onFailure(error: Any?) {
super.onFailure(error)
swipe_refresh.isRefreshing = false
swipeRefresh.isRefreshing = false
}
}

View File

@@ -5,9 +5,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import android.widget.TextView
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.model.forecast.Forecast
import kotlinx.android.synthetic.main.activity_further_info.*
/**
@@ -34,18 +34,18 @@ class FurtherInfoFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
maxtemp.text = param1?.mainTemp.appendWith(requireContext().getString(R.string.degrees))
averagetemp.text =
view.findViewById<TextView>(R.id.maxtemp).text = param1?.mainTemp.appendWith(requireContext().getString(R.string.degrees))
view.findViewById<TextView>(R.id.averagetemp).text =
param1?.averageTemp.appendWith(requireContext().getString(R.string.degrees))
minimumtemp.text =
view.findViewById<TextView>(R.id.minimumtemp).text =
param1?.minorTemp.appendWith(requireContext().getString(R.string.degrees))
windtext.text = param1?.windText.appendWith(" km")
preciptext.text = param1?.precipitation.appendWith(" %")
cloudtext.text = param1?.cloud.appendWith(" %")
humiditytext.text = param1?.humidity.appendWith(" %")
uvtext.text = param1?.uvi
sunrisetext.text = param1?.sunrise
sunsettext.text = param1?.sunset
view.findViewById<TextView>(R.id.windtext).text = param1?.windText.appendWith(" km")
view.findViewById<TextView>(R.id.preciptext).text = param1?.precipitation.appendWith(" %")
view.findViewById<TextView>(R.id.cloudtext).text = param1?.cloud.appendWith(" %")
view.findViewById<TextView>(R.id.humiditytext).text = param1?.humidity.appendWith(" %")
view.findViewById<TextView>(R.id.uvtext).text = param1?.uvi
view.findViewById<TextView>(R.id.sunrisetext).text = param1?.sunrise
view.findViewById<TextView>(R.id.sunsettext).text = param1?.sunset
}
fun String?.appendWith(suffix: String): String? {

View File

@@ -10,6 +10,8 @@ import android.view.View
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation.findNavController
import androidx.navigation.ui.onNavDestinationSelected
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.base.BaseFragment
import com.appttude.h_mal.atlas_weather.model.forecast.Forecast
@@ -19,7 +21,7 @@ import com.appttude.h_mal.atlas_weather.utils.navigateTo
import com.appttude.h_mal.atlas_weather.viewmodel.MainViewModel
import com.appttude.h_mal.monoWeather.dialog.PermissionsDeclarationDialog
import com.appttude.h_mal.monoWeather.ui.home.adapter.WeatherRecyclerAdapter
import kotlinx.android.synthetic.main.fragment_home.*
import permissions.dispatcher.NeedsPermission
import permissions.dispatcher.OnNeverAskAgain
import permissions.dispatcher.OnPermissionDenied
@@ -36,13 +38,14 @@ import permissions.dispatcher.RuntimePermissions
class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
lateinit var recyclerAdapter: WeatherRecyclerAdapter
lateinit var swipeRefresh: SwipeRefreshLayout
@SuppressLint("MissingPermission")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setHasOptionsMenu(true)
swipe_refresh.apply {
swipeRefresh = view.findViewById<SwipeRefreshLayout>(R.id.swipe_refresh).apply {
setOnRefreshListener {
showLocationWithPermissionCheck()
isRefreshing = true
@@ -53,7 +56,7 @@ class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
navigateToFurtherDetails(it)
})
forecast_listview.adapter = recyclerAdapter
view.findViewById<RecyclerView>(R.id.forecast_listview).adapter = recyclerAdapter
}
@SuppressLint("MissingPermission")
@@ -64,7 +67,7 @@ class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
override fun onSuccess(data: Any?) {
super.onSuccess(data)
swipe_refresh.isRefreshing = false
swipeRefresh.isRefreshing = false
if (data is WeatherDisplay) {
recyclerAdapter.addCurrent(data)
@@ -73,7 +76,7 @@ class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
override fun onFailure(error: Any?) {
super.onFailure(error)
swipe_refresh.isRefreshing = false
swipeRefresh.isRefreshing = false
}
private fun navigateToFurtherDetails(forecast: Forecast) {

View File

@@ -4,10 +4,12 @@ import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.utils.generateView
import kotlinx.android.synthetic.monoWeather.mono_item_two_cell.view.mono_item_cell
import kotlinx.android.synthetic.monoWeather.mono_item_two_cell.view.mono_text_cell
class GridAdapter(
@@ -20,8 +22,8 @@ class GridAdapter(
val item = getItem(position)
return view.apply {
mono_item_cell.setImageResource(item!!.first)
mono_text_cell.text = item.second
findViewById<ImageView>(R.id.mono_item_cell).setImageResource(item!!.first)
findViewById<TextView>(R.id.mono_text_cell).text = item.second
}
}
}

View File

@@ -11,6 +11,7 @@ import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.widget.Button
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
@@ -18,8 +19,8 @@ import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.utils.displayToast
import com.appttude.h_mal.monoWeather.dialog.DeclarationBuilder
import com.appttude.h_mal.monoWeather.dialog.PermissionsDeclarationDialog
import kotlinx.android.synthetic.monoWeather.permissions_declaration_dialog.cancel
import kotlinx.android.synthetic.monoWeather.permissions_declaration_dialog.submit
import permissions.dispatcher.NeedsPermission
import permissions.dispatcher.OnNeverAskAgain
import permissions.dispatcher.OnPermissionDenied
@@ -60,7 +61,7 @@ class WidgetLocationPermissionActivity : AppCompatActivity(), DeclarationBuilder
movementMethod = LinkMovementMethod.getInstance()
}
submit.setOnClickListener {
findViewById<Button>(R.id.submit).setOnClickListener {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
showBackgroundLocationWithPermissionCheck()
} else {
@@ -68,7 +69,7 @@ class WidgetLocationPermissionActivity : AppCompatActivity(), DeclarationBuilder
}
}
cancel.setOnClickListener { finish() }
findViewById<Button>(R.id.cancel).setOnClickListener { finish() }
}
private fun submitWidget() {

View File

@@ -2,14 +2,16 @@ package com.appttude.h_mal.monoWeather.ui.world
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.base.BaseFragment
import com.appttude.h_mal.atlas_weather.utils.displayToast
import com.appttude.h_mal.atlas_weather.utils.goBack
import com.appttude.h_mal.atlas_weather.utils.hideKeyboard
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
import kotlinx.android.synthetic.main.activity_add_forecast.location_name_tv
import kotlinx.android.synthetic.main.activity_add_forecast.submit
class AddLocationFragment : BaseFragment<WorldViewModel>(R.layout.activity_add_forecast) {
@@ -17,10 +19,11 @@ class AddLocationFragment : BaseFragment<WorldViewModel>(R.layout.activity_add_f
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
submit.setOnClickListener {
val locationName = location_name_tv.text?.trim()?.toString()
view.findViewById<Button>(R.id.submit).setOnClickListener {
val locationNameView = view.findViewById<TextView>(R.id.location_name_tv)
val locationName = locationNameView.text?.trim()?.toString()
if (locationName.isNullOrBlank()) {
location_name_tv.error = "Location cannot be blank"
locationNameView.error = "Location cannot be blank"
return@setOnClickListener
}
viewModel.fetchDataForSingleLocationSearch(locationName)

View File

@@ -2,17 +2,18 @@ package com.appttude.h_mal.monoWeather.ui.world
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.appttude.h_mal.atlas_weather.R
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
import com.appttude.h_mal.atlas_weather.base.BaseFragment
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
import com.appttude.h_mal.atlas_weather.utils.navigateTo
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
import com.appttude.h_mal.monoWeather.ui.world.WorldFragmentDirections.actionWorldFragmentToWorldItemFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.monoWeather.fragment__two.floatingActionButton
import kotlinx.android.synthetic.monoWeather.fragment__two.world_recycler
import com.google.android.material.floatingactionbutton.FloatingActionButton
/**
@@ -47,12 +48,12 @@ class WorldFragment : BaseFragment<WorldViewModel>(R.layout.fragment__two) {
.show()
}
world_recycler.apply {
view.findViewById<RecyclerView>(R.id.world_recycler).apply {
layoutManager = LinearLayoutManager(context)
adapter = recyclerAdapter
}
floatingActionButton.setOnClickListener {
view.findViewById<FloatingActionButton>(R.id.floatingActionButton).setOnClickListener {
navigateTo(R.id.action_worldFragment_to_addLocationFragment)
}

View File

@@ -1,24 +1,21 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = '1.5.20'
}
repositories {
maven { url "https://www.jitpack.io" }
}
dependencies {
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.4.1")
classpath ('com.android.tools.build:gradle:7.2.2')
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20")
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$NAVIGATION_VERSION"
classpath "com.android.tools.build:gradle:$GRADLE_PLUGIN_VERSION"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_GRADLE_PLUGIN"
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'com.google.gms.google-services' version '4.3.15' apply false
id 'androidx.navigation.safeargs.kotlin' version '2.4.0' apply false
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
id 'com.android.application' version "$ANDROID_APPLICATION" apply false
id 'com.android.library' version "$ANDROID_LIBRARY" apply false
id 'com.google.gms.google-services' version "$GOOGLE_SERVICES" apply false
id 'org.jetbrains.kotlin.android' version "$KOTLIN_VERSION" apply false
id 'com.autonomousapps.dependency-analysis' version "$GRADLE_ANALYZE_VERSION"
}
task clean(type: Delete) {

View File

@@ -9,11 +9,54 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
# When configured, Gradle will run in incubating parallel mode.
# 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
# Plugin versions
LEGACY_SUPPORT_VERSION = 1.0.0
FRAGMENT_VERSION = 1.4.0
MATERIAL_VERSION = 1.0.0
CONSTR_LAYOUT_VERSION = 1.1.3
PERMISSIONS_DISPATCHER = 4.9.2
TOMTOM_VERSION = 2.4771
NAVIGATION_VERSION = 2.5.0
PREFERENCES_VERSION = 1.2.1
MOKITO_INLINE_VERSION = 2.13.0
CORE_TEST_VERSION = 2.1.0
MOCKK_VERSION = 1.10.5
TEST_JUNIT_VERSION = 1.1.5
TEST_RUNNER_VERSION = 1.5.2
ESPRESSO_VERSION = 3.5.1
HAMCREST_VERSION = 2.2
JUNIT_VERSION = 4.13.2
KODEIN_VERSION = 6.2.1
ROOM_VERSION = 2.4.3
KOTLINX_COROUTINES = 1.6.1
TEST_KTX_VERSION = 1.4.0
GOOGLE_PLAY_SERVICE = 21.3.0
GOOGLE_SERVICES = 4.3.15
ANDROID_LIBRARY = 8.0.0
ANDROID_APPLICATION = 8.0.0
GRADLE_PLUGIN_VERSION = 8.0.0
KOTLIN_VERSION = 1.9.0
KOTLIN_GRADLE_PLUGIN = 1.6.21
GRADLE_ANALYZE_VERSION = 1.20.0
# Android configuration
TARGET_SDK_VERSION = 33
MIN_SDK_VERSION = 26
# Gradle parameters
org.gradle.jvmargs = -Xmx1536m
# AndroidX
android.useAndroidX = true
android.enableJetifier = true

View File

@@ -1,6 +1,6 @@
#Wed Jul 26 10:14:37 BST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists