Release version 1.1
This commit is contained in:
@ -23,6 +23,7 @@ import android.support.v7.widget.LinearLayoutManager
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.`object`.AppInfoSavedEvent
|
||||
import com.tommasoberlose.anotherwidget.ui.adapter.ApplicationInfoAdapter
|
||||
|
||||
|
||||
@ -47,14 +48,6 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
adapter = ApplicationInfoAdapter(this, appListFiltered);
|
||||
list_view.setAdapter(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 {
|
||||
@ -80,6 +73,16 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
finish()
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun saveApp(e: AppInfoSavedEvent) {
|
||||
val pm = packageManager
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(Constants.RESULT_APP_NAME, pm.getApplicationLabel(e.app).toString())
|
||||
resultIntent.putExtra(Constants.RESULT_APP_PACKAGE, e.app.packageName)
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
public override fun onStart() {
|
||||
super.onStart()
|
||||
EventBus.getDefault().register(this)
|
||||
|
@ -50,6 +50,10 @@ class MainActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_main)
|
||||
Fabric.with(this, Crashlytics())
|
||||
|
||||
if (intent.extras?.containsKey(Constants.ACTION_EXTRA_OPEN_WEATHER_PROVIDER) == true) {
|
||||
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
|
||||
}
|
||||
|
||||
val extras = intent.extras
|
||||
if (extras != null) {
|
||||
mAppWidgetId = extras.getInt(
|
||||
@ -129,7 +133,7 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val filter = IntentFilter()
|
||||
filter.addAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
||||
filter.addAction(Constants.ACTION_SOMETHING_APPENED);
|
||||
registerReceiver(receiver, filter);
|
||||
updateUI()
|
||||
}
|
||||
@ -143,18 +147,14 @@ class MainActivity : AppCompatActivity() {
|
||||
grantResults: IntArray) {
|
||||
when (requestCode) {
|
||||
Constants.CALENDAR_REQUEST_CODE -> if (!(permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED)) {
|
||||
CalendarUtil.updateEventList(this)
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
updateAppWidget()
|
||||
updateSettings()
|
||||
}
|
||||
Constants.LOCATION_REQUEST_CODE -> if (!(permissions.size != 1 || grantResults.size != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED)) {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
if (SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, "").equals("")) {
|
||||
startActivityForResult(Intent(this, WeatherProviderActivity::class.java), Constants.WEATHER_PROVIDER_REQUEST_CODE)
|
||||
} else {
|
||||
WeatherUtil.updateWeather(this)
|
||||
updateAppWidget()
|
||||
}
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
updateAppWidget()
|
||||
updateSettings()
|
||||
}
|
||||
}
|
||||
@ -179,8 +179,8 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
if (requestCode == Constants.RESULT_CODE_CUSTOM_LOCATION && resultCode == Activity.RESULT_OK) {
|
||||
updateSettings()
|
||||
WeatherUtil.updateWeather(this)
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
updateSettings()
|
||||
} 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))
|
||||
@ -188,7 +188,6 @@ class MainActivity : AppCompatActivity() {
|
||||
.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))
|
||||
@ -196,7 +195,6 @@ class MainActivity : AppCompatActivity() {
|
||||
.commit()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
} else if (requestCode == Constants.WEATHER_PROVIDER_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
updateSettings()
|
||||
@ -277,7 +275,7 @@ class MainActivity : AppCompatActivity() {
|
||||
if (locationLayout && SP.contains(Constants.PREF_WEATHER_TEMP) && SP.contains(Constants.PREF_WEATHER_ICON)) {
|
||||
weather.visibility = View.VISIBLE
|
||||
calendar_weather.visibility = View.VISIBLE
|
||||
val currentTemp = String.format(Locale.getDefault(), "%.0f °%s", SP.getFloat(Constants.PREF_WEATHER_TEMP, 0f), SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F"))
|
||||
val currentTemp = String.format(Locale.getDefault(), "%.0f °%s", SP.getFloat(Constants.PREF_WEATHER_TEMP, 0f), SP.getString(Constants.PREF_WEATHER_REAL_TEMP_UNIT, "F"))
|
||||
|
||||
|
||||
weather_icon.visibility = View.VISIBLE
|
||||
@ -309,9 +307,9 @@ class MainActivity : AppCompatActivity() {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_EVENTS, false)
|
||||
.commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
show_events_label.text = getString(R.string.show_events_visible)
|
||||
} else {
|
||||
@ -321,9 +319,9 @@ class MainActivity : AppCompatActivity() {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_EVENTS, true)
|
||||
.commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_CALENDAR_UPDATE))
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.READ_CALENDAR), Constants.CALENDAR_REQUEST_CODE)
|
||||
}
|
||||
@ -337,9 +335,9 @@ class MainActivity : AppCompatActivity() {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_WEATHER, false)
|
||||
.commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
show_weather_label.text = getString(R.string.show_weather_visible)
|
||||
} else {
|
||||
@ -349,9 +347,9 @@ class MainActivity : AppCompatActivity() {
|
||||
SP.edit()
|
||||
.putBoolean(Constants.PREF_SHOW_WEATHER, true)
|
||||
.commit()
|
||||
sendBroadcast(Intent(Constants.ACTION_WEATHER_UPDATE))
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), Constants.LOCATION_REQUEST_CODE)
|
||||
}
|
||||
@ -376,9 +374,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()
|
||||
Util.updateWidget(this)
|
||||
updateSettings()
|
||||
updateAppWidget()
|
||||
Util.updateWidget(this)
|
||||
}
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
@ -389,9 +387,9 @@ class MainActivity : AppCompatActivity() {
|
||||
date_format_label.text = dateStringValue
|
||||
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)
|
||||
updateAppWidget()
|
||||
updateSettings()
|
||||
}
|
||||
|
||||
label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(SP.getInt(Constants.PREF_WEATHER_REFRESH_PERIOD, 1)))
|
||||
|
@ -6,15 +6,23 @@ import android.app.AlertDialog
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.os.Build
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.support.design.widget.BottomSheetDialog
|
||||
import android.text.Editable
|
||||
import android.text.Html
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.`object`.Constants
|
||||
import com.tommasoberlose.anotherwidget.util.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.util.Util
|
||||
import com.tommasoberlose.anotherwidget.util.WeatherUtil
|
||||
import kotlinx.android.synthetic.main.activity_weather_provider.*
|
||||
import kotlinx.android.synthetic.main.main_menu_layout.view.*
|
||||
import kotlinx.android.synthetic.main.provider_info_layout.view.*
|
||||
|
||||
class WeatherProviderActivity : AppCompatActivity() {
|
||||
|
||||
@ -29,6 +37,9 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
api_key.setText(clipboard.primaryClip.getItemAt(0).text)
|
||||
}
|
||||
|
||||
Util.collapse(button_container)
|
||||
api_key.setText(SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, ""))
|
||||
|
||||
action_save.setOnClickListener {
|
||||
SP.edit()
|
||||
.putString(Constants.PREF_WEATHER_PROVIDER_API_KEY, api_key.text.toString())
|
||||
@ -40,9 +51,9 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
api_key.addTextChangedListener(object: TextWatcher {
|
||||
override fun afterTextChanged(text: Editable?) {
|
||||
if (text.toString().equals("") || text.toString().equals(SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, ""))) {
|
||||
action_save.animate().scaleY(-2f).start()
|
||||
Util.collapse(button_container)
|
||||
} else {
|
||||
action_save.animate().scaleY(0f).start()
|
||||
Util.expand(button_container)
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,15 +63,31 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
})
|
||||
|
||||
action_open_provider.setOnClickListener {
|
||||
Util.openURI(this, "https://home.openweathermap.org/users/sign_up")
|
||||
}
|
||||
|
||||
action_open_info_text.setOnClickListener {
|
||||
val mBottomSheetDialog: BottomSheetDialog = BottomSheetDialog(this)
|
||||
val provView: View = layoutInflater.inflate(R.layout.provider_info_layout, null)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_text), Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
provView.text.text = Html.fromHtml(getString(R.string.api_key_info_text))
|
||||
}
|
||||
mBottomSheetDialog.setContentView(provView)
|
||||
mBottomSheetDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
val SP = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
if (api_key.text.toString().equals("") || !api_key.text.toString().equals(SP.getString(Constants.PREF_WEATHER_PROVIDER_API_KEY, ""))) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.error_weather_api_key))
|
||||
.setMessage(getString(R.string.error_weather_api_key))
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, DialogInterface.OnClickListener { _,_ ->
|
||||
.setPositiveButton(android.R.string.yes, DialogInterface.OnClickListener { _,_ ->
|
||||
super.onBackPressed()
|
||||
})
|
||||
.show()
|
||||
|
@ -3,6 +3,7 @@ package com.tommasoberlose.anotherwidget.ui.adapter
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.util.EventLog
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@ -10,6 +11,8 @@ import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.`object`.AppInfoSavedEvent
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
@ -26,11 +29,16 @@ class ApplicationInfoAdapter (private val context: Context, private var mDataset
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val pm = context.packageManager
|
||||
holder.text.text = pm.getApplicationLabel(mDataset[position]).toString()
|
||||
val app = mDataset[position]
|
||||
holder.text.text = pm.getApplicationLabel(app).toString()
|
||||
try {
|
||||
holder.icon.setImageDrawable(mDataset[position].loadIcon(pm))
|
||||
holder.icon.setImageDrawable(app.loadIcon(pm))
|
||||
} catch (ignore: Exception) {
|
||||
}
|
||||
|
||||
holder.view.setOnClickListener {
|
||||
EventBus.getDefault().post(AppInfoSavedEvent(app))
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
|
@ -163,7 +163,7 @@ class TheWidget : AppWidgetProvider() {
|
||||
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)
|
||||
val temp = String.format(Locale.getDefault(), "%.0f °%s", SP.getFloat(Constants.PREF_WEATHER_TEMP, 0f), SP.getString(Constants.PREF_WEATHER_TEMP_UNIT, "F"))
|
||||
val temp = String.format(Locale.getDefault(), "%.0f °%s", SP.getFloat(Constants.PREF_WEATHER_TEMP, 0f), SP.getString(Constants.PREF_WEATHER_REAL_TEMP_UNIT, "F"))
|
||||
|
||||
|
||||
views.setViewVisibility(R.id.weather_icon, View.VISIBLE)
|
||||
|
Reference in New Issue
Block a user