Compare commits

..
6 Commits
Author SHA1 Message Date
Akinwale Ariwodola 8bd59f5e80 0.13.4 patch 2020-03-13 17:40:51 +01:00
Akinwale Ariwodola ea8ac783a8 bumpversion 0.13.2 --> 0.13.3 2020-03-13 08:32:09 +01:00
Akinwale Ariwodola 966dd2bf2c add log method to utility module 2020-03-13 02:03:39 +01:00
Akinwale Ariwodola 364de592fa use snake case for payload keys 2020-03-12 21:16:39 +01:00
Akinwale Ariwodola d38241f0d1 check for contentTitle and channelUrl in payload 2020-03-11 15:55:35 +01:00
Akinwale Ariwodola e217be6b67 Fast lite mode (native code) (#864)
* fast loading lite mode
* add react methods for lbrynet dir and platform
* send additional url parameters for cold start
* pending intent
* update gitlab CI
2020-03-11 15:21:41 +01:00
5 changed files with 75 additions and 46 deletions

No files matched your search

+6 -3
View File
@@ -3,6 +3,9 @@ stages:
- deploy
- release
variables:
REACT_NATIVE_BRANCH: "fix-related-content"
build apk:
stage: build
image: lbry/android-base:platform-28
@@ -14,7 +17,7 @@ build apk:
- ln -fs /opt/node-v10.19.0-linux-x64/bin/npx /usr/bin/npx
- chmod u+x $CI_PROJECT_DIR/gradlew
- export ANDROID_SDK_ROOT=~/.buildozer/android/platform/android-sdk-23
- export BUILD_VERSION=$($CI_PROJECT_DIR/gradlew -q printVersionName --console=plain | tail -1)
- export BUILD_VERSION=$($CI_PROJECT_DIR/gradlew -q printVersionName --console=plain | tail -1)
artifacts:
paths:
- bin/browser-*-release__arm.apk
@@ -31,7 +34,7 @@ build apk:
- git secret reveal
- npm install -g react-native-cli
- cd ~/
- git clone https://github.com/lbryio/lbry-react-native
- git clone --single-branch --branch $REACT_NATIVE_BRANCH https://github.com/lbryio/lbry-react-native
- cd lbry-react-native
- chmod u+x bundle-android.sh
- yarn
@@ -44,7 +47,7 @@ build apk:
- cd $CI_PROJECT_DIR
- cp bin/browser-$BUILD_VERSION-release__arm.apk /dev/null
- cp bin/browser-$BUILD_VERSION-release__arm64.apk /dev/null
deploy build.lbry.io:
image: python:stretch
stage: deploy
+2 -2
View File
@@ -143,8 +143,8 @@ android {
applicationId "io.lbry.browser"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1302
versionName "0.13.2"
versionCode 1304
versionName "0.13.4"
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
}
@@ -18,8 +18,11 @@ import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import io.lbry.lbrysdk.LbrynetService;
import io.lbry.browser.reactmodules.UtilityModule;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -54,6 +57,11 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
String title = payload.get("title");
String body = payload.get("body");
String name = payload.get("name"); // notification name
String contentTitle = payload.get("content_title");
String channelUrl = payload.get("channel_url");
//String publishTime = payload.get("publish_time");
String publishTime = null;
if (type != null && getEnabledTypes().indexOf(type) > -1 && body != null && body.trim().length() > 0) {
// only log the receive event for valid notifications received
if (firebaseAnalytics != null) {
@@ -62,7 +70,7 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
firebaseAnalytics.logEvent("lbry_notification_receive", bundle);
}
sendNotification(title, body, type, url, name);
sendNotification(title, body, type, url, name, contentTitle, channelUrl, publishTime);
}
}
}
@@ -94,7 +102,8 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String title, String messageBody, String type, String url, String name) {
private void sendNotification(String title, String messageBody, String type, String url, String name,
String contentTitle, String channelUrl, String publishTime) {
//Intent intent = new Intent(this, MainActivity.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (url == null) {
@@ -104,6 +113,28 @@ public class LbrynetMessagingService extends FirebaseMessagingService {
// default to home page
url = "lbry://?discover";
}
} else {
if (!MainActivity.isServiceRunning(this, LbrynetService.class) &&
contentTitle != null &&
channelUrl != null
) {
// only enter lite mode when contentTitle and channelUrl are set (and the service isn't running yet)
// cold start
url = url + ((url.indexOf("?") > -1) ? "&liteMode=1" : "?liteMode=1");
try {
if (contentTitle != null) {
url = url + "&contentTitle=" + URLEncoder.encode(contentTitle, "UTF-8");
}
if (channelUrl != null) {
url = url + "&channelUrl=" + URLEncoder.encode(channelUrl, "UTF-8");
}
if (publishTime != null) {
url = url + "&publishTime=" + URLEncoder.encode(publishTime, "UTF-8");
}
} catch (UnsupportedEncodingException ex) {
// shouldn't happen
}
}
}
Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
@@ -2,6 +2,7 @@ package io.lbry.browser;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.PendingIntent;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
@@ -153,12 +154,20 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
registerDownloadEventReceiver();
// Start the daemon service if it is not started
serviceRunning = isServiceRunning(LbrynetService.class);
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (!serviceRunning) {
CurrentLaunchTiming.setColdStart(true);
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
}
if (LbrynetService.serviceInstance != null) {
// TODO: Add a broadcast receiver to listen for the service started event, so that we can set this properly
Context context = getApplicationContext();
Intent contextIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
LbrynetService.serviceInstance.setPendingContextIntent(pendingIntent);
}
checkNotificationOpenIntent(getIntent());
mReactRootView = new RNGestureHandlerEnabledRootView(this);
@@ -383,9 +392,9 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
switch (requestCode) {
case STORAGE_PERMISSION_REQ_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (BuildConfig.DEBUG && !Settings.canDrawOverlays(this)) {
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}
if (reactContext != null) {
@@ -444,37 +453,6 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
}
}
public static String acquireDeviceId(Context context) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String id = null;
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
id = telephonyManager.getImei(); // GSM
if (id == null) {
id = telephonyManager.getMeid(); // CDMA
}
} else {
id = telephonyManager.getDeviceId();
}
} catch (SecurityException ex) {
// Maybe the permission was not granted? Try to acquire permission
checkPhoneStatePermission(context);
} catch (Exception ex) {
// id could not be obtained. Display a warning that rewards cannot be claimed.
}
if (id == null || id.trim().length() == 0) {
Toast.makeText(context, "Rewards cannot be claimed because we could not identify your device.", Toast.LENGTH_LONG).show();
}
SharedPreferences sp = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(DEVICE_ID_KEY, id);
editor.commit();
return id;
}
@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
@@ -494,7 +472,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
super.onResume();
SharedPreferences sp = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
serviceRunning = isServiceRunning(LbrynetService.class);
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (!serviceRunning) {
ServiceHelper.start(this, "", LbrynetService.class, "lbrynetservice");
}
@@ -510,7 +488,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
SharedPreferences sp = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
boolean shouldKeepDaemonRunning = sp.getBoolean(SETTING_KEEP_DAEMON_RUNNING, true);
if (!shouldKeepDaemonRunning) {
serviceRunning = isServiceRunning(LbrynetService.class);
serviceRunning = isServiceRunning(this, LbrynetService.class);
if (serviceRunning) {
ServiceHelper.stop(this, LbrynetService.class);
}
@@ -544,7 +522,7 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
notificationManager.cancel(downloadNotificationIds.get(i));
}
}
if (receivedStopService || !isServiceRunning(LbrynetService.class)) {
if (receivedStopService || !isServiceRunning(this, LbrynetService.class)) {
notificationManager.cancelAll();
}
super.onDestroy();
@@ -635,8 +613,8 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
true);
}
private boolean isServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(serviceInfo.service.getClassName())) {
return true;
@@ -470,4 +470,21 @@ public class UtilityModule extends ReactContextBaseJavaModule {
// This obtains a public default download directory after the storage permission has been granted
promise.resolve(Utils.getConfiguredDownloadDirectory(context));
}
@ReactMethod
public void getLbrynetDirectory(Promise promise) {
String path = String.format("%s/%s", Utils.getAppInternalStorageDir(context), "lbrynet");
promise.resolve(path);
}
@ReactMethod
public void getPlatform(Promise promise) {
String platform = String.format("Android %s (API %s)", Utils.getAndroidRelease(), Utils.getAndroidSdk());
promise.resolve(platform);
}
@ReactMethod
public void log(String tag, String message) {
android.util.Log.d(tag, message);
}
}