From 328ad552b0b508e08072ebcd9409f6214c748a0d Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 3 Jul 2017 15:45:50 +0200 Subject: Add configure activity, displaying various paths --- .../org/pacien/tincapp/activities/BaseActivity.kt | 19 +++---------- .../pacien/tincapp/activities/ConfigureActivity.kt | 31 ++++++++++++++++++++++ .../org/pacien/tincapp/activities/StartActivity.kt | 18 ++++++------- 3 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt (limited to 'app/src/main/java/org/pacien') diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index 2146cec..274e1ba 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt @@ -1,8 +1,5 @@ package org.pacien.tincapp.activities -import android.content.ClipData -import android.content.ClipboardManager -import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle @@ -45,18 +42,8 @@ abstract class BaseActivity : AppCompatActivity() { .show() } - protected fun openWebsite(@StringRes url: Int) { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(resources.getString(url)))) - } - - protected fun notify(@StringRes msg: Int) { - Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() - } - - protected fun copyIntoClipboard(label: String, str: String) { - val c = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - c.primaryClip = ClipData.newPlainText(label, str) - notify(R.string.message_text_copied) - } + protected fun openWebsite(@StringRes url: Int) = startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(resources.getString(url)))) + protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() + protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() } diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt new file mode 100644 index 0000000..69408d8 --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt @@ -0,0 +1,31 @@ +package org.pacien.tincapp.activities + +import android.os.Bundle +import android.view.View +import kotlinx.android.synthetic.main.base.* +import kotlinx.android.synthetic.main.page_configure.* +import org.pacien.tincapp.R +import org.pacien.tincapp.context.AppPaths + +/** + * @author pacien + */ +class ConfigureActivity : BaseActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + supportActionBar!!.setDisplayHomeAsUpEnabled(true) + layoutInflater.inflate(R.layout.page_configure, main_content) + writeContent() + } + + private fun writeContent() { + text_configuration_directories.text = AppPaths.Storage.values().map { AppPaths.confDir(it) }.joinToString("\n") + text_log_directories.text = AppPaths.Storage.values().map { AppPaths.cacheDir(it) }.joinToString("\n") + text_tinc_binaries.text = listOf(AppPaths.tinc(), AppPaths.tincd()).joinToString("\n") + } + + fun generateConf(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet") + fun joinNetwork(@Suppress("UNUSED_PARAMETER") v: View) = notify("Not implemented yet") + +} diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt index 910b36f..709989b 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt @@ -6,6 +6,8 @@ import android.content.Intent import android.net.VpnService import android.os.Bundle import android.support.v7.app.AlertDialog +import android.view.Menu +import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.EditText @@ -26,6 +28,11 @@ class StartActivity : BaseActivity() { layoutInflater.inflate(R.layout.page_start, main_content) } + override fun onCreateOptionsMenu(m: Menu): Boolean { + menuInflater.inflate(R.menu.menu_start, m) + return super.onCreateOptionsMenu(m) + } + override fun onActivityResult(request: Int, result: Int, data: Intent?) { notify(if (result == Activity.RESULT_OK) R.string.message_vpn_permissions_granted else R.string.message_vpn_permissions_denied) } @@ -45,7 +52,7 @@ class StartActivity : BaseActivity() { i.setHint(R.string.field_net_name) @SuppressLint("InflateParams") - val vg = layoutInflater.inflate(R.layout.dialog_frame, null) as ViewGroup + val vg = layoutInflater.inflate(R.layout.dialog_frame, main_content, false) as ViewGroup vg.addView(i) AlertDialog.Builder(this) @@ -56,14 +63,7 @@ class StartActivity : BaseActivity() { .show() } - fun confDirDialog(@Suppress("UNUSED_PARAMETER") v: View) { - AlertDialog.Builder(this) - .setTitle(R.string.title_tinc_config_dir) - .setMessage("Internal: " + AppPaths.confDir(AppPaths.Storage.INTERNAL) + "\n\n" + - "External: " + AppPaths.confDir(AppPaths.Storage.EXTERNAL)) - .setPositiveButton(R.string.action_close) { _, _ -> /* nop */ } - .show() - } + fun openConfigureActivity(@Suppress("UNUSED_PARAMETER") i: MenuItem) = startActivity(Intent(this, ConfigureActivity::class.java)) private fun startVpn(netName: String) { startService(Intent(this, TincVpnService::class.java).putExtra(TincVpnService.INTENT_EXTRA_NET_CONF, -- cgit v1.2.3