1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-07 15:45:14 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Implement blockupdate on android

This commit is contained in:
sunnylqm
2020-08-31 18:39:03 +08:00
parent c6f9bb20a1
commit 59fcba15ee
5 changed files with 80 additions and 20 deletions

View File

@@ -7,6 +7,8 @@ import android.content.pm.PackageManager;
import android.util.Log;
import com.facebook.react.ReactInstanceManager;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -68,6 +70,17 @@ 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));
put("reason", sp.getString("blockReason", null));
}};
}
public boolean getIsUsingBundleUrl() {
return isUsingBundleUrl;
}
@@ -130,6 +143,19 @@ public class UpdateContext {
editor.apply();
}
public void setUuid(String uuid) {
SharedPreferences.Editor editor = sp.edit();
editor.putString("uuid", uuid);
editor.apply();
}
public void setBlockUpdate(int until, String reason) {
SharedPreferences.Editor editor = sp.edit();
editor.putInt("blockUntil", until);
editor.putString("blockReason", reason);
editor.apply();
}
public String getCurrentVersion() {
return sp.getString("currentVersion", null);
}

View File

@@ -57,6 +57,8 @@ public class UpdateModule extends ReactContextBaseJavaModule{
if (isRolledBack) {
updateContext.clearRollbackMark();
}
constants.put("blockUpdate", updateContext.getBlockUpdate());
constants.put("uuid", updateContext.getUuid());
return constants;
}
@@ -184,6 +186,28 @@ public class UpdateModule extends ReactContextBaseJavaModule{
});
}
@ReactMethod
public void setBlockUpdate(ReadableMap options) {
final int until = options.getInt("until");
final String reason = options.getString("reason");
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
updateContext.setBlockUpdate(until, reason);
}
});
}
@ReactMethod
public void setUuid(final String uuid) {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
updateContext.setUuid(uuid);
}
});
}
/* 发送事件*/
public static void sendEvent(String eventName, WritableMap params) {
((ReactContext) mContext).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName,