Skip to content

Commit 15d7247

Browse files
Improve bug reporting flow
1 parent f9091d8 commit 15d7247

File tree

8 files changed

+155
-41
lines changed

8 files changed

+155
-41
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "me.hackerchick.raisetoanswer"
1111
minSdkVersion 26
1212
targetSdkVersion 29
13-
versionCode 24
14-
versionName "3.3"
13+
versionCode 25
14+
versionName "3.4"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
android:label="@string/app_name"
1717
android:supportsRtl="true"
1818
android:theme="@style/AppTheme">
19-
<activity android:name=".MainActivity">
19+
<activity android:name=".MainActivity"
20+
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden">
2021
<intent-filter>
2122
<action android:name="android.intent.action.MAIN" />
2223

@@ -32,5 +33,4 @@
3233

3334
<service android:enabled="true" android:name=".RaiseToAnswerSensorEventListener" />
3435
</application>
35-
3636
</manifest>

app/src/main/java/me/hackerchick/raisetoanswer/MainActivity.kt

Lines changed: 135 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package me.hackerchick.raisetoanswer
22

33
import android.Manifest
4-
import android.R.attr.label
5-
import android.content.ClipData
6-
import android.content.ClipboardManager
7-
import android.content.Context
8-
import android.content.Intent
4+
import android.content.*
95
import android.content.pm.PackageManager
6+
import android.content.res.Configuration
107
import android.net.Uri
118
import android.os.Bundle
129
import android.view.Menu
@@ -17,6 +14,7 @@ import android.widget.Button
1714
import android.widget.CheckedTextView
1815
import android.widget.TextView
1916
import android.widget.Toast
17+
import androidx.appcompat.app.AlertDialog
2018
import androidx.appcompat.app.AppCompatActivity
2119
import androidx.core.app.ActivityCompat
2220
import androidx.lifecycle.Observer
@@ -25,6 +23,10 @@ import androidx.lifecycle.Observer
2523
class MainActivity : AppCompatActivity() {
2624
private var PERMISSION_REQUEST_READ_PHONE_STATE = 1
2725

26+
private var mMenu : Menu? = null
27+
private var mTestMode = false
28+
private var mTestRunning = false
29+
2830
override fun onCreate(savedInstanceState: Bundle?) {
2931
super.onCreate(savedInstanceState)
3032
setContentView(R.layout.activity_main)
@@ -93,52 +95,56 @@ class MainActivity : AppCompatActivity() {
9395
debugLog.setOnClickListener {
9496
val clipboard: ClipboardManager =
9597
getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
96-
val clip = ClipData.newPlainText("RaiseToAnswer Debug Log", Util.getLog().value!!.joinToString(separator = "\n"))
98+
val clip = ClipData.newPlainText(
99+
"RaiseToAnswer Debug Log", Util.getLog().value!!.joinToString(
100+
separator = "\n"
101+
)
102+
)
97103
clipboard.setPrimaryClip(clip)
98104

99-
Toast.makeText(this, getString(R.string.debug_log_copied_to_clipboard), Toast.LENGTH_LONG).show()
105+
Toast.makeText(
106+
this,
107+
getString(R.string.debug_log_copied_to_clipboard),
108+
Toast.LENGTH_LONG
109+
).show()
100110
}
101111

102112
val testButton: Button = findViewById(R.id.test_button)
103113
testButton.setOnClickListener {
104-
if (!Util.startSensorListener(applicationContext, true)) {
114+
if (!mTestRunning) {
115+
if (!Util.startSensorListener(applicationContext, true)) {
116+
Toast.makeText(
117+
applicationContext,
118+
getString(R.string.enable_at_least_one_feature),
119+
Toast.LENGTH_SHORT
120+
).show()
121+
return@setOnClickListener
122+
}
123+
105124
Toast.makeText(
106125
applicationContext,
107-
getString(R.string.enable_at_least_one_feature),
126+
getString(R.string.test_started),
108127
Toast.LENGTH_SHORT
109128
).show()
110-
return@setOnClickListener
111-
}
112129

113-
Toast.makeText(applicationContext, getString(R.string.test_started), Toast.LENGTH_SHORT).show()
114-
Util.clearLog()
115-
Util.log("TEST STARTED")
116-
}
130+
Util.clearLog()
131+
Util.log("TEST STARTED")
117132

118-
val header: TextView = findViewById(R.id.raise_to_answer_header)
119-
var debugCounter = 0
120-
header.setOnClickListener {
121-
debugCounter += 1
122-
123-
if (debugCounter == 7) {
124-
Toast.makeText(this, getString(R.string.debug_mode_activated), Toast.LENGTH_LONG)
125-
.show()
126-
testButton.visibility = View.VISIBLE
127-
debugLog.visibility = View.VISIBLE
128-
129-
Util.getLog().observe(this, Observer {
130-
try {
131-
debugLog.text = it.reversed().joinToString(separator = "\n")
132-
} catch (ConcurrentModificationException: Exception) {
133-
// We don't care, just skip this update then...
134-
}
135-
})
136-
}
133+
testButton.text = getString(R.string.end_test)
137134

138-
return@setOnClickListener
135+
mTestRunning = true
136+
} else {
137+
endTest()
138+
}
139139
}
140140
}
141141

142+
override fun onConfigurationChanged(newConfig: Configuration) {
143+
super.onConfigurationChanged(newConfig)
144+
145+
showTestMode(mTestMode)
146+
}
147+
142148
override fun onRequestPermissionsResult(
143149
requestCode: Int,
144150
permissions: Array<String>,
@@ -161,6 +167,8 @@ class MainActivity : AppCompatActivity() {
161167
}
162168

163169
override fun onCreateOptionsMenu(menu: Menu): Boolean {
170+
mMenu = menu
171+
164172
val inflater: MenuInflater = menuInflater
165173
inflater.inflate(R.menu.main_menu, menu)
166174
return true
@@ -177,10 +185,102 @@ class MainActivity : AppCompatActivity() {
177185
startActivity(browserIntent)
178186
true
179187
}
188+
R.id.test_mode -> {
189+
if (!mTestMode) {
190+
enableTestMode(true)
191+
} else {
192+
enableTestMode(false)
193+
}
194+
true
195+
}
180196
else -> super.onOptionsItemSelected(item)
181197
}
182198
}
183199

200+
private fun endTest() {
201+
Util.stopSensorListener(this)
202+
203+
Util.log("TEST ENDED")
204+
205+
AlertDialog.Builder(this)
206+
.setTitle(R.string.test_ended)
207+
.setMessage(R.string.test_succesful_question)
208+
.setPositiveButton(R.string.close, null)
209+
.setNegativeButton(R.string.report_issue) { _, _ ->
210+
val emailDataBuilder = StringBuilder()
211+
emailDataBuilder.append("Product: " + android.os.Build.PRODUCT + "\n")
212+
emailDataBuilder.append("Model: " + android.os.Build.MODEL + "\n")
213+
emailDataBuilder.append("Device: " + android.os.Build.DEVICE + "\n")
214+
emailDataBuilder.append("SDK: " + android.os.Build.VERSION.SDK_INT + "\n")
215+
emailDataBuilder.append("App version: " + BuildConfig.VERSION_NAME + " (" + BuildConfig.VERSION_CODE + ")" + "\n")
216+
emailDataBuilder.append("Debug log:" + "\n")
217+
emailDataBuilder.append(
218+
Util.getLog().value!!.joinToString(
219+
separator = "\n"
220+
)
221+
)
222+
223+
val intent = Intent(Intent.ACTION_SENDTO)
224+
intent.data = Uri.parse("mailto:")
225+
intent.putExtra(
226+
Intent.EXTRA_EMAIL,
227+
228+
)
229+
intent.putExtra(Intent.EXTRA_SUBJECT, "Raise To Answer Debug Log")
230+
intent.putExtra(Intent.EXTRA_TEXT, emailDataBuilder.toString())
231+
if (intent.resolveActivity(packageManager) != null) {
232+
startActivity(intent)
233+
}
234+
}
235+
.setIcon(android.R.drawable.ic_dialog_info)
236+
.show()
237+
238+
val testButton: Button = findViewById(R.id.test_button)
239+
testButton.text = getString(R.string.start_test)
240+
241+
mTestRunning = false
242+
}
243+
244+
private fun enableTestMode(enable: Boolean) {
245+
val debugLog: TextView = findViewById(R.id.debug_log)
246+
val testButton: Button = findViewById(R.id.test_button)
247+
val menuItem: MenuItem = mMenu!!.findItem(R.id.test_mode)
248+
249+
if (enable) {
250+
menuItem.title = getString(R.string.disable_test_mode)
251+
252+
showTestMode(true)
253+
testButton.visibility = View.VISIBLE
254+
debugLog.visibility = View.VISIBLE
255+
256+
Util.getLog().observe(this, Observer {
257+
try {
258+
debugLog.text = it.reversed().joinToString(separator = "\n")
259+
} catch (ConcurrentModificationException: Exception) {
260+
// We don't care, just skip this update then...
261+
}
262+
})
263+
264+
testButton.text = getString(R.string.start_test)
265+
} else {
266+
menuItem.title = getString(R.string.enable_test_mode)
267+
268+
showTestMode(false)
269+
270+
Util.getLog().removeObservers(this)
271+
}
272+
273+
mTestMode = enable
274+
}
275+
276+
private fun showTestMode(show: Boolean) {
277+
val debugLog: TextView = findViewById(R.id.debug_log)
278+
val testButton: Button = findViewById(R.id.test_button)
279+
280+
testButton.visibility = if (show) View.VISIBLE else View.GONE
281+
debugLog.visibility = if (show) View.VISIBLE else View.GONE
282+
}
283+
184284
private fun setAnswerFeature(value: Boolean, propagate: Boolean) {
185285
val answerFeature: CheckedTextView = findViewById(R.id.feature_answer)
186286
answerFeature.isChecked = value

app/src/main/java/me/hackerchick/raisetoanswer/Util.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class Util {
1717
private val debugLogLiveData = MutableLiveData<List<String>>()
1818

1919
fun log(message: String) {
20-
debugLog.add(message)
20+
val timeStampedMessage = System.currentTimeMillis().toString() + ": " + message
21+
debugLog.add(timeStampedMessage)
2122
debugLogLiveData.postValue(debugLog)
2223
}
2324

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
android:layout_width="wrap_content"
149149
android:layout_height="wrap_content"
150150
android:layout_gravity="center"
151-
android:text="@string/test"
151+
android:text="@string/start_test"
152152
android:visibility="gone"/>
153153

154154
<TextView
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:id="@+id/test_mode"
4+
android:title="@string/enable_test_mode" />
35
<item android:id="@+id/privacy_policy"
46
android:title="@string/privacy_policy" />
57
</menu>

app/src/main/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@
2929
<string name="debug_mode_activated">You are now a developer</string>
3030
<string name="debug_log_copied_to_clipboard">Debug log copied to clipboard</string>
3131
<string name="behaviour_vibrate">Vibrate on incoming calls</string>
32+
<string name="enable_test_mode">Enable test mode</string>
33+
<string name="disable_test_mode">Disable test mode</string>
34+
<string name="start_test">Start Test</string>
35+
<string name="end_test">End test</string>
36+
<string name="test_manually_ended">Test was manually ended</string>
37+
<string name="test_ended">Test ended</string>
38+
<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>
39+
<string name="close">Close</string>
40+
<string name="report_issue">Report issue</string>
3241
</resources>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improved bug reporting flow
2+
Fix test state lost on rotation

0 commit comments

Comments
 (0)