From b3975ffc80ada9062839a49fee33191583f28526 Mon Sep 17 00:00:00 2001 From: Gazebo Date: Thu, 9 Jul 2020 22:38:23 -0300 Subject: [PATCH] AdicionandoTudoPeloApp --- .../DevicesFragments/AddDeviceFragment.java | 34 ++++++++++- .../AddInteractionFragment.java | 47 ++++++++++++++- .../AddHomeWorkFragment.java | 59 ++++++++++++++++--- .../ProjectsFragments/AddProjectFragment.java | 33 ++++++++++- .../sextafeiramobile/ServerConnection.java | 51 +++++++++------- .../main/res/layout/fragment_adddevice.xml | 4 +- .../main/res/layout/fragment_addproject.xml | 2 +- 7 files changed, 196 insertions(+), 34 deletions(-) diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/AddDeviceFragment.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/AddDeviceFragment.java index 847de8c..af287e3 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/AddDeviceFragment.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/AddDeviceFragment.java @@ -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; } } diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/InteractionsFragments/AddInteractionFragment.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/InteractionsFragments/AddInteractionFragment.java index 3c7c7e1..da9f25f 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/InteractionsFragments/AddInteractionFragment.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/InteractionsFragments/AddInteractionFragment.java @@ -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; } } diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/HomeworkFragments/AddHomeWorkFragment.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/HomeworkFragments/AddHomeWorkFragment.java index 0b0406d..43db0d8 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/HomeworkFragments/AddHomeWorkFragment.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/HomeworkFragments/AddHomeWorkFragment.java @@ -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; } } diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/ProjectsFragments/AddProjectFragment.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/ProjectsFragments/AddProjectFragment.java index 2553422..872eb68 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/ProjectsFragments/AddProjectFragment.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/SkillsFragments/ProjectsFragments/AddProjectFragment.java @@ -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; } } diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java index ec55257..f6e4e9a 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java @@ -27,20 +27,8 @@ public class ServerConnection extends AsyncTask list = null; private JSONArray arrayResponse; private char[] buffer = new char[9000]; + private boolean msgStatus = false; - public ArrayList sendRequest(JSONObject request){ - try { - execute(request); - while(this.list == null){ - sleep(100); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return this.list; - - } @Override protected ArrayList doInBackground(JSONObject... params) { @@ -51,6 +39,8 @@ protected ArrayList doInBackground(JSONObject... params) { this.out.println(params[0]); + this.msgStatus = true; + this.in.read(this.buffer); this.data = new String(this.buffer); @@ -77,17 +67,35 @@ protected ArrayList doInBackground(JSONObject... params) { return null; } + public boolean getMsgStatus(){ + return this.msgStatus; + } + + public ArrayList 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) { @@ -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(); @@ -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(); diff --git a/App/app/src/main/res/layout/fragment_adddevice.xml b/App/app/src/main/res/layout/fragment_adddevice.xml index 6447267..ef21fd3 100644 --- a/App/app/src/main/res/layout/fragment_adddevice.xml +++ b/App/app/src/main/res/layout/fragment_adddevice.xml @@ -68,7 +68,7 @@ android:textColor="#fff" android:fontFamily="sans-serif-black" android:textSize="20sp" - android:id="@+id/txtAddDescription" + android:id="@+id/txtAddDeviceDescription" /> @@ -84,7 +84,7 @@ android:textColor="#fff" android:fontFamily="sans-serif-black" android:layout_marginTop="300dp" - android:id="@+id/bntAddDevice"/> + android:id="@+id/btnAddDevice"/> \ No newline at end of file diff --git a/App/app/src/main/res/layout/fragment_addproject.xml b/App/app/src/main/res/layout/fragment_addproject.xml index 3655488..15e0490 100644 --- a/App/app/src/main/res/layout/fragment_addproject.xml +++ b/App/app/src/main/res/layout/fragment_addproject.xml @@ -55,7 +55,7 @@ android:textColor="#fff" android:fontFamily="sans-serif-black" android:layout_marginTop="300dp" - android:id="@+id/bntAddProject"/> + android:id="@+id/btnAddProject"/> \ No newline at end of file