Prevent adding HMA-OSS to the scope, show info text in list the when app/scope list is empty, add working mode indicator to template settings
This commit is contained in:
parent
0b5935328e
commit
11fc2fc206
6 changed files with 93 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ import icu.nullptr.hidemyapplist.ui.view.AppItemView
|
|||
import icu.nullptr.hidemyapplist.util.PackageHelper
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.frknkrc44.hma_oss.BuildConfig
|
||||
|
||||
abstract class AppSelectAdapter(
|
||||
private val firstFilter: ((String) -> Boolean)? = null
|
||||
|
|
@ -24,9 +25,11 @@ abstract class AppSelectAdapter(
|
|||
val filteredList = PackageHelper.appList.first().filter {
|
||||
if (firstFilter?.invoke(it) == false) return@filter false
|
||||
if (!PrefManager.appFilter_showSystem && PackageHelper.isSystem(it)) return@filter false
|
||||
if (it == BuildConfig.APPLICATION_ID &&
|
||||
(this@AppSelectAdapter.javaClass == AppManageAdapter::class.java ||
|
||||
(this@AppSelectAdapter.javaClass == AppScopeAdapter::class.java && firstFilter != null))) return@filter false
|
||||
val label = PackageHelper.loadAppLabel(it)
|
||||
val packageInfo = PackageHelper.loadPackageInfo(it)
|
||||
label.lowercase().contains(constraintLowered) || packageInfo.packageName.lowercase().contains(constraintLowered)
|
||||
label.lowercase().contains(constraintLowered) || it.lowercase().contains(constraintLowered)
|
||||
}
|
||||
|
||||
FilterResults().also { it.values = filteredList }
|
||||
|
|
|
|||
|
|
@ -4,13 +4,16 @@ import android.os.Build
|
|||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowInsets
|
||||
import android.widget.TextView
|
||||
import androidx.activity.addCallback
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.flowWithLifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import by.kirich1409.viewbindingdelegate.viewBinding
|
||||
import icu.nullptr.hidemyapplist.service.PrefManager
|
||||
import icu.nullptr.hidemyapplist.ui.adapter.AppSelectAdapter
|
||||
|
|
@ -113,6 +116,13 @@ abstract class AppSelectFragment : Fragment(R.layout.fragment_app_select) {
|
|||
PackageHelper.invalidateCache()
|
||||
}
|
||||
|
||||
adapter.registerAdapterDataObserver(
|
||||
EmptyDataObserver(
|
||||
binding.list,
|
||||
binding.listEmptyContainer
|
||||
)
|
||||
)
|
||||
|
||||
lifecycleScope.launch {
|
||||
PackageHelper.isRefreshing
|
||||
.flowWithLifecycle(lifecycle)
|
||||
|
|
@ -145,4 +155,32 @@ abstract class AppSelectFragment : Fragment(R.layout.fragment_app_select) {
|
|||
insets
|
||||
}
|
||||
}
|
||||
|
||||
// Credit: https://medium.com/nerd-for-tech/empty-dataset-in-recyclerview-ad86833dd5c6
|
||||
inner class EmptyDataObserver(
|
||||
private val recyclerView: RecyclerView,
|
||||
private val emptyView: View
|
||||
): RecyclerView.AdapterDataObserver() {
|
||||
private val isScopeFragment = this@AppSelectFragment.javaClass == ScopeFragment::class.java
|
||||
|
||||
private fun checkIfEmpty() {
|
||||
val emptyViewVisible = recyclerView.adapter!!.itemCount < if (isScopeFragment) 1 else 2
|
||||
emptyView.visibility = if (emptyViewVisible) View.VISIBLE else View.GONE
|
||||
if (emptyViewVisible) {
|
||||
emptyView.findViewById<TextView>(R.id.list_empty_text).text = getString(
|
||||
if (isScopeFragment) {
|
||||
R.string.list_empty_no_enabled
|
||||
} else {
|
||||
R.string.list_empty_no_apps
|
||||
}
|
||||
)
|
||||
}
|
||||
(recyclerView.parent as View).visibility = if (emptyViewVisible) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onChanged() {
|
||||
super.onChanged()
|
||||
checkIfEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ class TemplateSettingsFragment : Fragment(R.layout.fragment_template_settings) {
|
|||
)
|
||||
|
||||
binding.templateName.setText(viewModel.name)
|
||||
binding.workMode.setText(if (viewModel.isWhiteList) R.string.whitelist else R.string.blacklist)
|
||||
binding.templateName.addTextChangedListener { viewModel.name = it.toString() }
|
||||
binding.targetApps.setOnClickListener {
|
||||
setFragmentResultListener("app_select") { _, bundle ->
|
||||
|
|
|
|||
|
|
@ -37,5 +37,30 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/list_empty_container"
|
||||
android:visibility="gone"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/about_page_item_category_padding_horizontal"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
|
||||
<ImageView
|
||||
android:importantForAccessibility="no"
|
||||
android:src="@drawable/outline_android_24"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="@dimen/app_icon_size"
|
||||
android:layout_height="@dimen/app_icon_size"
|
||||
app:tint="?colorControlNormal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/list_empty_text"
|
||||
android:gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
|
|||
|
|
@ -39,6 +39,28 @@
|
|||
android:layout_height="wrap_content" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="@dimen/item_padding_horizontal"
|
||||
android:minHeight="?listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:textAppearance="?textAppearanceBodyLarge"
|
||||
android:text="@string/work_mode"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:textAppearance="?textAppearanceBodyMedium"
|
||||
android:id="@+id/work_mode"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<icu.nullptr.hidemyapplist.ui.view.ListItemView
|
||||
android:id="@+id/target_apps"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@
|
|||
<string name="list_sort_by_package_name">By package name</string>
|
||||
<string name="list_sort_by_install_time">By install time</string>
|
||||
<string name="list_sort_by_update_time">By update time</string>
|
||||
<string name="list_empty_no_enabled">Try enabling hiding for apps with this template\'s work mode and apps will appear here</string>
|
||||
<string name="list_empty_no_apps">No applications found, maybe you didn\'t allow this app to query all packages</string>
|
||||
|
||||
<!-- Manage templates -->
|
||||
<string name="template_usage_hint">Establish templates for \"restless\" apps, controlling applist they can obtain.\n\nBlacklist (recommended): the apps selected in the template will be invisible to the apps applying the template.\nWhitelist: the apps not selected in the template will be invisible to the apps applying the template.</string>
|
||||
|
|
|
|||
Reference in a new issue