Skip to content

Commit

Permalink
Improve bug reporting flow
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Mar 7, 2021
1 parent f9091d8 commit 15d7247
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 41 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.hackerchick.raisetoanswer"
minSdkVersion 26
targetSdkVersion 29
versionCode 24
versionName "3.3"
versionCode 25
versionName "3.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -32,5 +33,4 @@

<service android:enabled="true" android:name=".RaiseToAnswerSensorEventListener" />
</application>

</manifest>
170 changes: 135 additions & 35 deletions app/src/main/java/me/hackerchick/raisetoanswer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package me.hackerchick.raisetoanswer

import android.Manifest
import android.R.attr.label
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.*
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Bundle
import android.view.Menu
Expand All @@ -17,6 +14,7 @@ import android.widget.Button
import android.widget.CheckedTextView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.lifecycle.Observer
Expand All @@ -25,6 +23,10 @@ import androidx.lifecycle.Observer
class MainActivity : AppCompatActivity() {
private var PERMISSION_REQUEST_READ_PHONE_STATE = 1

private var mMenu : Menu? = null
private var mTestMode = false
private var mTestRunning = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand Down Expand Up @@ -93,52 +95,56 @@ class MainActivity : AppCompatActivity() {
debugLog.setOnClickListener {
val clipboard: ClipboardManager =
getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("RaiseToAnswer Debug Log", Util.getLog().value!!.joinToString(separator = "\n"))
val clip = ClipData.newPlainText(
"RaiseToAnswer Debug Log", Util.getLog().value!!.joinToString(
separator = "\n"
)
)
clipboard.setPrimaryClip(clip)

Toast.makeText(this, getString(R.string.debug_log_copied_to_clipboard), Toast.LENGTH_LONG).show()
Toast.makeText(
this,
getString(R.string.debug_log_copied_to_clipboard),
Toast.LENGTH_LONG
).show()
}

val testButton: Button = findViewById(R.id.test_button)
testButton.setOnClickListener {
if (!Util.startSensorListener(applicationContext, true)) {
if (!mTestRunning) {
if (!Util.startSensorListener(applicationContext, true)) {
Toast.makeText(
applicationContext,
getString(R.string.enable_at_least_one_feature),
Toast.LENGTH_SHORT
).show()
return@setOnClickListener
}

Toast.makeText(
applicationContext,
getString(R.string.enable_at_least_one_feature),
getString(R.string.test_started),
Toast.LENGTH_SHORT
).show()
return@setOnClickListener
}

Toast.makeText(applicationContext, getString(R.string.test_started), Toast.LENGTH_SHORT).show()
Util.clearLog()
Util.log("TEST STARTED")
}
Util.clearLog()
Util.log("TEST STARTED")

val header: TextView = findViewById(R.id.raise_to_answer_header)
var debugCounter = 0
header.setOnClickListener {
debugCounter += 1

if (debugCounter == 7) {
Toast.makeText(this, getString(R.string.debug_mode_activated), Toast.LENGTH_LONG)
.show()
testButton.visibility = View.VISIBLE
debugLog.visibility = View.VISIBLE

Util.getLog().observe(this, Observer {
try {
debugLog.text = it.reversed().joinToString(separator = "\n")
} catch (ConcurrentModificationException: Exception) {
// We don't care, just skip this update then...
}
})
}
testButton.text = getString(R.string.end_test)

return@setOnClickListener
mTestRunning = true
} else {
endTest()
}
}
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)

showTestMode(mTestMode)
}

override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
Expand All @@ -161,6 +167,8 @@ class MainActivity : AppCompatActivity() {
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
mMenu = menu

val inflater: MenuInflater = menuInflater
inflater.inflate(R.menu.main_menu, menu)
return true
Expand All @@ -177,10 +185,102 @@ class MainActivity : AppCompatActivity() {
startActivity(browserIntent)
true
}
R.id.test_mode -> {
if (!mTestMode) {
enableTestMode(true)
} else {
enableTestMode(false)
}
true
}
else -> super.onOptionsItemSelected(item)
}
}

private fun endTest() {
Util.stopSensorListener(this)

Util.log("TEST ENDED")

AlertDialog.Builder(this)
.setTitle(R.string.test_ended)
.setMessage(R.string.test_succesful_question)
.setPositiveButton(R.string.close, null)
.setNegativeButton(R.string.report_issue) { _, _ ->
val emailDataBuilder = StringBuilder()
emailDataBuilder.append("Product: " + android.os.Build.PRODUCT + "\n")
emailDataBuilder.append("Model: " + android.os.Build.MODEL + "\n")
emailDataBuilder.append("Device: " + android.os.Build.DEVICE + "\n")
emailDataBuilder.append("SDK: " + android.os.Build.VERSION.SDK_INT + "\n")
emailDataBuilder.append("App version: " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")" + "\n")
emailDataBuilder.append("Debug log:" + "\n")
emailDataBuilder.append(
Util.getLog().value!!.joinToString(
separator = "\n"
)
)

val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:")
intent.putExtra(
Intent.EXTRA_EMAIL,
"[email protected]"
)
intent.putExtra(Intent.EXTRA_SUBJECT, "Raise To Answer Debug Log")
intent.putExtra(Intent.EXTRA_TEXT, emailDataBuilder.toString())
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
}
}
.setIcon(android.R.drawable.ic_dialog_info)
.show()

val testButton: Button = findViewById(R.id.test_button)
testButton.text = getString(R.string.start_test)

mTestRunning = false
}

private fun enableTestMode(enable: Boolean) {
val debugLog: TextView = findViewById(R.id.debug_log)
val testButton: Button = findViewById(R.id.test_button)
val menuItem: MenuItem = mMenu!!.findItem(R.id.test_mode)

if (enable) {
menuItem.title = getString(R.string.disable_test_mode)

showTestMode(true)
testButton.visibility = View.VISIBLE
debugLog.visibility = View.VISIBLE

Util.getLog().observe(this, Observer {
try {
debugLog.text = it.reversed().joinToString(separator = "\n")
} catch (ConcurrentModificationException: Exception) {
// We don't care, just skip this update then...
}
})

testButton.text = getString(R.string.start_test)
} else {
menuItem.title = getString(R.string.enable_test_mode)

showTestMode(false)

Util.getLog().removeObservers(this)
}

mTestMode = enable
}

private fun showTestMode(show: Boolean) {
val debugLog: TextView = findViewById(R.id.debug_log)
val testButton: Button = findViewById(R.id.test_button)

testButton.visibility = if (show) View.VISIBLE else View.GONE
debugLog.visibility = if (show) View.VISIBLE else View.GONE
}

private fun setAnswerFeature(value: Boolean, propagate: Boolean) {
val answerFeature: CheckedTextView = findViewById(R.id.feature_answer)
answerFeature.isChecked = value
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/me/hackerchick/raisetoanswer/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Util {
private val debugLogLiveData = MutableLiveData<List<String>>()

fun log(message: String) {
debugLog.add(message)
val timeStampedMessage = System.currentTimeMillis().toString() + ": " + message
debugLog.add(timeStampedMessage)
debugLogLiveData.postValue(debugLog)
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/test"
android:text="@string/start_test"
android:visibility="gone"/>

<TextView
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/menu/main_menu.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/test_mode"
android:title="@string/enable_test_mode" />
<item android:id="@+id/privacy_policy"
android:title="@string/privacy_policy" />
</menu>
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@
<string name="debug_mode_activated">You are now a developer</string>
<string name="debug_log_copied_to_clipboard">Debug log copied to clipboard</string>
<string name="behaviour_vibrate">Vibrate on incoming calls</string>
<string name="enable_test_mode">Enable test mode</string>
<string name="disable_test_mode">Disable test mode</string>
<string name="start_test">Start Test</string>
<string name="end_test">End test</string>
<string name="test_manually_ended">Test was manually ended</string>
<string name="test_ended">Test ended</string>
<string name="test_succesful_question">Was the test succesful?\n\nIf not, you could send the test logs to the developer so she can help figure out what went wrong.</string>
<string name="close">Close</string>
<string name="report_issue">Report issue</string>
</resources>
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/25.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improved bug reporting flow
Fix test state lost on rotation

0 comments on commit 15d7247

Please sign in to comment.