1
0
Fork 0

Name added as field

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

Binäre Datei nicht angezeigt.

@ -23,6 +23,7 @@ fun <R> CoroutineScope.executeAsyncTask(
data class User( data class User(
@PrimaryKey val uid: Long, @PrimaryKey val uid: Long,
@ColumnInfo(name = "privilegien") val privilegien: Int, @ColumnInfo(name = "privilegien") val privilegien: Int,
@ColumnInfo(name = "name") val name: String,
) )
@Dao @Dao
@ -36,8 +37,8 @@ interface UserDao {
@Query("SELECT * FROM user WHERE uid == :id") @Query("SELECT * FROM user WHERE uid == :id")
fun findById(id: Long): User fun findById(id: Long): User
@Query("UPDATE user SET privilegien = :newPriv WHERE uid == :id") @Query("UPDATE user SET privilegien = :newPriv, name = :name WHERE uid == :id")
fun updatePrivilegien(id: Long, newPriv: Int) fun update(id: Long, newPriv: Int, name: String)
@Insert @Insert
fun insert(user: User) fun insert(user: User)
@ -46,7 +47,7 @@ interface UserDao {
fun delete(user: User) fun delete(user: User)
} }
@Database(entities = [User::class], version = 2) @Database(entities = [User::class], version = 3)
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): UserDao? abstract fun userDao(): UserDao?

@ -10,7 +10,7 @@ import java.lang.Exception
class ResultActivity : AppCompatActivity() { class ResultActivity : AppCompatActivity() {
private var search = String() private var search = String()
private var user = User(0, 0) private var user = User(0, 0, "")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -26,20 +26,21 @@ class ResultActivity : AppCompatActivity() {
val dao = AppDatabase.getInstance(this@ResultActivity).userDao() val dao = AppDatabase.getInstance(this@ResultActivity).userDao()
var tempUser = dao?.findById(search.toLong()) var tempUser = dao?.findById(search.toLong())
if(tempUser == null) { if(tempUser == null) {
tempUser = User(search.toLong(), 0) tempUser = User(search.toLong(), 0, "")
dao?.insert(tempUser) dao?.insert(tempUser)
} }
tempUser tempUser
}, onPostExecute = { }, onPostExecute = {
user = it user = it
findViewById<TextView>(R.id.textViewId).text = user.uid.toString() findViewById<TextView>(R.id.textViewId).text = user.uid.toString()
setCurrentName(user.name)
setCurrentPrivilegien(user.privilegien) setCurrentPrivilegien(user.privilegien)
}) })
findViewById<Button>(R.id.buttonSave).setOnClickListener { findViewById<Button>(R.id.buttonSave).setOnClickListener {
lifecycleScope.executeAsyncTask(onPreExecute = {}, doInBackground = { lifecycleScope.executeAsyncTask(onPreExecute = {}, doInBackground = {
val dao = AppDatabase.getInstance(this@ResultActivity).userDao() val dao = AppDatabase.getInstance(this@ResultActivity).userDao()
dao?.updatePrivilegien(user.uid, getCurrentPrivilegien()) dao?.update(user.uid, getCurrentPrivilegien(), getCurrentName())
}, onPostExecute = { }, onPostExecute = {
onBackPressed() onBackPressed()
}) })
@ -69,6 +70,15 @@ class ResultActivity : AppCompatActivity() {
findViewById<EditText>(R.id.editTextNumberSigned).setText(newPriv.toString()) findViewById<EditText>(R.id.editTextNumberSigned).setText(newPriv.toString())
} }
private fun getCurrentName() : String {
return findViewById<EditText>(R.id.editTextName).text.toString()
}
private fun setCurrentName(newName: String) {
findViewById<EditText>(R.id.editTextName).setText(newName)
}
private fun getModifier() : Int { private fun getModifier() : Int {
var ret = 0 var ret = 0
try { try {

@ -14,7 +14,7 @@
android:padding="@dimen/result_padding" android:padding="@dimen/result_padding"
android:text="@string/pn" android:text="@string/pn"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textView3" app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -29,7 +29,7 @@
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/buttonSave" app:layout_constraintBottom_toTopOf="@+id/buttonSave"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" /> app:layout_constraintTop_toBottomOf="@+id/textView2" />
<EditText <EditText
android:id="@+id/editTextNumberSigned" android:id="@+id/editTextNumberSigned"
@ -37,14 +37,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:width="@dimen/fixed" android:width="@dimen/fixed"
android:ems="10" android:ems="10"
android:importantForAutofill="no"
android:inputType="numberSigned" android:inputType="numberSigned"
android:padding="@dimen/result_padding" android:padding="@dimen/result_padding"
android:text="@string/_0"
app:layout_constraintBottom_toTopOf="@+id/buttonCancel" app:layout_constraintBottom_toTopOf="@+id/buttonCancel"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3" app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textViewId" app:layout_constraintTop_toBottomOf="@+id/editTextName" />
android:text="@string/_0"
android:importantForAutofill="no" />
<TextView <TextView
android:id="@+id/textViewId" android:id="@+id/textViewId"
@ -53,7 +53,7 @@
android:width="@dimen/fixed" android:width="@dimen/fixed"
android:padding="@dimen/result_padding" android:padding="@dimen/result_padding"
android:text="" android:text=""
app:layout_constraintBottom_toTopOf="@+id/editTextNumberSigned" app:layout_constraintBottom_toTopOf="@+id/editTextName"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView" app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -128,4 +128,32 @@
app:layout_constraintStart_toEndOf="@+id/buttonMinus" app:layout_constraintStart_toEndOf="@+id/buttonMinus"
app:layout_constraintTop_toBottomOf="@+id/editTextNumberSigned" app:layout_constraintTop_toBottomOf="@+id/editTextNumberSigned"
app:layout_constraintVertical_bias="0.25" /> app:layout_constraintVertical_bias="0.25" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed"
android:labelFor="@id/editTextName"
android:padding="@dimen/result_padding"
android:text="@string/name"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textView3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<EditText
android:id="@+id/editTextName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="@dimen/fixed"
android:ems="10"
android:inputType="textPersonName"
android:padding="@dimen/result_padding"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/editTextNumberSigned"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textViewId"
android:importantForAutofill="no" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -30,4 +30,5 @@
<string name="_10">10</string> <string name="_10">10</string>
<string name="_0">0</string> <string name="_0">0</string>
<string name="datenbank_anzeigen">Datenbank anzeigen</string> <string name="datenbank_anzeigen">Datenbank anzeigen</string>
<string name="name">Berechtigten-Name:</string>
</resources> </resources>