Skip to content
Snippets Groups Projects
Commit ab2e8ddf authored by ect1u17's avatar ect1u17
Browse files

Changes since last commit:

- Finished progress page
- Implemented Auth0 login and signup
parent 960651e6
No related branches found
No related tags found
No related merge requests found
Showing
with 1271 additions and 115 deletions
......@@ -11,6 +11,7 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [auth0Domain: "@string/com_auth0_domain", auth0Scheme: "@string/auth0_scheme"]
}
buildTypes {
release {
......@@ -35,4 +36,6 @@ dependencies {
api 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'com.github.sundeepk:compact-calendar-view:3.0.0'
implementation 'com.auth0.android:auth0:1.22.1'
implementation 'com.auth0.android:lock:2.7.0'
}
......@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
......@@ -24,6 +25,13 @@
</intent-filter>
</activity>
<activity
android:name="com.auth0.android.lock.LockActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/Lock.Theme"/>
<activity
android:name=".AboutActivity"
android:label="About"
......
......@@ -151,7 +151,7 @@ public class BoxesActivity extends AppCompatActivity {
JSONObject localData = new JSONObject(ProjectMacros.readFile(BoxesActivity.this, "localUserData.json"));
if (!locked && ProjectMacros.checkDateLimit(localData.getString("dateUntil"))) {
if (!locked) {
Intent openPage = new Intent(BoxesActivity.this, ExperimentActivity.class);
openPage.putExtra("JSON", box.toString());
startActivity(openPage);
......
......@@ -4,16 +4,31 @@ import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.auth0.android.Auth0;
import com.auth0.android.authentication.AuthenticationAPIClient;
import com.auth0.android.authentication.AuthenticationException;
import com.auth0.android.callback.BaseCallback;
import com.auth0.android.lock.AuthenticationCallback;
import com.auth0.android.lock.Lock;
import com.auth0.android.lock.utils.LockException;
import com.auth0.android.result.Credentials;
import java.util.Objects;
import static android.util.Log.d;
public class LoginActivity extends AppCompatActivity {
private Auth0 auth0;
private Lock lock;
@Override
public boolean onSupportNavigateUp() {
finish();
......@@ -32,11 +47,51 @@ public class LoginActivity extends AppCompatActivity {
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
auth0 = new Auth0(getString(R.string.com_auth0_client_id), getString(R.string.com_auth0_domain));
auth0.setOIDCConformant(true);
lock = Lock.newBuilder(auth0, cb).build(this);
final EditText email = findViewById(R.id.EmailEditText);
final EditText password = findViewById(R.id.PasswordEditText);
final AuthenticationAPIClient authentication = new AuthenticationAPIClient(auth0);
Button submitLoginButton = findViewById(R.id.LoginSubmitButton);
submitLoginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO: implement what happens on submitting login
authentication
.login(email.getText().toString(), password.getText().toString(), "Username-Password-Authentication")
.start(new BaseCallback<Credentials, AuthenticationException>() {
@Override
public void onSuccess(Credentials payload) {
d("dbg_success", payload.getIdToken());
}
@Override
public void onFailure(AuthenticationException error) {
d("dbg_failure", error.getMessage());
}
});
//startActivity(lock.newIntent(LoginActivity.this));
}
});
}
private AuthenticationCallback cb = new AuthenticationCallback() {
@Override
public void onError(LockException error) {
d("dbg_err", "err");
}
@Override
public void onAuthentication(Credentials credentials) {
d("dbg_success", "success");
}
@Override
public void onCanceled() {
d("dbg_cancelled", "cancelled");
}
};
}
......@@ -269,7 +269,25 @@ public class MainActivity extends AppCompatActivity {
File file = new File(this.getFilesDir(), "localUserData.json");
if (!file.exists()) {
// Do stuff to initialise the file
ProjectMacros.saveFile(this, "localUserData.json", "{\"d\":\"01/31/1999\",\"savedUserID\":\"A01\"}");
InputStream inputStream = getResources().openRawResource(R.raw.local_user_data);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
String localUserData = "";
int ctr;
try {
ctr = inputStream.read();
while (ctr != -1) {
byteArrayOutputStream.write(ctr);
ctr = inputStream.read();
}
inputStream.close();
localUserData = byteArrayOutputStream.toString();
} catch (Exception e) {
e.printStackTrace();
}
ProjectMacros.saveFile(this, "localUserData.json", localUserData);
}
}
......@@ -316,7 +334,23 @@ public class MainActivity extends AppCompatActivity {
ProjectMacros.saveFile(this, "boxData.json", boxesData);
ProjectMacros.saveFile(this, "localUserData.json", "{\"dateUntil\": \"01/31/1999\",\n\"savedUserID\": \"A01\",\n\"locked\": false}");
inputStream = getResources().openRawResource(R.raw.local_user_data);
byteArrayOutputStream = new ByteArrayOutputStream();
String localUserData = "";
try {
ctr = inputStream.read();
while (ctr != -1) {
byteArrayOutputStream.write(ctr);
ctr = inputStream.read();
}
inputStream.close();
localUserData = byteArrayOutputStream.toString();
} catch (Exception e) {
e.printStackTrace();
}
ProjectMacros.saveFile(this, "localUserData.json", localUserData);
d("dbg_file", ProjectMacros.readFile(this, "boxData.json"));
d("dbg_file", ProjectMacros.readFile(this, "localUserData.json"));
......@@ -351,6 +385,36 @@ public class MainActivity extends AppCompatActivity {
// Image permission check
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void askForWriteAccess() {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
Manifest.permission.INTERNET)) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Permission Required")
.setMessage("Permission to access internet for login.")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.fromParts("package", getPackageName(), null));
startActivityForResult(intent, 5);
}
}).setNegativeButton("Cancel", null).show();
} else {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.INTERNET},
1);
}
} else {
d("dbg_Perm", "Already granted");
}
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
......
......@@ -136,6 +136,16 @@ public class TestingActivity extends AppCompatActivity {
ProjectMacros.createNotification("Test Notification", "This is a test notification for the notification system!", R.raw.box_outline, "ALL_CHANNEL", TestingActivity.this, timeNowOffset, repeatTime);
}
});
Button fourthTestButton = new Button(this);
buttonHolder.addView(fourthTestButton);
fourthTestButton.setText(Html.fromHtml("Launch login page"));
fourthTestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(TestingActivity.this, LoginActivity.class));
}
});
}
@RequiresApi(api = Build.VERSION_CODES.N)
......
......@@ -30,6 +30,7 @@
android:text="@string/login_email" />
<EditText
android:id="@+id/EmailEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
......@@ -52,6 +53,7 @@
android:text="@string/login_password" />
<EditText
android:id="@+id/PasswordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProgressActivity"
......@@ -32,7 +33,7 @@
<ScrollView
android:id="@+id/progressScrollObject"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
......@@ -40,6 +41,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/calendarLinLay"
android:layout_width="match_parent"
......@@ -47,18 +49,18 @@
android:orientation="vertical">
<com.github.sundeepk.compactcalendarview.CompactCalendarView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/compactcalendar_view"
android:id="@+id/compactCalendarGraph"
android:layout_width="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_height="250dp"
app:compactCalendarTargetHeight="250dp"
app:compactCalendarTextSize="12sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:compactCalendarBackgroundColor="@color/calendarBackground"
app:compactCalendarTextColor="@color/colorPrimaryDark"
app:compactCalendarCurrentDayBackgroundColor="#8F587B7F"
app:compactCalendarCurrentSelectedDayBackgroundColor="@color/colorPrimary"
app:compactCalendarCurrentDayBackgroundColor="@color/colorPrimary"
app:compactCalendarMultiEventIndicatorColor="@color/colorAccent" />
app:compactCalendarMultiEventIndicatorColor="@color/colorAccent"
app:compactCalendarTargetHeight="250dp"
app:compactCalendarTextColor="@color/colorPrimaryDark"
app:compactCalendarTextSize="12sp" />
</LinearLayout>
<LinearLayout
......@@ -67,6 +69,20 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<com.github.sundeepk.compactcalendarview.CompactCalendarView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/compactCalendarJournal"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:compactCalendarBackgroundColor="@color/calendarBackground"
app:compactCalendarCurrentDayBackgroundColor="#8F587B7F"
app:compactCalendarCurrentSelectedDayBackgroundColor="@color/colorPrimary"
app:compactCalendarMultiEventIndicatorColor="@color/colorAccent"
app:compactCalendarTargetHeight="250dp"
app:compactCalendarTextColor="@color/colorPrimaryDark"
app:compactCalendarTextSize="12sp" />
</LinearLayout>
</LinearLayout>
......@@ -74,4 +90,16 @@
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/editCurrentJournal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:clickable="true"
app:backgroundTint="@color/colorPrimary"
app:fabCustomSize="100dp"
app:fabSize="normal"
app:maxImageSize="75dp"
app:srcCompat="@android:drawable/ic_menu_edit" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
{
"dateUntil":"22\/03\/2020",
"savedUserID":"A01",
"locked":true,
"lockedExperiment":{
"Title":"Sunlight",
"Instructions":"Get 30 to 45 minutes of sunlight a day. Make sure your room captures sunlight.",
"Description":"This will boost circadian rhythm.",
"VideoProcessing":true,
"AudioProcessing":true,
"ImageProcessing":true,
"SurveyQuestions":[
"Test question 1",
"Test question 2"],
"Notification":[{
"Title":"Test notification!",
"Message":"Testing Notification for all the cool abilities that it can run, should I allow another thing upload? No, I don't care enough tbh...",
"Time":"18:10",
"Repeat":"00:01 hours"
}],
"ArtefactImplementation":true,
"UserData": [{
"Date": "22\/03\/2020",
"AverageResult": "1.5",
"Experiment": "Test",
"Type": "Eat"
}]
},
"journal": [{
"Date": "04\/03\/2020",
"Entry": "This is a text entry for this result!1",
"Experiment": "Sleep"
},{
"Date": "05\/03\/2020",
"Entry": "This is a text entry for this result!2",
"Experiment": "Sleep"
},{
"Date": "06\/03\/2020",
"Entry": "This is a text entry for this result!3",
"Experiment": "Sleep"
},{
"Date": "07\/03\/2020",
"Entry": "This is a text entry for this result!4",
"Experiment": "Sleep"
},{
"Date": "08\/03\/2020",
"Entry": "This is a text entry for this result!5",
"Experiment": "Sleep"
},{
"Date": "20\/03\/2020",
"Entry": "This is a text entry for this result!6",
"Experiment": "Sunlight"
},{
"Date": "21\/03\/2020",
"Entry": "This is a text entry for this result!7",
"Experiment": "Sunlight"
},{
"Date": "22\/03\/2020",
"Entry": "This is a text entry for this result!8",
"Experiment": "Sunlight"
},{
"Date": "23\/03\/2020",
"Entry": "This is a text entry for this result!9",
"Experiment": "Sunlight"
}],
"archivedExperimentData": [{
"Date": "05\/01\/2020",
"AverageResult": "2",
"Experiment": "SleepBox",
"Type": "Sleep"
}, {
"Date": "06\/01\/2020",
"AverageResult": "1.5",
"Experiment": "SleepBox",
"Type": "Sleep"
}, {
"Date": "07\/01\/2020",
"AverageResult": "5",
"Experiment": "SleepBox",
"Type": "Sleep"
}, {
"Date": "08\/01\/2020",
"AverageResult": "1.5",
"Experiment": "SleepBox",
"Type": "Sleep"
}, {
"Date": "09\/01\/2020",
"AverageResult": "1.5",
"Experiment": "SleepBox",
"Type": "Sleep"
}, {
"Date": "12\/01\/2020",
"AverageResult": "0.5",
"Experiment": "SleepBoxV2",
"Type": "Sleep"
}, {
"Date": "13\/01\/2020",
"AverageResult": "2.5",
"Experiment": "SleepBoxV2",
"Type": "Sleep"
}, {
"Date": "14\/01\/2020",
"AverageResult": "0",
"Experiment": "SleepBoxV2",
"Type": "Sleep"
}, {
"Date": "15\/01\/2020",
"AverageResult": "4.5",
"Experiment": "SleepBoxV2",
"Type": "Sleep"
}, {
"Date": "16\/01\/2020",
"AverageResult": "5",
"Experiment": "SleepBoxV2",
"Type": "Sleep"
}, {
"Date": "17\/03\/2020",
"AverageResult": "4",
"Experiment": "Sunlight",
"Type": "Sleep"
}, {
"Date": "18\/03\/2020",
"AverageResult": "3.5",
"Experiment": "Sunlight",
"Type": "Sleep"
}, {
"Date": "19\/03\/2020",
"AverageResult": "2.5",
"Experiment": "Sunlight",
"Type": "Sleep"
}, {
"Date": "20\/03\/2020",
"AverageResult": "1",
"Experiment": "Sunlight",
"Type": "Sleep"
}, {
"Date": "21\/03\/2020",
"AverageResult": "5",
"Experiment": "Sunlight",
"Type": "Sleep"
}]
}
\ No newline at end of file
......@@ -53,4 +53,9 @@
<string name="NewBoxImageLabel">Image:</string>
<string name="NewBoxWarningLabel">Warning:</string>
<!-- Auth0 strings -->
<string name="com_auth0_client_id">srMEu3hqB26sHtiaIdr9uvYQmwOktLnK</string>
<string name="com_auth0_domain">eamonn-backend-oauth.eu.auth0.com</string>
<string name="auth0_scheme">https</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
......@@ -7,8 +7,14 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:navigationBarColor">@color/colorAccent</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:navigationBarColor" tools:targetApi="lollipop">@color/colorAccent</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
</style>
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:colorAccent" tools:targetApi="lollipop">@color/colorAccent</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:textColorPrimary">@color/colorPrimary</item>
</style>
<style name="AppTheme.NoActionBar">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment