mirror of
https://github.com/hmalik144/Weather-apps.git
synced 2025-12-10 02:05:20 +00:00
- Update to test framework
- Adjustments to layouts
This commit is contained in:
@@ -16,7 +16,7 @@ import com.appttude.h_mal.atlas_weather.data.room.AppDatabase
|
|||||||
import com.appttude.h_mal.atlas_weather.data.room.Converter
|
import com.appttude.h_mal.atlas_weather.data.room.Converter
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
|
|
||||||
class TestAppClass : BaseAppClass() {
|
class TestAppClass : AtlasApp() {
|
||||||
private val idlingResources = CountingIdlingResource("Data_loader")
|
private val idlingResources = CountingIdlingResource("Data_loader")
|
||||||
private val mockingNetworkInterceptor = MockingNetworkInterceptor(idlingResources)
|
private val mockingNetworkInterceptor = MockingNetworkInterceptor(idlingResources)
|
||||||
|
|
||||||
@@ -43,7 +43,8 @@ class TestAppClass : BaseAppClass() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun createRoomDatabase(): AppDatabase {
|
override fun createRoomDatabase(): AppDatabase {
|
||||||
database = Room.inMemoryDatabaseBuilder(this, AppDatabase::class.java)
|
database = Room.inMemoryDatabaseBuilder(applicationContext, AppDatabase::class.java)
|
||||||
|
.allowMainThreadQueries()
|
||||||
.addTypeConverter(Converter(this))
|
.addTypeConverter(Converter(this))
|
||||||
.build()
|
.build()
|
||||||
return database
|
return database
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
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
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.location.LocationProvider
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.location.MockLocationProvider
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.network.NetworkModule
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.network.WeatherApi
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.network.interceptors.MockingNetworkInterceptor
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.network.interceptors.NetworkConnectionInterceptor
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.network.interceptors.QueryParamsInterceptor
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.network.networkUtils.loggingInterceptor
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.room.AppDatabase
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.room.Converter
|
||||||
|
import java.io.BufferedReader
|
||||||
|
|
||||||
|
class TestAppClass : MonoApp() {
|
||||||
|
private val idlingResources = CountingIdlingResource("Data_loader")
|
||||||
|
private val mockingNetworkInterceptor = MockingNetworkInterceptor(idlingResources)
|
||||||
|
|
||||||
|
lateinit var database: AppDatabase
|
||||||
|
lateinit var locationProvider: MockLocationProvider
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
IdlingRegistry.getInstance().register(idlingResources)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createNetworkModule(): WeatherApi {
|
||||||
|
return NetworkModule().invoke<WeatherApi>(
|
||||||
|
mockingNetworkInterceptor,
|
||||||
|
NetworkConnectionInterceptor(this),
|
||||||
|
QueryParamsInterceptor(),
|
||||||
|
loggingInterceptor
|
||||||
|
) as WeatherApi
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createLocationModule(): LocationProvider {
|
||||||
|
locationProvider = MockLocationProvider()
|
||||||
|
return locationProvider
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createRoomDatabase(): AppDatabase {
|
||||||
|
database = Room.inMemoryDatabaseBuilder(applicationContext, AppDatabase::class.java)
|
||||||
|
.allowMainThreadQueries()
|
||||||
|
.addTypeConverter(Converter(this))
|
||||||
|
.build()
|
||||||
|
return database
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stubUrl(url: String, rawPath: String, code: Int = 200) {
|
||||||
|
val iStream =
|
||||||
|
InstrumentationRegistry.getInstrumentation().context.assets.open("$rawPath.json")
|
||||||
|
val data = iStream.bufferedReader().use(BufferedReader::readText)
|
||||||
|
mockingNetworkInterceptor.addUrlStub(url = url, data = data, code = code)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeUrlStub(url: String) {
|
||||||
|
mockingNetworkInterceptor.removeUrlStub(url = url)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stubLocation(location: String, lat: Double = 0.00, long: Double = 0.00) {
|
||||||
|
locationProvider.addLocationToList(location, lat, long)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,8 +11,6 @@ import android.icu.util.GregorianCalendar
|
|||||||
import androidx.core.app.NotificationManagerCompat
|
import androidx.core.app.NotificationManagerCompat
|
||||||
|
|
||||||
|
|
||||||
private const val HOUR_TO_SHOW_PUSH = 6
|
|
||||||
|
|
||||||
class NotificationService(context: Context) {
|
class NotificationService(context: Context) {
|
||||||
|
|
||||||
private val alarmManager = context.getSystemService(ALARM_SERVICE) as AlarmManager
|
private val alarmManager = context.getSystemService(ALARM_SERVICE) as AlarmManager
|
||||||
@@ -26,10 +24,10 @@ class NotificationService(context: Context) {
|
|||||||
fun schedulePushNotifications() {
|
fun schedulePushNotifications() {
|
||||||
val calendar = getCalendarForNotification()
|
val calendar = getCalendarForNotification()
|
||||||
|
|
||||||
alarmManager.setRepeating(
|
alarmManager.setWindow(
|
||||||
AlarmManager.RTC_WAKEUP,
|
AlarmManager.RTC_WAKEUP,
|
||||||
calendar.timeInMillis,
|
calendar.timeInMillis,
|
||||||
AlarmManager.INTERVAL_DAY,
|
AlarmManager.INTERVAL_HOUR,
|
||||||
alarmPendingIntent
|
alarmPendingIntent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#3F51B5</color>
|
<color name="colorPrimary">#3F51B5</color>
|
||||||
<color name="colorPrimaryDark">#303F9F</color>
|
<color name="colorPrimaryDark">#303F9F</color>
|
||||||
<color name="colorAccent">#FF4081</color>
|
<color name="colorAccent">@android:color/white</color>
|
||||||
|
|
||||||
<color name="colour_one">#E8D0DD</color>
|
<color name="colour_one">#E8D0DD</color>
|
||||||
<color name="colour_two">#5F8E7B</color>
|
<color name="colour_two">#5F8E7B</color>
|
||||||
<color name="colour_three">#B3C0CA</color>
|
<color name="colour_three">#B3C0CA</color>
|
||||||
<color name="colour_four">#8C98AD</color>
|
<color name="colour_four">#8C98AD</color>
|
||||||
<color name="colour_five">#2E3532</color>
|
<color name="colour_five">#2E3532</color>
|
||||||
|
|
||||||
|
<color name="weather_cell_colour">@android:color/transparent</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ abstract class BaseAppClass : Application(), KodeinAware {
|
|||||||
import(flavourModule)
|
import(flavourModule)
|
||||||
}
|
}
|
||||||
|
|
||||||
val parentModule = Kodein.Module("Parent Module") {
|
val parentModule = Kodein.Module("Parent Module", allowSilentOverride = true) {
|
||||||
import(androidXModule(this@BaseAppClass))
|
import(androidXModule(this@BaseAppClass))
|
||||||
|
|
||||||
bind() from singleton { createNetworkModule() }
|
bind() from singleton { createNetworkModule() }
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.appttude.h_mal.atlas_weather.application
|
package com.appttude.h_mal.atlas_weather.application
|
||||||
|
|
||||||
|
import com.appttude.h_mal.atlas_weather.data.location.LocationProvider
|
||||||
import com.appttude.h_mal.atlas_weather.data.location.LocationProviderImpl
|
import com.appttude.h_mal.atlas_weather.data.location.LocationProviderImpl
|
||||||
import com.appttude.h_mal.atlas_weather.data.network.NetworkModule
|
import com.appttude.h_mal.atlas_weather.data.network.NetworkModule
|
||||||
import com.appttude.h_mal.atlas_weather.data.network.WeatherApi
|
import com.appttude.h_mal.atlas_weather.data.network.WeatherApi
|
||||||
@@ -18,7 +19,7 @@ open class AppClass : BaseAppClass() {
|
|||||||
) as WeatherApi
|
) as WeatherApi
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createLocationModule() = LocationProviderImpl(this)
|
override fun createLocationModule(): LocationProvider = LocationProviderImpl(this)
|
||||||
|
|
||||||
override fun createRoomDatabase(): AppDatabase = AppDatabase(this)
|
override fun createRoomDatabase(): AppDatabase = AppDatabase(this)
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ abstract class BasePreferencesFragment<V : BaseAndroidViewModel>(@XmlRes private
|
|||||||
|
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
prefs.registerOnSharedPreferenceChangeListener { _, s ->
|
prefs.registerOnSharedPreferenceChangeListener { _, s ->
|
||||||
preferenceChanged(s)
|
s?.let { preferenceChanged(s) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_gravity="center"
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_margin="24dp"
|
android:layout_margin="24dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
@@ -33,8 +30,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:text="@string/submit"
|
android:text="@string/submit"
|
||||||
android:textColor="#ffffff"
|
android:textColor="@color/colour_one"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</FrameLayout>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
android:paddingTop="6dp"
|
android:paddingTop="6dp"
|
||||||
android:paddingRight="24dp"
|
android:paddingRight="24dp"
|
||||||
android:paddingBottom="6dp"
|
android:paddingBottom="6dp"
|
||||||
android:background="@color/colorPrimaryDark"
|
android:background="@color/weather_cell_colour"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
android:id="@+id/forecast_listview"
|
android:id="@+id/forecast_listview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:backgroundTint="@color/colorPrimaryDark"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
tools:listitem="@layout/db_list_item" />
|
tools:listitem="@layout/db_list_item" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user