adds clear log button to menu

- clear log now static function, with
  the log being updated from file
  every time the update function is called
- menu actions always act from main activity
  so the menu isn't able to use the existing
  bump instance
This commit is contained in:
2022-02-06 23:50:38 +01:00
parent 1f5fc5288b
commit 0e307c947a
5 changed files with 24 additions and 13 deletions

View File

@ -8,10 +8,10 @@ android {
defaultConfig { defaultConfig {
applicationId "com.maenle.bump" applicationId "com.maenle.bump"
minSdk 29 minSdk 26
targetSdk 30 targetSdk 30
versionCode 1 versionCode 3
versionName "1.0" versionName "0.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -12,6 +12,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import com.maenle.bump.R import com.maenle.bump.R
import com.maenle.bump.databinding.ActivityMainBinding import com.maenle.bump.databinding.ActivityMainBinding
import com.maenle.bump.util.BumpProcessor
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@ -38,8 +39,7 @@ class MainActivity : AppCompatActivity() {
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { 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)
// menuInflater.inflate(R.menu.menu_main, menu)
return true return true
} }
@ -48,9 +48,14 @@ class MainActivity : AppCompatActivity() {
// automatically handle clicks on the Home/Up button, so long // automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml. // as you specify a parent activity in AndroidManifest.xml.
return when (item.itemId) { return when (item.itemId) {
R.id.action_settings -> true R.id.action_settings -> {true}
R.id.action_clear_log -> {
BumpProcessor.clearLog(applicationContext)
true
}
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
} }
override fun onSupportNavigateUp(): Boolean { override fun onSupportNavigateUp(): Boolean {

View File

@ -32,6 +32,11 @@ class BumpProcessor constructor(context: Context) {
INSTANCE = it INSTANCE = it
} }
} }
fun clearLog(context: Context) {
val logFile = File(context.filesDir, ".bump_log")
logFile.writeText("")
}
} }
fun decryptMessage(message: String): String { fun decryptMessage(message: String): String {
@ -39,6 +44,7 @@ class BumpProcessor constructor(context: Context) {
} }
private fun updateLog(context: Context, list: JSONArray) { private fun updateLog(context: Context, list: JSONArray) {
log = getLog(context)
for(i in 0 until list.length()) { for(i in 0 until list.length()) {
var exists = false var exists = false
for(j in 0 until log.length()) { for(j in 0 until log.length()) {
@ -86,12 +92,6 @@ class BumpProcessor constructor(context: Context) {
logFile.appendText(line.toString() + "\n") logFile.appendText(line.toString() + "\n")
} }
private fun clearLog(context: Context) {
val logFile = File(context.filesDir, ".bump_log")
logFile.writeText("")
log = JSONArray("[]")
}
fun addSecret(context: Context, newCode: String): Boolean { fun addSecret(context: Context, newCode: String): Boolean {
return if(!checkCodeValidity(newCode)) { return if(!checkCodeValidity(newCode)) {
false false
@ -109,7 +109,7 @@ class BumpProcessor constructor(context: Context) {
return newCode.length == validChars && newCode.length >= 32 return newCode.length == validChars && newCode.length >= 32
} }
fun getLog(context: Context): JSONArray { private fun getLog(context: Context): JSONArray {
val logFile = File(context.filesDir, ".bump_log") val logFile = File(context.filesDir, ".bump_log")
val log = JSONArray() val log = JSONArray()
!logFile.exists().let { !logFile.exists().let {

View File

@ -2,6 +2,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context="com.maenle.bump.ui.MainActivity"> tools:context="com.maenle.bump.ui.MainActivity">
<item
android:id="@+id/action_clear_log"
android:orderInCategory="100"
android:title="@string/action_clear_log"
app:showAsAction="never" />
<item <item
android:id="@+id/action_settings" android:id="@+id/action_settings"
android:orderInCategory="100" android:orderInCategory="100"

View File

@ -1,6 +1,7 @@
<resources> <resources>
<string name="app_name">Bump</string> <string name="app_name">Bump</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="action_clear_log">Clear Log</string>
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->
<string name="main_fragment_label">Bump</string> <string name="main_fragment_label">Bump</string>
<string name="second_fragment_label">Second Fragment</string> <string name="second_fragment_label">Second Fragment</string>