From 2571919913f44772c40929c24c7949a2eecdec3a Mon Sep 17 00:00:00 2001
From: pacien
Date: Wed, 22 Aug 2018 00:46:07 +0200
Subject: Use custom base fragment and switch to embedded qr-code scanner
---
app/build.gradle | 2 +-
.../org/pacien/tincapp/activities/BaseFragment.kt | 36 ++++++++++++++++++++++
.../activities/common/FragmentListPagerAdapter.kt | 4 +--
.../activities/configure/PathInfoFragment.kt | 4 +--
.../tincapp/activities/configure/ToolsFragment.kt | 4 +--
.../activities/configure/tools/JoinNetworkTool.kt | 6 ++--
.../activities/start/NetworkListFragment.kt | 4 +--
.../status/networkinfo/NetworkInfoFragment.kt | 4 +--
.../activities/status/nodes/NodeListFragment.kt | 7 ++---
readme.md | 2 +-
10 files changed, 54 insertions(+), 19 deletions(-)
create mode 100644 app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt
diff --git a/app/build.gradle b/app/build.gradle
index 50fdddc..2c9c6b3 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -79,7 +79,7 @@ dependencies {
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "com.android.support:support-compat:27.1.1"
implementation 'com.android.support:design:27.1.1'
- implementation 'com.google.zxing:android-integration:3.3.0'
+ implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'org.bouncycastle:bcpkix-jdk15on:1.59'
implementation 'org.slf4j:slf4j-api:1.7.25'
//noinspection GradleDependency: inspection tool bug for logback-android
diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt
new file mode 100644
index 0000000..685950f
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/activities/BaseFragment.kt
@@ -0,0 +1,36 @@
+/*
+ * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
+ * Copyright (C) 2017-2018 Pacien TRAN-GIRARD
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package org.pacien.tincapp.activities
+
+import android.support.annotation.LayoutRes
+import android.support.v4.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import kotlinx.android.synthetic.main.base_activity.*
+
+/**
+ * @author pacien
+ */
+abstract class BaseFragment : Fragment() {
+ private val rootView by lazy { base_activity_frame!! }
+
+ fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, rootView, false)!!
+ fun inflate(inflateFunc: (LayoutInflater, ViewGroup?, Boolean) -> View) = inflateFunc(layoutInflater, rootView, false)
+}
diff --git a/app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt b/app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt
index e4063bf..c55e889 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt
@@ -18,16 +18,16 @@
package org.pacien.tincapp.activities.common
-import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
+import org.pacien.tincapp.activities.BaseFragment
import org.pacien.tincapp.context.App
/**
* @param pages ordered list of title and fragment pairs
* @author pacien
*/
-class FragmentListPagerAdapter(private val pages: List>,
+class FragmentListPagerAdapter(private val pages: List>,
fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) {
private val resources by lazy { App.getResources() }
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt
index dae4413..57a6bee 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/PathInfoFragment.kt
@@ -18,18 +18,18 @@
package org.pacien.tincapp.activities.configure
-import android.app.Fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import org.pacien.tincapp.activities.BaseFragment
import org.pacien.tincapp.context.AppPaths
import org.pacien.tincapp.databinding.ConfigureToolsPathInfoFragmentBinding
/**
* @author pacien
*/
-class PathInfoFragment : Fragment() {
+class PathInfoFragment : BaseFragment() {
private val appPaths = AppPaths
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/ToolsFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/ToolsFragment.kt
index 0ad2f19..714a7ae 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/ToolsFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/ToolsFragment.kt
@@ -18,13 +18,13 @@
package org.pacien.tincapp.activities.configure
-import android.app.Fragment
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.pacien.tincapp.activities.BaseActivity
+import org.pacien.tincapp.activities.BaseFragment
import org.pacien.tincapp.activities.configure.tools.EncryptDecryptPrivateKeysTool
import org.pacien.tincapp.activities.configure.tools.GenerateConfigTool
import org.pacien.tincapp.activities.configure.tools.JoinNetworkTool
@@ -33,7 +33,7 @@ import org.pacien.tincapp.databinding.ConfigureToolsFragmentBinding
/**
* @author pacien
*/
-class ToolsFragment : Fragment() {
+class ToolsFragment : BaseFragment() {
private val parentActivity by lazy { activity as BaseActivity }
private val generateConfigTool by lazy { GenerateConfigTool(parentActivity) }
private val joinNetworkTool by lazy { JoinNetworkTool(this, parentActivity) }
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkTool.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkTool.kt
index 82a4380..6656d86 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkTool.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/configure/tools/JoinNetworkTool.kt
@@ -18,7 +18,6 @@
package org.pacien.tincapp.activities.configure.tools
-import android.app.Fragment
import android.content.Intent
import android.view.View
import com.google.zxing.integration.android.IntentIntegrator
@@ -26,6 +25,7 @@ import com.google.zxing.integration.android.IntentResult
import kotlinx.android.synthetic.main.configure_tools_dialog_network_join.view.*
import org.pacien.tincapp.R
import org.pacien.tincapp.activities.BaseActivity
+import org.pacien.tincapp.activities.BaseFragment
import org.pacien.tincapp.commands.Tinc
import org.pacien.tincapp.commands.TincApp
import org.pacien.tincapp.databinding.ConfigureToolsDialogNetworkJoinBinding
@@ -33,8 +33,8 @@ import org.pacien.tincapp.databinding.ConfigureToolsDialogNetworkJoinBinding
/**
* @author pacien
*/
-class JoinNetworkTool(parentFragment: Fragment, private val parentActivity: BaseActivity) : ConfigurationTool(parentActivity) {
- private val scanner by lazy { IntentIntegrator(parentFragment) }
+class JoinNetworkTool(parentFragment: BaseFragment, private val parentActivity: BaseActivity) : ConfigurationTool(parentActivity) {
+ private val scanner by lazy { IntentIntegrator.forSupportFragment(parentFragment) }
private var joinDialog: View? = null
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
diff --git a/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt
index f255f53..2c4bae1 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/start/NetworkListFragment.kt
@@ -20,7 +20,6 @@ package org.pacien.tincapp.activities.start
import android.arch.lifecycle.Observer
import android.os.Bundle
-import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -29,6 +28,7 @@ import android.widget.ArrayAdapter
import android.widget.TextView
import kotlinx.android.synthetic.main.start_network_list.*
import org.pacien.tincapp.R
+import org.pacien.tincapp.activities.BaseFragment
import org.pacien.tincapp.context.AppPaths
import org.pacien.tincapp.extensions.hideBottomSeparator
import org.pacien.tincapp.extensions.setElements
@@ -36,7 +36,7 @@ import org.pacien.tincapp.extensions.setElements
/**
* @author pacien
*/
-class NetworkListFragment : Fragment() {
+class NetworkListFragment : BaseFragment() {
private val appPaths = AppPaths
private val networkListViewModel by lazy { NetworkListViewModel() }
private val networkListAdapter by lazy { ArrayAdapter(context, R.layout.start_network_list_item) }
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/NetworkInfoFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/NetworkInfoFragment.kt
index 5aa37a8..0129b75 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/NetworkInfoFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/status/networkinfo/NetworkInfoFragment.kt
@@ -19,17 +19,17 @@
package org.pacien.tincapp.activities.status.networkinfo
import android.os.Bundle
-import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import org.pacien.tincapp.activities.BaseFragment
import org.pacien.tincapp.databinding.StatusNetworkInfoFragmentBinding
import org.pacien.tincapp.service.TincVpnService
/**
* @author pacien
*/
-class NetworkInfoFragment : Fragment() {
+class NetworkInfoFragment : BaseFragment() {
private val vpnService by lazy { TincVpnService }
private val interfaceConfiguration by lazy { vpnService.getCurrentInterfaceCfg() }
private val listFormatter = VpnInterfaceConfigurationFormatter
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt
index cf1c1bc..4d245ef 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/status/nodes/NodeListFragment.kt
@@ -21,15 +21,14 @@ package org.pacien.tincapp.activities.status.nodes
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
-import android.support.v4.app.Fragment
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
-import kotlinx.android.synthetic.main.base_activity.*
import kotlinx.android.synthetic.main.status_node_info_dialog.view.*
import kotlinx.android.synthetic.main.status_node_list_fragment.*
import org.pacien.tincapp.R
+import org.pacien.tincapp.activities.BaseFragment
import org.pacien.tincapp.commands.Tinc
import org.pacien.tincapp.extensions.hideBottomSeparator
import org.pacien.tincapp.extensions.hideTopSeparator
@@ -39,7 +38,7 @@ import org.pacien.tincapp.service.TincVpnService
/**
* @author pacien
*/
-class NodeListFragment : Fragment() {
+class NodeListFragment : BaseFragment() {
private val vpnService = TincVpnService
private val tincCtl = Tinc
private val netName by lazy { vpnService.getCurrentNetName()!! }
@@ -67,7 +66,7 @@ class NodeListFragment : Fragment() {
showNodeInfo(nodeInfo.name)
private fun showNodeInfo(nodeName: String) {
- val dialogTextView = layoutInflater.inflate(R.layout.status_node_info_dialog, base_activity_frame, false)
+ val dialogTextView = inflate(R.layout.status_node_info_dialog)
AlertDialog.Builder(context!!)
.setTitle(R.string.status_node_info_dialog_title)
diff --git a/readme.md b/readme.md
index 58f61a6..c9a23da 100644
--- a/readme.md
+++ b/readme.md
@@ -50,7 +50,7 @@ Builds of this software embed and make use of the following libraries:
* Kotlin Standard Library, licensed under the Apache v2.0 License
* streamsupport-cfuture, licensed under the GNU General Public License v2.0
* Material Components for Android, licensed under the Apache v2.0 License
-* ZXing Android Integration, licensed under the Apache v2.0 License
+* ZXing Android Embedded, licensed under the Apache v2.0 License
* Bouncy Castle PKIX, licensed under the Bouncy Castle License
* SLF4J, licensed under the MIT License
* logback-android, licensed under the GNU Lesser General Public License v2.1
--
cgit v1.2.3