Skip to content

Commit

Permalink
Allow toggling autmatic error reporting.
Browse files Browse the repository at this point in the history
  • Loading branch information
DDoSolitary committed Nov 19, 2020
1 parent 8ed2f33 commit 5a84f97
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.preference:preference-ktx:1.1.1"
implementation 'com.google.android.material:material:1.2.1'
implementation 'org.sufficientlysecure:sshauthentication-api:1.0'
implementation 'org.sufficientlysecure:openpgp-api:12.0'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
android:taskAffinity=""
android:excludeFromRecents="true"
android:theme="@style/AppTheme.Dialog" />
<activity
android:name=".SettingsActivity"
android:label="@string/text_settings"
android:theme="@style/AppTheme" />

<meta-data
android:name="com.bugsnag.android.API_KEY"
Expand Down
40 changes: 36 additions & 4 deletions app/src/main/java/org/ddosolitary/okcagent/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.*
import android.widget.Button
import android.widget.ImageButton
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.ddosolitary.okcagent.gpg.GpgApi
import org.ddosolitary.okcagent.ssh.SshApi
import org.ddosolitary.okcagent.ssh.SshKeyInfo
Expand Down Expand Up @@ -157,6 +158,38 @@ class MainActivity : AppCompatActivity() {
} else {
textGpg.text = getString(R.string.text_has_gpg_key).format(gpgKeyId)
}

val settingsPref = PreferenceManager.getDefaultSharedPreferences(this)
if (!settingsPref.contains(getString(R.string.key_error_reporting))) {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.text_error_reporting)
.setMessage(R.string.text_error_reporting_message)
.setPositiveButton(R.string.button_yes) { _, _ ->
settingsPref.edit().run {
putBoolean(getString(R.string.key_error_reporting), true)
apply()
}
}
.setNegativeButton(R.string.button_no) { _, _ ->
settingsPref.edit().run {
putBoolean(getString(R.string.key_error_reporting), false)
apply()
}
}
.show()
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.item_settings -> startActivity(Intent(this, SettingsActivity::class.java))
}
return true
}

override fun onResume() {
Expand Down Expand Up @@ -197,7 +230,6 @@ class MainActivity : AppCompatActivity() {
super.onDestroy()
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK) {
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/org/ddosolitary/okcagent/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package org.ddosolitary.okcagent

import android.app.Application
import androidx.preference.PreferenceManager
import com.bugsnag.android.Bugsnag

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Bugsnag.start(this)
Bugsnag.start(this).addOnError {
try {
val pref = PreferenceManager.getDefaultSharedPreferences(this)
return@addOnError pref.getBoolean(getString(R.string.key_error_reporting), false)
} catch(e: Exception) {
return@addOnError false
}
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/org/ddosolitary/okcagent/SettingsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.ddosolitary.okcagent

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
setSupportActionBar(findViewById(R.id.toolbar))
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/org/ddosolitary/okcagent/SettingsFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.ddosolitary.okcagent

import android.os.Bundle
import androidx.preference.PreferenceFragmentCompat

class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.pref_screen_settings, rootKey)
}
}
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_bug_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z" />
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
</vector>
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="enterAlways" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_view_settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="org.ddosolitary.okcagent.SettingsFragment"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
9 changes: 9 additions & 0 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/item_settings"
android:icon="@drawable/ic_settings"
android:title="@string/text_settings"
app:showAsAction="always" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="key_error_reporting" translatable="false">ERROR_REPORTING</string>
<string name="key_gpg_key" translatable="false">GPG_KEY_ID</string>
<string name="key_ssh_keys" translatable="false">SSH_KEYS</string>
<string name="channel_id_auth" translatable="false">NOTIFICATION_CHANNEL_AUTH</string>
Expand Down
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 @@ -2,8 +2,10 @@
<string name="app_name">OkcAgent</string>
<string name="button_add_ssh_key">Add SSH Key</string>
<string name="button_install">Install Now</string>
<string name="button_no">No</string>
<string name="button_ok">OK</string>
<string name="button_remove">Remove</string>
<string name="button_yes">Yes</string>
<string name="button_select_gpg_key">Select GPG Key</string>
<string name="channel_auth">Authorization requests</string>
<string name="channel_error">Errors</string>
Expand All @@ -29,10 +31,13 @@
<string name="notification_ssh_content">Serving SSH agent requests&#8230;</string>
<string name="notification_ssh_title">SSH Agent Service</string>
<string name="text_error">Error</string>
<string name="text_error_reporting">Automatic error reporting</string>
<string name="text_error_reporting_message">This app uses the error reporting tools from Bugsnag, which will automatically send error reports to Bugsnag\'s servers when an error occurs or the app crashes. The reports contains some technical information to help the developer to diagnose and fix the errors. No personally identifiable information is collected.\nDo you want to enable automatic error reporting? You can always toggle this feature in settings later.</string>
<string name="text_has_gpg_key">GPG key selected: 0x<xliff:g>%016X</xliff:g></string>
<string name="text_no_gpg_key">No valid GPG key selected.</string>
<string name="text_no_provider">The OpenKeychain app, which this app relies upon, is not installed on this device. You need to install OpenKeychain before being able to use this app.</string>
<string name="text_no_ssh_key">No valid SSH key selected.</string>
<string name="text_settings">Settings</string>
<string name="text_terminate">Terminate</string>
<string name="text_waiting_provider">Waiting for crypto provider&#8230;</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/xml/pref_screen_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreferenceCompat
app:key="@string/key_error_reporting"
app:icon="@drawable/ic_bug_report"
app:title="@string/text_error_reporting" />
</androidx.preference.PreferenceScreen>

0 comments on commit 5a84f97

Please sign in to comment.