Skip to content

Commit

Permalink
AdicionandoTudoPeloApp
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSirtoriCorrea committed Jul 10, 2020
1 parent 4242732 commit b3975ff
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,49 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

public class AddDeviceFragment extends Fragment {
private Button btnAddDevice;
private EditText device;
private EditText desc;

private ServerConnection connection;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_adddevice, container, false);
View view = inflater.inflate(R.layout.fragment_adddevice, container, false);

btnAddDevice = view.findViewById(R.id.btnAddDevice);

device = view.findViewById(R.id.txtAddDevice);
desc = view.findViewById(R.id.txtAddDeviceDescription);

btnAddDevice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
connection = new ServerConnection();

connection.sendRequest(connection.prepareDevice("insertDevice", device.getText().toString(), desc.getText().toString(), "json"));

if(connection.getMsgStatus()){
Toast.makeText(view.getContext(), "Device adicionado", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(view.getContext(), "Erro ao adicionar device", Toast.LENGTH_SHORT).show();
}
}
});

return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,62 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

public class AddInteractionFragment extends Fragment {
private ServerConnection connection;
private Button btnAddInteraction;

private EditText key1;
private EditText key2;
private EditText key3;
private EditText res1;
private EditText res2;
private EditText res3;
private EditText command;


@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_addinteraction, container, false);
View view = inflater.inflate(R.layout.fragment_addinteraction, container, false);

btnAddInteraction = view.findViewById(R.id.btnAddInteraction);

key1 = view.findViewById(R.id.txtKeyword1);
key2 = view.findViewById(R.id.txtKeyword2);
key3 = view.findViewById(R.id.txtKeyword3);
res1 = view.findViewById(R.id.txtResponse1);
res2 = view.findViewById(R.id.txtResponse2);
res3 = view.findViewById(R.id.txtResponse3);
command = view.findViewById(R.id.txtCommand);

btnAddInteraction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
connection = new ServerConnection();

connection.sendRequest(connection.prepareInteraction("insertInteraction", key1.getText().toString(), key2.getText().toString(),
key3.getText().toString(), res1.getText().toString(), res2.getText().toString(), res3.getText().toString(),
command.getText().toString()));
if(connection.getMsgStatus()){
Toast.makeText(view.getContext(), "Interação adicionada", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(view.getContext(), "Erro ao adicionar interação", Toast.LENGTH_SHORT).show();
}

}
});

return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,71 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class AddHomeWorkFragment extends Fragment {
private Button btnAddHomeWork;
private EditText type;
private EditText subject;
private EditText homeWork;
private EditText delivery;
private EditText desc;

private ServerConnection connection;
private SimpleDateFormat sdf;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
/*checa se é uma data:
try {
sdf.parse(txtDelivery.getText().toString());
sdf = new SimpleDateFormat("dd/MM/yyyy");

View view = inflater.inflate(R.layout.fragment_addhomework, container, false);

btnAddHomeWork = view.findViewById(R.id.btnAddHomeWork);

type = view.findViewById(R.id.txtHomeWorkType);
subject = view.findViewById(R.id.txtHomeWorkSubject);
homeWork = view.findViewById(R.id.txtHomeWork);
delivery = view.findViewById(R.id.txtHomeWorkDelivery);
desc = view.findViewById(R.id.txtHomeWorkDescription);

btnAddHomeWork.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
connection = new ServerConnection();

try {
sdf.parse(delivery.getText().toString());

connection.sendRequest(connection.prepareHomework("insertHomeWork", type.getText().toString(), subject.getText().toString(),
homeWork.getText().toString(), delivery.getText().toString(), desc.getText().toString()));

if(connection.getMsgStatus()){
Toast.makeText(view.getContext(), "Tarefa enviada", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(view.getContext(), "Erro ao enviar a tarefa", Toast.LENGTH_SHORT).show();
}

} catch (ParseException e) {
Toast.makeText(view.getContext(), "Insira um formato válido", Toast.LENGTH_SHORT).show();
}

} catch (ParseException e) {
Toast.makeText(view.getContext(), "Insira um formato válido", Toast.LENGTH_SHORT).show();
}*/
}
});

return inflater.inflate(R.layout.fragment_addhomework, container, false);

return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,48 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

public class AddProjectFragment extends Fragment {
private Button btnAddProject;
private EditText project;

private ServerConnection connection;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_addproject, container, false);
View view = inflater.inflate(R.layout.fragment_addproject, container, false);

btnAddProject = view.findViewById(R.id.btnAddProject);
project = view.findViewById(R.id.txtAddNameProject);

btnAddProject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
connection = new ServerConnection();

connection.sendRequest(connection.prepareProject("insertProject", project.getText().toString(), "repository"));

if(connection.getMsgStatus()){
Toast.makeText(view.getContext(), "Projeto adicionado", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(view.getContext(), "Erro ao adicionar projeto", Toast.LENGTH_SHORT).show();
}

}
});


return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,8 @@ public class ServerConnection extends AsyncTask<JSONObject, Integer, ArrayList<J
private ArrayList<JSONArray> list = null;
private JSONArray arrayResponse;
private char[] buffer = new char[9000];
private boolean msgStatus = false;

public ArrayList<JSONArray> sendRequest(JSONObject request){
try {
execute(request);
while(this.list == null){
sleep(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
}

return this.list;

}

@Override
protected ArrayList<JSONArray> doInBackground(JSONObject... params) {
Expand All @@ -51,6 +39,8 @@ protected ArrayList<JSONArray> doInBackground(JSONObject... params) {

this.out.println(params[0]);

this.msgStatus = true;

this.in.read(this.buffer);

this.data = new String(this.buffer);
Expand All @@ -77,17 +67,35 @@ protected ArrayList<JSONArray> doInBackground(JSONObject... params) {
return null;
}

public boolean getMsgStatus(){
return this.msgStatus;
}

public ArrayList<JSONArray> sendRequest(JSONObject request){
try {
execute(request);
while(this.list == null){
sleep(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
}

return this.list;

}

public JSONObject prepareInteraction(String request, String key1, String key2, String key3, String res1, String res2, String res3, String command){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("key1", key1);
this.jsonRequest.put("key2", key2);
this.jsonRequest.put("key3", key3);
this.jsonRequest.put("res1", res1);
this.jsonRequest.put("res2", res2);
this.jsonRequest.put("res3", res3);
this.jsonRequest.put("keyWord1", key1);
this.jsonRequest.put("keyWord2", key2);
this.jsonRequest.put("keyWord3", key3);
this.jsonRequest.put("response1", res1);
this.jsonRequest.put("response2", res2);
this.jsonRequest.put("response3", res3);
this.jsonRequest.put("command", command);

} catch (JSONException e) {
Expand All @@ -96,13 +104,14 @@ public JSONObject prepareInteraction(String request, String key1, String key2, S
return jsonRequest;
}

public JSONObject prepareDevice(String request, String device, String desc){
public JSONObject prepareDevice(String request, String device, String desc, String json){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("device", device);
this.jsonRequest.put("description", desc);
this.jsonRequest.put("json", json);

} catch (JSONException e) {
e.printStackTrace();
Expand Down Expand Up @@ -133,7 +142,7 @@ public JSONObject prepareProject(String request, String project, String desc){
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("project", project);
this.jsonRequest.put("description", desc);
this.jsonRequest.put("repository", desc);

} catch (JSONException e) {
e.printStackTrace();
Expand Down
4 changes: 2 additions & 2 deletions App/app/src/main/res/layout/fragment_adddevice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
android:textColor="#fff"
android:fontFamily="sans-serif-black"
android:textSize="20sp"
android:id="@+id/txtAddDescription"
android:id="@+id/txtAddDeviceDescription"
/>

</LinearLayout>
Expand All @@ -84,7 +84,7 @@
android:textColor="#fff"
android:fontFamily="sans-serif-black"
android:layout_marginTop="300dp"
android:id="@+id/bntAddDevice"/>
android:id="@+id/btnAddDevice"/>


</LinearLayout>
2 changes: 1 addition & 1 deletion App/app/src/main/res/layout/fragment_addproject.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:textColor="#fff"
android:fontFamily="sans-serif-black"
android:layout_marginTop="300dp"
android:id="@+id/bntAddProject"/>
android:id="@+id/btnAddProject"/>


</LinearLayout>

0 comments on commit b3975ff

Please sign in to comment.