package com.testrn;

/**
 * Created by jilong5 on 2017/9/7.
 */

import android.content.Intent;
import android.widget.Toast;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import com.testrn.MainActivity;
import com.testrn.CeshiActivity;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

/**
 * 该类别是注册给rn nativeModule的句柄，方便rn的调用的
 * https://reactnative.cn/docs/0.48/native-modules-android.html#content
 */

public class ArticleHelper extends ReactContextBaseJavaModule {
    public ArticleHelper(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "ArticleHelper";
    }

    /**
     * 常量相关
     * 注册的其他方法 也同样可以被rn访问到 估计是转化到rn中的reactnativeModule上的articlehelper的proto上
     */
    @Override
    public Map<String, Object> getConstants() {
        final Map<String, Object> constants = new HashMap<>();
        constants.put("chno", 12);
        constants.put("appid", 1);
        constants.put("appver", "4.1.2");
        constants.put("deviceid", "62762b1fda6b3f7b71296786fa510e30");
        constants.put("login_uid", "1595082642");
        constants.put("article_id", "1342ac9e20102x2fn");
        constants.put("blog_uid", "5170186722");
        constants.put("sign", "ddbcc9e22f03882fb2bee91a94e3b28c336a1dbf7d10ffd086dd82b1ecce9b3b");
        constants.put("SUBP", "0033WrSXqPxfM725Ws9jqgMF55529P9D9WFNRjXsIH-MYLaUi_9fDxX-5NHD95QpSK.fehnESoBEWs4Dqcj_i--RiK.7i-i2i--fi-8siKL8i--NiKLWiKnXi--NiK.ci-zEi--ciKn0i-8F");
        constants.put("SUB", "_2A250sYmaDeRhGedL4lcR-CzKzz6IHXVXxvxSrDV_PUNbm9ANLU7hkW9KHH19dT7nLyZut2HLvmIv61FSww..");
        return constants;
    }

    @ReactMethod
    public void ajax(String cfg, Promise promise) {
        //TODO 进行后台数据请求 eg采用okhttp类库进行请求
        promise.resolve(cfg);
    }
    @ReactMethod
    public void goBack(Promise promise) {
        Intent intent = new Intent(getReactApplicationContext(),CeshiActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getReactApplicationContext().startActivity(intent);
        promise.resolve(null);
    }
}

@@ -58,16 +58,45 @@
 7.%0A */%0A%0A
+import android.app.Activity;%0A
 import a
@@ -2165,32 +2165,414 @@
 mise promise) %7B%0A
+        //%E9%80%9A%E8%BF%87getCurrentActivity %E6%96%B9%E6%B3%95%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%9A%84activity %E4%B9%8B%E5%90%8E%E8%B0%83%E7%94%A8finish%E8%B0%83%E7%94%A8%E9%80%80%E5%87%BA%E6%96%B9%E6%B3%95,%E4%BD%BF%E5%BE%97%E5%BD%93%E5%89%8D%E7%9A%84activity%E9%80%80%E5%87%BA%EF%BC%8C%E8%BF%99%E6%A0%B7%E5%9B%9E%E9%80%80%E6%A0%88%E6%8A%8A%E5%BD%93%E5%89%8D%E7%9A%84activity%E5%87%BA%E6%A0%88%EF%BC%81%0A        Activity activity = getCurrentActivity();%0A        if(activity != null)%7B%0A            promise.resolve(null);%0A            activity.finish();%0A        %7Delse%7B%0A            promise.reject(%22404%22,%22can't close activity!%22);%0A        %7D%0A        //%E6%B2%A1%E6%9C%89%E9%87%87%E7%94%A8 Intent%E7%9A%84%E6%96%B9%E5%BC%8F%E6%98%AF%E5%9B%A0%E4%B8%BA %E8%BF%99%E4%B8%AA%E4%BC%9A%E7%94%9F%E6%88%90%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84%E5%9B%9E%E9%80%80%E6%A0%88%EF%BC%8C%E4%BC%9A%E5%AF%BC%E8%87%B4%E6%88%91%E5%9B%9E%E9%80%80%0A%0A//
         Intent i
@@ -2641,16 +2641,18 @@
 class);%0A
+//
         
@@ -2699,16 +2699,18 @@
 _TASK);%0A
+//
         
@@ -2765,38 +2765,8 @@
 t);%0A
-        promise.resolve(null);
 %0A   

添加相关 退出activity的注释