mirror of
https://github.com/memen45/SubMusic.git
synced 2026-02-18 00:57:39 +01:00
fixes #9
added dynamic menus capability added note to user for possibly hanging sync fixed sync button when accessed from ConfigureSyncView
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 + " )");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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(); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user