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
This commit is contained in:
Jannik 2019-08-23 19:19:35 +02:00
parent 6cc1671a52
commit 5f2b3aa496
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
18 changed files with 79 additions and 18 deletions

View File

@ -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 {

View File

@ -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)
}

View File

@ -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,6 +52,7 @@ class NFCMensaCard {
fun readBalance(intent: Intent, context: Context) {
val tag: Tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
val isoDep = IsoDep.get(tag)
try {
isoDep.connect()
val card = DesfireProtocol(isoDep)
@ -58,11 +63,12 @@ class NFCMensaCard {
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
}
}
}

View File

@ -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
}
}
}

View File

@ -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>

View File

@ -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