Fix events order, fix horizontal resize, add widget preview toggle, fix next event function, fix weather icon click listner and relase v1.3-beta1
@ -17,7 +17,7 @@ android {
|
||||
applicationId "com.tommasoberlose.anotherwidget"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 26
|
||||
versionCode 27
|
||||
versionCode 28
|
||||
versionName "1.3"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":27},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}]
|
||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":28},"path":"app-release.apk","properties":{"packageId":"com.tommasoberlose.anotherwidget","split":"","minSdkVersion":"19"}}]
|
@ -12,6 +12,7 @@
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:name=".ui.AWApplication"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
@ -113,7 +114,7 @@
|
||||
<receiver
|
||||
android:name=".receiver.OpenWeatherIntentReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.tommasoberlose.anotherwidget.action.ACTION_OPEN_WEATHER_INTENT" />
|
||||
</intent-filter>
|
||||
@ -121,10 +122,12 @@
|
||||
|
||||
<service
|
||||
android:name=".util.CrocodileService"
|
||||
android:enabled="true"
|
||||
android:exported="true" />
|
||||
android:enabled="true"/>
|
||||
|
||||
<activity android:name=".ui.activity.SupportDevActivity"></activity>
|
||||
<activity android:name=".ui.activity.SupportDevActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:launchMode="singleInstance"
|
||||
android:screenOrientation="portrait" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -32,6 +32,7 @@ object Constants {
|
||||
val PREF_CALENDAR_ALL_DAY = "PREF_CALENDAR_ALL_DAY"
|
||||
val PREF_CALENDAR_FILTER = "PREF_CALENDAR_FILTER"
|
||||
|
||||
val PREF_EVENT_ID = "PREF_EVENT_ID"
|
||||
val PREF_NEXT_EVENT_ID = "PREF_NEXT_EVENT_ID"
|
||||
val PREF_NEXT_EVENT_NAME = "PREF_NEXT_EVENT_NAME"
|
||||
val PREF_NEXT_EVENT_START_DATE = "PREF_NEXT_EVENT_START_DATE"
|
||||
@ -69,6 +70,8 @@ object Constants {
|
||||
val PREF_SECOND_ROW_INFORMATION = "PREF_SECOND_ROW_INFORMATION"
|
||||
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
|
||||
|
||||
|
@ -10,7 +10,8 @@ import java.util.Date
|
||||
* Created by tommaso on 05/10/17.
|
||||
*/
|
||||
|
||||
open class Event(var id: Int = 0,
|
||||
open class Event(var id: Long = 0,
|
||||
var eventID: Long = 0,
|
||||
var title: String = "",
|
||||
var startDate: Long = 0,
|
||||
var endDate: Long = 0,
|
||||
|
@ -3,6 +3,7 @@ package com.tommasoberlose.anotherwidget.receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
|
||||
|
@ -27,7 +27,7 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
setUpdates(context)
|
||||
} else if (intent.action.equals(Constants.ACTION_TIME_UPDATE) || intent.action.equals("com.sec.android.widgetapp.APPWIDGET_RESIZE") || intent.action == "android.intent.action.USER_PRESENT") {
|
||||
val e: Event = CalendarUtil.getNextEvent(context)
|
||||
if (e.id == 0 || e.endDate <= Calendar.getInstance().timeInMillis) {
|
||||
if (e.id == 0.toLong() || e.endDate <= Calendar.getInstance().timeInMillis) {
|
||||
CalendarUtil.updateEventList(context)
|
||||
} else {
|
||||
Util.updateWidget(context)
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.tommasoberlose.anotherwidget.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.util.MyMigration
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
|
||||
class AWApplication : Application() {
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
Realm.init(this)
|
||||
val config = RealmConfiguration.Builder()
|
||||
.schemaVersion(2)
|
||||
.migration(MyMigration())
|
||||
.deleteRealmIfMigrationNeeded()
|
||||
.build()
|
||||
Realm.setDefaultConfiguration(config)
|
||||
}
|
||||
}
|
@ -59,6 +59,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
@ -66,6 +67,8 @@ class MainActivity : AppCompatActivity() {
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
if (intent.extras?.containsKey(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER) == true) {
|
||||
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
|
||||
}
|
||||
@ -98,6 +101,28 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
})
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_WIDGET_PREVIEW, true)) {
|
||||
menuView.widget_preview_icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_action_hide_preview))
|
||||
menuView.widget_preview_label.text = getString(R.string.action_hide_widget_preview)
|
||||
menuView.action_toggle_widget_preview.setOnClickListener {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_WIDGET_PREVIEW, false)
|
||||
.commit()
|
||||
updateUI()
|
||||
mBottomSheetDialog.dismiss()
|
||||
}
|
||||
} else {
|
||||
menuView.widget_preview_icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_action_show_preview))
|
||||
menuView.widget_preview_label.text = getString(R.string.action_show_widget_preview)
|
||||
menuView.action_toggle_widget_preview.setOnClickListener {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_WIDGET_PREVIEW, true)
|
||||
.commit()
|
||||
updateUI()
|
||||
mBottomSheetDialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
menuView.action_rate.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(p0: View?) {
|
||||
Util.rateApp(this@MainActivity, "https://play.google.com/store/apps/details?id=com.tommasoberlose.anotherwidget")
|
||||
@ -183,16 +208,23 @@ class MainActivity : AppCompatActivity() {
|
||||
updateClockView()
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val displayMetrics = Resources.getSystem().displayMetrics
|
||||
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()
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_WIDGET_PREVIEW, true)) {
|
||||
val displayMetrics = Resources.getSystem().displayMetrics
|
||||
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()
|
||||
}
|
||||
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.layoutParams.height = height + Util.convertDpToPixel(16f, this).toInt()
|
||||
|
||||
widget.visibility = View.VISIBLE
|
||||
} else {
|
||||
widget.visibility = View.GONE
|
||||
}
|
||||
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.layoutParams.height = height + Util.convertDpToPixel(16f, this).toInt()
|
||||
}
|
||||
|
||||
|
||||
@ -283,7 +315,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if (calendarLayout) {
|
||||
val e = CalendarUtil.getNextEvent(this)
|
||||
|
||||
if (e.id != 0) {
|
||||
if (e.id != 0.toLong()) {
|
||||
next_event.text = e.title
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, false) && CalendarUtil.getEventsCount(this) > 1) {
|
||||
@ -364,8 +396,8 @@ class MainActivity : AppCompatActivity() {
|
||||
second_row_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
|
||||
second_row_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
|
||||
|
||||
weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 20f
|
||||
weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 20f
|
||||
weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
|
||||
weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
|
||||
|
||||
empty_weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) / 24f
|
||||
empty_weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) / 24f
|
||||
|
@ -32,62 +32,66 @@ class SupportDevActivity : AppCompatActivity(), BillingProcessor.IBillingHandler
|
||||
|
||||
override fun onBillingInitialized() {
|
||||
loader.visibility = View.GONE
|
||||
val isAvailable = BillingProcessor.isIabServiceAvailable(this)
|
||||
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")
|
||||
try {
|
||||
val isAvailable = BillingProcessor.isIabServiceAvailable(this)
|
||||
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")
|
||||
|
||||
if (coffee != null) {
|
||||
import_donation_coffee.text = coffee.priceText
|
||||
action_donation_coffee.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_coffee")
|
||||
if (coffee != null) {
|
||||
import_donation_coffee.text = coffee.priceText
|
||||
action_donation_coffee.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_coffee")
|
||||
}
|
||||
} else {
|
||||
action_donation_coffee.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
action_donation_coffee.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (donuts != null) {
|
||||
import_donation_donuts.text = donuts.priceText
|
||||
action_donation_donuts.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_donuts")
|
||||
if (donuts != null) {
|
||||
import_donation_donuts.text = donuts.priceText
|
||||
action_donation_donuts.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_donuts")
|
||||
}
|
||||
} else {
|
||||
action_donation_donuts.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
action_donation_donuts.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (breakfast != null) {
|
||||
import_donation_breakfast.text = breakfast.priceText
|
||||
action_donation_breakfast.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_breakfast")
|
||||
if (breakfast != null) {
|
||||
import_donation_breakfast.text = breakfast.priceText
|
||||
action_donation_breakfast.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_breakfast")
|
||||
}
|
||||
} else {
|
||||
action_donation_breakfast.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
action_donation_breakfast.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (lunch != null) {
|
||||
import_donation_lunch.text = lunch.priceText
|
||||
action_donation_lunch.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_lunch")
|
||||
if (lunch != null) {
|
||||
import_donation_lunch.text = lunch.priceText
|
||||
action_donation_lunch.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_lunch")
|
||||
}
|
||||
} else {
|
||||
action_donation_lunch.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
action_donation_lunch.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (dinner != null) {
|
||||
import_donation_dinner.text = dinner.priceText
|
||||
action_donation_dinner.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_dinner")
|
||||
if (dinner != null) {
|
||||
import_donation_dinner.text = dinner.priceText
|
||||
action_donation_dinner.setOnClickListener {
|
||||
bp!!.purchase(this, "donation_dinner")
|
||||
}
|
||||
} else {
|
||||
action_donation_dinner.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
action_donation_dinner.visibility = View.GONE
|
||||
}
|
||||
|
||||
products_list.visibility = View.VISIBLE
|
||||
} else {
|
||||
products_list.visibility = View.VISIBLE
|
||||
} else {
|
||||
products_card.visibility = View.GONE
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
products_card.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import android.text.style.StyleSpan
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.TypedValue
|
||||
import android.widget.LinearLayout
|
||||
import com.tommasoberlose.anotherwidget.receiver.OpenWeatherIntentReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.view.CustomTypefaceSpan
|
||||
import kotlinx.android.synthetic.main.the_widget.*
|
||||
import kotlinx.android.synthetic.main.the_widget.view.*
|
||||
@ -136,6 +137,8 @@ class TheWidget : AppWidgetProvider() {
|
||||
views = updateLocationView(context, views, appWidgetId)
|
||||
views = updateClockView(context, views, appWidgetId)
|
||||
|
||||
views = fixViewsMargin(context, views)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
}
|
||||
|
||||
@ -160,7 +163,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
if (calendarLayout) {
|
||||
val e = CalendarUtil.getNextEvent(context)
|
||||
|
||||
if (e.id != 0) {
|
||||
if (e.id != 0.toLong()) {
|
||||
views.setTextViewText(R.id.next_event, e.title)
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, false) && CalendarUtil.getEventsCount(context) > 1) {
|
||||
@ -277,8 +280,9 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setTextViewText(R.id.temp, temp)
|
||||
views.setTextViewText(R.id.calendar_temp, temp)
|
||||
|
||||
|
||||
val weatherPIntent = PendingIntent.getBroadcast(context, widgetID, Intent(Constants.ACTION_OPEN_WEATHER_INTENT), 0)
|
||||
val i = Intent(context, OpenWeatherIntentReceiver::class.java)
|
||||
i.action = Constants.ACTION_OPEN_WEATHER_INTENT
|
||||
val weatherPIntent = PendingIntent.getBroadcast(context, widgetID, i, 0)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.weather, weatherPIntent)
|
||||
views.setOnClickPendingIntent(R.id.calendar_weather, weatherPIntent)
|
||||
@ -293,9 +297,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (!SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
|
||||
views.setViewVisibility(R.id.time, View.GONE)
|
||||
views.setViewVisibility(R.id.bottom_divider, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.bottom_divider, View.GONE)
|
||||
val now = Calendar.getInstance()
|
||||
if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) {
|
||||
val textBadHour = SpannableString(Constants.badHourFormat.format(now.timeInMillis).replace(" ", ""))
|
||||
@ -315,6 +317,26 @@ class TheWidget : AppWidgetProvider() {
|
||||
return views
|
||||
}
|
||||
|
||||
fun fixViewsMargin(context: Context, views: RemoteViews): RemoteViews {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
views.setViewVisibility(R.id.bottom_divider_24, View.GONE)
|
||||
views.setViewVisibility(R.id.bottom_divider_16, View.GONE)
|
||||
views.setViewVisibility(R.id.bottom_divider_8, View.GONE)
|
||||
val eVisible = SP.getBoolean(Constants.PREF_SHOW_EVENTS, true) && Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_CLOCK, false)) {
|
||||
if (eVisible) {
|
||||
views.setViewVisibility(R.id.bottom_divider_8, View.VISIBLE)
|
||||
} else {
|
||||
views.setViewVisibility(R.id.bottom_divider_24, View.VISIBLE)
|
||||
}
|
||||
} else {
|
||||
if (eVisible) {
|
||||
views.setViewVisibility(R.id.bottom_divider_8, View.VISIBLE)
|
||||
}
|
||||
}
|
||||
return views
|
||||
}
|
||||
|
||||
fun updateCalendarViewByLayout(context: Context, v: View): View {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val now = Calendar.getInstance()
|
||||
@ -332,7 +354,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
if (calendarLayout) {
|
||||
val e = CalendarUtil.getNextEvent(context)
|
||||
|
||||
if (e.id != 0) {
|
||||
if (e.id != 0.toLong()) {
|
||||
v.next_event.text = e.title
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_NEXT_EVENT, false) && CalendarUtil.getEventsCount(context) > 1) {
|
||||
@ -418,8 +440,8 @@ class TheWidget : AppWidgetProvider() {
|
||||
v.second_row_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
|
||||
v.second_row_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 18f
|
||||
|
||||
v.weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 20f
|
||||
v.weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 20f
|
||||
v.weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
v.weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_SECOND_SIZE, 16f) / 16f
|
||||
|
||||
v.empty_weather_icon.scaleX = SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) / 24f
|
||||
v.empty_weather_icon.scaleY = SP.getFloat(Constants.PREF_TEXT_MAIN_SIZE, 24f) / 24f
|
||||
|
@ -72,7 +72,7 @@ object CalendarUtil {
|
||||
instance.begin = start.timeInMillis - start.timeZone.getOffset(start.timeInMillis)
|
||||
instance.end = end.timeInMillis - end.timeZone.getOffset(end.timeInMillis)
|
||||
}
|
||||
eventList.add(Event(e.id.toInt(), 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 ?: ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,8 +118,7 @@ object CalendarUtil {
|
||||
}
|
||||
|
||||
fun saveEvents(context: Context, eventList: ArrayList<Event>) {
|
||||
Realm.init(context)
|
||||
val db = Realm.getDefaultInstance()
|
||||
val db = Util.getRealInstance(context)
|
||||
db.executeTransaction { realm ->
|
||||
realm.where(Event::class.java).findAll().deleteAllFromRealm()
|
||||
realm.copyToRealm(eventList)
|
||||
@ -128,13 +127,13 @@ object CalendarUtil {
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
fun resetNextEventData(context: Context) {
|
||||
Realm.init(context)
|
||||
val db = Realm.getDefaultInstance()
|
||||
val db = Util.getRealInstance(context)
|
||||
db.executeTransaction {
|
||||
db.where(Event::class.java).findAll().deleteAllFromRealm()
|
||||
}
|
||||
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
SP.edit()
|
||||
.remove(Constants.PREF_EVENT_ID)
|
||||
.remove(Constants.PREF_NEXT_EVENT_ID)
|
||||
.remove(Constants.PREF_NEXT_EVENT_NAME)
|
||||
.remove(Constants.PREF_NEXT_EVENT_START_DATE)
|
||||
@ -150,34 +149,20 @@ object CalendarUtil {
|
||||
fun saveNextEventData(context: Context, event: Event) {
|
||||
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
SP.edit()
|
||||
.putInt(Constants.PREF_NEXT_EVENT_ID, event.id)
|
||||
.putLong(Constants.PREF_EVENT_ID, event.id)
|
||||
.commit()
|
||||
Util.updateWidget(context)
|
||||
}
|
||||
|
||||
fun getNextEvent(context: Context): Event {
|
||||
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
Realm.init(context)
|
||||
val db = Realm.getDefaultInstance()
|
||||
val nextEvent = db.where(Event::class.java).equalTo("id", SP.getInt(Constants.PREF_NEXT_EVENT_ID, 0)).findFirst()
|
||||
val db = Util.getRealInstance(context)
|
||||
val nextEvent = db.where(Event::class.java).equalTo("id", SP.getLong(Constants.PREF_EVENT_ID, 0)).findFirst()
|
||||
return if (nextEvent != null) {
|
||||
nextEvent
|
||||
} else {
|
||||
val eventList = db.where(Event::class.java).findAll()
|
||||
|
||||
if (eventList.isNotEmpty()) {
|
||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
||||
if (event.allDay && event1.allDay) {
|
||||
event.startDate.compareTo(event1.startDate)
|
||||
} else if (event.allDay) {
|
||||
1
|
||||
} else if (event1.allDay) {
|
||||
-1
|
||||
} else {
|
||||
event1.startDate.compareTo(event.startDate)
|
||||
}
|
||||
})
|
||||
eventList.reverse()
|
||||
eventList[0] ?: Event()
|
||||
} else {
|
||||
Event()
|
||||
@ -187,36 +172,21 @@ object CalendarUtil {
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
fun goToNextEvent(context: Context) {
|
||||
Realm.init(context)
|
||||
val db = Realm.getDefaultInstance()
|
||||
val db = Util.getRealInstance(context)
|
||||
val SP: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val eventList = db.where(Event::class.java).findAll()
|
||||
|
||||
if (eventList.isNotEmpty()) {
|
||||
/*
|
||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
||||
if (event.allDay && event1.allDay) {
|
||||
event.startDate.compareTo(event1.startDate)
|
||||
} else if (event.allDay) {
|
||||
1
|
||||
} else if (event1.allDay) {
|
||||
-1
|
||||
} else {
|
||||
event1.startDate.compareTo(event.startDate)
|
||||
}
|
||||
})
|
||||
eventList.reverse()*/
|
||||
|
||||
var found = false
|
||||
for (e in eventList) {
|
||||
if (e.id == SP.getInt(Constants.PREF_NEXT_EVENT_ID, 0)) {
|
||||
if (e.id == SP.getLong(Constants.PREF_EVENT_ID, 0)) {
|
||||
if (eventList.indexOf(e) < eventList.size - 1) {
|
||||
SP.edit()
|
||||
.putInt(Constants.PREF_NEXT_EVENT_ID, eventList[eventList.indexOf(e) + 1]?.id ?: 0)
|
||||
.putLong(Constants.PREF_EVENT_ID, eventList[eventList.indexOf(e) + 1]?.id ?: 0)
|
||||
.commit()
|
||||
} else {
|
||||
SP.edit()
|
||||
.putInt(Constants.PREF_NEXT_EVENT_ID, eventList[0]?.id ?: 0)
|
||||
.putLong(Constants.PREF_EVENT_ID, eventList[0]?.id ?: 0)
|
||||
.commit()
|
||||
}
|
||||
found = true
|
||||
@ -226,7 +196,7 @@ object CalendarUtil {
|
||||
|
||||
if (!found) {
|
||||
SP.edit()
|
||||
.putInt(Constants.PREF_NEXT_EVENT_ID, eventList[0]?.id ?: 0)
|
||||
.putLong(Constants.PREF_EVENT_ID, eventList[0]?.id ?: 0)
|
||||
.commit()
|
||||
}
|
||||
} else {
|
||||
@ -237,8 +207,7 @@ object CalendarUtil {
|
||||
}
|
||||
|
||||
fun getEventsCount(context: Context): Int {
|
||||
Realm.init(context)
|
||||
val db = Realm.getDefaultInstance()
|
||||
val db = Util.getRealInstance(context)
|
||||
return db.where(Event::class.java).findAll().size
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ class CrocodileService : Service() {
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(this, "Settings")
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(this, "Config")
|
||||
.setSmallIcon(R.drawable.ic_stat_name)
|
||||
.setPriority(Notification.PRIORITY_MIN)
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
|
||||
|
@ -0,0 +1,51 @@
|
||||
package com.tommasoberlose.anotherwidget.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import io.realm.DynamicRealm;
|
||||
import io.realm.DynamicRealmObject;
|
||||
import io.realm.RealmMigration;
|
||||
import io.realm.RealmObjectSchema;
|
||||
import io.realm.RealmSchema;
|
||||
|
||||
/**
|
||||
* Created by tommaso on 06/11/17.
|
||||
*/
|
||||
|
||||
public class MyMigration implements RealmMigration {
|
||||
@Override
|
||||
public void migrate(@NonNull DynamicRealm realm, long oldVersion, long newVersion) {
|
||||
|
||||
RealmSchema schema = realm.getSchema();
|
||||
if (oldVersion == 1) {
|
||||
RealmObjectSchema event = schema.get("Event");
|
||||
if (event != null) {
|
||||
if (!event.hasField("eventID")) {
|
||||
event.addField("eventID", long.class);
|
||||
}
|
||||
event
|
||||
.addField("id_tmp", long.class)
|
||||
.transform(new RealmObjectSchema.Function() {
|
||||
@Override
|
||||
public void apply(@NonNull DynamicRealmObject obj) {
|
||||
obj.setLong("id_tmp", obj.getInt("id"));
|
||||
}
|
||||
})
|
||||
.removeField("id")
|
||||
.renameField("id_tmp", "id");
|
||||
}
|
||||
oldVersion++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 37;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof MyMigration);
|
||||
}
|
||||
}
|
@ -39,6 +39,8 @@ import android.widget.RemoteViews
|
||||
import android.widget.Toast
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.`object`.Event
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmConfiguration
|
||||
import org.joda.time.DateTime
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@ -68,7 +70,7 @@ object Util {
|
||||
val mNotificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
|
||||
|
||||
if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) {
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Settings")
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Config")
|
||||
.setSmallIcon(R.drawable.ic_stat_name)
|
||||
.setPriority(Notification.PRIORITY_MIN)
|
||||
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
|
||||
@ -284,7 +286,7 @@ object Util {
|
||||
if (SP.getString(Constants.PREF_WEATHER_APP_PACKAGE, "").equals("")) {
|
||||
val weatherIntent: Intent = Intent(Intent.ACTION_VIEW)
|
||||
weatherIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
weatherIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
weatherIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
weatherIntent.data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
weatherIntent.component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
return weatherIntent
|
||||
@ -295,12 +297,12 @@ object Util {
|
||||
return try {
|
||||
val intent: Intent = pm.getLaunchIntentForPackage(SP.getString(Constants.PREF_WEATHER_APP_PACKAGE, ""))
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
intent
|
||||
} catch (e: Exception) {
|
||||
val weatherIntent: Intent = Intent(Intent.ACTION_VIEW)
|
||||
weatherIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
weatherIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
weatherIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
weatherIntent.data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
weatherIntent.component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
weatherIntent
|
||||
@ -311,7 +313,7 @@ object Util {
|
||||
fun getEventIntent(context: Context, e: Event): Intent {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (SP.getString(Constants.PREF_EVENT_APP_PACKAGE, "").equals("")) {
|
||||
val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, e.id.toLong())
|
||||
val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, e.eventID)
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setData(uri)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
@ -380,7 +382,7 @@ object Util {
|
||||
val mNotificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
|
||||
|
||||
if (show) {
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Settings")
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Config")
|
||||
.setSmallIcon(R.drawable.ic_stat_name)
|
||||
.setPriority(Notification.PRIORITY_MIN)
|
||||
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
|
||||
@ -402,7 +404,7 @@ object Util {
|
||||
val mNotificationManager: NotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
|
||||
|
||||
if (show) {
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Settings")
|
||||
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(context, "Config")
|
||||
.setSmallIcon(R.drawable.ic_stat_name)
|
||||
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
|
||||
.setContentTitle(context.getString(R.string.settings_weather_provider_api_key_title))
|
||||
@ -566,7 +568,7 @@ object Util {
|
||||
@SuppressLint("ApplySharedPref")
|
||||
fun updateSettingsByDefault(context: Context) {
|
||||
try {
|
||||
context.startService(Intent(context, CrocodileService::class.java))
|
||||
// context.startService(Intent(context, CrocodileService::class.java))
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
@ -584,6 +586,10 @@ object Util {
|
||||
editor.commit()
|
||||
}
|
||||
|
||||
fun getRealInstance(context: Context): Realm {
|
||||
return Realm.getDefaultInstance()
|
||||
}
|
||||
|
||||
fun getNextAlarm(context: Context): String? {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
@ -188,15 +188,10 @@ object WeatherUtil {
|
||||
icon = "82"
|
||||
}
|
||||
|
||||
val uiManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
||||
return when {
|
||||
uiManager.nightMode == UiModeManager.MODE_NIGHT_YES -> icon + "n"
|
||||
uiManager.nightMode == UiModeManager.MODE_NIGHT_NO -> icon + "d"
|
||||
else -> return if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) >= 19 || Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 7) {
|
||||
icon + "n"
|
||||
} else {
|
||||
icon + "d"
|
||||
}
|
||||
return if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) >= 19 || Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 7) {
|
||||
icon + "n"
|
||||
} else {
|
||||
icon + "d"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
app/src/main/res/drawable-hdpi/ic_action_hide_preview.png
Normal file
After Width: | Height: | Size: 854 B |
BIN
app/src/main/res/drawable-hdpi/ic_action_show_preview.png
Normal file
After Width: | Height: | Size: 770 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_hide_preview.png
Normal file
After Width: | Height: | Size: 527 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_show_preview.png
Normal file
After Width: | Height: | Size: 500 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_hide_preview.png
Normal file
After Width: | Height: | Size: 981 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_show_preview.png
Normal file
After Width: | Height: | Size: 980 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_hide_preview.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_show_preview.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
@ -36,6 +36,35 @@
|
||||
android:paddingRight="16dp"
|
||||
android:textColor="@android:color/black" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:padding="16dp"
|
||||
android:textSize="14sp"
|
||||
android:id="@+id/action_toggle_widget_preview"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:id="@+id/widget_preview_icon"
|
||||
android:tint="@android:color/black"
|
||||
android:src="@drawable/ic_action_rate"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_hide_widget_preview"
|
||||
style="@style/AnotherWidget.Settings.Title"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:id="@+id/widget_preview_label"
|
||||
android:textColor="@android:color/black"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -31,7 +31,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:lines="1"
|
||||
android:maxLines="1"
|
||||
android:gravity="right"
|
||||
android:ellipsize="end"
|
||||
android:text="@string/loading_text"
|
||||
android:includeFontPadding="false"
|
||||
|
@ -18,11 +18,23 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/intent_container" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/bottom_divider_8"
|
||||
android:orientation="vertical" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="16dp"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/bottom_divider"
|
||||
android:id="@+id/bottom_divider_16"
|
||||
android:orientation="vertical" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="24dp"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/bottom_divider_24"
|
||||
android:orientation="vertical" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
@ -151,4 +151,6 @@
|
||||
<string name="donation_lunch">Una Pranzo Veloce</string>
|
||||
<string name="background_service_title">Another Widget è attivo</string>
|
||||
<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>
|
||||
</resources>
|
@ -156,4 +156,6 @@
|
||||
<string name="donation_lunch">A Quick Lunch</string>
|
||||
<string name="background_service_title">Another Widget is Running</string>
|
||||
<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>
|
||||
</resources>
|
||||
|
@ -8,6 +8,6 @@
|
||||
android:minResizeHeight="60dp"
|
||||
android:minResizeWidth="300dp"
|
||||
android:previewImage="@drawable/widget_preview"
|
||||
android:resizeMode="vertical"
|
||||
android:resizeMode="vertical|horizontal"
|
||||
android:updatePeriodMillis="60000"
|
||||
android:widgetCategory="home_screen" />
|
@ -7,6 +7,6 @@
|
||||
android:minResizeHeight="60dp"
|
||||
android:minResizeWidth="300dp"
|
||||
android:previewImage="@drawable/widget_preview"
|
||||
android:resizeMode="vertical"
|
||||
android:resizeMode="vertical|horizontal"
|
||||
android:updatePeriodMillis="60000"
|
||||
android:widgetCategory="home_screen" />
|