1 package io.branch.rnbranch; 2 3 import java.io.BufferedReader; 4 import java.io.FileNotFoundException; 5 import java.io.IOException; 6 import java.io.InputStreamReader; 7 import android.content.Context; 8 import android.util.Log; 9 10 import org.json.JSONException; 11 import org.json.JSONObject; 12 13 import javax.annotation.Nullable; 14 15 /** 16 * Created by jdee on 6/7/17. 17 */ 18 19 public class RNBranchConfig { 20 private JSONObject mConfiguration = null; 21 public static final String TAG = "RNBranchConfig"; 22 RNBranchConfig(Context context)23 public RNBranchConfig(Context context) { 24 try { 25 BufferedReader reader = null; 26 try { 27 reader = new BufferedReader(new InputStreamReader(context.getAssets().open("branch.json"))); 28 } catch (FileNotFoundException e) { 29 return; 30 } 31 32 StringBuilder builder = new StringBuilder(); 33 String line; 34 while ((line = reader.readLine()) != null) { 35 builder.append(line); 36 } 37 38 mConfiguration = new JSONObject(builder.toString()); 39 } 40 catch (IOException e) { 41 Log.e(TAG, "Error loading branch.json: " + e.getMessage()); 42 } 43 catch (JSONException e) { 44 Log.e(TAG, "Error parsing branch.json: " + e.getMessage()); 45 } 46 } 47 48 @Nullable get(String key)49 public Object get(String key) { 50 if (mConfiguration == null) return null; 51 52 try { 53 if (!mConfiguration.has(key)) return null; 54 return mConfiguration.get(key); 55 } 56 catch (JSONException exception) { 57 Log.e(TAG, "Error parsing branch.json: " + exception.getMessage()); 58 return null; 59 } 60 } 61 getDebugMode()62 public boolean getDebugMode() { 63 if (mConfiguration == null) return false; 64 65 try { 66 if (!mConfiguration.has("debugMode")) return false; 67 return mConfiguration.getBoolean("debugMode"); 68 } 69 catch (JSONException exception) { 70 Log.e(TAG, "Error parsing branch.json: " + exception.getMessage()); 71 return false; 72 } 73 } 74 75 @Nullable getBranchKey()76 public String getBranchKey() { 77 if (mConfiguration == null) return null; 78 79 try { 80 if (!mConfiguration.has("branchKey")) return null; 81 return mConfiguration.getString("branchKey"); 82 } 83 catch (JSONException exception) { 84 Log.e(TAG, "Error parsing branch.json: " + exception.getMessage()); 85 return null; 86 } 87 } 88 89 @Nullable getLiveKey()90 public String getLiveKey() { 91 if (mConfiguration == null) return null; 92 93 try { 94 if (!mConfiguration.has("liveKey")) return null; 95 return mConfiguration.getString("liveKey"); 96 } 97 catch (JSONException exception) { 98 Log.e(TAG, "Error parsing branch.json: " + exception.getMessage()); 99 return null; 100 } 101 } 102 103 @Nullable getTestKey()104 public String getTestKey() { 105 if (mConfiguration == null) return null; 106 107 try { 108 if (!mConfiguration.has("testKey")) return null; 109 return mConfiguration.getString("testKey"); 110 } 111 catch (JSONException exception) { 112 Log.e(TAG, "Error parsing branch.json: " + exception.getMessage()); 113 return null; 114 } 115 } 116 getUseTestInstance()117 public boolean getUseTestInstance() { 118 if (mConfiguration == null) return false; 119 120 try { 121 if (!mConfiguration.has("useTestInstance")) return false; 122 return mConfiguration.getBoolean("useTestInstance"); 123 } 124 catch (JSONException exception) { 125 Log.e(TAG, "Error parsing branch.json: " + exception.getMessage()); 126 return false; 127 } 128 } 129 getEnableFacebookLinkCheck()130 public boolean getEnableFacebookLinkCheck() { 131 if (mConfiguration == null) return false; 132 133 try { 134 if (!mConfiguration.has("enableFacebookLinkCheck")) return false; 135 return mConfiguration.getBoolean("enableFacebookLinkCheck"); 136 } 137 catch (JSONException exception) { 138 Log.e(TAG, "Error parsing branch.json: " + exception.getMessage()); 139 return false; 140 } 141 } 142 } 143