aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org
diff options
context:
space:
mode:
authorpacien2018-08-20 17:05:52 +0200
committerpacien2018-08-20 17:05:52 +0200
commit8c47b9d6947a3ff4f75842f874b882471efcab76 (patch)
tree5d6a146a80a23cfee60f8f6b1b4ce311e55c69ee /app/src/main/java/org
parent957826db1e46bffcd99ee52f21101728279521b9 (diff)
downloadtincapp-8c47b9d6947a3ff4f75842f874b882471efcab76.tar.gz
Generify fragment pager adapter
Diffstat (limited to 'app/src/main/java/org')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt (renamed from app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt)15
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/status/StatusActivity.kt10
2 files changed, 15 insertions, 10 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt b/app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt
index d44ac5c..e4063bf 100644
--- a/app/src/main/java/org/pacien/tincapp/activities/status/StatusFragmentPagerAdapter.kt
+++ b/app/src/main/java/org/pacien/tincapp/activities/common/FragmentListPagerAdapter.kt
@@ -16,24 +16,21 @@
16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19package org.pacien.tincapp.activities.status 19package org.pacien.tincapp.activities.common
20 20
21import android.support.v4.app.Fragment
21import android.support.v4.app.FragmentManager 22import android.support.v4.app.FragmentManager
22import android.support.v4.app.FragmentPagerAdapter 23import android.support.v4.app.FragmentPagerAdapter
23import org.pacien.tincapp.R
24import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment
25import org.pacien.tincapp.activities.status.nodes.NodeListFragment
26import org.pacien.tincapp.context.App 24import org.pacien.tincapp.context.App
27 25
28/** 26/**
27 * @param pages ordered list of title and fragment pairs
29 * @author pacien 28 * @author pacien
30 */ 29 */
31class StatusFragmentPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) { 30class FragmentListPagerAdapter(private val pages: List<Pair<Int, Fragment>>,
31 fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) {
32
32 private val resources by lazy { App.getResources() } 33 private val resources by lazy { App.getResources() }
33 private val pages = listOf(
34 R.string.status_activity_title_network_info to NetworkInfoFragment(),
35 R.string.status_activity_title_node_list to NodeListFragment()
36 )
37 34
38 override fun getPageTitle(position: Int) = resources.getString(pages[position].first)!! 35 override fun getPageTitle(position: Int) = resources.getString(pages[position].first)!!
39 override fun getItem(position: Int) = pages[position].second 36 override fun getItem(position: Int) = pages[position].second
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
26import kotlinx.android.synthetic.main.status_activity.* 26import kotlinx.android.synthetic.main.status_activity.*
27import org.pacien.tincapp.R 27import org.pacien.tincapp.R
28import org.pacien.tincapp.activities.BaseActivity 28import org.pacien.tincapp.activities.BaseActivity
29import org.pacien.tincapp.activities.common.FragmentListPagerAdapter
29import org.pacien.tincapp.activities.common.ProgressModal 30import org.pacien.tincapp.activities.common.ProgressModal
30import org.pacien.tincapp.activities.start.StartActivity 31import org.pacien.tincapp.activities.start.StartActivity
32import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment
33import org.pacien.tincapp.activities.status.nodes.NodeListFragment
31import org.pacien.tincapp.activities.viewlog.ViewLogActivity 34import org.pacien.tincapp.activities.viewlog.ViewLogActivity
32import org.pacien.tincapp.intent.Actions 35import org.pacien.tincapp.intent.Actions
33import org.pacien.tincapp.intent.BroadcastMapper 36import org.pacien.tincapp.intent.BroadcastMapper
@@ -39,8 +42,13 @@ import org.pacien.tincapp.service.TincVpnService
39class StatusActivity : BaseActivity() { 42class StatusActivity : BaseActivity() {
40 private val vpnService by lazy { TincVpnService } 43 private val vpnService by lazy { TincVpnService }
41 private val netName by lazy { vpnService.getCurrentNetName() } 44 private val netName by lazy { vpnService.getCurrentNetName() }
42 private val pagerAdapter by lazy { StatusFragmentPagerAdapter(supportFragmentManager) } 45 private val pagerAdapter by lazy { FragmentListPagerAdapter(pages, supportFragmentManager) }
43 private val broadcastMapper = BroadcastMapper(mapOf(Actions.EVENT_DISCONNECTED to this::onVpnShutdown)) 46 private val broadcastMapper = BroadcastMapper(mapOf(Actions.EVENT_DISCONNECTED to this::onVpnShutdown))
47 private val pages = listOf(
48 R.string.status_activity_title_network_info to NetworkInfoFragment(),
49 R.string.status_activity_title_node_list to NodeListFragment()
50 )
51
44 private var shutdownDialog: AlertDialog? = null 52 private var shutdownDialog: AlertDialog? = null
45 private var listNetworksAfterExit = true 53 private var listNetworksAfterExit = true
46 54