Skip to content

Commit

Permalink
Merge pull request #60 from RADAR-CNS/release_0.2.5
Browse files Browse the repository at this point in the history
Release 0.2.5
  • Loading branch information
blootsvoets authored Nov 23, 2017
2 parents 8945bca + aa3d34d commit fb340a4
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 44 deletions.
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'org.radarcns.detail'
minSdkVersion 21
targetSdkVersion 25
versionCode 6
versionName "0.2.4"
versionCode 7
versionName "0.2.5"
manifestPlaceholders = ['appAuthRedirectScheme': 'org.radarcns.detail']
multiDexEnabled true
}
Expand All @@ -33,23 +33,23 @@ configurations.compile {

repositories {
jcenter()
maven { url 'http://dl.bintray.com/radar-cns/org.radarcns' }
maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local' }
flatDir { dirs 'libs' }
maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local' }
maven { url 'http://dl.bintray.com/radar-cns/org.radarcns' }
}

dependencies {
compile 'org.radarcns:radar-commons-android:0.3.3'
compile 'org.radarcns:radar-android-empatica:0.1'
compile 'org.radarcns:radar-android-phone:0.1'
compile 'org.radarcns:radar-android-application-status:0.2'
compile group: 'org.radarcns', name: 'radar-commons-android', version: '0.3.4'
compile 'org.radarcns:radar-android-empatica:0.1.1'
compile 'org.radarcns:radar-android-phone:0.1.1'
compile 'org.radarcns:radar-android-application-status:0.2.1'
compile 'org.radarcns:radar-android-weather:0.1'

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.firebase:firebase-config:11.0.4'
compile 'org.radarcns:radar-android-login-oauth2:0.3'
compile 'org.radarcns:radar-android-login-qr:0.3'
compile group: 'org.radarcns', name: 'radar-android-login-oauth2', version: '0.3.4'
compile group: 'org.radarcns', name: 'radar-android-login-qr', version: '0.3.4'

// logging only on device, not for compiling or tests
apk 'org.slf4j:slf4j-android:1.7.25'
Expand Down
84 changes: 64 additions & 20 deletions app/src/main/java/org/radarcns/detail/RadarLoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,35 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import org.json.JSONException;
import org.json.JSONObject;
import org.radarcns.android.RadarConfiguration;
import org.radarcns.android.auth.*;
import org.radarcns.android.auth.oauth2.Jwt;
import org.radarcns.android.auth.AppAuthState;
import org.radarcns.android.auth.AuthStringParser;
import org.radarcns.android.auth.LoginActivity;
import org.radarcns.android.auth.LoginManager;
import org.radarcns.android.auth.ManagementPortalLoginManager;
import org.radarcns.android.auth.QrLoginManager;
import org.radarcns.android.auth.oauth2.OAuth2LoginManager;
import org.radarcns.android.util.Boast;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import static org.radarcns.android.auth.LoginManager.AUTH_TYPE_BEARER;
import static org.radarcns.android.auth.oauth2.OAuth2LoginManager.LOGIN_REFRESH_TOKEN;

public class RadarLoginActivity extends LoginActivity {
private static final Logger logger = LoggerFactory.getLogger(RadarLoginActivity.class);

private OAuth2LoginManager oauthManager;
private QrLoginManager qrManager;
private ManagementPortalLoginManager mpManager;
private boolean canLogin;
private ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedBundleInstance) {
Expand All @@ -57,30 +67,54 @@ protected void onResume() {
@Override
protected List<LoginManager> createLoginManagers(AppAuthState state) {
this.oauthManager = new OAuth2LoginManager(this, null, "sub", state);
RadarConfiguration config = RadarConfiguration.getInstance();
if (managementPortal == null) {
Boast.makeText(this, "Remote app configuration invalid. Quitting.", Toast.LENGTH_LONG).show();
try {
Thread.sleep(5_000L);
} catch (InterruptedException e) {
logger.error("Login exit sleep interrupted");
}
System.exit(1);
}
this.mpManager = new ManagementPortalLoginManager(this, state, managementPortal,
config.getString("oauth2_client_id", "pRMT"),
config.getString("oauth2_client_secret", ""));
this.qrManager = new QrLoginManager(this, new AuthStringParser() {
@NonNull
@Override
public AppAuthState parse(@NonNull String s) {
onProcessing(R.string.logging_in);
try {
JSONObject object = new JSONObject(s);
if (!object.has("refreshToken")) {
throw new IllegalArgumentException("No valid refresh token found");
}
String refreshToken = object.getString("refreshToken");
Jwt jwt = Jwt.parse(refreshToken);
JSONObject jwtBody = jwt.getBody();
return new AppAuthState.Builder()
.tokenType(AUTH_TYPE_BEARER)
.property(LOGIN_REFRESH_TOKEN, refreshToken)
.userId(jwtBody.getString("sub"))
.expiration(jwtBody.getLong("exp") * 1_000L)
.build();
mpManager.setRefreshToken(refreshToken);
mpManager.refresh();
return null;
} catch (JSONException e) {
throw new IllegalArgumentException("QR code does not contain valid JSON.", e);
}
}
});
return Arrays.asList(this.qrManager, this.oauthManager);
return Arrays.asList(this.qrManager, this.oauthManager, this.mpManager);
}

private void onProcessing(int titleResource) {
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setTitle(titleResource);
progressDialog.show();
}

private void onDoneProcessing() {
if (progressDialog != null) {
logger.info("Closing progress window");
progressDialog.cancel();
logger.info("Closed progress window");
progressDialog = null;
}
}

@NonNull
Expand All @@ -99,19 +133,29 @@ public void scan(View view) {
public void login(View view) {
if (canLogin) {
canLogin = false;
onProcessing(R.string.firebase_fetching);
final RadarConfiguration config = RadarConfiguration.getInstance();
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setTitle(R.string.firebase_fetching);
progressDialog.show();
config.fetch().addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
progressDialog.cancel();
onDoneProcessing();
config.activateFetched();
oauthManager.start();
}
});
}
}

@Override
protected AppAuthState updateMpInfo(LoginManager manager, @NonNull AppAuthState state) throws IOException {
AppAuthState newAuthState = super.updateMpInfo(manager, state);
onDoneProcessing();
return newAuthState;
}

@Override
public void loginFailed(LoginManager manager, Exception ex) {
onDoneProcessing();
super.loginFailed(manager, ex);
}
}
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20pt"
android:gravity="bottom"
android:gravity="center"
tools:context=".RadarLoginActivity">

<Button
Expand All @@ -32,7 +32,6 @@
android:onClick="scan"
android:layout_marginBottom="78dp"/>


<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@
<string name="login_button">Login on the website</string>
<string name="logout_button">Log out</string>
<string name="scan_qr_button">Scan QR code</string>
<string name="logging_in">Logging in</string>
</resources>
20 changes: 8 additions & 12 deletions app/src/main/res/xml/remote_config_defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,21 @@
<!-- START xml_defaults -->
<defaultsMap>
<entry>
<key>empatica_api_key</key>
<value></value>
<key>management_portal_url</key>
<value>https://radar-cns-platform.rosalind.kcl.ac.uk/managementportal/</value>
</entry>
<entry>
<key>kafka_rest_proxy_url</key>
<value></value>
<value>https://radar-cns-platform.rosalind.kcl.ac.uk/kafka/</value>
</entry>
<entry>
<key>schema_registry_url</key>
<value></value>
</entry>
<entry>
<key>default_group_id</key>
<value></value>
<value>https://radar-cns-platform.rosalind.kcl.ac.uk/schema/</value>
</entry>
<entry>
<key>start_at_boot</key>
<value>true</value>
</entry>
<entry>
<key>device_data_retention_ms</key>
<value>86400000</value>
</entry>
<entry>
<key>ui_refresh_rate_millis</key>
<value>250</value>
Expand Down Expand Up @@ -78,6 +70,10 @@
<key>oauth2_client_id</key>
<value>pRMT</value>
</entry>
<entry>
<key>oauth2_client_secret</key>
<value>secret</value>
</entry>
<entry>
<key>oauth2_redirect_url</key>
<value>org.radarcns.detail://oauth2/redirect</value>
Expand Down

0 comments on commit fb340a4

Please sign in to comment.