MainActivity -> jetpack
This commit is contained in:
parent
30547af0b4
commit
3f229dfa9b
2 changed files with 35 additions and 32 deletions
|
@ -87,7 +87,7 @@ def gitAvailable = { ->
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def allCommited = { ->
|
def allCommitted = { ->
|
||||||
StringBuilder stringBuilder = new StringBuilder()
|
StringBuilder stringBuilder = new StringBuilder()
|
||||||
try {
|
try {
|
||||||
def stdout = new ByteArrayOutputStream()
|
def stdout = new ByteArrayOutputStream()
|
||||||
|
@ -125,7 +125,7 @@ android {
|
||||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||||
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
|
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
|
||||||
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
||||||
buildConfigField "String", "COMMITED", '"' + allCommited() + '"'
|
buildConfigField "String", "COMMITTED", '"' + allCommitted() + '"'
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
// if you change minSdkVersion to less than 11, you need to change executeTask for wear
|
// if you change minSdkVersion to less than 11, you need to change executeTask for wear
|
||||||
|
|
||||||
|
@ -315,12 +315,12 @@ tasks.whenTaskAdded { task ->
|
||||||
printf('--------------\n')
|
printf('--------------\n')
|
||||||
printf('isMaster: %s\n', isMaster().toString())
|
printf('isMaster: %s\n', isMaster().toString())
|
||||||
printf('gitAvailable: %s\n', gitAvailable().toString())
|
printf('gitAvailable: %s\n', gitAvailable().toString())
|
||||||
printf('allCommited: %s\n', allCommited().toString())
|
printf('allCommitted: %s\n', allCommitted().toString())
|
||||||
printf('--------------\n')
|
printf('--------------\n')
|
||||||
if (isMaster() && !gitAvailable()) {
|
if (isMaster() && !gitAvailable()) {
|
||||||
throw new GradleException('GIT system is not available. On Windows try to run Android Studio as an Administrator. Check if GIT is installed and Studio have permissions to use it')
|
throw new GradleException('GIT system is not available. On Windows try to run Android Studio as an Administrator. Check if GIT is installed and Studio have permissions to use it')
|
||||||
}
|
}
|
||||||
if (isMaster() && !allCommited()) {
|
if (isMaster() && !allCommitted()) {
|
||||||
throw new GradleException('There are uncommitted changes. Clone sources again as described in wiki and do not allow gradle update')
|
throw new GradleException('There are uncommitted changes. Clone sources again as described in wiki and do not allow gradle update')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import info.nightscout.androidaps.activities.PreferencesActivity
|
||||||
import info.nightscout.androidaps.activities.ProfileHelperActivity
|
import info.nightscout.androidaps.activities.ProfileHelperActivity
|
||||||
import info.nightscout.androidaps.activities.SingleFragmentActivity
|
import info.nightscout.androidaps.activities.SingleFragmentActivity
|
||||||
import info.nightscout.androidaps.activities.StatsActivity
|
import info.nightscout.androidaps.activities.StatsActivity
|
||||||
|
import info.nightscout.androidaps.databinding.ActivityMainBinding
|
||||||
import info.nightscout.androidaps.events.EventAppExit
|
import info.nightscout.androidaps.events.EventAppExit
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
import info.nightscout.androidaps.events.EventRebuildTabs
|
import info.nightscout.androidaps.events.EventRebuildTabs
|
||||||
|
@ -61,7 +62,6 @@ import info.nightscout.androidaps.utils.tabs.TabPageAdapter
|
||||||
import info.nightscout.androidaps.utils.ui.UIRunnable
|
import info.nightscout.androidaps.utils.ui.UIRunnable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
@ -91,28 +91,31 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
private var pluginPreferencesMenuItem: MenuItem? = null
|
private var pluginPreferencesMenuItem: MenuItem? = null
|
||||||
private var menu: Menu? = null
|
private var menu: Menu? = null
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
Iconify.with(FontAwesomeModule())
|
Iconify.with(FontAwesomeModule())
|
||||||
LocaleHelper.update(applicationContext)
|
LocaleHelper.update(applicationContext)
|
||||||
setContentView(R.layout.activity_main)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setSupportActionBar(toolbar)
|
setContentView(binding.root)
|
||||||
|
setSupportActionBar(binding.toolbar)
|
||||||
supportActionBar?.setDisplayShowTitleEnabled(false)
|
supportActionBar?.setDisplayShowTitleEnabled(false)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setHomeButtonEnabled(true)
|
supportActionBar?.setHomeButtonEnabled(true)
|
||||||
actionBarDrawerToggle = ActionBarDrawerToggle(this, main_drawer_layout, R.string.open_navigation, R.string.close_navigation).also {
|
actionBarDrawerToggle = ActionBarDrawerToggle(this, binding.mainDrawerLayout, R.string.open_navigation, R.string.close_navigation).also {
|
||||||
main_drawer_layout.addDrawerListener(it)
|
binding.mainDrawerLayout.addDrawerListener(it)
|
||||||
it.syncState()
|
it.syncState()
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize screen wake lock
|
// initialize screen wake lock
|
||||||
processPreferenceChange(EventPreferenceChange(resourceHelper.gs(R.string.key_keep_screen_on)))
|
processPreferenceChange(EventPreferenceChange(resourceHelper.gs(R.string.key_keep_screen_on)))
|
||||||
main_pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
binding.mainPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
||||||
override fun onPageScrollStateChanged(state: Int) {}
|
override fun onPageScrollStateChanged(state: Int) {}
|
||||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
setPluginPreferenceMenuName()
|
setPluginPreferenceMenuName()
|
||||||
checkPluginPreferences(main_pager)
|
checkPluginPreferences(binding.mainPager)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -183,8 +186,8 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
private fun setupViews() {
|
private fun setupViews() {
|
||||||
// Menu
|
// Menu
|
||||||
val pageAdapter = TabPageAdapter(this)
|
val pageAdapter = TabPageAdapter(this)
|
||||||
main_navigation_view.setNavigationItemSelectedListener { true }
|
binding.mainNavigationView.setNavigationItemSelectedListener { true }
|
||||||
val menu = main_navigation_view.menu.also { it.clear() }
|
val menu = binding.mainNavigationView.menu.also { it.clear() }
|
||||||
for (p in activePlugin.getPluginsList()) {
|
for (p in activePlugin.getPluginsList()) {
|
||||||
pageAdapter.registerNewFragment(p)
|
pageAdapter.registerNewFragment(p)
|
||||||
if (p.isEnabled() && p.hasFragment() && !p.isFragmentVisible() && !p.pluginDescription.neverVisible) {
|
if (p.isEnabled() && p.hasFragment() && !p.isFragmentVisible() && !p.pluginDescription.neverVisible) {
|
||||||
|
@ -199,33 +202,33 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
val intent = Intent(this, SingleFragmentActivity::class.java)
|
val intent = Intent(this, SingleFragmentActivity::class.java)
|
||||||
intent.putExtra("plugin", activePlugin.getPluginsList().indexOf(p))
|
intent.putExtra("plugin", activePlugin.getPluginsList().indexOf(p))
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
main_drawer_layout.closeDrawers()
|
binding.mainDrawerLayout.closeDrawers()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main_pager.adapter = pageAdapter
|
binding.mainPager.adapter = pageAdapter
|
||||||
main_pager.offscreenPageLimit = 8 // This may cause more memory consumption
|
binding.mainPager.offscreenPageLimit = 8 // This may cause more memory consumption
|
||||||
checkPluginPreferences(main_pager)
|
checkPluginPreferences(binding.mainPager)
|
||||||
|
|
||||||
// Tabs
|
// Tabs
|
||||||
if (sp.getBoolean(R.string.key_short_tabtitles, false)) {
|
if (sp.getBoolean(R.string.key_short_tabtitles, false)) {
|
||||||
tabs_normal.visibility = View.GONE
|
binding.tabsNormal.visibility = View.GONE
|
||||||
tabs_compact.visibility = View.VISIBLE
|
binding.tabsCompact.visibility = View.VISIBLE
|
||||||
toolbar.layoutParams = LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, resources.getDimension(R.dimen.compact_height).toInt())
|
binding.toolbar.layoutParams = LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, resources.getDimension(R.dimen.compact_height).toInt())
|
||||||
TabLayoutMediator(tabs_compact, main_pager) { tab, position ->
|
TabLayoutMediator(binding.tabsCompact, binding.mainPager) { tab, position ->
|
||||||
tab.text = (main_pager.adapter as TabPageAdapter).getPluginAt(position).nameShort
|
tab.text = (binding.mainPager.adapter as TabPageAdapter).getPluginAt(position).nameShort
|
||||||
}.attach()
|
}.attach()
|
||||||
} else {
|
} else {
|
||||||
tabs_normal.visibility = View.VISIBLE
|
binding.tabsNormal.visibility = View.VISIBLE
|
||||||
tabs_compact.visibility = View.GONE
|
binding.tabsCompact.visibility = View.GONE
|
||||||
val typedValue = TypedValue()
|
val typedValue = TypedValue()
|
||||||
if (theme.resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
|
if (theme.resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
|
||||||
toolbar.layoutParams = LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
|
binding.toolbar.layoutParams = LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
|
||||||
TypedValue.complexToDimensionPixelSize(typedValue.data, resources.displayMetrics))
|
TypedValue.complexToDimensionPixelSize(typedValue.data, resources.displayMetrics))
|
||||||
}
|
}
|
||||||
TabLayoutMediator(tabs_normal, main_pager) { tab, position ->
|
TabLayoutMediator(binding.tabsNormal, binding.mainPager) { tab, position ->
|
||||||
tab.text = (main_pager.adapter as TabPageAdapter).getPluginAt(position).name
|
tab.text = (binding.mainPager.adapter as TabPageAdapter).getPluginAt(position).name
|
||||||
}.attach()
|
}.attach()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,8 +250,8 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setPluginPreferenceMenuName() {
|
private fun setPluginPreferenceMenuName() {
|
||||||
if (main_pager.currentItem >= 0) {
|
if (binding.mainPager.currentItem >= 0) {
|
||||||
val plugin = (main_pager.adapter as TabPageAdapter).getPluginAt(main_pager.currentItem)
|
val plugin = (binding.mainPager.adapter as TabPageAdapter).getPluginAt(binding.mainPager.currentItem)
|
||||||
this.menu?.findItem(R.id.nav_plugin_preferences)?.title = resourceHelper.gs(R.string.nav_preferences_plugin, plugin.name)
|
this.menu?.findItem(R.id.nav_plugin_preferences)?.title = resourceHelper.gs(R.string.nav_preferences_plugin, plugin.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,7 +261,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
menuInflater.inflate(R.menu.menu_main, menu)
|
menuInflater.inflate(R.menu.menu_main, menu)
|
||||||
pluginPreferencesMenuItem = menu.findItem(R.id.nav_plugin_preferences)
|
pluginPreferencesMenuItem = menu.findItem(R.id.nav_plugin_preferences)
|
||||||
setPluginPreferenceMenuName()
|
setPluginPreferenceMenuName()
|
||||||
checkPluginPreferences(main_pager)
|
checkPluginPreferences(binding.mainPager)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +319,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.nav_plugin_preferences -> {
|
R.id.nav_plugin_preferences -> {
|
||||||
val plugin = (main_pager.adapter as TabPageAdapter).getPluginAt(main_pager.currentItem)
|
val plugin = (binding.mainPager.adapter as TabPageAdapter).getPluginAt(binding.mainPager.currentItem)
|
||||||
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
|
||||||
val i = Intent(this, PreferencesActivity::class.java)
|
val i = Intent(this, PreferencesActivity::class.java)
|
||||||
i.putExtra("id", plugin.preferencesId)
|
i.putExtra("id", plugin.preferencesId)
|
||||||
|
@ -375,7 +378,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
FirebaseCrashlytics.getInstance().setCustomKey("HEAD", BuildConfig.HEAD)
|
FirebaseCrashlytics.getInstance().setCustomKey("HEAD", BuildConfig.HEAD)
|
||||||
FirebaseCrashlytics.getInstance().setCustomKey("Version", BuildConfig.VERSION)
|
FirebaseCrashlytics.getInstance().setCustomKey("Version", BuildConfig.VERSION)
|
||||||
FirebaseCrashlytics.getInstance().setCustomKey("Remote", remote)
|
FirebaseCrashlytics.getInstance().setCustomKey("Remote", remote)
|
||||||
FirebaseCrashlytics.getInstance().setCustomKey("Commited", BuildConfig.COMMITED)
|
FirebaseCrashlytics.getInstance().setCustomKey("Committed", BuildConfig.COMMITTED)
|
||||||
FirebaseCrashlytics.getInstance().setCustomKey("Hash", hashes[0])
|
FirebaseCrashlytics.getInstance().setCustomKey("Hash", hashes[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue