Skip to content
Snippets Groups Projects
Commit 98f23104 authored by jrb240's avatar jrb240
Browse files

Android function side of things have been written, but certain elements remain...

Android function side of things have been written, but certain elements remain uncomplete due to lack of information.

Model, main activity, and user datatype have been changed with lines that may be removed later.
parent f416ffce
No related branches found
No related tags found
1 merge request!27Android function side of things have been written, but certain elements remain...
package com.example.event36;
import android.net.wifi.WifiManager;
import androidx.appcompat.app.AppCompatActivity;
import java.net.UnknownHostException;
public class AndroidIp extends AppCompatActivity {
// private Integer ipAd;
// private WifiManager thing = (WifiManager) this.getApplicationContext().getSystemService(WIFI_SERVICE);
//
// public AndroidIp() throws UnknownHostException {
// ipAd = thing.getConnectionInfo().getIpAddress();
// }
// public String getIpAd() {return ipAd.toString();}
}
\ No newline at end of file
......@@ -277,6 +277,10 @@ public class Model {
return tags[randomIndex];
}
public User returnCurrentUser(){
return user;
}
public Restaurant getRestaurantById(String resId) {
for (EventRestoSuperClass item : popList.getEventRestoList()) {
......
......@@ -14,6 +14,7 @@ import java.net.Inet6Address;
import java.net.UnknownHostException;
public class RegisterActivity extends AppCompatActivity {
private String rePass,reUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -47,15 +48,21 @@ public class RegisterActivity extends AppCompatActivity {
REGISTER.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rePass = password.getText().toString();
reUser = user.getText().toString();
//in this case we want it to create a user name and password
//that we will be able to use later
//pass is going to create a file that we can access later even if we shut this program down
SharedPreferences pass = getBaseContext().getSharedPreferences("passwords", Context.MODE_PRIVATE);
//this is not the best way of doing this but it is what we got right now
pass.edit().putString(user.getText().toString(),password.getText().toString()).commit();
pass.edit().putString(reUser,rePass).commit();
//let's send this stuff to the server before we get ahead of ourselves.
BackgroudTask bLog = new BackgroudTask();
bLog.execute(user.getText().toString());
SendUserToServer newUserMsg = new SendUserToServer(reUser,rePass);
Thread sendUser = new Thread(newUserMsg);
sendUser.start();
//this did the same thing, but has been removed for he
// BackgroudTask bLog = new BackgroudTask();
// bLog.execute(user.getText().toString());
//alright now let's just pass the rest off the MainActivity
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
}
......
package com.example.event36;
public class RequestReviewsFromServer implements Runnable{
@Override
public void run() {
}
}
package com.example.event36;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class SendEventToServer implements Runnable{
//TODO
// currently not enough information of the the status
// of event creation to complete this
@Override
public void run() {
int portNumber = 8002;
String serverName = "172.16.1.79";
try(Socket connectToServer = new Socket(serverName,portNumber);
PrintWriter out = new PrintWriter(connectToServer.getOutputStream(), true);
) {
//TODO I am doing and sending nothing
} catch (UnknownHostException e) {
System.exit(1);
} catch (IOException e) {
System.exit(2);
}
}
}
package com.example.event36;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class SendReveiwToServer implements Runnable{
Model model;
User reviewer;
//name and password are there just in case
String name,password, comment,eventType,eventName;
int rating;
SendReveiwToServer(Model newModel){
model = newModel;
}
public void addUserAndPassword(String rComment, int nRating,String restOrEvent,String newEventName){
comment = rComment;
rating = nRating;
eventType = restOrEvent;
eventName = newEventName;
}
//I don't know the current setup of review to know if I have to collect everything now
//or later
// SendReveiwToServer(Model newModel, String rComment,int nRating){
// model = newModel;
// comment = rComment;
// rating = nRating;
// }
@Override
public void run() {
reviewer = model.returnCurrentUser();
int portNum = 8001;
/**
* if you are running your our server this will need to bee changed.
* The server will print the ip address of your device to when the
* terminal when you start the main thread of the server.
*/
String nameOfServer = "172.16.1.79";
//let's connect to the server and create stream to the server
//if we cannot find the server we exit(1)
//if we cannot connect to the server we exit(2)
try (Socket kkSocket = new Socket(nameOfServer, portNum);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
//ObjectOutputStream sendToServer = new ObjectOutputStream(kkSocket.getOutputStream());
) {
//TODO test if there are timing issues
out.println(reviewer.getName());
out.println(reviewer.getPassword());
//user and password are being sent to the server to test whether or not
//this user has been registered
out.println(eventType);
out.println(eventName);
out.println(Integer.valueOf(rating));
out.println(comment);
} catch (UnknownHostException e) {
//TODO create a failed to connect to server list
//currently we are just being optimistic
System.out.println("Server is not known to us");
System.exit(1);
} catch (IOException e) {
System.out.println("Failure of connect to host server");
System.exit(2);
}
}
}
......@@ -2,29 +2,41 @@ package com.example.event36;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class SendUserToServer implements Runnable {
ServerUser user;
int portNum;
String nameOfServer;
String user,password;
public SendUserToServer(String serverName,int accessPort,ServerUser newUser){
portNum = accessPort;
nameOfServer = serverName;
public SendUserToServer(String newUser,String uPassword){
user = newUser;
password = uPassword;
}
@Override
public void run() {
int portNum = 8000;
/**
* if you are running your our server this will need to bee changed.
* The server will print the ip address of your device to when the
* terminal when you start the main thread of the server.
*/
String nameOfServer = "172.16.1.79";
//let's connect to the server and create stream to the server
//if we cannot find the server we exit(1)
//if we cannot connect to the server we exit(2)
try (Socket kkSocket = new Socket(nameOfServer, portNum);
ObjectOutputStream sendToServer = new ObjectOutputStream(kkSocket.getOutputStream());) {
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
//ObjectOutputStream sendToServer = new ObjectOutputStream(kkSocket.getOutputStream());
) {
System.out.println("connected");
//all we want to do is send the user to the server
sendToServer.writeObject(user);
//sendToServer.writeObject(user);
out.println(user);
out.println(password);
System.out.println("Finish");
} catch (UnknownHostException e) {
System.out.println("Server is not known to us");
......
......@@ -54,6 +54,9 @@ public class User implements java.io.Serializable{
this.password = pw;
}
public void changePassword(String newPassword){
password = newPassword;
}
public String getEmail(){
return email;
......@@ -108,4 +111,5 @@ public class User implements java.io.Serializable{
}
public String getName() { return this.name; }
public String getPassword() {return this.password;}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment