Ursprung
ec6601da33
Commit
ad1501a625
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="1.8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -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>
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,81 @@
|
|||||||
package eu.smoser.epv
|
package eu.smoser.epv
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
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() {
|
class ResultActivity : AppCompatActivity() {
|
||||||
|
private var search = String()
|
||||||
|
private var user = User(0, 0)
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_result)
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="result_padding">10dp</dimen>
|
<dimen name="result_padding">10dp</dimen>
|
||||||
|
<dimen name="fixed">160dp</dimen>
|
||||||
|
<dimen name="fixed_third">50dp</dimen>
|
||||||
</resources>
|
</resources>
|
@ -1,6 +1,6 @@
|
|||||||
#Tue Jul 14 15:14:17 CEST 2020
|
#Thu Oct 15 12:56:28 CEST 2020
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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'
|
include ':app'
|
||||||
rootProject.name = "LibraryatHome"
|
rootProject.name = "Elektronische Privileg-Verwaltung"
|
||||||
|
In neuem Issue referenzieren