This commit is contained in:
Tommaso Berlose
2020-10-15 10:10:38 +02:00
parent a1a6f9f607
commit 6150dd7e22
91 changed files with 98 additions and 20 deletions

View File

@ -64,7 +64,8 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
view.action_filter_music_players.isVisible = provider == Constants.GlanceProviderId.PLAYING_SONG
if (provider == Constants.GlanceProviderId.PLAYING_SONG) {
view.action_filter_music_players.setOnClickListener {
context.startActivity(Intent(context, MusicPlayersFilterActivity::class.java))
dismiss()
context.startActivityForResult(Intent(context, MusicPlayersFilterActivity::class.java), 0)
}
checkNotificationPermission(view)
}
@ -97,7 +98,8 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
if (provider == Constants.GlanceProviderId.NOTIFICATIONS) {
checkLastNotificationsPermission(view)
view.action_filter_notifications_app.setOnClickListener {
context.startActivity(Intent(context, AppNotificationsFilterActivity::class.java))
dismiss()
context.startActivityForResult(Intent(context, AppNotificationsFilterActivity::class.java), 0)
}
}

View File

@ -1,6 +1,7 @@
package com.tommasoberlose.anotherwidget.helpers
import android.content.Context
import android.util.Log
import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.db.EventRepository
import com.tommasoberlose.anotherwidget.global.Constants
@ -16,7 +17,9 @@ object GlanceProviderHelper {
val providers = Constants.GlanceProviderId.values()
.filter {
context.checkIfFitInstalled() || it != Constants.GlanceProviderId.GOOGLE_FIT_STEPS
}.toTypedArray()
}
.filterNot { it.id == Constants.GlanceProviderId.GREETINGS.id }
.toTypedArray()
providers.sortWith(Comparator { p1, p2 ->
when {
@ -35,6 +38,8 @@ object GlanceProviderHelper {
}
})
Log.d("ciao", providers.toList().toString())
return ArrayList(providers.toList())
}
@ -49,7 +54,7 @@ object GlanceProviderHelper {
Constants.GlanceProviderId.PLAYING_SONG -> {
GlanceProvider(providerId.id,
context.getString(R.string.settings_show_music_title),
R.drawable.round_radio
R.drawable.round_music_note
)
}
Constants.GlanceProviderId.CUSTOM_INFO -> {
@ -67,7 +72,7 @@ object GlanceProviderHelper {
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
GlanceProvider(providerId.id,
context.getString(R.string.settings_daily_steps_title),
R.drawable.round_run_circle
R.drawable.round_near_me
)
}
Constants.GlanceProviderId.NOTIFICATIONS -> {

View File

@ -13,6 +13,7 @@ import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper
import com.tommasoberlose.anotherwidget.helpers.MediaPlayerHelper
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import java.lang.Exception
import java.util.*
@ -35,10 +36,18 @@ class NotificationListener : NotificationListenerService() {
Preferences.lastNotificationId = sbn.id
Preferences.lastNotificationTitle = bundle.getString(Notification.EXTRA_TITLE) ?: ""
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Preferences.lastNotificationIcon = sbn.notification.smallIcon.resId
try {
Preferences.lastNotificationIcon = sbn.notification.smallIcon.resId
} catch (ex: Exception) {
Preferences.lastNotificationIcon = 0
}
Preferences.lastNotificationPackage = sbn.notification.smallIcon.resPackage
} else {
Preferences.lastNotificationIcon = sbn.notification.icon
try {
Preferences.lastNotificationIcon = sbn.notification.icon
} catch (ex: Exception) {
Preferences.lastNotificationIcon = 0
}
Preferences.lastNotificationPackage = sbn.packageName
}
MainWidget.updateWidget(this)

View File

@ -30,6 +30,7 @@ import kotlinx.android.synthetic.main.activity_choose_application.search
import kotlinx.android.synthetic.main.activity_music_players_filter.*
import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter
import net.idik.lib.slimadapter.SlimAdapterEx
class ChooseApplicationActivity : AppCompatActivity() {
@ -47,7 +48,7 @@ class ChooseApplicationActivity : AppCompatActivity() {
val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager
adapter = SlimAdapter.create()
adapter = SlimAdapterEx.create()
adapter
.register<String>(R.layout.application_info_layout) { _, injector ->
injector

View File

@ -241,8 +241,6 @@ class GlanceTabFragment : Fragment() {
val toPos = target.adapterPosition
// move item in `fromPos` to `toPos` in adapter.
adapter.notifyItemMoved(fromPos, toPos)
Collections.swap(list, fromPos, toPos)
return true
}
@ -250,12 +248,22 @@ class GlanceTabFragment : Fragment() {
return false
}
override fun clearView(
override fun onMoved(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder
viewHolder: RecyclerView.ViewHolder,
fromPos: Int,
target: RecyclerView.ViewHolder,
toPos: Int,
x: Int,
y: Int
) {
super.clearView(recyclerView, viewHolder)
with(list[fromPos]) {
list[fromPos] = list[toPos]
list[toPos] = this
}
GlanceProviderHelper.saveGlanceProviderOrder(list)
Log.d("ciao", list.toString())
super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y)
}
override fun onChildDraw(
@ -279,7 +287,6 @@ class GlanceTabFragment : Fragment() {
}
val topEdge = if ((view.top == 0 && dY < 0) || ((view.top + view.height >= recyclerView.height - 32f.convertDpToPixel(requireContext())) && dY > 0)) 0f else dY
Log.d("ciao", "${view.top} + ${view.height} = ${view.top + view.height} to compare to ${recyclerView.height} - ${32f.convertDpToPixel(requireContext())}")
super.onChildDraw(c,
recyclerView,
@ -302,7 +309,6 @@ class GlanceTabFragment : Fragment() {
adapter.updateData(
GlanceProviderHelper.getGlanceProviders(requireContext())
.mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) }
.filterNot { it.id == Constants.GlanceProviderId.GREETINGS.id }
)
providers_list.isNestedScrollingEnabled = false

View File

@ -624,8 +624,15 @@ class MainWidget : AppWidgetProvider() {
} else {
val flags: Int =
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
v.next_event_date.text =
val start = Calendar.getInstance().apply { timeInMillis = nextEvent.startDate }
v.next_event_date.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get(Calendar.DAY_OF_YEAR)) {
DateUtils.formatDateTime(context, nextEvent.startDate, flags)
} else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get(Calendar.YEAR) > start.get(Calendar.YEAR)) {
DateUtils.formatDateTime(context, now.timeInMillis, flags)
} else {
DateUtils.formatDateTime(context, nextEvent.startDate, flags)
}
}
}
@ -718,9 +725,14 @@ class MainWidget : AppWidgetProvider() {
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
try {
val remotePackageContext = context.createPackageContext(Preferences.lastNotificationPackage, 0)
val icon = ContextCompat.getDrawable(remotePackageContext, Preferences.lastNotificationIcon)
v.second_row_icon.isVisible = true
v.second_row_icon.setImageDrawable(icon)
if (Preferences.lastNotificationIcon != 0) {
val icon = ContextCompat.getDrawable(remotePackageContext,
Preferences.lastNotificationIcon)
v.second_row_icon.isVisible = true
v.second_row_icon.setImageDrawable(icon)
} else {
v.second_row_icon.isVisible = false
}
v.next_event_date.text = Preferences.lastNotificationTitle
showSomething = true
break@loop