Skip to content

Commit

Permalink
Lower memory usage + smoother screen transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Digimezzo Raphaël committed Aug 5, 2021
1 parent 04f76c9 commit 39f6bc3
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 41 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.0-preview.3] - 2021-07-24
## [3.0.0-preview.3] - 2021-08-05

### Added

- Pressing the ENTER key pauses and resumes playback
- Clicking on the album cover of the currently playing song, opens the "Now playing" screen.
- Added now playing background
- Smoother transitions between screens
- Lower memory usage

### Changed

Expand Down
3 changes: 2 additions & 1 deletion src/app/common/application/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export class Constants {

public static readonly albumSizeInPixels: number = 120;
public static readonly albumMarginInPixels: number = 8;
public static readonly listLoadDelayMilliseconds: number = 50;
public static readonly longListLoadDelayMilliseconds: number = 500;
public static readonly shortListLoadDelayMilliseconds: number = 50;
public static readonly albumsRedrawDelayMilliseconds: number = 150;

public static readonly fontSizes: FontSize[] = [new FontSize(12), new FontSize(13), new FontSize(14), new FontSize(15)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { BaseIndexingService } from '../../../services/indexing/base-indexing.se
import { BaseTrackService } from '../../../services/track/base-track.service';
import { TrackModels } from '../../../services/track/track-models';
import { AlbumOrder } from '../album-order';
import { CollectionPersister } from '../collection-persister';
import { CollectionTab } from '../collection-tab';
import { AlbumsAlbumsPersister } from './albums-albums-persister';
import { AlbumsTracksPersister } from './albums-tracks-persister';

Expand All @@ -26,6 +28,7 @@ export class CollectionAlbumsComponent implements OnInit, OnDestroy {
constructor(
public albumsPersister: AlbumsAlbumsPersister,
public tracksPersister: AlbumsTracksPersister,
private collectionPersister: CollectionPersister,
private indexingService: BaseIndexingService,
private albumService: BaseAlbumService,
private trackService: BaseTrackService,
Expand All @@ -50,8 +53,7 @@ export class CollectionAlbumsComponent implements OnInit, OnDestroy {

public ngOnDestroy(): void {
this.subscription.unsubscribe();
this.albums = [];
this.tracks = new TrackModels();
this.clearLists();
}

public async ngOnInit(): Promise<void> {
Expand All @@ -63,29 +65,51 @@ export class CollectionAlbumsComponent implements OnInit, OnDestroy {

this.subscription.add(
this.indexingService.indexingFinished$.subscribe(() => {
this.fillListsAsync();
this.processListsAsync();
})
);

this.subscription.add(
this.collectionPersister.selectedTabChanged$.subscribe(() => {
this.processListsAsync();
})
);

this.selectedAlbumOrder = this.albumsPersister.getSelectedAlbumOrder();
await this.fillListsAsync();
await this.processListsAsync();
}

public splitDragEnd(event: any): void {
this.settings.albumsRightPaneWidthPercent = event.sizes[1];
}

private async processListsAsync(): Promise<void> {
if (this.collectionPersister.selectedTab === CollectionTab.albums) {
await this.fillListsAsync();
} else {
this.clearLists();
}
}

private async fillListsAsync(): Promise<void> {
await this.scheduler.sleepAsync(Constants.listLoadDelayMilliseconds);
await this.scheduler.sleepAsync(Constants.longListLoadDelayMilliseconds);

try {
await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getAlbums();

await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getTracks();
} catch (e) {
this.logger.error(`Could not fill lists. Error: ${e.message}`, 'CollectionAlbumsComponent', 'fillLists');
}
}

private clearLists(): void {
this.albums = [];
this.tracks = new TrackModels();
}

private getAlbums(): void {
this.albums = this.albumService.getAllAlbums();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { BaseIndexingService } from '../../../services/indexing/base-indexing.se
import { BaseTrackService } from '../../../services/track/base-track.service';
import { TrackModels } from '../../../services/track/track-models';
import { AlbumOrder } from '../album-order';
import { CollectionPersister } from '../collection-persister';
import { CollectionTab } from '../collection-tab';
import { ArtistsAlbumsPersister } from './artists-albums-persister';
import { ArtistsPersister } from './artists-persister';
import { ArtistsTracksPersister } from './artists-tracks-persister';
Expand All @@ -31,6 +33,7 @@ export class CollectionArtistsComponent implements OnInit, OnDestroy {
public artistsPersister: ArtistsPersister,
public albumsPersister: ArtistsAlbumsPersister,
public tracksPersister: ArtistsTracksPersister,
private collectionPersister: CollectionPersister,
private indexingService: BaseIndexingService,
private artistService: BaseArtistService,
private albumService: BaseAlbumService,
Expand Down Expand Up @@ -58,9 +61,7 @@ export class CollectionArtistsComponent implements OnInit, OnDestroy {

public ngOnDestroy(): void {
this.subscription.unsubscribe();
this.artists = [];
this.albums = [];
this.tracks = new TrackModels();
this.clearLists();
}

public async ngOnInit(): Promise<void> {
Expand All @@ -87,31 +88,56 @@ export class CollectionArtistsComponent implements OnInit, OnDestroy {

this.subscription.add(
this.indexingService.indexingFinished$.subscribe(() => {
this.fillListsAsync();
this.processListsAsync();
})
);

this.subscription.add(
this.collectionPersister.selectedTabChanged$.subscribe(() => {
this.processListsAsync();
})
);

this.selectedAlbumOrder = this.albumsPersister.getSelectedAlbumOrder();
await this.fillListsAsync();
await this.processListsAsync();
}

public splitDragEnd(event: any): void {
this.settings.artistsLeftPaneWidthPercent = event.sizes[0];
this.settings.artistsRightPaneWidthPercent = event.sizes[2];
}

private async processListsAsync(): Promise<void> {
if (this.collectionPersister.selectedTab === CollectionTab.artists) {
await this.fillListsAsync();
} else {
this.clearLists();
}
}

private async fillListsAsync(): Promise<void> {
await this.scheduler.sleepAsync(Constants.listLoadDelayMilliseconds);
await this.scheduler.sleepAsync(Constants.longListLoadDelayMilliseconds);

try {
await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getArtists();

await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getAlbums();

await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getTracks();
} catch (e) {
this.logger.error(`Could not fill lists. Error: ${e.message}`, 'CollectionArtistsComponent', 'fillLists');
}
}

private clearLists(): void {
this.artists = [];
this.albums = [];
this.tracks = new TrackModels();
}

private getArtists(): void {
const selectedArtistType: ArtistType = this.artistsPersister.getSelectedArtistType();
this.artists = this.artistService.getArtists(selectedArtistType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="side-pane">
<div class="folder-browser p-3">
<!-- Folders in collection -->
<div *ngIf="folders.length > 0" class="folder-browser__header m-1">
<div *ngIf="this.folderService.collectionHasFolders" class="folder-browser__header m-1">
<div class="folder-browser__title no-select">{{ 'folder' | translate }}</div>
<div
mat-icon-button
Expand Down Expand Up @@ -41,7 +41,7 @@
</div>
</cdk-virtual-scroll-viewport>
<!-- No folders in collection -->
<div class="folder-browser__message" *ngIf="folders.length === 0">
<div class="folder-browser__message" *ngIf="!this.folderService.collectionHasFolders">
{{ 'no-folders-in-collection' | translate }}
<button class="mt-3" mat-raised-button color="primary" (click)="goToManageCollection()">
{{ 'add-folder' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { PlaybackStarted } from '../../../services/playback/playback-started';
import { BaseTrackService } from '../../../services/track/base-track.service';
import { TrackModel } from '../../../services/track/track-model';
import { TrackModels } from '../../../services/track/track-models';
import { CollectionPersister } from '../collection-persister';
import { CollectionTab } from '../collection-tab';
import { FoldersPersister } from './folders-persister';

@Component({
Expand All @@ -28,10 +30,11 @@ import { FoldersPersister } from './folders-persister';
})
export class CollectionFoldersComponent implements OnInit, OnDestroy {
constructor(
private indexingService: BaseIndexingService,
public folderService: BaseFolderService,
public playbackService: BasePlaybackService,
private indexingService: BaseIndexingService,
private collectionPersister: CollectionPersister,
private settings: BaseSettings,
private folderService: BaseFolderService,
private navigationService: BaseNavigationService,
private trackService: BaseTrackService,
private playbackIndicationService: BasePlaybackIndicationService,
Expand All @@ -56,11 +59,10 @@ export class CollectionFoldersComponent implements OnInit, OnDestroy {

public ngOnDestroy(): void {
this.subscription.unsubscribe();
this.clearLists();
}

public async ngOnInit(): Promise<void> {
await this.fillListsAsync();

this.subscription.add(
this.playbackService.playbackStarted$.subscribe((playbackStarted: PlaybackStarted) => {
this.playbackIndicationService.setPlayingSubfolder(this.subfolders, playbackStarted.currentTrack);
Expand All @@ -77,9 +79,17 @@ export class CollectionFoldersComponent implements OnInit, OnDestroy {

this.subscription.add(
this.indexingService.indexingFinished$.subscribe(() => {
this.fillListsAsync();
this.processListsAsync();
})
);

this.subscription.add(
this.collectionPersister.selectedTabChanged$.subscribe(() => {
this.processListsAsync();
})
);

await this.processListsAsync();
}

public splitDragEnd(event: any): void {
Expand Down Expand Up @@ -140,14 +150,30 @@ export class CollectionFoldersComponent implements OnInit, OnDestroy {
this.navigationService.navigateToManageCollection();
}

private async processListsAsync(): Promise<void> {
if (this.collectionPersister.selectedTab === CollectionTab.folders) {
await this.fillListsAsync();
} else {
this.clearLists();
}
}

private async fillListsAsync(): Promise<void> {
await this.scheduler.sleepAsync(Constants.listLoadDelayMilliseconds);
await this.scheduler.sleepAsync(Constants.longListLoadDelayMilliseconds);
this.getFolders();

await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
const persistedOpenedFolder: FolderModel = this.foldersPersister.getOpenedFolder(this.folders);
await this.setOpenedFolderAsync(persistedOpenedFolder);
}

private clearLists(): void {
this.folders = [];
this.subfolders = [];
this.subfolderBreadCrumbs = [];
this.tracks = new TrackModels();
}

private getOpenedSubfolderPath(): string {
return this.subfolders.length > 0 && this.subfolders.some((x) => x.isGoToParent)
? this.subfolders.filter((x) => x.isGoToParent)[0].path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { BaseIndexingService } from '../../../services/indexing/base-indexing.se
import { BaseTrackService } from '../../../services/track/base-track.service';
import { TrackModels } from '../../../services/track/track-models';
import { AlbumOrder } from '../album-order';
import { CollectionPersister } from '../collection-persister';
import { CollectionTab } from '../collection-tab';
import { GenresAlbumsPersister } from './genres-albums-persister';
import { GenresPersister } from './genres-persister';
import { GenresTracksPersister } from './genres-tracks-persister';
Expand All @@ -30,6 +32,7 @@ export class CollectionGenresComponent implements OnInit, OnDestroy {
public genresPersister: GenresPersister,
public albumsPersister: GenresAlbumsPersister,
public tracksPersister: GenresTracksPersister,
private collectionPersister: CollectionPersister,
private indexingService: BaseIndexingService,
private genreService: BaseGenreService,
private albumService: BaseAlbumService,
Expand Down Expand Up @@ -57,9 +60,7 @@ export class CollectionGenresComponent implements OnInit, OnDestroy {

public ngOnDestroy(): void {
this.subscription.unsubscribe();
this.genres = [];
this.albums = [];
this.tracks = new TrackModels();
this.clearLists();
}

public async ngOnInit(): Promise<void> {
Expand All @@ -79,31 +80,56 @@ export class CollectionGenresComponent implements OnInit, OnDestroy {

this.subscription.add(
this.indexingService.indexingFinished$.subscribe(async () => {
await this.fillListsAsync();
await this.processListsAsync();
})
);

this.subscription.add(
this.collectionPersister.selectedTabChanged$.subscribe(() => {
this.processListsAsync();
})
);

this.selectedAlbumOrder = this.albumsPersister.getSelectedAlbumOrder();
await this.fillListsAsync();
await this.processListsAsync();
}

public splitDragEnd(event: any): void {
this.settings.genresLeftPaneWidthPercent = event.sizes[0];
this.settings.genresRightPaneWidthPercent = event.sizes[2];
}

private async processListsAsync(): Promise<void> {
if (this.collectionPersister.selectedTab === CollectionTab.genres) {
await this.fillListsAsync();
} else {
this.clearLists();
}
}

private async fillListsAsync(): Promise<void> {
await this.scheduler.sleepAsync(Constants.listLoadDelayMilliseconds);
await this.scheduler.sleepAsync(Constants.longListLoadDelayMilliseconds);

try {
await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getGenres();

await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getAlbums();

await this.scheduler.sleepAsync(Constants.shortListLoadDelayMilliseconds);
this.getTracks();
} catch (e) {
this.logger.error(`Could not fill lists. Error: ${e.message}`, 'CollectionGenresComponent', 'fillLists');
}
}

private clearLists(): void {
this.genres = [];
this.albums = [];
this.tracks = new TrackModels();
}

private getGenres(): void {
this.genres = this.genreService.getGenres();
}
Expand Down
Loading

0 comments on commit 39f6bc3

Please sign in to comment.