Browse Source

clean up the layout & polished Mensa credit dialog

* don't crash if the nfc tag has been removed between triggering intent and connecting to the tag
* closes #21
pull/31/head
Jannik 3 years ago
parent
commit
5f2b3aa496
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 13
      app/build.gradle
  2. 4
      app/src/main/java/com/codebutler/farebot/card/desfire/DesfireException.kt
  3. 38
      app/src/main/java/org/mosad/seil0/projectlaogai/controller/NFCMensaCard.kt
  4. 4
      app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt
  5. 0
      app/src/main/res/layouts/activities/layout/activity_main.xml
  6. 0
      app/src/main/res/layouts/activities/layout/app_bar_main.xml
  7. 0
      app/src/main/res/layouts/activities/layout/cardview_day.xml
  8. 0
      app/src/main/res/layouts/activities/layout/linearlayout_lesson.xml
  9. 0
      app/src/main/res/layouts/activities/layout/linearlayout_meal.xml
  10. 0
      app/src/main/res/layouts/activities/layout/nav_header_main.xml
  11. 0
      app/src/main/res/layouts/dialogs/layout/dialog_loading.xml
  12. 34
      app/src/main/res/layouts/dialogs/layout/dialog_mensa_credit.xml
  13. 0
      app/src/main/res/layouts/fragments/layout/fragment_home.xml
  14. 0
      app/src/main/res/layouts/fragments/layout/fragment_mensa.xml
  15. 0
      app/src/main/res/layouts/fragments/layout/fragment_moodle.xml
  16. 0
      app/src/main/res/layouts/fragments/layout/fragment_settings.xml
  17. 0
      app/src/main/res/layouts/fragments/layout/fragment_timetable.xml
  18. 4
      build.gradle

13
app/build.gradle

@ -35,6 +35,19 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res/layouts/activities',
'src/main/res/layouts/dialogs',
'src/main/res/layouts/fragments',
'src/main/res/layouts',
'src/main/res'
]
}
}
}
dependencies {

4
app/src/main/java/com/codebutler/farebot/card/desfire/DesfireException.kt

@ -4,6 +4,6 @@ package com.codebutler.farebot.card.desfire
* Created by Jakob Wenzel on 16.11.13.
*/
class DesfireException : Exception {
constructor(message: String) : super(message) {}
constructor(cause: Throwable) : super(cause) {}
constructor(message: String) : super(message)
constructor(cause: Throwable) : super(cause)
}

38
app/src/main/java/org/mosad/seil0/projectlaogai/controller/NFCMensaCard.kt

@ -27,16 +27,20 @@ import android.content.Intent
import android.nfc.NfcAdapter
import android.nfc.Tag
import android.nfc.tech.IsoDep
import android.util.Log
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.codebutler.farebot.Utils
import com.codebutler.farebot.card.desfire.DesfireFileSettings
import com.codebutler.farebot.card.desfire.DesfireProtocol
import kotlinx.android.synthetic.main.dialog_mensa_credit.*
import org.mosad.seil0.projectlaogai.R
import java.lang.Exception
class NFCMensaCard {
companion object {
private const val className = "NFCMensaCard"
private const val appId = 0x5F8415
private const val fileId = 1
@ -48,21 +52,23 @@ class NFCMensaCard {
fun readBalance(intent: Intent, context: Context) {
val tag: Tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
val isoDep = IsoDep.get(tag)
isoDep.connect()
try {
isoDep.connect()
val card = DesfireProtocol(isoDep)
val settings = Utils.selectAppFile(card, appId, fileId)
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 }
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()
lookAtMe(context, data, settings.value).show()
}
} catch (ex: Exception) {
Log.i(className,"could not connect to tag", ex)
}
}
/**
@ -74,7 +80,10 @@ class NFCMensaCard {
* @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 {
private fun lookAtMe(context: Context, currentRaw: Int, lastRaw: Int): MaterialDialog {
val dialog = MaterialDialog(context)
.customView(R.layout.dialog_mensa_credit)
val current = if (!PreferencesController.oGiants) {
String.format("%.2f €", (currentRaw.toFloat() / 1000))
} else {
@ -87,7 +96,10 @@ class NFCMensaCard {
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)
dialog.txtView_current.text = current
dialog.txtView_last.text = context.resources.getString(R.string.mensa_last, last)
return dialog
}
}
}

4
app/src/main/java/org/mosad/seil0/projectlaogai/fragments/HomeFragment.kt

@ -24,6 +24,7 @@ package org.mosad.seil0.projectlaogai.fragments
import android.graphics.Typeface
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -52,6 +53,7 @@ import java.util.*
*/
class HomeFragment : Fragment() {
private val className = "MyActivity"
private val formatter = SimpleDateFormat("E dd.MM", Locale.getDefault())
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -146,7 +148,7 @@ class HomeFragment : Fragment() {
.title(R.string.error)
.message(R.string.timetable_error)
.show()
// TODO log the error and send feedback
Log.e(className, "could not load timetable") // TODO send feedback
}
}
}

0
app/src/main/res/layout/activity_main.xml → app/src/main/res/layouts/activities/layout/activity_main.xml

0
app/src/main/res/layout/app_bar_main.xml → app/src/main/res/layouts/activities/layout/app_bar_main.xml

0
app/src/main/res/layout/cardview_day.xml → app/src/main/res/layouts/activities/layout/cardview_day.xml

0
app/src/main/res/layout/linearlayout_lesson.xml → app/src/main/res/layouts/activities/layout/linearlayout_lesson.xml

0
app/src/main/res/layout/linearlayout_meal.xml → app/src/main/res/layouts/activities/layout/linearlayout_meal.xml

0
app/src/main/res/layout/nav_header_main.xml → app/src/main/res/layouts/activities/layout/nav_header_main.xml

0
app/src/main/res/layout/dialog_loading.xml → app/src/main/res/layouts/dialogs/layout/dialog_loading.xml

34
app/src/main/res/layouts/dialogs/layout/dialog_mensa_credit.xml

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linLayout_mensacredit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtView_Heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mensa_credit"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtView_current"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:text="16,95 €"
android:textAlignment="center"
android:textSize="20sp" />
<TextView
android:id="@+id/txtView_last"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mensa_last"
android:textAlignment="center"
android:textSize="16sp" />
</LinearLayout>

0
app/src/main/res/layout/fragment_home.xml → app/src/main/res/layouts/fragments/layout/fragment_home.xml

0
app/src/main/res/layout/fragment_mensa.xml → app/src/main/res/layouts/fragments/layout/fragment_mensa.xml

0
app/src/main/res/layout/fragment_moodle.xml → app/src/main/res/layouts/fragments/layout/fragment_moodle.xml

0
app/src/main/res/layout/fragment_settings.xml → app/src/main/res/layouts/fragments/layout/fragment_settings.xml

0
app/src/main/res/layout/fragment_timetable.xml → app/src/main/res/layouts/fragments/layout/fragment_timetable.xml

4
build.gradle

@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.40'
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close