<commit_before>package org.fathens.cordova.plugin.fbconnect

import com.facebook.CallbackManager
import org.apache.cordova.CallbackContext
import org.apache.cordova.CordovaPlugin
import org.json.JSONArray
import com.facebook.*
import com.facebook.login.*

public class FBConnect: CordovaPlugin() {
    override fun execute(action: String, data: JSONArray, callbackContext: CallbackContext): Boolean {
        try {
            val method = javaClass.getMethod(action, data.javaClass)
            val runner = method.invoke(this, data) as (() -> Unit)
            cordova.getThreadPool().execute {
                runner()
            }
            return true
        } catch (e: NoSuchMethodException) {
            return false
        }
    }

    public fun login(callbackContext: CallbackContext, args: JSONArray): () -> Unit {
        return {
            val perms = (1..args.length()).map { args.getString(it -1) }.toArrayList()

            LoginManager.getInstance().registerCallback(CallbackManager.Factory.create(), object: FacebookCallback<LoginResult> {
                override fun onSuccess(result: LoginResult?) {
                    callbackContext.success(AccessToken.getCurrentAccessToken().token)
                }

                override fun onCancel() {
                    callbackContext.error("Cancelled")
                }

                override fun onError(error: FacebookException?) {
                    callbackContext.error(error?.message ?: "")
                }
            })

            if (perms.isEmpty()) {
                perms.add("public_profile")
            }
            LoginManager.getInstance().logInWithReadPermissions(cordova.activity, perms)
        }
    }
}
<commit_msg>Android に login, logout, getToken, getName を実装<commit_after>package org.fathens.cordova.plugin.fbconnect

import com.facebook.CallbackManager
import org.apache.cordova.CallbackContext
import org.apache.cordova.CordovaPlugin
import org.json.*
import com.facebook.*
import com.facebook.login.*

public class FBConnect : CordovaPlugin() {
    private var currentAction: String? = null
    private var currentCallback: CallbackContext? = null

    private val profileTracker = object: ProfileTracker() {
        var currentName: String? = null

        override fun onCurrentProfileChanged(oldProfile: Profile?, currentProfile: Profile?) {
            currentName = currentProfile?.name
            if (currentAction == "getName") {
                currentCallback?.success(currentName)
            }
        }
    }

    override fun onDestroy() {
        profileTracker.stopTracking()
    }

    override fun execute(action: String, args: JSONArray, callbackContext: CallbackContext): Boolean {
        try {
            val method = javaClass.getMethod(action, args.javaClass)
            if (method != null) {
                cordova.threadPool.execute {
                    currentAction = action
                    currentCallback = callbackContext
                    method.invoke(this, args)
                }
                return true
            } else {
                return false
            }
        } catch (e: NoSuchMethodException) {
            return false
        }
    }

    override fun pluginInitialize() {
        LoginManager.getInstance().registerCallback(CallbackManager.Factory.create(), object : FacebookCallback<LoginResult> {
            override fun onSuccess(result: LoginResult?) {
                when (currentAction) {
                    "login" -> currentCallback?.success(AccessToken.getCurrentAccessToken().token)
                }
            }
            override fun onCancel() {
                currentCallback?.error("Cancelled")
            }
            override fun onError(error: FacebookException?) {
                currentCallback?.error(error?.message ?: "")
            }
        })
    }

    public fun login(args: JSONArray) {
        val permissions = (0..args.length() - 1).map { args.getString(it) }.toArrayList()
        if (permissions.isEmpty()) {
            permissions.add("public_profile")
        }
        val (pubs, reads) = permissions.partition { perm ->
            when (perm) {
                "ads_management", "create_event", "rsvp_event" -> true
                else -> perm.startsWith("publish") || perm.startsWith("manage")
            }
        }
        if (reads.isNotEmpty() && pubs.isNotEmpty()) {
            currentCallback?.error("Cannot use permissions of both read and publish")
        }
        if (reads.isNotEmpty()) {
            LoginManager.getInstance().logInWithReadPermissions(cordova.activity, reads)
        }
        if (pubs.isNotEmpty()) {
            LoginManager.getInstance().logInWithPublishPermissions(cordova.activity, pubs)
        }
    }

    public fun logout(args: JSONArray) {
        LoginManager.getInstance().logOut()
        currentCallback?.success()
    }

    public fun getToken(args: JSONArray) {
        val result = AccessToken.getCurrentAccessToken()?.let { ac ->
            JSONObject(hashMapOf(
                    "token" to ac.token,
                    "permissions" to JSONArray(ac.permissions)
            ))
        }
        currentCallback?.success(result)
    }

    public fun getName(args: JSONArray) {
        val result = profileTracker.currentName
        if (result != null) {
            currentCallback?.success(result)
        } else {
            login(JSONArray())
        }
    }
}

{'fraction_non_alphanumeric': 0.10131675201170447, 'fraction_numerical': 0.000731528895391368, 'mean_word_length': 2.00329489291598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4221233', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1345, 'n_words': 280}