gestione comunità
This commit is contained in:
@@ -11,6 +11,8 @@ import { ConnectivityService } from '../../services/connectivity.service';
|
||||
import { PlaylistService } from '../../services/playlist.service';
|
||||
import { YoutubePlayerService } from '../../services/youtube-player.service';
|
||||
import { MyCantiService } from '../../services/my-canti.service';
|
||||
import { ComunitaService } from '../../services/comunita.service';
|
||||
import { StatsService } from '../../services/stats.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-player',
|
||||
@@ -103,11 +105,15 @@ export class PlayerPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
public settingsService = inject(SettingsService);
|
||||
public connectivityService = inject(ConnectivityService);
|
||||
public playlistService = inject(PlaylistService);
|
||||
public comunitaService = inject(ComunitaService);
|
||||
private myCantiService = inject(MyCantiService);
|
||||
private statsService = inject(StatsService);
|
||||
private gestureCtrl = inject(GestureController);
|
||||
private el = inject(ElementRef);
|
||||
private sanitizer = inject(DomSanitizer);
|
||||
|
||||
private songStartTime: number = 0;
|
||||
|
||||
constructor() {
|
||||
// Sync mode from global settings
|
||||
effect(() => {
|
||||
@@ -195,9 +201,24 @@ export class PlayerPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
if (found) {
|
||||
this.logPreviousSongTime();
|
||||
this.canto.set(found);
|
||||
this.songStartTime = Date.now();
|
||||
this.cantiService.getStorage()?.set('last_song_id', id);
|
||||
this.channel.postMessage({ type: 'SYNC_CANTO', id: found.id });
|
||||
|
||||
// Set custom community transposition if active
|
||||
if (this.comunitaService.comunitaCode() && this.comunitaService.isFilterActive()) {
|
||||
const settings = this.comunitaService.comunitaCantiSettings();
|
||||
const songSetting = settings.find(s => s.id_canti === found.id_canti || s.id_canti === Number(found.id));
|
||||
if (songSetting && songSetting.tonalita !== undefined) {
|
||||
this.transposeAmount.set(songSetting.tonalita);
|
||||
} else {
|
||||
this.transposeAmount.set(0);
|
||||
}
|
||||
} else {
|
||||
this.transposeAmount.set(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -243,11 +264,21 @@ export class PlayerPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
transposeUp() {
|
||||
this.transposeAmount.update(v => v + 1);
|
||||
this.channel.postMessage({ type: 'SYNC_TRANSPOSE', amount: this.transposeAmount() });
|
||||
|
||||
const c = this.canto();
|
||||
if (c) {
|
||||
this.statsService.updateSongSettings(c.id_canti, this.transposeAmount());
|
||||
}
|
||||
}
|
||||
|
||||
transposeDown() {
|
||||
this.transposeAmount.update(v => v - 1);
|
||||
this.channel.postMessage({ type: 'SYNC_TRANSPOSE', amount: this.transposeAmount() });
|
||||
|
||||
const c = this.canto();
|
||||
if (c) {
|
||||
this.statsService.updateSongSettings(c.id_canti, this.transposeAmount());
|
||||
}
|
||||
}
|
||||
|
||||
zoomIn() {
|
||||
@@ -485,7 +516,25 @@ export class PlayerPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
getCommunitySongNumber(canto: any): string | null {
|
||||
if (!canto) return null;
|
||||
if (!this.comunitaService.comunitaCode() || !this.comunitaService.isFilterActive()) return null;
|
||||
const cantiInfo = this.comunitaService.comunitaCantiInfo();
|
||||
const info = cantiInfo.find(x => x.id_canti === canto.id_canti || x.id_canti === Number(canto.id));
|
||||
return info && info.num_canto ? info.num_canto.toString() : null;
|
||||
}
|
||||
|
||||
private logPreviousSongTime() {
|
||||
const c = this.canto();
|
||||
if (c && this.songStartTime > 0) {
|
||||
const timeSpent = (Date.now() - this.songStartTime) / 1000;
|
||||
this.statsService.logSongView(c.id_canti, timeSpent);
|
||||
this.songStartTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.logPreviousSongTime();
|
||||
this.audioEngine.stopListening();
|
||||
this.channel.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user