From 9d053bfb60ba5114e418e0f33c8d1d00a67a8113 Mon Sep 17 00:00:00 2001 From: hmalik144 Date: Tue, 1 Dec 2020 19:22:52 +0000 Subject: [PATCH] - new flavours added --- .idea/assetWizardSettings.xml | 271 ++++++++++++++- .idea/caches/build_file_checksums.ser | Bin 537 -> 537 bytes .idea/modules.xml | 6 +- app/build.gradle | 38 ++- app/src/atlasWeather/AndroidManifest.xml | 55 ++++ .../notification/NotificationData.kt | 2 +- .../notification/NotificationReceiver.kt | 82 +++++ .../atlasWeather/ui/BaseActivity.kt | 8 + .../atlasWeather/ui/BaseFragment.kt | 55 ++++ .../atlasWeather/ui/MainActivity.kt | 63 ++++ .../atlasWeather/ui/WorldItemFragment.kt | 50 +++ .../ui/details/FurtherInfoFragment.kt | 2 +- .../atlasWeather}/ui/home/HomeFragment.kt | 14 +- .../ui/home/adapter/EmptyViewHolder.kt | 6 + .../ui/home/adapter/ViewHolderCurrent.kt | 26 ++ .../ui/home/adapter/ViewHolderForecast.kt | 28 ++ .../home/adapter/ViewHolderFurtherDetails.kt | 24 ++ .../home/adapter}/WeatherRecyclerAdapter.kt | 70 +--- .../ui/settings/UnitSettingsActivity.kt | 7 +- .../ui/world/AddLocationFragment.kt | 4 +- .../atlasWeather}/ui/world/WorldFragment.kt | 6 +- .../ui/world/WorldRecyclerAdapter.kt | 2 +- .../atlasWeather/widget/BaseWidgetClass.kt | 37 +++ .../widget/MyWidgetRemoteViewsFactory.kt | 77 +++++ .../atlasWeather/widget/NewAppWidget.kt | 141 ++++++++ .../widget/WidgetRemoteViewsService.kt | 10 + .../atlasWeather/widget/WidgetUtils.kt | 15 + .../res/layout/activity_further_info.xml | 311 ++++++++++++++++++ .../atlasWeather/res/layout/activity_main.xml | 60 ++++ .../res/layout/list_item_current.xml} | 13 +- .../res/layout/list_item_forecast.xml} | 8 +- .../res/layout/list_item_further.xml} | 18 +- .../res/navigation/main_navigation.xml | 74 +++++ app/src/atlasWeather/res/values/strings.xml | 4 + .../res/values/styles.xml | 3 +- app/src/atlasWeather/res/xml/prefs.xml | 42 +++ app/src/main/AndroidManifest.xml | 48 +-- .../atlas_weather/application/AppClass.kt | 2 +- .../data/location/LocationProvider.kt | 1 - .../data/repository/Repository.kt | 2 +- .../data/repository/RepositoryImpl.kt | 4 +- .../atlas_weather/data/room/WeatherDao.kt | 3 +- .../ServicesHelper.kt | 4 +- .../model/forecast/WeatherDisplay.kt | 4 +- .../atlas_weather/model/widget/WidgetData.kt | 4 +- .../atlas_weather/ui/home/BaseActivity.kt | 30 -- .../h_mal/atlas_weather/utils/ViewUtils.kt | 9 +- .../atlas_weather/viewmodel/MainViewModel.kt | 1 - .../atlas_weather/viewmodel/WorldViewModel.kt | 38 ++- .../main/res/drawable/ic_baseline_add_24.xml | 5 + .../res/drawable/ic_baseline_cloud_off_24.xml | 5 + .../main/res/layout/activity_add_forecast.xml | 78 ++--- app/src/main/res/layout/activity_main.xml | 53 --- .../res/layout/activity_main_navigation.xml | 6 +- app/src/main/res/layout/db_list_item.xml | 153 +++++---- app/src/main/res/layout/fragment__two.xml | 26 +- app/src/main/res/layout/fragment_home.xml | 6 +- app/src/main/res/layout/fragment_main.xml | 67 +--- app/src/main/res/layout/new_app_widget.xml | 20 +- app/src/main/res/values/colors.xml | 6 +- app/src/main/res/values/strings.xml | 101 +----- app/src/main/res/xml/pref_data_sync.xml | 21 -- app/src/main/res/xml/pref_general.xml | 33 -- app/src/main/res/xml/pref_headers.xml | 20 -- app/src/main/res/xml/pref_notification.xml | 27 -- app/src/main/res/xml/prefs.xml | 42 --- app/src/monoWeather/AndroidManifest.xml | 55 ++++ app/src/monoWeather/ic_launcher-playstore.png | Bin 0 -> 19727 bytes .../monoWeather/ui/BaseActivity.kt | 8 + .../monoWeather}/ui/BaseFragment.kt | 2 +- .../monoWeather}/ui/MainActivity.kt | 13 +- .../monoWeather}/ui/WorldItemFragment.kt | 4 +- .../ui/details/FurtherInfoFragment.kt | 45 +++ .../monoWeather/ui/home/HomeFragment.kt | 102 ++++++ .../ui/home/adapter/EmptyViewHolder.kt | 6 + .../ui/home/adapter/ViewHolderCurrent.kt | 26 ++ .../ui/home/adapter/WeatherRecyclerAdapter.kt | 112 +++++++ .../home/adapter/forecast/GridCellHolder.kt | 24 ++ .../adapter/forecast/GridForecastAdapter.kt | 38 +++ .../adapter/forecast/ViewHolderForecast.kt | 24 ++ .../forecastDaily/ViewHolderForecastDaily.kt | 24 ++ .../ui/home/adapter/further/GridAdapter.kt | 26 ++ .../further/ViewHolderFurtherDetails.kt | 21 ++ .../ui/settings/UnitSettingsActivity.kt | 87 +++++ .../ui/world/AddLocationFragment.kt | 56 ++++ .../monoWeather/ui/world/WorldFragment.kt | 85 +++++ .../ui/world/WorldRecyclerAdapter.kt | 102 ++++++ .../monoWeather}/widget/BaseWidgetClass.kt | 4 +- .../widget/MyWidgetRemoteViewsFactory.kt | 78 +++++ .../monoWeather/widget/NewAppWidget.kt | 141 ++++++++ .../widget/WidgetRemoteViewsService.kt | 10 + .../monoWeather/widget/WidgetUtils.kt | 15 + .../res/drawable/ic_launcher_foreground.xml | 15 + .../res/layout/list_item_forecast.xml | 72 ++++ .../res/layout/mono_forecast_grid_item.xml | 50 +++ .../res/layout/mono_item_forecast.xml | 25 ++ .../monoWeather/res/layout/mono_item_one.xml | 84 +++++ .../monoWeather/res/layout/mono_item_two.xml | 21 ++ .../res/layout/mono_item_two_cell.xml | 28 ++ .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 1609 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 2930 bytes .../res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 1146 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 1720 bytes .../res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 2193 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 3944 bytes .../res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 3871 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 6876 bytes .../res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 5377 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 9738 bytes .../res/navigation/main_navigation.xml | 10 +- .../res/values/ic_launcher_background.xml | 4 + app/src/monoWeather/res/values/strings.xml | 54 +++ app/src/monoWeather/res/values/styles.xml | 92 ++++++ app/src/monoWeather/res/xml/prefs_screen.xml | 10 + 115 files changed, 3282 insertions(+), 747 deletions(-) create mode 100644 app/src/atlasWeather/AndroidManifest.xml rename app/src/{main/java/com/appttude/h_mal/atlas_weather => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather}/notification/NotificationData.kt (62%) create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/notification/NotificationReceiver.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseActivity.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseFragment.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/MainActivity.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/WorldItemFragment.kt rename app/src/{main/java/com/appttude/h_mal/atlas_weather => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather}/ui/details/FurtherInfoFragment.kt (95%) rename app/src/{main/java/com/appttude/h_mal/atlas_weather => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather}/ui/home/HomeFragment.kt (88%) create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/EmptyViewHolder.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderCurrent.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderForecast.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderFurtherDetails.kt rename app/src/{main/java/com/appttude/h_mal/atlas_weather/ui => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter}/WeatherRecyclerAdapter.kt (51%) rename app/src/{main/java/com/appttude/h_mal/atlas_weather => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather}/ui/settings/UnitSettingsActivity.kt (94%) rename app/src/{main/java/com/appttude/h_mal/atlas_weather => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather}/ui/world/AddLocationFragment.kt (93%) rename app/src/{main/java/com/appttude/h_mal/atlas_weather => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather}/ui/world/WorldFragment.kt (88%) rename app/src/{main/java/com/appttude/h_mal/atlas_weather => atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather}/ui/world/WorldRecyclerAdapter.kt (98%) create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/BaseWidgetClass.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/MyWidgetRemoteViewsFactory.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/NewAppWidget.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetRemoteViewsService.kt create mode 100644 app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetUtils.kt create mode 100644 app/src/atlasWeather/res/layout/activity_further_info.xml create mode 100644 app/src/atlasWeather/res/layout/activity_main.xml rename app/src/{main/res/layout/list_item4.xml => atlasWeather/res/layout/list_item_current.xml} (90%) rename app/src/{main/res/layout/list_item_layout2.xml => atlasWeather/res/layout/list_item_forecast.xml} (92%) rename app/src/{main/res/layout/list_item3.xml => atlasWeather/res/layout/list_item_further.xml} (93%) create mode 100644 app/src/atlasWeather/res/navigation/main_navigation.xml create mode 100644 app/src/atlasWeather/res/values/strings.xml rename app/src/{main => atlasWeather}/res/values/styles.xml (94%) create mode 100644 app/src/atlasWeather/res/xml/prefs.xml rename app/src/main/java/com/appttude/h_mal/atlas_weather/{notification => helper}/ServicesHelper.kt (96%) delete mode 100644 app/src/main/java/com/appttude/h_mal/atlas_weather/ui/home/BaseActivity.kt create mode 100644 app/src/main/res/drawable/ic_baseline_add_24.xml create mode 100644 app/src/main/res/drawable/ic_baseline_cloud_off_24.xml delete mode 100644 app/src/main/res/layout/activity_main.xml delete mode 100644 app/src/main/res/xml/pref_data_sync.xml delete mode 100644 app/src/main/res/xml/pref_general.xml delete mode 100644 app/src/main/res/xml/pref_headers.xml delete mode 100644 app/src/main/res/xml/pref_notification.xml delete mode 100644 app/src/main/res/xml/prefs.xml create mode 100644 app/src/monoWeather/AndroidManifest.xml create mode 100644 app/src/monoWeather/ic_launcher-playstore.png create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/BaseActivity.kt rename app/src/{main/java/com/appttude/h_mal/atlas_weather => monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather}/ui/BaseFragment.kt (96%) rename app/src/{main/java/com/appttude/h_mal/atlas_weather => monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather}/ui/MainActivity.kt (87%) rename app/src/{main/java/com/appttude/h_mal/atlas_weather => monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather}/ui/WorldItemFragment.kt (88%) create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/details/FurtherInfoFragment.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/HomeFragment.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/EmptyViewHolder.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/ViewHolderCurrent.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/WeatherRecyclerAdapter.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/forecast/GridCellHolder.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/forecast/GridForecastAdapter.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/forecast/ViewHolderForecast.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/forecastDaily/ViewHolderForecastDaily.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/further/GridAdapter.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/home/adapter/further/ViewHolderFurtherDetails.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/settings/UnitSettingsActivity.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/world/AddLocationFragment.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/world/WorldFragment.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/ui/world/WorldRecyclerAdapter.kt rename app/src/{main/java/com/appttude/h_mal/atlas_weather => monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather}/widget/BaseWidgetClass.kt (88%) create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/widget/MyWidgetRemoteViewsFactory.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/widget/NewAppWidget.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/widget/WidgetRemoteViewsService.kt create mode 100644 app/src/monoWeather/java/com/appttude/h_mal/atlas_weather/monoWeather/widget/WidgetUtils.kt create mode 100644 app/src/monoWeather/res/drawable/ic_launcher_foreground.xml create mode 100644 app/src/monoWeather/res/layout/list_item_forecast.xml create mode 100644 app/src/monoWeather/res/layout/mono_forecast_grid_item.xml create mode 100644 app/src/monoWeather/res/layout/mono_item_forecast.xml create mode 100644 app/src/monoWeather/res/layout/mono_item_one.xml create mode 100644 app/src/monoWeather/res/layout/mono_item_two.xml create mode 100644 app/src/monoWeather/res/layout/mono_item_two_cell.xml create mode 100644 app/src/monoWeather/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/monoWeather/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/monoWeather/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/monoWeather/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/monoWeather/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/monoWeather/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/monoWeather/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/monoWeather/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/monoWeather/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/monoWeather/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/monoWeather/res/mipmap-xxxhdpi/ic_launcher_round.png rename app/src/{main => monoWeather}/res/navigation/main_navigation.xml (87%) create mode 100644 app/src/monoWeather/res/values/ic_launcher_background.xml create mode 100644 app/src/monoWeather/res/values/strings.xml create mode 100644 app/src/monoWeather/res/values/styles.xml create mode 100644 app/src/monoWeather/res/xml/prefs_screen.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index dd49c39..053c97f 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -8,6 +8,17 @@ + + + + + + + + @@ -61,6 +169,7 @@ @@ -78,6 +187,40 @@ + + + + + + + + + + + + + + + + + + + + + - @@ -121,7 +378,7 @@ @@ -132,7 +389,7 @@ diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index a3c902cb198008d487b7b2f3fc3bbfd1d0fa4daf..1a7278dd44235148f15443e9ba21a006a835c6cf 100644 GIT binary patch delta 35 tcmV+;0NnqX1epYom;@g__S2D^cM!HL(@FLtcWE=J0gcXocXX2@0rn5}4~GB% delta 35 tcmV+;0NnqX1epYom;?+CZJ&{xcM#zBts2Kfk@D~KzpOgDfzy*C0rnkf5wQRO diff --git a/.idea/modules.xml b/.idea/modules.xml index aa616a2..d401ed3 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,10 +2,8 @@ - - - - + + diff --git a/app/build.gradle b/app/build.gradle index fb1582b..67eb58f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "com.appttude.h_mal.atlas_weather" minSdkVersion 23 targetSdkVersion 30 - versionCode 1 - versionName "1.0" + versionCode 2 + versionName "2.0" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' vectorDrawables.useSupportLibrary = true @@ -36,12 +36,34 @@ android { jvmTarget = "1.8" } + flavorDimensions "default" + productFlavors{ + atlasWeather{ + applicationIdSuffix ".atlasWeather" + } + monoWeather{ + applicationIdSuffix ".monoWeather" + } + } + sourceSets { + atlasWeather { + manifest { + srcFile 'src/atlasWeather/AndroidManifest.xml' + } + } + monoWeather { + manifest { + srcFile 'src/monoWeather/AndroidManifest.xml' + } + } + } + } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.0' - implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' @@ -55,7 +77,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:rules:1.2.0' testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" - implementation "org.jetbrains.kotlin:kotlin-test:1.3.71" + implementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version" // android unit testing and espresso androidTestImplementation 'androidx.test.ext:junit:1.1.1' @@ -76,11 +98,13 @@ dependencies { androidTestImplementation "io.mockk:mockk-android:$mockk_ver" // Retrofit - implementation 'com.squareup.retrofit2:retrofit:2.8.1' - implementation 'com.squareup.retrofit2:converter-gson:2.8.1' + def retrofit_ver = "2.8.1" + implementation "com.squareup.retrofit2:retrofit:$retrofit_ver" + implementation "com.squareup.retrofit2:converter-gson:$retrofit_ver" // Shared prefs - implementation "androidx.preference:preference-ktx:1.1.1" + def prefs_ver = "1.1.1" + implementation "androidx.preference:preference-ktx:$prefs_ver" //Kodein Dependency Injection def kodein_version = "6.2.1" diff --git a/app/src/atlasWeather/AndroidManifest.xml b/app/src/atlasWeather/AndroidManifest.xml new file mode 100644 index 0000000..e1e047e --- /dev/null +++ b/app/src/atlasWeather/AndroidManifest.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/notification/NotificationData.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/notification/NotificationData.kt similarity index 62% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/notification/NotificationData.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/notification/NotificationData.kt index f7dedd9..89525fd 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/notification/NotificationData.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/notification/NotificationData.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.notification +package com.appttude.h_mal.atlas_weather.atlasWeather.notification import android.graphics.Bitmap diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/notification/NotificationReceiver.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/notification/NotificationReceiver.kt new file mode 100644 index 0000000..7ca4dc7 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/notification/NotificationReceiver.kt @@ -0,0 +1,82 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.notification + +import android.Manifest +import android.app.Notification +import android.app.NotificationManager +import android.app.PendingIntent +import android.app.TaskStackBuilder +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Build +import androidx.core.app.ActivityCompat +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.MainActivity +import com.appttude.h_mal.atlas_weather.helper.ServicesHelper +import com.appttude.h_mal.atlas_weather.model.weather.FullWeather +import com.appttude.h_mal.atlas_weather.utils.displayToast +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import org.kodein.di.KodeinAware +import org.kodein.di.LateInitKodein +import org.kodein.di.generic.instance + +/** + * Created by h_mal on 29/04/2018. + * Updated by h_mal on 27/11/2020 + */ +const val NOTIFICATION_CHANNEL_ID = "my_notification_channel_1" +class NotificationReceiver : BroadcastReceiver() { + + private val kodein = LateInitKodein() + private val helper : ServicesHelper by kodein.instance() + + override fun onReceive(context: Context, intent: Intent) { + kodein.baseKodein = (context.applicationContext as KodeinAware).kodein + + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + context.displayToast("Please enable location permissions") + return + } + + if (helper.isEnabled()) { + CoroutineScope(Dispatchers.IO).launch { + helper.getData()?.let { + pushNotif(context, it) + } + } + } + helper.setFirstTimer() + } + + private fun pushNotif(context: Context?, weather: FullWeather) { + val notificationIntent = Intent(context, MainActivity::class.java) + + val stackBuilder = TaskStackBuilder.create(context).apply { + addParentStack(MainActivity::class.java) + addNextIntent(notificationIntent) + } + + val pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) + + val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Notification.Builder(context, NOTIFICATION_CHANNEL_ID ) + } else { + Notification.Builder(context) + } + + val notification = builder.setContentTitle("Weather App") + .setContentText(weather.current?.main + "°C") + .setSmallIcon(R.mipmap.ic_notif) //change icon +// .setLargeIcon(Icon.createWithResource(context, getImageResource(forecastItem.getCurrentForecast().getIconURL(), context))) + .setAutoCancel(true) + .setContentIntent(pendingIntent).build() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + builder.setChannelId(NOTIFICATION_CHANNEL_ID) + } + val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + notificationManager.notify(0, notification) + } +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseActivity.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseActivity.kt new file mode 100644 index 0000000..c8b3a5a --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseActivity.kt @@ -0,0 +1,8 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui + +import androidx.appcompat.app.AppCompatActivity + +abstract class BaseActivity : AppCompatActivity(){ + + +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseFragment.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseFragment.kt new file mode 100644 index 0000000..5e091cf --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/BaseFragment.kt @@ -0,0 +1,55 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui + +import android.annotation.SuppressLint +import android.content.pm.PackageManager +import android.view.View +import androidx.core.app.ActivityCompat +import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer +import com.appttude.h_mal.atlas_weather.utils.Event +import com.appttude.h_mal.atlas_weather.utils.displayToast +import com.appttude.h_mal.atlas_weather.utils.hide +import com.appttude.h_mal.atlas_weather.utils.show +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +abstract class BaseFragment: Fragment(){ + + // toggle visibility of progress spinner while async operations are taking place + fun progressBarStateObserver(progressBar: View) = Observer> { + when(it.getContentIfNotHandled()){ + true -> { + progressBar.show() + } + false -> { + progressBar.hide() + } + } + } + + // display a toast when operation fails + fun errorObserver() = Observer> { + it.getContentIfNotHandled()?.let { message -> + displayToast(message) + } + } + + @SuppressLint("MissingPermission") + fun getPermissionResult( + permission: String, + permissionCode: Int, + permissionGranted: () -> Unit + ){ + if (ActivityCompat.checkSelfPermission(requireContext(), permission) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(arrayOf(permission), permissionCode) + return + }else{ + CoroutineScope(Dispatchers.Main).launch{ + permissionGranted.invoke() + } + } + + } + +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/MainActivity.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/MainActivity.kt new file mode 100644 index 0000000..0100fe6 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/MainActivity.kt @@ -0,0 +1,63 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui + +import android.content.Intent +import android.os.Bundle +import android.view.Menu +import android.view.MenuItem +import androidx.navigation.NavController +import androidx.navigation.fragment.NavHostFragment +import androidx.navigation.ui.AppBarConfiguration +import androidx.navigation.ui.setupActionBarWithNavController +import androidx.navigation.ui.setupWithNavController +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.settings.UnitSettingsActivity +import com.google.android.material.bottomnavigation.BottomNavigationView +import kotlinx.android.synthetic.atlasWeather.activity_main.* + + +class MainActivity : BaseActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val navView: BottomNavigationView = findViewById(R.id.nav_view) + setSupportActionBar(toolbar) + + val navHost = supportFragmentManager + .findFragmentById(R.id.container) as NavHostFragment + val navController = navHost.navController + navController.setGraph(R.navigation.main_navigation) + + setupBottomBar(navView, navController) + + } + + private fun setupBottomBar(navView: BottomNavigationView, navController: NavController) { + val tabs = setOf(R.id.nav_home, R.id.nav_world) + val appBarConfiguration = AppBarConfiguration(tabs) + + setupActionBarWithNavController(navController, appBarConfiguration) + navView.setupWithNavController(navController) + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.menu_main, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + when (item.itemId) { + R.id.action_settings -> { + val i = Intent(this, UnitSettingsActivity::class.java) + startActivity(i) + return true + } + } + return super.onOptionsItemSelected(item) + } +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/WorldItemFragment.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/WorldItemFragment.kt new file mode 100644 index 0000000..f134378 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/WorldItemFragment.kt @@ -0,0 +1,50 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.WorldItemFragmentArgs +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.home.adapter.WeatherRecyclerAdapter +import com.appttude.h_mal.atlas_weather.utils.navigateTo +import kotlinx.android.synthetic.main.fragment_home.* +import kotlinx.android.synthetic.main.fragment_main.* + + +class WorldItemFragment : Fragment() { + private var param1: WeatherDisplay? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + param1 = WorldItemFragmentArgs.fromBundle(requireArguments()).weatherDisplay + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_home, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val recyclerAdapter = WeatherRecyclerAdapter { + val directions = + WorldItemFragmentDirections.actionWorldItemFragmentToFurtherDetailsFragment(it) + navigateTo(directions) + } + + param1?.let { recyclerAdapter.addCurrent(it) } + + forecast_listview.apply { + layoutManager = LinearLayoutManager(context) + adapter = recyclerAdapter + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/details/FurtherInfoFragment.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/details/FurtherInfoFragment.kt similarity index 95% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/ui/details/FurtherInfoFragment.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/details/FurtherInfoFragment.kt index 21f7853..d0288fc 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/details/FurtherInfoFragment.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/details/FurtherInfoFragment.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.ui.details +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.details import android.os.Bundle import android.view.LayoutInflater diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/home/HomeFragment.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/HomeFragment.kt similarity index 88% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/ui/home/HomeFragment.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/HomeFragment.kt index 5259b0c..ec3f633 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/home/HomeFragment.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/HomeFragment.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.ui.home +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.home import android.Manifest import android.annotation.SuppressLint @@ -13,16 +13,16 @@ import androidx.lifecycle.observe import androidx.recyclerview.widget.LinearLayoutManager import com.appttude.h_mal.atlas_weather.R import com.appttude.h_mal.atlas_weather.application.LOCATION_PERMISSION_REQUEST -import com.appttude.h_mal.atlas_weather.ui.BaseFragment -import com.appttude.h_mal.atlas_weather.ui.WeatherRecyclerAdapter +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.BaseFragment +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.home.adapter.WeatherRecyclerAdapter import com.appttude.h_mal.atlas_weather.utils.displayToast import com.appttude.h_mal.atlas_weather.utils.navigateTo import com.appttude.h_mal.atlas_weather.viewmodel.ApplicationViewModelFactory import com.appttude.h_mal.atlas_weather.viewmodel.MainViewModel -import kotlinx.android.synthetic.main.activity_add_forecast.* -import kotlinx.android.synthetic.main.fragment_main.* +import kotlinx.android.synthetic.main.fragment_home.* import org.kodein.di.KodeinAware import org.kodein.di.android.x.kodein + import org.kodein.di.generic.instance @@ -63,7 +63,9 @@ class HomeFragment : BaseFragment(), KodeinAware { swipe_refresh.apply { setOnRefreshListener { - viewModel.fetchData() + getPermissionResult(Manifest.permission.ACCESS_FINE_LOCATION, LOCATION_PERMISSION_REQUEST){ + viewModel.fetchData() + } isRefreshing = true } } diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/EmptyViewHolder.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/EmptyViewHolder.kt new file mode 100644 index 0000000..d0bdd52 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/EmptyViewHolder.kt @@ -0,0 +1,6 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.home.adapter + +import android.view.View +import androidx.recyclerview.widget.RecyclerView + +class EmptyViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderCurrent.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderCurrent.kt new file mode 100644 index 0000000..eadc3e8 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderCurrent.kt @@ -0,0 +1,26 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.home.adapter + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay +import com.appttude.h_mal.atlas_weather.utils.loadImage + +class ViewHolderCurrent(listItemView: View) : RecyclerView.ViewHolder(listItemView) { + + var locationTV: TextView = listItemView.findViewById(R.id.location_main_4) + var conditionTV: TextView = listItemView.findViewById(R.id.condition_main_4) + var weatherIV: ImageView = listItemView.findViewById(R.id.icon_main_4) + var avgTempTV: TextView = listItemView.findViewById(R.id.temp_main_4) + var tempUnit: TextView = listItemView.findViewById(R.id.temp_unit_4) + + fun bindData(weather: WeatherDisplay?){ + locationTV.text = weather?.location + conditionTV.text = weather?.description + weatherIV.loadImage(weather?.iconURL) + avgTempTV.text = weather?.averageTemp?.toInt().toString() + tempUnit.text = weather?.unit + } +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderForecast.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderForecast.kt new file mode 100644 index 0000000..a5a5674 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderForecast.kt @@ -0,0 +1,28 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.home.adapter + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.model.forecast.Forecast +import com.appttude.h_mal.atlas_weather.utils.loadImage + +class ViewHolderForecast(itemView: View) : RecyclerView.ViewHolder(itemView) { + + var dateTV: TextView = itemView.findViewById(R.id.list_date) + var dayTV: TextView = itemView.findViewById(R.id.list_day) + var conditionTV: TextView = itemView.findViewById(R.id.list_condition) + var weatherIV: ImageView = itemView.findViewById(R.id.list_icon) + var mainTempTV: TextView = itemView.findViewById(R.id.list_main_temp) + var minorTempTV: TextView = itemView.findViewById(R.id.list_minor_temp) + + fun bindView(forecast: Forecast?) { + dateTV.text = forecast?.date + dayTV.text = forecast?.day + conditionTV.text = forecast?.condition + weatherIV.loadImage(forecast?.weatherIcon) + mainTempTV.text = forecast?.mainTemp + minorTempTV.text = forecast?.minorTemp + } +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderFurtherDetails.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderFurtherDetails.kt new file mode 100644 index 0000000..d5fa7ef --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/ViewHolderFurtherDetails.kt @@ -0,0 +1,24 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.home.adapter + +import android.view.View +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay + +internal class ViewHolderFurtherDetails(itemView: View) : RecyclerView.ViewHolder(itemView) { + + var windSpeed: TextView = itemView.findViewById(R.id.windspeed) + var windDirection: TextView = itemView.findViewById(R.id.winddirection) + var precipitation: TextView = itemView.findViewById(R.id.precip_) + var humidity: TextView = itemView.findViewById(R.id.humidity_) + var clouds: TextView = itemView.findViewById(R.id.clouds_) + + fun bindData(weather: WeatherDisplay?){ + windSpeed.text = weather?.windSpeed + windDirection.text = weather?.windDirection + precipitation.text = weather?.precipitation + humidity.text = weather?.humidity + clouds.text = weather?.clouds + } +} \ No newline at end of file diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/WeatherRecyclerAdapter.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/WeatherRecyclerAdapter.kt similarity index 51% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/ui/WeatherRecyclerAdapter.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/WeatherRecyclerAdapter.kt index d5d5386..dfb54c9 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/WeatherRecyclerAdapter.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/home/adapter/WeatherRecyclerAdapter.kt @@ -1,15 +1,12 @@ -package com.appttude.h_mal.atlas_weather.ui +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.home.adapter import android.view.View import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.appttude.h_mal.atlas_weather.R import com.appttude.h_mal.atlas_weather.model.forecast.Forecast import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay import com.appttude.h_mal.atlas_weather.utils.generateView -import com.appttude.h_mal.atlas_weather.utils.loadImage class WeatherRecyclerAdapter( val itemClick: (Forecast) -> Unit @@ -28,15 +25,15 @@ class WeatherRecyclerAdapter( EmptyViewHolder(emptyViewHolder) } is ViewType.Current -> { - val viewCurrent = parent.generateView(R.layout.list_item4) + val viewCurrent = parent.generateView(R.layout.list_item_current) ViewHolderCurrent(viewCurrent) } is ViewType.Forecast -> { - val viewForecast = parent.generateView(R.layout.list_item_layout2) + val viewForecast = parent.generateView(R.layout.list_item_forecast) ViewHolderForecast(viewForecast) } is ViewType.Further -> { - val viewFurther = parent.generateView(R.layout.list_item3) + val viewFurther = parent.generateView(R.layout.list_item_further) ViewHolderFurtherDetails(viewFurther) } } @@ -49,7 +46,7 @@ class WeatherRecyclerAdapter( object Further : ViewType() } - private fun getDataType(type: Int): ViewType{ + private fun getDataType(type: Int): ViewType { return when (type){ 0 -> ViewType.Empty 1 -> ViewType.Current @@ -83,7 +80,7 @@ class WeatherRecyclerAdapter( is ViewType.Forecast -> { val viewHolderForecast = holder as ViewHolderForecast - weather?.forecast?.get(position)?.let { i -> + weather?.forecast?.get(position - 1)?.let { i -> viewHolderForecast.bindView(i) viewHolderForecast.itemView.setOnClickListener { itemClick(i) @@ -103,59 +100,4 @@ class WeatherRecyclerAdapter( return 2 + (weather?.forecast?.size?: 0) } - internal class ViewHolderCurrent(listItemView: View) : RecyclerView.ViewHolder(listItemView) { - - var locationTV: TextView = listItemView.findViewById(R.id.location_main_4) - var conditionTV: TextView = listItemView.findViewById(R.id.condition_main_4) - var weatherIV: ImageView = listItemView.findViewById(R.id.icon_main_4) - var avgTempTV: TextView = listItemView.findViewById(R.id.temp_main_4) - var tempUnit: TextView = listItemView.findViewById(R.id.temp_unit_4) - - fun bindData(weather: WeatherDisplay?){ - locationTV.text = weather?.location - conditionTV.text = weather?.description - weatherIV.loadImage(weather?.iconURL) - avgTempTV.text = weather?.averageTemp?.toInt().toString() - tempUnit.text = weather?.unit - } - } - - internal class ViewHolderForecast(itemView: View) : RecyclerView.ViewHolder(itemView) { - - var dateTV: TextView = itemView.findViewById(R.id.list_date) - var dayTV: TextView = itemView.findViewById(R.id.list_day) - var conditionTV: TextView = itemView.findViewById(R.id.list_condition) - var weatherIV: ImageView = itemView.findViewById(R.id.list_icon) - var mainTempTV: TextView = itemView.findViewById(R.id.list_main_temp) - var minorTempTV: TextView = itemView.findViewById(R.id.list_minor_temp) - - fun bindView(forecast: Forecast?) { - dateTV.text = forecast?.date - dayTV.text = forecast?.day - conditionTV.text = forecast?.condition - weatherIV.loadImage(forecast?.weatherIcon) - mainTempTV.text = forecast?.mainTemp - minorTempTV.text = forecast?.minorTemp - } - } - - internal class ViewHolderFurtherDetails(itemView: View) : RecyclerView.ViewHolder(itemView) { - - var windSpeed: TextView = itemView.findViewById(R.id.windspeed) - var windDirection: TextView = itemView.findViewById(R.id.winddirection) - var precipitation: TextView = itemView.findViewById(R.id.precip_) - var humidity: TextView = itemView.findViewById(R.id.humidity_) - var clouds: TextView = itemView.findViewById(R.id.clouds_) - - fun bindData(weather: WeatherDisplay?){ - windSpeed.text = weather?.windSpeed - windDirection.text = weather?.windDirection - precipitation.text = weather?.precipitation - humidity.text = weather?.humidity - clouds.text = weather?.clouds - } - } - - internal class EmptyViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) - } \ No newline at end of file diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/settings/UnitSettingsActivity.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/settings/UnitSettingsActivity.kt similarity index 94% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/ui/settings/UnitSettingsActivity.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/settings/UnitSettingsActivity.kt index 034eab0..b95ee82 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/settings/UnitSettingsActivity.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/settings/UnitSettingsActivity.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.ui.settings +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.settings import android.app.AlarmManager import android.app.PendingIntent @@ -12,13 +12,12 @@ import android.preference.PreferenceActivity import android.preference.PreferenceFragment import androidx.preference.PreferenceManager import com.appttude.h_mal.atlas_weather.R -import com.appttude.h_mal.atlas_weather.notification.NotificationReceiver -import com.appttude.h_mal.atlas_weather.widget.NewAppWidget +import com.appttude.h_mal.atlas_weather.atlasWeather.notification.NotificationReceiver +import com.appttude.h_mal.atlas_weather.atlasWeather.widget.NewAppWidget import java.util.* class UnitSettingsActivity : PreferenceActivity() { - private val TAG = javaClass.simpleName private var prefListener: OnSharedPreferenceChangeListener? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/AddLocationFragment.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/AddLocationFragment.kt similarity index 93% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/AddLocationFragment.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/AddLocationFragment.kt index fab3591..0ac4234 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/AddLocationFragment.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/AddLocationFragment.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.ui.world +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.world import android.os.Bundle import android.view.LayoutInflater @@ -7,7 +7,7 @@ import android.view.ViewGroup import androidx.fragment.app.viewModels import androidx.lifecycle.observe import com.appttude.h_mal.atlas_weather.R -import com.appttude.h_mal.atlas_weather.ui.BaseFragment +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.BaseFragment import com.appttude.h_mal.atlas_weather.utils.displayToast import com.appttude.h_mal.atlas_weather.utils.goBack import com.appttude.h_mal.atlas_weather.viewmodel.ApplicationViewModelFactory diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/WorldFragment.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/WorldFragment.kt similarity index 88% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/WorldFragment.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/WorldFragment.kt index a1c1011..4bef5b4 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/WorldFragment.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/WorldFragment.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.ui.world +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.world import android.os.Bundle import android.view.LayoutInflater @@ -9,7 +9,9 @@ import androidx.fragment.app.viewModels import androidx.lifecycle.observe import androidx.recyclerview.widget.LinearLayoutManager import com.appttude.h_mal.atlas_weather.R -import com.appttude.h_mal.atlas_weather.ui.BaseFragment +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.world.WorldRecyclerAdapter +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.BaseFragment +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.world.WorldFragmentDirections import com.appttude.h_mal.atlas_weather.utils.navigateTo import com.appttude.h_mal.atlas_weather.viewmodel.ApplicationViewModelFactory import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/WorldRecyclerAdapter.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/WorldRecyclerAdapter.kt similarity index 98% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/WorldRecyclerAdapter.kt rename to app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/WorldRecyclerAdapter.kt index f52740f..26a3cfb 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/world/WorldRecyclerAdapter.kt +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/ui/world/WorldRecyclerAdapter.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.ui.world +package com.appttude.h_mal.atlas_weather.atlasWeather.ui.world import android.view.View import android.view.ViewGroup diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/BaseWidgetClass.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/BaseWidgetClass.kt new file mode 100644 index 0000000..161f345 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/BaseWidgetClass.kt @@ -0,0 +1,37 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.widget + +import android.app.Activity +import android.app.PendingIntent +import android.app.TaskStackBuilder +import android.appwidget.AppWidgetManager +import android.appwidget.AppWidgetProvider +import android.content.Context +import android.content.Intent +import android.widget.RemoteViews +import androidx.annotation.LayoutRes + +abstract class BaseWidgetClass : AppWidgetProvider(){ + + fun createRemoteView(context: Context, @LayoutRes id: Int): RemoteViews { + return RemoteViews(context.packageName, id) + } + + fun AppWidgetProvider.createUpdatePendingIntent(context: Context, appWidgetId: Int): PendingIntent? { + val seconds = (System.currentTimeMillis() / 1000L).toInt() + val intentUpdate = Intent(context, this::class.java) + intentUpdate.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE + val idArray = intArrayOf(appWidgetId) + intentUpdate.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, idArray) + return PendingIntent.getBroadcast( + context, seconds, intentUpdate, + PendingIntent.FLAG_UPDATE_CURRENT) + } + + fun createClickingPendingIntent(context: Context, activityClass: Class): PendingIntent { + val clickIntentTemplate = Intent(context, activityClass) + + return TaskStackBuilder.create(context) + .addNextIntentWithParentStack(clickIntentTemplate) + .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) + } +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/MyWidgetRemoteViewsFactory.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/MyWidgetRemoteViewsFactory.kt new file mode 100644 index 0000000..a53ae26 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/MyWidgetRemoteViewsFactory.kt @@ -0,0 +1,77 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.widget + +import android.appwidget.AppWidgetManager +import android.content.Context +import android.content.Intent +import android.widget.RemoteViews +import android.widget.RemoteViewsService.RemoteViewsFactory +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.helper.ServicesHelper +import com.appttude.h_mal.atlas_weather.model.widget.InnerWidgetData +import kotlinx.coroutines.runBlocking +import org.kodein.di.KodeinAware +import org.kodein.di.LateInitKodein +import org.kodein.di.generic.instance + + +class MyWidgetRemoteViewsFactory( + private val context: Context, + val intent: Intent +) : RemoteViewsFactory{ + private val TAG = "MyWidgetRemoteViewsFactory" + + private val kodein = LateInitKodein() + private val helper : ServicesHelper by kodein.instance() + + private var appWidgetId: Int? = 0 + private var list: List? = null + + init { + appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID) + kodein.baseKodein = (context.applicationContext as KodeinAware).kodein + + } + + override fun onCreate() {} + override fun onDataSetChanged() { + runBlocking { + list = helper.getWidgetInnerWeather() + } + } + override fun onDestroy() {} + + override fun getCount(): Int = list?.size ?: 5 + + override fun getViewAt(i: Int): RemoteViews { + val rv = RemoteViews(context.packageName, R.layout.widget_item) + + if (list.isNullOrEmpty()) return rv + + + list?.get(i)?.let { + rv.setTextViewText(R.id.widget_item_day, it.date) + rv.setImageViewBitmap(R.id.widget_item_image, it.icon) + rv.setTextViewText(R.id.widget_item_temp_high, it.highTemp) + rv.setOnClickFillInIntent(R.id.widget_item_layout, intent) + } + + return rv + } + + override fun getLoadingView(): RemoteViews { + return RemoteViews(context.packageName, R.layout.widget_item_loading) + } + + override fun getViewTypeCount(): Int = 1 + + + override fun getItemId(i: Int): Long = i.toLong() + + + override fun hasStableIds(): Boolean { + return true + } + + +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/NewAppWidget.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/NewAppWidget.kt new file mode 100644 index 0000000..9e546ba --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/NewAppWidget.kt @@ -0,0 +1,141 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.widget + +import android.Manifest +import android.app.PendingIntent +import android.appwidget.AppWidgetManager +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.net.Uri +import android.util.Log +import android.widget.RemoteViews +import androidx.core.app.ActivityCompat +import com.appttude.h_mal.atlas_weather.R +import com.appttude.h_mal.atlas_weather.atlasWeather.ui.MainActivity +import com.appttude.h_mal.atlas_weather.helper.ServicesHelper +import com.appttude.h_mal.atlas_weather.model.widget.WidgetData +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import org.kodein.di.KodeinAware +import org.kodein.di.LateInitKodein +import org.kodein.di.generic.instance + +/** + * Implementation of App Widget functionality. + */ +private val TAG = NewAppWidget::class.java.simpleName +class NewAppWidget : BaseWidgetClass() { + + private val kodein = LateInitKodein() + private val helper : ServicesHelper by kodein.instance() + + override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { + kodein.baseKodein = (context.applicationContext as KodeinAware).kodein + // There may be multiple widgets active, so update all of them + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + return + } + + CoroutineScope(Dispatchers.IO).launch { + val results = helper.fetchData() + if (results) return@launch + val weatherWidgetCurrent = helper.getWidgetWeather() + + withContext(Dispatchers.Main){ + for (appWidgetId in appWidgetIds) { + val updatePendingIntent = createUpdatePendingIntent(context, appWidgetId) + val views = createRemoteView(context, R.layout.new_app_widget) + bindView(context, appWidgetId, views, updatePendingIntent, weatherWidgetCurrent) + } + super.onUpdate(context, appWidgetManager, appWidgetIds) + } + + } + } + + override fun onEnabled(context: Context) { + try { + val appWidgetManager = AppWidgetManager.getInstance(context) + val thisAppWidget = ComponentName(context.packageName, NewAppWidget::class.java.name) + val appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget) + onUpdate(context, appWidgetManager, appWidgetIds) + appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_listview) + } catch (e: Exception) { + Log.e(TAG, "onEnabled: ", e) + } + } + + override fun onDisabled(context: Context) { + // Enter relevant functionality for when the last widget is disabled + } + + override fun onReceive(context: Context, intent: Intent) { + if (intent.action == + AppWidgetManager.ACTION_APPWIDGET_UPDATE) { + val appWidgetManager = AppWidgetManager.getInstance(context) + val thisAppWidget = ComponentName(context.packageName, NewAppWidget::class.java.name) + val appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget) + appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_listview) + } + super.onReceive(context, intent) + } + + private fun createForecastListIntent( + context: Context, + appWidgetId: Int + ): Intent { + return Intent(context, WidgetRemoteViewsService::class.java).apply { + putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) + data = Uri.parse(toUri(Intent.URI_INTENT_SCHEME)) + } + } + + private fun bindView( + context: Context, + appWidgetId: Int, + views: RemoteViews, + updatePendingIntent: PendingIntent?, + weather: WidgetData?){ + + val appWidgetManager = AppWidgetManager.getInstance(context) + + views.setInt(R.id.whole_widget_view, "setBackgroundColor", helper.getWidgetBackground()) + + weather?.let { + + val intent = createForecastListIntent( + context, + appWidgetId + ) + + views.setRemoteAdapter(R.id.widget_listview, intent) + views.setTextViewText(R.id.widget_main_temp, it.currentTemp) + views.setTextViewText(R.id.widget_feel_temp, "°C") + views.setTextViewText(R.id.widget_current_location, it.location) + views.setImageViewResource(R.id.location_icon, R.drawable.location_flag) + views.setImageViewBitmap(R.id.widget_current_icon, it.icon) + + val clickPendingIntentTemplate = createClickingPendingIntent(context, MainActivity::class.java) + views.setPendingIntentTemplate(R.id.widget_listview, clickPendingIntentTemplate) + + views.setOnClickPendingIntent(R.id.widget_current_icon, updatePendingIntent) + views.setOnClickPendingIntent(R.id.widget_current_location, updatePendingIntent) + + // Instruct the widget manager to update the widget + appWidgetManager.updateAppWidget(appWidgetId, views) + appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_listview) + return + } + + Log.i(TAG, "onPostExecute: weather is empty") + views.setTextViewText(R.id.widget_current_location, "Refresh") + views.setImageViewResource(R.id.widget_current_icon, R.drawable.widget_error_icon) + views.setImageViewResource(R.id.location_icon, R.drawable.refreshing) + views.setOnClickPendingIntent(R.id.widget_current_icon, updatePendingIntent) + views.setOnClickPendingIntent(R.id.widget_current_location, updatePendingIntent) + appWidgetManager.updateAppWidget(appWidgetId, views) + } +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetRemoteViewsService.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetRemoteViewsService.kt new file mode 100644 index 0000000..d8dbf77 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetRemoteViewsService.kt @@ -0,0 +1,10 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.widget + +import android.content.Intent +import android.widget.RemoteViewsService + +class WidgetRemoteViewsService : RemoteViewsService() { + override fun onGetViewFactory(intent: Intent): RemoteViewsFactory { + return MyWidgetRemoteViewsFactory(applicationContext, intent) + } +} \ No newline at end of file diff --git a/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetUtils.kt b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetUtils.kt new file mode 100644 index 0000000..969ec86 --- /dev/null +++ b/app/src/atlasWeather/java/com/appttude/h_mal/atlas_weather/atlasWeather/widget/WidgetUtils.kt @@ -0,0 +1,15 @@ +package com.appttude.h_mal.atlas_weather.atlasWeather.widget + +import android.app.Activity +import android.app.PendingIntent +import android.app.TaskStackBuilder +import android.content.Context +import android.content.Intent + +fun createClickingPendingIntent(context: Context, activityClass: Class): PendingIntent { + val clickIntentTemplate = Intent(context, activityClass) + + return TaskStackBuilder.create(context) + .addNextIntentWithParentStack(clickIntentTemplate) + .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) +} \ No newline at end of file diff --git a/app/src/atlasWeather/res/layout/activity_further_info.xml b/app/src/atlasWeather/res/layout/activity_further_info.xml new file mode 100644 index 0000000..a857e01 --- /dev/null +++ b/app/src/atlasWeather/res/layout/activity_further_info.xml @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/atlasWeather/res/layout/activity_main.xml b/app/src/atlasWeather/res/layout/activity_main.xml new file mode 100644 index 0000000..421a59b --- /dev/null +++ b/app/src/atlasWeather/res/layout/activity_main.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/list_item4.xml b/app/src/atlasWeather/res/layout/list_item_current.xml similarity index 90% rename from app/src/main/res/layout/list_item4.xml rename to app/src/atlasWeather/res/layout/list_item_current.xml index 83247cf..e816d27 100644 --- a/app/src/main/res/layout/list_item4.xml +++ b/app/src/atlasWeather/res/layout/list_item_current.xml @@ -20,6 +20,7 @@ android:layout_height="match_parent" android:layout_gravity="center" android:layout_marginRight="6dp" + android:tint="@color/colorAccent" android:src="@drawable/location_flag" /> @@ -40,7 +41,7 @@ android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:includeFontPadding="false" - android:textColor="@color/colour_five" + android:textSize="90sp" tools:text="24" /> @@ -53,7 +54,7 @@ android:layout_toRightOf="@id/temp_main_4" android:includeFontPadding="false" android:text="°C" - android:textColor="@color/colour_five" + android:textSize="30sp" /> diff --git a/app/src/main/res/layout/list_item_layout2.xml b/app/src/atlasWeather/res/layout/list_item_forecast.xml similarity index 92% rename from app/src/main/res/layout/list_item_layout2.xml rename to app/src/atlasWeather/res/layout/list_item_forecast.xml index 6c73bf4..8e42060 100644 --- a/app/src/main/res/layout/list_item_layout2.xml +++ b/app/src/atlasWeather/res/layout/list_item_forecast.xml @@ -7,13 +7,12 @@ android:layout_height="wrap_content"> @@ -34,7 +33,6 @@ android:id="@+id/list_date" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textColor="@color/colour_five" android:textSize="22sp" tools:text="Nov 28" /> @@ -42,7 +40,6 @@ android:id="@+id/list_day" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textColor="@color/colour_five" tools:text="Wednesday" /> @@ -73,7 +70,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:includeFontPadding="false" - android:textColor="@color/colour_five" android:textSize="28sp" tools:text="28" /> diff --git a/app/src/main/res/layout/list_item3.xml b/app/src/atlasWeather/res/layout/list_item_further.xml similarity index 93% rename from app/src/main/res/layout/list_item3.xml rename to app/src/atlasWeather/res/layout/list_item_further.xml index cf3f40e..93e78c9 100644 --- a/app/src/main/res/layout/list_item3.xml +++ b/app/src/atlasWeather/res/layout/list_item_further.xml @@ -12,7 +12,7 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="12dp" - android:layout_weight="1"> + android:layout_weight="2"> + /> + /> @@ -89,7 +89,7 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="12dp" - android:layout_weight="1"> + android:layout_weight="2"> + /> + android:text="Precip: " /> + /> @@ -164,7 +164,7 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="12dp" - android:layout_weight="1"> + android:layout_weight="2"> + /> diff --git a/app/src/atlasWeather/res/navigation/main_navigation.xml b/app/src/atlasWeather/res/navigation/main_navigation.xml new file mode 100644 index 0000000..ad81a1e --- /dev/null +++ b/app/src/atlasWeather/res/navigation/main_navigation.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/atlasWeather/res/values/strings.xml b/app/src/atlasWeather/res/values/strings.xml new file mode 100644 index 0000000..6048840 --- /dev/null +++ b/app/src/atlasWeather/res/values/strings.xml @@ -0,0 +1,4 @@ + + + Hello blank fragment + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/atlasWeather/res/values/styles.xml similarity index 94% rename from app/src/main/res/values/styles.xml rename to app/src/atlasWeather/res/values/styles.xml index a87ec58..79b99b4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/atlasWeather/res/values/styles.xml @@ -8,6 +8,7 @@ @color/colour_one @drawable/gradient sans-serif-light + @color/colorAccent diff --git a/app/src/atlasWeather/res/xml/prefs.xml b/app/src/atlasWeather/res/xml/prefs.xml new file mode 100644 index 0000000..ae62ca4 --- /dev/null +++ b/app/src/atlasWeather/res/xml/prefs.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 56ae5a5..43fd8c6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ - @@ -15,50 +15,4 @@ android:name="android.hardware.location.gps" android:required="true" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/application/AppClass.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/application/AppClass.kt index 8b302d5..b29bb7c 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/application/AppClass.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/application/AppClass.kt @@ -11,7 +11,7 @@ import com.appttude.h_mal.atlas_weather.data.repository.RepositoryImpl import com.appttude.h_mal.atlas_weather.data.repository.SettingsRepositoryImpl import com.appttude.h_mal.atlas_weather.data.room.AppDatabase import com.appttude.h_mal.atlas_weather.viewmodel.ApplicationViewModelFactory -import com.appttude.h_mal.atlas_weather.notification.ServicesHelper +import com.appttude.h_mal.atlas_weather.helper.ServicesHelper import com.google.gson.Gson import org.kodein.di.Kodein import org.kodein.di.KodeinAware diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/location/LocationProvider.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/location/LocationProvider.kt index 5d67ec3..0622452 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/location/LocationProvider.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/location/LocationProvider.kt @@ -37,7 +37,6 @@ class LocationProvider( return result?.let { location -> location.locality?.let { return it } - location.thoroughfare?.let { return it } location.subAdminArea?.let { return it } } ?: "$lat, $long" } diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/Repository.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/Repository.kt index f3b9b2d..39474a7 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/Repository.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/Repository.kt @@ -14,6 +14,6 @@ interface Repository { suspend fun loadSingleCurrentWeatherFromRoom(id: String): EntityItem fun isSearchValid(locationName: String): Boolean fun saveLastSavedAt(locationName: String) - suspend fun deleteSavedWeatherEntry(locationName: String) + suspend fun deleteSavedWeatherEntry(locationName: String): Boolean fun getSavedLocations(): List } \ No newline at end of file diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/RepositoryImpl.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/RepositoryImpl.kt index 612168d..1922183 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/RepositoryImpl.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/repository/RepositoryImpl.kt @@ -56,9 +56,9 @@ class RepositoryImpl( prefs.saveLastSavedAt("$LOCATION_CONST$locationName") } - override suspend fun deleteSavedWeatherEntry(locationName: String){ - db.getSimpleDao().deleteEntry(locationName) + override suspend fun deleteSavedWeatherEntry(locationName: String): Boolean { prefs.deleteLocation(locationName) + return db.getSimpleDao().deleteEntry(locationName) > 0 } override fun getSavedLocations(): List { diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/room/WeatherDao.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/room/WeatherDao.kt index 99e75bc..8f64932 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/data/room/WeatherDao.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/data/room/WeatherDao.kt @@ -1,5 +1,6 @@ package com.appttude.h_mal.atlas_weather.data.room +import android.text.BoringLayout import androidx.lifecycle.LiveData import androidx.room.Dao import androidx.room.Insert @@ -27,6 +28,6 @@ interface WeatherDao { fun getAllFullWeatherWithoutCurrent(id: String = CURRENT_LOCATION) : LiveData> @Query("DELETE FROM EntityItem WHERE id = :userId") - suspend fun deleteEntry(userId: String) + suspend fun deleteEntry(userId: String): Int } \ No newline at end of file diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/notification/ServicesHelper.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/helper/ServicesHelper.kt similarity index 96% rename from app/src/main/java/com/appttude/h_mal/atlas_weather/notification/ServicesHelper.kt rename to app/src/main/java/com/appttude/h_mal/atlas_weather/helper/ServicesHelper.kt index d11d280..65081e0 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/notification/ServicesHelper.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/helper/ServicesHelper.kt @@ -1,4 +1,4 @@ -package com.appttude.h_mal.atlas_weather.notification +package com.appttude.h_mal.atlas_weather.helper import android.Manifest import android.graphics.Bitmap @@ -90,7 +90,7 @@ class ServicesHelper( } - fun getBitmapFromUrl(imageAddress: String?): Bitmap? { + private fun getBitmapFromUrl(imageAddress: String?): Bitmap? { return try { val url = URL(imageAddress) BitmapFactory.decodeStream(url.openConnection().getInputStream()) diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/model/forecast/WeatherDisplay.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/model/forecast/WeatherDisplay.kt index ac0c6f9..ea34958 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/model/forecast/WeatherDisplay.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/model/forecast/WeatherDisplay.kt @@ -41,10 +41,10 @@ data class WeatherDisplay( null, weather.current?.icon, weather.current?.description, - weather.daily?.map { Forecast(it) }, + weather.daily?.drop(1)?.map { Forecast(it) }, weather.current?.windSpeed?.toString(), weather.current?.windDeg?.toString(), - weather.daily?.get(0)?.pop?.toString(), + weather.daily?.get(0)?.pop?.times(100)?.toString(), weather.current?.humidity?.toString(), weather.current?.clouds?.toString(), weather.lat, diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/model/widget/WidgetData.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/model/widget/WidgetData.kt index 5554039..c814b41 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/model/widget/WidgetData.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/model/widget/WidgetData.kt @@ -42,7 +42,7 @@ data class WidgetData( data class InnerWidgetData( val date: String?, val icon: Bitmap?, - val currentTemp: String? + val highTemp: String? ):Parcelable{ constructor(parcel: Parcel) : this( @@ -54,7 +54,7 @@ data class InnerWidgetData( override fun writeToParcel(parcel: Parcel, flags: Int) { parcel.writeString(date) parcel.writeParcelable(icon, flags) - parcel.writeString(currentTemp) + parcel.writeString(highTemp) } override fun describeContents(): Int { diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/home/BaseActivity.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/home/BaseActivity.kt deleted file mode 100644 index 235c0cb..0000000 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/ui/home/BaseActivity.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.appttude.h_mal.atlas_weather.ui.home - -import android.annotation.SuppressLint -import android.content.pm.PackageManager -import androidx.appcompat.app.AppCompatActivity -import androidx.core.app.ActivityCompat -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch - -abstract class BaseActivity : AppCompatActivity(){ - - @SuppressLint("MissingPermission") - fun getPermissionResult( - permission: String, - permissionCode: Int, - permissionGranted: () -> Unit - ){ - if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { - requestPermissions(arrayOf(permission), permissionCode) - return - }else{ - CoroutineScope(Dispatchers.Main).launch{ - permissionGranted.invoke() - } - } - - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/utils/ViewUtils.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/utils/ViewUtils.kt index ef7b510..450a4be 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/utils/ViewUtils.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/utils/ViewUtils.kt @@ -1,6 +1,7 @@ package com.appttude.h_mal.atlas_weather.utils import android.content.Context +import android.content.res.Resources import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -30,7 +31,7 @@ fun Fragment.displayToast(message: String) { fun ImageView.loadImage(url: String?){ Picasso.get() .load(url) - .placeholder(R.mipmap.ic_launcher) + .error(R.drawable.ic_baseline_cloud_off_24) .into(this) } @@ -41,12 +42,14 @@ fun ViewGroup.generateView(layoutId: Int): View = LayoutInflater fun ImageView.loadImage(url: String?, height: Int, width: Int){ Picasso.get() .load(url) - .resize(width, height) + .resize(width.dpToPx(), height.dpToPx()) .centerCrop() - .placeholder(R.mipmap.ic_launcher) + .error(R.drawable.ic_baseline_cloud_off_24) .into(this) } +fun Int.dpToPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt() + fun SearchView.onSubmitListener(searchSubmit: (String) -> Unit) { this.setOnQueryTextListener(object : SearchView.OnQueryTextListener { diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/MainViewModel.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/MainViewModel.kt index b430b89..55af152 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/MainViewModel.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/MainViewModel.kt @@ -20,7 +20,6 @@ class MainViewModel( private val repository: Repository ): ViewModel(){ - val currentWeatherLiveData = MutableLiveData() val weatherLiveData = MutableLiveData() val operationState = MutableLiveData>() diff --git a/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/WorldViewModel.kt b/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/WorldViewModel.kt index 5ceff18..fd070fe 100644 --- a/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/WorldViewModel.kt +++ b/app/src/main/java/com/appttude/h_mal/atlas_weather/viewmodel/WorldViewModel.kt @@ -30,6 +30,10 @@ class WorldViewModel( init { weatherListLiveData.observeForever { + it.forEach { item-> + println(item) + } + val list = it.map { data -> WeatherDisplay(data.weather).apply { unit = "°C" @@ -43,7 +47,7 @@ class WorldViewModel( fun fetchDataForSingleLocation(locationName: String) { CoroutineScope(Dispatchers.IO).launch { operationState.postValue(Event(true)) - + // Check if location exists if (repository.getSavedLocations().contains(locationName)){ operationError.postValue(Event("$locationName already exists")) return@launch @@ -53,14 +57,24 @@ class WorldViewModel( // Get location val latLong = locationProvider.getLatLongFromLocationString(locationName) + val lat = latLong.first + val lon = latLong.second + // Get weather from api val weather = repository - .getWeatherFromApi(latLong.first.toString(), latLong.second.toString()) + .getWeatherFromApi(lat.toString(), lon.toString()) + + // retrieved location name + val retrievedLocation = locationProvider.getLocationName(weather.lat, weather.lon) + if (repository.getSavedLocations().contains(retrievedLocation)){ + operationError.postValue(Event("$retrievedLocation already exists")) + return@launch + } // Save data if not null weather.let { - repository.saveCurrentWeatherToRoom(locationName, it) - operationComplete.postValue(Event("$locationName saved")) + repository.saveCurrentWeatherToRoom(retrievedLocation, it) + operationComplete.postValue(Event("$retrievedLocation saved")) return@launch } } catch (e: IOException) { @@ -100,4 +114,20 @@ class WorldViewModel( } } } + + fun deleteLocation(locationName: String){ + CoroutineScope(Dispatchers.IO).launch { + operationState.postValue(Event(true)) + try { + val success = repository.deleteSavedWeatherEntry(locationName) + if (!success){ + operationError.postValue(Event("Failed to delete")) + } + } catch (e: IOException) { + operationError.postValue(Event(e.message!!)) + } finally { + operationState.postValue(Event(false)) + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_add_24.xml b/app/src/main/res/drawable/ic_baseline_add_24.xml new file mode 100644 index 0000000..6f192f4 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_add_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_cloud_off_24.xml b/app/src/main/res/drawable/ic_baseline_cloud_off_24.xml new file mode 100644 index 0000000..19171b0 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_cloud_off_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_add_forecast.xml b/app/src/main/res/layout/activity_add_forecast.xml index db30dc0..766dad7 100644 --- a/app/src/main/res/layout/activity_add_forecast.xml +++ b/app/src/main/res/layout/activity_add_forecast.xml @@ -6,71 +6,45 @@ android:orientation="vertical" tools:context=".legacy.ui.AddForecastActivity"> - - + android:layout_height="wrap_content" + android:layout_centerHorizontal="true" + android:layout_centerVertical="true" + android:layout_margin="24dp" + android:orientation="vertical"> - - - - - - - + android:layout_weight="2" + android:ems="10" + android:hint="@string/location_name" + android:inputType="textPersonName" + android:maxLines="2" + tools:text="Greater London"/>