Skip to content

Commit

Permalink
edit secret
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky committed Jul 11, 2022
1 parent 5763de5 commit ebf2a59
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "me.lucky.wasted"
minSdk 23
targetSdk 32
versionCode 33
versionName "1.5.4"
versionCode 34
versionName "1.5.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
62 changes: 61 additions & 1 deletion app/src/main/java/me/lucky/wasted/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package me.lucky.wasted

import android.content.ClipData
import android.content.ClipboardManager
import android.content.SharedPreferences
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricPrompt
import androidx.core.content.ContextCompat
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textfield.TextInputLayout

import me.lucky.wasted.databinding.ActivityMainBinding
import me.lucky.wasted.fragment.*
Expand All @@ -15,6 +23,11 @@ open class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var prefs: Preferences
private lateinit var prefsdb: Preferences
private val clipboardManager by lazy { getSystemService(ClipboardManager::class.java) }

private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
prefs.copyTo(prefsdb, key)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -74,6 +87,16 @@ open class MainActivity : AppCompatActivity() {
return true
}

override fun onStart() {
super.onStart()
prefs.registerListener(prefsListener)
}

override fun onStop() {
super.onStop()
prefs.unregisterListener(prefsListener)
}

private fun setup() = binding.apply {
appBar.setNavigationOnClickListener {
drawer.open()
Expand All @@ -88,6 +111,14 @@ open class MainActivity : AppCompatActivity() {
})
true
}
R.id.top_copy -> {
copySecret()
true
}
R.id.top_edit -> {
editSecret()
true
}
else -> false
}
}
Expand All @@ -99,11 +130,13 @@ open class MainActivity : AppCompatActivity() {
}
}

private fun replaceFragment(f: Fragment) =
private fun replaceFragment(f: Fragment) {
binding.appBar.menu.setGroupVisible(R.id.top_group_main, f is MainFragment)
supportFragmentManager
.beginTransaction()
.replace(binding.fragment.id, f)
.commit()
}

private fun getFragment(id: Int) = when (id) {
R.id.nav_main -> MainFragment()
Expand All @@ -113,4 +146,31 @@ open class MainActivity : AppCompatActivity() {
R.id.top_settings -> SettingsFragment()
else -> MainFragment()
}

private fun copySecret() {
clipboardManager.setPrimaryClip(ClipData.newPlainText("", prefs.secret))
Snackbar.make(binding.fragment, R.string.copied_popup, Snackbar.LENGTH_SHORT).show()
}

private fun editSecret() {
val view = layoutInflater.inflate(R.layout.dialog_edit_secret, null)
val secret = view.findViewById<TextInputLayout>(R.id.secret)
val dialog = MaterialAlertDialogBuilder(this)
.setTitle(R.string.edit)
.setView(view)
.setPositiveButton(android.R.string.cancel) { _, _ -> }
.setNegativeButton(android.R.string.ok) { _, _ ->
if (secret.error != null) return@setNegativeButton
prefs.secret = secret.editText?.text?.toString()?.trim() ?: return@setNegativeButton
replaceFragment(MainFragment())
}
.create()
secret.editText?.setText(prefs.secret)
secret.editText?.doAfterTextChanged {
secret.error = if (it?.toString()?.isBlank() == true)
getString(R.string.edit_secret_error) else null
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).isEnabled = secret.error == null
}
dialog.show()
}
}
13 changes: 0 additions & 13 deletions app/src/main/java/me/lucky/wasted/fragment/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package me.lucky.wasted.fragment

import android.app.Activity
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
Expand All @@ -11,7 +9,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import java.util.*

import me.lucky.wasted.Preferences
Expand All @@ -25,7 +22,6 @@ class MainFragment : Fragment() {
private lateinit var ctx: Context
private lateinit var prefs: Preferences
private lateinit var prefsdb: Preferences
private val clipboardManager by lazy { ctx.getSystemService(ClipboardManager::class.java) }
private val admin by lazy { DeviceAdminManager(ctx) }

private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
Expand Down Expand Up @@ -71,10 +67,6 @@ class MainFragment : Fragment() {
}

private fun setup() = binding.apply {
secret.setOnLongClickListener {
copySecret()
true
}
wipeData.setOnCheckedChangeListener { _, isChecked ->
prefs.isWipeData = isChecked
wipeEmbeddedSim.isEnabled = isChecked
Expand All @@ -87,11 +79,6 @@ class MainFragment : Fragment() {
}
}

private fun copySecret() {
clipboardManager.setPrimaryClip(ClipData.newPlainText("", prefs.secret))
Snackbar.make(binding.secret, R.string.copied_popup, Snackbar.LENGTH_SHORT).show()
}

private fun setOn() {
prefs.isEnabled = true
Utils(ctx).setEnabled(true)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_content_copy_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_edit_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
24 changes: 24 additions & 0 deletions app/src/main/res/layout/dialog_edit_secret.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="16dp"
android:paddingHorizontal="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/secret"
app:helperText="@string/edit_secret_helper_text"
app:helperTextEnabled="true"
app:errorEnabled="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/edit_secret_hint" />

</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:checked="true" />

<group
android:id="@+id/nav_group_options"
android:id="@+id/nav_group_triggers"
android:checkableBehavior="all">

<item
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/res/menu/top.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<group
android:id="@+id/top_group_main">

<item
android:id="@+id/top_edit"
android:icon="@drawable/ic_baseline_edit_24"
android:title="@string/edit"
app:showAsAction="ifRoom" />

<item
android:id="@+id/top_copy"
android:icon="@drawable/ic_baseline_content_copy_24"
android:title="@string/top_copy"
app:showAsAction="ifRoom" />

</group>

<item
android:id="@+id/top_settings"
android:icon="@drawable/ic_baseline_settings_24"
android:title="@string/settings"
app:showAsAction="always" />
app:showAsAction="ifRoom" />

</menu>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
<string name="copied_popup">Copied</string>
<string name="main">Main</string>
<string name="settings">Settings</string>
<string name="edit">Edit</string>
<string name="top_copy">Copy</string>
<string name="goto_button">GOTO</string>
<string name="authentication">Authentication</string>
<string name="edit_secret_hint">secret</string>
<string name="edit_secret_helper_text">Use strong enough secret.</string>
<string name="edit_secret_error">Must not be blank!</string>
<string name="trigger_panic_kit_description">Enable panic responder. PanicKit is a collection of tools for creating “panic buttons” that can trigger a system-wide response when the user is in an anxious or dangerous situation. It enables trigger apps and responder apps to safely and easily connect to each other. The user engages with the trigger app when in a panic situation. The responder apps receive that trigger signal, and individually execute the steps that they were configured to do.</string>
<string name="trigger_tile_description">Enable tile service. It is a button in quick settings panel when you swipe from the top of the screen. This button will mimic to the airplane mode.</string>
<string name="trigger_shortcut_description">Enable icon shortcut. It is a button you will see when you make a long tap on the Wasted icon.</string>
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/34.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
edit secret
Binary file modified fastlane/metadata/android/en-US/images/phoneScreenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fastlane/metadata/android/en-US/images/phoneScreenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified fastlane/metadata/android/en-US/images/phoneScreenshots/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ebf2a59

Please sign in to comment.