diff --git a/OlympusServices/.idea/caches/build_file_checksums.ser b/OlympusServices/.idea/caches/build_file_checksums.ser index becd4a3..2d10815 100644 Binary files a/OlympusServices/.idea/caches/build_file_checksums.ser and b/OlympusServices/.idea/caches/build_file_checksums.ser differ diff --git a/OlympusServices/.idea/misc.xml b/OlympusServices/.idea/misc.xml index cc51e58..dc34569 100644 --- a/OlympusServices/.idea/misc.xml +++ b/OlympusServices/.idea/misc.xml @@ -25,7 +25,7 @@ - + diff --git a/OlympusServices/app/src/main/AndroidManifest.xml b/OlympusServices/app/src/main/AndroidManifest.xml index 5b8f51e..f8bc8ab 100644 --- a/OlympusServices/app/src/main/AndroidManifest.xml +++ b/OlympusServices/app/src/main/AndroidManifest.xml @@ -30,13 +30,18 @@ - - - + android:screenOrientation="portrait" /> + + + + + \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java index 3b2ee4a..0068236 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/AdminWelcome.java @@ -4,13 +4,6 @@ import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.GridView; -import android.widget.ListView; -import android.widget.TextView; - -import java.util.Iterator; -import java.util.List; public class AdminWelcome extends AppCompatActivity { @@ -19,21 +12,6 @@ public class AdminWelcome extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_admin_welcome); - DBHelper dbHelper = new DBHelper(this); - List users = dbHelper.getAllUsers(); - String[] usernames = new String[(users.size()+1)*2]; - usernames[0] = "Username"; - usernames[1] = "User Type"; - Iterator iter = users.iterator(); - for (int i=0; i(this, android.R.layout.simple_list_item_1, usernames); - GridView gridView = (GridView) findViewById(R.id.Users); - gridView.setAdapter(adapter); - } @Override public void onBackPressed(){ @@ -44,4 +22,12 @@ public class AdminWelcome extends AppCompatActivity { startActivity(intent); finish(); } + public void goToUsers(View view){ + Intent intent = new Intent(getApplicationContext(), UsersList.class); + startActivity(intent); + } + public void goToServices(View view){ + Intent intent = new Intent(getApplicationContext(), ServicesList.class); + startActivity(intent); + } } diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditServiceDialogFragment.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditServiceDialogFragment.java new file mode 100644 index 0000000..ecdd495 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/EditServiceDialogFragment.java @@ -0,0 +1,67 @@ +package com.uottawa.olympus.olympusservices; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; + +public class EditServiceDialogFragment extends DialogFragment{ + +public interface NoticeDialogListener { + public void onDialogEdit(DialogFragment dialog); + public void onDialogDelete(DialogFragment dialog); + } + EditServiceDialogFragment.NoticeDialogListener mListener; + + // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener + @Override + public void onAttach(Context context) { + super.onAttach(context); + // Verify that the host activity implements the callback interface + try { + // Instantiate the NoticeDialogListener so we can send events to the host + mListener = (EditServiceDialogFragment.NoticeDialogListener) context; + } catch (ClassCastException e) { + // The activity doesn't implement the interface, throw exception + throw new ClassCastException(this.toString() + + " must implement NoticeDialogListener"); + } + } + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + // Get the layout inflater + LayoutInflater inflater = getActivity().getLayoutInflater(); + + // Inflate and set the layout for the dialog + // Pass null as the parent view because its going in the dialog layout + builder.setView(inflater.inflate(R.layout.dialog_service_edit, null)) + // Add action buttons + .setPositiveButton(R.string.update, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + //@anshu: get the name and rate to come from the dialog_service_new dialog + args.putString("name", "hey"); + args.putDouble("rate", 2.5); + // + EditServiceDialogFragment.this.setArguments(args); + mListener.onDialogEdit(EditServiceDialogFragment.this); + } + }) + .setNegativeButton(R.string.delete, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + //@anshu: get the name and rate to come from the dialog_service_new dialog + args.putString("name", "hey"); + // + EditServiceDialogFragment.this.setArguments(args); + mListener.onDialogDelete(EditServiceDialogFragment.this); + } + }); + return builder.create(); + } +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java new file mode 100644 index 0000000..2e35941 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java @@ -0,0 +1,63 @@ +package com.uottawa.olympus.olympusservices; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; + +public class NewServiceDialogFragment extends DialogFragment { + + public interface NoticeDialogListener { + public void onDialogNew(DialogFragment dialog); + public void onDialogNevermind(DialogFragment dialog); + } + NoticeDialogListener mListener; + + // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener + @Override + public void onAttach(Context context) { + super.onAttach(context); + // Verify that the host activity implements the callback interface + try { + // Instantiate the NoticeDialogListener so we can send events to the host + mListener = (NoticeDialogListener) context; + } catch (ClassCastException e) { + // The activity doesn't implement the interface, throw exception + throw new ClassCastException(this.toString() + + " must implement NoticeDialogListener"); + } + } + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + // Get the layout inflater + LayoutInflater inflater = getActivity().getLayoutInflater(); + + // Inflate and set the layout for the dialog + // Pass null as the parent view because its going in the dialog layout + builder.setView(inflater.inflate(R.layout.dialog_service_new, null)) + // Add action buttons + .setPositiveButton(R.string.add, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Bundle args = new Bundle(); + //@anshu: get the name and rate to come from the dialog_service_new dialog + args.putString("name", "hey"); + args.putDouble("rate", 2.5); + /// + NewServiceDialogFragment.this.setArguments(args); + mListener.onDialogNew(NewServiceDialogFragment.this); + } + }) + .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + NewServiceDialogFragment.this.getDialog().cancel(); + } + }); + return builder.create(); + } + +} diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java new file mode 100644 index 0000000..e070cb1 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/ServicesList.java @@ -0,0 +1,86 @@ +package com.uottawa.olympus.olympusservices; + +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.GridView; +import android.widget.TextView; + +import java.util.Iterator; +import java.util.List; + +public class ServicesList extends AppCompatActivity implements NewServiceDialogFragment.NoticeDialogListener, EditServiceDialogFragment.NoticeDialogListener{ + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_services_list); + DBHelper dbHelper = new DBHelper(this); + List users = dbHelper.getAllServices(); + String[] services = new String[(users.size()+1)*2]; + services[0] = "Name"; + services[1] = "Rate"; + Iterator iter = users.iterator(); + for (int i=0; i(this, android.R.layout.simple_list_item_1, services); + GridView gridView = findViewById(R.id.Services); + gridView.setAdapter(adapter); + gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, + int position, long id) { + editService(view); + } + }); + } + public void addService(View view) { + DialogFragment newFragment = new NewServiceDialogFragment(); + newFragment.show(getSupportFragmentManager(), "addService"); + } + public void editService(View view) { + DialogFragment newFragment = new EditServiceDialogFragment(); + newFragment.show(getSupportFragmentManager(), "editService"); + } + //add new service + @Override + public void onDialogNew(DialogFragment dialog) { + DBHelper dbHelper = new DBHelper(this); + String name = (String)dialog.getArguments().get("name"); + Double rate = (Double)dialog.getArguments().get("rate"); + dbHelper.addService(new Service(name,rate)); + dialog.dismiss(); + this.recreate(); + } + //user clicked cancel + @Override + public void onDialogNevermind(DialogFragment dialog) { + + } + //edits service with info from dialog + @Override + public void onDialogEdit(DialogFragment dialog) { + DBHelper dbHelper = new DBHelper(this); + String name = (String)dialog.getArguments().get("name"); + Double rate = (Double)dialog.getArguments().get("rate"); + dbHelper.updateService(new Service(name,rate)); + dialog.dismiss(); + this.recreate(); + } + //deletes service with info from dialog + @Override + public void onDialogDelete(DialogFragment dialog) { + DBHelper dbHelper = new DBHelper(this); + String name = (String)dialog.getArguments().get("name"); + dbHelper.deleteService(name); + dialog.dismiss(); + this.recreate(); + } + +} \ No newline at end of file diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UsersList.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UsersList.java new file mode 100644 index 0000000..e7bbff4 --- /dev/null +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/UsersList.java @@ -0,0 +1,33 @@ +package com.uottawa.olympus.olympusservices; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.ArrayAdapter; +import android.widget.GridView; + +import java.util.Iterator; +import java.util.List; + +public class UsersList extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_users_list); + + DBHelper dbHelper = new DBHelper(this); + List users = dbHelper.getAllUsers(); + String[] usernames = new String[(users.size()+1)*2]; + usernames[0] = "Username"; + usernames[1] = "User Type"; + Iterator iter = users.iterator(); + for (int i=0; i(this, android.R.layout.simple_list_item_1, usernames); + GridView gridView = findViewById(R.id.Users); + gridView.setAdapter(adapter); + } +} diff --git a/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml b/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml index 6aef240..49da067 100644 --- a/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml +++ b/OlympusServices/app/src/main/res/layout/activity_admin_welcome.xml @@ -24,28 +24,31 @@ android:textSize="20sp" android:layout_marginTop="10dp" app:fontFamily="@font/julius_sans_one" /> - - - - - + android:layout_marginTop="20dp" + android:onClick="goToUsers" + android:text="List of Users" + android:theme="@style/AppTheme.Button" /> +