summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/mapboxfreezerepro/MainActivity.kt
blob: 03377e2fb41c46d59eed9a6c4e846dc7cdd12b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.mapbox.mapboxsdk.testapp.mapboxfreezerepro

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views.EmptyView
import com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views.MapView
import kotlinx.android.synthetic.main.activity_main.*
import timber.log.Timber

class MainActivity : AppCompatActivity() {

    private var empty = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        fragmentContainer.addView(EmptyView(this))
        button.setOnClickListener {
            Timber.e("removeAllViews")

            if (!empty) {
                val fragment = supportFragmentManager.findFragmentByTag(com.mapbox.mapboxsdk.testapp.mapboxfreezerepro.views.TAG)
                if (fragment != null) {
                    supportFragmentManager.beginTransaction()
                            .remove(fragment)
                            .commitNowAllowingStateLoss()
                }
            }

            fragmentContainer.removeAllViews()
            if (empty) {
                fragmentContainer.addView(
                        MapView(
                                this
                        )
                )
                empty = false
            } else {
                fragmentContainer.addView(
                        EmptyView(
                                this
                        )
                )
                empty = true
            }
        }
    }
}