Commit 1c297cc8 authored by chris.crook's avatar chris.crook

> added a whole load of stuff (nav)

parent f0bd4ef9
......@@ -9,7 +9,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Summative_Chris_Crook">
<activity android:name=".AdminRegister"></activity>
<activity android:name=".MainShopPage"></activity>
<activity android:name=".MainBookingPage" />
<activity android:name=".AdminRegister" />
<activity android:name=".AdminMenu" />
<activity android:name=".UserMenu" />
<activity android:name=".register_page" />
......
......@@ -26,6 +26,16 @@ public class AdminMenu extends AppCompatActivity {
startActivity(intent);
}
public void tobookings (View view){
Intent intent = new Intent(this,MainBookingPage.class);
startActivity(intent);
}
public void toshop (View view){
Intent intent = new Intent(this,MainShopPage.class);
startActivity(intent);
}
public void register2electricboogaloo (View view){
Intent intent = new Intent(this,AdminRegister.class);
startActivity(intent);
......@@ -117,6 +127,11 @@ public class AdminMenu extends AppCompatActivity {
}
public void wipealldialogboxopen (View view){
AlertDialog.Builder msgbox = new AlertDialog.Builder(this);
msgbox.setMessage("This action is not reversible");
msgbox.setTitle("Are you sure");
......@@ -133,10 +148,32 @@ public class AdminMenu extends AppCompatActivity {
msgbox.setNeutralButton("Display all wipe-able data", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
File file2; // all this does is read the file and display it all
String filename2 = "appdatatxt";
String temp = "";
file2 = new File(getApplicationContext().getFilesDir(), filename2 + ".txt");
try{
Scanner reader = new Scanner(file2);
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
if (temp.equals("")){
temp = "No user data";
}
if (temp.equals("ADMIN")){
//no access to this function
Toast.makeText(getApplicationContext(), "Only Super Admins can use this function", Toast.LENGTH_SHORT).show();
return;
}
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
// display all data in an alert box
File file1; // all this does is read the file and display it all
String filename1 = "magicwords";
String temp = "";
temp = "";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
try{
Scanner reader = new Scanner(file1);
......
......@@ -223,7 +223,23 @@ public class MainActivity extends AppCompatActivity {
if (magicwords [i] [4].equals("ADMIN")){
// user is an admin
Toast.makeText(getApplicationContext(), "Signed in as " + magicwords [i] [1] + " (admin)", Toast.LENGTH_SHORT).show();
String writetotemp = magicwords [i] [1] + "&" + magicwords [i] [4] + "&" + magicwords [i] [5];
String writetotemp = magicwords [i] [1] + "&" + magicwords [i] [3] + "&" + magicwords [i] [4] + "&" + magicwords [i] [5] + "&" + i;
Toast.makeText(getApplicationContext(), "Admin preferences loaded: " + writetotemp, Toast.LENGTH_SHORT).show();
try{
FileWriter stream = new FileWriter(file2, false);
stream.append(writetotemp);
stream.close();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "Internal File Error", Toast.LENGTH_LONG).show();
}
Intent intent = new Intent(this,AdminMenu.class);
startActivity(intent);
return;
}
else if (magicwords [i] [4].equals("SUPER")){
// user is an admin
Toast.makeText(getApplicationContext(), "Signed in as " + magicwords [i] [1] + " (super admin)", Toast.LENGTH_SHORT).show();
String writetotemp = magicwords [i] [1] + "&" + magicwords [i] [3] + "&" + magicwords [i] [4] + "&" + magicwords [i] [5] + "&" + i;
Toast.makeText(getApplicationContext(), "Admin preferences loaded: " + writetotemp, Toast.LENGTH_SHORT).show();
try{
FileWriter stream = new FileWriter(file2, false);
......@@ -238,7 +254,7 @@ public class MainActivity extends AppCompatActivity {
}
else{
Toast.makeText(getApplicationContext(), "Signed in as " + magicwords [i] [1], Toast.LENGTH_SHORT).show();
String writetotemp = magicwords [i] [1] + "&" + magicwords [i] [4] + "&" + magicwords [i] [5];
String writetotemp = magicwords [i] [1] + "&" + magicwords [i] [3] + "&" + magicwords [i] [4] + "&" + magicwords [i] [5] + "&" + i; // name,flag,currency,language,internalID
Toast.makeText(getApplicationContext(), "User preferences loaded: " + writetotemp, Toast.LENGTH_SHORT).show();
try{
FileWriter stream = new FileWriter(file2, false);
......
package com.example.summative_chris_crook;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.util.Scanner;
public class MainBookingPage extends AppCompatActivity {
String filename1 = "magicwords";
String filename2 = "appdatatxt";
File file1;
File file2;
// generic variables and stuff
int sizeoverride = 1000;
String tempload = "";
String [] [] magicwords = new String [sizeoverride] [7]; // storage of the login info
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_booking_page);
}
public String openandload(){
try{
Scanner reader = new Scanner(file1);
String temp = "";
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
//Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
return temp;
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_LONG).show();
return "&&&";
}
}
public void loadncomp (View view){
//
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
file2 = new File(getApplicationContext().getFilesDir(), filename2 + ".txt");
for (int i = 0; i < sizeoverride; i ++){
magicwords [i] [0] = "END";
}
int tempint;
tempload = openandload();
if (tempload.equals("&&&")){
// this means that the load failed
}
else {
// load successful
if (tempload.equals("")) {
// dont add a '%' to the start
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
} else {
tempload += "%";
tempload += "adminname&adminuser&" + "adminpassword".hashCode() + "&ADMIN&£&ENG";
tempload += "%examplename&exampleuser&" + "examplepassword".hashCode() + "&USER&£&ENG";
}
String[] temploadarray = tempload.split("%");
int size = temploadarray.length;
for (int i = 0; i < size; i++) {
magicwords[i][0] = temploadarray[i]; // splits by user
}
for (int i = 0; i < size; i++) {
String[] sort = temploadarray[i].split("&");
magicwords[i][1] = sort[0]; // name of user
magicwords[i][2] = sort[1]; // username
magicwords[i][3] = sort[2]; // password
magicwords[i][4] = sort[3]; // admin flag
magicwords[i][5] = sort[4]; // currency mode
magicwords[i][6] = sort[5]; // language
}
for (int i = 0; i < sizeoverride; i++) {
if (magicwords[i][0].equals("END")) {
// end marker found
tempint = i;
break;
}
}
String temp = "";
try {
Scanner reader = new Scanner(file2);
while (reader.hasNextLine()) {
temp = temp + reader.nextLine();
}
//Toast.makeText(getApplicationContext(), temp + " ", Toast.LENGTH_LONG).show();
} catch (Exception e) {
}
String[] passeddata = temp.split("&");
if (passeddata[0].equals(magicwords[Integer.parseInt(passeddata[4])])) { // verifies load successful
//load successful
Toast.makeText(getApplicationContext(), "Load Successful", Toast.LENGTH_LONG).show();
} else {
//load failed
Toast.makeText(getApplicationContext(), "Load Failed", Toast.LENGTH_LONG).show();
}
}
}
public void gobackfromtheshop (View view){
//
file2 = new File(getApplicationContext().getFilesDir(), filename2 + ".txt");
String temp = "";
try {
Scanner reader = new Scanner(file2);
while (reader.hasNextLine()) {
temp = temp + reader.nextLine();
}
} catch (Exception e) { }
String [] datatolookat = temp.split("&");
if( datatolookat [1].equals("ADMIN")){
// go to admin screen
}
else{
// go to user menu
}
}
}
\ No newline at end of file
package com.example.summative_chris_crook;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.util.Scanner;
public class MainShopPage extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_shop_page);
}
public void goback (View view){
File file1; // all this does is read the file and display it all
String filename1 = "appdatatxt";
String temp = "";
file1 = new File(getApplicationContext().getFilesDir(), filename1 + ".txt");
try{
Scanner reader = new Scanner(file1);
while (reader.hasNextLine()){
temp = temp + reader.nextLine();
}
if (temp.equals("")){
temp = "No user data";
}
if (temp.equals("ADMIN")){
Intent intent = new Intent(this,AdminMenu.class);
startActivity(intent);
return;
}
else if (temp.equals("SUPER")){
Intent intent = new Intent(this,AdminMenu.class);
startActivity(intent);
return;
}
else{
Intent intent = new Intent(this,UserMenu.class);
startActivity(intent);
return;
}
} catch(Exception e){
Toast.makeText(getApplicationContext(), "read error", Toast.LENGTH_SHORT).show();
}
}
}
\ No newline at end of file
......@@ -18,4 +18,14 @@ public class UserMenu extends AppCompatActivity {
Intent intent = new Intent(this,MainActivity.class);
startActivity(intent);
}
public void tobookings (View view){
Intent intent = new Intent(this,MainBookingPage.class);
startActivity(intent);
}
public void toshop (View view){
Intent intent = new Intent(this,MainShopPage.class);
startActivity(intent);
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Admin Main Menu" />
android:text="Main Menu" />
<Button
android:id="@+id/button5"
......@@ -24,6 +24,44 @@
android:onClick="goback"
android:text="Log Out" />
<Button
android:id="@+id/button15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="tobookings"
android:text="Bookings" />
<Button
android:id="@+id/button16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toshop"
android:text="Shop" />
<Button
android:id="@+id/button17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cart and Checkout" />
<Button
android:id="@+id/button24"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Settings" />
<Button
android:id="@+id/button22"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete Account" />
<TextView
android:id="@+id/textView15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Admin only settings" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
......@@ -44,5 +82,6 @@
android:layout_height="wrap_content"
android:onClick="register2electricboogaloo"
android:text="Register page (admin)" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainBookingPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_editor_absoluteX="65dp"
tools:layout_editor_absoluteY="33dp">
<TextView
android:id="@+id/textView14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bookings" />
<Button
android:id="@+id/button14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="gobackfromtheshop"
android:text="back" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainShopPage">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Shop" />
<Button
android:id="@+id/button26"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="goback"
android:text="Back" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -23,5 +23,37 @@
android:layout_height="wrap_content"
android:onClick="goback"
android:text="Log Out" />
<Button
android:id="@+id/button18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="tobookings"
android:text="Bookings" />
<Button
android:id="@+id/button19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toshop"
android:text="Shop" />
<Button
android:id="@+id/button20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cart and Checkout" />
<Button
android:id="@+id/button23"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Settings" />
<Button
android:id="@+id/button21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Delete account" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment