Create empty SettingsActivity and an Intent to open it from the Settings icon in the MainActivity bottom status bar.

This commit is contained in:
Severiano Jaramillo 2018-10-30 12:41:09 -06:00
parent 79a0a5fc79
commit 30ae9c36bf
6 changed files with 64 additions and 41 deletions

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="cy.agorise.bitsybitshareswallet">
xmlns:tools="http://schemas.android.com/tools"
package="cy.agorise.bitsybitshareswallet">
<application
android:allowBackup="true"
@ -15,10 +16,15 @@
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activities.SettingsActivity"
android:label="@string/title_settings">
</activity>
</application>
</manifest>

View file

@ -1,13 +1,12 @@
package cy.agorise.bitsybitshareswallet.activities
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import cy.agorise.bitsybitshareswallet.BuildConfig
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.fragments.BalancesFragment
@ -32,7 +31,6 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//setSupportActionBar(toolbar)
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager)
@ -44,29 +42,23 @@ class MainActivity : AppCompatActivity() {
// Force first tab to show BTS icon
tabLayout.getTabAt(0)?.setIcon(R.drawable.tab_home_selector)
tvBuildVersion.text = String.format("v%s", BuildConfig.VERSION_NAME)
}
initBottomBar()
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
val id = item.itemId
if (id == R.id.action_settings) {
return true
ivSettings.setOnClickListener {
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
}
return super.onOptionsItemSelected(item)
}
private fun initBottomBar() {
// Show app version number in bottom bar
tvBuildVersion.text = String.format("v%s", BuildConfig.VERSION_NAME)
// Show block number in bottom bar
tvBlockNumber.text = getString(R.string.block_number_bottom_bar, "-----")
// TODO add listener to update block number
}
/**
* A [FragmentPagerAdapter] that returns a fragment corresponding to

View file

@ -0,0 +1,32 @@
package cy.agorise.bitsybitshareswallet.activities
import android.os.Bundle
import android.view.MenuItem
import android.support.v7.app.AppCompatActivity
/**
* A simple activity for the user to select his preferences
*/
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setupActionBar()
}
/**
* Set up the [android.app.ActionBar], if the API is available.
*/
private fun setupActionBar() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}
}

View file

@ -66,7 +66,7 @@
android:id="@+id/tvBlockNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Block: ----"
tools:text="Block: ----"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -92,7 +92,8 @@
android:src="@drawable/ic_settings"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/title_settings"/>
</android.support.constraint.ConstraintLayout>

View file

@ -1,9 +0,0 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="cy.agorise.bitsybitshareswallet.activities.MainActivity">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
</menu>

View file

@ -1,10 +1,11 @@
<resources>
<string name="app_name">BiTSy</string>
<string name="tab_text_1">Tab 1</string>
<string name="tab_text_2">Tab 2</string>
<string name="tab_text_3">Tab 3</string>
<string name="action_settings">Settings</string>
<string name="section_format">Hello World from section: %1$d</string>
<!-- Main Activity -->
<string name="title_transactions">Transactions</string>
<string name="title_merchants">Merchants</string>
<string name="block_number_bottom_bar">Block: %1$s</string>
<!-- Settings -->
<string name="title_settings">Settings</string>
</resources>