New changes and fixes
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
package com.tommasoberlose.anotherwidget.`object`
|
||||
|
||||
import android.content.pm.ApplicationInfo
|
||||
|
||||
/**
|
||||
* Created by tommaso on 15/10/17.
|
||||
*/
|
||||
|
||||
class ApplicationListEvent(apps: List<ApplicationInfo>, filtered: Boolean) {
|
||||
var apps: List<ApplicationInfo> = ArrayList()
|
||||
var filtered: Boolean = false
|
||||
init {
|
||||
this.apps = apps
|
||||
this.filtered = filtered
|
||||
}
|
||||
}
|
@ -12,10 +12,16 @@ import java.util.*
|
||||
object Constants {
|
||||
val CALENDAR_REQUEST_CODE = 1
|
||||
val LOCATION_REQUEST_CODE = 2
|
||||
val CALENDAR_APP_REQUEST_CODE = 3
|
||||
val WEATHER_APP_REQUEST_CODE = 4
|
||||
|
||||
|
||||
val RESULT_CODE_CUSTOM_LOCATION = 45
|
||||
val RESULT_APP_NAME = "RESULT_APP_NAME"
|
||||
val RESULT_APP_PACKAGE = "RESULT_APP_PACKAGE"
|
||||
|
||||
val PREF_FIRST_STEP = "PREF_FIRST_STEP"
|
||||
val PREF_SHOW_EVENTS = "PREF_SHOW_EVENTS"
|
||||
val PREF_SHOW_WEATHER = "PREF_SHOW_WEATHER"
|
||||
val PREF_WEATHER_ICON = "PREF_WEATHER_ICON"
|
||||
val PREF_WEATHER_TEMP = "PREF_WEATHER_TEMP"
|
||||
val PREF_WEATHER_TEMP_UNIT = "PREF_WEATHER_TEMP_UNIT"
|
||||
@ -34,11 +40,16 @@ object Constants {
|
||||
val PREF_HOUR_FORMAT = "PREF_HOUR_FORMAT"
|
||||
val PREF_ITA_FORMAT_DATE = "PREF_ITA_FORMAT_DATE"
|
||||
val PREF_WEATHER_REFRESH_PERIOD = "PREF_WEATHER_REFRESH_PERIOD"
|
||||
val PREF_SHOW_UNTIL = "PREF_SHOW_UNTIL"
|
||||
val PREF_CALENDAR_APP_NAME = "PREF_CALENDAR_APP_NAME"
|
||||
val PREF_CALENDAR_APP_PACKAGE = "PREF_CALENDAR_APP_PACKAGE"
|
||||
val PREF_WEATHER_APP_NAME = "PREF_WEATHER_APP_NAME"
|
||||
val PREF_WEATHER_APP_PACKAGE = "PREF_WEATHER_APP_PACKAGE"
|
||||
|
||||
val itDateFormat = SimpleDateFormat("EEEE, d MMM")
|
||||
val engDateFormat = SimpleDateFormat("EEEE, MMM d")
|
||||
val goodHourFormat = SimpleDateFormat("HH:mm")
|
||||
val badHourFormat = SimpleDateFormat("KK:mm aa")
|
||||
val badHourFormat = SimpleDateFormat("hh:mm a")
|
||||
|
||||
val ACTION_TIME_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_TIME_UPDATE"
|
||||
val ACTION_CALENDAR_UPDATE = "com.tommasoberlose.anotherwidget.action.ACTION_CALENDAR_UPDATE"
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.tommasoberlose.anotherwidget.`object`
|
||||
|
||||
import android.location.Address
|
||||
|
||||
/**
|
||||
* Created by tommaso on 14/10/17.
|
||||
*/
|
||||
|
||||
class CustomLocationEvent(addresses: ArrayList<Address>) {
|
||||
var addresses: ArrayList<Address> = ArrayList()
|
||||
init {
|
||||
this.addresses = addresses
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.location.Address
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.`object`.CustomLocationEvent
|
||||
import kotlinx.android.synthetic.main.activity_choose_application.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import com.tommasoberlose.anotherwidget.`object`.ApplicationListEvent
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.Geocoder
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
|
||||
|
||||
class ChooseApplicationActivity : AppCompatActivity() {
|
||||
lateinit var adapter: ArrayAdapter<String>
|
||||
val appList = ArrayList<ApplicationInfo>()
|
||||
val appListFiltered = ArrayList<ApplicationInfo>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_choose_application)
|
||||
val pm = packageManager
|
||||
|
||||
action_default.setOnClickListener {
|
||||
selectDefaultApp()
|
||||
}
|
||||
|
||||
adapter = ArrayAdapter(this, R.layout.custom_location_item, appList.map { it.name })
|
||||
list_view.adapter = adapter
|
||||
|
||||
list_view.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, pm.getApplicationLabel(appListFiltered[position]).toString())
|
||||
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, appListFiltered[position].packageName)
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
location.addTextChangedListener(object: TextWatcher {
|
||||
override fun afterTextChanged(text: Editable?) {
|
||||
Thread().run {
|
||||
val appsFiltered = appList.filter { pm.getApplicationLabel(it).toString().contains(text.toString(), true) }
|
||||
EventBus.getDefault().post(ApplicationListEvent(appsFiltered, true))
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fun selectDefaultApp() {
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, getString(R.string.default_name))
|
||||
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, "")
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
public override fun onStart() {
|
||||
super.onStart()
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
public override fun onResume() {
|
||||
super.onResume()
|
||||
Thread().run {
|
||||
val pm = packageManager
|
||||
val apps = pm.getInstalledApplications(0)
|
||||
EventBus.getDefault().post(ApplicationListEvent(apps, false))
|
||||
}
|
||||
}
|
||||
|
||||
public override fun onStop() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onMessageEvent(event: ApplicationListEvent) {
|
||||
val pm = packageManager
|
||||
adapter.clear()
|
||||
if (!event.filtered) {
|
||||
appList.clear()
|
||||
event.apps.mapTo(appList, {it})
|
||||
for (a:ApplicationInfo in appList) {
|
||||
adapter.add(pm.getApplicationLabel(a).toString())
|
||||
}
|
||||
}
|
||||
appListFiltered.clear()
|
||||
event.apps.mapTo(appListFiltered, {it})
|
||||
for (a:ApplicationInfo in appListFiltered) {
|
||||
adapter.add(pm.getApplicationLabel(a).toString())
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
@ -19,13 +19,24 @@ import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ListView
|
||||
import android.widget.Toast
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.`object`.CustomLocationEvent
|
||||
import com.tommasoberlose.anotherwidget.util.WeatherUtil
|
||||
import kotlinx.android.synthetic.main.activity_custom_location.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CustomLocationActivity : AppCompatActivity() {
|
||||
lateinit var adapter: ArrayAdapter<String>
|
||||
val addressesList = ArrayList<Address>()
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -34,11 +45,7 @@ class CustomLocationActivity : AppCompatActivity() {
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
val list = ArrayList<String>()
|
||||
val addressesList = ArrayList<Address>()
|
||||
val thread: Thread = Thread()
|
||||
|
||||
var adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, list)
|
||||
adapter = ArrayAdapter(this, R.layout.custom_location_item, addressesList.map { it.getAddressLine(0) })
|
||||
list_view.adapter = adapter
|
||||
|
||||
list_view.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
|
||||
@ -51,21 +58,26 @@ class CustomLocationActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
action_geolocation.setOnClickListener {
|
||||
SP.edit()
|
||||
.remove(Constants.PREF_CUSTOM_LOCATION_LAT)
|
||||
.remove(Constants.PREF_CUSTOM_LOCATION_LON)
|
||||
.remove(Constants.PREF_CUSTOM_LOCATION_ADD)
|
||||
.commit()
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
|
||||
location.addTextChangedListener(object: TextWatcher {
|
||||
override fun afterTextChanged(text: Editable?) {
|
||||
val coder = Geocoder(this@CustomLocationActivity)
|
||||
try {
|
||||
val addresses = coder.getFromLocationName(text.toString(), 10) as ArrayList<Address>
|
||||
list.clear()
|
||||
addressesList.clear()
|
||||
|
||||
addresses.mapTo(list) { it.getAddressLine(0) }
|
||||
addresses.mapTo(addressesList) { it }
|
||||
|
||||
adapter = ArrayAdapter(this@CustomLocationActivity, R.layout.custom_location_item, list)
|
||||
list_view.adapter = adapter
|
||||
} catch (ignored: Exception) {
|
||||
Toast.makeText(this@CustomLocationActivity, "Erroreeeee", Toast.LENGTH_SHORT).show()
|
||||
Thread().run {
|
||||
val coder = Geocoder(this@CustomLocationActivity)
|
||||
try {
|
||||
val addresses = coder.getFromLocationName(text.toString(), 10) as ArrayList<Address>
|
||||
EventBus.getDefault().post(CustomLocationEvent(addresses))
|
||||
} catch (ignored: Exception) {
|
||||
EventBus.getDefault().post(CustomLocationEvent(ArrayList<Address>()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,4 +89,25 @@ class CustomLocationActivity : AppCompatActivity() {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
public override fun onStart() {
|
||||
super.onStart()
|
||||
EventBus.getDefault().register(this)
|
||||
}
|
||||
|
||||
public override fun onStop() {
|
||||
EventBus.getDefault().unregister(this)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onMessageEvent(event: CustomLocationEvent) {
|
||||
adapter.clear()
|
||||
addressesList.clear()
|
||||
event.addresses.mapTo(addressesList, {it})
|
||||
for (a:Address in addressesList) {
|
||||
adapter.add(a.getAddressLine(0))
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import android.view.View
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
import com.tommasoberlose.anotherwidget.receiver.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.receiver.WeatherReceiver
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -25,13 +24,9 @@ import com.tommasoberlose.anotherwidget.util.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.util.WeatherUtil
|
||||
import android.content.DialogInterface
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import com.github.rubensousa.bottomsheetbuilder.BottomSheetBuilder
|
||||
import com.github.rubensousa.bottomsheetbuilder.BottomSheetMenuDialog
|
||||
import com.tommasoberlose.anotherwidget.`object`.CalendarSelector
|
||||
import io.fabric.sdk.android.Fabric
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
@ -40,18 +35,38 @@ import kotlinx.android.synthetic.main.the_widget.*
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
var mAppWidgetId: Int = -1
|
||||
|
||||
private val receiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
updateUI()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
Fabric.with(this, Crashlytics())
|
||||
|
||||
val extras = intent.extras
|
||||
if (extras != null) {
|
||||
mAppWidgetId = extras.getInt(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||
|
||||
if (mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
|
||||
action_refresh.visibility = View.GONE
|
||||
action_support.visibility = View.GONE
|
||||
action_share.visibility = View.GONE
|
||||
action_add_widget.visibility = View.VISIBLE
|
||||
|
||||
action_add_widget.setOnClickListener {
|
||||
addNewWidget()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
action_support.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(p0: View?) {
|
||||
Util.openURI(this@MainActivity, "https://paypal.me/tommasoberlose")
|
||||
@ -64,11 +79,28 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
})
|
||||
|
||||
action_rate.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(p0: View?) {
|
||||
Util.openURI(this@MainActivity, "https://play.google.com/store/apps/details?id=com.tommasoberlose.anotherwidget")
|
||||
}
|
||||
})
|
||||
action_refresh.setOnClickListener {
|
||||
WeatherUtil.updateWeather(this)
|
||||
CalendarUtil.updateEventList(this)
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (mAppWidgetId > 0) {
|
||||
addNewWidget()
|
||||
} else {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
fun addNewWidget() {
|
||||
val resultValue = Intent()
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)
|
||||
setResult(Activity.RESULT_OK, resultValue)
|
||||
finish()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@ -89,38 +121,19 @@ class MainActivity : AppCompatActivity() {
|
||||
when (requestCode) {
|
||||
Constants.CALENDAR_REQUEST_CODE -> if (!(permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED)) {
|
||||
CalendarUtil.updateEventList(this)
|
||||
updateAppWidget()
|
||||
updateSettings()
|
||||
}
|
||||
Constants.LOCATION_REQUEST_CODE -> if (!(permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED)) {
|
||||
WeatherUtil.updateWeather(this)
|
||||
updateAppWidget()
|
||||
updateSettings()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateUI() {
|
||||
no_calendar_permission_container.visibility= View.GONE
|
||||
no_location_permission_container.visibility= View.GONE
|
||||
all_set_container.visibility = View.GONE
|
||||
updateSettings()
|
||||
|
||||
if (!Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)) {
|
||||
no_calendar_permission_container.visibility = View.VISIBLE
|
||||
request_calendar.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(view: View?) {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.READ_CALENDAR), Constants.CALENDAR_REQUEST_CODE)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (!Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
no_location_permission_container.visibility = View.VISIBLE
|
||||
request_location.setOnClickListener(object: View.OnClickListener {
|
||||
override fun onClick(view: View?) {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), Constants.LOCATION_REQUEST_CODE)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
all_set_container.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
updateAppWidget()
|
||||
}
|
||||
|
||||
@ -134,19 +147,35 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == Constants.RESULT_CODE_CUSTOM_LOCATION) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
if (requestCode == Constants.RESULT_CODE_CUSTOM_LOCATION && resultCode == Activity.RESULT_OK) {
|
||||
updateSettings()
|
||||
WeatherUtil.updateWeather(this)
|
||||
}
|
||||
} else if (requestCode == Constants.CALENDAR_APP_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
||||
SP.edit()
|
||||
.putString(Constants.PREF_CALENDAR_APP_NAME, data.getStringExtra(Constants.RESULT_APP_NAME))
|
||||
.putString(Constants.PREF_CALENDAR_APP_PACKAGE, data.getStringExtra(Constants.RESULT_APP_PACKAGE))
|
||||
.commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
} else if (requestCode == Constants.WEATHER_APP_REQUEST_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
||||
SP.edit()
|
||||
.putString(Constants.PREF_WEATHER_APP_NAME, data.getStringExtra(Constants.RESULT_APP_NAME))
|
||||
.putString(Constants.PREF_WEATHER_APP_PACKAGE, data.getStringExtra(Constants.RESULT_APP_PACKAGE))
|
||||
.commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCalendarView() {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val now = Calendar.getInstance()
|
||||
val calendarLayout = Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)
|
||||
val calendarLayout = SP.getBoolean(Constants.PREF_SHOW_EVENTS, true) && Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)
|
||||
|
||||
empty_layout.visibility = View.VISIBLE
|
||||
calendar_layout.visibility = View.GONE
|
||||
@ -184,7 +213,22 @@ class MainActivity : AppCompatActivity() {
|
||||
if (!e.allDay) {
|
||||
val startHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.startDate) else Constants.goodHourFormat.format(e.startDate)
|
||||
val endHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.endDate) else Constants.goodHourFormat.format(e.endDate)
|
||||
next_event_date.text = String.format("%s - %s", startHour, endHour)
|
||||
var dayDiff = TimeUnit.MILLISECONDS.toDays(e.endDate - e.startDate)
|
||||
|
||||
val startCal = Calendar.getInstance()
|
||||
startCal.timeInMillis = e.startDate
|
||||
|
||||
val endCal = Calendar.getInstance()
|
||||
endCal.timeInMillis = e.endDate
|
||||
|
||||
if (startCal.get(Calendar.HOUR_OF_DAY) >= endCal.get(Calendar.HOUR_OF_DAY)) {
|
||||
dayDiff++
|
||||
}
|
||||
var multipleDay: String = ""
|
||||
if (dayDiff > 0) {
|
||||
multipleDay = String.format(" (+%s%s)", dayDiff, getString(R.string.day_char))
|
||||
}
|
||||
next_event_date.text = String.format("%s - %s%s", startHour, endHour, multipleDay)
|
||||
} else {
|
||||
next_event_date.text = dateStringValue
|
||||
}
|
||||
@ -196,9 +240,9 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
fun updateLocationView() {
|
||||
val locationLayout = Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val locationLayout = SP.getBoolean(Constants.PREF_SHOW_WEATHER, true) && Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
|
||||
if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
|
||||
weather.visibility = View.VISIBLE
|
||||
calendar_weather.visibility = View.VISIBLE
|
||||
@ -227,6 +271,63 @@ class MainActivity : AppCompatActivity() {
|
||||
@SuppressLint("ApplySharedPref")
|
||||
fun updateSettings() {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_EVENTS, true) && Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)) {
|
||||
calendar_settings.visibility = View.VISIBLE
|
||||
action_show_events.setOnClickListener {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_EVENTS, false)
|
||||
.commit()
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
show_events_label.text = getString(R.string.show_events_visible)
|
||||
} else {
|
||||
calendar_settings.visibility= View.GONE
|
||||
action_show_events.setOnClickListener {
|
||||
if (Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)) {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_EVENTS, true)
|
||||
.commit()
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.READ_CALENDAR), Constants.CALENDAR_REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
show_events_label.text = if (Util.checkGrantedPermission(this, Manifest.permission.READ_CALENDAR)) getString(R.string.show_events_not_visible) else getString(R.string.description_permission_calendar)
|
||||
}
|
||||
|
||||
if (SP.getBoolean(Constants.PREF_SHOW_WEATHER, true) && Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
weather_settings.visibility = View.VISIBLE
|
||||
action_show_weather.setOnClickListener {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_WEATHER, false)
|
||||
.commit()
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
show_weather_label.text = getString(R.string.show_weather_visible)
|
||||
} else {
|
||||
weather_settings.visibility= View.GONE
|
||||
action_show_weather.setOnClickListener {
|
||||
if (Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_WEATHER, true)
|
||||
.commit()
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), Constants.LOCATION_REQUEST_CODE)
|
||||
}
|
||||
}
|
||||
show_weather_label.text = if (Util.checkGrantedPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) getString(R.string.show_weather_not_visible) else getString(R.string.description_permission_location)
|
||||
}
|
||||
|
||||
temp_unit.text = if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) getString(R.string.fahrenheit) else getString(R.string.celsius)
|
||||
action_change_unit.setOnClickListener {
|
||||
SP.edit().putString(Constants.PREF_WEATHER_TEMP_UNIT, if (SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F").equals("F")) "C" else "F").commit()
|
||||
@ -244,8 +345,9 @@ class MainActivity : AppCompatActivity() {
|
||||
hour_format_label.text = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) getString(R.string.settings_hour_format_subtitle_12) else getString(R.string.settings_hour_format_subtitle_24)
|
||||
action_hour_format.setOnClickListener {
|
||||
SP.edit().putString(Constants.PREF_HOUR_FORMAT, if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) "24" else "12").commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
@ -257,31 +359,38 @@ class MainActivity : AppCompatActivity() {
|
||||
action_date_format.setOnClickListener {
|
||||
SP.edit().putBoolean(Constants.PREF_ITA_FORMAT_DATE, !SP.getBoolean(Constants.PREF_ITA_FORMAT_DATE, false)).commit()
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
|
||||
label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)))
|
||||
action_weather_refresh_period.setOnClickListener {
|
||||
val dialog: BottomSheetMenuDialog = BottomSheetBuilder(this, R.style.Theme_Design_Light_BottomSheetDialog)
|
||||
.setMode(BottomSheetBuilder.MODE_LIST)
|
||||
.setMenu(R.menu.weather_refresh_period_menu)
|
||||
.setIconTintColor(ContextCompat.getColor(this, R.color.black_50))
|
||||
.delayDismissOnItemClick(false)
|
||||
.setItemClickListener({ item: MenuItem ->
|
||||
SP.edit().putInt(Constants.PREF_WEATHER_REFRESH_PERIOD, when (item.itemId) {
|
||||
R.id.refresh_1 -> 1
|
||||
R.id.refresh_2 -> 2
|
||||
R.id.refresh_3 -> 3
|
||||
R.id.refresh_4 -> 4
|
||||
R.id.refresh_5 -> 5
|
||||
else -> 1
|
||||
}).commit()
|
||||
updateSettings()
|
||||
WeatherReceiver().setUpdates(this@MainActivity)
|
||||
})
|
||||
.createDialog()
|
||||
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)
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
show_until_label.text = getString(Util.getShowUntilString(SP.getInt(Constants.PREF_SHOW_UNTIL, 1)))
|
||||
action_show_until.setOnClickListener {
|
||||
SP.edit().putInt(Constants.PREF_SHOW_UNTIL, when (SP.getInt(Constants.PREF_SHOW_UNTIL, 1)) {
|
||||
0 -> 1
|
||||
1 -> 2
|
||||
2 -> 3
|
||||
3 -> 4
|
||||
4 -> 5
|
||||
5 -> 0
|
||||
else -> 1
|
||||
}).commit()
|
||||
updateSettings()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
}
|
||||
|
||||
label_custom_location.text = SP.getString(Constants.PREF_CUSTOM_LOCATION_ADD, getString(R.string.custom_location_gps))
|
||||
@ -289,6 +398,16 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivityForResult(Intent(this, CustomLocationActivity::class.java), Constants.RESULT_CODE_CUSTOM_LOCATION)
|
||||
}
|
||||
|
||||
calendar_app_label.text = SP.getString(Constants.PREF_CALENDAR_APP_NAME, getString(R.string.default_name))
|
||||
action_calendar_app.setOnClickListener {
|
||||
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.CALENDAR_APP_REQUEST_CODE)
|
||||
}
|
||||
|
||||
weather_app_label.text = SP.getString(Constants.PREF_WEATHER_APP_NAME, getString(R.string.default_name))
|
||||
action_weather_app.setOnClickListener {
|
||||
startActivityForResult(Intent(this, ChooseApplicationActivity::class.java), Constants.WEATHER_APP_REQUEST_CODE)
|
||||
}
|
||||
|
||||
action_filter_calendar.setOnClickListener {
|
||||
val calendarSelectorList: List<CalendarSelector> = CalendarUtil.getCalendarList(this)
|
||||
var calFiltered = SP.getString(Constants.PREF_CALENDAR_FILTER, "")
|
||||
|
@ -29,6 +29,10 @@ import android.net.Uri
|
||||
import android.widget.TextClock
|
||||
import android.widget.TextView
|
||||
import android.content.ComponentName
|
||||
import android.support.v4.content.ContextCompat.startActivity
|
||||
import android.provider.CalendarContract.Events
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -72,7 +76,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
fun updateCalendarView(context: Context, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val now = Calendar.getInstance()
|
||||
val calendarLayout = Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)
|
||||
val calendarLayout = SP.getBoolean(Constants.PREF_SHOW_EVENTS, true) && Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)
|
||||
|
||||
views.setViewVisibility(R.id.empty_layout, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.calendar_layout, View.GONE)
|
||||
@ -83,9 +87,8 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setTextViewText(R.id.empty_date, dateStringValue)
|
||||
//views.setImageViewBitmap(R.id.empty_date, Util.buildUpdate(context, Constants.dateFormat.format(now.time)[0].toUpperCase() + Constants.dateFormat.format(now.time).substring(1), "fonts/product_sans_regular.ttf"))
|
||||
|
||||
val calIntent = Intent(Intent.ACTION_MAIN)
|
||||
calIntent.addCategory(Intent.CATEGORY_APP_CALENDAR)
|
||||
val calPIntent = PendingIntent.getActivity(context, widgetID, calIntent, 0)
|
||||
|
||||
val calPIntent = PendingIntent.getActivity(context, widgetID, Util.getCalendarIntent(context), 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, calPIntent)
|
||||
|
||||
|
||||
@ -114,7 +117,24 @@ class TheWidget : AppWidgetProvider() {
|
||||
if (!e.allDay) {
|
||||
val startHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.startDate) else Constants.goodHourFormat.format(e.startDate)
|
||||
val endHour: String = if (SP.getString(Constants.PREF_HOUR_FORMAT, "12").equals("12")) Constants.badHourFormat.format(e.endDate) else Constants.goodHourFormat.format(e.endDate)
|
||||
views.setTextViewText(R.id.next_event_date, String.format("%s - %s", startHour, endHour))
|
||||
var dayDiff = TimeUnit.MILLISECONDS.toDays(e.endDate - e.startDate)
|
||||
|
||||
val startCal = Calendar.getInstance()
|
||||
startCal.timeInMillis = e.startDate
|
||||
|
||||
val endCal = Calendar.getInstance()
|
||||
endCal.timeInMillis = e.endDate
|
||||
|
||||
if (startCal.get(Calendar.HOUR_OF_DAY) >= endCal.get(Calendar.HOUR_OF_DAY)) {
|
||||
dayDiff++
|
||||
}
|
||||
|
||||
var multipleDay: String = ""
|
||||
if (dayDiff > 0) {
|
||||
multipleDay = String.format(" (+%s%s)", dayDiff, context.getString(R.string.day_char))
|
||||
}
|
||||
|
||||
views.setTextViewText(R.id.next_event_date, String.format("%s - %s%s", startHour, endHour, multipleDay))
|
||||
} else {
|
||||
views.setTextViewText(R.id.next_event_date, dateStringValue)
|
||||
}
|
||||
@ -122,11 +142,12 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setViewVisibility(R.id.empty_layout, View.GONE)
|
||||
views.setViewVisibility(R.id.calendar_layout, View.VISIBLE)
|
||||
|
||||
val builder = CalendarContract.CONTENT_URI.buildUpon()
|
||||
builder.appendPath("time")
|
||||
ContentUris.appendId(builder, e.startDate)
|
||||
|
||||
val uri = ContentUris.withAppendedId(Events.CONTENT_URI, e.id.toLong())
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setData(builder.build())
|
||||
.setData(uri)
|
||||
intent.putExtra("beginTime", e.startDate);
|
||||
intent.putExtra("endTime", e.endDate);
|
||||
val pIntent = PendingIntent.getActivity(context, widgetID, intent, 0)
|
||||
views.setOnClickPendingIntent(R.id.main_layout, pIntent)
|
||||
}
|
||||
@ -136,9 +157,9 @@ class TheWidget : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
fun updateLocationView(context: Context, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val locationLayout = Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val locationLayout = SP.getBoolean(Constants.PREF_SHOW_WEATHER, true) && Util.checkGrantedPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
|
||||
if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
|
||||
views.setViewVisibility(R.id.weather, View.VISIBLE)
|
||||
views.setViewVisibility(R.id.calendar_weather, View.VISIBLE)
|
||||
@ -159,12 +180,8 @@ class TheWidget : AppWidgetProvider() {
|
||||
views.setTextViewText(R.id.temp, temp)
|
||||
views.setTextViewText(R.id.calendar_temp, temp)
|
||||
|
||||
val weatherIntent: Intent = Intent(Intent.ACTION_VIEW)
|
||||
weatherIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
weatherIntent.data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
weatherIntent.component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
|
||||
val weatherPIntent = PendingIntent.getActivity(context, widgetID, weatherIntent, 0)
|
||||
val weatherPIntent = PendingIntent.getActivity(context, widgetID, Util.getWeatherIntent(context), 0)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.weather, weatherPIntent)
|
||||
views.setOnClickPendingIntent(R.id.calendar_weather, weatherPIntent)
|
||||
|
@ -25,12 +25,21 @@ object CalendarUtil {
|
||||
val eventList = ArrayList<Event>()
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
val hourLimit = Calendar.getInstance()
|
||||
hourLimit.add(Calendar.HOUR, 8)
|
||||
val limit = Calendar.getInstance()
|
||||
when (SP.getInt(Constants.PREF_SHOW_UNTIL, 1)) {
|
||||
0 -> limit.add(Calendar.HOUR, 3)
|
||||
1 -> limit.add(Calendar.HOUR, 6)
|
||||
2 -> limit.add(Calendar.HOUR, 12)
|
||||
3 -> limit.add(Calendar.DAY_OF_MONTH, 1)
|
||||
4 -> limit.add(Calendar.DAY_OF_MONTH, 3)
|
||||
5 -> limit.add(Calendar.DAY_OF_MONTH, 7)
|
||||
else -> limit.add(Calendar.HOUR, 6)
|
||||
}
|
||||
|
||||
|
||||
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
||||
ContentUris.appendId(builder, now.timeInMillis)
|
||||
ContentUris.appendId(builder, hourLimit.timeInMillis)
|
||||
ContentUris.appendId(builder, limit.timeInMillis)
|
||||
|
||||
if (!Util.checkGrantedPermission(context, Manifest.permission.READ_CALENDAR)) {
|
||||
resetNextEventData(context)
|
||||
@ -107,10 +116,13 @@ object CalendarUtil {
|
||||
calendarList.add(CalendarSelector(calendarCursor.getInt(0), calendarCursor.getString(1), calendarCursor.getString(2)))
|
||||
calendarCursor.moveToNext()
|
||||
}
|
||||
} else {
|
||||
Log.d("AW", "No calendar")
|
||||
}
|
||||
|
||||
calendarCursor.close()
|
||||
} catch (ignored: Exception) {
|
||||
ignored.printStackTrace()
|
||||
try {
|
||||
val calendarCursor = context.contentResolver.query(CalendarContract.Calendars.CONTENT_URI,
|
||||
arrayOf(CalendarContract.Calendars._ID, CalendarContract.Calendars.NAME, CalendarContract.Calendars.ACCOUNT_NAME),
|
||||
@ -130,7 +142,7 @@ object CalendarUtil {
|
||||
|
||||
calendarCursor.close()
|
||||
} catch (ignore: Exception) {
|
||||
|
||||
ignore.printStackTrace()
|
||||
} finally {
|
||||
return calendarList
|
||||
}
|
||||
|
@ -24,8 +24,12 @@ import android.graphics.Bitmap
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.support.annotation.StringRes
|
||||
import android.util.TypedValue
|
||||
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.ComponentName
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
|
||||
|
||||
/**
|
||||
@ -34,7 +38,6 @@ import android.util.TypedValue
|
||||
|
||||
object Util {
|
||||
|
||||
|
||||
fun checkGrantedPermission(context: Context, permission: String): Boolean {
|
||||
return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
@ -43,7 +46,7 @@ object Util {
|
||||
val widgetManager = AppWidgetManager.getInstance(context)
|
||||
val widgetComponent = ComponentName(context, TheWidget::class.java)
|
||||
val widgetIds = widgetManager.getAppWidgetIds(widgetComponent)
|
||||
val update = Intent()
|
||||
val update = Intent(context, TheWidget::class.java)
|
||||
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
|
||||
update.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
context.sendBroadcast(update)
|
||||
@ -78,9 +81,20 @@ object Util {
|
||||
val customTabsIntent: CustomTabsIntent = builder.build();
|
||||
customTabsIntent.launchUrl(context, Uri.parse(url));
|
||||
} catch (e: Exception) {
|
||||
val legalIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
context.startActivity(legalIntent);
|
||||
try {
|
||||
val openIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
context.startActivity(openIntent);
|
||||
} catch (ignored: Exception) {
|
||||
val clipboard:ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText(context.getString(R.string.app_name), url);
|
||||
clipboard.primaryClip = clip;
|
||||
Toast.makeText(context, R.string.error_opening_uri, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
val clipboard:ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText(context.getString(R.string.app_name), url);
|
||||
clipboard.primaryClip = clip;
|
||||
Toast.makeText(context, R.string.error_opening_uri, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
fun share(context: Context) {
|
||||
@ -157,4 +171,62 @@ object Util {
|
||||
else -> R.string.settings_weather_refresh_period_subtitle_0
|
||||
}
|
||||
}
|
||||
|
||||
fun getShowUntilString(period: Int): Int {
|
||||
return when (period) {
|
||||
0 -> R.string.settings_show_until_subtitle_0
|
||||
1 -> R.string.settings_show_until_subtitle_1
|
||||
2 -> R.string.settings_show_until_subtitle_2
|
||||
3 -> R.string.settings_show_until_subtitle_3
|
||||
4 -> R.string.settings_show_until_subtitle_4
|
||||
5 -> R.string.settings_show_until_subtitle_5
|
||||
else -> R.string.settings_show_until_subtitle_1
|
||||
}
|
||||
}
|
||||
|
||||
fun getCalendarIntent(context: Context): Intent {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (SP.getString(Constants.PREF_CALENDAR_APP_PACKAGE, "").equals("")) {
|
||||
val calIntent = Intent(Intent.ACTION_MAIN)
|
||||
calIntent.addCategory(Intent.CATEGORY_APP_CALENDAR)
|
||||
return calIntent
|
||||
} else {
|
||||
val pm: PackageManager = context.packageManager
|
||||
return try {
|
||||
val intent: Intent = pm.getLaunchIntentForPackage(SP.getString(Constants.PREF_CALENDAR_APP_PACKAGE, ""))
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
intent
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
val calIntent = Intent(Intent.ACTION_MAIN)
|
||||
calIntent.addCategory(Intent.CATEGORY_APP_CALENDAR)
|
||||
calIntent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getWeatherIntent(context: Context): Intent {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
if (SP.getString(Constants.PREF_WEATHER_APP_PACKAGE, "").equals("")) {
|
||||
val weatherIntent: Intent = Intent(Intent.ACTION_VIEW)
|
||||
weatherIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
weatherIntent.data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
weatherIntent.component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
return weatherIntent
|
||||
} else {
|
||||
val pm: PackageManager = context.packageManager
|
||||
return try {
|
||||
val intent: Intent = pm.getLaunchIntentForPackage(SP.getString(Constants.PREF_WEATHER_APP_PACKAGE, ""))
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
intent
|
||||
} catch (e: Exception) {
|
||||
val weatherIntent: Intent = Intent(Intent.ACTION_VIEW)
|
||||
weatherIntent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
weatherIntent.data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
weatherIntent.component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
weatherIntent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user