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

DateCheckFromLocalJSON

parent c283cf9d
Branches
No related tags found
No related merge requests found
# README V0.1 # README V0.1
## Purpose ## Purpose
This project is developed by Eamonn Trim, for the third year individual project. 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. It's purpose is to develop an application that allows for Experiments in a Box (XBs) to be quickly launched from within the application.
......
...@@ -172,38 +172,45 @@ public class BoxesActivity extends AppCompatActivity { ...@@ -172,38 +172,45 @@ public class BoxesActivity extends AppCompatActivity {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
String dateToday = simpleDateFormat.format(calendar.getTime()); 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)); 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); 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)); 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()); dateToday = simpleDateFormat.format(calendar.getTime());
d("dateToday", dateToday); d("dateTodayMonth", dateToday);
Integer dateTodayMonth = 10*Character.getNumericValue(dateToday.codePointAt(0))+Character.getNumericValue(dateToday.codePointAt(1)); Integer dateTodayMonth = 10*Character.getNumericValue(dateToday.codePointAt(0))+Character.getNumericValue(dateToday.codePointAt(1));
dateLimitFormatted = dateLimit.substring(dateLimit.length()-7, dateLimit.length()-5); 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)); 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"); simpleDateFormat = new SimpleDateFormat("dd");
dateToday = simpleDateFormat.format(calendar.getTime()); dateToday = simpleDateFormat.format(calendar.getTime());
d("dateToday", dateToday); d("dateTodayDay", dateToday);
Integer dateTodayDay = 10*Character.getNumericValue(dateToday.codePointAt(0))+Character.getNumericValue(dateToday.codePointAt(1)); Integer dateTodayDay = 10*Character.getNumericValue(dateToday.codePointAt(0))+Character.getNumericValue(dateToday.codePointAt(1));
dateLimitFormatted = dateLimit.substring(dateLimit.length()-10, dateLimit.length()-8); 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)); Integer dateLimitDay = 10*Character.getNumericValue(dateLimitFormatted.codePointAt(0))+Character.getNumericValue(dateLimitFormatted.codePointAt(1));
......
package com.yearthreeproject.xbframework; package com.yearthreeproject.xbframework;
import android.graphics.Color; import android.graphics.Color;
import android.icu.text.SimpleDateFormat;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -10,6 +12,7 @@ import android.widget.RadioButton; ...@@ -10,6 +12,7 @@ import android.widget.RadioButton;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
...@@ -18,6 +21,7 @@ import org.json.JSONException; ...@@ -18,6 +21,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import static android.util.Log.d; import static android.util.Log.d;
...@@ -115,10 +119,40 @@ public class ExperimentActivity extends AppCompatActivity { ...@@ -115,10 +119,40 @@ public class ExperimentActivity extends AppCompatActivity {
submitButton = findViewById(R.id.ExperimentSubmitButton); submitButton = findViewById(R.id.ExperimentSubmitButton);
submitButton.setOnClickListener(new View.OnClickListener() { submitButton.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.N)
public void onClick(View v) { public void onClick(View v) {
for(int x = 0; x < experimentsRadioButtonArray.size(); x++) for(int x = 0; x < experimentsRadioButtonArray.size(); x++)
if(experimentsRadioButtonArray.get(x).isChecked()){ if(experimentsRadioButtonArray.get(x).isChecked()){
Integer psudoCount = 0;
Integer experimentGroup = 0;
d("submit", experimentsRadioButtonArray.get(x).getText().toString()); 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();
}
} }
} }
}); });
......
...@@ -14,6 +14,7 @@ import android.view.Menu; ...@@ -14,6 +14,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
...@@ -22,6 +23,9 @@ import androidx.appcompat.widget.Toolbar; ...@@ -22,6 +23,9 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
...@@ -72,10 +76,13 @@ public class MainActivity extends AppCompatActivity { ...@@ -72,10 +76,13 @@ public class MainActivity extends AppCompatActivity {
homeButton.setOnClickListener(new View.OnClickListener() { homeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { 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() { loginButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
...@@ -83,6 +90,23 @@ public class MainActivity extends AppCompatActivity { ...@@ -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() { shopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
...@@ -111,13 +135,16 @@ public class MainActivity extends AppCompatActivity { ...@@ -111,13 +135,16 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
} }
private void checkLocalUserFile() { private void checkLocalUserFile() {
File file = new File(this.getFilesDir(), "localUserData.json"); File file = new File(this.getFilesDir(), "localUserData.json");
if(!file.exists()) { if(!file.exists()) {
// Do stuff to initialise the file // 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 { } else {
// Do nothing // Do nothing
} }
...@@ -165,7 +192,10 @@ public class MainActivity extends AppCompatActivity { ...@@ -165,7 +192,10 @@ public class MainActivity extends AppCompatActivity {
FileStoreReader.saveFile(this, "boxData.json", boxesData); 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, "boxData.json"));
d("file", FileStoreReader.readFile(this, "localUserData.json"));
} }
// Image permission check // Image permission check
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment