From 8c47b9d6947a3ff4f75842f874b882471efcab76 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 20 Aug 2018 17:05:52 +0200 Subject: Generify fragment pager adapter --- .../activities/common/FragmentListPagerAdapter.kt | 38 ++++++++++++++++++++ .../tincapp/activities/status/StatusActivity.kt | 10 +++++- .../status/StatusFragmentPagerAdapter.kt | 41 ---------------------- 3 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt delete mode 100644 app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt (limited to 'app') 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 new file mode 100644 index 0000000..e4063bf --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt @@ -0,0 +1,38 @@ +/* + * 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.common + +import android.support.v4.app.Fragment +import android.support.v4.app.FragmentManager +import android.support.v4.app.FragmentPagerAdapter +import org.pacien.tincapp.context.App + +/** + * @param pages ordered list of title and fragment pairs + * @author pacien + */ +class FragmentListPagerAdapter(private val pages: List>, + fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) { + + private val resources by lazy { App.getResources() } + + override fun getPageTitle(position: Int) = resources.getString(pages[position].first)!! + override fun getItem(position: Int) = pages[position].second + override fun getCount() = pages.size +} diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt index 6627b61..f47df6c 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt @@ -26,8 +26,11 @@ import android.view.MenuItem import kotlinx.android.synthetic.main.status_activity.* import org.pacien.tincapp.R import org.pacien.tincapp.activities.BaseActivity +import org.pacien.tincapp.activities.common.FragmentListPagerAdapter import org.pacien.tincapp.activities.common.ProgressModal import org.pacien.tincapp.activities.start.StartActivity +import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment +import org.pacien.tincapp.activities.status.nodes.NodeListFragment import org.pacien.tincapp.activities.viewlog.ViewLogActivity import org.pacien.tincapp.intent.Actions import org.pacien.tincapp.intent.BroadcastMapper @@ -39,8 +42,13 @@ import org.pacien.tincapp.service.TincVpnService class StatusActivity : BaseActivity() { private val vpnService by lazy { TincVpnService } private val netName by lazy { vpnService.getCurrentNetName() } - private val pagerAdapter by lazy { StatusFragmentPagerAdapter(supportFragmentManager) } + private val pagerAdapter by lazy { FragmentListPagerAdapter(pages, supportFragmentManager) } private val broadcastMapper = BroadcastMapper(mapOf(Actions.EVENT_DISCONNECTED to this::onVpnShutdown)) + private val pages = listOf( + R.string.status_activity_title_network_info to NetworkInfoFragment(), + R.string.status_activity_title_node_list to NodeListFragment() + ) + private var shutdownDialog: AlertDialog? = null private var listNetworksAfterExit = true diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt b/app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt deleted file mode 100644 index d44ac5c..0000000 --- a/app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.status - -import android.support.v4.app.FragmentManager -import android.support.v4.app.FragmentPagerAdapter -import org.pacien.tincapp.R -import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment -import org.pacien.tincapp.activities.status.nodes.NodeListFragment -import org.pacien.tincapp.context.App - -/** - * @author pacien - */ -class StatusFragmentPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) { - private val resources by lazy { App.getResources() } - private val pages = listOf( - R.string.status_activity_title_network_info to NetworkInfoFragment(), - R.string.status_activity_title_node_list to NodeListFragment() - ) - - override fun getPageTitle(position: Int) = resources.getString(pages[position].first)!! - override fun getItem(position: Int) = pages[position].second - override fun getCount() = pages.size -} -- cgit v1.2.3