Fix/fast appmenu (#20)

* Preload list of Apps when starting the App

In OnCreate, the variable `appsList` is used globally

* Improve ChooseActivity layout

Match it to the style of settings

* Reload appList continuously

Every 30 Seconds or when a app gets removed

* Create a `Install Apps` button

On click the PlayStore will be opened.

* Add missing translations

* Move global variables to `Functions.kt`

Anyone thinking global vars should not be used? I don't care haha... 
unless ... feel free to fork this repository and provide a better way of 
doing this ^^
This commit is contained in:
Finn M Glas 2020-05-22 12:50:13 +02:00 committed by GitHub
parent 61fd660195
commit f6c20098b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 123 additions and 71 deletions

View file

@ -35,37 +35,23 @@ class ChooseActivity : AppCompatActivity() {
heading.text = getString(R.string.choose_title_launch)
else if (action == "pick") {
heading.text = getString(R.string.choose_title)
subheading.text = forApp // TODO: make translatable
}
else if (action == "uninstall")
heading.text = getString(R.string.choose_title_remove)
/* Build Layout */
// TODO: Make this more efficient, faster, generate the list before
val mainIntent = Intent(Intent.ACTION_MAIN, null)
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
val pm = packageManager
val i = Intent(Intent.ACTION_MAIN)
i.addCategory(Intent.CATEGORY_LAUNCHER)
val apps = pm.queryIntentActivities(i, 0)
apps.sortBy { it.activityInfo.loadLabel(pm).toString() }
for (resolveInfo in apps) {
for (resolveInfo in appsList) {
val app = resolveInfo.activityInfo
pm.getLaunchIntentForPackage(app.packageName)
// creating TextView programmatically
val tvdynamic = TextView(this)
tvdynamic.textSize = 24f
tvdynamic.text = app.loadLabel(pm).toString()
tvdynamic.text = app.loadLabel(packageManager).toString()
tvdynamic.setTextColor(Color.parseColor("#cccccc"))
if (action == "launch"){
tvdynamic.setOnClickListener { startActivity(pm.getLaunchIntentForPackage(app.packageName)) }
tvdynamic.setOnClickListener { startActivity(packageManager.getLaunchIntentForPackage(app.packageName)) }
}
else if (action == "pick"){
tvdynamic.setOnClickListener {
@ -96,6 +82,7 @@ class ChooseActivity : AppCompatActivity() {
if (requestCode == UNINSTALL_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(this, getString(R.string.choose_removed_toast), Toast.LENGTH_LONG).show()
updateAppList(packageManager)
finish()
} else if (resultCode == Activity.RESULT_FIRST_USER) {
Toast.makeText(this, getString(R.string.choose_not_removed_toast), Toast.LENGTH_LONG).show()

View file

@ -7,6 +7,7 @@ import android.content.DialogInterface
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
@ -16,6 +17,19 @@ import android.view.animation.Animation
import android.view.animation.DecelerateInterpolator
import android.widget.Toast
/** Variables for all of the app */
var upApp = ""
var downApp = ""
var rightApp = ""
var leftApp = ""
var volumeUpApp = ""
var volumeDownApp = ""
var calendarApp = ""
var clockApp = ""
var appsList : MutableList<ResolveInfo> = mutableListOf()
// Taken from https://stackoverflow.com/questions/47293269
fun View.blink(
times: Int = Animation.INFINITE,
@ -58,6 +72,13 @@ fun isInstalled(uri: String, context: Context): Boolean {
return false
}
fun updateAppList(pm : PackageManager) {
val intent = Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER)
appsList = pm.queryIntentActivities(intent, 0)
appsList.sortBy { it.activityInfo.loadLabel(pm).toString() }
}
private fun getIntent(packageName: String, context: Context): Intent? {
val intent: Intent? = context.packageManager.getLaunchIntentForPackage(packageName)
intent?.addCategory(Intent.CATEGORY_LAUNCHER)

View file

@ -2,6 +2,7 @@ package com.finnmglas.launcher
import android.content.Context
import android.content.Intent
import android.os.AsyncTask
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.*
@ -13,17 +14,6 @@ import java.util.*
import kotlin.concurrent.fixedRateTimer
import kotlin.math.abs
/** Variables for all of the app */
var upApp = ""
var downApp = ""
var rightApp = ""
var leftApp = ""
var volumeUpApp = ""
var volumeDownApp = ""
var calendarApp = ""
var clockApp = ""
class MainActivity : AppCompatActivity(),
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
@ -36,6 +26,7 @@ class MainActivity : AppCompatActivity(),
// timers
private var clockTimer = Timer()
private var tooltipTimer = Timer()
private var loadAppsTimer = Timer()
private var settingsIconShown = false
@ -99,11 +90,17 @@ class MainActivity : AppCompatActivity(),
}
}
val pm = packageManager
loadAppsTimer = fixedRateTimer("loadAppsTimer", true, 0L, 30000) {
AsyncTask.execute { updateAppList(pm) }
}
}
override fun onPause() {
super.onPause()
clockTimer.cancel()
loadAppsTimer.cancel()
}

View file

@ -8,6 +8,7 @@ import android.os.Bundle
import android.provider.Settings
import android.view.View
import android.view.WindowManager
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.finnmglas.launcher.ui.main.SectionsPagerAdapter
@ -81,6 +82,18 @@ class SettingsActivity : AppCompatActivity() {
startActivity(intent)
}
fun chooseInstallApp(view : View) {
try {
val rateIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/"))
startActivity(rateIntent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(this,getString(R.string.settings_toast_store_not_found), Toast.LENGTH_SHORT)
.show()
}
}
fun openFinnWebsite(view: View) { openNewTabWindow(getString(R.string.settings_footer_web), this) }
fun openGithubRepo(view: View) { openNewTabWindow(getString(R.string.settings_footer_repo), this) }