Created
March 24, 2017 10:28
-
-
Save deniszink/7a440681a835eafe980d3a4c25b838f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wellaapp.presentation.screens.authorization.view | |
import android.app.Activity | |
import android.content.Intent | |
import com.facebook.CallbackManager | |
import com.facebook.FacebookCallback | |
import com.facebook.FacebookException | |
import com.facebook.login.LoginManager | |
import com.facebook.login.LoginResult | |
import com.wellaapp.presentation.screens.authorization.presenter.AuthorizationMVP | |
/** | |
* @author Denis_Zinkovskiy at 2/16/17. | |
*/ | |
class FacebookHelper(view: AuthorizationMVP.View) { | |
private var defaultPermissions: MutableList<String> = mutableListOf("public_profile", "email") | |
private val loginManager: LoginManager = LoginManager.getInstance() | |
private var callbackManager: CallbackManager = CallbackManager.Factory.create() | |
init { | |
loginManager.registerCallback(callbackManager, object : FacebookCallback<LoginResult?> { | |
override fun onError(error: FacebookException?) { | |
view.onError<Unit>(error?.message!!, null) | |
} | |
override fun onSuccess(result: LoginResult?) { | |
view.facebookLogin(result?.accessToken!!) | |
} | |
override fun onCancel() { | |
} | |
}) | |
} | |
fun login(activity: Activity, permissions: MutableList<String> = defaultPermissions) { | |
loginManager.logInWithReadPermissions(activity, permissions) | |
} | |
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
callbackManager.onActivityResult(requestCode, resultCode, data) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment