diff --git a/README.md b/README.md index b2f7e85fef021bf8c94bb218f16014ffbadb0494..00e95f7e1e972aa9232443c6e4cc2dbf09303f48 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # README V0.1 + ## Purpose + This project is developed by Eamonn Trim, for the third year individual project. It's purpose is to develop an application that allows for Experiments in a Box (XBs) to be quickly launched from within the application. An XB requires at the bare minimum a set of instructions that a user will follow in order to attempt to improve one area of their life (Movement, Eating, Engaging, Cogitating, or Sleeping [MEECS]). -In addition to this an XB may allow for the collection of data to enable a broader understanding of the society wide patterns that affect these important aspects of everyday life. \ No newline at end of file +In addition to this an XB may allow for the collection of data to enable a broader understanding of the society wide patterns that affect these important aspects of everyday life. diff --git a/app/src/main/java/com/yearthreeproject/xbframework/BoxesActivity.java b/app/src/main/java/com/yearthreeproject/xbframework/BoxesActivity.java index 06cd583ff012c687336408cbef598c4c188d5896..dda395438d4162eb8c814d3af3d34ff6a25f8f1e 100644 --- a/app/src/main/java/com/yearthreeproject/xbframework/BoxesActivity.java +++ b/app/src/main/java/com/yearthreeproject/xbframework/BoxesActivity.java @@ -172,38 +172,45 @@ public class BoxesActivity extends AppCompatActivity { Calendar calendar = Calendar.getInstance(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy"); String dateToday = simpleDateFormat.format(calendar.getTime()); - d("dateToday", dateToday); + d("dateTodayYear", dateToday); Integer dateTodayYear = 1000*Character.getNumericValue(dateToday.codePointAt(0))+100*Character.getNumericValue(dateToday.codePointAt(1))+10*Character.getNumericValue(dateToday.codePointAt(2))+Character.getNumericValue(dateToday.codePointAt(3)); String dateLimitFormatted = dateLimit.substring(dateLimit.length()-4); - d("dateDeadline", dateLimitFormatted); + d("dateDeadlineYear", dateLimitFormatted); Integer dateLimitYear = 1000*Character.getNumericValue(dateLimitFormatted.codePointAt(0))+100*Character.getNumericValue(dateLimitFormatted.codePointAt(1))+10*Character.getNumericValue(dateLimitFormatted.codePointAt(2))+Character.getNumericValue(dateLimitFormatted.codePointAt(3)); - if(dateTodayYear >= dateLimitYear){ - simpleDateFormat = new SimpleDateFormat("mm"); + + if(dateTodayYear > dateLimitYear){ + d("dateTest", "Release from lock"); + return true; + }else if(dateTodayYear >= dateLimitYear){ + simpleDateFormat = new SimpleDateFormat("MM"); dateToday = simpleDateFormat.format(calendar.getTime()); - d("dateToday", dateToday); + d("dateTodayMonth", dateToday); Integer dateTodayMonth = 10*Character.getNumericValue(dateToday.codePointAt(0))+Character.getNumericValue(dateToday.codePointAt(1)); dateLimitFormatted = dateLimit.substring(dateLimit.length()-7, dateLimit.length()-5); - d("dateDeadline", dateLimitFormatted); + d("dateDeadlineMonth", dateLimitFormatted); Integer dateLimitMonth = 10*Character.getNumericValue(dateLimitFormatted.codePointAt(0))+Character.getNumericValue(dateLimitFormatted.codePointAt(1)); - if(dateTodayMonth >= dateLimitMonth){ + if(dateTodayMonth > dateLimitMonth){ + d("dateTest", "Release from lock"); + return true; + }else if(dateTodayMonth >= dateLimitMonth){ simpleDateFormat = new SimpleDateFormat("dd"); dateToday = simpleDateFormat.format(calendar.getTime()); - d("dateToday", dateToday); + d("dateTodayDay", dateToday); Integer dateTodayDay = 10*Character.getNumericValue(dateToday.codePointAt(0))+Character.getNumericValue(dateToday.codePointAt(1)); dateLimitFormatted = dateLimit.substring(dateLimit.length()-10, dateLimit.length()-8); - d("dateDeadline", dateLimitFormatted); + d("dateDeadlineDay", dateLimitFormatted); Integer dateLimitDay = 10*Character.getNumericValue(dateLimitFormatted.codePointAt(0))+Character.getNumericValue(dateLimitFormatted.codePointAt(1)); diff --git a/app/src/main/java/com/yearthreeproject/xbframework/ExperimentActivity.java b/app/src/main/java/com/yearthreeproject/xbframework/ExperimentActivity.java index c37aa73bc6a7474d843863b713190c160191bec7..574b9df90ffc17c6c566aa5981197065739740d6 100644 --- a/app/src/main/java/com/yearthreeproject/xbframework/ExperimentActivity.java +++ b/app/src/main/java/com/yearthreeproject/xbframework/ExperimentActivity.java @@ -1,6 +1,8 @@ package com.yearthreeproject.xbframework; import android.graphics.Color; +import android.icu.text.SimpleDateFormat; +import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; @@ -10,6 +12,7 @@ import android.widget.RadioButton; import android.widget.TextView; import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -18,6 +21,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Calendar; import static android.util.Log.d; @@ -115,10 +119,40 @@ public class ExperimentActivity extends AppCompatActivity { submitButton = findViewById(R.id.ExperimentSubmitButton); submitButton.setOnClickListener(new View.OnClickListener() { + @RequiresApi(api = Build.VERSION_CODES.N) public void onClick(View v) { for(int x = 0; x < experimentsRadioButtonArray.size(); x++) if(experimentsRadioButtonArray.get(x).isChecked()){ + Integer psudoCount = 0; + Integer experimentGroup = 0; d("submit", experimentsRadioButtonArray.get(x).getText().toString()); + try { + JSONObject boxJSON = new JSONObject(getIntent().getStringExtra("JSON")); + for(int i = 0; i < boxJSON.getJSONArray("Experiments").length(); i++){ + if(boxJSON.getJSONArray("Experiments").getJSONObject(i).getJSONArray("Options").length()+psudoCount <= x){ + psudoCount += boxJSON.getJSONArray("Experiments").getJSONObject(i).getJSONArray("Options").length(); + experimentGroup++; + } else { + JSONObject editJSON = new JSONObject(FileStoreReader.readFile(ExperimentActivity.this, "localUserData.json")); + editJSON.put("lockedExperiment", boxJSON.getJSONArray("Experiments").getJSONObject(experimentGroup).getJSONArray("Options").getJSONObject(x-psudoCount)); + + Calendar calendar = Calendar.getInstance(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + calendar.add(Calendar.DATE, 5); + String dateUntil = simpleDateFormat.format(calendar.getTime()); + + editJSON.put("DateUntil", dateUntil); + + FileStoreReader.saveFile(ExperimentActivity.this, "localUserData.json", editJSON.toString()); + + d("storedJSON", editJSON.toString()); + finish(); + } + } + } catch(Exception e){ + e.printStackTrace(); + } + } } }); diff --git a/app/src/main/java/com/yearthreeproject/xbframework/MainActivity.java b/app/src/main/java/com/yearthreeproject/xbframework/MainActivity.java index daa4aa89209fbbf3c02a55de99864a94e25e451f..e88d3b4992b85fc9eadd48893ac27726843a506d 100644 --- a/app/src/main/java/com/yearthreeproject/xbframework/MainActivity.java +++ b/app/src/main/java/com/yearthreeproject/xbframework/MainActivity.java @@ -14,6 +14,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.LinearLayout; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AlertDialog; @@ -22,6 +23,9 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import org.json.JSONException; +import org.json.JSONObject; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStream; @@ -72,10 +76,13 @@ public class MainActivity extends AppCompatActivity { homeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - d("testing", "homeButton clicked"); + d("testing", "When is this used?"); } }); + LinearLayout homeACT = findViewById(R.id.HomeActivityLayout); + homeACT.removeView(homeButton); + loginButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { @@ -83,6 +90,23 @@ public class MainActivity extends AppCompatActivity { } }); + try { + JSONObject localUserJSON = new JSONObject(FileStoreReader.readFile(this, "localUserData.json")); + d("testing", localUserJSON.toString()); + if(localUserJSON.get("savedUserID") != JSONObject.NULL){ + d("test", "got user id"); + LinearLayout homeActLay = findViewById(R.id.HomeActivityLayout); + homeActLay.removeView(loginButton); + } else{ + d("test", "do not got user id"); + LinearLayout homeActLay = findViewById(R.id.HomeActivityLayout); + homeActLay.removeAllViews(); + homeActLay.addView(loginButton); + } + } catch (JSONException e) { + e.printStackTrace(); + } + shopButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { @@ -111,13 +135,16 @@ public class MainActivity extends AppCompatActivity { } }); + + + } private void checkLocalUserFile() { File file = new File(this.getFilesDir(), "localUserData.json"); if(!file.exists()) { // Do stuff to initialise the file - FileStoreReader.saveFile(this, "localUserData.json", "{DateUntil:'31/01/1999'}"); + FileStoreReader.saveFile(this, "localUserData.json", "{\"DateUntil\":\"01/31/1999\",\"savedUserID\":\"A01\"}"); } else { // Do nothing } @@ -165,7 +192,10 @@ public class MainActivity extends AppCompatActivity { FileStoreReader.saveFile(this, "boxData.json", boxesData); + FileStoreReader.saveFile(this, "localUserData.json", "{\"DateUntil\": \"01/31/1999\",\n\"savedUserID\": \"A01\"}"); + d("file", FileStoreReader.readFile(this, "boxData.json")); + d("file", FileStoreReader.readFile(this, "localUserData.json")); } // Image permission check