From 01a9af1678df733e33a00aaa8a02a319dcb301ba Mon Sep 17 00:00:00 2001 From: 030 <030@notfound.404> Date: Fri, 26 Nov 2021 21:08:35 +0800 Subject: [PATCH] WIP: workaround against invalid event --- .../moe/dic1911/autodnd/DNDAccessibilityService.kt | 10 +++++++++- .../main/java/moe/dic1911/autodnd/PopupActivity.kt | 12 ++++++++++++ .../java/moe/dic1911/autodnd/ui/main/MainFragment.kt | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/moe/dic1911/autodnd/PopupActivity.kt diff --git a/app/src/main/java/moe/dic1911/autodnd/DNDAccessibilityService.kt b/app/src/main/java/moe/dic1911/autodnd/DNDAccessibilityService.kt index 31ea2e3..23ea066 100644 --- a/app/src/main/java/moe/dic1911/autodnd/DNDAccessibilityService.kt +++ b/app/src/main/java/moe/dic1911/autodnd/DNDAccessibilityService.kt @@ -2,6 +2,7 @@ package moe.dic1911.autodnd import android.accessibilityservice.AccessibilityService import android.accessibilityservice.AccessibilityServiceInfo +import android.app.Application import android.app.NotificationManager import android.content.BroadcastReceiver import android.content.Context @@ -9,6 +10,7 @@ import android.content.Intent import android.content.IntentFilter import android.media.AudioManager import android.util.Log +import android.util.TimeUtils import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityEvent.* import moe.dic1911.autodnd.data.Storage @@ -22,6 +24,7 @@ class DNDAccessibilityService : AccessibilityService() { private var state = 0 private var bakNotiState = NotificationManager.INTERRUPTION_FILTER_ALL private var bakRingMode = AudioManager.RINGER_MODE_VIBRATE + private var launcherTimestamp: Long = 0 override fun onInterrupt() {} @@ -75,6 +78,12 @@ class DNDAccessibilityService : AccessibilityService() { notiMan.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALARMS) state = 1 } else if (state == 1) { + // workaround against invalid(?) events triggered by gesture + if (false && curApp.contains("launcher")) { + val popup = Intent(this, PopupActivity()::class.java) + popup.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(popup) + } state = 0 if (bakNotiState != notiMan.currentInterruptionFilter) { notiMan.setInterruptionFilter(bakNotiState) @@ -84,5 +93,4 @@ class DNDAccessibilityService : AccessibilityService() { } } } - } \ No newline at end of file diff --git a/app/src/main/java/moe/dic1911/autodnd/PopupActivity.kt b/app/src/main/java/moe/dic1911/autodnd/PopupActivity.kt new file mode 100644 index 0000000..045a4eb --- /dev/null +++ b/app/src/main/java/moe/dic1911/autodnd/PopupActivity.kt @@ -0,0 +1,12 @@ +package moe.dic1911.autodnd + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle + +class PopupActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_popup) + finishAffinity() + } +} \ No newline at end of file diff --git a/app/src/main/java/moe/dic1911/autodnd/ui/main/MainFragment.kt b/app/src/main/java/moe/dic1911/autodnd/ui/main/MainFragment.kt index b5745c3..0848f63 100644 --- a/app/src/main/java/moe/dic1911/autodnd/ui/main/MainFragment.kt +++ b/app/src/main/java/moe/dic1911/autodnd/ui/main/MainFragment.kt @@ -52,7 +52,7 @@ class MainFragment(val index: Int) : Fragment() { pageViewModel.applist.observe(viewLifecycleOwner, { Log.d("030-list", it.size.toString()) (recyclerView.adapter as AppListAdapter?)?.appList = it - (recyclerView.adapter as AppListAdapter?)?.notifyDataSetChanged() + (recyclerView.adapter as AppListAdapter?)?.notifyItemRangeChanged(0, it.size) }) if (Storage.prefs_str.hasObservers()) { Storage.prefs_str.removeObservers(this)