AndroidAPS/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt

57 lines
2.2 KiB
Kotlin
Raw Normal View History

2019-12-22 21:37:26 +01:00
package info.nightscout.androidaps.activities
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
2020-03-16 21:40:29 +01:00
import dagger.android.support.DaggerAppCompatActivity
2019-12-22 21:37:26 +01:00
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginBase
2020-03-16 21:40:29 +01:00
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
2019-12-22 21:37:26 +01:00
import info.nightscout.androidaps.utils.LocaleHelper
2020-03-22 19:59:35 +01:00
import info.nightscout.androidaps.utils.protection.ProtectionCheck
2020-03-16 21:40:29 +01:00
import javax.inject.Inject
class SingleFragmentActivity : DaggerAppCompatActivity() {
@Inject lateinit var pluginStore: PluginStore
2019-12-22 21:37:26 +01:00
private var plugin: PluginBase? = null
2020-03-16 21:40:29 +01:00
2019-12-22 21:37:26 +01:00
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_single_fragment)
2020-03-16 21:40:29 +01:00
plugin = pluginStore.plugins[intent.getIntExtra("plugin", -1)]
2019-12-22 21:37:26 +01:00
title = plugin?.name
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction().replace(R.id.frame_layout,
supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), plugin?.pluginDescription?.fragmentClass!!)).commit()
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
} else if (item.itemId == R.id.nav_plugin_preferences) {
2020-03-22 19:59:35 +01:00
ProtectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, Runnable {
2019-12-22 21:37:26 +01:00
val i = Intent(this, PreferencesActivity::class.java)
i.putExtra("id", plugin?.preferencesId)
startActivity(i)
}, null)
return true
}
return false
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
if (plugin?.preferencesId != -1) menuInflater.inflate(R.menu.menu_single_fragment, menu)
return super.onCreateOptionsMenu(menu)
}
public override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleHelper.wrap(newBase))
}
}