diff --git a/app/build.gradle b/app/build.gradle index 6e859f1..dc8eec8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,7 +17,7 @@ android { applicationId "com.tommasoberlose.anotherwidget" minSdkVersion 19 targetSdkVersion 26 - versionCode 28 + versionCode 29 versionName "1.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/release/output.json b/app/release/output.json index c964bde..2863276 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":28},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":29},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 65c8ddb..1569079 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -83,6 +83,7 @@ + diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt index bbc910e..60a8a23 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/object/Constants.kt @@ -71,7 +71,6 @@ object Constants { val PREF_CUSTOM_FONT = "PREF_CUSTOM_FONT" val PREF_SHOW_NEXT_EVENT = "PREF_SHOW_NEXT_EVENT" val PREF_SHOW_WIDGET_PREVIEW = "PREF_SHOW_WIDGET_PREVIEW" - val PREF_SCHEMA_VERSION = "PREF_SCHEMA_VERSION" val CUSTOM_FONT_PRODUCT_SANS = 1 diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt index e8e5a1f..3b8b80f 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/OpenWeatherIntentReceiver.kt @@ -12,7 +12,11 @@ class OpenWeatherIntentReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { if (intent.action == Constants.ACTION_OPEN_WEATHER_INTENT) { context.sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE)) - context.startActivity(Util.getWeatherIntent(context)) + try { + context.startActivity(Util.getWeatherIntent(context)) + } catch (e: Exception) { + context.applicationContext.startActivity(Util.getWeatherIntent(context.applicationContext)) + } } } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt index 99ad259..b07f96b 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/receiver/WeatherReceiver.kt @@ -14,6 +14,9 @@ import com.tommasoberlose.anotherwidget.util.CalendarUtil import com.tommasoberlose.anotherwidget.util.Util import com.tommasoberlose.anotherwidget.util.WeatherUtil import java.util.* +import android.widget.Toast + + class WeatherReceiver : BroadcastReceiver() { @@ -22,6 +25,8 @@ class WeatherReceiver : BroadcastReceiver() { setUpdates(context) } else if (intent.action.equals(Constants.ACTION_WEATHER_UPDATE) || intent.action.equals("android.location.PROVIDERS_CHANGED")) { WeatherUtil.updateWeather(context) + } else if (intent.action == "android.location.PROVIDERS_CHANGED") { + Util.showWeatherErrorNotification(context) } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt index 4536b97..1135ed7 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/MainActivity.kt @@ -211,6 +211,10 @@ class MainActivity : AppCompatActivity() { if (SP.getBoolean(Constants.PREF_SHOW_WIDGET_PREVIEW, true)) { val displayMetrics = Resources.getSystem().displayMetrics + var width = displayMetrics.widthPixels + if (width <= 0) { + width = Util.convertDpToPixel(300f, this).toInt() + } var height = Util.convertDpToPixel(120f, this).toInt() if (SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) { height += Util.convertSpToPixels(SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f), this).toInt() + Util.convertDpToPixel(8f, this).toInt() @@ -218,7 +222,7 @@ class MainActivity : AppCompatActivity() { if (SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) + SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) > 50) { height += Util.convertDpToPixel(24f, this).toInt() } - widget_bitmap.setImageBitmap(Util.getBitmapFromView(main_layout, displayMetrics.widthPixels, height - Util.convertDpToPixel(32f, this).toInt())) + widget_bitmap.setImageBitmap(Util.getBitmapFromView(main_layout, width, height - Util.convertDpToPixel(32f, this).toInt())) widget.layoutParams.height = height + Util.convertDpToPixel(16f, this).toInt() widget.visibility = View.VISIBLE @@ -649,7 +653,7 @@ class MainActivity : AppCompatActivity() { action_clock_text_size.setOnClickListener { var fontSize = SP.getFloat(Constants.PREF_TEXT_CLOCK_SIZE, 90f) + 5 if (fontSize > 110) { - fontSize = 70f + fontSize = 50f } SP.edit().putFloat(Constants.PREF_TEXT_CLOCK_SIZE, fontSize).commit() Util.updateWidget(this) @@ -688,25 +692,19 @@ class MainActivity : AppCompatActivity() { updateSettings() } - - if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) { - action_weather_refresh_period.visibility = View.GONE - } else { - label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1))) - action_weather_refresh_period.setOnClickListener { - SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)) { - 0 -> 1 - 1 -> 2 - 2 -> 3 - 3 -> 4 - 4 -> 5 - 5 -> 0 - else -> 1 - }).commit() - updateSettings() - WeatherReceiver().setUpdates(this@MainActivity) - } - action_weather_refresh_period.visibility = View.VISIBLE + label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1))) + action_weather_refresh_period.setOnClickListener { + SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)) { + 0 -> 1 + 1 -> 2 + 2 -> 3 + 3 -> 4 + 4 -> 5 + 5 -> 0 + else -> 1 + }).commit() + updateSettings() + WeatherReceiver().setUpdates(this@MainActivity) } show_until_label.text = getString(Util.getShowUntilString(SP.getInt(Constants.PREF_SHOW_UNTIL, 1))) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt index 3c12d63..5863a12 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activity/SupportDevActivity.kt @@ -12,7 +12,7 @@ import com.tommasoberlose.anotherwidget.util.Util import kotlinx.android.synthetic.main.activity_support_dev.* class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler { - internal var bp: BillingProcessor? = null + internal lateinit var bp: BillingProcessor internal val BILLING_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAox5CcxuoLJ6CmNS7s6lVQzJ253njKKGF8MoQ/gQ5gEw2Fr03fBvtHpiVMpnjhNLw5NMeIpzRvkVqeQ7BfkC7c0BLCJUqf/fFA11ArQe8na6QKt5O4d+v4sbHtP7mm3GQNPOBaqRzcpFZaiAbfk6mnalo+tzM47GXrQFt5bNSrMctCs7bbChqJfH2cyMW0F8DHWEEeO5xElBmH3lh4FVpwIUTPYJIV3n0yhE3qqRA0WXkDej66g/uAt/rebmMZLmwNwIive5cObU4o41YyKRv2wSAicrv3W40LftzXAOOordIbmzDFN8ksh3VrnESqwCDGG97nZVbPG/+3LD0xHWiRwIDAQAB" @@ -34,18 +34,18 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler loader.visibility = View.GONE try { val isAvailable = BillingProcessor.isIabServiceAvailable(this) - val isOneTimePurchaseSupported = bp!!.isOneTimePurchaseSupported + val isOneTimePurchaseSupported = bp.isOneTimePurchaseSupported if (isAvailable && isOneTimePurchaseSupported) { - val coffee = bp!!.getPurchaseListingDetails("donation_coffee") - val donuts = bp!!.getPurchaseListingDetails("donation_donuts") - val breakfast = bp!!.getPurchaseListingDetails("donation_breakfast") - val lunch = bp!!.getPurchaseListingDetails("donation_lunch") - val dinner = bp!!.getPurchaseListingDetails("donation_dinner") + val coffee = bp.getPurchaseListingDetails("donation_coffee") + val donuts = bp.getPurchaseListingDetails("donation_donuts") + val breakfast = bp.getPurchaseListingDetails("donation_breakfast") + val lunch = bp.getPurchaseListingDetails("donation_lunch") + val dinner = bp.getPurchaseListingDetails("donation_dinner") if (coffee != null) { import_donation_coffee.text = coffee.priceText action_donation_coffee.setOnClickListener { - bp!!.purchase(this, "donation_coffee") + bp.purchase(this, "donation_coffee") } } else { action_donation_coffee.visibility = View.GONE @@ -54,7 +54,7 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler if (donuts != null) { import_donation_donuts.text = donuts.priceText action_donation_donuts.setOnClickListener { - bp!!.purchase(this, "donation_donuts") + bp.purchase(this, "donation_donuts") } } else { action_donation_donuts.visibility = View.GONE @@ -63,7 +63,7 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler if (breakfast != null) { import_donation_breakfast.text = breakfast.priceText action_donation_breakfast.setOnClickListener { - bp!!.purchase(this, "donation_breakfast") + bp.purchase(this, "donation_breakfast") } } else { action_donation_breakfast.visibility = View.GONE @@ -72,7 +72,7 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler if (lunch != null) { import_donation_lunch.text = lunch.priceText action_donation_lunch.setOnClickListener { - bp!!.purchase(this, "donation_lunch") + bp.purchase(this, "donation_lunch") } } else { action_donation_lunch.visibility = View.GONE @@ -81,7 +81,7 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler if (dinner != null) { import_donation_dinner.text = dinner.priceText action_donation_dinner.setOnClickListener { - bp!!.purchase(this, "donation_dinner") + bp.purchase(this, "donation_dinner") } } else { action_donation_dinner.visibility = View.GONE @@ -101,7 +101,7 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler override fun onProductPurchased(productId: String, details: TransactionDetails?) { Toast.makeText(this, R.string.thanks, Toast.LENGTH_SHORT).show() - bp!!.consumePurchase(productId) + bp.consumePurchase(productId) } override fun onBillingError(errorCode: Int, error: Throwable?) { @@ -109,15 +109,13 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { - if (!bp!!.handleActivityResult(requestCode, resultCode, data)) { + if (!bp.handleActivityResult(requestCode, resultCode, data)) { super.onActivityResult(requestCode, resultCode, data) } } public override fun onDestroy() { - if (bp != null) { - bp!!.release() - } + bp.release() super.onDestroy() } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt index feea9af..4bad735 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widget/TheWidget.kt @@ -73,7 +73,6 @@ class TheWidget : AppWidgetProvider() { override fun onEnabled(context: Context) { UpdatesReceiver().setUpdates(context) WeatherReceiver().setUpdates(context) - Util.showNotification(context) } override fun onDisabled(context: Context) { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/util/CalendarUtil.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/util/CalendarUtil.kt index 2e67c94..241e7ec 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/util/CalendarUtil.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/util/CalendarUtil.kt @@ -62,18 +62,20 @@ object CalendarUtil { if (data != null) { val instances = data.list for (instance in instances) { - val e = provider.getEvent(instance.eventId) - if (e != null && instance.begin <= limit.timeInMillis && (SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false) || !e.allDay) && !(SP.getString(Constants.PREF_CALENDAR_FILTER, "").contains(" " + e.calendarId + ",")) && (SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true) || !e.selfAttendeeStatus.equals(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED))) { - if (e.allDay) { - val start = Calendar.getInstance() - start.timeInMillis = instance.begin - val end = Calendar.getInstance() - end.timeInMillis = instance.end - instance.begin = start.timeInMillis - start.timeZone.getOffset(start.timeInMillis) - instance.end = end.timeInMillis - end.timeZone.getOffset(end.timeInMillis) + try { + val e = provider.getEvent(instance.eventId) + if (e != null && instance.begin <= limit.timeInMillis && (SP.getBoolean(Constants.PREF_CALENDAR_ALL_DAY, false) || !e.allDay) && !(SP.getString(Constants.PREF_CALENDAR_FILTER, "").contains(" " + e.calendarId + ",")) && (SP.getBoolean(Constants.PREF_SHOW_DECLINED_EVENTS, true) || !e.selfAttendeeStatus.equals(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED))) { + if (e.allDay) { + val start = Calendar.getInstance() + start.timeInMillis = instance.begin + val end = Calendar.getInstance() + end.timeInMillis = instance.end + instance.begin = start.timeInMillis - start.timeZone.getOffset(start.timeInMillis) + instance.end = end.timeInMillis - end.timeZone.getOffset(end.timeInMillis) + } + eventList.add(Event(instance.id, e.id, e.title ?: "", instance.begin, instance.end, e.calendarId.toInt(), e.allDay, e.eventLocation ?: "")) } - eventList.add(Event(instance.id, e.id, e.title, instance.begin, instance.end, e.calendarId.toInt(), e.allDay, e.eventLocation ?: "")) - } + } catch (ignored: Exception) {} } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt index 605d9a3..b647c6a 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/util/Util.kt @@ -24,6 +24,7 @@ import android.support.annotation.StringRes import android.util.TypedValue import android.content.Intent import android.content.ComponentName +import android.location.LocationManager import android.os.Build import android.preference.PreferenceManager import android.provider.AlarmClock @@ -88,6 +89,28 @@ object Util { } + fun showWeatherErrorNotification(context: Context) { + val mNotificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager + val SP = PreferenceManager.getDefaultSharedPreferences(context) + + if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) { + val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Error") + .setSmallIcon(R.drawable.ic_stat_name) + .setColor(ContextCompat.getColor(context, R.color.colorPrimary)) + .setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher_round)) + .setContentTitle(context.getString(R.string.notification_gps_title)) + .setContentText(context.getString(R.string.notification_gps_subtitle)) + + val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS) + val pi: PendingIntent = PendingIntent.getActivity(context, 50, intent, PendingIntent.FLAG_UPDATE_CURRENT); + mBuilder.setContentIntent(pi); + mNotificationManager.notify(10, mBuilder.build()); + } else { + mNotificationManager.cancel(10) + } + } + fun openURI(context: Context, url: String) { try { val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder() @@ -587,28 +610,33 @@ object Util { } fun getRealInstance(context: Context): Realm { + Realm.init(context) return Realm.getDefaultInstance() } fun getNextAlarm(context: Context): String? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - val SP = PreferenceManager.getDefaultSharedPreferences(context) - val am = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager - val alarm = am.nextAlarmClock - if (alarm != null) { - val time = am.nextAlarmClock.triggerTime - if (SP.getString(Constants.PREF_HOUR_FORMAT, "12") == "12") Constants.badHourFormat.format(time) else Constants.goodHourFormat.format(time) + try { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + val SP = PreferenceManager.getDefaultSharedPreferences(context) + val am = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager + val alarm = am.nextAlarmClock + if (alarm != null) { + val time = am.nextAlarmClock.triggerTime + if (SP.getString(Constants.PREF_HOUR_FORMAT, "12") == "12") Constants.badHourFormat.format(time) else Constants.goodHourFormat.format(time) + } else { + null + } } else { - null - } - } else { - val time = Settings.System.getString(context.contentResolver, - Settings.System.NEXT_ALARM_FORMATTED) - return if (time != "") { - time - } else { - null + val time = Settings.System.getString(context.contentResolver, + Settings.System.NEXT_ALARM_FORMATTED) + return if (time != "") { + time + } else { + null + } } + } catch (ignored: Exception) { + return null } } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt index 75ca5cf..012eccb 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/util/WeatherUtil.kt @@ -4,6 +4,7 @@ import android.Manifest import android.annotation.SuppressLint import android.app.UiModeManager import android.content.Context +import android.content.Context.LOCATION_SERVICE import android.content.SharedPreferences import android.location.* import android.os.Bundle @@ -44,6 +45,7 @@ object WeatherUtil { fun updateWeather(context: Context) { Util.showLocationNotification(context, false) val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + Util.showWeatherErrorNotification(context) if (SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").equals("") || SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").equals("")) { if (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) == Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS) { @@ -60,6 +62,25 @@ object WeatherUtil { .setResultCallback({ locationResult -> if (locationResult.status.isSuccess) { getCurrentWeather(context, locationResult.location) + } else { + val locationManager = context.getSystemService(LOCATION_SERVICE) as LocationManager + if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { + val gpsLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER) + if (gpsLocation != null) { + getCurrentWeather(context, gpsLocation) + } else { + if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { + val networkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER) + if (networkLocation != null) { + getCurrentWeather(context, networkLocation) + } else { + getWeatherByDefaultLocation(context) + } + } else { + getWeatherByDefaultLocation(context) + } + } + } } }) } @@ -75,7 +96,7 @@ object WeatherUtil { } val mGoogleApiClient = GoogleApiClient.Builder(context) .addApi(Awareness.API) - .build(); + .build() mGoogleApiClient.connect() Awareness.SnapshotApi.getWeather(mGoogleApiClient) @@ -95,6 +116,13 @@ object WeatherUtil { } + fun getWeatherByDefaultLocation(context: Context) { + val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + if (!SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").equals("") && !SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").equals("")) { + weatherNetworkRequest(context, SP.getString(Constants.PREF_CUSTOM_LOCATION_LAT, "").toDouble(), SP.getString(Constants.PREF_CUSTOM_LOCATION_LON, "").toDouble()) + } + } + @SuppressLint("ApplySharedPref") fun getCurrentWeather(context: Context, location: Location?) { if (location != null) { @@ -104,6 +132,11 @@ object WeatherUtil { fun weatherNetworkRequest(context: Context, latitude: Double, longitude: Double) { val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) + SP.edit() + .putString(Constants.PREF_CUSTOM_LOCATION_LAT, latitude.toString()) + .putString(Constants.PREF_CUSTOM_LOCATION_LON, longitude.toString()) + .apply() + if (!SP.getString(when (SP.getInt(Constants.PREF_WEATHER_PROVIDER, Constants.WEATHER_PROVIDER_GOOGLE_AWARENESS)) { Constants.WEATHER_PROVIDER_OPEN_WEATHER -> Constants.PREF_OPEN_WEATHER_API_KEY else -> Constants.PREF_OPEN_WEATHER_API_KEY diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a5f2a9c..999c9f1 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -281,6 +281,30 @@ android:id="@+id/clock_text_size_label" style="@style/AnotherWidget.Settings.Subtitle"/> + + + + - - - - "Provider del Meteo " Il provider meteo è configurato correttamente Il provider meteo deve essere configurato - Localizzazione disattivata - Riaccendi la localizzazione per avere il meteo aggiornato. + Riattiva la localizzazione + Google Awareness ha bisogno del GPS attivo per funzionare. Feedback AW Feedback Invia email… @@ -153,4 +153,6 @@ AW è attivo in background Mostra Anteprima Widget Nascondi Anteprima Widget + GPS Disattivato + Riattiva il GPS così che Another Widget possa aggiornare il meteo con le API di Google Awareness. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a1db4aa..f80809b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -73,8 +73,8 @@ Weather Provider The weather provider is configured correctly The weather provider must be configured - Location is turned off - Turn on the localization to get the updated weather. + Turn location on + Google Awareness needs active GPS to work. Feedback AW Feedback Send email… @@ -158,4 +158,6 @@ AW is running in the background Show Widget Preview Hide Widget Preview + Location is turned off + Turn Location back on so Another Widget can update weather informations with Google Awareness API.