├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── ezike │ │ └── tobenna │ │ └── myweather │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ │ └── ezike │ │ │ └── tobenna │ │ │ └── myweather │ │ │ ├── AppCoroutineDispatcher.kt │ │ │ ├── WeatherApplication.java │ │ │ ├── data │ │ │ ├── Resource.kt │ │ │ ├── local │ │ │ │ ├── LocalDataSource.kt │ │ │ │ ├── LocalDataSourceImpl.kt │ │ │ │ └── db │ │ │ │ │ ├── WeatherDao.kt │ │ │ │ │ ├── WeatherDatabase.kt │ │ │ │ │ └── WeatherTypeConverter.kt │ │ │ ├── model │ │ │ │ ├── Current.kt │ │ │ │ ├── Request.kt │ │ │ │ ├── WeatherLocation.kt │ │ │ │ └── WeatherResponse.kt │ │ │ └── remote │ │ │ │ ├── RemoteImpl.kt │ │ │ │ ├── RemoteSource.kt │ │ │ │ ├── api │ │ │ │ └── ApiService.kt │ │ │ │ └── interceptors │ │ │ │ ├── ConnectivityInterceptor.kt │ │ │ │ └── RequestInterceptor.kt │ │ │ ├── di │ │ │ ├── AppComponent.kt │ │ │ ├── ViewModelKey.java │ │ │ ├── ViewModelModule.java │ │ │ └── module │ │ │ │ ├── ActivityModule.java │ │ │ │ ├── ApiModule.kt │ │ │ │ ├── AppModule.kt │ │ │ │ ├── DataSourceModule.java │ │ │ │ ├── DatabaseModule.java │ │ │ │ ├── LocationModule.java │ │ │ │ └── UnitModule.java │ │ │ ├── provider │ │ │ ├── LocationProvider.java │ │ │ ├── LocationProviderImpl.java │ │ │ ├── PreferenceProvider.java │ │ │ ├── UnitProvider.java │ │ │ └── UnitProviderImpl.java │ │ │ ├── repository │ │ │ ├── Repository.kt │ │ │ └── WeatherRepository.kt │ │ │ ├── ui │ │ │ ├── BindingAdapters.kt │ │ │ ├── WeatherViewModel.kt │ │ │ ├── activity │ │ │ │ ├── MainActivity.java │ │ │ │ └── SplashActivity.java │ │ │ └── fragment │ │ │ │ ├── AboutFragment.java │ │ │ │ ├── SettingsFragment.java │ │ │ │ └── WeatherFragment.kt │ │ │ ├── utils │ │ │ ├── LocationHandler.java │ │ │ ├── UnitSystem.java │ │ │ ├── Utilities.java │ │ │ ├── WeatherIconUtils.java │ │ │ └── extensions.kt │ │ │ ├── viewmodel │ │ │ └── WeatherViewModelFactory.java │ │ │ └── widget │ │ │ ├── WeatherWidgetProvider.java │ │ │ └── WidgetUpdateService.java │ └── res │ │ ├── drawable-nodpi │ │ └── example_appwidget_preview.png │ │ ├── drawable-v24 │ │ ├── day.png │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── ic_launcher_foreground.xml │ │ ├── ic_settings.xml │ │ ├── ic_today.xml │ │ └── widget_bg.jpeg │ │ ├── font │ │ └── googlesans.ttf │ │ ├── layout-land │ │ ├── fragment_about.xml │ │ └── fragment_weather.xml │ │ ├── layout-v17 │ │ └── activity_main.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_splash.xml │ │ ├── fragment_about.xml │ │ ├── fragment_weather.xml │ │ └── weather_widget.xml │ │ ├── menu │ │ ├── bottom_nav.xml │ │ └── menu_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── navigation │ │ └── mobile_navigation.xml │ │ ├── transition │ │ ├── explode.xml │ │ └── slide_out.xml │ │ ├── values-v14 │ │ └── dimens.xml │ │ ├── values │ │ ├── arrays.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ ├── network_security_config.xml │ │ ├── preferences.xml │ │ └── weather_widget_info.xml │ └── test │ └── java │ └── ezike │ └── tobenna │ └── myweather │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── weather.jks /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/android 3 | # Edit at https://www.gitignore.io/?templates=android 4 | 5 | ### Android ### 6 | # Built application files 7 | *.apk 8 | *.ap_ 9 | *.aab 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle/ 24 | build/ 25 | 26 | # ezike.tobenna.myweather.data.LocalTee configuration file (sdk path, etc) 27 | local.properties 28 | 29 | # Proguard folder generated by Eclipse 30 | proguard/ 31 | 32 | # Log Files 33 | *.log 34 | 35 | # Android Studio Navigation editor temp files 36 | .navigation/ 37 | 38 | # Android Studio captures folder 39 | captures/ 40 | 41 | # IntelliJ 42 | *.iml 43 | .idea/workspace.xml 44 | .idea/tasks.xml 45 | .idea/gradle.xml 46 | .idea/assetWizardSettings.xml 47 | .idea/dictionaries 48 | .idea/libraries 49 | .idea/caches 50 | # Android Studio 3 in .gitignore file. 51 | .idea/caches/build_file_checksums.ser 52 | .idea/modules.xml 53 | 54 | # Keystore files 55 | # Uncomment the following lines if you do not want to check your keystore files in. 56 | #*.jks 57 | #*.keystore 58 | 59 | # External native build folder generated in Android Studio 2.2 and later 60 | .externalNativeBuild 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Version control 66 | vcs.xml 67 | 68 | # lint 69 | lint/intermediates/ 70 | lint/generated/ 71 | lint/outputs/ 72 | lint/tmp/ 73 | # lint/reports/ 74 | 75 | ### Android Patch ### 76 | gen-external-apklibs 77 | output.json 78 | 79 | # End of https://www.gitignore.io/api/android -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MyWeather 2 | App shows real-time weather updates for your location and any custom location you set. 3 | Was initially written in Java but is now in Kotlin and uses coroutines. Data is from [Apixu Api](https://www.apixu.com/api.aspx) 4 | 5 | * You can clone the project and fix stuff or maybe write some tests 😉☺️ 6 | 7 |

8 |

9 | 10 | 11 | ## Features 12 | * kotlin coroutines for async operations 13 | * kotlin flow for data streaming 14 | * Local persistence using Room database 15 | * MVVM architecture 16 | * Databinding for binding data to views 17 | * Navigation component 18 | * Homescreen Widget that shows weather information 19 | * Dependency injection with Dagger 2 20 | 21 | #### 1. Clone or fork the repository (Master Branch) by running the command below 22 | on your git terminal 23 | ``` 24 | git clone https://github.com/Ezike/MyWeather.git 25 | ``` 26 | 27 | #### 2. Import the project in AndroidStudio, and add API Key 28 | 1. In Android Studio, go to File -> New -> Import project 29 | 2. Follow the dialog for set up instructions 30 | 3. Get your api key from [Apixu website](https://www.apixu.com/api.aspx) 31 | 4. Create a local `gradle.properties` file and store the api key there 32 | 33 | ``` 34 | ApiXuKey="Your API Key here" 35 | ``` 36 | 37 | ## Libraries 38 | * [Coroutines](https://developer.android.com/kotlin/coroutines) 39 | * [Flow](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/) 40 | * [AndroidX](https://developer.android.com/jetpack/androidx/) 41 | * [Navigation component](https://developer.android.com/guide/navigation) 42 | * [Retrofit 2](https://github.com/square/retrofit) 43 | * [LiveData](https://developer.android.com/topic/libraries/architecture/livedata) 44 | * [ViewModel](https://developer.android.com/topic/libraries/architecture/viewmodel) 45 | * [Room](https://developer.android.com/topic/libraries/architecture/room) 46 | * [Glide](https://github.com/bumptech/glide) 47 | * [DataBinding](https://developer.android.com/topic/libraries/data-binding) 48 | * [Dagger2](https://google.github.io/dagger/users-guide) 49 | * [Timber](https://github.com/JakeWharton/timber) 50 | * [WeatherIconView](https://github.com/pwittchen/WeatherIconView) 51 | * [Moshi](https://github.com/square/moshi) 52 | * [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) 53 | * [OkHttp3](https://square.github.io/okhttp) 54 | * [Google Admob](https://developers.google.com/admob/android/quick-start) 55 | 56 | ## Author 57 | Ezike Tobenna 58 | 59 | ## License 60 | This project is licensed under the Apache License 2.0 - See: http://www.apache.org/licenses/LICENSE-2.0.txt 61 | 62 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/android 3 | # Edit at https://www.gitignore.io/?templates=android 4 | 5 | ### Android ### 6 | # Built application files 7 | *.apk 8 | *.ap_ 9 | *.aab 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle/ 24 | build/ 25 | 26 | # ezike.tobenna.myweather.data.LocalTee configuration file (sdk path, etc) 27 | local.properties 28 | 29 | # Proguard folder generated by Eclipse 30 | proguard/ 31 | 32 | # Log Files 33 | *.log 34 | 35 | # Android Studio Navigation editor temp files 36 | .navigation/ 37 | 38 | # Android Studio captures folder 39 | captures/ 40 | 41 | # IntelliJ 42 | *.iml 43 | .idea/workspace.xml 44 | .idea/tasks.xml 45 | .idea/gradle.xml 46 | .idea/assetWizardSettings.xml 47 | .idea/dictionaries 48 | .idea/libraries 49 | .idea/caches 50 | # Android Studio 3 in .gitignore file. 51 | .idea/caches/build_file_checksums.ser 52 | .idea/modules.xml 53 | 54 | # Keystore files 55 | # Uncomment the following lines if you do not want to check your keystore files in. 56 | #*.jks 57 | #*.keystore 58 | 59 | # External native build folder generated in Android Studio 2.2 and later 60 | .externalNativeBuild 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Version control 66 | vcs.xml 67 | 68 | # lint 69 | lint/intermediates/ 70 | lint/generated/ 71 | lint/outputs/ 72 | lint/tmp/ 73 | # lint/reports/ 74 | 75 | ### Android Patch ### 76 | gen-external-apklibs 77 | output.json 78 | 79 | # End of https://www.gitignore.io/api/android -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'com.google.gms.google-services' 5 | apply plugin: 'io.fabric' 6 | apply plugin: 'kotlin-kapt' 7 | apply plugin: "androidx.navigation.safeargs.kotlin" 8 | 9 | android { 10 | signingConfigs { 11 | keyWeather { 12 | keyAlias 'keyWeather' 13 | keyPassword '123456' 14 | storeFile file("..\\weather.jks") 15 | storePassword '123456' 16 | } 17 | } 18 | 19 | compileSdkVersion 29 20 | 21 | defaultConfig { 22 | applicationId "ezike.tobenna.myweather" 23 | minSdkVersion min_sdk_version 24 | targetSdkVersion compile_sdk_version 25 | multiDexEnabled true 26 | versionCode 1 27 | versionName "1.0" 28 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 29 | } 30 | 31 | buildTypes { 32 | debug { 33 | buildConfigField 'String', "ApiKey", "\"e5235257b00adf728e360a7521c9e096\"" 34 | buildConfigField 'String', "BaseUrl", "\"http://api.weatherstack.com/\"" 35 | // resValue 'string', "api_key", "c1b490e5810e7515ef5bdcf47f8497ad" 36 | } 37 | release { 38 | minifyEnabled false 39 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 40 | buildConfigField 'String', "ApiKey", "c1b490e5810e7515ef5bdcf47f8497ad" 41 | buildConfigField 'String', "BaseUrl", "\"http://api.weatherstack.com/\"" 42 | resValue 'string', "api_key", "c1b490e5810e7515ef5bdcf47f8497ad" 43 | signingConfig signingConfigs.keyWeather 44 | } 45 | } 46 | 47 | buildFeatures { 48 | dataBinding = true 49 | viewBinding = true 50 | } 51 | 52 | 53 | compileOptions { 54 | sourceCompatibility = '1.8' 55 | targetCompatibility = '1.8' 56 | } 57 | 58 | defaultConfig { 59 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 60 | } 61 | 62 | tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { 63 | kotlinOptions { 64 | jvmTarget = "1.8" 65 | } 66 | } 67 | } 68 | 69 | dependencies { 70 | implementation fileTree (include: ['*.jar'], dir: 'libs') 71 | implementation libraries 72 | implementation arch_libraries 73 | kapt librariesKapt 74 | 75 | testImplementation testLibraries 76 | androidTestImplementation androidTestLibraries 77 | } -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "108354523106", 4 | "firebase_url": "https://myweather-a16e6.firebaseio.com", 5 | "project_id": "myweather-a16e6", 6 | "storage_bucket": "myweather-a16e6.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:108354523106:android:eb6b4cb7d114737a", 12 | "android_client_info": { 13 | "package_name": "ezike.tobenna.myweather" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "108354523106-s6r6mtsddus8i7joh0r1e8b5toef90df.apps.googleusercontent.com", 19 | "client_type": 3 20 | } 21 | ], 22 | "api_key": [ 23 | { 24 | "current_key": "AIzaSyCraUlQ_8hRIpGAh9I0HxovIRe7gIu5t6E" 25 | } 26 | ], 27 | "services": { 28 | "analytics_service": { 29 | "status": 1 30 | }, 31 | "appinvite_service": { 32 | "status": 1, 33 | "other_platform_oauth_client": [] 34 | }, 35 | "ads_service": { 36 | "status": 2 37 | } 38 | } 39 | } 40 | ], 41 | "configuration_version": "1" 42 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/ezike/tobenna/myweather/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather; 2 | 3 | import android.content.Context; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | 8 | import androidx.test.core.app.ApplicationProvider; 9 | import androidx.test.ext.junit.runners.AndroidJUnit4; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | 23 | // Use either Application Provider to get context or use Androidx InstrumentationRegistry below 24 | Context appContext = ApplicationProvider.getApplicationContext(); 25 | 26 | // Context appContext = InstrumentationRegistry.getInstrumentation().getContext(); 27 | 28 | assertEquals("ezike.tobenna.myweather", appContext.getPackageName()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 45 | 48 | 49 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/AppCoroutineDispatcher.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather 2 | 3 | import kotlinx.coroutines.CoroutineDispatcher 4 | import kotlinx.coroutines.Dispatchers 5 | 6 | data class AppCoroutineDispatchers( 7 | val io: CoroutineDispatcher = Dispatchers.IO, 8 | val default: CoroutineDispatcher = Dispatchers.Default, 9 | val main: CoroutineDispatcher = Dispatchers.Main 10 | ) 11 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/WeatherApplication.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather; 2 | 3 | import androidx.multidex.MultiDexApplication; 4 | import androidx.preference.PreferenceManager; 5 | 6 | import com.jakewharton.threetenabp.AndroidThreeTen; 7 | 8 | import javax.inject.Inject; 9 | 10 | import dagger.android.AndroidInjector; 11 | import dagger.android.DispatchingAndroidInjector; 12 | import dagger.android.HasAndroidInjector; 13 | import ezike.tobenna.myweather.di.DaggerAppComponent; 14 | import timber.log.Timber; 15 | 16 | /** 17 | * @author tobennaezike 18 | */ 19 | public class WeatherApplication extends MultiDexApplication implements HasAndroidInjector { 20 | 21 | @Inject 22 | DispatchingAndroidInjector dispatchingAndroidInjector; 23 | 24 | @Override 25 | public void onCreate() { 26 | DaggerAppComponent 27 | .builder() 28 | .application(this) 29 | .build() 30 | .inject(this); 31 | 32 | super.onCreate(); 33 | if (BuildConfig.DEBUG) { 34 | Timber.plant(new Timber.DebugTree()); 35 | } 36 | 37 | AndroidThreeTen.init(this); 38 | 39 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); 40 | 41 | } 42 | 43 | @Override 44 | public AndroidInjector androidInjector() { 45 | return dispatchingAndroidInjector; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/Resource.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data 2 | 3 | sealed class Resource( 4 | val data: T? = null, 5 | val message: String? = null 6 | ) { 7 | data class Success(val t: T) : Resource(t) 8 | data class Loading(val t: T? = null) : Resource(t) 9 | data class Error(val error: Throwable, val t: T? = null) : Resource(t, error.message) 10 | 11 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/local/LocalDataSource.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.local 2 | 3 | import ezike.tobenna.myweather.data.model.WeatherResponse 4 | import kotlinx.coroutines.flow.Flow 5 | 6 | 7 | interface LocalDataSource { 8 | suspend fun save(weatherResponse: WeatherResponse?) 9 | fun hasLocationChanged(weatherResponse: WeatherResponse): Boolean 10 | fun getWeather(): Flow 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/local/LocalDataSourceImpl.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.local 2 | 3 | import ezike.tobenna.myweather.data.local.db.WeatherDao 4 | import ezike.tobenna.myweather.data.model.WeatherResponse 5 | import ezike.tobenna.myweather.provider.LocationProvider 6 | import kotlinx.coroutines.flow.Flow 7 | import javax.inject.Inject 8 | 9 | class LocalDataSourceImpl @Inject constructor(private val weatherDao: WeatherDao, private val locationProvider: LocationProvider) 10 | : LocalDataSource { 11 | 12 | override suspend fun save(weatherResponse: WeatherResponse?) { 13 | weatherDao.insert(weatherResponse) 14 | } 15 | 16 | override fun hasLocationChanged(weatherResponse: WeatherResponse): Boolean { 17 | return locationProvider.isLocationChanged(weatherResponse.weatherLocation); 18 | } 19 | 20 | override fun getWeather(): Flow { 21 | return weatherDao.fetchWeather() 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/local/db/WeatherDao.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.local.db 2 | 3 | import androidx.room.Dao 4 | import androidx.room.Insert 5 | import androidx.room.OnConflictStrategy 6 | import androidx.room.Query 7 | import ezike.tobenna.myweather.data.model.WeatherResponse 8 | import kotlinx.coroutines.flow.Flow 9 | 10 | @Dao 11 | interface WeatherDao { 12 | @Query("select * from weather_response") 13 | fun fetchWeather(): Flow 14 | 15 | @Insert(onConflict = OnConflictStrategy.REPLACE) 16 | suspend fun insert(weather: WeatherResponse?) 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/local/db/WeatherDatabase.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.local.db 2 | 3 | import androidx.room.Database 4 | import androidx.room.RoomDatabase 5 | import androidx.room.TypeConverters 6 | import ezike.tobenna.myweather.data.model.WeatherResponse 7 | 8 | 9 | @Database(entities = [WeatherResponse::class], version = 1, exportSchema = false) 10 | @TypeConverters(WeatherTypeConverter::class) 11 | abstract class WeatherDatabase : RoomDatabase() { 12 | abstract fun weatherDao(): WeatherDao? 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/local/db/WeatherTypeConverter.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.local.db 2 | 3 | import androidx.room.TypeConverter 4 | import com.squareup.moshi.Moshi.Builder 5 | import ezike.tobenna.myweather.data.model.Current 6 | import ezike.tobenna.myweather.data.model.Request 7 | import ezike.tobenna.myweather.data.model.WeatherLocation 8 | import ezike.tobenna.myweather.data.model.WeatherResponse 9 | import java.io.IOException 10 | 11 | /** 12 | * @author tobennaezike 13 | */ 14 | class WeatherTypeConverter { 15 | private val moshi = Builder().build() 16 | 17 | @TypeConverter 18 | fun weatherToJson(weather: WeatherResponse?): String? { 19 | return if (weather == null) null else moshi.adapter(WeatherResponse::class.java).toJson(weather) 20 | } 21 | 22 | @TypeConverter 23 | fun weatherFromJson(string: String): WeatherResponse? { 24 | val weather: WeatherResponse? 25 | weather = try { 26 | moshi.adapter(WeatherResponse::class.java).fromJson(string) 27 | } catch (e: IOException) { 28 | e.printStackTrace() 29 | return null 30 | } 31 | return weather 32 | } 33 | 34 | @TypeConverter 35 | fun locationToJson(weatherLocation: WeatherLocation?): String? { 36 | return if (weatherLocation == null) null else moshi.adapter(WeatherLocation::class.java).toJson(weatherLocation) 37 | } 38 | 39 | @TypeConverter 40 | fun locationFromJson(string: String?): WeatherLocation? { 41 | val location: WeatherLocation? 42 | location = try { 43 | moshi.adapter(WeatherLocation::class.java).fromJson(string) 44 | } catch (e: IOException) { 45 | e.printStackTrace() 46 | return null 47 | } 48 | return location 49 | } 50 | 51 | @TypeConverter 52 | fun currentToJson(current: Current?): String? { 53 | return if (current == null) null else moshi.adapter(Current::class.java).toJson(current) 54 | } 55 | 56 | @TypeConverter 57 | fun currentFromJson(string: String): Current? { 58 | val current: Current? 59 | current = try { 60 | moshi.adapter(Current::class.java).fromJson(string) 61 | } catch (e: IOException) { 62 | e.printStackTrace() 63 | return null 64 | } 65 | return current 66 | } 67 | 68 | @TypeConverter 69 | fun requestToJson(request: Request?): String? { 70 | return if (request == null) null else moshi.adapter(Request::class.java).toJson(request) 71 | } 72 | 73 | @TypeConverter 74 | fun requestFromJson(string: String): Request? { 75 | val request: Request? 76 | request = try { 77 | moshi.adapter(Request::class.java).fromJson(string) 78 | } catch (e: IOException) { 79 | e.printStackTrace() 80 | return null 81 | } 82 | return request 83 | } 84 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/model/Current.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.model 2 | 3 | 4 | import com.squareup.moshi.Json 5 | import com.squareup.moshi.JsonClass 6 | 7 | @JsonClass(generateAdapter = true) 8 | data class Current( 9 | @Json(name = "cloudcover") 10 | val cloudCover: Double, 11 | @Json(name = "feelslike") 12 | val feelsLike: Double, 13 | @Json(name = "humidity") 14 | val humidity: Double, 15 | @Json(name = "is_day") 16 | val isDay: String, 17 | @Json(name = "observation_time") 18 | val observationTime: String, 19 | @Json(name = "precip") 20 | val precipitation: Double, 21 | @Json(name = "pressure") 22 | val pressure: Double, 23 | @Json(name = "temperature") 24 | val temperature: Double, 25 | @Json(name = "uv_index") 26 | val uvIndex: Double, 27 | @Json(name = "visibility") 28 | val visibility: Double, 29 | @Json(name = "weather_code") 30 | val weatherCode: Double, 31 | @Json(name = "weather_descriptions") 32 | val weatherDescriptions: List, 33 | @Json(name = "weather_icons") 34 | val weatherIcons: List, 35 | @Json(name = "wind_degree") 36 | val windDegree: Double, 37 | @Json(name = "wind_dir") 38 | val windDir: String, 39 | @Json(name = "wind_speed") 40 | val windSpeed: Double 41 | ) -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/model/Request.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.model 2 | 3 | 4 | import com.squareup.moshi.Json 5 | import com.squareup.moshi.JsonClass 6 | 7 | @JsonClass(generateAdapter = true) 8 | data class Request( 9 | @Json(name = "language") 10 | val language: String, 11 | @Json(name = "query") 12 | val query: String, 13 | @Json(name = "type") 14 | val type: String, 15 | @Json(name = "unit") 16 | val unit: String 17 | ) -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/model/WeatherLocation.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.model 2 | 3 | 4 | import android.os.Build 5 | import androidx.annotation.RequiresApi 6 | import com.squareup.moshi.Json 7 | import com.squareup.moshi.JsonClass 8 | import org.threeten.bp.Instant 9 | import org.threeten.bp.LocalDate 10 | import org.threeten.bp.ZoneId 11 | import org.threeten.bp.ZonedDateTime 12 | import org.threeten.bp.ZonedDateTime.ofInstant 13 | import org.threeten.bp.format.TextStyle 14 | import java.util.* 15 | 16 | @JsonClass(generateAdapter = true) 17 | data class WeatherLocation( 18 | @Json(name = "country") 19 | val country: String, 20 | @Json(name = "lat") 21 | val lat: String, 22 | @Json(name = "localtime") 23 | val localtime: String, 24 | @Json(name = "localtime_epoch") 25 | val localtimeEpoch: Long, 26 | @Json(name = "lon") 27 | val lon: String, 28 | @Json(name = "name") 29 | val name: String, 30 | @Json(name = "region") 31 | val region: String, 32 | @Json(name = "timezone_id") 33 | val timezoneId: String, 34 | @Json(name = "utc_offset") 35 | val utcOffset: String 36 | ) { 37 | @RequiresApi(Build.VERSION_CODES.O) 38 | fun getZonedDateTime(): ZonedDateTime { 39 | val instant = Instant.ofEpochSecond(localtimeEpoch); 40 | val zoneId = ZoneId.of(timezoneId); 41 | return ofInstant(instant, zoneId); 42 | } 43 | 44 | fun getDay(): String { 45 | val dow = LocalDate.now(ZoneId.of(timezoneId)).dayOfWeek; 46 | return dow.getDisplayName(TextStyle.FULL, Locale.ENGLISH); 47 | } 48 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/model/WeatherResponse.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.model 2 | 3 | 4 | import androidx.room.Entity 5 | import androidx.room.PrimaryKey 6 | import com.squareup.moshi.Json 7 | import com.squareup.moshi.JsonClass 8 | 9 | @JsonClass(generateAdapter = true) 10 | @Entity(tableName = "weather_response") 11 | data class WeatherResponse( 12 | @PrimaryKey 13 | val id: Int = 0, 14 | @Json(name = "current") 15 | val current: Current, 16 | @Json(name = "location") 17 | val weatherLocation: WeatherLocation, 18 | @Json(name = "request") 19 | val request: Request 20 | ) -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/remote/RemoteImpl.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.remote 2 | 3 | import ezike.tobenna.myweather.data.model.WeatherResponse 4 | import ezike.tobenna.myweather.data.remote.api.ApiService 5 | import javax.inject.Inject 6 | 7 | class RemoteImpl @Inject constructor(private val apiService: ApiService) : RemoteSource { 8 | 9 | override suspend fun fetchWeather(location: String): WeatherResponse { 10 | return apiService.getWeather(location) 11 | } 12 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/remote/RemoteSource.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.remote 2 | 3 | import ezike.tobenna.myweather.data.model.WeatherResponse 4 | 5 | 6 | interface RemoteSource { 7 | suspend fun fetchWeather(location: String): WeatherResponse 8 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/remote/api/ApiService.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.remote.api 2 | 3 | import ezike.tobenna.myweather.data.model.WeatherResponse 4 | import retrofit2.http.GET 5 | import retrofit2.http.Query 6 | 7 | interface ApiService { 8 | 9 | @GET("current") 10 | suspend fun getWeather( 11 | @Query("query") location: String): WeatherResponse 12 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/remote/interceptors/ConnectivityInterceptor.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.remote.interceptors 2 | 3 | import android.content.Context 4 | import ezike.tobenna.myweather.utils.Utilities 5 | import okhttp3.Interceptor 6 | import okhttp3.Response 7 | import java.io.IOException 8 | import javax.inject.Inject 9 | 10 | class ConnectivityInterceptor @Inject constructor(val context: Context) : Interceptor { 11 | 12 | override fun intercept(chain: Interceptor.Chain): Response { 13 | if (!Utilities.isOnline(context)) { 14 | throw IOException("Please check your internet connection") 15 | } 16 | return chain.proceed(chain.request()) 17 | } 18 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/data/remote/interceptors/RequestInterceptor.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.data.remote.interceptors 2 | 3 | import ezike.tobenna.myweather.BuildConfig 4 | import okhttp3.Interceptor 5 | import okhttp3.Request 6 | import okhttp3.Response 7 | import javax.inject.Inject 8 | 9 | class RequestInterceptor @Inject constructor(): Interceptor { 10 | 11 | override fun intercept(chain: Interceptor.Chain): Response { 12 | var request: Request = chain.request() 13 | val url = request.url.newBuilder() 14 | .addQueryParameter(ACCESS_KEY, BuildConfig.ApiKey) 15 | .build() 16 | request = request.newBuilder().url(url).build() 17 | return chain.proceed(request) 18 | } 19 | 20 | companion object { 21 | const val ACCESS_KEY: String = "access_key" 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/AppComponent.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di 2 | 3 | import android.app.Application 4 | import dagger.BindsInstance 5 | import dagger.Component 6 | import dagger.android.support.AndroidSupportInjectionModule 7 | import ezike.tobenna.myweather.WeatherApplication 8 | import ezike.tobenna.myweather.di.module.* 9 | import javax.inject.Singleton 10 | 11 | /** 12 | * @author tobennaezike 13 | * @since 20/03/19 14 | */ 15 | @Singleton 16 | @Component(modules = [AndroidSupportInjectionModule::class, 17 | ActivityModule::class, 18 | ApiModule::class, DatabaseModule::class, 19 | AppModule::class, UnitModule::class, 20 | LocationModule::class, 21 | DataSourceModule::class, 22 | ViewModelModule::class]) 23 | 24 | interface AppComponent { 25 | fun inject(application: WeatherApplication?) 26 | 27 | @Component.Builder 28 | interface Builder { 29 | @BindsInstance 30 | fun application(application: Application): Builder 31 | 32 | fun build(): AppComponent 33 | } 34 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/ViewModelKey.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import androidx.lifecycle.ViewModel; 10 | import dagger.MapKey; 11 | 12 | /** 13 | * @author tobennaezike 14 | */ 15 | 16 | @Documented 17 | @Target({ElementType.METHOD}) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @MapKey 20 | @interface ViewModelKey { 21 | Class value(); 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/ViewModelModule.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di; 2 | 3 | import androidx.lifecycle.ViewModel; 4 | import androidx.lifecycle.ViewModelProvider; 5 | import dagger.Binds; 6 | import dagger.Module; 7 | import dagger.multibindings.IntoMap; 8 | import ezike.tobenna.myweather.ui.WeatherViewModel; 9 | import ezike.tobenna.myweather.viewmodel.WeatherViewModelFactory; 10 | 11 | /** 12 | * @author tobennaezike 13 | */ 14 | @Module 15 | abstract class ViewModelModule { 16 | 17 | /* 18 | * inject this object into a Map using the @IntoMap annotation, 19 | * with the WeatherViewModel.class as key, 20 | * and a Provider that will build a WeatherViewModel 21 | * object. 22 | * 23 | * */ 24 | 25 | @Binds 26 | @IntoMap 27 | @ViewModelKey(WeatherViewModel.class) 28 | abstract ViewModel currentWeatherViewModel(WeatherViewModel weatherViewModel); 29 | 30 | @Binds 31 | abstract ViewModelProvider.Factory bindViewModelFactory(WeatherViewModelFactory factory); 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/module/ActivityModule.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di.module; 2 | 3 | import dagger.Module; 4 | import dagger.android.ContributesAndroidInjector; 5 | import ezike.tobenna.myweather.ui.activity.MainActivity; 6 | import ezike.tobenna.myweather.ui.fragment.WeatherFragment; 7 | 8 | /** 9 | * @author tobennaezike 10 | */ 11 | 12 | @Module 13 | public abstract class ActivityModule { 14 | 15 | @ContributesAndroidInjector 16 | abstract MainActivity contributeMainActivity(); 17 | 18 | @ContributesAndroidInjector 19 | abstract WeatherFragment contributeWeatherFragment(); 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/module/ApiModule.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di.module 2 | 3 | import android.app.Application 4 | import com.squareup.moshi.Moshi 5 | import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory 6 | import dagger.Module 7 | import dagger.Provides 8 | import ezike.tobenna.myweather.AppCoroutineDispatchers 9 | import ezike.tobenna.myweather.BuildConfig 10 | import ezike.tobenna.myweather.data.remote.api.ApiService 11 | import ezike.tobenna.myweather.data.remote.interceptors.ConnectivityInterceptor 12 | import ezike.tobenna.myweather.data.remote.interceptors.RequestInterceptor 13 | import okhttp3.Cache 14 | import okhttp3.OkHttpClient 15 | import okhttp3.OkHttpClient.Builder 16 | import okhttp3.logging.HttpLoggingInterceptor 17 | import okhttp3.logging.HttpLoggingInterceptor.Level 18 | import retrofit2.Retrofit 19 | import retrofit2.converter.moshi.MoshiConverterFactory 20 | import java.io.File 21 | import javax.inject.Singleton 22 | 23 | /** 24 | * @author tobennaezike 25 | */ 26 | 27 | @Module 28 | object ApiModule { 29 | @Provides 30 | @JvmStatic 31 | @Singleton 32 | internal fun provideCache(application: Application): Cache { 33 | val cacheSize = 10 * 1024 * 1024.toLong() // 10 MB 34 | val httpCacheDirectory = File(application.cacheDir, "http-cache") 35 | return Cache(httpCacheDirectory, cacheSize) 36 | } 37 | 38 | @Provides 39 | @Singleton 40 | internal fun provideOkHttpClient(cache: Cache, connectivityInterceptor: ConnectivityInterceptor, 41 | requestInterceptor: RequestInterceptor, 42 | logger: HttpLoggingInterceptor): OkHttpClient { 43 | val httpClient = Builder() 44 | httpClient.cache(cache) 45 | httpClient.addInterceptor(logger) 46 | httpClient.addNetworkInterceptor(requestInterceptor) 47 | httpClient.addInterceptor(connectivityInterceptor) 48 | return httpClient.build() 49 | } 50 | 51 | @Provides 52 | @Singleton 53 | internal fun provideOkHttpLogger(): HttpLoggingInterceptor { 54 | return HttpLoggingInterceptor().apply { 55 | if (BuildConfig.DEBUG) { 56 | level = Level.BODY 57 | } 58 | } 59 | } 60 | 61 | @Provides 62 | @Singleton 63 | internal fun provideMoshi(): Moshi { 64 | return Moshi.Builder() 65 | .add(KotlinJsonAdapterFactory()).build() 66 | } 67 | 68 | @Singleton 69 | @Provides 70 | internal fun provideApiService(moshi: Moshi, okHttpClient: OkHttpClient): ApiService { 71 | return Retrofit 72 | .Builder() 73 | .baseUrl(BuildConfig.BaseUrl) 74 | .addConverterFactory(MoshiConverterFactory.create(moshi)) 75 | .client(okHttpClient) 76 | .build() 77 | .create(ApiService::class.java) 78 | } 79 | 80 | @Provides 81 | fun provideDispatcher(): AppCoroutineDispatchers { 82 | return AppCoroutineDispatchers() 83 | } 84 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/module/AppModule.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di.module 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import android.content.SharedPreferences 6 | import android.location.LocationManager 7 | import com.google.android.gms.location.FusedLocationProviderClient 8 | import com.google.android.gms.location.LocationServices 9 | import dagger.Module 10 | import dagger.Provides 11 | import javax.inject.Singleton 12 | 13 | /** 14 | * @author tobennaezike 15 | * @since 22/03/19 16 | */ 17 | @Module 18 | object AppModule { 19 | @Provides 20 | @Singleton 21 | internal fun provideContext(application: Application): Context { 22 | return application.applicationContext 23 | } 24 | 25 | @Singleton 26 | @Provides 27 | internal fun provideFusedLocationProviderClient(context: Context): FusedLocationProviderClient { 28 | return LocationServices.getFusedLocationProviderClient(context) 29 | } 30 | 31 | @Singleton 32 | @Provides 33 | internal fun provideLocationManager(context: Context): LocationManager { 34 | return context.getSystemService(Context.LOCATION_SERVICE) as LocationManager 35 | } 36 | 37 | @Singleton 38 | @Provides 39 | internal fun providePrefs(context: Context): SharedPreferences.Editor { 40 | return context.getSharedPreferences(WIDGET_PREF, Context.MODE_PRIVATE).edit() 41 | } 42 | 43 | private const val WIDGET_PREF = "ezike.tobenna.myweather.ui.widget.pref" 44 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/module/DataSourceModule.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di.module; 2 | 3 | import dagger.Binds; 4 | import dagger.Module; 5 | import ezike.tobenna.myweather.data.local.LocalDataSource; 6 | import ezike.tobenna.myweather.data.local.LocalDataSourceImpl; 7 | import ezike.tobenna.myweather.data.remote.RemoteImpl; 8 | import ezike.tobenna.myweather.data.remote.RemoteSource; 9 | import ezike.tobenna.myweather.repository.Repository; 10 | import ezike.tobenna.myweather.repository.WeatherRepository; 11 | 12 | @Module 13 | public abstract class DataSourceModule { 14 | 15 | @Binds 16 | abstract LocalDataSource provideDataSource(LocalDataSourceImpl localDataSource); 17 | 18 | @Binds 19 | abstract Repository provideRepoImpl(WeatherRepository repo); 20 | 21 | @Binds 22 | abstract RemoteSource provideRemoteImpl(RemoteImpl remote); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/module/DatabaseModule.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di.module; 2 | 3 | import android.content.Context; 4 | 5 | import javax.inject.Singleton; 6 | 7 | import androidx.annotation.NonNull; 8 | import androidx.room.Room; 9 | import dagger.Module; 10 | import dagger.Provides; 11 | import ezike.tobenna.myweather.data.local.db.WeatherDao; 12 | import ezike.tobenna.myweather.data.local.db.WeatherDatabase; 13 | 14 | 15 | /** 16 | * @author tobennaezike 17 | * @since 20/03/19 18 | */ 19 | @Module 20 | public class DatabaseModule { 21 | 22 | @Provides 23 | @Singleton 24 | static WeatherDatabase provideDatabase(@NonNull Context context) { 25 | return Room.databaseBuilder(context, 26 | WeatherDatabase.class, "weather_db") 27 | .build(); 28 | } 29 | 30 | @Provides 31 | @Singleton 32 | static WeatherDao provideWeatherResponseDao(@NonNull WeatherDatabase appDatabase) { 33 | return appDatabase.weatherDao(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/module/LocationModule.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di.module; 2 | 3 | import javax.inject.Singleton; 4 | 5 | import dagger.Binds; 6 | import dagger.Module; 7 | import ezike.tobenna.myweather.provider.LocationProvider; 8 | import ezike.tobenna.myweather.provider.LocationProviderImpl; 9 | 10 | /** 11 | * @author tobennaezike 12 | */ 13 | 14 | @Module 15 | public abstract class LocationModule { 16 | 17 | @Singleton 18 | @Binds 19 | abstract LocationProvider provideLocationProvider(LocationProviderImpl locationProvider); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/di/module/UnitModule.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.di.module; 2 | 3 | import dagger.Binds; 4 | import dagger.Module; 5 | import ezike.tobenna.myweather.provider.UnitProvider; 6 | import ezike.tobenna.myweather.provider.UnitProviderImpl; 7 | 8 | /** 9 | * @author tobennaezike 10 | * @since 23/03/19 11 | */ 12 | @Module 13 | public abstract class UnitModule { 14 | 15 | @Binds 16 | abstract UnitProvider provideUnitProvider(UnitProviderImpl unitProvider); 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/provider/LocationProvider.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.provider; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | import ezike.tobenna.myweather.data.model.WeatherLocation; 6 | 7 | public interface LocationProvider { 8 | 9 | boolean isLocationChanged(WeatherLocation weatherLocation); 10 | 11 | @NotNull String getPreferredLocationString(); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/provider/LocationProviderImpl.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.provider; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.location.Location; 6 | 7 | import com.google.android.gms.location.FusedLocationProviderClient; 8 | import com.google.android.gms.location.LocationCallback; 9 | import com.google.android.gms.location.LocationResult; 10 | import com.google.android.gms.tasks.OnSuccessListener; 11 | 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | import javax.inject.Inject; 15 | 16 | import ezike.tobenna.myweather.data.model.WeatherLocation; 17 | import timber.log.Timber; 18 | 19 | public class LocationProviderImpl extends PreferenceProvider implements LocationProvider, OnSuccessListener { 20 | 21 | private static final String USE_DEVICE_LOCATION = "USE_DEVICE_LOCATION"; 22 | 23 | private static final String CUSTOM_LOCATION = "CUSTOM_LOCATION"; 24 | 25 | private FusedLocationProviderClient mFusedLocationProviderClient; 26 | 27 | private Location deviceWeatherLocation; 28 | 29 | @Inject 30 | LocationProviderImpl(Context context, FusedLocationProviderClient client) { 31 | super(context); 32 | mFusedLocationProviderClient = client; 33 | } 34 | 35 | @Override 36 | public boolean isLocationChanged(WeatherLocation weatherLocation) { 37 | Timber.d("Device location change %b", hasDeviceLocationChanged(deviceWeatherLocation)); 38 | return hasDeviceLocationChanged(deviceWeatherLocation) || hasCustomLocationChanged(weatherLocation); 39 | } 40 | 41 | @NotNull 42 | @Override 43 | public String getPreferredLocationString() { 44 | if (isUsingDeviceLocation()) { 45 | if (getLastDeviceLocation() == null) { 46 | return getCustomLocationName(); 47 | } else { 48 | String latitude = String.valueOf(getLastDeviceLocation().getLatitude()); 49 | String longitude = String.valueOf(getLastDeviceLocation().getLongitude()); 50 | Timber.d("Coordinates %s,%s", latitude, longitude); 51 | return (latitude + "," + longitude); 52 | } 53 | } else { 54 | return getCustomLocationName(); 55 | } 56 | } 57 | 58 | private boolean hasDeviceLocationChanged(Location weatherLocation) { 59 | if (!isUsingDeviceLocation()) { 60 | return false; 61 | } 62 | 63 | double comparisonThreshold = 0.03; 64 | 65 | if (getLastDeviceLocation() != null && weatherLocation != null) { 66 | return Math.abs(getLastDeviceLocation().getLatitude() - weatherLocation.getLatitude()) > comparisonThreshold 67 | && Math.abs(getLastDeviceLocation().getLongitude() - weatherLocation.getLongitude()) > comparisonThreshold; 68 | 69 | } 70 | return false; 71 | } 72 | 73 | private boolean hasCustomLocationChanged(WeatherLocation weatherLocation) { 74 | if (!isUsingDeviceLocation()) { 75 | String customLocationName = getCustomLocationName(); 76 | return !customLocationName.equals(weatherLocation.getName()); 77 | } 78 | return false; 79 | } 80 | 81 | private boolean isUsingDeviceLocation() { 82 | startLocationUpdates(); 83 | return getSharedPreferences().getBoolean(USE_DEVICE_LOCATION, true); 84 | } 85 | 86 | private String getCustomLocationName() { 87 | return getSharedPreferences().getString(CUSTOM_LOCATION, null); 88 | } 89 | 90 | private Location getLastDeviceLocation() { 91 | 92 | startLocationUpdates(); 93 | 94 | return deviceWeatherLocation; 95 | } 96 | 97 | @SuppressLint("MissingPermission") 98 | private void startLocationUpdates() { 99 | mFusedLocationProviderClient.getLastLocation().addOnSuccessListener(this); 100 | 101 | new LocationCallback() { 102 | @Override 103 | public void onLocationResult(LocationResult locationResult) { 104 | super.onLocationResult(locationResult); 105 | for (Location weatherLocation : locationResult.getLocations()) { 106 | if (weatherLocation != null) { 107 | deviceWeatherLocation = weatherLocation; 108 | } 109 | } 110 | 111 | } 112 | }; 113 | } 114 | 115 | @Override 116 | public void onSuccess(Location weatherLocation) { 117 | if (weatherLocation != null) { 118 | deviceWeatherLocation = weatherLocation; 119 | } else { 120 | Timber.d("Device Location not yet available. Please try again"); 121 | } 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/provider/PreferenceProvider.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.provider; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.preference.PreferenceManager; 6 | 7 | 8 | /** 9 | * @author tobennaezike 10 | * @since 23/03/19 11 | */ 12 | abstract class PreferenceProvider { 13 | 14 | private Context mContext; 15 | 16 | public PreferenceProvider(Context context) { 17 | mContext = context; 18 | } 19 | 20 | public SharedPreferences getSharedPreferences() { 21 | return PreferenceManager.getDefaultSharedPreferences(mContext); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/provider/UnitProvider.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.provider; 2 | 3 | import ezike.tobenna.myweather.utils.UnitSystem; 4 | 5 | /** 6 | * @author tobennaezike 7 | * @since 23/03/19 8 | */ 9 | public interface UnitProvider { 10 | 11 | UnitSystem getUnitSystem(); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/provider/UnitProviderImpl.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.provider; 2 | 3 | import android.content.Context; 4 | 5 | import javax.inject.Inject; 6 | import javax.inject.Singleton; 7 | 8 | import ezike.tobenna.myweather.utils.UnitSystem; 9 | 10 | /** 11 | * @author tobennaezike 12 | * @since 23/03/19 13 | */ 14 | @Singleton 15 | public class UnitProviderImpl extends PreferenceProvider implements UnitProvider { 16 | 17 | private static final String UNIT_SYSTEM = "UNIT_SYSTEM"; 18 | 19 | @Inject 20 | public UnitProviderImpl(Context context) { 21 | super(context); 22 | } 23 | 24 | @Override 25 | public UnitSystem getUnitSystem() { 26 | String selectedName = getSharedPreferences().getString(UNIT_SYSTEM, UnitSystem.METRIC.name()); 27 | return UnitSystem.valueOf(selectedName); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/repository/Repository.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.repository 2 | 3 | import ezike.tobenna.myweather.data.Resource 4 | import ezike.tobenna.myweather.data.model.WeatherResponse 5 | import kotlinx.coroutines.flow.Flow 6 | 7 | interface Repository { 8 | fun fetchWeather(): Flow> 9 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/repository/WeatherRepository.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.repository 2 | 3 | import android.content.Context 4 | import android.content.SharedPreferences 5 | import ezike.tobenna.myweather.AppCoroutineDispatchers 6 | import ezike.tobenna.myweather.data.Resource 7 | import ezike.tobenna.myweather.data.local.LocalDataSource 8 | import ezike.tobenna.myweather.data.model.WeatherResponse 9 | import ezike.tobenna.myweather.data.remote.RemoteSource 10 | import ezike.tobenna.myweather.provider.LocationProvider 11 | import ezike.tobenna.myweather.widget.WeatherWidgetProvider 12 | import kotlinx.coroutines.ExperimentalCoroutinesApi 13 | import kotlinx.coroutines.flow.* 14 | import javax.inject.Inject 15 | 16 | @ExperimentalCoroutinesApi 17 | class WeatherRepository @Inject constructor( 18 | private val dispatcher: AppCoroutineDispatchers, 19 | private val remoteSource: RemoteSource, 20 | private val localDataSource: LocalDataSource, 21 | private val locationProvider: LocationProvider, 22 | private val prefEditor: SharedPreferences.Editor, 23 | private val context: Context 24 | ) : Repository { 25 | 26 | @ExperimentalCoroutinesApi 27 | override fun fetchWeather(): Flow> { 28 | return flow> { 29 | val currentData: WeatherResponse = localDataSource.getWeather().first() 30 | emit(Resource.Loading(currentData)) 31 | fetchWeatherAndCache() 32 | updateWidgetData(currentData) 33 | emitAll(localDataSource.getWeather().map { Resource.Success(it) }) 34 | }.catch { cause -> 35 | val previousData: WeatherResponse = localDataSource.getWeather().first() 36 | emit(Resource.Error(cause, previousData)) 37 | cause.printStackTrace() 38 | }.flowOn(dispatcher.io) 39 | } 40 | 41 | private fun updateWidgetData(weather: WeatherResponse) { 42 | saveToPreferences(weather) 43 | WeatherWidgetProvider.updateWidget(context) 44 | } 45 | 46 | private suspend fun fetchWeatherAndCache() { 47 | val weather: WeatherResponse = remoteSource 48 | .fetchWeather(locationProvider.preferredLocationString) 49 | localDataSource.save(weather) 50 | } 51 | 52 | private fun saveToPreferences(weather: WeatherResponse?) { 53 | weather?.let { 54 | if (it.current.weatherDescriptions.isNotEmpty()) { 55 | prefEditor.putString(WIDGET_TEXT, weather.current.weatherDescriptions.first()) 56 | prefEditor.putString(WIDGET_LOCATION, weather.weatherLocation.region) 57 | prefEditor.putString(WIDGET_ICON, weather.current.weatherDescriptions.first()) 58 | prefEditor.apply() 59 | } 60 | } 61 | } 62 | 63 | companion object { 64 | const val WIDGET_TEXT: String = "ezike.tobenna.myweather.ui.widget.text" 65 | const val WIDGET_LOCATION: String = "ezike.tobenna.myweather.ui.widget.location" 66 | const val WIDGET_ICON: String = "ezike.tobenna.myweather.ui.widget.icon" 67 | } 68 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/ui/BindingAdapters.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.ui 2 | 3 | import android.view.View 4 | import android.widget.ImageView 5 | import android.widget.TextView 6 | import androidx.databinding.BindingAdapter 7 | import com.bumptech.glide.Glide 8 | import com.github.pwittchen.weathericonview.WeatherIconView 9 | import ezike.tobenna.myweather.R 10 | import ezike.tobenna.myweather.data.Resource 11 | import ezike.tobenna.myweather.data.model.WeatherResponse 12 | import ezike.tobenna.myweather.utils.WeatherIconUtils 13 | import ezike.tobenna.myweather.utils.visible 14 | import java.io.IOException 15 | 16 | /** 17 | * @author tobennaezike 18 | */ 19 | 20 | @BindingAdapter("imageUrl") 21 | fun bindImage(imageView: ImageView, imagePath: String) { 22 | Glide.with(imageView.context) 23 | .load("http:$imagePath") 24 | .placeholder(R.drawable.day) 25 | .into(imageView) 26 | } 27 | 28 | @BindingAdapter("showIcon") 29 | fun showIcon(iconView: WeatherIconView, condition: String?) { 30 | val context = iconView.context 31 | WeatherIconUtils.getIconResource(context, iconView, condition) 32 | } 33 | 34 | @BindingAdapter("showLoading") 35 | fun View.showLoading(resource: Resource?) { 36 | when (resource) { 37 | is Resource.Loading -> visibility == View.VISIBLE 38 | else -> visibility == View.GONE 39 | } 40 | } 41 | 42 | @BindingAdapter("showSuccess") 43 | fun View.showSuccess(boolean: Boolean) { 44 | visible = boolean 45 | } 46 | 47 | @BindingAdapter("showError") 48 | fun TextView.showError(resource: Resource?) { 49 | when (resource) { 50 | is Resource.Error -> { 51 | visible = true 52 | text = if (resource.error is IOException) { 53 | context.getString(R.string.data_fetch_failed) 54 | } else resource.error.localizedMessage 55 | return 56 | } 57 | else -> visibility == View.GONE 58 | } 59 | } 60 | 61 | 62 | @BindingAdapter("visibleGone") 63 | fun View.toggleVisibility(boolean: Boolean) { 64 | when (boolean) { 65 | true -> visibility == View.VISIBLE 66 | false -> visibility == View.GONE 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/ui/WeatherViewModel.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.ui 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.lifecycle.ViewModel 5 | import androidx.lifecycle.asLiveData 6 | import androidx.lifecycle.viewModelScope 7 | import ezike.tobenna.myweather.data.Resource 8 | import ezike.tobenna.myweather.data.model.WeatherResponse 9 | import ezike.tobenna.myweather.repository.Repository 10 | import kotlinx.coroutines.ExperimentalCoroutinesApi 11 | import kotlinx.coroutines.FlowPreview 12 | import kotlinx.coroutines.channels.ConflatedBroadcastChannel 13 | import kotlinx.coroutines.flow.asFlow 14 | import kotlinx.coroutines.flow.launchIn 15 | import kotlinx.coroutines.flow.onEach 16 | import javax.inject.Inject 17 | 18 | @FlowPreview 19 | @ExperimentalCoroutinesApi 20 | class WeatherViewModel @Inject constructor(repository: Repository) 21 | : ViewModel(), Repository by repository { 22 | 23 | private val channel = ConflatedBroadcastChannel>(Resource.Loading()) 24 | val weatherLiveData: LiveData> = channel.asFlow().asLiveData() 25 | 26 | init { 27 | fetchData() 28 | } 29 | 30 | fun fetchData() { 31 | fetchWeather() 32 | .onEach { 33 | channel.offer(it) 34 | }.launchIn(viewModelScope) 35 | } 36 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/ui/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.ui.activity; 2 | 3 | import android.Manifest; 4 | import android.content.pm.PackageManager; 5 | import android.location.LocationManager; 6 | import android.os.Bundle; 7 | import android.view.Menu; 8 | import android.view.MenuItem; 9 | import android.widget.Toast; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.appcompat.app.AppCompatActivity; 13 | import androidx.core.app.ActivityCompat; 14 | import androidx.databinding.DataBindingUtil; 15 | import androidx.drawerlayout.widget.DrawerLayout; 16 | import androidx.navigation.NavController; 17 | import androidx.navigation.Navigation; 18 | import androidx.navigation.ui.NavigationUI; 19 | 20 | import com.google.android.gms.ads.MobileAds; 21 | import com.google.android.gms.location.LocationCallback; 22 | import com.google.android.gms.location.LocationResult; 23 | 24 | import javax.inject.Inject; 25 | 26 | import dagger.android.AndroidInjection; 27 | import dagger.android.support.AndroidSupportInjection; 28 | import ezike.tobenna.myweather.R; 29 | import ezike.tobenna.myweather.databinding.ActivityMainBinding; 30 | import ezike.tobenna.myweather.utils.LocationHandler; 31 | import ezike.tobenna.myweather.utils.Utilities; 32 | import timber.log.Timber; 33 | 34 | /** 35 | * @author tobennaezike 36 | * @since 16/03/19 37 | */ 38 | public class MainActivity extends AppCompatActivity { 39 | 40 | private static final int PERMISSION_ACCESS_COARSE_LOCATION = 98; 41 | 42 | @Inject 43 | LocationManager mLocationManager; 44 | 45 | private String[] permissions = new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, 46 | Manifest.permission.ACCESS_FINE_LOCATION}; 47 | 48 | private LocationCallback mLocationCallback = new LocationCallback() { 49 | @Override 50 | public void onLocationResult(LocationResult locationResult) { 51 | super.onLocationResult(locationResult); 52 | } 53 | }; 54 | 55 | private NavController mNavController; 56 | 57 | @Override 58 | protected void onCreate(Bundle savedInstanceState) { 59 | super.onCreate(savedInstanceState); 60 | 61 | AndroidInjection.inject(this); 62 | 63 | ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); 64 | 65 | setSupportActionBar(binding.toolbar); 66 | 67 | mNavController = Navigation.findNavController(this, R.id.nav_host_fragment); 68 | 69 | NavigationUI.setupWithNavController(binding.bottomNav, mNavController); 70 | 71 | checkLocationPermission(); 72 | 73 | checkGpsEnabled(); 74 | 75 | MobileAds.initialize(this, getString(R.string.ad_id)); 76 | } 77 | 78 | @Override 79 | public boolean onSupportNavigateUp() { 80 | return NavigationUI.navigateUp(mNavController, (DrawerLayout) null); 81 | } 82 | 83 | @Override 84 | public boolean onCreateOptionsMenu(Menu menu) { 85 | getMenuInflater().inflate(R.menu.menu_main, menu); 86 | return true; 87 | } 88 | 89 | @Override 90 | public boolean onOptionsItemSelected(MenuItem item) { 91 | boolean navigated = NavigationUI.onNavDestinationSelected(item, mNavController); 92 | return navigated || super.onOptionsItemSelected(item); 93 | } 94 | 95 | private void checkGpsEnabled() { 96 | if (Utilities.isLocationProviderEnabled(mLocationManager)) { 97 | Timber.d("gps enabled"); 98 | startLocationUpdates(); 99 | } else { 100 | Timber.d("gps disabled"); 101 | Utilities.enableLocationProvider(this, getString(R.string.enable_gps), 102 | getString(R.string.gps_enable_prompt)); 103 | } 104 | } 105 | 106 | private void startLocationUpdates() { 107 | LocationHandler.getLocationHandler(this, mLocationCallback); 108 | } 109 | 110 | public void checkLocationPermission() { 111 | if (!isPermissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION) || 112 | !isPermissionGranted(Manifest.permission.ACCESS_FINE_LOCATION)) { 113 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, 114 | Manifest.permission.ACCESS_COARSE_LOCATION)) { 115 | Utilities.showDialog(this, getString(R.string.location_permission_dialog_title), 116 | getString(R.string.location_permission_prompt), 117 | (dialog, i) -> requestPermission(permissions), 118 | (dialog, i) -> Utilities.showToast(this, 119 | getString(R.string.set_custom_location), 120 | Toast.LENGTH_LONG)); 121 | } else { 122 | requestPermission(permissions); 123 | } 124 | } else { 125 | Timber.d("Permission granted"); 126 | startLocationUpdates(); 127 | } 128 | } 129 | 130 | private void requestPermission(String[] permissions) { 131 | ActivityCompat.requestPermissions(this, permissions, PERMISSION_ACCESS_COARSE_LOCATION); 132 | } 133 | 134 | private boolean isPermissionGranted(String permission) { 135 | return ActivityCompat.checkSelfPermission(this, 136 | permission) == PackageManager.PERMISSION_GRANTED; 137 | } 138 | 139 | @Override 140 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, 141 | @NonNull int[] grantResults) { 142 | switch (requestCode) { 143 | case PERMISSION_ACCESS_COARSE_LOCATION: { 144 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == 145 | PackageManager.PERMISSION_GRANTED) { 146 | startLocationUpdates(); 147 | Timber.d("permission granted"); 148 | } else { 149 | Timber.d("permission not granted"); 150 | } 151 | } 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/ui/activity/SplashActivity.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.ui.activity; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.ActivityOptions; 5 | import android.content.Intent; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | 10 | import androidx.appcompat.app.AppCompatActivity; 11 | import ezike.tobenna.myweather.R; 12 | 13 | public class SplashActivity extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_splash); 19 | 20 | scheduleSplashScreen(); 21 | } 22 | 23 | private void scheduleSplashScreen() { 24 | new Handler().postDelayed(() -> { 25 | routeToActivity(); 26 | finish(); 27 | }, 1000L); 28 | } 29 | 30 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 31 | private void routeToActivity() { 32 | ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this); 33 | Intent intent = new Intent(SplashActivity.this, MainActivity.class); 34 | startActivity(intent, options.toBundle()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/ui/fragment/AboutFragment.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.ui.fragment; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.fragment.app.Fragment; 11 | import ezike.tobenna.myweather.R; 12 | 13 | 14 | /** 15 | * A simple {@link Fragment} subclass. 16 | */ 17 | public class AboutFragment extends Fragment { 18 | 19 | @Override 20 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, 21 | Bundle savedInstanceState) { 22 | 23 | return inflater.inflate(R.layout.fragment_about, container, false); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/ui/fragment/SettingsFragment.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.ui.fragment; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import androidx.annotation.NonNull; 8 | import androidx.annotation.Nullable; 9 | import androidx.appcompat.app.AppCompatActivity; 10 | import androidx.fragment.app.Fragment; 11 | import androidx.preference.PreferenceFragmentCompat; 12 | 13 | import ezike.tobenna.myweather.R; 14 | 15 | /** 16 | * A simple {@link Fragment} subclass. 17 | */ 18 | public class SettingsFragment extends PreferenceFragmentCompat { 19 | 20 | @Override 21 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 22 | addPreferencesFromResource(R.xml.preferences); 23 | } 24 | 25 | @Override 26 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 27 | super.onActivityCreated(savedInstanceState); 28 | } 29 | 30 | @Override 31 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 32 | super.onViewCreated(view, savedInstanceState); 33 | if (((AppCompatActivity) requireActivity()).getSupportActionBar() != null) { 34 | ((AppCompatActivity) requireActivity()).getSupportActionBar().setTitle("Settings"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/ui/fragment/WeatherFragment.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.ui.fragment 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.View.OnClickListener 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import androidx.fragment.app.viewModels 10 | import androidx.lifecycle.ViewModelProvider.Factory 11 | import androidx.lifecycle.observe 12 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout 13 | import com.google.android.material.snackbar.Snackbar 14 | import dagger.android.support.AndroidSupportInjection 15 | import ezike.tobenna.myweather.R 16 | import ezike.tobenna.myweather.databinding.FragmentWeatherBinding 17 | import ezike.tobenna.myweather.ui.WeatherViewModel 18 | import ezike.tobenna.myweather.utils.Utilities 19 | import ezike.tobenna.myweather.utils.actionBar 20 | import ezike.tobenna.myweather.utils.toolbarTitle 21 | import kotlinx.coroutines.ExperimentalCoroutinesApi 22 | import kotlinx.coroutines.FlowPreview 23 | import javax.inject.Inject 24 | 25 | @ExperimentalCoroutinesApi 26 | @FlowPreview 27 | class WeatherFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener { 28 | 29 | @Inject 30 | lateinit var viewModelFactory: Factory 31 | 32 | private val weatherViewmodel: WeatherViewModel by viewModels { viewModelFactory } 33 | 34 | private lateinit var binding: FragmentWeatherBinding 35 | 36 | private val isLoading = true 37 | 38 | override fun onCreate(savedInstanceState: Bundle?) { 39 | super.onCreate(savedInstanceState) 40 | AndroidSupportInjection.inject(this) 41 | } 42 | 43 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 44 | binding = FragmentWeatherBinding.inflate(inflater, container, false).apply { 45 | viewModel = weatherViewmodel 46 | lifecycleOwner = viewLifecycleOwner 47 | } 48 | return binding.getRoot() 49 | } 50 | 51 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 52 | super.onViewCreated(view, savedInstanceState) 53 | binding.swipeRefresh.setOnRefreshListener(this) 54 | setActionBarTitle() 55 | } 56 | 57 | private fun setActionBarTitle() { 58 | weatherViewmodel.weatherLiveData.observe(this) { 59 | actionBar?.toolbarTitle = "${it.data?.weatherLocation?.name}, " + 60 | "${it.data?.weatherLocation?.country}" 61 | } 62 | } 63 | 64 | private fun showSnackBar(message: String, listener: OnClickListener) { 65 | Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG) 66 | .setAction(R.string.retry, listener) 67 | .show() 68 | } 69 | 70 | private fun isConnected(): Boolean { 71 | return if (!Utilities.isOnline(requireContext())) { 72 | showSnackBar(getString(R.string.no_internet), OnClickListener { 73 | snackRetryAction() 74 | }) 75 | false 76 | } else true 77 | } 78 | 79 | private fun snackRetryAction() { 80 | if (isConnected()) { 81 | retryFetch() 82 | } 83 | isConnected() 84 | } 85 | 86 | private fun retryFetch() { 87 | weatherViewmodel.fetchData() 88 | } 89 | 90 | override fun onRefresh() { 91 | if (isConnected()) { 92 | retryFetch() 93 | binding.swipeRefresh.isRefreshing = isLoading 94 | } 95 | binding.swipeRefresh.isRefreshing = false 96 | } 97 | } -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/utils/LocationHandler.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.utils; 2 | 3 | import android.annotation.SuppressLint; 4 | 5 | import androidx.lifecycle.Lifecycle; 6 | import androidx.lifecycle.LifecycleObserver; 7 | import androidx.lifecycle.LifecycleOwner; 8 | import androidx.lifecycle.OnLifecycleEvent; 9 | 10 | import com.google.android.gms.location.FusedLocationProviderClient; 11 | import com.google.android.gms.location.LocationCallback; 12 | import com.google.android.gms.location.LocationRequest; 13 | 14 | import javax.inject.Inject; 15 | 16 | import timber.log.Timber; 17 | 18 | public class LocationHandler implements LifecycleObserver { 19 | 20 | private static LocationHandler sInstance; 21 | 22 | @Inject 23 | FusedLocationProviderClient mFusedClient; 24 | 25 | private LocationRequest locationRequest; 26 | 27 | private LocationCallback mLocationCallback; 28 | 29 | private LocationHandler(LifecycleOwner lifecycleOwner, 30 | LocationCallback callback) { 31 | lifecycleOwner.getLifecycle().addObserver(this); 32 | mLocationCallback = callback; 33 | } 34 | 35 | public static LocationHandler getLocationHandler(LifecycleOwner lifecycleOwner, 36 | LocationCallback locationCallback) { 37 | if (sInstance == null) { 38 | sInstance = new LocationHandler(lifecycleOwner, locationCallback); 39 | } 40 | return sInstance; 41 | } 42 | 43 | private LocationRequest getLocationRequest() { 44 | try { 45 | locationRequest = new LocationRequest(); 46 | locationRequest.setNumUpdates(1); 47 | locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); 48 | locationRequest.setSmallestDisplacement(2); 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | return null; 52 | } 53 | return locationRequest; 54 | } 55 | 56 | @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) 57 | @SuppressLint("MissingPermission") 58 | void requestLocation() { 59 | try { 60 | if (mFusedClient != null) { 61 | getLocationRequest(); 62 | Timber.d("requesting location"); 63 | mFusedClient.requestLocationUpdates(locationRequest, mLocationCallback, null); 64 | } 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | 70 | @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) 71 | void stopLocationUpdates() { 72 | try { 73 | if (mFusedClient != null) { 74 | Timber.d("stop location requests"); 75 | mFusedClient.removeLocationUpdates(mLocationCallback); 76 | } 77 | } catch (Exception e) { 78 | e.printStackTrace(); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/utils/UnitSystem.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.utils; 2 | 3 | 4 | /** 5 | * @author tobennaezike 6 | * @since 23/03/19 7 | */ 8 | public enum UnitSystem { 9 | METRIC, IMPERIAL 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/utils/Utilities.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.utils; 2 | 3 | import android.content.Context; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.location.LocationManager; 7 | import android.net.ConnectivityManager; 8 | import android.net.NetworkInfo; 9 | import android.provider.Settings; 10 | import android.widget.Toast; 11 | 12 | import androidx.appcompat.app.AlertDialog; 13 | 14 | public class Utilities { 15 | 16 | /** 17 | * checks if device has internet connection 18 | */ 19 | public static boolean isOnline(Context context) { 20 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 21 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); 22 | return networkInfo != null && networkInfo.isConnected(); 23 | } 24 | 25 | 26 | /** 27 | * shows a dialog 28 | */ 29 | public static void showDialog(Context context, String title, String message, DialogInterface.OnClickListener positive, 30 | DialogInterface.OnClickListener negative) { 31 | new AlertDialog.Builder(context) 32 | .setTitle(title) 33 | .setMessage(message) 34 | .setPositiveButton("Ok", positive) 35 | .setNegativeButton("Cancel", negative) 36 | .create() 37 | .show(); 38 | } 39 | 40 | /** 41 | * checks if gps is enabled 42 | */ 43 | public static boolean isLocationProviderEnabled(LocationManager locationManager) { 44 | return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled( 45 | LocationManager.NETWORK_PROVIDER); 46 | } 47 | 48 | 49 | /** 50 | * enables GPS by opening settings 51 | */ 52 | public static void enableLocationProvider(Context context, String title, String message) { 53 | showDialog(context, title, message, (dialog, which) -> openSettingsActivity(context), null); 54 | } 55 | 56 | 57 | /** 58 | * open settings for enabling gps 59 | */ 60 | public static void openSettingsActivity(Context context) { 61 | context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 62 | } 63 | 64 | 65 | /** 66 | * show toast 67 | */ 68 | public static void showToast(Context context, String message, int length) { 69 | Toast.makeText(context, message, length).show(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/utils/WeatherIconUtils.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.utils; 2 | 3 | import android.content.Context; 4 | 5 | import com.github.pwittchen.weathericonview.WeatherIconView; 6 | 7 | import ezike.tobenna.myweather.R; 8 | 9 | public class WeatherIconUtils { 10 | 11 | public static void getIconResource(Context context, WeatherIconView iconView, String condition) { 12 | if (condition != null) { 13 | if (condition.contains("rain")) { 14 | iconView.setIconResource(context.getString(R.string.wi_rain)); 15 | } else if (condition.contains("snow")) { 16 | iconView.setIconResource(context.getString(R.string.wi_snow)); 17 | } else if (condition.contains("sun")) { 18 | iconView.setIconResource(context.getString(R.string.wi_day_sunny)); 19 | } else if (condition.contains("cloud")) { 20 | iconView.setIconResource(context.getString(R.string.wi_forecast_io_cloudy)); 21 | } else if (condition.contains("Clear")) { 22 | iconView.setIconResource(context.getString(R.string.wi_wu_clear)); 23 | } else if (condition.contains("Overcast")) { 24 | iconView.setIconResource(context.getString(R.string.wi_day_sunny_overcast)); 25 | } else if (condition.contains("sleet")) { 26 | iconView.setIconResource(context.getString(R.string.wi_day_sleet_storm)); 27 | } else if (condition.contains("Mist")) { 28 | iconView.setIconResource(context.getString(R.string.wi_fog)); 29 | } else if (condition.contains("drizzle")) { 30 | iconView.setIconResource(context.getString(R.string.wi_raindrops)); 31 | } else if (condition.contains("thunderstorm")) { 32 | iconView.setIconResource(context.getString(R.string.wi_wu_tstorms)); 33 | } else if (condition.contains("Thunder")) { 34 | iconView.setIconResource(context.getString(R.string.wi_thunderstorm)); 35 | } else if (condition.contains("Cloudy")) { 36 | iconView.setIconResource(context.getString(R.string.wi_forecast_io_cloudy)); 37 | } else if (condition.contains("Fog")) { 38 | iconView.setIconResource(context.getString(R.string.wi_forecast_io_fog)); 39 | } else if (condition.contains("Sunny")) { 40 | iconView.setIconResource(context.getString(R.string.wi_wu_mostlysunny)); 41 | } else if (condition.contains("Blizzard")) { 42 | iconView.setIconResource(context.getString(R.string.wi_snow_wind)); 43 | } else if (condition.contains("Ice")) { 44 | iconView.setIconResource(context.getString(R.string.wi_wu_chancesnow)); 45 | } else if (condition.contains("ice")) { 46 | iconView.setIconResource(context.getString(R.string.wi_forecast_io_snow)); 47 | } else if (condition.contains("Rain")) { 48 | iconView.setIconResource(context.getString(R.string.wi_rain_wind)); 49 | } else if (condition.contains("wind")) { 50 | iconView.setIconResource(context.getString(R.string.wi_windy)); 51 | } else if (condition.contains("Wind")) { 52 | iconView.setIconResource(context.getString(R.string.wi_strong_wind)); 53 | } else if (condition.contains("storm")) { 54 | iconView.setIconResource(context.getString(R.string.wi_storm_warning)); 55 | } else if (condition.contains("Storm")) { 56 | iconView.setIconResource(context.getString(R.string.wi_forecast_io_thunderstorm)); 57 | } else if (condition.contains("thunder")) { 58 | iconView.setIconResource(context.getString(R.string.wi_day_snow_thunderstorm)); 59 | } else { 60 | iconView.setIconResource(context.getString(R.string.wi_forecast_io_partly_cloudy_day)); 61 | } 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/utils/extensions.kt: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.utils 2 | 3 | import android.view.View 4 | import androidx.appcompat.app.ActionBar 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.fragment.app.Fragment 7 | 8 | var ActionBar.toolbarTitle: String? 9 | get() = title.toString() 10 | set(value) { 11 | title = value ?: title ?: "" 12 | } 13 | 14 | val Fragment.actionBar: ActionBar? 15 | get() = (requireActivity() as AppCompatActivity).supportActionBar 16 | 17 | var View.visible: Boolean 18 | get() = visibility == View.VISIBLE 19 | set(value) = if (value) visibility = View.VISIBLE else visibility = View.GONE -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/viewmodel/WeatherViewModelFactory.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.viewmodel; 2 | 3 | import java.util.Map; 4 | 5 | import javax.inject.Inject; 6 | import javax.inject.Provider; 7 | import javax.inject.Singleton; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.lifecycle.ViewModel; 11 | import androidx.lifecycle.ViewModelProvider; 12 | 13 | /** 14 | * @author tobennaezike 15 | */ 16 | @Singleton 17 | public class WeatherViewModelFactory implements ViewModelProvider.Factory { 18 | 19 | private final Map, Provider> creators; 20 | 21 | @Inject 22 | public WeatherViewModelFactory(Map, Provider> creators) { 23 | this.creators = creators; 24 | } 25 | 26 | @SuppressWarnings("unchecked") 27 | @NonNull 28 | @Override 29 | public T create(@NonNull Class modelClass) { 30 | 31 | Provider creator = creators.get(modelClass); 32 | if (creator == null) { 33 | for (Map.Entry, Provider> entry : creators.entrySet()) { 34 | if (modelClass.isAssignableFrom(entry.getKey())) { 35 | creator = entry.getValue(); 36 | break; 37 | } 38 | } 39 | } 40 | 41 | if (creator == null) { 42 | throw new IllegalArgumentException("unknown model class " + modelClass); 43 | } 44 | 45 | try { 46 | return (T) creator.get(); 47 | } catch (Exception e) { 48 | throw new RuntimeException(e); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/widget/WeatherWidgetProvider.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.widget; 2 | 3 | import android.app.AlarmManager; 4 | import android.app.PendingIntent; 5 | import android.appwidget.AppWidgetManager; 6 | import android.appwidget.AppWidgetProvider; 7 | import android.content.ComponentName; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.content.SharedPreferences; 11 | import android.graphics.Bitmap; 12 | import android.os.SystemClock; 13 | import android.widget.RemoteViews; 14 | 15 | import androidx.annotation.NonNull; 16 | 17 | import com.bumptech.glide.Glide; 18 | import com.bumptech.glide.request.RequestOptions; 19 | import com.bumptech.glide.request.target.AppWidgetTarget; 20 | import com.bumptech.glide.request.transition.Transition; 21 | 22 | import ezike.tobenna.myweather.R; 23 | import ezike.tobenna.myweather.ui.activity.MainActivity; 24 | 25 | /** 26 | * Implementation of App Widget functionality. 27 | */ 28 | public class WeatherWidgetProvider extends AppWidgetProvider { 29 | 30 | private PendingIntent pendingIntent; 31 | 32 | private AlarmManager manager; 33 | 34 | static final String WIDGET_PREF = "ezike.tobenna.myweather.ui.widget.pref"; 35 | static final String WIDGET_TEXT = "ezike.tobenna.myweather.ui.widget.text"; 36 | static final String WIDGET_LOCATION = "ezike.tobenna.myweather.ui.widget.location"; 37 | static final String WIDGET_ICON = "ezike.tobenna.myweather.ui.widget.icon"; 38 | 39 | static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, 40 | int appWidgetId) { 41 | 42 | SharedPreferences sharedPreferences = context.getSharedPreferences(WIDGET_PREF, Context.MODE_PRIVATE); 43 | String defaultValue = context.getString(R.string.no_data); 44 | String conditionText = sharedPreferences.getString(WIDGET_TEXT, defaultValue); 45 | String location = sharedPreferences.getString(WIDGET_LOCATION, defaultValue); 46 | String iconUrl = sharedPreferences.getString(WIDGET_ICON, defaultValue); 47 | 48 | RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.weather_widget); 49 | views.setTextViewText(R.id.appwidget_location, location); 50 | views.setTextViewText(R.id.appwidget_condition, context.getString(R.string.widget_forecast, conditionText)); 51 | 52 | Intent clickIntent = new Intent(context, MainActivity.class); 53 | PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, clickIntent, 0); 54 | views.setOnClickPendingIntent(R.id.appwidget_root, pendingIntent); 55 | 56 | // Display weather condition icon using Glide 57 | showWeatherIcon(context, appWidgetId, iconUrl, views); 58 | 59 | appWidgetManager.updateAppWidget(appWidgetId, views); 60 | } 61 | 62 | public static void updateWidget(@NonNull Context context) { 63 | AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 64 | int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, WeatherWidgetProvider.class)); 65 | for (int appWidgetId : appWidgetIds) { 66 | WeatherWidgetProvider.updateAppWidget(context, appWidgetManager, appWidgetId); 67 | } 68 | } 69 | 70 | private static void showWeatherIcon(Context context, int appWidgetId, String iconUrl, RemoteViews views) { 71 | AppWidgetTarget widgetTarget = new AppWidgetTarget(context, R.id.appwidget_icon, views, appWidgetId) { 72 | @Override 73 | public void onResourceReady(@NonNull Bitmap resource, Transition transition) { 74 | super.onResourceReady(resource, transition); 75 | } 76 | }; 77 | 78 | RequestOptions options = new RequestOptions(). 79 | override(300, 300).placeholder(R.drawable.day).error(R.drawable.day); 80 | 81 | Glide.with(context.getApplicationContext()) 82 | .asBitmap() 83 | .load("http:" + iconUrl) 84 | .apply(options) 85 | .into(widgetTarget); 86 | } 87 | 88 | @Override 89 | public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 90 | for (int appWidgetId : appWidgetIds) { 91 | updateAppWidget(context, appWidgetManager, appWidgetId); 92 | startWidgetUpdateService(context); 93 | } 94 | super.onUpdate(context, appWidgetManager, appWidgetIds); 95 | } 96 | 97 | private void startWidgetUpdateService(Context context) { 98 | manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 99 | final Intent updateIntent = new Intent(context, WidgetUpdateService.class); 100 | 101 | if (pendingIntent == null) { 102 | pendingIntent = PendingIntent.getService(context, 0, updateIntent, PendingIntent.FLAG_CANCEL_CURRENT); 103 | } 104 | manager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 60000, pendingIntent); 105 | } 106 | 107 | @Override 108 | public void onEnabled(Context context) { 109 | } 110 | 111 | @Override 112 | public void onDisabled(Context context) { 113 | if (manager != null) { 114 | manager.cancel(pendingIntent); 115 | } 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /app/src/main/java/ezike/tobenna/myweather/widget/WidgetUpdateService.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather.widget; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.IBinder; 6 | 7 | import timber.log.Timber; 8 | 9 | public class WidgetUpdateService extends Service { 10 | 11 | public WidgetUpdateService() { 12 | } 13 | 14 | @Override 15 | public IBinder onBind(Intent intent) { 16 | return null; 17 | } 18 | 19 | @Override 20 | public int onStartCommand(Intent intent, int flags, int startId) { 21 | WeatherWidgetProvider.updateWidget(this); 22 | Timber.d("widget update service started"); 23 | return super.onStartCommand(intent, flags, startId); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/example_appwidget_preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/drawable-nodpi/example_appwidget_preview.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/day.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/drawable-v24/day.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | 18 | 23 | 28 | 33 | 38 | 43 | 48 | 53 | 58 | 63 | 68 | 73 | 78 | 83 | 88 | 93 | 98 | 103 | 108 | 113 | 118 | 123 | 128 | 133 | 138 | 143 | 148 | 153 | 158 | 163 | 168 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 22 | 29 | 36 | 43 | 50 | 57 | 64 | 71 | 78 | 81 | 84 | 91 | 98 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_settings.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_today.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/widget_bg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/drawable/widget_bg.jpeg -------------------------------------------------------------------------------- /app/src/main/res/font/googlesans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/font/googlesans.ttf -------------------------------------------------------------------------------- /app/src/main/res/layout-land/fragment_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 24 | 25 | 34 | 35 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout-land/fragment_weather.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 21 | 22 | 28 | 29 | 40 | 41 | 51 | 52 | 61 | 62 | 70 | 71 | 82 | 83 | 94 | 95 | 96 | 107 | 108 | 119 | 120 | 121 | 122 | 128 | 129 | 139 | 140 | 151 | 152 | 163 | 164 | 177 | 178 | 188 | 189 | 199 | 200 | 210 | 211 | 220 | 221 | 232 | 233 | 234 | 235 | -------------------------------------------------------------------------------- /app/src/main/res/layout-v17/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 21 | 22 | 30 | 31 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 22 | 23 | 31 | 32 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_splash.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | 22 | 23 | 33 | 34 | 43 | 44 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_weather.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 22 | 23 | 29 | 30 | 40 | 41 | 51 | 52 | 61 | 62 | 71 | 72 | 83 | 84 | 95 | 96 | 107 | 108 | 119 | 120 | 121 | 122 | 128 | 129 | 139 | 140 | 151 | 152 | 163 | 164 | 177 | 178 | 188 | 189 | 199 | 200 | 210 | 211 | 220 | 221 | 233 | 234 | 235 | 236 | -------------------------------------------------------------------------------- /app/src/main/res/layout/weather_widget.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 14 | 15 | 30 | 31 | 32 | 44 | 45 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/res/menu/bottom_nav.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/mobile_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 16 | 17 | 21 | 22 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/transition/explode.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/transition/slide_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-v14/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 0dp 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | METRIC 5 | IMPERIAL 6 | 7 | 8 | 9 | Metric 10 | Imperial 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #8157AF 4 | #00574B 5 | #D81B60 6 | #51CEEEFC 7 | #7986CB 8 | #5A67AC 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 8dp 9 | 8dp 10 | 16sp 11 | 60sp 12 | 25sp 13 | 16dp 14 | 35sp 15 | 530dp 16 | 18sp 17 | 32dp 18 | 40sp 19 | 24dp 20 | 44sp 21 | 34sp 22 | 150dp 23 | 1dp 24 | 20sp 25 | 64dp 26 | 40dp 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MyWeather 3 | Settings 4 | Today 5 | Location Permssion 6 | You need to grant location permission in order to get weather updates 7 | weather_icon 8 | Retry 9 | Loading weather 10 | Precipitation 11 | Visibility 12 | Wind 13 | Unknown Error 14 | Check your internet connection 15 | You can set custom location in App Settings 16 | Device location not available 17 | You need to enable GPS in order to get weather updates 18 | ca-app-pub-8292346947931553~5764095591 19 | ca-app-pub-3940256099942544/6300978111 20 | weather condition 21 | Add widget 22 | condition_text 23 | No data 24 | widget background 25 | Forecast: 26 | Content loading 27 | Forecast: %1$s 28 | Data fetch failed.\nPlease check your internet connection and try again.\n\nSwipe down to retry 🙂 29 | About 30 | Version 1.0 31 | MyWeather 1.0 32 | \u2103 33 | Enable GPS 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/xml/network_security_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/xml/preferences.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/xml/weather_widget_info.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/test/java/ezike/tobenna/myweather/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package ezike.tobenna.myweather; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.61' 5 | ext.nav_version = '2.0.0' 6 | 7 | repositories { 8 | google() 9 | jcenter() 10 | maven { 11 | url 'https://maven.fabric.io/public' 12 | } 13 | mavenCentral() 14 | maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } 15 | } 16 | 17 | dependencies { 18 | classpath 'com.android.tools.build:gradle:4.0.0-alpha08' 19 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 20 | classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" 21 | classpath 'com.google.gms:google-services:4.3.3' 22 | classpath 'io.fabric.tools:gradle:1.31.2' 23 | } 24 | } 25 | 26 | allprojects { 27 | repositories { 28 | google() 29 | jcenter() 30 | mavenCentral() 31 | maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } 32 | } 33 | } 34 | 35 | ext { 36 | 37 | // global variables 38 | compile_sdk_version = 29 39 | kotlin_version = '1.3.61' 40 | min_sdk_version = 21 41 | 42 | // local variables (use def) 43 | def androidx_test_version = '1.2.0' 44 | def appcompat_version = '1.1.0' 45 | def constraint_layout_version = '1.1.3' 46 | def coroutines_android_version = '1.3.3' 47 | def expresso_version = '3.2.0' 48 | def glide_version = '4.11.0' 49 | def junit_version = '4.13' 50 | def lifecycle_version = '2.1.0' 51 | def livedata_version = '2.2.0-rc03' 52 | def material_version = '1.2.0-alpha03' 53 | def retrofit_version = '2.7.1' 54 | def room_version = '2.2.3' 55 | def truth_version = '1.0.1' 56 | def moshiCodeGen = '1.9.2' 57 | def timber_version = "4.7.1" 58 | def threetenabp_version = '1.2.2' 59 | def moshi_version = '1.9.2' 60 | def okhttp_version = '4.3.1' 61 | def weather_icon_version = "1.1.0" 62 | def dagger_version = '2.25.4' 63 | def preference_version = '1.1.0' 64 | def location_version = '17.0.0' 65 | def nav_version = '2.2.0-rc04' 66 | def ads_version = '18.3.0' 67 | def multi_dex_version = "1.0.3" 68 | def firebase_version = '17.2.1' 69 | def crashlytics_version = '2.10.1' 70 | def card_view_version = '1.0.0' 71 | def fragment_version = '1.1.0' 72 | 73 | 74 | libraries = [ 75 | // Kotlin standard library 76 | "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version", 77 | 78 | // Coroutines 79 | "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_android_version", 80 | "org.jetbrains.kotlinx:kotlinx-coroutines-android:${coroutines_android_version}", 81 | 82 | // Android UI and appcompat 83 | "androidx.appcompat:appcompat:$appcompat_version", 84 | "com.google.android.material:material:$material_version", 85 | "androidx.constraintlayout:constraintlayout:$constraint_layout_version", 86 | "androidx.fragment:fragment-ktx:$fragment_version", 87 | "androidx.cardview:cardview:$card_view_version", 88 | 89 | // Glide 90 | "com.github.bumptech.glide:glide:$glide_version", 91 | 92 | // ViewModel and LiveData 93 | "androidx.lifecycle:lifecycle-extensions:$lifecycle_version", 94 | "androidx.lifecycle:lifecycle-livedata-ktx:$livedata_version", 95 | "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version", 96 | 97 | // network & serialization 98 | "com.squareup.retrofit2:retrofit:$retrofit_version", 99 | "com.squareup.retrofit2:converter-moshi:$retrofit_version", 100 | 101 | // navigation 102 | "androidx.navigation:navigation-fragment-ktx:$nav_version", 103 | "androidx.navigation:navigation-ui-ktx:$nav_version", 104 | 105 | // Dagger core 106 | "com.google.dagger:dagger:$dagger_version", 107 | 108 | //Dagger Android 109 | "com.google.dagger:dagger-android:$dagger_version", 110 | "com.google.dagger:dagger-android-support:$dagger_version", 111 | 112 | // Google Ad 113 | "com.google.android.gms:play-services-ads:$ads_version", 114 | 115 | // Firebase 116 | "com.google.firebase:firebase-core:$firebase_version", 117 | 118 | //Crashlytics 119 | "com.crashlytics.sdk.android:crashlytics:$crashlytics_version", 120 | 121 | // ThreeTenAbp 122 | "com.jakewharton.threetenabp:threetenabp:$threetenabp_version", 123 | 124 | // Preference 125 | "androidx.preference:preference:$preference_version", 126 | 127 | // Location 128 | "com.google.android.gms:play-services-location:$location_version", 129 | 130 | // Moshi 131 | "com.squareup.moshi:moshi-kotlin:$moshi_version", 132 | 133 | // OkHttp3 134 | "com.squareup.okhttp3:logging-interceptor:$okhttp_version", 135 | 136 | // Timber 137 | "com.jakewharton.timber:timber:$timber_version", 138 | 139 | // Weather icons 140 | "com.github.pwittchen:weathericonview:$weather_icon_version", 141 | 142 | // MultiDex 143 | "com.android.support:multidex:$multi_dex_version", 144 | 145 | ] 146 | 147 | arch_libraries = [ 148 | // Room for database 149 | "androidx.room:room-ktx:$room_version" 150 | ] 151 | 152 | librariesKapt = [ 153 | "androidx.room:room-compiler:$room_version", 154 | "com.github.bumptech.glide:compiler:$glide_version", 155 | "com.squareup.moshi:moshi-kotlin-codegen:$moshiCodeGen", 156 | "com.google.dagger:dagger-compiler:$dagger_version", 157 | "com.google.dagger:dagger-android-processor:$dagger_version", 158 | ] 159 | 160 | testLibraries = [ 161 | "junit:junit:$junit_version", 162 | // Coroutines testing 163 | "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_android_version", 164 | 165 | // mocks 166 | 'org.mockito:mockito-core:3.2.4', 167 | 168 | // Architecture Components testing libraries 169 | "androidx.arch.core:core-testing:$lifecycle_version", 170 | 171 | "com.google.truth:truth:$truth_version", 172 | ] 173 | 174 | androidTestLibraries = [ 175 | "junit:junit:$junit_version", 176 | "androidx.test:runner:$androidx_test_version", 177 | "androidx.test:rules:$androidx_test_version", 178 | 179 | // Espresso 180 | "androidx.test.espresso:espresso-core:$expresso_version", 181 | "androidx.test.espresso:espresso-contrib:$expresso_version", 182 | "androidx.test.espresso:espresso-intents:$expresso_version", 183 | 184 | // Architecture Components testing libraries 185 | "androidx.arch.core:core-testing:$lifecycle_version", 186 | 187 | ] 188 | } 189 | 190 | task clean(type: Delete) { 191 | delete rootProject.buildDir 192 | } 193 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | android.enableJetifier=true 10 | android.useAndroidX=true 11 | org.gradle.jvmargs=-Xmx1536m 12 | android.databinding.enableV2=true 13 | # When configured, Gradle will run in incubating parallel mode. 14 | # This option should only be used with decoupled projects. More details, visit 15 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 16 | # org.gradle.parallel=true 17 | 18 | 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 17 11:14:07 WAT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | weatherLocation of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | weatherLocation of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo weatherLocation of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo weatherLocation of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /weather.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ezike/MyWeatherKotlinFlow/495010e2b9664aa990c5a32a293be49cd95b63aa/weather.jks --------------------------------------------------------------------------------