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:
parent
1f5fc5288b
commit
0e307c947a
@ -8,10 +8,10 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.maenle.bump"
|
||||
minSdk 29
|
||||
minSdk 26
|
||||
targetSdk 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode 3
|
||||
versionName "0.1.1"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.maenle.bump.R
|
||||
import com.maenle.bump.databinding.ActivityMainBinding
|
||||
import com.maenle.bump.util.BumpProcessor
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@ -38,8 +39,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -48,9 +48,14 @@ class MainActivity : AppCompatActivity() {
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
|
@ -32,6 +32,11 @@ class BumpProcessor constructor(context: Context) {
|
||||
INSTANCE = it
|
||||
}
|
||||
}
|
||||
fun clearLog(context: Context) {
|
||||
val logFile = File(context.filesDir, ".bump_log")
|
||||
logFile.writeText("")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun decryptMessage(message: String): String {
|
||||
@ -39,6 +44,7 @@ class BumpProcessor constructor(context: Context) {
|
||||
}
|
||||
|
||||
private fun updateLog(context: Context, list: JSONArray) {
|
||||
log = getLog(context)
|
||||
for(i in 0 until list.length()) {
|
||||
var exists = false
|
||||
for(j in 0 until log.length()) {
|
||||
@ -86,12 +92,6 @@ class BumpProcessor constructor(context: Context) {
|
||||
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 {
|
||||
return if(!checkCodeValidity(newCode)) {
|
||||
false
|
||||
@ -109,7 +109,7 @@ class BumpProcessor constructor(context: Context) {
|
||||
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 log = JSONArray()
|
||||
!logFile.exists().let {
|
||||
|
@ -2,6 +2,11 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
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
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
|
@ -1,6 +1,7 @@
|
||||
<resources>
|
||||
<string name="app_name">Bump</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_clear_log">Clear Log</string>
|
||||
<!-- Strings used for fragments for navigation -->
|
||||
<string name="main_fragment_label">Bump</string>
|
||||
<string name="second_fragment_label">Second Fragment</string>
|
||||
|
Loading…
Reference in New Issue
Block a user