Skip to content

Commit

Permalink
Added menu options (debug options)
Browse files Browse the repository at this point in the history
- fixed progressbar - only count songs that are not yet local
- fixed crash on sync empty playlist (progress divide by 0)
- fixed initial Sync setup (removed deprecated uses)
- fixed crashes on Error handling
- added last sync time record
- added support for descentmk2 device
  • Loading branch information
memen45 committed Dec 2, 2020
1 parent b06d715 commit f26e33d
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 84 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Version [0.0.20] - 2020-
- fixed progressbar - only count songs that are not yet local
- fixed crash on sync empty playlist (progress divide by 0)
- fixed initial Sync setup (removed deprecated methods)
- fixed crashes on Error handling
- fixed hot reloading of settings
- refactor of menus
- added last sync time record
- added support for descentmk2 device

Version [0.0.19] - 2020-11-20
- refactor of sync engine
- fixed stack overflow error (rare case)
Expand Down
3 changes: 2 additions & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="SubMusicApp" id="62436b93f69e4823a8b41854b6684b4a" launcherIcon="@Drawables.LauncherIcon" name="@Strings.AppName" type="audio-content-provider-app" version="0.0.19">
<iq:application entry="SubMusicApp" id="62436b93f69e4823a8b41854b6684b4a" launcherIcon="@Drawables.LauncherIcon" name="@Strings.AppName" type="audio-content-provider-app" version="0.0.20">
<iq:products>
<iq:product id="d2air"/>
<iq:product id="d2delta"/>
<iq:product id="d2deltapx"/>
<iq:product id="d2deltas"/>
<iq:product id="descentmk2"/>
<iq:product id="fenix5plus"/>
<iq:product id="fenix5splus"/>
<iq:product id="fenix5xplus"/>
Expand Down
4 changes: 4 additions & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<string id="confSync_ManagePlaylists_label">Manage Playlists</string>
<string id="confSync_DebugInfo_label">Debug Info</string>
<string id="confSync_DebugInfo_TestServer_label">Test Server</string>
<string id="confSync_DebugInfo_RemoveAll_label">Remove All</string>
<string id="confSync_DebugInfo_RemoveAll_sublabel">Reset application storage</string>
<string id="confSync_DebugInfo_ServerDetail_label">Server</string>
<string id="confSync_DebugInfo_ServerDetail_sublabel">Show server settings</string>
<string id="confSync_PlaylistDetail_label">Playlist Detail</string>
<string id="confSync_Test_start">Starting test...</string>

Expand Down
35 changes: 18 additions & 17 deletions source/PlaylistSync.mc
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,36 @@ class PlaylistSync extends Deferrable {
}

function onGetPlaylistSongs(songs) {
// count the total number of songs on this playlist
d_todo_total = songs.size();

// retrieve array of ids of non local songs
d_todo_songs = d_playlist.update(songs);

// update fallback
d_provider.setFallback(method(:onError));
// count the number of songs on this playlist that need a download
d_todo_total = d_todo_songs.size();

syncNextSong();
}

function syncNextSong() {
function progress() {
var done = d_todo_total - d_todo_songs.size();
var progress = (100 * done) / d_todo_total.toFloat();
f_progress.invoke(progress);
return progress;
}

function syncNextSong() {

// if songs not all finished, start the download
if (d_todo_songs.size() != 0) {
d_song = new ISong(d_todo_songs[0]);
d_provider.getRefId(d_song.id(), d_song.mime(), method(:onSongDownloaded));
// if songs all finished, complete this task
if (d_todo_songs.size() == 0) {
d_playlist.setSynced(!d_failed); // not failed = successful sync
Deferrable.complete(); // set complete
return;
}

// reset the fallback
d_provider.setFallback(method(:onError));

// all songs finished
d_playlist.setSynced(!d_failed); // not failed = successful sync
Deferrable.complete();
// update progress
f_progress.invoke(progress());
// start download
d_song = new ISong(d_todo_songs[0]);
d_provider.getRefId(d_song.id(), d_song.mime(), method(:onSongDownloaded));
}

// Callback for when a song is downloaded
Expand Down
4 changes: 2 additions & 2 deletions source/SubMusicApp.mc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class SubMusicApp extends Application.AudioContentProviderApp {

// Get the initial view for configuring playback
function getPlaybackConfigurationView() {
return [ new SubMusicConfigurePlaybackView(), new WatchUi.BehaviorDelegate() ];
return [ new SubMusicConfigurePlaybackView(), new SubMusicConfigurePlaybackDelegate() ];
}

// Get the initial view for configuring sync
function getSyncConfigurationView() {
return [ new SubMusicConfigureSyncView(), new SubMusicConfigureSyncDelegate() ];
return [ new SubMusicConfigureSyncView(), new SubMusicConfigureSyncDelegate(true) ];
}
}
2 changes: 2 additions & 0 deletions source/SubMusicMenu.mc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module SyncMenu {
module SyncDebugMenu {
enum {
TEST_SERVER,
REMOVE_ALL,
SERVER_DETAIL,
LIST_ERRORS,
PLAYLIST_DETAIL,
}
Expand Down
9 changes: 4 additions & 5 deletions source/SubMusicSyncDelegate.mc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Toybox.Application;
using Toybox.Communications;
using Toybox.Media;
using Toybox.Time;

// Performs the sync with the music provider
class SubMusicSyncDelegate extends Media.SyncDelegate {
class SubMusicSyncDelegate extends Communications.SyncDelegate {

// playlists to sync
private var d_todo; // array of playlist ids
Expand All @@ -25,7 +24,7 @@ class SubMusicSyncDelegate extends Media.SyncDelegate {
System.println("Sync started...");

// show progress
Media.notifySyncProgress(0);
Communications.notifySyncProgress(0);

// starting sync
d_todo = PlaylistStore.getIds();
Expand All @@ -49,8 +48,8 @@ class SubMusicSyncDelegate extends Media.SyncDelegate {
System.println("Sync completed...");

// finish sync
Media.notifySyncComplete(null);
Communications.notifySyncComplete(null);
Application.Storage.setValue(Storage.LAST_SYNC, { "time" => Time.now().value(), });
return;
}

Expand All @@ -61,7 +60,7 @@ class SubMusicSyncDelegate extends Media.SyncDelegate {
progress /= d_loop.end().toFloat();

System.println(progress.toNumber());
Media.notifySyncProgress(progress.toNumber());
Communications.notifySyncProgress(progress.toNumber());
}

function step(idx) {
Expand Down
4 changes: 2 additions & 2 deletions source/SubMusicVersion.mc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class SubMusicVersion {

private var d_major = 0;
private var d_minor = 0;
private var d_patch = 19;
private var d_name = "tau";
private var d_patch = 20;
private var d_name = "upsilon";

function initialize(storage) {
if (storage == null) {
Expand Down
11 changes: 5 additions & 6 deletions source/View/SubMusicConfigurePlaybackDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ class SubMusicConfigurePlaybackDelegate extends WatchUi.BehaviorDelegate {

function initialize() {
BehaviorDelegate.initialize();

}

function onSelect(item) {

// store selection as current playlist
Application.Storage.setValue(Storage.PLAYLIST, item.getId());
Media.startPlayback(null);
function onSelect() {
// tap on the empty screen opens the sync menu
var view = new SubMusicConfigureSyncView();
var delegate = new SubMusicConfigureSyncDelegate(false);
WatchUi.switchToView(view, delegate, WatchUi.SLIDE_IMMEDIATE);
}

function onBack() {
Expand Down
43 changes: 11 additions & 32 deletions source/View/SubMusicConfigurePlaybackMenuDelegate.mc
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
using Toybox.Media;
using Toybox.WatchUi;

// Delegate for playback menu
class SubMusicConfigurePlaybackMenuDelegate extends WatchUi.Menu2InputDelegate {
class SubMusicConfigurePlaybackMenuDelegate extends WatchUi.BehaviorDelegate {

// Constructor
function initialize() {
Menu2InputDelegate.initialize();
BehaviorDelegate.initialize();

System.println("Constructing PlaybackMenuDelegate");
}

// When an item is selected, add or remove it from the system playlist
function onSelect(item) {

System.println("onSelect PlaybackMenuDelegate");
var playlist = Application.Storage.getValue(Storage.PLAYLIST);

if (playlist == null) {
playlist = [];
}

if (item.isChecked()) {
playlist.add(item.getId());
} else {
playlist.remove(item.getId());
}

Application.Storage.setValue(Storage.PLAYLIST, playlist);
function onSelect(item) {

// store selection as current playlist
Application.Storage.setValue(Storage.PLAYLIST, item.getId());
Media.startPlayback(null);
}

// Pop the view when done
function onDone() {
Media.startPlayback(null);
}

// Pop the view when back is pushed

function onBack() {
WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
}
}

}
4 changes: 2 additions & 2 deletions source/View/SubMusicConfigurePlaybackView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class SubMusicConfigurePlaybackView extends WatchUi.View {
}
if (empty)
{
d_msg = "No local playlists";
d_msg = "No local playlists\nTap to sync";
return;
}

WatchUi.pushView(menu, new SubMusicConfigurePlaybackDelegate(), WatchUi.SLIDE_IMMEDIATE);
WatchUi.pushView(menu, new SubMusicConfigurePlaybackMenuDelegate(), WatchUi.SLIDE_IMMEDIATE);
}

// Update the view
Expand Down
32 changes: 28 additions & 4 deletions source/View/SubMusicConfigureSyncDebugDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ using Toybox.Media;

class SubMusicConfigureSyncDebugDelegate extends WatchUi.Menu2InputDelegate {

private var d_provider;
private var d_provider = SubMusic.Provider.get();

function initialize(provider) {
function initialize() {
Menu2InputDelegate.initialize();

d_provider = provider;
}

function onSelect(item) {
Expand All @@ -24,8 +22,34 @@ class SubMusicConfigureSyncDebugDelegate extends WatchUi.Menu2InputDelegate {
WatchUi.pushView(new SubMusicPlaylistView(new Playlist(storage)), new WatchUi.BehaviorDelegate(), WatchUi.SLIDE_IMMEDIATE);
return;
}
if (SyncDebugMenu.SERVER_DETAIL == id) {
WatchUi.pushView(new SubMusicServerView(), new WatchUi.BehaviorDelegate(), WatchUi.SLIDE_IMMEDIATE);
return;
}
if (SyncDebugMenu.REMOVE_ALL == id) {
var msg = "Are you sure you want to delete all Application data?";
WatchUi.pushView(new WatchUi.Confirmation(msg), new SubMusicConfirmationDelegate(self.method(:onRemoveAll)), WatchUi.SLIDE_IMMEDIATE);
return;
}
WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
return;
}

function onRemoveAll() {
// collect all ids of songs
var ids = SongStore.getIds();
for (var idx = 0; idx != ids.size(); ++idx) {
var id = ids[idx];
var isong = new ISong(id);
isong.setRefId(null); // delete from cache
isong.remove(); // remove from Store
}

// remove all metadata
Application.Storage.clearValues();

// check storage to set the storage version number
Storage.check();
}

}
12 changes: 12 additions & 0 deletions source/View/SubMusicConfigureSyncDebugView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ class SubMusicConfigureSyncDebugView extends WatchUi.Menu2 {
function initialize() {
Menu2.initialize({:title=>Rez.Strings.confSync_DebugInfo_label});

addItem(new WatchUi.MenuItem(
Rez.Strings.confSync_DebugInfo_ServerDetail_label, // label
Rez.Strings.confSync_DebugInfo_ServerDetail_sublabel, // sublabel
SyncDebugMenu.SERVER_DETAIL, // identifier
null
));
addItem(new WatchUi.MenuItem(
Rez.Strings.confSync_DebugInfo_TestServer_label, // label
null, // sublabel
SyncDebugMenu.TEST_SERVER, // identifier
null
));
addItem(new WatchUi.MenuItem(
Rez.Strings.confSync_DebugInfo_RemoveAll_label, // label
Rez.Strings.confSync_DebugInfo_RemoveAll_sublabel, // sublabel
SyncDebugMenu.REMOVE_ALL, // identifier
null
));
}
}
20 changes: 10 additions & 10 deletions source/View/SubMusicConfigureSyncDelegate.mc
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using Toybox.WatchUi;
using Toybox.Media;

class SubMusicConfigureSyncDelegate extends WatchUi.Menu2InputDelegate {

private var d_provider;
private var d_syncauto; // set true if called from watch (sync will start w ith popview), false if called from anywhere else

function initialize(provider) {
function initialize(syncauto) {
Menu2InputDelegate.initialize();

d_provider = provider;
d_syncauto = syncauto;
}

function onSelect(item) {
var id = item.getId();

if (SyncMenu.SELECT_PLAYLISTS == id) {
WatchUi.pushView(new SubMusicConfigureSyncPlaylistView(d_provider), new WatchUi.BehaviorDelegate(), WatchUi.SLIDE_IMMEDIATE);
return;
}
if (SyncMenu.START_SYNC == id) {
WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
WatchUi.pushView(new SubMusicConfigureSyncPlaylistView(), new WatchUi.BehaviorDelegate(), WatchUi.SLIDE_IMMEDIATE);
return;
}
if (SyncMenu.DEBUG_INFO == id) {
WatchUi.pushView(new SubMusicConfigureSyncDebugView(), new SubMusicConfigureSyncDebugDelegate(d_provider), WatchUi.SLIDE_IMMEDIATE);
WatchUi.pushView(new SubMusicConfigureSyncDebugView(), new SubMusicConfigureSyncDebugDelegate(), WatchUi.SLIDE_IMMEDIATE);
return;
}

if ((SyncMenu.START_SYNC == id) && !d_syncauto) {
Communications.startSync();
}

WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
return;
}
Expand Down
5 changes: 2 additions & 3 deletions source/View/SubMusicConfigureSyncPlaylistView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ class SubMusicConfigureSyncPlaylistView extends WatchUi.View {

private var d_playlists = null;
private var d_menushown = false;
private var d_provider;
private var d_provider = SubMusic.Provider.get();

function initialize(provider) {
function initialize() {
View.initialize();

d_provider = provider;
d_provider.setFallback(method(:onError));
}

Expand Down
Loading

0 comments on commit f26e33d

Please sign in to comment.