Commit 3d4574f1f05c3703cd75e93604ec3fe10b520dfb

Authored by Ali B
1 parent 0eaaa40e

fixed merge issues and refactored some of the code

Risiko/.idea/caches/build_file_checksums.ser
No preview for this file type
Risiko/app/src/main/AndroidManifest.xml
... ... @@ -18,8 +18,8 @@
18 18 </activity>
19 19 <activity android:name="activity.MainMenu" />
20 20 <activity android:name="activity.Activities" />
21   - <activity android:name="activity.Events" />
22   - <activity android:name="activity.NewEvent" />
  21 + <activity android:name="activity.Incident" />
  22 + <activity android:name="activity.NewIncident" />
23 23 <activity android:name="activity.NewEvaluation" />
24 24 <activity android:name="activity.Evaluations" />
25 25 <activity android:name="activity.SequenceOfActivities"></activity>
... ...
Risiko/app/src/main/java/activity/Evaluations.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.graphics.Color;
5 4 import android.graphics.Typeface;
6 5 import android.support.v7.app.AlertDialog;
7 6 import android.support.v7.app.AppCompatActivity;
8 7 import android.os.Bundle;
9   -import android.text.TextUtils;
10 8 import android.view.LayoutInflater;
11 9 import android.view.View;
12 10 import android.widget.AdapterView;
13 11 import android.widget.Button;
14   -import android.widget.EditText;
15 12 import android.widget.ListView;
16 13 import android.widget.TextView;
17 14  
... ... @@ -40,8 +37,8 @@ public class Evaluations extends AppCompatActivity {
40 37  
41 38 //TODO Bytte ut Mockdata på sikt
42 39 ArrayList<Evaluation> evaluationList= new ArrayList<>();
43   - evaluationList.add(new Evaluation("Tråkke over", "Skade foten", "Velge riktig skotøy", "Ufarlig", "Stor"));
44   - evaluationList.add(new Evaluation("Falle i elva", "Blir våt", "Ikke gjør det", "Ufarlig", "Liten"));
  40 + evaluationList.add(new Evaluation("Tråkke over", "Skade foten", "Velge riktig skotøy", 1, 3));
  41 + evaluationList.add(new Evaluation("Falle i elva", "Blir våt", "Ikke gjør det", 1, 1));
45 42 insertEvaluations(evaluationList);
46 43 }
47 44  
... ... @@ -52,7 +49,7 @@ public class Evaluations extends AppCompatActivity {
52 49 lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
53 50 @Override
54 51 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
55   - chosenEvaluation = ((Evaluation) lv.getItemAtPosition(position)).getHeadline();
  52 + chosenEvaluation = ((Evaluation) lv.getItemAtPosition(position)).getTitle();
56 53 showEvaluationPopup();
57 54 }
58 55 });
... ... @@ -66,7 +63,7 @@ public class Evaluations extends AppCompatActivity {
66 63 alertDialogBuilder.setView(promptView);
67 64  
68 65 //TODO FINNE EN MÅTE Å KNYTTE SAMMEN POPUP MED DET ELEMENTET SOM
69   - Evaluation evaluati = new Evaluation("Tråkke over", "Skade foten", "Velge riktig skotøy", "Ufarlig", "Middels");
  66 + Evaluation evaluati = new Evaluation("Tråkke over", "Skade foten", "Velge riktig skotøy", 1, 2);
70 67  
71 68  
72 69  
... ... @@ -81,10 +78,10 @@ public class Evaluations extends AppCompatActivity {
81 78 TextView probabilityHigh = promptView.findViewById(R.id.pop_probability_high);
82 79  
83 80  
84   - if (evaluati.getProbability().equals("Stor")) {
  81 + if (evaluati.getProbability() == 3) {
85 82 probabilityHigh.setTextColor(getResources().getColor(R.color.colorDarkGreen));
86 83 probabilityHigh.setTypeface(Typeface.DEFAULT_BOLD);
87   - } else if(evaluati.getProbability().equals("Middels")) {
  84 + } else if(evaluati.getProbability() == 2) {
88 85 probabilityMedium.setTextColor(getResources().getColor(R.color.colorDarkGreen));
89 86 probabilityMedium.setTypeface(Typeface.DEFAULT_BOLD);
90 87 } else {
... ... @@ -93,10 +90,10 @@ public class Evaluations extends AppCompatActivity {
93 90 }
94 91  
95 92  
96   - if (evaluati.getConsequence().equals("Ufarlig")) {
  93 + if (evaluati.getConsequence() == 1) {
97 94 consequenceHarmless.setTextColor(getResources().getColor(R.color.colorDarkGreen));
98 95 consequenceHarmless.setTypeface(Typeface.DEFAULT_BOLD);
99   - } else if(evaluati.getConsequence().equals("Moderat")) {
  96 + } else if(evaluati.getConsequence() == 2) {
100 97 consequenceModerate.setTextColor(getResources().getColor(R.color.colorDarkGreen));
101 98 consequenceModerate.setTypeface(Typeface.DEFAULT_BOLD);
102 99 } else {
... ... @@ -105,8 +102,8 @@ public class Evaluations extends AppCompatActivity {
105 102 }
106 103  
107 104  
108   - headline.setText(evaluati.getHeadline());
109   - outcome.setText("- " + evaluati.getPossibleOutcomes());
  105 + headline.setText(evaluati.getTitle());
  106 + outcome.setText("- " + evaluati.getOutcome());
110 107 measures.setText("- " + evaluati.getMeasures());
111 108  
112 109  
... ...
Risiko/app/src/main/java/activity/Events.java renamed to Risiko/app/src/main/java/activity/Incident.java
... ... @@ -13,40 +13,37 @@ import com.risiko.risiko.R;
13 13 import java.util.ArrayList;
14 14 import java.util.List;
15 15  
16   -import adapters.ListAdapterActivities;
17   -import adapters.ListAdapterEvents;
18   -import dataclasses.Activity;
19   -import dataclasses.Event;
  16 +import adapters.ListAdapterIncidents;
20 17  
21   -public class Events extends AppCompatActivity {
  18 +public class Incident extends AppCompatActivity {
22 19 ListView lv;
23 20 int chosenEventId;
24 21  
25 22 @Override
26 23 protected void onCreate(Bundle savedInstanceState) {
27 24 super.onCreate(savedInstanceState);
28   - setContentView(R.layout.activity_events);
  25 + setContentView(R.layout.activity_incidents);
29 26  
30 27  
31 28 //TODO Bytte ut Mockdata på sikt
32   - ArrayList<Event> eventList = new ArrayList<>();
33   - eventList.add(new Event("Datt i elva"));
34   - eventList.add(new Event("Brant meg under matlaging"));
35   - eventList.add(new Event("Vrikket foten"));
36   - eventList.add(new Event("Falt ned fra et bord"));
37   - eventList.add(new Event("Kræsjet i et tre"));
38   - eventList.add(new Event("Fikk alkoholforgiftning"));
39   - insertEvents(eventList);
  29 + ArrayList<dataclasses.Incident> incidentList = new ArrayList<>();
  30 + incidentList.add(new dataclasses.Incident("Datt i elva"));
  31 + incidentList.add(new dataclasses.Incident("Brant meg under matlaging"));
  32 + incidentList.add(new dataclasses.Incident("Vrikket foten"));
  33 + incidentList.add(new dataclasses.Incident("Falt ned fra et bord"));
  34 + incidentList.add(new dataclasses.Incident("Kræsjet i et tre"));
  35 + incidentList.add(new dataclasses.Incident("Fikk alkoholforgiftning"));
  36 + insertEvents(incidentList);
40 37 }
41 38  
42 39  
43   - private void insertEvents(List<Event> event) {
  40 + private void insertEvents(List<dataclasses.Incident> incident) {
44 41 lv = (ListView) findViewById(R.id.lv_events);
45   - lv.setAdapter(new ListAdapterEvents(this, event));
  42 + lv.setAdapter(new ListAdapterIncidents(this, incident));
46 43 lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
47 44 @Override
48 45 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
49   - chosenEventId = ((Event) lv.getItemAtPosition(position)).getId();
  46 + chosenEventId = ((dataclasses.Incident) lv.getItemAtPosition(position)).getId();
50 47 showEventPopup();
51 48  
52 49 }
... ...
Risiko/app/src/main/java/activity/MainMenu.java
... ... @@ -3,7 +3,6 @@ package activity;
3 3 import android.content.Intent;
4 4 import android.support.v7.app.AppCompatActivity;
5 5 import android.os.Bundle;
6   -import android.view.View;
7 6 import android.widget.Button;
8 7  
9 8 import com.risiko.risiko.R;
... ... @@ -23,10 +22,10 @@ public class MainMenu extends AppCompatActivity {
23 22 toActivityList.setOnClickListener(view -> startActivity(new Intent(this, Activities.class)));
24 23  
25 24 toEventList = findViewById(R.id.btn_to_events);
26   - toEventList.setOnClickListener(view -> startActivity(new Intent(this, Events.class)));
  25 + toEventList.setOnClickListener(view -> startActivity(new Intent(this, Incident.class)));
27 26  
28 27 toNewEvent = findViewById(R.id.btn_to_new_event);
29   - toNewEvent.setOnClickListener(view -> startActivity(new Intent(this, NewEvent.class)));
  28 + toNewEvent.setOnClickListener(view -> startActivity(new Intent(this, NewIncident.class)));
30 29  
31 30 }
32 31  
... ...
Risiko/app/src/main/java/activity/NewEvent.java renamed to Risiko/app/src/main/java/activity/NewIncident.java
... ... @@ -5,11 +5,11 @@ import android.os.Bundle;
5 5  
6 6 import com.risiko.risiko.R;
7 7  
8   -public class NewEvent extends AppCompatActivity {
  8 +public class NewIncident extends AppCompatActivity {
9 9  
10 10 @Override
11 11 protected void onCreate(Bundle savedInstanceState) {
12 12 super.onCreate(savedInstanceState);
13   - setContentView(R.layout.activity_new_event);
  13 + setContentView(R.layout.activity_new_incident);
14 14 }
15 15 }
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvaluations.java
... ... @@ -26,7 +26,7 @@ public class ListAdapterEvaluations extends ArrayAdapter&lt;Evaluation&gt; {
26 26 }
27 27  
28 28 TextView evaluationHeadline = convertView.findViewById(R.id.tv_headline);
29   - evaluationHeadline.setText(evaluation.getHeadline());
  29 + evaluationHeadline.setText(evaluation.getTitle());
30 30  
31 31 TextView probability = convertView.findViewById(R.id.tv_probability);
32 32 probability.setText(evaluation.getProbability());
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvents.java renamed to Risiko/app/src/main/java/adapters/ListAdapterIncidents.java
... ... @@ -12,24 +12,24 @@ import com.risiko.risiko.R;
12 12  
13 13 import java.util.List;
14 14  
15   -import dataclasses.Event;
  15 +import dataclasses.Incident;
16 16  
17   -public class ListAdapterEvents extends ArrayAdapter<Event> {
  17 +public class ListAdapterIncidents extends ArrayAdapter<Incident> {
18 18  
19   - public ListAdapterEvents(@NonNull Context context, List<Event> events) {
20   - super(context, R.layout.activity_events, events);
  19 + public ListAdapterIncidents(@NonNull Context context, List<Incident> incidents) {
  20 + super(context, R.layout.activity_incidents, incidents);
21 21 }
22 22  
23 23 @NonNull
24 24 @Override
25 25 public View getView(int position, View convertView, @NonNull ViewGroup parent) {
26   - Event event = getItem(position);
  26 + Incident incident = getItem(position);
27 27 if (convertView == null) {
28   - convertView = LayoutInflater.from(getContext()).inflate(R.layout.eventlist, parent, false);
  28 + convertView = LayoutInflater.from(getContext()).inflate(R.layout.incidentlist, parent, false);
29 29 }
30 30  
31   - TextView eventHeadline = convertView.findViewById(R.id.tv_eventHeadline);
32   - eventHeadline.setText(event.getHeadline());
  31 + TextView eventHeadline = convertView.findViewById(R.id.tv_incidentHeadline);
  32 + eventHeadline.setText(incident.getTitle());
33 33  
34 34  
35 35 return convertView;
... ...
Risiko/app/src/main/java/database/DatabaseSource.java
... ... @@ -6,9 +6,9 @@ import android.database.Cursor;
6 6 import android.database.sqlite.SQLiteDatabase;
7 7  
8 8 import java.util.ArrayList;
9   -import java.util.Date;
10 9  
11   -import dataclasses.Event;
  10 +import dataclasses.Evaluation;
  11 +import dataclasses.Incident;
12 12  
13 13 public class DatabaseSource {
14 14  
... ... @@ -23,7 +23,7 @@ public class DatabaseSource {
23 23 values.put(EvaluationTable.EVALUATION_COL_ASSOCIATED_ACTIVITY, evaluation.getAssociatedActivity());
24 24 values.put(EvaluationTable.EVALUATION_COL_TITLE, evaluation.getTitle());
25 25 values.put(EvaluationTable.EVALUATION_COL_OUTCOME, evaluation.getOutcome());
26   - values.put(EvaluationTable.EVALUATION_COL_ACTION, evaluation.getAction());
  26 + values.put(EvaluationTable.EVALUATION_COL_ACTION, evaluation.getMeasures());
27 27 values.put(EvaluationTable.EVALUATION_COL_CONSEQUENCE, evaluation.getConsequence());
28 28 values.put(EvaluationTable.EVALUATION_COL_PROBABILITY, evaluation.getProbability());
29 29  
... ... @@ -34,10 +34,10 @@ public class DatabaseSource {
34 34 return insertId > -1;
35 35 }
36 36  
37   - public boolean insertIncident(Event incident) {
  37 + public boolean insertIncident(Incident incident) {
38 38 ContentValues values = new ContentValues();
39   - values.put(IncidentTable.INCIDENT_COL_ASSOCIATED_EVALUATION, incident.getAssociatedEvaluation);
40   - values.put(IncidentTable.INCIDENT_COL_TITLE, incident.getHeadline());
  39 + values.put(IncidentTable.INCIDENT_COL_ASSOCIATED_EVALUATION, incident.getAssociatedEvaluation());
  40 + values.put(IncidentTable.INCIDENT_COL_TITLE, incident.getTitle());
41 41 values.put(IncidentTable.INCIDENT_COL_DATE, incident.getDate().toString());
42 42 values.put(IncidentTable.INCIDENT_COL_LOCATION, incident.getPlaceOfEvent());
43 43 values.put(IncidentTable.INCIDENT_COL_DESCRIPTION, incident.getDescription());
... ... @@ -62,7 +62,7 @@ public class DatabaseSource {
62 62 database.close();
63 63 }
64 64  
65   - public void getAllIncidents(ArrayList<Event> incidents) {
  65 + public void getAllIncidents(ArrayList<Incident> incidents) {
66 66 SQLiteDatabase database = helper.getWritableDatabase();
67 67 Cursor cursor = database.rawQuery("select * from " + IncidentTable.INCIDENT_TABLE, null);
68 68 cursor.moveToFirst();
... ... @@ -89,15 +89,15 @@ public class DatabaseSource {
89 89 data.setAssociatedActivity(cursor.getInt(associatedActivityIndex));
90 90 data.setTitle(cursor.getString(titleIndex));
91 91 data.setOutcome(cursor.getString(outcomeIndex));
92   - data.setAction(cursor.getString(actionIndex));
  92 + data.setMeasures(cursor.getString(actionIndex));
93 93 data.setConsequence(cursor.getInt(consequenceIndex));
94   - data.setPrbability(cursor.getInt(probabilityIndex));
  94 + data.setProbability(cursor.getInt(probabilityIndex));
95 95  
96 96 return data;
97 97 }
98 98  
99   - private Event cursorToIncident(Cursor cursor) {
100   - Event data = new Event();
  99 + private Incident cursorToIncident(Cursor cursor) {
  100 + Incident data = new Incident();
101 101 int idIndex = cursor.getColumnIndexOrThrow(IncidentTable.INCIDENT_COL_ID);
102 102 int associatedEvaluationIndex = cursor.getColumnIndexOrThrow(IncidentTable.INCIDENT_COL_ASSOCIATED_EVALUATION);
103 103 int titleIndex = cursor.getColumnIndexOrThrow(IncidentTable.INCIDENT_COL_TITLE);
... ... @@ -107,7 +107,7 @@ public class DatabaseSource {
107 107  
108 108 data.setId(cursor.getInt(idIndex));
109 109 data.setAssociatedEvaluation(cursor.getInt(associatedEvaluationIndex));
110   - data.setHeadline(cursor.getString(titleIndex));
  110 + data.setTitle(cursor.getString(titleIndex));
111 111 data.setDate(cursor.getString(dateIndex));
112 112 data.setPlaceOfEvent(cursor.getString(locationIndex));
113 113 data.setDescription(cursor.getString(descriptionIndex));
... ...
Risiko/app/src/main/java/dataclasses/Evaluation.java
... ... @@ -5,31 +5,48 @@ package dataclasses;
5 5 */
6 6  
7 7 public class Evaluation {
8   - String headline;
9   - String possibleOutcomes;
  8 +
  9 + int id;
  10 + int associatedActivity;
  11 + String title;
  12 + String outcome;
10 13 String measures;
11   - String consequence;
12   - String probability;
  14 + int consequence;
  15 + int probability;
13 16  
14 17 public Evaluation() {
15 18 }
16 19  
17   -
18   - public Evaluation(String headline, String possibleOutcomes, String measures, String consequence, String probability) {
19   - this.headline = headline;
20   - this.possibleOutcomes = possibleOutcomes;
  20 + public Evaluation(String title, String outcome, String measures, int consequence, int probability) {
  21 + this.title = title;
  22 + this.outcome = outcome;
21 23 this.measures = measures;
22 24 this.consequence = consequence;
23 25 this.probability = probability;
24 26 }
25 27  
  28 + public int getId() {
  29 + return id;
  30 + }
  31 +
  32 + public void setId(int id) {
  33 + this.id = id;
  34 + }
  35 +
  36 + public int getAssociatedActivity() {
  37 + return associatedActivity;
  38 + }
  39 +
  40 + public void setAssociatedActivity(int associatedActivity) {
  41 + this.associatedActivity = associatedActivity;
  42 + }
26 43  
27   - public String getHeadline() {
28   - return headline;
  44 + public String getTitle() {
  45 + return title;
29 46 }
30 47  
31   - public void setHeadline(String headline) {
32   - this.headline = headline;
  48 + public void setTitle(String title) {
  49 + this.title = title;
33 50 }
34 51  
35 52 public String getMeasures() {
... ... @@ -40,27 +57,27 @@ public class Evaluation {
40 57 this.measures = measures;
41 58 }
42 59  
43   - public String getConsequence() {
  60 + public int getConsequence() {
44 61 return consequence;
45 62 }
46 63  
47   - public void setConsequence(String consequence) {
  64 + public void setConsequence(int consequence) {
48 65 this.consequence = consequence;
49 66 }
50 67  
51   - public String getProbability() {
  68 + public int getProbability() {
52 69 return probability;
53 70 }
54 71  
55   - public void setProbability(String probability) {
  72 + public void setProbability(int probability) {
56 73 this.probability = probability;
57 74 }
58 75  
59   - public String getPossibleOutcomes() {
60   - return possibleOutcomes;
  76 + public String getOutcome() {
  77 + return outcome;
61 78 }
62 79  
63   - public void setPossibleOutcomes(String possibleOutcomes) {
64   - this.possibleOutcomes = possibleOutcomes;
  80 + public void setOutcome(String outcome) {
  81 + this.outcome = outcome;
65 82 }
66 83 }
... ...
Risiko/app/src/main/java/dataclasses/Event.java renamed to Risiko/app/src/main/java/dataclasses/Incident.java
... ... @@ -6,35 +6,43 @@ import java.util.Date;
6 6 * Created by kristinlaahneolsen on 23.09.2018.
7 7 */
8 8  
9   -public class Event {
10   - private Date date;
  9 +public class Incident {
  10 + private String date;
11 11 private String placeOfEvent;
12   - private String headline;
  12 + private String title;
13 13 private String description;
14 14 private int id;
  15 + private int associatedEvaluation;
15 16  
16 17  
17   - public Event() {
  18 + public Incident() {
18 19 }
19 20  
20   - public Event(Date date, String place, String headline, String description, int id) {
  21 + public Incident(String date, String place, String title, String description, int id) {
21 22 this.date = date;
22 23 this.placeOfEvent = place;
23   - this.headline = headline;
  24 + this.title = title;
24 25 this.description = description;
25 26 this.id = id;
26 27 }
27 28  
28   - public Event(String headline) {
29   - this.headline = headline;
  29 + public Incident(String title) {
  30 + this.title = title;
30 31 }
31 32  
  33 + public int getAssociatedEvaluation() {
  34 + return associatedEvaluation;
  35 + }
  36 +
  37 + public void setAssociatedEvaluation(int associatedEvaluation) {
  38 + this.associatedEvaluation = associatedEvaluation;
  39 + }
32 40  
33   - public Date getDate() {
  41 + public String getDate() {
34 42 return date;
35 43 }
36 44  
37   - public void setDate(Date date) {
  45 + public void setDate(String date) {
38 46 this.date = date;
39 47 }
40 48  
... ... @@ -46,12 +54,12 @@ public class Event {
46 54 this.placeOfEvent = placeOfEvent;
47 55 }
48 56  
49   - public String getHeadline() {
50   - return headline;
  57 + public String getTitle() {
  58 + return title;
51 59 }
52 60  
53   - public void setHeadline(String headline) {
54   - this.headline = headline;
  61 + public void setTitle(String title) {
  62 + this.title = title;
55 63 }
56 64  
57 65 public String getDescription() {
... ...
Risiko/app/src/main/res/layout/activity_events.xml renamed to Risiko/app/src/main/res/layout/activity_incidents.xml
Risiko/app/src/main/res/layout/activity_new_event.xml renamed to Risiko/app/src/main/res/layout/activity_new_incident.xml
Risiko/app/src/main/res/layout/eventlist.xml renamed to Risiko/app/src/main/res/layout/incidentlist.xml
... ... @@ -6,7 +6,7 @@
6 6 android:orientation="horizontal">
7 7  
8 8 <TextView
9   - android:id="@+id/tv_eventHeadline"
  9 + android:id="@+id/tv_incidentHeadline"
10 10 android:layout_width="wrap_content"
11 11 android:layout_height="wrap_content"
12 12 android:layout_marginBottom="10dp"
... ...