Bug fixes, move clock format settings, fix network provider for weather updates and add notification when location is turned off with google awareness as provider
This commit is contained in:
parent
0a289d82b2
commit
2757f7f66f
@ -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"
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":28},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}]
|
||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":29},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}]
|
@ -83,6 +83,7 @@
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="com.tommasoberlose.anotherwidget.action.ACTION_WEATHER_UPDATE" />
|
||||
<action android:name="android.location.PROVIDERS_CHANGED" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||
|
@ -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
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)))
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -281,6 +281,30 @@
|
||||
android:id="@+id/clock_text_size_label"
|
||||
style="@style/AnotherWidget.Settings.Subtitle"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:paddingLeft="32dp"
|
||||
android:paddingRight="32dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/action_hour_format"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AnotherWidget.Settings.Title"
|
||||
android:text="@string/settings_hour_format_title"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/hour_format_label"
|
||||
style="@style/AnotherWidget.Settings.Subtitle"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -373,30 +397,6 @@
|
||||
android:id="@+id/date_format_label"
|
||||
style="@style/AnotherWidget.Settings.Subtitle"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:paddingLeft="32dp"
|
||||
android:paddingRight="32dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/action_hour_format"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AnotherWidget.Settings.Title"
|
||||
android:text="@string/settings_hour_format_title"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/hour_format_label"
|
||||
style="@style/AnotherWidget.Settings.Subtitle"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -9,7 +9,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="-16dp"
|
||||
android:lineSpacingMultiplier="1"
|
||||
android:lineSpacingExtra="0dp"
|
||||
android:visibility="gone"
|
||||
|
@ -71,8 +71,8 @@
|
||||
<string name="settings_weather_provider_api_key_title">"Provider del Meteo "</string>
|
||||
<string name="settings_weather_provider_api_key_subtitle_all_set">Il provider meteo è configurato correttamente</string>
|
||||
<string name="settings_weather_provider_api_key_subtitle_not_set">Il provider meteo deve essere configurato</string>
|
||||
<string name="notification_gps_title">Localizzazione disattivata</string>
|
||||
<string name="notification_gps_subtitle">Riaccendi la localizzazione per avere il meteo aggiornato.</string>
|
||||
<string name="notification_gps_title">Riattiva la localizzazione</string>
|
||||
<string name="notification_gps_subtitle">Google Awareness ha bisogno del GPS attivo per funzionare.</string>
|
||||
<string name="action_feedback">Feedback</string>
|
||||
<string name="feedback_title">AW Feedback</string>
|
||||
<string name="feedback_chooser_title">Invia email…</string>
|
||||
@ -153,4 +153,6 @@
|
||||
<string name="background_service_subtitle">AW è attivo in background</string>
|
||||
<string name="action_show_widget_preview">Mostra Anteprima Widget</string>
|
||||
<string name="action_hide_widget_preview">Nascondi Anteprima Widget</string>
|
||||
<string name="error_widget_notification_title">GPS Disattivato</string>
|
||||
<string name="error_widget_notification_subtitle">Riattiva il GPS così che Another Widget possa aggiornare il meteo con le API di Google Awareness.</string>
|
||||
</resources>
|
@ -73,8 +73,8 @@
|
||||
<string name="settings_weather_provider_api_key_title">Weather Provider</string>
|
||||
<string name="settings_weather_provider_api_key_subtitle_all_set">The weather provider is configured correctly</string>
|
||||
<string name="settings_weather_provider_api_key_subtitle_not_set">The weather provider must be configured</string>
|
||||
<string name="notification_gps_title">Location is turned off</string>
|
||||
<string name="notification_gps_subtitle">Turn on the localization to get the updated weather.</string>
|
||||
<string name="notification_gps_title">Turn location on</string>
|
||||
<string name="notification_gps_subtitle">Google Awareness needs active GPS to work.</string>
|
||||
<string name="action_feedback">Feedback</string>
|
||||
<string name="feedback_title">AW Feedback</string>
|
||||
<string name="feedback_chooser_title">Send email…</string>
|
||||
@ -158,4 +158,6 @@
|
||||
<string name="background_service_subtitle">AW is running in the background</string>
|
||||
<string name="action_show_widget_preview">Show Widget Preview</string>
|
||||
<string name="action_hide_widget_preview">Hide Widget Preview</string>
|
||||
<string name="error_widget_notification_title">Location is turned off</string>
|
||||
<string name="error_widget_notification_subtitle">Turn Location back on so Another Widget can update weather informations with Google Awareness API.</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user