Removed LicenseActivity and created LicenseFragment instead, to comply with the proposed app architecture using the AAC Navigation component where there is only one Activity and all the views are represented by Fragments.

This commit is contained in:
Severiano Jaramillo 2019-01-04 15:53:29 -06:00
parent 4e64b10014
commit 58e1e0a575
9 changed files with 100 additions and 65 deletions

View file

@ -44,7 +44,6 @@
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".activities.LicenseActivity"/>
<activity android:name=".activities.ImportBrainkeyActivity"/> <activity android:name=".activities.ImportBrainkeyActivity"/>
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"

View file

@ -1,55 +0,0 @@
package cy.agorise.bitsybitshareswallet.activities
import android.content.Intent
import android.os.Bundle
import android.preference.PreferenceManager
import androidx.appcompat.app.AppCompatActivity
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.utils.Constants
import kotlinx.android.synthetic.main.activity_license.*
class LicenseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_license)
// Get version number of the last agreed license version
val agreedLicenseVersion = PreferenceManager.getDefaultSharedPreferences(this)
.getInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, 0)
// If the last agreed license version is the actual one then proceed to the following Activities
if (agreedLicenseVersion == Constants.CURRENT_LICENSE_VERSION) {
agree()
} else {
wbLA.loadUrl("file:///android_asset/eula.html")
btnDisagree.setOnClickListener { finish() }
btnAgree.setOnClickListener { agree() }
}
}
/**
* This function stores the version of the current accepted license version into the Shared Preferences and
* sends the user to import/create account if there is no active account or to the MainActivity otherwise.
*/
private fun agree() {
PreferenceManager.getDefaultSharedPreferences(this).edit()
.putInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION).apply()
val intent : Intent?
val initialSetupDone = PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(Constants.KEY_INITIAL_SETUP_DONE, false)
intent = if (!initialSetupDone)
Intent(this, ImportBrainkeyActivity::class.java)
else
Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}
}

View file

@ -9,7 +9,7 @@ class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val intent = Intent(this, LicenseActivity::class.java) val intent = Intent(this, MainActivity::class.java)
startActivity(intent) startActivity(intent)
finish() finish()
} }

View file

@ -20,7 +20,7 @@ import io.reactivex.disposables.CompositeDisposable
* Base fragment that defines the methods and variables commonly used in all fragments that directly connect and * Base fragment that defines the methods and variables commonly used in all fragments that directly connect and
* talk to the BitShares nodes through graphenej's NetworkService * talk to the BitShares nodes through graphenej's NetworkService
*/ */
abstract class ConnectedFragment: Fragment(), ServiceConnection { abstract class ConnectedFragment : Fragment(), ServiceConnection {
companion object { companion object {
private const val TAG = "ConnectedFragment" private const val TAG = "ConnectedFragment"

View file

@ -45,13 +45,22 @@ class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
// Get version number of the last agreed license version
val agreedLicenseVersion = PreferenceManager.getDefaultSharedPreferences(context)
.getInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, 0)
val userId = PreferenceManager.getDefaultSharedPreferences(context)
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "") ?: ""
if (agreedLicenseVersion != Constants.CURRENT_LICENSE_VERSION || userId == "") {
findNavController().navigate(R.id.setup_action)
return
}
// Configure UserAccountViewModel to show the current account // Configure UserAccountViewModel to show the current account
mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java) mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java)
val userId = PreferenceManager.getDefaultSharedPreferences(context) mUserAccountViewModel.getUserAccount(userId).observe(this, Observer<UserAccount>{ user ->
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "")
mUserAccountViewModel.getUserAccount(userId!!).observe(this, Observer<UserAccount>{ user ->
tvAccountName.text = user.name tvAccountName.text = user.name
}) })

View file

@ -0,0 +1,66 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.utils.Constants
import kotlinx.android.synthetic.main.fragment_license.*
class LicenseFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Remove up navigation icon from the toolbar
val toolbar: Toolbar? = activity?.findViewById(R.id.toolbar)
toolbar?.navigationIcon = null
return inflater.inflate(R.layout.fragment_license, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Get version number of the last agreed license version
val agreedLicenseVersion = PreferenceManager.getDefaultSharedPreferences(context)
.getInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, 0)
// If the last agreed license version is the actual one then proceed to the following Activities
if (agreedLicenseVersion == Constants.CURRENT_LICENSE_VERSION) {
agree()
} else {
wbLA.loadUrl("file:///android_asset/eula.html")
btnDisagree.setOnClickListener { activity?.finish() }
btnAgree.setOnClickListener { agree() }
}
}
/**
* This function stores the version of the current accepted license version into the Shared Preferences and
* sends the user to import/create account if there is no active account or to the MainActivity otherwise.
*/
private fun agree() {
PreferenceManager.getDefaultSharedPreferences(context).edit()
.putInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION).apply()
// val intent : Intent?
//
// val initialSetupDone = PreferenceManager.getDefaultSharedPreferences(this)
// .getBoolean(Constants.KEY_INITIAL_SETUP_DONE, false)
//
// intent = if (!initialSetupDone)
// Intent(this, ImportBrainkeyActivity::class.java)
// else
// Intent(this, MainActivity::class.java)
//
//
// startActivity(intent)
// finish()
}
}

View file

@ -8,9 +8,6 @@ object Constants {
/** Version of the currently used license */ /** Version of the currently used license */
const val CURRENT_LICENSE_VERSION = 1 const val CURRENT_LICENSE_VERSION = 1
/** Key used to store if the initial setup is already done or not */
const val KEY_INITIAL_SETUP_DONE = "key_initial_setup_done"
/** Key used to store the id value of the currently active account in the shared preferences */ /** Key used to store the id value of the currently active account in the shared preferences */
const val KEY_CURRENT_ACCOUNT_ID = "key_current_account_id" const val KEY_CURRENT_ACCOUNT_ID = "key_current_account_id"

View file

@ -35,6 +35,13 @@
app:exitAnim="@anim/slide_out_left" app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left" app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/> app:popExitAnim="@anim/slide_out_right"/>
<action
android:id="@+id/setup_action"
app:destination="@id/navigation_setup"
app:popUpTo="@id/home_dest"
app:popUpToInclusive="true"/>
</fragment> </fragment>
<fragment <fragment
@ -73,4 +80,16 @@
android:defaultValue="false" /> android:defaultValue="false" />
</fragment> </fragment>
<navigation
android:id="@+id/navigation_setup"
app:startDestination="@id/license_dest">
<fragment
android:id="@+id/license_dest"
android:name="cy.agorise.bitsybitshareswallet.fragments.LicenseFragment"
android:label="LicenseFragment"
tools:layout="@layout/fragment_license"/>
</navigation>
</navigation> </navigation>