Skip to content

Commit

Permalink
Major refactor, removed all of the Computable stuff in favour of an i…
Browse files Browse the repository at this point in the history
…con loader
  • Loading branch information
Zagura committed Apr 13, 2022
1 parent c1f80c2 commit 40b2739
Show file tree
Hide file tree
Showing 33 changed files with 522 additions and 750 deletions.
68 changes: 53 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,64 @@
# Launcher utils
A library for android launcher creation (very much in alpha stage)
# launcherutil

A library for android launcher creation (in alpha stage)

## Features
- App loading
- Kustom variables
- Icon-related utilities
- Send signals to live wallpaper
- Kustom variables

## How to use
Make sure you have the jitpack.io repo added in your project
```kotlin
allprojects {
## Installation
Add the dependency to your `build.gradle(.kts)` file:
<table>
<thead>
<tr>
<th>Kotlin</th>
<th>Groovy</th>
</tr>
</thead>
<tr>
<td>
<pre lang="kotlin">dependencies {
// ...
implementation("io.posidon:android.launcherutil:22.0")
}</pre>
</td>
<td>
<pre lang="groovy">dependencies {
// ...
implementation 'io.posidon:android.launcherutil:22.0'
}</pre>
</td>
</tr>
</table>

And also make sure that the `jitpack.io` repository is included
<table>
<thead>
<tr>
<th>Kotlin</th>
<th>Groovy</th>
</tr>
</thead>
<tr>
<td>
<pre lang="kotlin">allprojects {
repositories {
// ...
maven {
url = uri("https://jitpack.io")
}
}
}
```
Add the dependency
```kotlin
dependencies {
implementation("io.posidon:android.launcherUtils:${VERSION}")
}
```
}</pre>
</td>
<td>
<pre lang="groovy">allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}</pre>
</td>
</tr>
</table>
10 changes: 5 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ plugins {
}

android {
compileSdk = 31
compileSdk = 32

defaultConfig {
applicationId = "io.posidon.android.launcherutils.demo"
applicationId = "io.posidon.android.launcherutil.demo"
minSdk = 26
targetSdk = 31
targetSdk = 32
versionCode = 1
versionName = "1.0"
versionName = "22.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -31,7 +31,7 @@ dependencies {
implementation("io.posidon:android.convenienceLib:master-SNAPSHOT")
implementation("org.jetbrains.kotlin:kotlin-stdlib:${getKotlinPluginVersion()}")
implementation("androidx.core:core-ktx:1.7.0")
implementation("com.google.android.material:material:1.4.0")
implementation("com.google.android.material:material:1.5.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.posidon.android.launcherutils.demo">
package="io.posidon.android.launcherutil.demo">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.LauncherUtils">
android:theme="@style/Theme.launcherutil">
<activity
android:name=".MainActivity"
android:name="io.posidon.android.launcherutil.demo.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
13 changes: 0 additions & 13 deletions app/src/main/java/io/posidon/android/launcherutils/demo/App.kt

This file was deleted.

This file was deleted.

10 changes: 10 additions & 0 deletions app/src/main/kotlin/io/posidon/android/launcherutil/demo/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.posidon.android.launcherutil.demo

import android.os.UserHandle

class App(
val packageName: String,
val name: String,
val profile: UserHandle,
val label: String
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.posidon.android.launcherutils.demo
package io.posidon.android.launcherutil.demo

import android.view.View
import android.widget.ImageView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.posidon.android.launcherutils.demo
package io.posidon.android.launcherutil.demo

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import io.posidon.android.computable.compute
import java.util.concurrent.Future

class AppsAdapter : RecyclerView.Adapter<AppViewHolder>() {
class AppsAdapter(val mainActivity: MainActivity) : RecyclerView.Adapter<AppViewHolder>() {

private var list = emptyList<App>()

Expand All @@ -15,21 +15,29 @@ class AppsAdapter : RecyclerView.Adapter<AppViewHolder>() {
return AppViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.app_item, parent, false))
}

private var workers = HashMap<Int, Future<Unit>>()

override fun onBindViewHolder(holder: AppViewHolder, i: Int) {
val img = holder.icon
workers[i]?.cancel(true)
img.setImageDrawable(null)
val app = list[i]
holder.icon.setImageDrawable(null)
app.icon.compute {
holder.icon.post {
holder.icon.setImageDrawable(it)
workers[i] = mainActivity.iconLoader.load(
holder.itemView.context,
app.packageName,
app.name,
app.profile,
) {
img.post {
img.setImageDrawable(it.icon)
}
}
holder.label.text = app.label
}

override fun onViewRecycled(holder: AppViewHolder) {
val i = holder.adapterPosition
if (i != -1)
list[i].icon.offload()
workers[holder.adapterPosition]?.cancel(true)
holder.icon.setImageDrawable(null)
}

fun update(list: List<App>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package io.posidon.android.launcherutils.demo
package io.posidon.android.launcherutil.demo

import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.posidon.android.launcherutils.IconTheming
import io.posidon.android.launcherutils.appLoading.AppLoader
import io.posidon.android.launcherutils.appLoading.IconConfig
import io.posidon.android.launcherutil.IconTheming
import io.posidon.android.launcherutil.Launcher
import io.posidon.android.launcherutil.isUserRunning
import io.posidon.android.launcherutil.loader.AppIconLoader

class MainActivity : AppCompatActivity() {

val appsAdapter = AppsAdapter()
val appLoader = AppLoader(::AppCollection)
val appsAdapter = AppsAdapter(this)
lateinit var iconLoader: AppIconLoader<Nothing?>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -37,16 +41,41 @@ class MainActivity : AppCompatActivity() {
}

fun loadApps(iconPack: String? = null) {
val iconConfig = IconConfig(
iconLoader = Launcher.iconLoader(
this,
size = (resources.displayMetrics.density * 128f).toInt(),
density = resources.configuration.densityDpi,
packPackages = iconPack?.let { arrayOf(it) } ?: emptyArray(),
) { _, _, profile, icon ->
if (!isUserRunning(profile)) {
icon?.convertToGrayscale() to null
} else icon to null
}
val list = ArrayList<App>()
Launcher.appLoader.loadAsync(
this,
onEnd = {
list.sortWith { o1, o2 ->
o1.label.compareTo(o2.label, ignoreCase = true)
}
runOnUiThread {
appsAdapter.update(list)
}
},
forEachApp = {
list += App(
it.packageName,
it.name,
it.profile,
it.getBadgedLabel(this)
)
}
)
}

appLoader.async(this, iconConfig) {
runOnUiThread {
appsAdapter.update(it.list)
}
}
private fun Drawable.convertToGrayscale(): Drawable = apply {
colorFilter = ColorMatrixColorFilter(ColorMatrix().apply {
setSaturation(0f)
})
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<string name="app_name">LauncherUtils</string>
<string name="app_name">launcherutil</string>
<string name="choose_icon_pack">Choose icon pack</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.LauncherUtils" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.launcherutil" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
val kotlinVersion by extra("1.6.0")
val kotlinVersion by extra("1.6.20")
repositories {
google()
gradlePluginPortal()
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.3")
classpath("com.android.tools.build:gradle:7.1.3")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jun 23 08:52:45 CEST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading

0 comments on commit 40b2739

Please sign in to comment.