diff --git a/changelog.md b/changelog.md index 7967049..1b97fac 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ Version [] - - (tentative) added support for updating play count to server (scrobble/record_play) Version [0.0.23] - 2020-12- +- update last sync in menu - refactor in menus - fixes potential ampache crash diff --git a/source/SongStore.mc b/source/SongStore.mc index def5148..7447174 100644 --- a/source/SongStore.mc +++ b/source/SongStore.mc @@ -21,8 +21,8 @@ class Id { module SongStore { - var d_songs = new ObjectStore(Storage.SONGS); - var d_delete = new ArrayStore(Storage.SONGS_DELETE); + var d_songs = new ObjectStore(Storage.SONGS); // allows fast indexing by id + var d_delete = new ArrayStore(Storage.SONGS_DELETE); // allows fast access function get(id) { System.println("SongStore::get( id : " + id + " )"); diff --git a/source/SubMusicApp.mc b/source/SubMusicApp.mc index ffeaadf..961bd4b 100644 --- a/source/SubMusicApp.mc +++ b/source/SubMusicApp.mc @@ -15,10 +15,12 @@ class SubMusicApp extends Application.AudioContentProviderApp { // onStart() is called on application start up function onStart(state) { + System.println("Start with state: " + state); } // onStop() is called when your application is exiting function onStop(state) { + System.println("Stop with state: " + state); } function onSettingsChanged() { @@ -30,6 +32,7 @@ class SubMusicApp extends Application.AudioContentProviderApp { // Get a Media.ContentDelegate for use by the system to get and iterate through media on the device function getContentDelegate(arg) { + System.println("getContentDelegate with arg: " + arg); return new SubMusicContentDelegate(); } @@ -40,11 +43,20 @@ class SubMusicApp extends Application.AudioContentProviderApp { // Get the initial view for configuring playback function getPlaybackConfigurationView() { - return [ new SubMusic.Menu.PlaybackView(), new SubMusic.Menu.Delegate() ]; + return [ new SubMusic.Menu.PlaybackView(), new SubMusic.Menu.Delegate(null) ]; } // Get the initial view for configuring sync function getSyncConfigurationView() { - return [ new SubMusic.Menu.SyncView(true), new SubMusic.Menu.Delegate() ]; + return [ new SubMusic.Menu.SyncView(), new SubMusic.Menu.Delegate(method(:onBack)) ]; // show note on exit + } + + function onBack() { + var msg = "Note: \"Start syncing music\" might not complete on this device"; + WatchUi.switchToView(new TextView(msg), new TapDelegate(method(:popView)), WatchUi.SLIDE_IMMEDIATE); + } + + function popView() { + WatchUi.popView(WatchUi.SLIDE_IMMEDIATE); } } diff --git a/source/View/SubMusicConfirmationDelegate.mc b/source/View/SubMusicConfirmationDelegate.mc index ba3798f..5cb1874 100644 --- a/source/View/SubMusicConfirmationDelegate.mc +++ b/source/View/SubMusicConfirmationDelegate.mc @@ -11,9 +11,11 @@ class SubMusicConfirmationDelegate extends WatchUi.ConfirmationDelegate { } function onResponse(response) { - if (response != WatchUi.CONFIRM_YES) { + if ((d_callback == null) + || (response == WatchUi.CONFIRM_NO)) { return; } + d_callback.invoke(); } } \ No newline at end of file diff --git a/source/View/SubMusicMenu.mc b/source/View/SubMusicMenu.mc index 7ffe174..0fd608c 100644 --- a/source/View/SubMusicMenu.mc +++ b/source/View/SubMusicMenu.mc @@ -11,34 +11,75 @@ module SubMusic { } class MenuView extends WatchUi.Menu2 { + + private var d_menu; + private var d_created = false; // menu not created yet function initialize(menu) { Menu2.initialize({:title => menu.title}); - var items = menu.items.keys().size(); - for (var idx = 0; idx != items; ++idx) { - addItem(new WatchUi.MenuItem( - menu.items[idx][LABEL], // label - menu.items[idx][SUBLABEL], // sublabel - menu.items[idx][METHOD], // identifier (use method for simple callback) - null // options - )); + d_menu = menu; + } + + // update the created menu with new values + function updateMenu(items) { + for (var idx = 0; idx != items.keys().size(); ++idx) { + updateItem(makeMenuItem(items[idx]), idx); } + } + + // create the menu by adding the items + function createMenu(items) { + for (var idx = 0; idx != items.keys().size(); ++idx) { + addItem(makeMenuItem(items[idx])); + } + } + + // returns a WatchUi.MenuItem from object + function makeMenuItem(item) { + return new WatchUi.MenuItem( + item[LABEL], // label + item[SUBLABEL], // sublabel + item[METHOD], // identifier (use method for simple callback) + null // options + ); + } + + function onShow() { + + var items = d_menu.getItems(); + if (d_created) { + System.println("MenuView::onShow(update)"); + setTitle(d_menu.title); + updateMenu(items); + return; + } + + // create menu and indicate created + System.println("MenuView::onShow(create)"); + createMenu(items); + d_created = true; } } class Delegate extends WatchUi.Menu2InputDelegate { - function initialize() { + private var d_callback; // callback on Back + + function initialize(callback) { Menu2InputDelegate.initialize(); + + d_callback = callback; } function onSelect(item) { item.getId().invoke(); } - // optional: function onBack() to close the menu properly + function onBack() { + if (d_callback) { d_callback.invoke(); } + } } } diff --git a/source/View/SubMusicMenuMore.mc b/source/View/SubMusicMenuMore.mc index 08fa834..befff51 100644 --- a/source/View/SubMusicMenuMore.mc +++ b/source/View/SubMusicMenuMore.mc @@ -15,28 +15,30 @@ module SubMusic { MANAGE_PLAYLISTS, PLAYLIST_DETAIL, } - var items = { - TEST_SERVER => { - LABEL => Rez.Strings.confSync_MoreInfo_TestServer_label, - SUBLABEL => null, - METHOD => method(:onTestServer), - }, - SERVER_DETAIL => { - LABEL => Rez.Strings.confSync_MoreInfo_ServerDetail_label, - SUBLABEL => Rez.Strings.confSync_MoreInfo_ServerDetail_sublabel, - METHOD => method(:onServerDetail), - }, - DONATE => { - LABEL => Rez.Strings.Donate_label, - SUBLABEL => null, - METHOD => method(:onDonate), - }, - REMOVE_ALL => { - LABEL => Rez.Strings.confSync_MoreInfo_RemoveAll_label, - SUBLABEL => Rez.Strings.confSync_MoreInfo_RemoveAll_sublabel, - METHOD => method(:onRemoveAll), - }, - }; + function getItems() { + return { + TEST_SERVER => { + LABEL => Rez.Strings.confSync_MoreInfo_TestServer_label, + SUBLABEL => null, + METHOD => method(:onTestServer), + }, + SERVER_DETAIL => { + LABEL => Rez.Strings.confSync_MoreInfo_ServerDetail_label, + SUBLABEL => Rez.Strings.confSync_MoreInfo_ServerDetail_sublabel, + METHOD => method(:onServerDetail), + }, + DONATE => { + LABEL => Rez.Strings.Donate_label, + SUBLABEL => null, + METHOD => method(:onDonate), + }, + REMOVE_ALL => { + LABEL => Rez.Strings.confSync_MoreInfo_RemoveAll_label, + SUBLABEL => Rez.Strings.confSync_MoreInfo_RemoveAll_sublabel, + METHOD => method(:onRemoveAll), + }, + }; + } function onTestServer() { WatchUi.pushView(new SubMusicTestView(), new WatchUi.BehaviorDelegate(), WatchUi.SLIDE_IMMEDIATE); diff --git a/source/View/SubMusicMenuPlayback.mc b/source/View/SubMusicMenuPlayback.mc index f6258d5..2ac6c67 100644 --- a/source/View/SubMusicMenuPlayback.mc +++ b/source/View/SubMusicMenuPlayback.mc @@ -10,32 +10,35 @@ module SubMusic { SELECT_PLAYLIST, OPEN_SYNC, DONATE, - } - var items = { - SELECT_PLAYLIST => { - LABEL => Rez.Strings.confPlayback_SelectPlaylist_label, - SUBLABEL => null, - METHOD => method(:onSelectPlaylist), - }, - OPEN_SYNC => { - LABEL => Rez.Strings.confPlayback_OpenSync_label, - SUBLABEL => null, - METHOD => method(:onOpenSync), - }, - DONATE => { - LABEL => Rez.Strings.Donate_label, - SUBLABEL => null, - METHOD => method(:onDonate), - }, - }; + } + + function getItems() { + return { + SELECT_PLAYLIST => { + LABEL => Rez.Strings.confPlayback_SelectPlaylist_label, + SUBLABEL => null, + METHOD => method(:onSelectPlaylist), + }, + OPEN_SYNC => { + LABEL => Rez.Strings.confPlayback_OpenSync_label, + SUBLABEL => null, + METHOD => method(:onOpenSync), + }, + DONATE => { + LABEL => Rez.Strings.Donate_label, + SUBLABEL => null, + METHOD => method(:onDonate), + }, + }; + } function onSelectPlaylist() { WatchUi.pushView(new SubMusicConfigurePlaybackPlaylistView(), null, WatchUi.SLIDE_IMMEDIATE); } function onOpenSync() { - // pass false to indicate we are coming from another sync flow than normal - WatchUi.pushView(new SubMusic.Menu.SyncView(false), new SubMusic.Menu.Delegate(), WatchUi.SLIDE_IMMEDIATE); + // nothing to do on menu exit, so null + WatchUi.pushView(new SubMusic.Menu.SyncView(), new SubMusic.Menu.Delegate(null), WatchUi.SLIDE_IMMEDIATE); } function onDonate() { diff --git a/source/View/SubMusicMenuSync.mc b/source/View/SubMusicMenuSync.mc index 9326f11..6484fa2 100644 --- a/source/View/SubMusicMenuSync.mc +++ b/source/View/SubMusicMenuSync.mc @@ -13,28 +13,25 @@ module SubMusic { START_SYNC, MORE_INFO, } - var items = { - SELECT_PLAYLISTS => { - LABEL => Rez.Strings.confSync_SelectPlaylists_label, - SUBLABEL => null, - METHOD => method(:onSelectPlaylists), - }, - START_SYNC => { - LABEL => Rez.Strings.confSync_StartSync_label, - SUBLABEL => getLastSyncString(), - METHOD => method(:onStartSync), - }, - MORE_INFO => { - LABEL => Rez.Strings.confSync_MoreInfo_label, - SUBLABEL => null, - METHOD => method(:onMoreInfo), - }, - }; - private var d_syncauto; - - function initialize(syncauto) { - d_syncauto = syncauto; + function getItems() { + return { + SELECT_PLAYLISTS => { + LABEL => Rez.Strings.confSync_SelectPlaylists_label, + SUBLABEL => null, + METHOD => method(:onSelectPlaylists), + }, + START_SYNC => { + LABEL => Rez.Strings.confSync_StartSync_label, + SUBLABEL => getLastSyncString(), + METHOD => method(:onStartSync), + }, + MORE_INFO => { + LABEL => Rez.Strings.confSync_MoreInfo_label, + SUBLABEL => null, + METHOD => method(:onMoreInfo), + }, + }; } function getLastSyncString() { @@ -53,8 +50,7 @@ module SubMusic { } function onStartSync() { - if (!d_syncauto) { Communications.startSync(); } - else { WatchUi.popView(WatchUi.SLIDE_IMMEDIATE); } + Communications.startSync(); } function onMoreInfo() { @@ -63,8 +59,8 @@ module SubMusic { } class SyncView extends MenuView { - function initialize(syncauto) { - MenuView.initialize(new Sync(syncauto)); + function initialize() { + MenuView.initialize(new Sync()); } } }