aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorpacien2018-03-04 19:54:08 +0100
committerpacien2018-03-04 19:54:08 +0100
commit9c987682bde9f532f53f3f1ac3ade7e96a5e2293 (patch)
tree8d1681ff2ecf27d768bec005aec41c9264ec6df9 /app/src
parent1f30a8838d787f31dbc0af83458d73afef104927 (diff)
downloadtincapp-9c987682bde9f532f53f3f1ac3ade7e96a5e2293.tar.gz
Add share button on log view
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt18
-rw-r--r--app/src/main/res/drawable/ic_share_primary_24dp.xml9
-rw-r--r--app/src/main/res/menu/menu_viewlog.xml7
-rw-r--r--app/src/main/res/values/strings.xml1
4 files changed, 33 insertions, 2 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt
index 673dedb..2a56ceb 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/ViewLogActivity.kt
@@ -1,5 +1,6 @@
1package org.pacien.tincapp.activities 1package org.pacien.tincapp.activities
2 2
3import android.content.Intent
3import android.os.Bundle 4import android.os.Bundle
4import android.view.Menu 5import android.view.Menu
5import android.view.MenuItem 6import android.view.MenuItem
@@ -21,8 +22,10 @@ class ViewLogActivity : BaseActivity() {
21 companion object { 22 companion object {
22 private const val LOG_LINES = 250 23 private const val LOG_LINES = 250
23 private const val LOG_LEVEL = 5 24 private const val LOG_LEVEL = 5
24 private const val NEW_LINE = "\n\n" 25 private const val NEW_LINE = "\n"
26 private const val SPACED_NEW_LINE = "\n\n"
25 private const val UPDATE_INTERVAL = 250L // ms 27 private const val UPDATE_INTERVAL = 250L // ms
28 private const val MIME_TYPE = "text/plain"
26 } 29 }
27 30
28 private val log = LinkedList<String>() 31 private val log = LinkedList<String>()
@@ -61,6 +64,17 @@ class ViewLogActivity : BaseActivity() {
61 } 64 }
62 } 65 }
63 66
67 fun share(@Suppress("UNUSED_PARAMETER") menuItem: MenuItem) {
68 synchronized(this) {
69 val logFragment = log.joinToString(NEW_LINE)
70 val shareIntent = Intent(Intent.ACTION_SEND)
71 .setType(MIME_TYPE)
72 .putExtra(Intent.EXTRA_TEXT, logFragment)
73
74 startActivity(Intent.createChooser(shareIntent, resources.getString(R.string.menu_share_log)))
75 }
76 }
77
64 private fun startLogging(level: Int = LOG_LEVEL) { 78 private fun startLogging(level: Int = LOG_LEVEL) {
65 disableUserScroll() 79 disableUserScroll()
66 appendLog(resources.getString(R.string.message_log_level_set, level)) 80 appendLog(resources.getString(R.string.message_log_level_set, level))
@@ -96,7 +110,7 @@ class ViewLogActivity : BaseActivity() {
96 } 110 }
97 111
98 private fun printLog() = synchronized(this) { 112 private fun printLog() = synchronized(this) {
99 log.joinToString(NEW_LINE).let { 113 log.joinToString(SPACED_NEW_LINE).let {
100 logview_text.post { 114 logview_text.post {
101 logview_text.text = it 115 logview_text.text = it
102 logview_frame.post { logview_frame.fullScroll(View.FOCUS_DOWN) } 116 logview_frame.post { logview_frame.fullScroll(View.FOCUS_DOWN) }
diff --git a/app/src/main/res/drawable/ic_share_primary_24dp.xml b/app/src/main/res/drawable/ic_share_primary_24dp.xml
new file mode 100644
index 0000000..6095142
--- /dev/null
+++ b/app/src/main/res/drawable/ic_share_primary_24dp.xml
@@ -0,0 +1,9 @@
1<vector xmlns:android="http://schemas.android.com/apk/res/android"
2 android:width="24dp"
3 android:height="24dp"
4 android:viewportHeight="24.0"
5 android:viewportWidth="24.0">
6 <path
7 android:fillColor="@color/textPrimary"
8 android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
9</vector>
diff --git a/app/src/main/res/menu/menu_viewlog.xml b/app/src/main/res/menu/menu_viewlog.xml
index ee3c60f..397055a 100644
--- a/app/src/main/res/menu/menu_viewlog.xml
+++ b/app/src/main/res/menu/menu_viewlog.xml
@@ -10,4 +10,11 @@
10 android:title="@string/menu_toggle_logging" 10 android:title="@string/menu_toggle_logging"
11 app:showAsAction="ifRoom"/> 11 app:showAsAction="ifRoom"/>
12 12
13 <item
14 android:icon="@drawable/ic_share_primary_24dp"
15 android:onClick="share"
16 android:tint="@color/colorAccent"
17 android:title="@string/menu_share_log"
18 app:showAsAction="ifRoom"/>
19
13</menu> 20</menu>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6eaed13..3301486 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -16,6 +16,7 @@
16 <string name="menu_disconnect">Disconnect</string> 16 <string name="menu_disconnect">Disconnect</string>
17 <string name="menu_show_log">Show log</string> 17 <string name="menu_show_log">Show log</string>
18 <string name="menu_toggle_logging">Toggle logging</string> 18 <string name="menu_toggle_logging">Toggle logging</string>
19 <string name="menu_share_log">Share log</string>
19 20
20 <string name="field_net_name">Tinc network name</string> 21 <string name="field_net_name">Tinc network name</string>
21 <string name="field_node_name">Name of this node</string> 22 <string name="field_node_name">Name of this node</string>