mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 02:39:34 +02:00
Improve footer of add apps screen
This commit is contained in:
parent
917f134d77
commit
dbd29af815
2 changed files with 63 additions and 28 deletions
|
@ -30,7 +30,10 @@ import io.timelimit.android.data.Database
|
||||||
import io.timelimit.android.data.model.UserType
|
import io.timelimit.android.data.model.UserType
|
||||||
import io.timelimit.android.databinding.FragmentAddCategoryAppsBinding
|
import io.timelimit.android.databinding.FragmentAddCategoryAppsBinding
|
||||||
import io.timelimit.android.extensions.showSafe
|
import io.timelimit.android.extensions.showSafe
|
||||||
import io.timelimit.android.livedata.*
|
import io.timelimit.android.livedata.ignoreUnchanged
|
||||||
|
import io.timelimit.android.livedata.liveDataFromValue
|
||||||
|
import io.timelimit.android.livedata.map
|
||||||
|
import io.timelimit.android.livedata.switchMap
|
||||||
import io.timelimit.android.logic.DefaultAppLogic
|
import io.timelimit.android.logic.DefaultAppLogic
|
||||||
import io.timelimit.android.sync.actions.AddCategoryAppsAction
|
import io.timelimit.android.sync.actions.AddCategoryAppsAction
|
||||||
import io.timelimit.android.ui.main.ActivityViewModel
|
import io.timelimit.android.ui.main.ActivityViewModel
|
||||||
|
@ -138,36 +141,36 @@ class AddCategoryAppsFragment : DialogFragment() {
|
||||||
adapter.categoryTitleByPackageName = it
|
adapter.categoryTitleByPackageName = it
|
||||||
})
|
})
|
||||||
|
|
||||||
|
binding.addAppsButton.setOnClickListener {
|
||||||
|
val packageNames = adapter.selectedApps.toList()
|
||||||
|
|
||||||
|
if (packageNames.isNotEmpty()) {
|
||||||
|
auth.tryDispatchParentAction(
|
||||||
|
AddCategoryAppsAction(
|
||||||
|
categoryId = params.categoryId,
|
||||||
|
packageNames = packageNames
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.cancelButton.setOnClickListener {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.selectAllButton.setOnClickListener {
|
||||||
|
adapter.selectedApps.addAll(
|
||||||
|
adapter.data?.map { it.packageName } ?: emptySet()
|
||||||
|
)
|
||||||
|
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
return AlertDialog.Builder(context!!, R.style.AppTheme)
|
return AlertDialog.Builder(context!!, R.style.AppTheme)
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
.setPositiveButton(R.string.category_apps_add_dialog_btn_positive) {
|
|
||||||
_, _->
|
|
||||||
|
|
||||||
val packageNames = adapter.selectedApps.toList()
|
|
||||||
|
|
||||||
if (packageNames.isNotEmpty()) {
|
|
||||||
auth.tryDispatchParentAction(
|
|
||||||
AddCategoryAppsAction(
|
|
||||||
categoryId = params.categoryId,
|
|
||||||
packageNames = packageNames
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.setNegativeButton(R.string.generic_cancel, null)
|
|
||||||
.setNeutralButton(R.string.category_apps_add_dialog_select_all, null)
|
|
||||||
.create()
|
.create()
|
||||||
.apply {
|
|
||||||
setOnShowListener {
|
|
||||||
getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener {
|
|
||||||
adapter.selectedApps.addAll(
|
|
||||||
adapter.data?.map { it.packageName } ?: emptySet()
|
|
||||||
)
|
|
||||||
|
|
||||||
adapter.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun show(manager: FragmentManager) {
|
fun show(manager: FragmentManager) {
|
||||||
|
|
|
@ -77,5 +77,37 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
style="?android:buttonBarStyle"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="?android:buttonBarButtonStyle"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/category_apps_add_dialog_select_all"
|
||||||
|
android:id="@+id/select_all_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="?android:buttonBarButtonStyle"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/generic_cancel"
|
||||||
|
android:id="@+id/cancel_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="?android:buttonBarButtonStyle"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/category_apps_add_dialog_btn_positive"
|
||||||
|
android:id="@+id/add_apps_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue