diff --git a/app/src/main/kotlin/jackall/overlaymulticounter/activity/MainActivity.kt b/app/src/main/kotlin/jackall/overlaymulticounter/activity/MainActivity.kt index 1c360ef..48111e0 100644 --- a/app/src/main/kotlin/jackall/overlaymulticounter/activity/MainActivity.kt +++ b/app/src/main/kotlin/jackall/overlaymulticounter/activity/MainActivity.kt @@ -1,9 +1,12 @@ package jackall.overlaymulticounter.activity import android.arch.lifecycle.ViewModelProviders +import android.content.Intent import android.databinding.DataBindingUtil import android.graphics.Typeface +import android.net.Uri import android.os.Bundle +import android.provider.Settings import android.support.v7.app.AppCompatActivity import com.getkeepsafe.taptargetview.TapTarget import com.getkeepsafe.taptargetview.TapTargetView @@ -12,8 +15,10 @@ import jackall.overlaymulticounter.R import jackall.overlaymulticounter.common.PreferenceKeys import jackall.overlaymulticounter.common.PreferenceNames +import jackall.overlaymulticounter.contract.MainContract import jackall.overlaymulticounter.databinding.ActivityMainBinding import jackall.overlaymulticounter.db.CounterRealmHelper +import jackall.overlaymulticounter.service.MainService import jackall.overlaymulticounter.utils.AdUtil import jackall.overlaymulticounter.utils.MySharedPref import jackall.overlaymulticounter.viewmodel.MainViewModel @@ -21,7 +26,7 @@ import kotlinx.android.synthetic.main.activity_main.view.* -class MainActivity : AppCompatActivity() { +class MainActivity : AppCompatActivity(), MainContract { lateinit var binding: ActivityMainBinding lateinit var mainViewModel: MainViewModel @@ -30,7 +35,7 @@ super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this, R.layout.activity_main) - mainViewModel = ViewModelProviders.of(this, MainViewModel.Factory()).get(MainViewModel::class.java) + mainViewModel = ViewModelProviders.of(this, MainViewModel.Factory(this as MainContract)).get(MainViewModel::class.java) binding.mainViewModel = mainViewModel lifecycle.addObserver(mainViewModel) @@ -75,4 +80,17 @@ }) } } + + override fun startService() { + startService(Intent(this, MainService::class.java)) + } + + override fun stopService() { + stopService(Intent(this, MainService::class.java)) + } + + override fun openSetting() { + val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:jackall.overlaymulticounter")) + startActivityForResult(intent, 0) + } }