diff options
author | pacien | 2018-08-20 17:05:52 +0200 |
---|---|---|
committer | pacien | 2018-08-20 17:05:52 +0200 |
commit | 8c47b9d6947a3ff4f75842f874b882471efcab76 (patch) | |
tree | 5d6a146a80a23cfee60f8f6b1b4ce311e55c69ee | |
parent | 957826db1e46bffcd99ee52f21101728279521b9 (diff) | |
download | tincapp-8c47b9d6947a3ff4f75842f874b882471efcab76.tar.gz |
Generify fragment pager adapter
-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.kt | 10 |
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 | ||
19 | package org.pacien.tincapp.activities.status | 19 | package org.pacien.tincapp.activities.common |
20 | 20 | ||
21 | import android.support.v4.app.Fragment | ||
21 | import android.support.v4.app.FragmentManager | 22 | import android.support.v4.app.FragmentManager |
22 | import android.support.v4.app.FragmentPagerAdapter | 23 | import android.support.v4.app.FragmentPagerAdapter |
23 | import org.pacien.tincapp.R | ||
24 | import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment | ||
25 | import org.pacien.tincapp.activities.status.nodes.NodeListFragment | ||
26 | import org.pacien.tincapp.context.App | 24 | import 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 | */ |
31 | class StatusFragmentPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) { | 30 | class 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 | |||
26 | import kotlinx.android.synthetic.main.status_activity.* | 26 | import kotlinx.android.synthetic.main.status_activity.* |
27 | import org.pacien.tincapp.R | 27 | import org.pacien.tincapp.R |
28 | import org.pacien.tincapp.activities.BaseActivity | 28 | import org.pacien.tincapp.activities.BaseActivity |
29 | import org.pacien.tincapp.activities.common.FragmentListPagerAdapter | ||
29 | import org.pacien.tincapp.activities.common.ProgressModal | 30 | import org.pacien.tincapp.activities.common.ProgressModal |
30 | import org.pacien.tincapp.activities.start.StartActivity | 31 | import org.pacien.tincapp.activities.start.StartActivity |
32 | import org.pacien.tincapp.activities.status.networkinfo.NetworkInfoFragment | ||
33 | import org.pacien.tincapp.activities.status.nodes.NodeListFragment | ||
31 | import org.pacien.tincapp.activities.viewlog.ViewLogActivity | 34 | import org.pacien.tincapp.activities.viewlog.ViewLogActivity |
32 | import org.pacien.tincapp.intent.Actions | 35 | import org.pacien.tincapp.intent.Actions |
33 | import org.pacien.tincapp.intent.BroadcastMapper | 36 | import org.pacien.tincapp.intent.BroadcastMapper |
@@ -39,8 +42,13 @@ import org.pacien.tincapp.service.TincVpnService | |||
39 | class StatusActivity : BaseActivity() { | 42 | class 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 | ||