Revert "Update VodafoneDE.js"

This reverts commit 172ec57727.
This commit is contained in:
Chaos53925 2023-09-19 20:07:27 +02:00
parent 2659c15a55
commit f8288a4d63

View file

@ -3,11 +3,9 @@
// icon-color: red; icon-glyph: broadcast-tower; // icon-color: red; icon-glyph: broadcast-tower;
/************** /**************
Version 2.4.0 Version 2.3.0
Changelog: Changelog:
v2.4.0:
- added Support for flat tariff like "GigaMobil M mit unbegrenzten GB", "GigaMobil XL mit unbegrenzten GB" or other flat tariffs
v2.3.0: v2.3.0:
- Support for lockscreen widgets added - Support for lockscreen widgets added
v2.2.2: v2.2.2:
@ -79,12 +77,12 @@ let showRemainingDaysAsProgressbar = true
// Please add additional values to these list, in case that your contract/tarif isn't supported by these default values. // Please add additional values to these list, in case that your contract/tarif isn't supported by these default values.
let containerList = ['Daten', 'D_EU_DATA', 'C_DIY_Data_National'] let containerList = ['Daten', 'D_EU_DATA', 'C_DIY_Data_National']
let codeList = ['-1', '-5', '45500', '40100'] let codeList = ['-1', '-5' ,'45500', '40100']
// Please add additional values if you see technical descriptions like D_EU_DATA in your widget // Please add additional values if you see technical descriptions like D_EU_DATA in your widget
const descriptionMapping = { const descriptionMapping = {
'Datenvolumen Inland & EU': 'Datenvolumen', 'Datenvolumen Inland & EU' : 'Datenvolumen',
'GigaDepot-Datenvolumen Inland & EU': 'GigaDepot-Datenvolumen', 'GigaDepot-Datenvolumen Inland & EU' : 'GigaDepot-Datenvolumen',
'D_EU_DATA': 'Datenvolumen' 'D_EU_DATA': 'Datenvolumen'
} }
@ -107,7 +105,7 @@ let user, pass, number, json, cacheUUID
if (widgetInputRAW !== null) { if (widgetInputRAW !== null) {
const parameter = widgetInputRAW.toString().split("|") const parameter = widgetInputRAW.toString().split("|")
if (parameter.length > 1) { if(parameter.length > 1) {
[user, pass, number, json] = parameter; [user, pass, number, json] = parameter;
@ -188,7 +186,7 @@ if (darkModeSupport) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
async function setupAssistant() { async function setupAssistant () {
let parameter = '' let parameter = ''
const promptLoginType = new Alert() const promptLoginType = new Alert()
@ -254,7 +252,7 @@ async function setupAssistant() {
let res, data let res, data
try { try {
res = await req.loadJSON() res = await req.loadJSON()
if (!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0] || !res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']) { if(!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0] || !res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']) {
throw new Error('invalid response: ' + JSON.stringify(res)) throw new Error('invalid response: ' + JSON.stringify(res))
} }
data = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup'] data = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup']
@ -268,7 +266,7 @@ async function setupAssistant() {
} }
const list = data.map(function (o) { const list = data.map(function (o) {
return o.usage.map(function (i) { return o.usage.map(function(i) {
i.container = o.container || null i.container = o.container || null
i.selected = false i.selected = false
return i return i
@ -291,7 +289,7 @@ async function setupAssistant() {
let row = new UITableRow() let row = new UITableRow()
row.dismissOnSelect = false row.dismissOnSelect = false
let selectedCell = row.addText((list[i].selected) ? "✓" : "") let selectedCell = row.addText((list[i].selected)? "✓" : "")
selectedCell.widthWeight = 5 selectedCell.widthWeight = 5
let textCell = row.addText(list[i].name) let textCell = row.addText(list[i].name)
@ -376,7 +374,7 @@ function creatProgress(total, havegone) {
return context.getImage() return context.getImage()
} }
function getDiagram(percentage, isFlat, widgetType) { function getDiagram(percentage) {
function drawArc(ctr, rad, w, deg) { function drawArc(ctr, rad, w, deg) {
bgx = ctr.x - rad bgx = ctr.x - rad
bgy = ctr.y - rad bgy = ctr.y - rad
@ -428,22 +426,9 @@ function getDiagram(percentage, isFlat, widgetType) {
) )
canvas.setTextAlignedCenter() canvas.setTextAlignedCenter()
canvas.setTextColor(textColor) canvas.setTextColor(textColor)
canvas.setFont(Font.boldSystemFont(108)) canvas.setFont(Font.boldSystemFont(canvTextSize))
if (isFlat === true) { canvas.drawTextInRect(`${percentage}%`, canvTextRect)
if (widgetType === "small" || "medium" || "large" || "extraLarge") {
const infinitySize = canvSize / 2;
canvas.setFont(Font.boldSystemFont(infinitySize));
const textRect = new Rect(0, infinitySize / 3, canvSize, canvSize);
canvas.drawTextInRect(``, textRect);
} else {
const infinitySize = canvSize / 2;
canvas.setFont(Font.boldSystemFont(infinitySize));
const textRect = new Rect(0, infinitySize / 1, canvSize, canvSize);
canvas.drawTextInRect(``, textRect);
}
} else {
canvas.drawTextInRect(`${percentage}%`, canvTextRect);
}
return canvas.getImage() return canvas.getImage()
} }
@ -464,21 +449,11 @@ function getTimeRemaining(endtime) {
} }
function getTotalValues(v) { function getTotalValues(v) {
let totalValues;
if (v.unitOfMeasure !== 'MB') { if (v.unitOfMeasure !== 'MB') {
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure} von ${v.total} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure}` totalValues = `${(showRemainingContingent ? v.remaining : v.used)} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure} von ${v.total} ${descriptionMapping[v.unitOfMeasure] !== undefined ? descriptionMapping[v.unitOfMeasure] : v.unitOfMeasure}`
} else if (parseInt(v.total) < 1000) { } else if (parseInt(v.total) < 1000) {
totalValues = `${(showRemainingContingent ? v.remaining : v.used)} MB von ${v.total} MB` totalValues = `${(showRemainingContingent ? v.remaining : v.used)} MB von ${v.total} MB`
} else if (parseInt(v.total) >= 100000000) {
if (showRemainingContingent === true) {
totalValues = `Flat`
} else {
if (v.used <= 1024) {
totalValues = `${v.used} MB verbraucht.`
} else {
let usedGB = (v.used / 1024).toFixed(2)
totalValues = `${usedGB} GB verbraucht.`
}
}
} else { } else {
let GB = ((showRemainingContingent ? v.remaining : v.used) / 1024).toFixed(2) let GB = ((showRemainingContingent ? v.remaining : v.used) / 1024).toFixed(2)
let totalGB = (v.total / 1024).toFixed(2) let totalGB = (v.total / 1024).toFixed(2)
@ -561,7 +536,7 @@ async function getUsage(user, pass, number) {
} }
try { try {
let res = await req.loadJSON() let res = await req.loadJSON()
if (!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0]) { if(!res['serviceUsageVBO'] || !res['serviceUsageVBO']['usageAccounts'] || !res['serviceUsageVBO']['usageAccounts'][0]) {
if (debug) { if (debug) {
console.log(JSON.stringify(res, null, 2)) console.log(JSON.stringify(res, null, 2))
} }
@ -594,7 +569,7 @@ async function getUsage(user, pass, number) {
} }
for (let i = 0; i < container.length; i++) { for(let i = 0; i < container.length; i++) {
for (let j = 0; j < container[i]['usage'].length; j++) { for (let j = 0; j < container[i]['usage'].length; j++) {
if (codeList.includes(container[i]['usage'][j]['code'])) { if (codeList.includes(container[i]['usage'][j]['code'])) {
usage.push(container[i]['usage'][j]) usage.push(container[i]['usage'][j])
@ -606,7 +581,7 @@ async function getUsage(user, pass, number) {
console.log(ErrorMsg) console.log(ErrorMsg)
const listOfCodeInResponse = [] const listOfCodeInResponse = []
for (let i = 0; i < container.length; i++) { for(let i = 0; i < container.length; i++) {
for (let j = 0; j < container[i]['usage'].length; j++) { for (let j = 0; j < container[i]['usage'].length; j++) {
listOfCodeInResponse.push(`Code: "${container[i]['usage'][j].code}" for "${container[i]['usage'][j].description}"`) listOfCodeInResponse.push(`Code: "${container[i]['usage'][j].code}" for "${container[i]['usage'][j].description}"`)
} }
@ -642,7 +617,7 @@ var today = new Date()
const files = FileManager.local() const files = FileManager.local()
// Set up cache // Set up cache
const cacheNamePostfix = ((number) ? number.substr(number.length - 4) : 'networkLogin') + (cacheUUID ? `-${cacheUUID}` : '') const cacheNamePostfix = ((number) ? number.substr(number.length - 4) : 'networkLogin') + ( cacheUUID ? `-${cacheUUID}` : '')
const cachePath = files.joinPath(files.cacheDirectory(), "widget-vodafone-" + cacheNamePostfix) const cachePath = files.joinPath(files.cacheDirectory(), "widget-vodafone-" + cacheNamePostfix)
const cacheExists = files.fileExists(cachePath) const cacheExists = files.fileExists(cachePath)
const cacheDate = cacheExists ? files.modificationDate(cachePath) : 0 const cacheDate = cacheExists ? files.modificationDate(cachePath) : 0
@ -685,29 +660,28 @@ const lockscreenWidget = config.widgetFamily.includes('accessory')
// Create Widget // Create Widget
let widget = new ListWidget(); let widget = new ListWidget();
if (!lockscreenWidget) { if(!lockscreenWidget) {
widget.setPadding(10, 10, 10, 10) widget.setPadding(10, 10, 10, 10)
} }
if (data !== undefined) { if (data !== undefined) {
if (debug) { if(debug) {
console.log(JSON.stringify(data, null, 2)) console.log(JSON.stringify(data, null, 2))
} }
if (lockscreenWidget) { if(lockscreenWidget) {
let stack = widget.addStack() let stack = widget.addStack()
stack.layoutHorizontally() stack.layoutHorizontally()
let v = data.usage[0] let v = data.usage[0]
if (config.widgetFamily !== "accessoryInline") { if(config.widgetFamily !== "accessoryInline") {
const percentage = v.total >= 100000000 ? '∞' : (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0); const percentage = (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
const isFlat = v.total >= 100000000 stack.addImage(getDiagram(percentage));
stack.addImage(getDiagram(percentage, isFlat, config.widgetFamily));
} }
if (config.widgetFamily === "accessoryRectangular") { if(config.widgetFamily === "accessoryRectangular"){
stack.addSpacer(5) stack.addSpacer(5)
} }
if (config.widgetFamily !== "accessoryCircular") { if(config.widgetFamily !== "accessoryCircular"){
const totalValues = getTotalValues(v) const totalValues = getTotalValues(v)
stack.centerAlignContent() stack.centerAlignContent()
stack.addText(totalValues) stack.addText(totalValues)
@ -759,12 +733,11 @@ if (data !== undefined) {
column.layoutVertically() column.layoutVertically()
column.centerAlignContent() column.centerAlignContent()
const percentage = v.total > 100000000 ? 100 : (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0); const percentage = (100 / v.total * (showRemainingContingent ? v.remaining : v.used)).toFixed(0);
const isFlat = v.total >= 100000000
const imageStack = column.addStack() const imageStack = column.addStack()
imageStack.layoutHorizontally() imageStack.layoutHorizontally()
imageStack.addSpacer() imageStack.addSpacer()
imageStack.addImage(getDiagram(percentage, isFlat, config.widgetFamily)); imageStack.addImage(getDiagram(percentage));
imageStack.addSpacer() imageStack.addSpacer()
column.addSpacer(2) column.addSpacer(2)
@ -799,7 +772,7 @@ if (data !== undefined) {
if (data.endDate) { if (data.endDate) {
widget.addSpacer(5) widget.addSpacer(5)
let remainingDays = getTimeRemaining(data.endDate).days + 2 let remainingDays = getTimeRemaining(data.endDate).days + 2
if (data.billDate && showRemainingDaysAsProgressbar) { if(data.billDate && showRemainingDaysAsProgressbar) {
const startDate = new Date(data.billDate) const startDate = new Date(data.billDate)
const endDate = new Date(data.endDate) const endDate = new Date(data.endDate)
const total = (endDate - startDate) / (1000 * 60 * 60 * 24) const total = (endDate - startDate) / (1000 * 60 * 60 * 24)