tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

README.md (2341B)


[Android Components](../../README.md) > Samples > Firefox Sync - Logins

A simple app showcasing the service-sync-logins component.

Concepts

The main concepts shown in the sample app are:

`SyncResult` usage

SyncResult represents a chainable asynchronous result, and is used as a convenient method of running potentially long-running tasks (eg. network requests, crypto operations) on threads outside of the UI thread.

A value or exception can be wrapped in an SyncResult:

val syncValue = SyncResult.fromValue(42)
val syncException = SyncResult.fromException(Exception("Something went wrong"))

One can attach OnValueListeners or OnExceptionListeners to an SyncResult. There are a few ways of chaining results in Kotlin:

`kotlin SyncResult.fromValue(42).then(object : OnValueListener<Integer, Void> { override fun onValue(value: Integer): SyncResult<Void>? { // handle the value return SyncResult<Void>() } }, object : OnExceptionListener<Void> { override fun onException(exception: Exception): SyncResult<Void>? { // handle the exception return SyncResult<Void>() } }) `

Since Java 6 does not support simple lambda syntax, this is one of the main ways to chain SyncResults in Java.

`kotlin SyncResult.fromValue(42).then({ value: Int -> // valueListener // handle the value return SyncResult<Void>() }, { exception: Exception -> // handle the exception return SyncResult<Void>() }) `

`kotlin SyncResult.fromValue(42).whenComplete { value: Integer -> // handle the value } `

Since whenComplete implies that the chain of promises has come to an end, there is no need to return another SyncResult at the end.

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/