Merge pull request #204 from lbryio/keep-awake
This commit is contained in:
commit
5e3275e547
3 changed files with 60 additions and 1 deletions
|
@ -65,6 +65,9 @@ class FilePage extends React.PureComponent {
|
||||||
if (NativeModules.Mixpanel) {
|
if (NativeModules.Mixpanel) {
|
||||||
NativeModules.Mixpanel.track('Open File Page', { Uri: uri });
|
NativeModules.Mixpanel.track('Open File Page', { Uri: uri });
|
||||||
}
|
}
|
||||||
|
if (NativeModules.UtilityModule) {
|
||||||
|
NativeModules.UtilityModule.keepAwakeOn();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
|
@ -135,6 +138,9 @@ class FilePage extends React.PureComponent {
|
||||||
StatusBar.setHidden(false);
|
StatusBar.setHidden(false);
|
||||||
if (NativeModules.ScreenOrientation) {
|
if (NativeModules.ScreenOrientation) {
|
||||||
NativeModules.ScreenOrientation.unlockOrientation();
|
NativeModules.ScreenOrientation.unlockOrientation();
|
||||||
|
}
|
||||||
|
if (NativeModules.UtilityModule) {
|
||||||
|
NativeModules.UtilityModule.keepAwakeOff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package io.lbry.browser.reactmodules;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
|
|
||||||
|
public class UtilityModule extends ReactContextBaseJavaModule {
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public UtilityModule(ReactApplicationContext reactContext) {
|
||||||
|
super(reactContext);
|
||||||
|
this.context = reactContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "UtilityModule";
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void keepAwakeOn() {
|
||||||
|
final Activity activity = getCurrentActivity();
|
||||||
|
|
||||||
|
if (activity != null) {
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void keepAwakeOff() {
|
||||||
|
final Activity activity = getCurrentActivity();
|
||||||
|
|
||||||
|
if (activity != null) {
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import io.lbry.browser.reactmodules.FirstRunModule;
|
||||||
import io.lbry.browser.reactmodules.MixpanelModule;
|
import io.lbry.browser.reactmodules.MixpanelModule;
|
||||||
import io.lbry.browser.reactmodules.ScreenOrientationModule;
|
import io.lbry.browser.reactmodules.ScreenOrientationModule;
|
||||||
import io.lbry.browser.reactmodules.VersionInfoModule;
|
import io.lbry.browser.reactmodules.VersionInfoModule;
|
||||||
|
import io.lbry.browser.reactmodules.UtilityModule;;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -31,8 +32,9 @@ public class LbryReactPackage implements ReactPackage {
|
||||||
modules.add(new FirstRunModule(reactContext));
|
modules.add(new FirstRunModule(reactContext));
|
||||||
modules.add(new MixpanelModule(reactContext));
|
modules.add(new MixpanelModule(reactContext));
|
||||||
modules.add(new ScreenOrientationModule(reactContext));
|
modules.add(new ScreenOrientationModule(reactContext));
|
||||||
|
modules.add(new UtilityModule(reactContext));
|
||||||
modules.add(new VersionInfoModule(reactContext));
|
modules.add(new VersionInfoModule(reactContext));
|
||||||
|
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue