Skip to content

Commit

Permalink
Merge to Jetpack Compose
Browse files Browse the repository at this point in the history
Theme selection
  • Loading branch information
wenxuanjun committed May 11, 2022
1 parent 0d534c0 commit 0759f76
Show file tree
Hide file tree
Showing 35 changed files with 861 additions and 397 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NoLitter

Prevents apps from littering in storage.
23 changes: 19 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ plugins {

android {
compileSdk 32

defaultConfig {
applicationId "lantian.nolitter"
minSdk 27
targetSdk 32
versionCode 13
versionName "1.4.2"
versionCode 14
versionName "1.5.0"
}
buildTypes {
release {
Expand All @@ -19,6 +20,12 @@ android {
proguardFiles 'proguard-rules.pro'
}
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion "1.1.1"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -28,6 +35,14 @@ android {
dependencies {
compileOnly 'de.robv.android.xposed:api:82'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.preference:preference:1.2.0'
implementation "androidx.compose.ui:ui:1.2.0-alpha08"
implementation 'androidx.compose.ui:ui-tooling:1.2.0-alpha08'
implementation "androidx.compose.ui:ui-tooling-preview:1.2.0-alpha08"
implementation 'androidx.compose.animation:animation:1.1.1'
implementation "androidx.compose.material:material:1.2.0-alpha08"
implementation "androidx.compose.material:material-icons-extended:1.2.0-alpha08"
implementation 'androidx.activity:activity-compose:1.5.0-beta01'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-beta01'
implementation 'androidx.navigation:navigation-compose:2.5.0-beta01'
implementation 'com.google.accompanist:accompanist-drawablepainter:0.24.7-alpha'
}
25 changes: 7 additions & 18 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,20 @@

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission" />

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="xposedmodule"
android:value="true" />
<meta-data
android:name="xposeddescription"
android:value="@string/xposed_description" />
<meta-data
android:name="xposedminversion"
android:value="93" />

<activity
android:name=".MainActivity"
android:exported="true">
<meta-data android:name="xposedmodule" android:value="true" />
<meta-data android:name="xposeddescription" android:value="@string/xposed_description" />
<meta-data android:name="xposedminversion" android:value="93" />

<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -45,15 +36,13 @@
</activity-alias>

<receiver
android:name=".CleanFolderReceiver"
android:name=".receiver.CleanFolder"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>

</application>

</manifest>
31 changes: 11 additions & 20 deletions app/src/main/java/lantian/nolitter/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
package lantian.nolitter

import android.Manifest
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.core.app.ActivityCompat
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.ViewModelProvider
import lantian.nolitter.ui.AppUi

class MainActivity : AppCompatActivity() {

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 233)
}
supportFragmentManager.beginTransaction().replace(android.R.id.content, SettingsFragment()).commit()
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
233 -> {
if (!(grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
Toast.makeText(this, R.string.ui_failPermission, Toast.LENGTH_SHORT).show()
}
}
}
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean ->
if (!isGranted) Toast.makeText(this, R.string.ui_failPermission, Toast.LENGTH_SHORT).show()
}.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE)
setContent { AppUi(ViewModelProvider(this)[MainViewModel::class.java]) }
}
}
74 changes: 74 additions & 0 deletions app/src/main/java/lantian/nolitter/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package lantian.nolitter

import android.app.Application
import android.content.ComponentName
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.AndroidViewModel

data class InstalledPackageInfo (val appName: String, val appIcon: Drawable, val isSystem: Boolean, val isModule: Boolean, val isForced: Boolean, val packageName: String)

class MainViewModel(application: Application) : AndroidViewModel(application) {
private var activity: Application = application
private var sharedPreferences: SharedPreferences? = try {
activity.getSharedPreferences(BuildConfig.APPLICATION_ID + "_preferences", Context.MODE_WORLD_READABLE)
} catch (e: SecurityException) { null }

var appTheme: MutableState<String?> = mutableStateOf(getStringPreference("theme", "default"))
var topAppBarTitle: MutableState<String> = mutableStateOf(activity.resources.getString(R.string.app_name))
fun isAvailable(): Boolean { return sharedPreferences != null }
fun getBooleanPreference(key: String, defaultValue: Boolean): Boolean { return sharedPreferences?.getBoolean(key, defaultValue) ?: defaultValue }
fun getStringPreference(key: String, defaultValue: String): String { return sharedPreferences?.getString(key, defaultValue) ?: defaultValue }
fun setBooleanPreference(key: String, value: Boolean) { sharedPreferences!!.edit().putBoolean(key, value).apply() }
fun setStringPreference(key: String, value: String) { sharedPreferences!!.edit().putString(key, value).apply() }
fun hideAppIcon(value: Boolean) {
activity.packageManager.setComponentEnabledSetting(
ComponentName(activity, MainActivity::class.java),
if (value) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
}
fun getNavigationTitle(key: String?): String {
return when (key) {
"PreferenceGeneral" -> activity.resources.getString(R.string.ui_settings_general)
"PreferenceInterface" -> activity.resources.getString(R.string.ui_settings_interface)
"PreferenceAdvanced" -> activity.resources.getString(R.string.ui_settings_advanced)
"PreferenceSelectApps" -> activity.resources.getString(R.string.ui_settings_forceMode)
else -> activity.resources.getString(R.string.app_name)
}
}
fun getAllInstalledPackages(): ArrayList<InstalledPackageInfo> {
val packageManager = activity.packageManager
val installedPackages: List<PackageInfo> = packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
var allPackageInfo: ArrayList<InstalledPackageInfo> = ArrayList()
val forcedApps = getStringPreference("forced", "").split(",")
for (installedPackage in installedPackages) {
val applicationInfo = installedPackage.applicationInfo
val applicationFlag = installedPackage.applicationInfo.flags
allPackageInfo.add(InstalledPackageInfo(
appName = applicationInfo.loadLabel(packageManager).toString(),
appIcon = applicationInfo.loadIcon(packageManager),
isSystem = (applicationFlag and ApplicationInfo.FLAG_SYSTEM != 0) || (applicationFlag and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0),
isModule = applicationInfo.metaData != null && applicationInfo.metaData.containsKey("xposedmodule"),
isForced = forcedApps.contains(applicationInfo.packageName),
packageName = applicationInfo.packageName,
))
}
return allPackageInfo
}
fun onChangeForcedApps(packageName: String, newValue: Boolean) {
val forcedApps = getStringPreference("forced", "").split(",").toMutableList()
if (newValue) forcedApps.add(packageName) else forcedApps.remove(packageName)
var newForcedApps = ""
for (forcedApp in forcedApps) {
if (forcedApp.trim().isNotEmpty()) newForcedApps += forcedApp.trim() + ","
}
setStringPreference("forced", newForcedApps)
}
}
Loading

0 comments on commit 0759f76

Please sign in to comment.