Skip to content

Instantly share code, notes, and snippets.

View dkhmelenko's full-sized avatar

Dmytro Khmelenko dkhmelenko

View GitHub Profile
public class Presenter {
private final NetworkApi api;
public Presenter(NetworkApi api) {
this.api = api;
}
public void loadData() {
view.showProgress(true);
@dkhmelenko
dkhmelenko / analyze_apk_size.sh
Created March 6, 2018 22:15
Script for analyzing Android APK size
PATH_TO_APK=$1
APK_THRESHOLD=$2
echo "Analyze APK size command"
NEW_APK_SIZE=`expr $(stat -c%s PATH_TO_APK) / 1024`
echo "APK size is now "$NEW_APK_SIZE" KB"
if [[ $NEW_APK_SIZE -lt $APK_THRESHOLD ]]; then
echo "APK file is less than "$APK_THRESHOLD" KB. OK"
interface SmartLockCredentialsManager {
/**
* Retrieves stored credentials
*
* @return Single that emits stored credentials
*/
fun retrieveCredentials(): Single<Credential>
/**
override fun storeCredentials(credential: Credential): Completable {
startHiddenActivity(REQUEST_CODE_STORE_CREDENTIALS)
return googleApiClientSubject.concatMapCompletable {
saveCredentialsRequest(credential)
}
}
lateinit var googleApiClient: GoogleApiClient
private var googleApiClientSubject = PublishSubject.create<GoogleApiClient>()
fun init() {
googleApiClient = GoogleApiClient.Builder(context)
.addConnectionCallbacks(object : GoogleApiClient.ConnectionCallbacks {
override fun onConnected(connectionHint: Bundle?) {
googleApiClientSubject.onNext(googleApiClient!!)
}
private val activityResultSubject = PublishSubject.create<ActivityResult>()
fun saveCredentialsRequest(credentialsToSave: Credential): Completable {
return Completable.create { emitter ->
Auth.CredentialsApi
.save(googleApiClient, credentialsToSave)
.setResultCallback { result ->
val status = result.status
if (status.isSuccess) {
emitter.onComplete()
fun handleSaveCredentialsResult(resultCode: Int, emitter: CompletableEmitter) {
if (resultCode == Activity.RESULT_OK) {
emitter.onComplete()
} else {
emitter.onError(Exception("Saving credentials failed: $resultCode"))
}
}
interface SmartLockManager {
/**
* Retrieves stored credentials from Smartlock
*
* @return Single that emits stored credentials if there are any
*/
fun retrieveCredentials(context: Context): Single<Credential>
/**
val credential = Credential.Builder(login)
.setName(login)
.setPassword(password)
.build()
RxGoogleSmartLockManager.storeCredentials(context, credential)
.subscribe({
Toast.makeText(this, "Credential stored successfully", Toast.LENGTH_SHORT).show()
}, {
Toast.makeText(this, "Failed storing credential: $it", Toast.LENGTH_SHORT).show()
RxGoogleSmartLockManager.retrieveCredentials(context)
.subscribe({
Toast.makeText(this, "Retrieved: name ${it.name}, pass ${it.password}", Toast.LENGTH_SHORT).show()
}, {
Toast.makeText(this, "Failed retrieving credentials: $it", Toast.LENGTH_SHORT).show()
})