
package com.netcetera.reactnative.twitterkit;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;


import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.Twitter;
import com.twitter.sdk.android.core.DefaultLogger;
import com.twitter.sdk.android.core.TwitterConfig;

public class ReactTwitterKitPackage implements ReactPackage {


  @Nullable
  private final String consumerKey;
  @Nullable
  private final String consumerSecret;

  /**
   * Initializes the package. If you don't pass a consumer key and secret the package
   * assumes you've *already* initialized Fabric elsewhere.
   *
   * @param consumerKey the key
   * @param consumerSecret the secret
   */
  public ReactTwitterKitPackage(@Nullable String consumerKey,  @Nullable String consumerSecret) {

    this.consumerKey = consumerKey;
    this.consumerSecret = consumerSecret;
  }

  /**
   * Initializes the package *without* initializing Fabric.
   */
  public ReactTwitterKitPackage() {
    this(null, null);
  }

  public void initFabric(Context reactContext) {
    if (consumerKey == null || consumerSecret == null) {
      return;
    }

    TwitterAuthConfig authConfig
            = new TwitterAuthConfig(consumerKey, consumerSecret);

    final TwitterConfig config = new TwitterConfig.Builder(reactContext)
            .twitterAuthConfig(authConfig)
            .debug(true)
            .build();
    Twitter.initialize(config);;
  }

  @Override
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
    return Collections.emptyList();
  }

  @Override
  public List<ViewManager> createViewManagers(
          ReactApplicationContext reactContext) {
    initFabric(reactContext);
    return Arrays.<ViewManager>asList(
            new ReactTweetViewManager()
    );
  }
}
@@ -147,88 +147,8 @@
 g;%0A%0A
-import java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0A%0A
 impo
@@ -337,16 +337,60 @@
 anager;%0A
+import com.twitter.sdk.android.core.Twitter;
 %0Aimport 
@@ -484,110 +484,141 @@
 tter
-;%0Aimport com.twitter.sdk.android.core.DefaultLogger;%0Aimport com.twitter.sdk.android.core.TwitterConfig
+Config;%0Aimport com.twitter.sdk.android.tweetui.TweetUi;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List
 ;%0A%0Ap
@@ -1751,16 +1751,210 @@
 config);
+%0A    new Thread(new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A        TweetUi.getInstance();%0A        Log.i(%22ReactTwitterKit%22, %22TweetUi instance initialized%22);%0A      %7D%0A    %7D).start()
 ;%0A  %7D%0A%0A 

Initialize TweetUi