9 changed files with 177 additions and 68 deletions
@ -0,0 +1,93 @@
|
||||
/** |
||||
* ProjectLaogai |
||||
* |
||||
* Copyright 2019 <seil0@mosad.xyz> |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
||||
* MA 02110-1301, USA. |
||||
* |
||||
*/ |
||||
|
||||
package org.mosad.seil0.projectlaogai.controller |
||||
|
||||
import android.content.Context |
||||
import android.content.Intent |
||||
import android.nfc.NfcAdapter |
||||
import android.nfc.Tag |
||||
import android.nfc.tech.IsoDep |
||||
import com.afollestad.materialdialogs.MaterialDialog |
||||
import com.codebutler.farebot.Utils |
||||
import com.codebutler.farebot.card.desfire.DesfireFileSettings |
||||
import com.codebutler.farebot.card.desfire.DesfireProtocol |
||||
import org.mosad.seil0.projectlaogai.R |
||||
import java.lang.Exception |
||||
|
||||
class NFCMensaCard { |
||||
|
||||
companion object { |
||||
private const val appId = 0x5F8415 |
||||
private const val fileId = 1 |
||||
|
||||
/** |
||||
* read the current balance and last payment from the mensa card |
||||
* @param intent a nfc intent |
||||
* @param context the context to show the dialog in |
||||
*/ |
||||
fun readBalance(intent: Intent, context: Context) { |
||||
val tag: Tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG) |
||||
val isoDep = IsoDep.get(tag) |
||||
isoDep.connect() |
||||
|
||||
val card = DesfireProtocol(isoDep) |
||||
val settings = Utils.selectAppFile(card, appId, fileId) |
||||
|
||||
if (settings is DesfireFileSettings.ValueDesfireFileSettings) { |
||||
val data = try { |
||||
card.readValue(fileId) |
||||
} catch (ex: Exception) { 0 } |
||||
|
||||
MaterialDialog(context) |
||||
.title(R.string.mensa_credit) |
||||
.message(text = lookAtMe(context, data, settings.value)) |
||||
.show() |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* generate the values for current balance and last payment |
||||
* if the easter egg is active use schmeckles as currency |
||||
* 0.0000075 = 1.11 / 148 / 1000 (dollar / shm / card multiplier) |
||||
* @param context the context to access resources |
||||
* @param currentRaw the raw card value of the current balance |
||||
* @param lastRaw the raw card value of the last payment |
||||
* @return the message containing all values |
||||
*/ |
||||
private fun lookAtMe(context: Context, currentRaw: Int, lastRaw: Int): String { |
||||
val current = if (!PreferencesController.oGiants) { |
||||
String.format("%.2f €", (currentRaw.toFloat() / 1000)) |
||||
} else { |
||||
String.format("%.4f shm", (currentRaw.toFloat() * 0.0000075)) |
||||
} |
||||
|
||||
val last = if (!PreferencesController.oGiants) { |
||||
String.format("%.2f €", (lastRaw.toFloat() / 1000)) |
||||
} else { |
||||
String.format("%.4f shm", (lastRaw.toFloat() * 0.0000075)) |
||||
} |
||||
|
||||
return context.resources.getString(R.string.mensa_current, current) + context.resources.getString(R.string.mensa_last, last) |
||||
} |
||||
} |
||||
} |
@ -1,36 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
||||
<string name="navigation_drawer_close">Navigationsleiste schließen</string> |
||||
<string name="navigation_drawer_open">Navigationsleiste öffnen</string> |
||||
|
||||
<!-- nav-view --> |
||||
<string name="home">Home</string> |
||||
<string name="mensa">Mensa</string> |
||||
<string name="timetable">Stundenplan</string> |
||||
<string name="moodle">Moodle</string> |
||||
<string name="settings">Einstellungen</string> |
||||
|
||||
<!-- fragment_home --> |
||||
<string name="meal">Essen</string> |
||||
<string name="today_date">Heute, %1$s</string> |
||||
<string name="tomorrow_date">Morgen, %1$s</string> |
||||
<string name="mensa_closed">keine Essensausgabe</string> |
||||
<string name="no_more_food">Diese Woche keine weitere Essensausgabe</string> |
||||
<string name="no_lesson_today">heute keine Vorlesung!</string> |
||||
<string name="error">Fehler</string> |
||||
<string name="timetable_error">Stundenplan konnte nicht geladen werden!</string> |
||||
|
||||
<!-- fragment_settings --> |
||||
<string name="info">Info</string> |
||||
<string name="user">Benutzer</string> |
||||
<string name="course_desc">Tippen, um den Kurs zu ändern</string> |
||||
<string name="about_dialog_heading">Über</string> |
||||
<string name="licenses">Lizenzen</string> |
||||
<string name="theme">Design</string> |
||||
<string name="themeLight">Hell</string> |
||||
<string name="themeDark">Dunkel</string> |
||||
<string name="themeBlack">Schwarz</string> |
||||
<string name="primary_color">Hauptfarbe</string> |
||||
<string name="primary_color_desc">Die Primärfarbe, Standard ist Schwarz.</string> |
||||
<string name="accent_color">Akzentfarbe</string> |
||||
<string name="accent_color_desc">Die Akzentfarbe, Standard ist indigo</string> |
||||
<string name="show_buffet">Buffet immer anzeigen</string> |
||||
|
||||
<!-- dialogs --> |
||||
<string name="select_course">Wähle deinen Studiengang</string> |
||||
<string name="loading_timetable">lade Stundenplan …</string> |
||||
<string name="select">auswählen</string> |
||||
<string name="close">schließen</string> |
||||
<string name="about_dialog_heading">Über</string> |
||||
<string name="loading_timetable">lade Stundenplan …</string> |
||||
<string name="navigation_drawer_close">Navigationsleiste schließen</string> |
||||
<string name="navigation_drawer_open">Navigationsleiste öffnen</string> |
||||
<string name="show_buffet">Buffet immer anzeigen</string> |
||||
<string name="select_course">Wähle deinen Studiengang aus</string> |
||||
<string name="theme">Design</string> |
||||
<string name="themeLight">Hell</string> |
||||
<string name="themeDark">Dunkel</string> |
||||
<string name="themeBlack">Schwarz</string> |
||||
<string name="licenses">Lizenzen</string> |
||||
<string name="mensa_credit">Mensa-Guthaben</string> |
||||
<string name="mensa_current">aktuell: %1$s\n</string> |
||||
<string name="mensa_last">letzte Abbuchung: %1$s</string> |
||||
|
||||
<!-- errors --> |
||||
<string name="error">Fehler</string> |
||||
<string name="timetable_error">Stundenplan konnte nicht geladen werden!</string> |
||||
|
||||
</resources> |
||||
|
Loading…
Reference in new issue