Commit 937dd6838548c6c549b10e6eb1c471e95751840f

Authored by Ali B
1 parent 89a213a0

Improved and cleaned up code in many classes and added UUID to all dataclasses

Risiko/.idea/misc.xml
... ... @@ -24,7 +24,7 @@
24 24 </value>
25 25 </option>
26 26 </component>
27   - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
  27 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
28 28 <output url="file://$PROJECT_DIR$/build/classes" />
29 29 </component>
30 30 <component name="ProjectType">
... ...
Risiko/.idea/modules.xml
... ... @@ -3,7 +3,9 @@
3 3 <component name="ProjectModuleManager">
4 4 <modules>
5 5 <module fileurl="file://$PROJECT_DIR$/Risiko.iml" filepath="$PROJECT_DIR$/Risiko.iml" />
  6 + <module fileurl="file://C:\Users\aliba\Desktop\ITE1893_Risikovurdering_Gruppe4\Risiko\Risiko.iml" filepath="C:\Users\aliba\Desktop\ITE1893_Risikovurdering_Gruppe4\Risiko\Risiko.iml" />
6 7 <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
  8 + <module fileurl="file://C:\Users\aliba\Desktop\ITE1893_Risikovurdering_Gruppe4\Risiko\app\app.iml" filepath="C:\Users\aliba\Desktop\ITE1893_Risikovurdering_Gruppe4\Risiko\app\app.iml" />
7 9 </modules>
8 10 </component>
9 11 </project>
10 12 \ No newline at end of file
... ...
Risiko/app/src/main/java/activity/Activities.java
... ... @@ -31,19 +31,16 @@ public class Activities extends AppCompatActivity {
31 31 insertActivities(activityList);
32 32 }
33 33  
34   -
35 34 private void insertActivities(List<Activity> activities) {
36   - lv = (ListView) findViewById(R.id.lv_activities);
  35 + lv = findViewById(R.id.lv_activities);
37 36 lv.setAdapter(new ListAdapterActivities(this, activities));
38 37 lv.setOnItemClickListener((parent, view, position, id) -> {
39 38 String nameOfChosenActivity = ((Activity) lv.getItemAtPosition(position)).getNameOfActivity();
40 39 int activityId = ((Activity) lv.getItemAtPosition(position)).getId();
41   - System.out.println(activityId);
42 40 goToChosenActivity(nameOfChosenActivity, activityId);
43 41 });
44 42 }
45 43  
46   -
47 44 private void goToChosenActivity(String nameOfChosenActivity, int activityId) {
48 45 Intent intent = new Intent(this, Evaluations.class);
49 46 intent.putExtra("NAME_OF_CHOSEN_ACTIVITY", nameOfChosenActivity);
... ...
Risiko/app/src/main/java/activity/Evaluations.java
... ... @@ -7,7 +7,6 @@ import android.support.v7.app.AppCompatActivity;
7 7 import android.os.Bundle;
8 8 import android.view.LayoutInflater;
9 9 import android.view.View;
10   -import android.widget.AdapterView;
11 10 import android.widget.Button;
12 11 import android.widget.ListView;
13 12 import android.widget.TextView;
... ... @@ -24,9 +23,8 @@ import dataclasses.Evaluation;
24 23  
25 24 public class Evaluations extends AppCompatActivity {
26 25 ListView lv;
27   - String chosenEvaluation;
28 26 TextView tvNameOfActivity;
29   - Button addNewEvaluation;
  27 + Button btnNewEvaluation;
30 28 DatabaseSource dbs;
31 29  
32 30 @Override
... ... @@ -34,8 +32,8 @@ public class Evaluations extends AppCompatActivity {
34 32 super.onCreate(savedInstanceState);
35 33 setContentView(R.layout.activity_evaluations);
36 34  
37   -
38 35 dbs = new DatabaseSource(this);
  36 +
39 37 Intent intent = getIntent();
40 38 String activityName = intent.getStringExtra("NAME_OF_CHOSEN_ACTIVITY");
41 39 int activityId = intent.getIntExtra("ID_OF_CHOSEN_ACTIVITY", -1);
... ... @@ -43,9 +41,9 @@ public class Evaluations extends AppCompatActivity {
43 41 tvNameOfActivity = findViewById(R.id.tv_nameOfActivity);
44 42 tvNameOfActivity.setText(activityName);
45 43  
46   - addNewEvaluation = findViewById(R.id.btn_add_new_evaluation);
  44 + btnNewEvaluation = findViewById(R.id.btn_add_new_evaluation);
47 45 intent.setClass(this, NewEvaluation.class);
48   - addNewEvaluation.setOnClickListener(view -> {
  46 + btnNewEvaluation.setOnClickListener(view -> {
49 47 finish();
50 48 startActivity(intent);
51 49 });
... ... @@ -57,10 +55,9 @@ public class Evaluations extends AppCompatActivity {
57 55  
58 56  
59 57 private void insertEvaluations(List<Evaluation> evaluations) {
60   - lv = (ListView) findViewById(R.id.lv_evaluations);
  58 + lv = findViewById(R.id.lv_evaluations);
61 59 lv.setAdapter(new ListAdapterEvaluations(this, evaluations));
62 60 lv.setOnItemClickListener((parent, view, position, id) -> {
63   - chosenEvaluation = ((Evaluation) lv.getItemAtPosition(position)).getTitle();
64 61 showEvaluationPopup((Evaluation) lv.getItemAtPosition(position));
65 62 });
66 63 }
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -27,6 +27,7 @@ public class Incident extends AppCompatActivity {
27 27 protected void onCreate(Bundle savedInstanceState) {
28 28 super.onCreate(savedInstanceState);
29 29 setContentView(R.layout.activity_incidents);
  30 +
30 31 dbs = new DatabaseSource(this);
31 32  
32 33 ArrayList<dataclasses.Incident> incidentList = new ArrayList<>();
... ... @@ -36,7 +37,7 @@ public class Incident extends AppCompatActivity {
36 37  
37 38  
38 39 private void insertEvents(List<dataclasses.Incident> incident) {
39   - lv = (ListView) findViewById(R.id.lv_events);
  40 + lv = findViewById(R.id.lv_events);
40 41 lv.setAdapter(new ListAdapterIncidents(this, incident));
41 42 lv.setOnItemClickListener((parent, view, position, id) -> {
42 43 chosenEventId = ((dataclasses.Incident) lv.getItemAtPosition(position)).getId();
... ...
Risiko/app/src/main/java/activity/MainPage.java
... ... @@ -16,12 +16,7 @@ public class MainPage extends AppCompatActivity {
16 16 super.onCreate(savedInstanceState);
17 17 setContentView(R.layout.activity_main_page);
18 18 toMainMenu = findViewById(R.id.btn_to_main_menu);
19   - toMainMenu.setOnClickListener(new View.OnClickListener() {
20   - @Override
21   - public void onClick(View view) {
22   - toMainMenuEvent();
23   - }
24   - });
  19 + toMainMenu.setOnClickListener(view -> toMainMenuEvent());
25 20 }
26 21  
27 22 public void toMainMenuEvent(){
... ...
Risiko/app/src/main/java/activity/NewEvaluation.java
... ... @@ -16,6 +16,7 @@ import dataclasses.Evaluation;
16 16 public class NewEvaluation extends AppCompatActivity {
17 17  
18 18 private EditText etNewEvalTitle, etNewEvalOutcome, etNewEvalAction;
  19 + private Spinner spinnerConsequence, spinnerProbability;
19 20 private Button btnNewEval;
20 21 DatabaseSource dbs;
21 22  
... ... @@ -23,49 +24,49 @@ public class NewEvaluation extends AppCompatActivity {
23 24 protected void onCreate(Bundle savedInstanceState) {
24 25 super.onCreate(savedInstanceState);
25 26 setContentView(R.layout.activity_new_evaluation);
  27 +
26 28 Intent intent = getIntent();
27 29 int activityId = intent.getIntExtra("ID_OF_CHOSEN_ACTIVITY", -1);
28 30  
29   -
30 31 dbs = new DatabaseSource(this);
31 32 etNewEvalTitle = findViewById(R.id.et_newEval_title);
32 33 etNewEvalOutcome = findViewById(R.id.et_newEval_outcome);
33 34 etNewEvalAction = findViewById(R.id.et_newEval_action);
34 35  
35   - Spinner consequenceSpinner = (Spinner) findViewById(R.id.spinner_consequence);
36   - ArrayAdapter<CharSequence> consequenceAdapter = ArrayAdapter.createFromResource(this, R.array.consequence_array, android.R.layout.simple_spinner_item);
37   - consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
38   - consequenceSpinner.setAdapter(consequenceAdapter);
39   -
40   - Spinner probabilitySpinner = (Spinner) findViewById(R.id.spinner_probability);
41   - ArrayAdapter<CharSequence> probabilityAdapter = ArrayAdapter.createFromResource(this, R.array.probability_array, android.R.layout.simple_spinner_item);
42   - consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
43   - probabilitySpinner.setAdapter(probabilityAdapter);
  36 + setupSpinners();
44 37  
45 38 btnNewEval = findViewById(R.id.btn_new_eval);
46   -
47 39 btnNewEval.setOnClickListener(view -> {
48 40 if (inputAccepted()) {
49 41 String title = etNewEvalTitle.getText().toString();
50 42 String outcome = etNewEvalOutcome.getText().toString();
51 43 String action = etNewEvalAction.getText().toString();
52   - String consequence = consequenceSpinner.getSelectedItem().toString();
53   - String probability = probabilitySpinner.getSelectedItem().toString();
  44 + String consequence = spinnerConsequence.getSelectedItem().toString();
  45 + String probability = spinnerProbability.getSelectedItem().toString();
54 46  
55 47 int consequenceValue = getConsequenceValue(consequence);
56 48 int probabilityValue = getProbabilityValue(probability);
57 49  
58 50 Evaluation newEval = new Evaluation(activityId, title, outcome, action, consequenceValue, probabilityValue);
59 51 dbs.insertEvaluation(newEval);
60   -
61   -// intent.setClass(this, Evaluations.class);
62   -// startActivity(intent);
63 52 finish();
64 53 }
65 54 });
66 55  
67 56 }
68 57  
  58 + private void setupSpinners() {
  59 + spinnerConsequence = findViewById(R.id.spinner_consequence);
  60 + ArrayAdapter<CharSequence> consequenceAdapter = ArrayAdapter.createFromResource(this, R.array.consequence_array, android.R.layout.simple_spinner_item);
  61 + consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  62 + spinnerConsequence.setAdapter(consequenceAdapter);
  63 +
  64 + spinnerProbability = findViewById(R.id.spinner_probability);
  65 + ArrayAdapter<CharSequence> probabilityAdapter = ArrayAdapter.createFromResource(this, R.array.probability_array, android.R.layout.simple_spinner_item);
  66 + consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  67 + spinnerProbability.setAdapter(probabilityAdapter);
  68 + }
  69 +
69 70 private int getConsequenceValue(String consequence) {
70 71 switch (consequence) {
71 72 case "Ufarlig": return 1;
... ...
Risiko/app/src/main/java/activity/NewIncident.java
1 1 package activity;
2 2  
3   -import android.content.Intent;
4 3 import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
6   -import android.util.Log;
7 5 import android.widget.ArrayAdapter;
8 6 import android.widget.Button;
9 7 import android.widget.EditText;
... ... @@ -12,9 +10,7 @@ import android.widget.Spinner;
12 10 import com.risiko.risiko.R;
13 11  
14 12 import java.util.ArrayList;
15   -import java.util.Dictionary;
16 13 import java.util.HashMap;
17   -import java.util.List;
18 14  
19 15 import database.DatabaseSource;
20 16 import dataclasses.Evaluation;
... ... @@ -22,7 +18,7 @@ import dataclasses.Incident;
22 18  
23 19 public class NewIncident extends AppCompatActivity {
24 20  
25   - private EditText etDate, etLocation, etTitle, etDescripton;
  21 + private EditText etDate, etLocation, etTitle, etDescription;
26 22 private Spinner spinnerAssociatedRisk;
27 23 private Button btnNewIncident;
28 24 private DatabaseSource dbs;
... ... @@ -35,11 +31,10 @@ public class NewIncident extends AppCompatActivity {
35 31 etDate = findViewById(R.id.et_newIncident_date);
36 32 etLocation = findViewById(R.id.et_newIncident_location);
37 33 etTitle = findViewById(R.id.et_newIncident_title);
38   - etDescripton = findViewById(R.id.et_newIncident_description);
  34 + etDescription = findViewById(R.id.et_newIncident_description);
39 35 btnNewIncident = findViewById(R.id.btn_newIncident);
40   -
41   -
42 36 dbs = new DatabaseSource(this);
  37 +
43 38 ArrayList<Evaluation> evaluations = new ArrayList<>();
44 39 dbs.getAllEvaluation(evaluations);
45 40 HashMap<String, Integer> evalMap = convertToDictionaryWithIdAndTitle(evaluations);
... ... @@ -54,17 +49,13 @@ public class NewIncident extends AppCompatActivity {
54 49 String title = etTitle.getText().toString();
55 50 String date = etDate.getText().toString();
56 51 String location = etLocation.getText().toString();
57   - String description = etDescripton.getText().toString();
  52 + String description = etDescription.getText().toString();
58 53  
59 54 String associatedRiskTitle = spinnerAssociatedRisk.getSelectedItem().toString();
60 55 int associatedRisk = evalMap.get(associatedRiskTitle);
61   - System.out.println();
62 56  
63 57 dataclasses.Incident newIncident = new Incident(date, location, title, description, associatedRisk);
64 58 dbs.insertIncident(newIncident);
65   -
66   -// Intent intent = new Intent(this, activity.Incident.class);
67   -// startActivity(intent);
68 59 finish();
69 60 }
70 61 });
... ... @@ -75,13 +66,13 @@ public class NewIncident extends AppCompatActivity {
75 66 if (etDate.getText().toString().isEmpty()) return false;
76 67 if (etTitle.getText().toString().isEmpty()) return false;
77 68 if (etLocation.getText().toString().isEmpty()) return false;
78   - if (etDescripton.getText().toString().isEmpty()) return false;
  69 + if (etDescription.getText().toString().isEmpty()) return false;
79 70  
80 71 return true;
81 72 }
82 73  
83 74 private HashMap<String, Integer> convertToDictionaryWithIdAndTitle(ArrayList<Evaluation> evaluations) {
84   - HashMap<String, Integer> evalMap = new HashMap<String, Integer>();
  75 + HashMap<String, Integer> evalMap = new HashMap<>();
85 76 for (Evaluation e : evaluations) {
86 77 evalMap.put(e.getTitle(), e.getId());
87 78 }
... ...
Risiko/app/src/main/java/activity/SequenceOfActivities.java
... ... @@ -24,17 +24,17 @@ public class SequenceOfActivities extends AppCompatActivity {
24 24 generateReport.setOnClickListener(view -> reportDialog());
25 25  
26 26  
27   - Spinner activity1Spinner = (Spinner) findViewById(R.id.spinner_activity1);
  27 + Spinner activity1Spinner = findViewById(R.id.spinner_activity1);
28 28 ArrayAdapter<CharSequence> activity1Adapter = ArrayAdapter.createFromResource(this, R.array.activities_array, android.R.layout.simple_spinner_item);
29 29 activity1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
30 30 activity1Spinner.setAdapter(activity1Adapter);
31 31  
32   - Spinner activity2Spinner = (Spinner) findViewById(R.id.spinner_activity2);
  32 + Spinner activity2Spinner = findViewById(R.id.spinner_activity2);
33 33 ArrayAdapter<CharSequence> activity2Adapter = ArrayAdapter.createFromResource(this, R.array.activities_array, android.R.layout.simple_spinner_item);
34 34 activity2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
35 35 activity2Spinner.setAdapter(activity2Adapter);
36 36  
37   - Spinner activity3Spinner = (Spinner) findViewById(R.id.spinner_activity3);
  37 + Spinner activity3Spinner = findViewById(R.id.spinner_activity3);
38 38 ArrayAdapter<CharSequence> activity3Adapter = ArrayAdapter.createFromResource(this, R.array.activities_array, android.R.layout.simple_spinner_item);
39 39 activity3Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
40 40 activity3Spinner.setAdapter(activity3Adapter);
... ...
Risiko/app/src/main/java/dataclasses/Activity.java
1 1 package dataclasses;
2 2  
3 3 import java.util.ArrayList;
  4 +import java.util.UUID;
4 5  
5 6 /**
6 7 * Created by kristinlaahneolsen on 24.09.2018.
7 8 */
8 9  
9 10 public class Activity {
  11 +
  12 + private UUID uuid;
10 13 private int id;
11 14 private String nameOfActivity;
12 15 private ArrayList<Activity> allActivities;
... ... @@ -14,6 +17,7 @@ public class Activity {
14 17 public Activity(String nameOfActivity) {
15 18 allActivities = new ArrayList<>();
16 19 this.nameOfActivity = nameOfActivity;
  20 + uuid = UUID.randomUUID();
17 21 }
18 22  
19 23 public Activity(int id, String name) {
... ...
Risiko/app/src/main/java/dataclasses/Evaluation.java
1 1 package dataclasses;
2 2  
  3 +import java.util.UUID;
  4 +
3 5 /**
4 6 * Created by kristinlaahneolsen on 25.09.2018.
5 7 */
... ... @@ -9,6 +11,7 @@ public class Evaluation {
9 11 public static final int CONSEQUENCE_HARMLESS = 1, CONSEQUENCE_MODERATE = 2, CONSEQUENCE_SEVERE = 3;
10 12 public static final int PROBABILITY_LOW = 1, PROBABILITY_MEDIUM = 2, PROBABILITY_HIGH = 3;
11 13  
  14 + UUID uuid;
12 15 int id;
13 16 int associatedActivity;
14 17 String title;
... ... @@ -18,6 +21,7 @@ public class Evaluation {
18 21 int probability;
19 22  
20 23 public Evaluation() {
  24 + uuid = UUID.randomUUID();
21 25 }
22 26  
23 27 public Evaluation(int associatedActivity, String title, String outcome, String measures, int consequence, int probability) {
... ... @@ -27,6 +31,7 @@ public class Evaluation {
27 31 this.measures = measures;
28 32 this.consequence = consequence;
29 33 this.probability = probability;
  34 + uuid = UUID.randomUUID();
30 35 }
31 36  
32 37 public int getId() {
... ...
Risiko/app/src/main/java/dataclasses/Incident.java
1 1 package dataclasses;
2   -
3   -import java.util.Date;
  2 +import java.util.UUID;
4 3  
5 4 /**
6 5 * Created by kristinlaahneolsen on 23.09.2018.
7 6 */
8 7  
9 8 public class Incident {
  9 +
  10 + UUID uuid;
10 11 private String date;
11 12 private String placeOfEvent;
12 13 private String title;
... ... @@ -16,6 +17,7 @@ public class Incident {
16 17  
17 18  
18 19 public Incident() {
  20 + uuid = UUID.randomUUID();
19 21 }
20 22  
21 23 public Incident(String date, String place, String title, String description, int associatedEvaluation) {
... ... @@ -24,6 +26,7 @@ public class Incident {
24 26 this.title = title;
25 27 this.description = description;
26 28 this.associatedEvaluation = associatedEvaluation;
  29 + uuid = UUID.randomUUID();
27 30 }
28 31  
29 32 public Incident(String title) {
... ...