Skip to content

Commit

Permalink
1.5 release & add hide system apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-TSNG committed May 1, 2021
1 parent 371ee50 commit a62d49f
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 130 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.drakeet.about:about:2.4.1'
implementation 'com.drakeet.multitype:multitype:4.2.0'
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'
implementation 'com.scwang.smart:refresh-header-material:2.0.3'

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'org.jetbrains:annotations:15.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'com.google.android.material:material:1.3.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
compileOnly 'de.robv.android.xposed:api:82'
compileOnly 'de.robv.android.xposed:api:82:sources'
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AboutActivity : AbsAboutActivity() {
items.add(License("Gson", "Google", License.APACHE_2, "https://github.com/google/gson"))
items.add(License("MultiType", "drakeet", License.APACHE_2, "https://github.com/drakeet/MultiType"))
items.add(License("about-page", "drakeet", License.APACHE_2, "https://github.com/drakeet/about-page"))
items.add(License("SmartRefreshLayout", "scwang90", License.APACHE_2, "https://github.com/scwang90/SmartRefreshLayout"))
items.add(License("Dobby", "jmpews", License.APACHE_2, "https://github.com/jmpews/Dobby"))
}
}
66 changes: 56 additions & 10 deletions app/src/main/java/com/tsng/hidemyapplist/ui/ScopeManageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ package com.tsng.hidemyapplist.ui

import android.content.pm.ApplicationInfo
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.iterator
import com.tsng.hidemyapplist.R
import kotlinx.android.synthetic.main.appselect.*
import kotlinx.android.synthetic.main.toolbar.*
import java.text.Collator
import java.util.*
import kotlin.collections.set
import kotlin.concurrent.thread

class ScopeManageActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_scope_manage)
setContentView(R.layout.appselect)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(R.id.xposed_score_container, SettingsFragment())
.replace(R.id.appselect_container, SelectAppsFragment())
.commit()
}
}
Expand All @@ -29,34 +37,70 @@ class ScopeManageActivity : AppCompatActivity() {
return true
}

class SettingsFragment : PreferenceFragmentCompat() {

class SelectAppsFragment : PreferenceFragmentCompat() {
private lateinit var map: MutableMap<String, String>
private lateinit var templates: Set<String>

private var showSystemApps = false

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.toolbar_appselect, menu)
val searchView = menu.findItem(R.id.toolbar_search).actionView as SearchView
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
return true
}

override fun onQueryTextChange(newText: String): Boolean {
for (pref in preferenceScreen)
pref.isVisible = pref.title.contains(newText)
return false
}
})
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.toolbar_show_system_apps -> {
item.isChecked = !item.isChecked
showSystemApps = item.isChecked
requireActivity().refresh_layout.autoRefresh()
true
}
else -> super.onOptionsItemSelected(item)
}
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setHasOptionsMenu(true)
preferenceManager.sharedPreferencesName = "Scope"
setPreferencesFromResource(R.xml.scope_preferences, rootKey)
setPreferencesFromResource(R.xml.empty_preferences, rootKey)
map = preferenceManager.sharedPreferences.all as MutableMap<String, String>
templates = setOf("<close>") +
requireActivity().getSharedPreferences("Templates", MODE_PRIVATE).getStringSet("List", setOf())!!
refresh()
requireActivity().refresh_layout.apply {
setOnRefreshListener {
thread { refresh() }
}
autoRefresh()
}
}

private fun refresh() {
val packages = requireActivity().packageManager.getInstalledPackages(0)
packages.removeAll { it.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0 }
if (!showSystemApps)
packages.removeAll { it.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0 && !map.contains(it.packageName) }
packages.sortWith { o1, o2 ->
val l1 = o1.applicationInfo.loadLabel(requireActivity().packageManager) as String
val l2 = o2.applicationInfo.loadLabel(requireActivity().packageManager) as String
if (map.containsKey(o1.packageName) xor map.containsKey(o2.packageName))
if (map.containsKey(o2.packageName)) 1
else -1
else
l1.compareTo(l2)
Collator.getInstance(Locale.getDefault()).compare(l1, l2)
}
preferenceScreen.removeAll()
for (pkg in packages)
for (pkg in packages) {
preferenceScreen.addPreference(ListPreference(context).apply {
dialogTitle = getString(R.string.template_select)
title = pkg.applicationInfo.loadLabel(requireActivity().packageManager)
Expand All @@ -80,6 +124,8 @@ class ScopeManageActivity : AppCompatActivity() {
}
}
})
}
requireActivity().refresh_layout.finishRefresh()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@ package com.tsng.hidemyapplist.ui

import android.content.pm.ApplicationInfo
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.preference.CheckBoxPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.iterator
import com.tsng.hidemyapplist.R
import kotlinx.android.synthetic.main.appselect.*
import kotlinx.android.synthetic.main.toolbar.*
import java.text.Collator
import java.util.*
import kotlin.concurrent.thread


class TemplateSettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {

private var template: String? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_template_settings)
setContentView(R.layout.appselect)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
template = intent.getStringExtra("template")
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
.replace(R.id.xposed_template_container, SettingsFragment().apply {
.replace(R.id.appselect_container, SettingsFragment().apply {
arguments = Bundle().apply { putString("template", template) }
})
.commit()
Expand All @@ -35,7 +43,7 @@ class TemplateSettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.O
fragment.arguments = Bundle().apply { putString("template", template) }
supportFragmentManager
.beginTransaction()
.replace(R.id.xposed_template_container, fragment)
.replace(R.id.appselect_container, fragment)
.addToBackStack(null)
.commit()
return true
Expand All @@ -54,30 +62,66 @@ class TemplateSettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.O
}

class HideAppsFragment : PreferenceFragmentCompat() {

private lateinit var list: MutableSet<String>

private var showSystemApps = false

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.toolbar_appselect, menu)
val searchView = menu.findItem(R.id.toolbar_search).actionView as SearchView
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
return true
}

override fun onQueryTextChange(newText: String): Boolean {
for (pref in preferenceScreen)
pref.isVisible = pref.title.contains(newText)
return false
}
})
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.toolbar_show_system_apps -> {
item.isChecked = !item.isChecked
showSystemApps = item.isChecked
requireActivity().refresh_layout.autoRefresh()
true
}
else -> super.onOptionsItemSelected(item)
}
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setHasOptionsMenu(true)
preferenceManager.sharedPreferencesName = "tpl_" + arguments?.getString("template")
setPreferencesFromResource(R.xml.template_hideapps_preference, rootKey)
setPreferencesFromResource(R.xml.empty_preferences, rootKey)
list = preferenceManager.sharedPreferences.getStringSet("HideApps", setOf())!!.toMutableSet()
refresh()
requireActivity().refresh_layout.apply {
setOnRefreshListener {
thread { refresh() }
}
autoRefresh()
}
}

private fun refresh() {
val packages = requireActivity().packageManager.getInstalledPackages(0)
packages.removeAll { it.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0 }
if (!showSystemApps)
packages.removeAll { it.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0 && !list.contains(it.packageName) }
packages.sortWith { o1, o2 ->
val l1 = o1.applicationInfo.loadLabel(requireActivity().packageManager) as String
val l2 = o2.applicationInfo.loadLabel(requireActivity().packageManager) as String
if (list.contains(o1.packageName) xor list.contains(o2.packageName))
if (list.contains(o2.packageName)) 1
else -1
else
l1.compareTo(l2)
Collator.getInstance(Locale.getDefault()).compare(l1, l2)
}
preferenceScreen.removeAll()
for (pkg in packages)
for (pkg in packages) {
preferenceScreen.addPreference(CheckBoxPreference(context).apply {
title = pkg.applicationInfo.loadLabel(requireActivity().packageManager)
icon = pkg.applicationInfo.loadIcon(requireActivity().packageManager)
Expand All @@ -91,6 +135,8 @@ class TemplateSettingsActivity : AppCompatActivity(), PreferenceFragmentCompat.O
true
}
})
}
requireActivity().refresh_layout.finishRefresh()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.tsng.hidemyapplist.xposed

import com.tsng.hidemyapplist.xposed.XposedUtils.Companion.APPNAME
import com.tsng.hidemyapplist.xposed.XposedUtils.APPNAME
import com.tsng.hidemyapplist.xposed.hooks.IndividualHooks
import com.tsng.hidemyapplist.xposed.hooks.PackageManagerService
import de.robv.android.xposed.IXposedHookLoadPackage
Expand Down
Loading

0 comments on commit a62d49f

Please sign in to comment.