added dynamic menus capability
added note to user for possibly hanging sync
fixed sync button when accessed from ConfigureSyncView
This commit is contained in:
memen45
2020-12-14 16:03:21 +01:00
parent 7df197821c
commit 783737cd26
8 changed files with 139 additions and 82 deletions

View File

@@ -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

View File

@@ -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 + " )");

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -12,33 +12,74 @@ 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(); }
}
}
}

View File

@@ -15,7 +15,8 @@ module SubMusic {
MANAGE_PLAYLISTS,
PLAYLIST_DETAIL,
}
var items = {
function getItems() {
return {
TEST_SERVER => {
LABEL => Rez.Strings.confSync_MoreInfo_TestServer_label,
SUBLABEL => null,
@@ -37,6 +38,7 @@ module SubMusic {
METHOD => method(:onRemoveAll),
},
};
}
function onTestServer() {
WatchUi.pushView(new SubMusicTestView(), new WatchUi.BehaviorDelegate(), WatchUi.SLIDE_IMMEDIATE);

View File

@@ -11,7 +11,9 @@ module SubMusic {
OPEN_SYNC,
DONATE,
}
var items = {
function getItems() {
return {
SELECT_PLAYLIST => {
LABEL => Rez.Strings.confPlayback_SelectPlaylist_label,
SUBLABEL => null,
@@ -28,14 +30,15 @@ module SubMusic {
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() {

View File

@@ -13,7 +13,9 @@ module SubMusic {
START_SYNC,
MORE_INFO,
}
var items = {
function getItems() {
return {
SELECT_PLAYLISTS => {
LABEL => Rez.Strings.confSync_SelectPlaylists_label,
SUBLABEL => null,
@@ -30,11 +32,6 @@ module SubMusic {
METHOD => method(:onMoreInfo),
},
};
private var d_syncauto;
function initialize(syncauto) {
d_syncauto = syncauto;
}
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());
}
}
}