mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 13:23:12 +08:00 
			
		
		
		
	Record local hash info
This commit is contained in:
		| @@ -15,7 +15,6 @@ import org.json.JSONException; | ||||
| import org.json.JSONObject; | ||||
| import org.json.JSONTokener; | ||||
|  | ||||
| import java.io.BufferedInputStream; | ||||
| import java.io.ByteArrayOutputStream; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| @@ -32,9 +31,8 @@ import okio.BufferedSink; | ||||
| import okio.BufferedSource; | ||||
| import okio.Okio; | ||||
| import static cn.reactnative.modules.update.UpdateModule.sendEvent; | ||||
| /** | ||||
|  * Created by tdzl2003 on 3/31/16. | ||||
|  */ | ||||
|  | ||||
|  | ||||
| class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> { | ||||
|     final int DOWNLOAD_CHUNK_SIZE = 4096; | ||||
|  | ||||
|   | ||||
| @@ -17,9 +17,6 @@ import java.util.concurrent.Executors; | ||||
|  | ||||
| import java.io.File; | ||||
|  | ||||
| /** | ||||
|  * Created by tdzl2003 on 3/31/16. | ||||
|  */ | ||||
| public class UpdateContext { | ||||
|     private Context context; | ||||
|     private File rootDir; | ||||
| @@ -72,10 +69,6 @@ public class UpdateContext { | ||||
|         return context.getString(R.string.pushy_build_time); | ||||
|     } | ||||
|  | ||||
|     public String getUuid() { | ||||
|         return sp.getString("uuid", null); | ||||
|     } | ||||
|  | ||||
|     public Map getBlockUpdate() { | ||||
|         return new HashMap<String, Object>() {{ | ||||
|             put("until", sp.getInt("blockUntil", 0)); | ||||
| @@ -163,12 +156,16 @@ public class UpdateContext { | ||||
|         editor.apply(); | ||||
|     } | ||||
|  | ||||
|     public void setUuid(String uuid) { | ||||
|     public void setKv(String key, String value) { | ||||
|         SharedPreferences.Editor editor = sp.edit(); | ||||
|         editor.putString("uuid", uuid); | ||||
|         editor.putString(key, value); | ||||
|         editor.apply(); | ||||
|     } | ||||
|  | ||||
|     public String getKv(String key) { | ||||
|         return sp.getString(key, null); | ||||
|     } | ||||
|  | ||||
|     public void setBlockUpdate(int until, String reason) { | ||||
|         SharedPreferences.Editor editor = sp.edit(); | ||||
|         editor.putInt("blockUntil", until); | ||||
| @@ -191,7 +188,11 @@ public class UpdateContext { | ||||
|     public void markSuccess() { | ||||
|         SharedPreferences.Editor editor = sp.edit(); | ||||
|         editor.putBoolean("firstTimeOk", true); | ||||
|         editor.remove("lastVersion"); | ||||
|         String lastVersion = sp.getString("lastVersion", null); | ||||
|         if (lastVersion != null) { | ||||
|             editor.remove("lastVersion"); | ||||
|             editor.remove("hash_" + lastVersion); | ||||
|         } | ||||
|         editor.apply(); | ||||
|  | ||||
|         this.cleanUp(); | ||||
|   | ||||
| @@ -22,15 +22,11 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| import static android.support.v4.content.FileProvider.getUriForFile; | ||||
|  | ||||
| /** | ||||
|  * Created by tdzl2003 on 3/31/16. | ||||
|  */ | ||||
| public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|     UpdateContext updateContext; | ||||
|     public static ReactApplicationContext mContext; | ||||
| @@ -64,7 +60,7 @@ public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|             updateContext.clearRollbackMark(); | ||||
|         } | ||||
|         constants.put("blockUpdate", updateContext.getBlockUpdate()); | ||||
|         constants.put("uuid", updateContext.getUuid()); | ||||
|         constants.put("uuid", updateContext.getKv("uuid")); | ||||
|         return constants; | ||||
|     } | ||||
|  | ||||
| @@ -264,11 +260,27 @@ public class UpdateModule extends ReactContextBaseJavaModule { | ||||
|         UiThreadUtil.runOnUiThread(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 updateContext.setUuid(uuid); | ||||
|                 updateContext.setKv("uuid", uuid); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @ReactMethod | ||||
|     public void setLocalHashInfo(final String hash, final String info) { | ||||
|         UiThreadUtil.runOnUiThread(new Runnable() { | ||||
|             @Override | ||||
|             public void run() { | ||||
|                 updateContext.setKv("hash_" + hash, info); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @ReactMethod | ||||
|     public void getLocalHashInfo(final String hash, final Promise promise) { | ||||
|         promise.resolve(updateContext.getKv("hash_" + hash)); | ||||
|     } | ||||
|      | ||||
|  | ||||
|     /* 发送事件*/ | ||||
|     public static void sendEvent(String eventName, WritableMap params) { | ||||
|         ((ReactContext) mContext).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm