diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b243968..6a60934 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -44,7 +44,6 @@ - { user -> + mUserAccountViewModel.getUserAccount(userId).observe(this, Observer{ user -> tvAccountName.text = user.name }) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/LicenseFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/LicenseFragment.kt new file mode 100644 index 0000000..385b7d1 --- /dev/null +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/LicenseFragment.kt @@ -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() + } +} \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt index f404a82..7aa59cf 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt @@ -8,9 +8,6 @@ object Constants { /** Version of the currently used license */ 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 */ const val KEY_CURRENT_ACCOUNT_ID = "key_current_account_id" diff --git a/app/src/main/res/layout/activity_license.xml b/app/src/main/res/layout/fragment_license.xml similarity index 100% rename from app/src/main/res/layout/activity_license.xml rename to app/src/main/res/layout/fragment_license.xml diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index 1e2c596..3981905 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -35,6 +35,13 @@ app:exitAnim="@anim/slide_out_left" app:popEnterAnim="@anim/slide_in_left" app:popExitAnim="@anim/slide_out_right"/> + + + + + + + + + \ No newline at end of file