mirror of
https://github.com/jrpie/Launcher.git
synced 2025-05-15 15:01:53 +02:00
show number of widgets for widget panel
This commit is contained in:
parent
8173993601
commit
30e9fcd20f
5 changed files with 36 additions and 8 deletions
|
@ -18,13 +18,16 @@ import de.jrpie.android.launcher.widgets.updateWidgetPanel
|
|||
|
||||
class ManageWidgetPanelsActivity : AppCompatActivity(), UIObject {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private val sharedPreferencesListener =
|
||||
SharedPreferences.OnSharedPreferenceChangeListener { _, prefKey ->
|
||||
if (prefKey == LauncherPreferences.widgets().keys().customPanels()) {
|
||||
if (
|
||||
prefKey == LauncherPreferences.widgets().keys().customPanels()
|
||||
|| prefKey == LauncherPreferences.widgets().keys().widgets()
|
||||
) {
|
||||
viewAdapter.widgetPanels =
|
||||
(LauncherPreferences.widgets().customPanels() ?: setOf()).toTypedArray()
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
viewAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +79,6 @@ class ManageWidgetPanelsActivity : AppCompatActivity(), UIObject {
|
|||
)
|
||||
)
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,16 @@ class WidgetPanelsRecyclerAdapter(
|
|||
|
||||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var labelView: TextView = itemView.findViewById(R.id.list_widget_panels_label)
|
||||
var infoView: TextView = itemView.findViewById(R.id.list_widget_panels_info)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) {
|
||||
viewHolder.labelView.text = widgetPanels[i].label
|
||||
val numWidgets = widgetPanels[i].getWidgets().size
|
||||
viewHolder.infoView.text = context.resources.getQuantityString(
|
||||
R.plurals.widget_panel_number_of_widgets,
|
||||
numWidgets, numWidgets
|
||||
)
|
||||
|
||||
viewHolder.itemView.setOnClickListener {
|
||||
onSelectWidgetPanel(widgetPanels[i])
|
||||
|
|
|
@ -32,6 +32,12 @@ class WidgetPanel(val id: Int, var label: String) {
|
|||
.filter { it.panelId == this.id }.forEach { it.delete(context) }
|
||||
}
|
||||
|
||||
fun getWidgets(): List<Widget> {
|
||||
return LauncherPreferences.widgets().widgets().filter {
|
||||
it.panelId == this.id
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
val HOME = WidgetPanel(0, "home")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/list_widget_panels_row_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -14,10 +15,23 @@
|
|||
android:layout_marginEnd="5dp"
|
||||
android:gravity="start"
|
||||
android:text=""
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:text="Panel #1"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<TextView
|
||||
android:id="@+id/list_widget_panels_info"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="60sp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:gravity="start"
|
||||
android:text=""
|
||||
tools:text="Contains 5 widgets"
|
||||
android:textSize="11sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/list_widget_panels_label" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -406,8 +406,8 @@
|
|||
|
||||
<string name="widget_panel_default_name">Widget Panel #%1$d</string>
|
||||
<plurals name="widget_panel_number_of_widgets">
|
||||
<item quantity="one">Contains %d widget.</item>
|
||||
<item quantity="other">Contains %d widgets.</item>
|
||||
<item quantity="one">Contains %1$d widget.</item>
|
||||
<item quantity="other">Contains %1$d widgets.</item>
|
||||
</plurals>
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue