forked from Dr-TSNG/Hide-My-Applist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
310 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
app/src/main/java/icu/nullptr/hidemyapplist/ui/adapter/AppAdapter.kt
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
app/src/main/java/icu/nullptr/hidemyapplist/ui/adapter/AppManageAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package icu.nullptr.hidemyapplist.ui.adapter | ||
|
||
import android.view.ViewGroup | ||
import icu.nullptr.hidemyapplist.service.ConfigManager | ||
import icu.nullptr.hidemyapplist.ui.view.AppItemView | ||
|
||
class AppManageAdapter : AppSelectAdapter() { | ||
|
||
inner class ViewHolder(view: AppItemView) : AppSelectAdapter.ViewHolder(view) { | ||
override fun bind(packageName: String) { | ||
(itemView as AppItemView).let { | ||
it.load(packageName) | ||
it.showEnabled = ConfigManager.isUsingHide(packageName) | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = AppItemView(parent.context, false) | ||
view.layoutParams = ViewGroup.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.WRAP_CONTENT | ||
) | ||
return ViewHolder(view) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/icu/nullptr/hidemyapplist/ui/adapter/AppScopeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package icu.nullptr.hidemyapplist.ui.adapter | ||
|
||
import android.view.ViewGroup | ||
import icu.nullptr.hidemyapplist.service.ConfigManager | ||
import icu.nullptr.hidemyapplist.ui.view.AppItemView | ||
|
||
class AppScopeAdapter( | ||
filterOnlyEnabled: Boolean, | ||
private val checked: MutableSet<String> | ||
) : AppSelectAdapter(if (filterOnlyEnabled) ConfigManager::isUsingHide else null) { | ||
|
||
private inline var String.isChecked | ||
get() = checked.contains(this) | ||
set(value) { | ||
if (value) checked.add(this) else checked.remove(this) | ||
} | ||
|
||
inner class ViewHolder(view: AppItemView) : AppSelectAdapter.ViewHolder(view) { | ||
init { | ||
view.setOnClickListener { | ||
val packageName = filteredList[absoluteAdapterPosition] | ||
packageName.isChecked = !packageName.isChecked | ||
view.isChecked = packageName.isChecked | ||
} | ||
} | ||
|
||
override fun bind(packageName: String) { | ||
(itemView as AppItemView).let { | ||
it.load(packageName) | ||
it.isChecked = packageName.isChecked | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = AppItemView(parent.context, true) | ||
view.layoutParams = ViewGroup.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.WRAP_CONTENT | ||
) | ||
return ViewHolder(view) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/icu/nullptr/hidemyapplist/ui/adapter/AppSelectAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package icu.nullptr.hidemyapplist.ui.adapter | ||
|
||
import android.widget.Filter | ||
import android.widget.Filterable | ||
import androidx.recyclerview.widget.RecyclerView | ||
import icu.nullptr.hidemyapplist.service.PrefManager | ||
import icu.nullptr.hidemyapplist.ui.view.AppItemView | ||
import icu.nullptr.hidemyapplist.util.PackageHelper | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
|
||
abstract class AppSelectAdapter( | ||
private val firstFilter: ((String) -> Boolean)? = null | ||
) : RecyclerView.Adapter<AppSelectAdapter.ViewHolder>(), Filterable { | ||
|
||
abstract class ViewHolder(view: AppItemView) : RecyclerView.ViewHolder(view) { | ||
abstract fun bind(packageName: String) | ||
} | ||
|
||
private inner class AppFilter : Filter() { | ||
override fun performFiltering(constraint: CharSequence): FilterResults { | ||
return runBlocking { | ||
val constraintLowered = constraint.toString().lowercase() | ||
val filteredList = PackageHelper.appList.first().filter { | ||
if (firstFilter?.invoke(it) == false) return@filter false | ||
if (!PrefManager.filter_showSystem && PackageHelper.isSystem(it)) return@filter false | ||
val label = PackageHelper.loadAppLabel(it) | ||
val packageInfo = PackageHelper.loadPackageInfo(it) | ||
label.lowercase().contains(constraintLowered) || packageInfo.packageName.lowercase().contains(constraintLowered) | ||
} | ||
|
||
FilterResults().also { it.values = filteredList } | ||
} | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST", "NotifyDataSetChanged") | ||
override fun publishResults(constraint: CharSequence, results: FilterResults) { | ||
filteredList = results.values as List<String> | ||
notifyDataSetChanged() | ||
} | ||
} | ||
|
||
private val mFilter = AppFilter() | ||
|
||
protected var filteredList: List<String> = listOf() | ||
|
||
override fun getItemCount() = filteredList.size | ||
|
||
override fun getItemId(position: Int) = filteredList[position].hashCode().toLong() | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(filteredList[position]) | ||
|
||
override fun getFilter(): Filter = mFilter | ||
} |
23 changes: 20 additions & 3 deletions
23
app/src/main/java/icu/nullptr/hidemyapplist/ui/fragment/AppManageFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
package icu.nullptr.hidemyapplist.ui.fragment | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.tsng.hidemyapplist.R | ||
import android.os.Bundle | ||
import androidx.fragment.app.viewModels | ||
import com.google.android.material.transition.MaterialSharedAxis | ||
import icu.nullptr.hidemyapplist.service.ConfigManager | ||
import icu.nullptr.hidemyapplist.ui.adapter.AppManageAdapter | ||
import icu.nullptr.hidemyapplist.ui.viewmodel.AppSelectViewModel | ||
|
||
class AppManageFragment : Fragment(R.layout.fragment_app_manage) { | ||
class AppManageFragment : AppSelectFragment() { | ||
|
||
override val viewModel by viewModels<AppSelectViewModel> { | ||
AppSelectViewModel.Factory( | ||
firstComparator = Comparator.comparing(ConfigManager::isUsingHide).reversed(), | ||
adapter = AppManageAdapter() | ||
) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, true) | ||
returnTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/main/java/icu/nullptr/hidemyapplist/ui/fragment/ScopeFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package icu.nullptr.hidemyapplist.ui.fragment | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.setFragmentResult | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.navArgs | ||
import icu.nullptr.hidemyapplist.ui.adapter.AppScopeAdapter | ||
import icu.nullptr.hidemyapplist.ui.util.navController | ||
import icu.nullptr.hidemyapplist.ui.viewmodel.AppSelectViewModel | ||
|
||
class ScopeFragment : AppSelectFragment() { | ||
|
||
private lateinit var checked: MutableSet<String> | ||
|
||
override val viewModel by viewModels<AppSelectViewModel> { | ||
val args by navArgs<ScopeFragmentArgs>() | ||
checked = args.checked.toMutableSet() | ||
AppSelectViewModel.Factory( | ||
firstComparator = Comparator.comparing { !checked.contains(it) }, | ||
adapter = AppScopeAdapter(args.filterOnlyEnabled, checked) | ||
) | ||
} | ||
|
||
override fun onBack() { | ||
setFragmentResult("app_select", Bundle().apply { | ||
putStringArrayList("checked", ArrayList(checked)) | ||
}) | ||
navController.navigateUp() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.