Skip to content

Commit

Permalink
Merge pull request espruino#2359 from thyttan/podcast-addict
Browse files Browse the repository at this point in the history
[Podcast Addict Remote] compatibility with Fastload Utils
  • Loading branch information
gfwilliams authored Dec 6, 2022
2 parents 74dfa8f + 350e005 commit 04d9c6a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 40 deletions.
1 change: 1 addition & 0 deletions apps/podadrem/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
Addict.
0.04: New layout.
0.05: Add widget field, tweak layout.
0.06: Add compatibility with Fastload Utils.
90 changes: 51 additions & 39 deletions apps/podadrem/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
/*
Bluetooth.println(JSON.stringify({t:"intent", action:"", flags:["flag1", "flag2",...], categories:["category1","category2",...], mimetype:"", data:"", package:"", class:"", target:"", extra:{someKey:"someValueOrString"}}));
Expand Down Expand Up @@ -65,13 +66,14 @@ Since v2020.16
com.bambuna.podcastaddict.service.player.togglespeed – This will toggle the Playback speed for the episode currently playing (alternate between selected speed and 1.0x).
*/

var R;
var backToMenu = false;
var dark = g.theme.dark; // bool
let R;
let widgetUtils = require("widget_utils");
let backToMenu = false;
let dark = g.theme.dark; // bool

// The main layout of the app
function gfx() {
//Bangle.drawWidgets();
let gfx = function() {
widgetUtils.hide();
R = Bangle.appRect;
marigin = 8;
// g.drawString(str, x, y, solid)
Expand Down Expand Up @@ -106,10 +108,10 @@ function gfx() {

g.setFontAlign(1, 1, 0);
g.drawString("Speed", R.x + R.w - 2*marigin, R.y + R.h - 2*marigin);
}
};

// Touch handler for main layout
function touchHandler(_, xy) {
let touchHandler = function(_, xy) {
x = xy.x;
y = xy.y;
len = (R.w<R.h+1)?(R.w/3):(R.h/3);
Expand Down Expand Up @@ -145,53 +147,61 @@ function touchHandler(_, xy) {
//play/pause
btMsg("service", standardCls, "player.toggle");
}
}
};

// Swipe handler for main layout, used to jump backward and forward within a podcast episode.
function swipeHandler(LR, _) {
let swipeHandler = function(LR, _) {
if (LR==-1) {
btMsg("service", standardCls, "player.jumpforward");
}
if (LR==1) {
btMsg("service", standardCls, "player.jumpbackward");
}
}
};

// Navigation input on the main layout
function setUI() {
// Bangle.setUI code from rigrig's smessages app for volume control: https://git.tubul.net/rigrig/BangleApps/src/branch/personal/apps/smessages/app.js
let setUI = function() {
// Bangle.setUI code from rigrig's smessages app for volume control: https://git.tubul.net/rigrig/BangleApps/src/branch/personal/apps/smessages/app.js
Bangle.setUI(
{mode : "updown", back : load},
ud => {
if (ud) Bangle.musicControl(ud>0 ? "volumedown" : "volumeup");
}
{mode : "updown",
remove : ()=>{
Bangle.removeListener("touch", touchHandler);
Bangle.removeListener("swipe", swipeHandler);
clearWatch(buttonHandler);
widgetUtils.show();
}
},
ud => {
if (ud) Bangle.musicControl(ud>0 ? "volumedown" : "volumeup");
}
);
Bangle.on("touch", touchHandler);
Bangle.on("swipe", swipeHandler);
}
let buttonHandler = setWatch(()=>{load();}, BTN, {edge:'falling'});
};

/*
The functions for interacting with Android and the Podcast Addict app
*/

pkg = "com.bambuna.podcastaddict";
standardCls = pkg + ".receiver.PodcastAddictPlayerReceiver";
updateCls = pkg + ".receiver.PodcastAddictBroadcastReceiver";
speed = 1.0;
let pkg = "com.bambuna.podcastaddict";
let standardCls = pkg + ".receiver.PodcastAddictPlayerReceiver";
let updateCls = pkg + ".receiver.PodcastAddictBroadcastReceiver";
let speed = 1.0;

simpleSearch = "";
let simpleSearch = "";

function simpleSearchTerm() { // input a simple search term without tags, overrides search with tags (artist and track)
let simpleSearchTerm = function() { // input a simple search term without tags, overrides search with tags (artist and track)
require("textinput").input({
text: simpleSearch
}).then(result => {
simpleSearch = result;
}).then(() => {
E.showMenu(searchMenu);
});
}
};

function searchPlayWOTags() { //make a search and play using entered terms
let searchPlayWOTags = function() { //make a search and play using entered terms
searchString = simpleSearch;
Bluetooth.println(JSON.stringify({
t: "intent",
Expand All @@ -203,25 +213,25 @@ function searchPlayWOTags() { //make a search and play using entered terms
},
flags: ["FLAG_ACTIVITY_NEW_TASK"]
}));
}
};

function gadgetbridgeWake() {
let gadgetbridgeWake = function() {
Bluetooth.println(JSON.stringify({
t: "intent",
target: "activity",
flags: ["FLAG_ACTIVITY_NEW_TASK", "FLAG_ACTIVITY_CLEAR_TASK", "FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS", "FLAG_ACTIVITY_NO_ANIMATION"],
package: "gadgetbridge",
class: "nodomain.freeyourgadget.gadgetbridge.activities.WakeActivity"
}));
}
};

// For stringing together the action for Podcast Addict to perform
function actFn(actName, activOrServ) {
let actFn = function(actName, activOrServ) {
return "com.bambuna.podcastaddict." + (activOrServ == "service" ? "service." : "") + actName;
}
};

// Send the intent message to Gadgetbridge
function btMsg(activOrServ, cls, actName, xtra) {
let btMsg = function(activOrServ, cls, actName, xtra) {

Bluetooth.println(JSON.stringify({
t: "intent",
Expand All @@ -231,10 +241,10 @@ function btMsg(activOrServ, cls, actName, xtra) {
target: "broadcastreceiver",
extra: xtra
}));
}
};

// Get back to the main layout
function backToGfx() {
let backToGfx = function() {
E.showMenu();
g.clear();
g.reset();
Expand All @@ -243,10 +253,10 @@ function backToGfx() {
setUI();
gfx();
backToMenu = false;
}
};

// Podcast Addict Menu
var paMenu = {
let paMenu = {
"": {
title: " ",
back: backToGfx
Expand All @@ -271,7 +281,7 @@ var paMenu = {
};


var controlMenu = {
let controlMenu = {
"": {
title: " ",
back: () => {if (backToMenu) E.showMenu(paMenu);
Expand Down Expand Up @@ -310,7 +320,7 @@ var controlMenu = {
},
};

var speedMenu = {
let speedMenu = {
"": {
title: " ",
back: () => {if (backToMenu) E.showMenu(paMenu);
Expand All @@ -333,7 +343,7 @@ var speedMenu = {
//"Slower" : ()=>{speed-=0.1; speed=((speed<0.1)?0.1:speed); btMsg("service",standardCls,"player.customspeed",{arg1:speed});},
};

var searchMenu = {
let searchMenu = {
"": {
title: " ",

Expand All @@ -356,7 +366,7 @@ var searchMenu = {
"Simpler search and play" : searchPlayWOTags,
};

var navigationMenu = {
let navigationMenu = {
"": {
title: " ",
back: () => {if (backToMenu) E.showMenu(paMenu);
Expand All @@ -372,4 +382,6 @@ var navigationMenu = {

Bangle.loadWidgets();
setUI();
widgetUtils.hide();
gfx();
}
2 changes: 1 addition & 1 deletion apps/podadrem/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "podadrem",
"name": "Podcast Addict Remote",
"shortName": "PA Remote",
"version": "0.05",
"version": "0.06",
"description": "Control Podcast Addict on your android device.",
"readme": "README.md",
"type": "app",
Expand Down

0 comments on commit 04d9c6a

Please sign in to comment.