From 9c987682bde9f532f53f3f1ac3ade7e96a5e2293 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 4 Mar 2018 19:54:08 +0100 Subject: Add share button on log view --- .../org/pacien/tincapp/activities/ViewLogActivity.kt | 18 ++++++++++++++++-- app/src/main/res/drawable/ic_share_primary_24dp.xml | 9 +++++++++ app/src/main/res/menu/menu_viewlog.xml | 7 +++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/ic_share_primary_24dp.xml 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 @@ package org.pacien.tincapp.activities +import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -21,8 +22,10 @@ class ViewLogActivity : BaseActivity() { companion object { private const val LOG_LINES = 250 private const val LOG_LEVEL = 5 - private const val NEW_LINE = "\n\n" + private const val NEW_LINE = "\n" + private const val SPACED_NEW_LINE = "\n\n" private const val UPDATE_INTERVAL = 250L // ms + private const val MIME_TYPE = "text/plain" } private val log = LinkedList() @@ -61,6 +64,17 @@ class ViewLogActivity : BaseActivity() { } } + fun share(@Suppress("UNUSED_PARAMETER") menuItem: MenuItem) { + synchronized(this) { + val logFragment = log.joinToString(NEW_LINE) + val shareIntent = Intent(Intent.ACTION_SEND) + .setType(MIME_TYPE) + .putExtra(Intent.EXTRA_TEXT, logFragment) + + startActivity(Intent.createChooser(shareIntent, resources.getString(R.string.menu_share_log))) + } + } + private fun startLogging(level: Int = LOG_LEVEL) { disableUserScroll() appendLog(resources.getString(R.string.message_log_level_set, level)) @@ -96,7 +110,7 @@ class ViewLogActivity : BaseActivity() { } private fun printLog() = synchronized(this) { - log.joinToString(NEW_LINE).let { + log.joinToString(SPACED_NEW_LINE).let { logview_text.post { logview_text.text = it 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 @@ + + + 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 @@ android:title="@string/menu_toggle_logging" app:showAsAction="ifRoom"/> + + 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 @@ Disconnect Show log Toggle logging + Share log Tinc network name Name of this node -- cgit v1.2.3