Reuse Home tiles and Plex artwork to reduce allocation
This commit is contained in:
parent
5f035d909a
commit
ac0a892c5f
14 changed files with 741 additions and 40 deletions
|
|
@ -6,8 +6,8 @@ android {
|
|||
applicationId 'tv.luma.launcher'
|
||||
minSdk 26
|
||||
targetSdk 34
|
||||
versionCode 13
|
||||
versionName '1.1.10'
|
||||
versionCode 14
|
||||
versionName '1.1.11'
|
||||
}
|
||||
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8; targetCompatibility JavaVersion.VERSION_1_8 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tv.luma.launcher" android:versionCode="13" android:versionName="1.1.10">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tv.luma.launcher" android:versionCode="14" android:versionName="1.1.11">
|
||||
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="34" />
|
||||
<uses-feature android:name="android.software.leanback" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
|
||||
|
|
|
|||
|
|
@ -128,6 +128,8 @@ final class AppTile extends LinearLayout {
|
|||
art.animate().cancel();
|
||||
if (shadowAnimation != null) shadowAnimation.cancel();
|
||||
shadowAmount = hasFocus() ? 1 : 0;
|
||||
setScaleX(hasFocus() ? 1.065f : 1f);
|
||||
setScaleY(hasFocus() ? 1.065f : 1f);
|
||||
}
|
||||
|
||||
void bitmap(Bitmap b) {
|
||||
|
|
|
|||
|
|
@ -38,9 +38,12 @@ public final class MainActivity extends Activity {
|
|||
private volatile int generation = 0;
|
||||
private volatile int iconGeneration = 0;
|
||||
private volatile int artGeneration = 0;
|
||||
private String displayedArtPath = "", requestedArtPath = "";
|
||||
private Runnable artworkTask;
|
||||
private int rotation = 0;
|
||||
private volatile boolean foreground = false;
|
||||
private boolean appsNeedRefresh = true;
|
||||
private int gridColumns, gridWidth;
|
||||
private boolean moving = false;
|
||||
private volatile Dialog currentDialog;
|
||||
private PlexClient plex;
|
||||
|
|
@ -296,7 +299,7 @@ public final class MainActivity extends Activity {
|
|||
}
|
||||
|
||||
private void keepFocusVisible(View focused) {
|
||||
if (!focused.hasFocus() || content == null) return;
|
||||
if (!foreground || !focused.hasFocus() || content == null) return;
|
||||
Rect bounds = new Rect();
|
||||
focused.getDrawingRect(bounds);
|
||||
content.offsetDescendantRectToMyCoords(focused, bounds);
|
||||
|
|
@ -368,7 +371,7 @@ public final class MainActivity extends Activity {
|
|||
handler.removeCallbacks(refreshInputTask);
|
||||
inputGeneration++;
|
||||
generation++;
|
||||
artGeneration++;
|
||||
cancelArtworkRequest();
|
||||
work.getQueue().clear();
|
||||
network.getQueue().clear();
|
||||
handler.removeCallbacks(minuteTick);
|
||||
|
|
@ -398,7 +401,7 @@ public final class MainActivity extends Activity {
|
|||
super.onStop();
|
||||
generation++;
|
||||
appsNeedRefresh = true;
|
||||
artGeneration++;
|
||||
cancelArtworkRequest();
|
||||
work.getQueue().clear();
|
||||
network.getQueue().clear();
|
||||
repository.icons.evictAll();
|
||||
|
|
@ -480,12 +483,10 @@ public final class MainActivity extends Activity {
|
|||
if (!tile.hasImage() && tile.getTag() instanceof PlexClient.Media)
|
||||
loadMediaThumbnail(tile, (PlexClient.Media) tile.getTag(), g);
|
||||
}
|
||||
if (!scene.hasMediaArt()) {
|
||||
View focused = getCurrentFocus();
|
||||
if (focused != null && focused.getTag() instanceof PlexClient.Media)
|
||||
featureArtwork(((PlexClient.Media) focused.getTag()).art);
|
||||
else if (selected.contains("plex") || selected.contains("plezy")) featurePlexArtwork();
|
||||
}
|
||||
View focused = getCurrentFocus();
|
||||
if (focused != null && focused.getTag() instanceof PlexClient.Media)
|
||||
featureArtwork(((PlexClient.Media) focused.getTag()).art);
|
||||
else if (selected.contains("plex") || selected.contains("plezy")) featurePlexArtwork();
|
||||
}
|
||||
|
||||
private int columns() {
|
||||
|
|
@ -503,6 +504,7 @@ public final class MainActivity extends Activity {
|
|||
|
||||
private void renderApps() {
|
||||
iconGeneration++;
|
||||
List<AppRepository.App> previous = new ArrayList<>(visibleApps);
|
||||
Set<String> hidden = hidden();
|
||||
List<String> order = savedOrder();
|
||||
List<String> defaults =
|
||||
|
|
@ -528,32 +530,55 @@ public final class MainActivity extends Activity {
|
|||
if (bi < 0) bi = 1000 + (defaults.contains(b.pkg) ? defaults.indexOf(b.pkg) : 100);
|
||||
return ai == bi ? a.label.compareToIgnoreCase(b.label) : Integer.compare(ai, bi);
|
||||
});
|
||||
appsContainer.removeAllViews();
|
||||
tiles.clear();
|
||||
int cols = columns();
|
||||
int screen =
|
||||
(int)
|
||||
(getResources().getDisplayMetrics().widthPixels
|
||||
/ getResources().getDisplayMetrics().density);
|
||||
int width = (screen - 102) / cols;
|
||||
boolean reuse =
|
||||
gridColumns == cols
|
||||
&& gridWidth == width
|
||||
&& previous.size() == visibleApps.size()
|
||||
&& tiles.size() == visibleApps.size();
|
||||
for (int i = 0; reuse && i < previous.size(); i++) {
|
||||
AppRepository.App old = previous.get(i), current = visibleApps.get(i);
|
||||
reuse =
|
||||
old.pkg.equals(current.pkg)
|
||||
&& old.label.equals(current.label)
|
||||
&& old.component.equals(current.component)
|
||||
&& Objects.equals(
|
||||
old.info.activityInfo.applicationInfo.sourceDir,
|
||||
current.info.activityInfo.applicationInfo.sourceDir);
|
||||
}
|
||||
if (!reuse) {
|
||||
appsContainer.removeAllViews();
|
||||
tiles.clear();
|
||||
}
|
||||
gridColumns = cols;
|
||||
gridWidth = width;
|
||||
LinearLayout row = null;
|
||||
int index = 0;
|
||||
for (AppRepository.App app : visibleApps) {
|
||||
if (index % cols == 0) {
|
||||
if (!reuse && index % cols == 0) {
|
||||
row = new LinearLayout(this);
|
||||
row.setClipChildren(false);
|
||||
row.setClipToPadding(false);
|
||||
appsContainer.addView(row, new LinearLayout.LayoutParams(-1, -2));
|
||||
}
|
||||
AppTile tile = new AppTile(this, app.label, width, cols > 6);
|
||||
tile.setId(View.generateViewId());
|
||||
AppTile tile;
|
||||
if (reuse) tile = tiles.get(app.pkg);
|
||||
else {
|
||||
tile = new AppTile(this, app.label, width, cols > 6);
|
||||
tile.setId(View.generateViewId());
|
||||
row.addView(tile, new LinearLayout.LayoutParams(d(width), -2));
|
||||
tiles.put(app.pkg, tile);
|
||||
}
|
||||
tile.setTag(app.pkg);
|
||||
tile.setMotion(motion());
|
||||
tile.setLabelMode(prefs.getString("labels", "focused"));
|
||||
tile.setAccent(AppRepository.color(app.pkg));
|
||||
if (index < cols) tile.setNextFocusUpId(settingsButton.getId());
|
||||
row.addView(tile, new LinearLayout.LayoutParams(d(width), -2));
|
||||
tiles.put(app.pkg, tile);
|
||||
tile.onFocused(
|
||||
f -> {
|
||||
if (f) {
|
||||
|
|
@ -569,7 +594,7 @@ public final class MainActivity extends Activity {
|
|||
});
|
||||
index++;
|
||||
}
|
||||
if (visibleApps.isEmpty()) {
|
||||
if (!reuse && visibleApps.isEmpty()) {
|
||||
TextView empty = chip("No visible apps · Open all apps", v -> showAllApps());
|
||||
appsContainer.addView(empty, new LinearLayout.LayoutParams(-1, d(70)));
|
||||
}
|
||||
|
|
@ -586,6 +611,7 @@ public final class MainActivity extends Activity {
|
|||
if (target != null) {
|
||||
target.requestFocus();
|
||||
updateHero(findApp(restore));
|
||||
if (reuse) target.post(() -> keepFocusVisible(target));
|
||||
}
|
||||
reloadIcons();
|
||||
}
|
||||
|
|
@ -607,7 +633,10 @@ public final class MainActivity extends Activity {
|
|||
Bitmap b = repository.icon(a);
|
||||
handler.post(
|
||||
() -> {
|
||||
if (foreground && g == generation && tiles.get(a.pkg) == t) t.bitmap(b);
|
||||
if (foreground
|
||||
&& g == generation
|
||||
&& ig == iconGeneration
|
||||
&& tiles.get(a.pkg) == t) t.bitmap(b);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -615,9 +644,9 @@ public final class MainActivity extends Activity {
|
|||
|
||||
private void updateHero(AppRepository.App a) {
|
||||
if (a == null) return;
|
||||
artGeneration++;
|
||||
scene.setMediaArt(null);
|
||||
String p = a.pkg;
|
||||
boolean plexApp = p.contains("plex") || p.contains("plezy");
|
||||
if (!plexApp || plexFeatured == null) clearFeaturedArtwork();
|
||||
String title = a.label;
|
||||
String body = "Your next favorite moment is one click away.";
|
||||
String tag = "READY WHEN YOU ARE";
|
||||
|
|
@ -657,7 +686,7 @@ public final class MainActivity extends Activity {
|
|||
int accent = prefs.getInt("accent", 0);
|
||||
scene.accent(accent == 0 ? AppRepository.color(a.pkg) : accent, motion());
|
||||
updateFeaturedText();
|
||||
if ((p.contains("plex") || p.contains("plezy")) && plexFeatured != null) featurePlexArtwork();
|
||||
if (plexApp && plexFeatured != null) featurePlexArtwork();
|
||||
}
|
||||
|
||||
private void launch(AppRepository.App a) {
|
||||
|
|
@ -1448,7 +1477,7 @@ public final class MainActivity extends Activity {
|
|||
null,
|
||||
() -> {
|
||||
prefs.edit().putString("scene", v).apply();
|
||||
scene.setMediaArt(null);
|
||||
clearFeaturedArtwork();
|
||||
configureScene();
|
||||
appearance();
|
||||
});
|
||||
|
|
@ -1642,7 +1671,7 @@ public final class MainActivity extends Activity {
|
|||
() -> {
|
||||
plex.disconnect();
|
||||
plexFeatured = null;
|
||||
scene.setMediaArt(null);
|
||||
clearFeaturedArtwork();
|
||||
prefs.edit().putBoolean("media", false).apply();
|
||||
mediaContainer.removeAllViews();
|
||||
plexSettings();
|
||||
|
|
@ -1689,6 +1718,8 @@ public final class MainActivity extends Activity {
|
|||
handler.post(
|
||||
() -> {
|
||||
if (currentDialog != dialog || !foreground) return;
|
||||
clearFeaturedArtwork();
|
||||
plexFeatured = null;
|
||||
prefs.edit().putBoolean("media", true).apply();
|
||||
dismiss();
|
||||
loadMedia();
|
||||
|
|
@ -1782,6 +1813,8 @@ public final class MainActivity extends Activity {
|
|||
handler.post(
|
||||
() -> {
|
||||
if (currentDialog != dialog || !foreground) return;
|
||||
clearFeaturedArtwork();
|
||||
plexFeatured = null;
|
||||
prefs.edit().putBoolean("media", true).apply();
|
||||
dismiss();
|
||||
loadMedia();
|
||||
|
|
@ -1897,10 +1930,37 @@ public final class MainActivity extends Activity {
|
|||
featureArtwork(plexFeatured.art);
|
||||
}
|
||||
|
||||
private void cancelArtworkRequest() {
|
||||
artGeneration++;
|
||||
if (artworkTask != null) handler.removeCallbacks(artworkTask);
|
||||
artworkTask = null;
|
||||
requestedArtPath = "";
|
||||
}
|
||||
|
||||
private void clearFeaturedArtwork() {
|
||||
cancelArtworkRequest();
|
||||
displayedArtPath = "";
|
||||
scene.setMediaArt(null);
|
||||
}
|
||||
|
||||
private void featureArtwork(String path) {
|
||||
final int g = generation, art = ++artGeneration;
|
||||
handler.postDelayed(
|
||||
if (!foreground) return;
|
||||
if (path == null || path.isEmpty()) {
|
||||
clearFeaturedArtwork();
|
||||
return;
|
||||
}
|
||||
if (path.equals(displayedArtPath) && scene.hasMediaArt()) {
|
||||
// Cancel a different pending selection without clearing an already displayed image.
|
||||
if (!requestedArtPath.isEmpty()) cancelArtworkRequest();
|
||||
return;
|
||||
}
|
||||
if (path.equals(requestedArtPath)) return;
|
||||
cancelArtworkRequest();
|
||||
requestedArtPath = path;
|
||||
final int g = generation, art = artGeneration;
|
||||
artworkTask =
|
||||
() -> {
|
||||
artworkTask = null;
|
||||
if (!foreground || g != generation || art != artGeneration) return;
|
||||
network.execute(
|
||||
() -> {
|
||||
|
|
@ -1908,12 +1968,16 @@ public final class MainActivity extends Activity {
|
|||
Bitmap bitmap = plex.image(path, true);
|
||||
handler.post(
|
||||
() -> {
|
||||
if (foreground && g == generation && art == artGeneration)
|
||||
if (!foreground || g != generation || art != artGeneration) return;
|
||||
requestedArtPath = "";
|
||||
if (bitmap != null) {
|
||||
displayedArtPath = path;
|
||||
scene.setMediaArt(bitmap);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
180);
|
||||
};
|
||||
handler.postDelayed(artworkTask, 180);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue