Skip to content

Commit

Permalink
added app storage info in settings
Browse files Browse the repository at this point in the history
moved menu location of settings and about info
  • Loading branch information
memen45 committed Dec 26, 2022
1 parent a4d5dcf commit d347197
Show file tree
Hide file tree
Showing 23 changed files with 311 additions and 223 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Version [] -

Version [0.2.7] - 14-11-2022
Version [0.2.7] - 26-12-2022
- fixed podcast episode downloading on og subsonic and airsonic-advanced servers
- fixed progressbar during sync
- fixed title/artist showing when browsing online (subsonic, ampache)
- moved settings and about info
- added app storage info in settings

Version [0.2.6] - 19-10-2022
- added workaround for Plex' missing metadata
Expand Down
6 changes: 6 additions & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<string id="Browse_label">Browse</string>
<string id="More_label">More...</string>
<string id="About_label">About</string>
<string id="Settings_label">Settings</string>
<string id="AppSettings_label">App Settings</string>
<string id="Storage_label">Storage</string>
<string id="Version_label">Version</string>
<string id="Settings_label">Settings</string>

Expand Down Expand Up @@ -74,4 +77,7 @@
<string id="Menu_PodcastMode_label">Podcast Mode</string>
<string id="Menu_PodcastMode_sublabel">Stores play state</string>
<string id="Menu_Songs_label">Songs</string>

<string id="Memory_label">Memory</string>
<string id="Cache_label">Media cache</string>
</strings>
3 changes: 2 additions & 1 deletion source/Api/SubsonicAPI.mc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Toybox.System;
using Toybox.Lang;
using SubMusic;
using SubMusic.Utils;
using SubMusic.Storage;

// class for interfacing with a subsonic API endpoint
class SubsonicAPI extends Api {
Expand Down Expand Up @@ -270,7 +271,7 @@ class SubsonicAPI extends Api {

function updateAut(aut) {
// clear authentication headers
if (aut == ApiAuthMethod.API_AUTH) {
if (aut == Storage.ApiAuthMethod.API_AUTH) {
d_options = {};
return;
}
Expand Down
3 changes: 2 additions & 1 deletion source/Artwork.mc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Artwork extends Storable {
using SubMusic.Storage;

class Artwork extends Storable {

enum { SONG, ARTIST, ALBUM, PLAYLIST, SEARCH, PODCAST, END } // only add types at end, as these are stored
static private var s_types = [ "song", "artist", "album", "playlist", "search", "podcast" ];
Expand Down
1 change: 1 addition & 0 deletions source/Store/ArtworkStore.mc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Toybox.System;
using Toybox.Application;
using SubMusic.Storage;

/**
* module ArtworkStore
Expand Down
1 change: 1 addition & 0 deletions source/Store/EpisodeStore.mc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Toybox.System;
using Toybox.Application;
using SubMusic.Storage;

/**
* module EpisodeStore
Expand Down
1 change: 1 addition & 0 deletions source/Store/NowPlayingStore.mc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Toybox.Application;
using Toybox.System;
using SubMusic.Storage;

module SubMusic {
module PlayableStore {
Expand Down
2 changes: 2 additions & 0 deletions source/Store/PlaylistStore.mc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SubMusic.Storage;

module PlaylistStore {
var d_store = new ObjectStore(Storage.PLAYLISTS);

Expand Down
2 changes: 2 additions & 0 deletions source/Store/PodcastStore.mc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SubMusic.Storage;

module PodcastStore {
var d_store = new ObjectStore(Storage.PODCASTS);

Expand Down
2 changes: 2 additions & 0 deletions source/Store/ScrobbleStore.mc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using SubMusic.Storage;

module SubMusic {

class Scrobble {
Expand Down
1 change: 1 addition & 0 deletions source/Store/SongStore.mc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Toybox.System;
using Toybox.Application;
using SubMusic.Storage;

/**
* module SongStore
Expand Down
1 change: 1 addition & 0 deletions source/SubMusicApp.mc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Toybox.Application;
using Toybox.WatchUi;
using SubMusic.Menu;
using SubMusic.Storage;

class SubMusicApp extends Application.AudioContentProviderApp {

Expand Down
3 changes: 2 additions & 1 deletion source/SubMusicContentDelegate.mc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Toybox.Media;
using SubMusic;
using SubMusic.ScrobbleStore;

// This class handles events from the system's media
// player. getContentIterator() returns an iterator
Expand Down Expand Up @@ -81,7 +82,7 @@ class SubMusicContentDelegate extends Media.ContentDelegate {

if (songEvent == PLAYBACK_NOTIFY) {
// record a play
ScrobbleStore.add(new Scrobble({
ScrobbleStore.add(new SubMusic.Scrobble({
"id" => audio.id(),
}));
return;
Expand Down
186 changes: 94 additions & 92 deletions source/SubMusicStorage.mc
Original file line number Diff line number Diff line change
Expand Up @@ -15,119 +15,121 @@ module Storage_Deprecated {
}
}

module Storage {
enum {
PLAYABLE, // playable dictionary
module SubMusic {
module Storage {
enum {
PLAYABLE, // playable dictionary

SONGS, // dictionary where song id is key
SONGS_DELETE, // array of song ids of todelete songs (refCount == 0)
PLAYLISTS, // dictionary where playlist id is key

LAST_SYNC, // dictionary with details on last sync
SONGS, // dictionary where song id is key
SONGS_DELETE, // array of song ids of todelete songs (refCount == 0)
PLAYLISTS, // dictionary where playlist id is key
LAST_SYNC, // dictionary with details on last sync

PLAY_RECORDS, // array with play_record objects (scrobble)
PLAY_RECORDS, // array with play_record objects (scrobble)

SYNC_REQUEST, // stores boolean true if sync was requested by user
SYNC_REQUEST, // stores boolean true if sync was requested by user

ARTWORK, // dictionary where art id is key
ARTWORK_DELETE, // array of artwork ids of todelete artwork (refCount == 0)
ARTWORK_PREFIX, // starting code for all artwork storage keys (max size per key)
ARTWORK, // dictionary where art id is key
ARTWORK_DELETE, // array of artwork ids of todelete artwork (refCount == 0)
ARTWORK_PREFIX, // starting code for all artwork storage keys (max size per key)

PODCASTS, // dictionary where podcast id is key
EPISODES, // dictionary where episodes id is key
SONGS_TODO, // array of song ids of todo songs (refId == null)
PODCASTS, // dictionary where podcast id is key
EPISODES, // dictionary where episodes id is key
SONGS_TODO, // array of song ids of todo songs (refId == null)

VERSION = 200, // version string of store
}
VERSION = 200, // version string of store
}

function check() {
var current = new SubMusicVersion(null);

var storage = Application.Storage.getValue(VERSION);
if (storage == null) {
// normally: new install
// for Version.V0_0_16_PI only: fix storage if available
tryFixDeprecated();
function check() {
var current = new SubMusicVersion(null);

var storage = Application.Storage.getValue(VERSION);
if (storage == null) {
// normally: new install
// for Version.V0_0_16_PI only: fix storage if available
tryFixDeprecated();

// store current version number to storage
Application.Storage.setValue(VERSION, current.toStorage());
return;
}

var previous = new SubMusicVersion(storage);
if (current.compare(previous) == 0) {
// same version, nothing to do
return;
}

// store current version number to storage
// below 0.1.4, playable was playlist id, due to bug in 0.1.4, this is now set to 0.1.5
var version = new SubMusicVersion({"major" => 0, "minor" => 1, "patch" => 5});
if (previous.lessthan(version)) {
Application.Storage.setValue(PLAYABLE, null);
}

// update stored version
Application.Storage.setValue(VERSION, current.toStorage());
return;
}

var previous = new SubMusicVersion(storage);
if (current.compare(previous) == 0) {
// same version, nothing to do
return;
}

// below 0.1.4, playable was playlist id, due to bug in 0.1.4, this is now set to 0.1.5
var version = new SubMusicVersion({"major" => 0, "minor" => 1, "patch" => 5});
if (previous.lessthan(version)) {
Application.Storage.setValue(PLAYABLE, null);
// future should provide code here to update existing storages
}

// update stored version
Application.Storage.setValue(VERSION, current.toStorage());

// future should provide code here to update existing storages
}
// this can be removed in later versions as this translates storage from pre 0.0.16
function tryFixDeprecated() {
// check if any existing playlists
var playlists = Application.Storage.getValue(Storage_Deprecated.PLAYLIST_LOCAL);
if (playlists == null) {
Application.Storage.clearValues();
return;
}

// this can be removed in later versions as this translates storage from pre 0.0.16
function tryFixDeprecated() {
// check if any existing playlists
var playlists = Application.Storage.getValue(Storage_Deprecated.PLAYLIST_LOCAL);
if (playlists == null) {
// check if any existing songs
var songs = Application.Storage.getValue(Storage_Deprecated.SONGS_LOCAL);

// clear all persistent storage (we have copies now)
Application.Storage.clearValues();
return;
}

// check if any existing songs
var songs = Application.Storage.getValue(Storage_Deprecated.SONGS_LOCAL);

// clear all persistent storage (we have copies now)
Application.Storage.clearValues();

// if no songs to recover, return
if (songs == null) {
return;
}

// if no songs to recover, return
if (songs == null) {
return;
}

// here we have both playlists and songs
// here we have both playlists and songs

// store playlist ids
var pl_ids = playlists.keys();
for (var idx = 0; idx < pl_ids.size(); ++idx) {
var playlist = new IPlaylist(pl_ids[idx]);
playlist.setLocal(true);
playlist.setName(playlists[pl_ids[idx]]["name"]);
playlist.setCount(playlists[pl_ids[idx]]["songCount"]);
playlist.setRemote(true);
}
// store playlist ids
var pl_ids = playlists.keys();
for (var idx = 0; idx < pl_ids.size(); ++idx) {
var playlist = new IPlaylist(pl_ids[idx]);
playlist.setLocal(true);
playlist.setName(playlists[pl_ids[idx]]["name"]);
playlist.setCount(playlists[pl_ids[idx]]["songCount"]);
playlist.setRemote(true);
}

// safely remove all songs from cache
var refIds = songs.keys();
for (var idx = 0; idx < refIds.size(); ++idx) {
var refId = refIds[idx];
if (refId != null) {
// remove from media cache
var contentRef = new Media.ContentRef(refId, Media.CONTENT_TYPE_AUDIO);
Media.deleteCachedItem(contentRef);
// safely remove all songs from cache
var refIds = songs.keys();
for (var idx = 0; idx < refIds.size(); ++idx) {
var refId = refIds[idx];
if (refId != null) {
// remove from media cache
var contentRef = new Media.ContentRef(refId, Media.CONTENT_TYPE_AUDIO);
Media.deleteCachedItem(contentRef);
}
}
}
}
}

module ApiStandard {
enum {
SUBSONIC = 0,
AMPACHE = 1,
PLEX = 2,
module ApiStandard {
enum {
SUBSONIC = 0,
AMPACHE = 1,
PLEX = 2,
}
}
}

module ApiAuthMethod {
enum {
API_AUTH = 0,
HTTP_AUTH = 1,
module ApiAuthMethod {
enum {
API_AUTH = 0,
HTTP_AUTH = 1,
}
}
}
}
2 changes: 1 addition & 1 deletion source/SubMusicSyncDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Toybox.Communications;
using Toybox.Media;
using Toybox.Time;
using Toybox.WatchUi;
using SubMusic;
using SubMusic.Storage;

module SubMusic {

Expand Down
Loading

0 comments on commit d347197

Please sign in to comment.