added admin welcome page
This commit is contained in:
		
							parent
							
								
									a76cced0fd
								
							
						
					
					
						commit
						5ebf406850
					
				
					 5 changed files with 101 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -37,6 +37,7 @@
 | 
			
		|||
        </activity>
 | 
			
		||||
        <activity android:name=".LogIn" />
 | 
			
		||||
        <activity android:name=".Welcome" />
 | 
			
		||||
        <activity android:name=".AdminWelcome"></activity>
 | 
			
		||||
    </application>
 | 
			
		||||
 | 
			
		||||
</manifest>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
package com.uottawa.olympus.olympusservices;
 | 
			
		||||
 | 
			
		||||
import android.support.v7.app.AppCompatActivity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.widget.ArrayAdapter;
 | 
			
		||||
import android.widget.ListView;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class AdminWelcome extends AppCompatActivity {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        setContentView(R.layout.activity_admin_welcome);
 | 
			
		||||
 | 
			
		||||
        DBHelper dbHelper = new DBHelper(this);
 | 
			
		||||
        List<String[]> users = dbHelper.getAllUsers();
 | 
			
		||||
        String[] usernames = new String[users.size()+1];
 | 
			
		||||
        String[] usertypes = new String[users.size()+1];
 | 
			
		||||
        usernames[0] = "Username";
 | 
			
		||||
        usertypes[0] = "User Type";
 | 
			
		||||
        Iterator iter = users.iterator();
 | 
			
		||||
        for (int i=0; i<users.size();i++){
 | 
			
		||||
            String[] current = (String[])iter.next();
 | 
			
		||||
            usernames[i+1] = current[0];
 | 
			
		||||
            usertypes[i+1] = current[3];
 | 
			
		||||
        }
 | 
			
		||||
        ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames);
 | 
			
		||||
        ListView listView = (ListView) findViewById(R.id.Users);
 | 
			
		||||
        listView.setAdapter(adapter);
 | 
			
		||||
        ArrayAdapter adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usertypes);
 | 
			
		||||
        ListView listView2 = (ListView) findViewById(R.id.Types);
 | 
			
		||||
        listView2.setAdapter(adapter2);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -19,14 +19,21 @@ public class LogIn extends AppCompatActivity {
 | 
			
		|||
        String username = ((EditText) findViewById(R.id.UsernameInput)).getText().toString();
 | 
			
		||||
        String password = ((EditText) findViewById(R.id.PasswordInput)).getText().toString();
 | 
			
		||||
        DBHelper dbHelper = new DBHelper(this);
 | 
			
		||||
        Intent intent = new Intent(getApplicationContext(),Welcome.class);
 | 
			
		||||
        if(username.matches("[a-zA-Z0-9]*")&&password.matches("[a-zA-Z0-9]*")
 | 
			
		||||
                && password.length()>0 && username.length()>0) {
 | 
			
		||||
            if (dbHelper.findUserByUsername(username) != null) {
 | 
			
		||||
                if (dbHelper.findUserByUsername(username).getUsername().equals(username) &&
 | 
			
		||||
                        dbHelper.findUserByUsername(username).getPassword().equals(password)) {
 | 
			
		||||
                    intent.putExtra("username", username);
 | 
			
		||||
                    startActivity(intent);
 | 
			
		||||
                UserType user = dbHelper.findUserByUsername(username);
 | 
			
		||||
                if (user.getUsername().equals(username) &&
 | 
			
		||||
                        user.getPassword().equals(password)) {
 | 
			
		||||
                    if(user.getRole()=="Admin"){
 | 
			
		||||
                        Intent intent = new Intent(getApplicationContext(),AdminWelcome.class);
 | 
			
		||||
                        startActivity(intent);
 | 
			
		||||
                    }
 | 
			
		||||
                    else {
 | 
			
		||||
                        Intent intent = new Intent(getApplicationContext(),Welcome.class);
 | 
			
		||||
                        intent.putExtra("username", username);
 | 
			
		||||
                        startActivity(intent);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                } else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,49 @@
 | 
			
		|||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<LinearLayout 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"
 | 
			
		||||
    android:gravity="center_horizontal"
 | 
			
		||||
    android:orientation="vertical"
 | 
			
		||||
    android:paddingBottom="@dimen/activity_vertical_margin"
 | 
			
		||||
    android:paddingLeft="@dimen/activity_horizontal_margin"
 | 
			
		||||
    android:paddingRight="@dimen/activity_horizontal_margin"
 | 
			
		||||
    android:paddingTop="@dimen/activity_vertical_margin"
 | 
			
		||||
    android:background="@drawable/background"
 | 
			
		||||
    tools:context=".Welcome">
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/Welcome"
 | 
			
		||||
        android:layout_width="300dp"
 | 
			
		||||
        android:layout_height="80dp"
 | 
			
		||||
        android:layout_marginBottom="20dp"
 | 
			
		||||
        android:gravity="center"
 | 
			
		||||
        android:text="Welcome Admin"
 | 
			
		||||
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
 | 
			
		||||
        android:textColor="@android:color/white"
 | 
			
		||||
        android:textSize="20sp"
 | 
			
		||||
        android:layout_marginTop="10dp"
 | 
			
		||||
        app:fontFamily="@font/julius_sans_one" />
 | 
			
		||||
 | 
			
		||||
    <LinearLayout
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="match_parent"
 | 
			
		||||
        android:orientation="horizontal">
 | 
			
		||||
 | 
			
		||||
        <ListView
 | 
			
		||||
            android:id="@+id/Users"
 | 
			
		||||
            android:layout_width="fill_parent"
 | 
			
		||||
            android:layout_weight="1"
 | 
			
		||||
            android:layout_height="match_parent"
 | 
			
		||||
            android:textColor="@android:color/white"
 | 
			
		||||
            android:textSize="15sp" />
 | 
			
		||||
        <ListView
 | 
			
		||||
            android:id="@+id/Types"
 | 
			
		||||
            android:layout_width="fill_parent"
 | 
			
		||||
            android:layout_weight="1"
 | 
			
		||||
            android:layout_height="match_parent"
 | 
			
		||||
            android:textColor="@android:color/white"
 | 
			
		||||
            android:textSize="15sp" />
 | 
			
		||||
    </LinearLayout>
 | 
			
		||||
 | 
			
		||||
</LinearLayout>
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue