1
0
Fork 0

Minimal working version

master v1
Simon Moser vor 4 Jahren
Ursprung ec6601da33
Commit ad1501a625
Signiert von: mosers
GPG-Schlüssel-ID: 96B3365A234B500C

3
.idea/.gitignore vendored

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -1,6 +1,22 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>

@ -15,6 +15,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="TerminalProjectOptionsProvider">
<option name="myStartingDirectory" value="C:\Users\Simon\AndroidStudioProjects\ElektronischePrivilegVerwaltung" />
</component>
</project>

@ -4,6 +4,7 @@ import java.time.format.DateTimeFormatter
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
android {
@ -39,25 +40,31 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0@aar'
implementation 'com.google.zxing:core:3.3.2'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-beta01'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-beta01'
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
static def getVersion() {
def version = "„Library at Home“ Version "
def version = "„Elektronische Privileg-Verwaltung“ Version "
version += LocalDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE) + "."
def proc = "git log --format=\"%h\" -n 1".execute()
proc.in.eachLine { line -> version += line }

Binäre Datei nicht angezeigt.

@ -0,0 +1,18 @@
{
"version": 2,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "eu.smoser.libraryathome",
"variantName": "processReleaseResources",
"elements": [
{
"type": "SINGLE",
"filters": [],
"versionCode": 1,
"versionName": "1.0",
"outputFile": "app-release.apk"
}
]
}

@ -0,0 +1,73 @@
package eu.smoser.epv
import android.content.Context
import androidx.room.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
fun <R> CoroutineScope.executeAsyncTask(
onPreExecute: () -> Unit,
doInBackground: () -> R,
onPostExecute: (R) -> Unit
) = launch {
onPreExecute()
val result = withContext(Dispatchers.IO) {
doInBackground()
}
onPostExecute(result)
}
@Entity
data class User(
@PrimaryKey val uid: Long,
@ColumnInfo(name = "privilegien") val privilegien: Int,
)
@Dao
interface UserDao {
@Query("SELECT * FROM user")
fun getAll(): List<User>
@Query("UPDATE user SET privilegien = privilegien + :modifier WHERE uid IN (:userIds)")
fun updateAllPrivilegien(userIds: LongArray, modifier: Int)
@Query("SELECT * FROM user WHERE uid == :id")
fun findById(id: Long): User
@Query("UPDATE user SET privilegien = :newPriv WHERE uid == :id")
fun updatePrivilegien(id: Long, newPriv: Int)
@Insert
fun insert(user: User)
@Delete
fun delete(user: User)
}
@Database(entities = [User::class], version = 2)
abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): UserDao?
companion object {
private const val DB_NAME = "UserDatabase.db"
@Volatile
private var appDatabase: AppDatabase? = null
@Synchronized
fun getInstance(context: Context): AppDatabase {
if (appDatabase == null) appDatabase = create(context)
return appDatabase!!
}
private fun create(context: Context): AppDatabase {
return Room.databaseBuilder(
context,
AppDatabase::class.java,
DB_NAME
).fallbackToDestructiveMigration().build()
}
}
}

@ -2,6 +2,9 @@ package eu.smoser.epv
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.lifecycle.lifecycleScope
class HelpActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -10,6 +13,18 @@ class HelpActivity : AppCompatActivity() {
setSupportActionBar(findViewById(R.id.toolbar))
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
findViewById<Button>(R.id.button).setOnClickListener {
lifecycleScope.executeAsyncTask(onPreExecute = {}, doInBackground = {
val dao = AppDatabase.getInstance(this@HelpActivity).userDao()
dao?.getAll()
}, onPostExecute = {
findViewById<TextView>(R.id.textHelp).text = ""
it?.forEach { user ->
findViewById<TextView>(R.id.textHelp).append(user.toString() + "\n")
}
})
}
}
override fun onSupportNavigateUp(): Boolean {

@ -31,9 +31,11 @@ class MainActivity : AppCompatActivity() {
val editTextSearch = findViewById<EditText>(R.id.editTextSearch)
findViewById<Button>(R.id.buttonSearch).setOnClickListener {
if(!editTextSearch.text.toString().trim().isBlank()) {
val intent = Intent(this, ResultActivity::class.java)
intent.putExtra("search", editTextSearch.text.toString())
val input = editTextSearch.text.toString().trim()
// TODO: set {13} after development
if(input.matches("\\d{1,13}".toRegex())) {
val intent = Intent(this@MainActivity, ResultActivity::class.java)
intent.putExtra("search", input)
startActivity(intent)
} else {
Toast.makeText(this, getString(R.string.emptySearch), Toast.LENGTH_SHORT).show()

@ -1,11 +1,81 @@
package eu.smoser.epv
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import java.lang.Exception
class ResultActivity : AppCompatActivity() {
private var search = String()
private var user = User(0, 0)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_result)
if (intent.extras?.getString("search") !== null) {
search = intent.extras?.getString("search")!!
} else {
onBackPressed()
}
lifecycleScope.executeAsyncTask(onPreExecute = {}, doInBackground = {
val dao = AppDatabase.getInstance(this@ResultActivity).userDao()
var tempUser = dao?.findById(search.toLong())
if(tempUser == null) {
tempUser = User(search.toLong(), 0)
dao?.insert(tempUser)
}
tempUser
}, onPostExecute = {
user = it
findViewById<TextView>(R.id.textViewId).text = user.uid.toString()
setCurrentPrivilegien(user.privilegien)
})
findViewById<Button>(R.id.buttonSave).setOnClickListener {
lifecycleScope.executeAsyncTask(onPreExecute = {}, doInBackground = {
val dao = AppDatabase.getInstance(this@ResultActivity).userDao()
dao?.updatePrivilegien(user.uid, getCurrentPrivilegien())
}, onPostExecute = {
onBackPressed()
})
}
findViewById<Button>(R.id.buttonCancel).setOnClickListener {
onBackPressed()
}
findViewById<Button>(R.id.buttonPlus).setOnClickListener {
setCurrentPrivilegien(getCurrentPrivilegien() + getModifier())
}
findViewById<Button>(R.id.buttonMinus).setOnClickListener {
setCurrentPrivilegien(getCurrentPrivilegien() - getModifier())
}
}
private fun getCurrentPrivilegien() : Int {
var ret = 0
try {
ret = Integer.parseInt(findViewById<EditText>(R.id.editTextNumberSigned).text.toString())
} catch (e : Exception) {
findViewById<EditText>(R.id.editTextNumberSigned).setText("0")
}
return ret
}
private fun setCurrentPrivilegien(newPriv: Int) {
findViewById<EditText>(R.id.editTextNumberSigned).setText(newPriv.toString())
}
private fun getModifier() : Int {
var ret = 0
try {
ret = Integer.parseInt(findViewById<EditText>(R.id.editTextNumber).text.toString())
} catch (e : Exception) {
findViewById<EditText>(R.id.editTextNumber).setText("0")
}
return ret
}
}

@ -26,18 +26,6 @@ class SettingsActivity : AppCompatActivity() {
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
val manPref = findPreference<SwitchPreference>("preference_auth_manual")!!
manPref.setOnPreferenceChangeListener{ _, newValue ->
val manual = newValue as Boolean
findPreference<EditTextPreference>("preference_auth_jwt")!!.isEnabled = manual
findPreference<ListPreference>("preference_auth_algo")!!.isEnabled = !manual
findPreference<EditTextPreference>("preference_jwt_key")!!.isEnabled = !manual
findPreference<ListPreference>("preference_jwt_permissions")!!.isEnabled = !manual
true
}
manPref.onPreferenceChangeListener.onPreferenceChange(manPref,
PreferenceManager.getDefaultSharedPreferences(manPref.context).
getBoolean("preference_auth_manual", true))
val theme = findPreference<ListPreference>(getString(R.string.preference_rest_theme))!!
theme.setOnPreferenceChangeListener{ _, newValue ->
AppCompatDelegate.setDefaultNightMode((newValue as String).toInt())

@ -39,18 +39,31 @@
android:layout_height="0dp"
android:fillViewport="true"
android:scrollbars="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textHelp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="@dimen/result_padding"
android:text="@string/help" />
</ScrollView>
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorAccent"
android:text="@string/datenbank_anzeigen"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textLicBody" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

@ -6,4 +6,126 @@
android:layout_height="match_parent"
tools:context="eu.smoser.epv.ResultActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed"
android:padding="@dimen/result_padding"
android:text="@string/pn"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed"
android:labelFor="@id/editTextNumberSigned"
android:padding="@dimen/result_padding"
android:text="@string/ps"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/buttonSave"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<EditText
android:id="@+id/editTextNumberSigned"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed"
android:ems="10"
android:inputType="numberSigned"
android:padding="@dimen/result_padding"
app:layout_constraintBottom_toTopOf="@+id/buttonCancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textViewId"
android:text="@string/_0"
android:importantForAutofill="no" />
<TextView
android:id="@+id/textViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed"
android:padding="@dimen/result_padding"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/editTextNumberSigned"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="@dimen/result_padding"
android:backgroundTint="@color/colorAccentGreen"
android:text="@string/speichern"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/buttonCancel"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
<Button
android:id="@+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="@dimen/result_padding"
android:background="@color/colorAccentRed"
android:text="@string/abbrechen"
android:textAllCaps="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/buttonSave"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberSigned" />
<Button
android:id="@+id/buttonPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed_third"
android:backgroundTint="@color/colorAccentYellow"
android:text="@string/plus"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/buttonCancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/editTextNumber"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberSigned"
app:layout_constraintVertical_bias="0.25" />
<Button
android:id="@+id/buttonMinus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed_third"
android:backgroundTint="@color/colorAccentYellow"
android:text="@string/minus"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/buttonSave"
app:layout_constraintEnd_toStartOf="@id/editTextNumber"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberSigned"
app:layout_constraintVertical_bias="0.25" />
<EditText
android:id="@+id/editTextNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed_third"
android:ems="10"
android:importantForAutofill="no"
android:inputType="number"
android:text="@string/_10"
android:textAlignment="center"
android:textSize="14sp"
app:layout_constraintBottom_toTopOf="@+id/buttonCancel"
app:layout_constraintEnd_toStartOf="@+id/buttonPlus"
app:layout_constraintStart_toEndOf="@+id/buttonMinus"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberSigned"
app:layout_constraintVertical_bias="0.25" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -6,4 +6,7 @@
<color name="colorbgPrimaryDark">#002b36</color>
<color name="colorbgPrimaryTransparent">#77657b83</color>
<color name="colorAccent">#2aa198</color>
<color name="colorAccentRed">#cb4b16</color>
<color name="colorAccentYellow">#b58900</color>
<color name="colorAccentGreen">#859900</color>
</resources>

@ -1,3 +1,5 @@
<resources>
<dimen name="result_padding">10dp</dimen>
<dimen name="fixed">160dp</dimen>
<dimen name="fixed_third">50dp</dimen>
</resources>

@ -2,4 +2,5 @@
<resources>
<item name="action_batch" type="id" />
<item name="all_books" type="id" />
<item name="editTextNumberSigned" type="id" />
</resources>

@ -9,6 +9,10 @@
<string name="barcode">Barcode</string>
<string name="title_activity_settings">Einstellungen</string>
<string name="speichern">Speichern</string>
<string name="abbrechen">Abbrechen</string>
<string name="pn">Privilegien-Nummer:</string>
<string name="ps">Aktuelle Privilegien:</string>
<string name="note">Notiz:</string>
<string name="search_new">Search new</string>
<string name="action_about">Über</string>
<string name="copyright">Copyright &#169; 2020 Simon Moser - info@smoser.eu</string>
@ -21,4 +25,9 @@
<string name="title_activity_help">Hilfe</string>
<string name="help" tools:ignore="Typos">Lorem Ipsum</string>
<string name="scanned">Privilegien-Nummer abgelesen</string>
<string name="minus">-</string>
<string name="plus">+</string>
<string name="_10">10</string>
<string name="_0">0</string>
<string name="datenbank_anzeigen">Datenbank anzeigen</string>
</resources>

@ -1,51 +1,5 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="Lokaler Server">
<EditTextPreference
android:defaultValue="192.168.178.46:5000"
android:key="preference_local_url"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="URL"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
android:defaultValue="false"
android:key="preference_local_https"
android:title="HTTPS verwenden" />
</PreferenceCategory>
<PreferenceCategory app:title="Authentifizierung">
<SwitchPreference
android:defaultValue="true"
android:key="preference_auth_manual"
android:title="JWT manuell eingeben" />
<EditTextPreference
android:defaultValue="eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJ3cml0ZSIsImV4cCI6IjE5MTAzOTA0MDAifQ.aC8PKwbDjfZagC84VlOTQvuRJpjnDXOszNX7CUlUAbs38gWC4ilffFUiTskJ75NQ-z-5O08sDV6Gwa2TEaPK3w"
android:key="preference_auth_jwt"
android:title="JWT"
android:selectAllOnFocus="true"
android:singleLine="true"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:defaultValue="ES256"
android:entries="@array/jwt_algos"
android:entryValues="@array/jwt_algos"
android:key="preference_auth_algo"
android:title="Signatur-Algorithmus"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:defaultValue=""
android:key="preference_jwt_key"
android:selectAllOnFocus="true"
android:singleLine="false"
android:title="Privater Signatur-Schlüssel" />
<ListPreference
android:defaultValue="read"
android:entries="@array/jwt_permissions"
android:entryValues="@array/jwt_permissions"
android:key="preference_jwt_permissions"
android:title="Berechtigungen"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory android:title="Diverses">
<ListPreference

@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.android.gms:oss-licenses-plugin:0.10.2'

@ -1,6 +1,6 @@
#Tue Jul 14 15:14:17 CEST 2020
#Thu Oct 15 12:56:28 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

@ -1,2 +1,2 @@
include ':app'
rootProject.name = "LibraryatHome"
rootProject.name = "Elektronische Privileg-Verwaltung"