Skip to content

Commit

Permalink
Merge pull request #173 from axel358/notifications
Browse files Browse the repository at this point in the history
Notification rework
  • Loading branch information
axel358 authored Sep 21, 2024
2 parents f75a547 + 66b6aa6 commit 14c07fe
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import android.content.SharedPreferences
import android.graphics.Color
import android.graphics.PorterDuff
import android.service.notification.StatusBarNotification
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -17,7 +15,6 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.button.MaterialButton
import cu.axel.smartdock.R
import cu.axel.smartdock.utils.AppUtils
import cu.axel.smartdock.utils.ColorUtils
Expand Down Expand Up @@ -106,7 +103,7 @@ class NotificationAdapter(
if (sbn.isClearable) {
viewHolder.notifCancelBtn.alpha = 1f
viewHolder.notifCancelBtn.setOnClickListener { view ->
if (sbn.isClearable) listener.onNotificationCancelClicked(sbn, view)
listener.onNotificationCancelClicked(sbn, view)
}
} else viewHolder.notifCancelBtn.alpha = 0f

Expand Down Expand Up @@ -141,11 +138,11 @@ class NotificationAdapter(
var notifActionsLayout: LinearLayout

init {
notifTitle = itemView.findViewById(R.id.notif_w_title_tv)
notifText = itemView.findViewById(R.id.notif_w_text_tv)
notifIcon = itemView.findViewById(R.id.notif_w_icon_iv)
notifCancelBtn = itemView.findViewById(R.id.notif_w_close_btn)
notifActionsLayout = itemView.findViewById(R.id.notif_actions_container)
notifTitle = itemView.findViewById(R.id.notification_title_tv)
notifText = itemView.findViewById(R.id.notification_text_tv)
notifIcon = itemView.findViewById(R.id.notification_icon_iv)
notifCancelBtn = itemView.findViewById(R.id.notification_close_btn)
notifActionsLayout = itemView.findViewById(R.id.notification_actions_layout)
}

fun bind(notification: StatusBarNotification, listener: OnNotificationClickListener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package cu.axel.smartdock.preferences

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.ListView
import android.widget.TextView
import android.widget.Toast
import androidx.preference.Preference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import cu.axel.smartdock.R
import cu.axel.smartdock.models.App
import cu.axel.smartdock.utils.AppUtils
import cu.axel.smartdock.utils.ColorUtils


class AppChooserMultiplePreference(private val context: Context, private val attrs: AttributeSet?) :
Preference(context, attrs) {
override fun onClick() {

val apps =
if (key.startsWith("ignored_notifications")) AppUtils.getInstalledPackages(context) else AppUtils.getInstalledApps(
context
)
val savedApps = sharedPreferences!!.getStringSet(key, emptySet())!!
val adapter = AppAdapter(context, apps.sortedWith(compareByDescending { savedApps.contains(it.packageName) }), savedApps.toList())

val dialogBuilder = MaterialAlertDialogBuilder(context)
dialogBuilder.setTitle(R.string.choose_apps)
val view = LayoutInflater.from(context).inflate(R.layout.app_chooser_list, null)
val listView: ListView = view.findViewById(R.id.app_chooser_lv)
dialogBuilder.setView(view)
dialogBuilder.setPositiveButton(R.string.ok) { _, _ ->
persistStringSet(adapter.sApps.toSet())
}
dialogBuilder.setNeutralButton(R.string.cancel, null)
val dialog = dialogBuilder.create()
listView.adapter = adapter
dialog.show()
}

class AppAdapter(
private val context: Context,
apps: List<App>,
private val selectedApps: List<String>?
) :
ArrayAdapter<App>(
context, R.layout.app_chooser_entry, apps
) {
val sApps = selectedApps?.toMutableList() ?: mutableListOf()
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
var view = convertView
val holder: Holder

if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.app_chooser_entry, null)
holder = Holder()
holder.icon = view.findViewById(R.id.app_chooser_entry_iv)
holder.text = view.findViewById(R.id.app_chooser_entry_tv)
holder.selection = view.findViewById(R.id.app_chooser_entry_chkbx)
view.tag = holder
} else {
holder = view.tag as Holder
holder.selection.setOnCheckedChangeListener(null)
}

val app: App = getItem(position)!!


holder.icon.setImageDrawable(app.icon)
holder.text.text = app.name
ColorUtils.applyColor(
holder.icon,
ColorUtils.getDrawableDominantColor(holder.icon.drawable)
)


if (selectedApps != null) {
holder.selection.visibility = View.VISIBLE
holder.selection.isChecked = sApps.contains(app.packageName)
holder.selection.setOnCheckedChangeListener { _, isChecked ->
if (isChecked)
sApps.add(app.packageName)
else
sApps.remove(app.packageName)
}
}
return view!!
}

inner class Holder {
lateinit var icon: ImageView
lateinit var text: TextView
lateinit var selection: CheckBox
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/cu/axel/smartdock/services/DockService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
updateRunningTasks()
else
updateRunningTasks()

} else if (sharedPreferences.getBoolean(
"custom_toasts",
false
Expand Down Expand Up @@ -1027,6 +1026,8 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
if (!isPinned && sharedPreferences.getBoolean("auto_pin", true))
pinDock()
}
if (Utils.notificationPanelVisible)
toggleNotificationPanel(false)
}

private fun setOrientation() {
Expand Down Expand Up @@ -1509,7 +1510,6 @@ class DockService : AccessibilityService(), OnSharedPreferenceChangeListener, On
}
tasksGv.layoutParams.width = gridSize * apps.size
tasksGv.adapter = DockAppAdapter(context, apps, this, iconPackUtils)

//TODO: Move context outta here
wifiBtn.setImageResource(if (wifiManager.isWifiEnabled) R.drawable.ic_wifi_on else R.drawable.ic_wifi_off)
val bluetoothAdapter = bluetoothManager.adapter
Expand Down
Loading

0 comments on commit 14c07fe

Please sign in to comment.