Admin-Modus hinzugefügt

master
Niko Diamadis 6 years ago
parent ce1b9fab0b
commit 588d1fffa7

@ -2,8 +2,20 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
android {
signingConfigs {
signingconf {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
storeFile file(properties.getProperty("signing.file"))
storePassword properties.getProperty("signing.password")
keyAlias properties.getProperty("signing.key.alias")
keyPassword properties.getProperty("signing.key.password")
}
}
compileSdkVersion 29
buildToolsVersion "29.0.3"
@ -17,8 +29,8 @@ android {
buildTypes {
release {
signingConfig signingConfigs.signingconf
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
@ -38,11 +50,14 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0'
// implementation 'com.github.cyb3rko:about-icons:1.1.1'
implementation "com.google.android.material:material:1.2.0"
implementation 'com.amitshekhar.android:android-networking:1.0.2'
// implementation 'com.github.cyb3rko:about-icons:1.0.0'
implementation 'com.github.GrenderG:Toasty:1.5.0'
implementation 'com.github.medyo:android-about-page:1.3'
implementation 'com.google.android.material:material:1.2.0'
implementation 'com.google.firebase:firebase-database:19.3.1'
implementation "com.mikepenz:aboutlibraries:8.3.0"
implementation "com.mikepenz:aboutlibraries-core:8.3.0"
implementation "com.mikepenz:aboutlibraries:$about_libraries_version"
implementation "com.mikepenz:aboutlibraries-core:$about_libraries_version"
implementation 'me.ibrahimyilmaz:kiel:1.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

@ -1,45 +1,67 @@
package com.cyb3rko.techniklogger
import android.Manifest
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Base64
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.input.getInputField
import com.afollestad.materialdialogs.input.input
import com.androidnetworking.AndroidNetworking
import com.androidnetworking.error.ANError
import com.androidnetworking.interfaces.StringRequestListener
import com.cyb3rko.techniklogger.recycler.ProjectEntryViewHolder
import com.cyb3rko.techniklogger.recycler.ProjectViewState
import com.cyb3rko.techniklogger.utils.About
import com.cyb3rko.techniklogger.utils.Updater
import com.google.firebase.database.*
import java.lang.IndexOutOfBoundsException
import es.dmoral.toasty.Toasty
import kotlinx.android.synthetic.main.activity_main.*
import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter.Companion.adapterOf
import java.nio.charset.StandardCharsets
import java.text.SimpleDateFormat
import java.util.*
class MainActivity : AppCompatActivity() {
private var adminMode = false
private val data: MutableList<ProjectViewState.ProjectEntry> = mutableListOf()
private lateinit var databaseReference: DatabaseReference
private lateinit var sharedPref: SharedPreferences
private lateinit var sharedPrefEditor: SharedPreferences.Editor
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
sharedPref = getSharedPreferences("Safe", 0)
sharedPrefEditor = sharedPref.edit()
sharedPrefEditor.apply()
databaseReference = FirebaseDatabase.getInstance().reference
if (sharedPref.getString("name", "") == "") {
showNameDialog()
}
if (sharedPref.getBoolean("admin", false)) {
adminMode = true
floatingActionButton.show()
floatingActionButton.setOnClickListener {
}
Toasty.info(applicationContext, "Admin-Zugriff", Toasty.LENGTH_SHORT).show()
}
val adapter = adapterOf<ProjectViewState> {
register(
layoutResource = R.layout.item_recycler_projects,
@ -121,17 +143,62 @@ class MainActivity : AppCompatActivity() {
sharedPref.edit().putString("name", inputName.toString()).apply()
}
}
positiveButton(0, "Speichern")
}
}
private fun hideProgess() {
private fun toggleAdminMode() {
if (!adminMode) {
var adminKey = ""
val listener = object: ChildEventListener {
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
if (snapshot.key == "admin_key") {
adminKey = snapshot.value.toString()
}
}
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {}
override fun onChildRemoved(snapshot: DataSnapshot) {}
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {}
override fun onCancelled(error: DatabaseError) {}
}
databaseReference.addChildEventListener(listener)
MaterialDialog(this)
.title(0, "Bitte gebe den Admin-Key ein")
.show {
input(hint = "Admin-Key", waitForPositiveButton = false) { _, inputKey ->
positiveButton {
if (inputKey.toString() == adminKey) {
sharedPref.edit().putBoolean("admin", true).apply()
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
finishAffinity()
} else {
Toasty.error(applicationContext, "Ungültiger Key").show()
}
}
}
positiveButton(0, "Speichern")
}
} else {
sharedPref.edit().putBoolean("admin", false).apply()
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
finishAffinity()
}
}
private fun hideProgress() {
progress_bar.visibility = View.GONE
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
if (adminMode) {
menu.findItem(R.id.action_admin).title = "Admin-Zugriff deaktivieren"
}
return true
}

@ -1,5 +1,8 @@
package com.cyb3rko.techniklogger
import android.annotation.SuppressLint
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@ -17,6 +20,8 @@ import com.cyb3rko.techniklogger.recycler.ProjectTechnikerViewHolder
import com.cyb3rko.techniklogger.recycler.ProjectTechnikerViewState
import com.google.firebase.database.*
import es.dmoral.toasty.Toasty
import java.lang.IndexOutOfBoundsException
import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter.Companion.adapterOf
@ -24,20 +29,29 @@ import me.ibrahimyilmaz.kiel.adapter.RecyclerViewAdapter.Companion.adapterOf
import kotlinx.android.synthetic.main.activity_project.*
import kotlinx.android.synthetic.main.activity_project.recycler_view
@SuppressLint("SetTextI18n")
class ProjectActivity : AppCompatActivity() {
private var adminMode = false
private var childKey = ""
private val techniker: MutableList<ProjectTechnikerViewState.ProjectTechniker> = mutableListOf()
private lateinit var databaseReference: DatabaseReference
private lateinit var sharedPref: SharedPreferences
private val techniker: MutableList<ProjectTechnikerViewState.ProjectTechniker> = mutableListOf()
override fun onCreate(savedInstanceState: Bundle?) {
childKey = intent.extras?.getString("childKey").toString()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_project)
sharedPref = getSharedPreferences("Safe", 0)
if (sharedPref.getBoolean("admin", false)) {
adminMode = true
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
databaseReference = FirebaseDatabase.getInstance().getReference(childKey)
databaseReference = FirebaseDatabase.getInstance().getReference("einsätze").child(childKey)
val adapter = adapterOf<ProjectTechnikerViewState> {
register(
@ -45,7 +59,17 @@ class ProjectActivity : AppCompatActivity() {
viewHolder = ::ProjectTechnikerViewHolder,
onBindBindViewHolder = { vh, _, text ->
vh.textView.text = text.name
if (adminMode) {
vh.itemView.setOnClickListener {
MaterialDialog(this@ProjectActivity)
.show {
message(0, "Möchtest du \'${text.name}\' entfernen?")
positiveButton(0, "Ja") {
databaseReference.child("techniker").child(text.key).removeValue()
}
negativeButton(0, "Abbrechen")
}
}
}
}
)
@ -53,21 +77,23 @@ class ProjectActivity : AppCompatActivity() {
val listener = object: ChildEventListener {
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
techniker.add(techniker.size, ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString()))
techniker.add(techniker.size, ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString(), snapshot.key!!))
techniker.sortBy { it.name }
recycler_view.scheduleLayoutAnimation()
adapter.notifyDataSetChanged()
showDivider()
techniker_view.text = "Techniker: ${techniker.size}"
}
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {
}
override fun onChildRemoved(snapshot: DataSnapshot) {
techniker.remove(ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString()))
techniker.remove(ProjectTechnikerViewState.ProjectTechniker(snapshot.value.toString(), snapshot.key!!))
recycler_view.scheduleLayoutAnimation()
adapter.notifyDataSetChanged()
emptyCheck()
techniker_view.text = "Techniker: ${techniker.size}"
}
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {
@ -148,9 +174,55 @@ class ProjectActivity : AppCompatActivity() {
}
}
private fun toggleAdminMode() {
if (!adminMode) {
var adminKey = ""
val listener = object: ChildEventListener {
override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
if (snapshot.key == "admin_key") {
adminKey = snapshot.value.toString()
}
}
override fun onChildChanged(snapshot: DataSnapshot, previousChildName: String?) {}
override fun onChildRemoved(snapshot: DataSnapshot) {}
override fun onChildMoved(snapshot: DataSnapshot, previousChildName: String?) {}
override fun onCancelled(error: DatabaseError) {}
}
FirebaseDatabase.getInstance().reference.addChildEventListener(listener)
MaterialDialog(this)
.title(0, "Bitte gebe den Admin-Key ein")
.show {
input(hint = "Admin-Key", waitForPositiveButton = false) { _, inputKey ->
positiveButton {
if (inputKey.toString() == adminKey) {
sharedPref.edit().putBoolean("admin", true).apply()
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
finishAffinity()
} else {
Toasty.error(applicationContext, "Ungültiger Key").show()
}
}
}
positiveButton(0, "Speichern")
}
} else {
sharedPref.edit().putBoolean("admin", false).apply()
val intent = Intent(applicationContext, MainActivity::class.java)
startActivity(intent)
finishAffinity()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
if (adminMode) {
menu.findItem(R.id.action_admin).title = "Admin-Zugriff deaktivieren"
}
return true
}
@ -161,6 +233,7 @@ class ProjectActivity : AppCompatActivity() {
when (item.itemId) {
android.R.id.home -> finish()
R.id.action_rename -> showNameDialog()
R.id.action_admin -> toggleAdminMode()
// R.id.action_icons -> setContentView(AboutIcons(applicationContext, R.drawable::class.java).setTitle("Benutzte Icons").get())
// R.id.action_libraries -> LibsBuilder().start(this)
// R.id.action_privacy_policy ->

@ -7,11 +7,10 @@
android:title="Namen ändern"
app:showAsAction="never" />
<!-- <item-->
<!-- android:id="@+id/action_icons"-->
<!-- android:orderInCategory="100"-->
<!-- android:title="Icon Credits"-->
<!-- app:showAsAction="never" />-->
<item
android:id="@+id/action_admin"
android:title="Admin-Zugang aktivieren"
app:showAsAction="never" />
<item
android:id="@+id/action_about"

@ -1,5 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.about_libraries_version = "8.3.0"
ext.kotlin_version = "1.4.0"
repositories {
google()
@ -7,8 +8,9 @@ buildscript {
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:$about_libraries_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

Loading…
Cancel
Save