Commit 85beaaa902866783ffd17d98ba99565c537bf8bf

Authored by kristinlaahneolsen
1 parent 70b54cf8

Har ryddet i koden. Fjernet ting som ikke er i bruk, sjekket at alle TODO's er g…

…jort og formattert kode. Nå skal det være klart til å leveres
Showing 38 changed files with 652 additions and 739 deletions   Show diff stats
Risiko/app/src/main/java/activity/Accesslog.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
6 6 import android.support.v7.widget.Toolbar;
  7 +import android.util.Log;
7 8 import android.view.Menu;
8 9 import android.view.MenuItem;
9 10 import android.widget.ListView;
10   -import android.widget.Toast;
11 11  
12 12 import com.risiko.risiko.R;
13 13  
... ... @@ -15,10 +15,8 @@ import java.util.ArrayList;
15 15 import java.util.List;
16 16  
17 17 import adapters.ListAdapterAccesslog;
18   -import adapters.ListAdapterEvaluationLog;
19 18 import api.Api;
20   -import dataclasses.*;
21   -import dataclasses.EvaluationLog;
  19 +import api.TokenEncrypter;
22 20 import retrofit2.Call;
23 21 import retrofit2.Callback;
24 22 import retrofit2.Response;
... ... @@ -36,8 +34,6 @@ public class Accesslog extends AppCompatActivity {
36 34 Intent intent = getIntent();
37 35 Bundle b = intent.getExtras();
38 36 String assosiatedincident = b.getString("associatedincitent");
39   - System.out.println("ASSOSIATED INCIDENT" + assosiatedincident);
40   -
41 37  
42 38 Api.getInstance().getAccesslog(assosiatedincident).enqueue(new Callback<List<dataclasses.Accesslog>>() {
43 39 @Override
... ... @@ -49,26 +45,22 @@ public class Accesslog extends AppCompatActivity {
49 45 if (log != null) {
50 46 for (dataclasses.Accesslog e : log) {
51 47 logs.add(e);
52   -
53 48 }
54 49  
55 50 insertLog(logs);
56 51 }
57 52 }
58   -
59 53 }
60 54  
61 55 @Override
62 56 public void onFailure(Call<List<dataclasses.Accesslog>> call, Throwable t) {
63   - t.printStackTrace();
  57 + Log.d("Error", t.getMessage());
64 58  
65 59 }
66 60 });
67 61  
68 62 }
69 63  
70   - //TODO GJØRE DET SLIK AT VI FÅR SATT INN GRUPPENAVN i AKSSLOGGEN
71   -
72 64 private void insertLog(List<dataclasses.Accesslog> log) {
73 65 lv = findViewById(R.id.lv_accesslog);
74 66 lv.setAdapter(new ListAdapterAccesslog(this, log));
... ... @@ -76,7 +68,7 @@ public class Accesslog extends AppCompatActivity {
76 68  
77 69  
78 70 @Override
79   - public boolean onCreateOptionsMenu (Menu menu) {
  71 + public boolean onCreateOptionsMenu(Menu menu) {
80 72 getMenuInflater().inflate(R.menu.main, menu);
81 73 return true;
82 74 }
... ... @@ -86,9 +78,7 @@ public class Accesslog extends AppCompatActivity {
86 78 public boolean onOptionsItemSelected(MenuItem item) {
87 79 switch (item.getItemId()) {
88 80 case R.id.action_logout:
89   - //TODO: LEGG TIL LOGG-UT-FUNKSJON
90   - Toast.makeText(Accesslog.this, "Logger ut",
91   - Toast.LENGTH_LONG).show();
  81 + TokenEncrypter.logOut(this);
92 82 return true;
93 83  
94 84 case R.id.action_home:
... ... @@ -103,9 +93,9 @@ public class Accesslog extends AppCompatActivity {
103 93 return true;
104 94  
105 95 default:
  96 +
106 97 return super.onOptionsItemSelected(item);
107 98  
108 99 }
109 100 }
110   -
111 101 }
... ...
Risiko/app/src/main/java/activity/Activities.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
6 6 import android.support.v7.widget.Toolbar;
7 7 import android.util.Log;
8 8 import android.view.Menu;
9 9 import android.view.MenuItem;
10 10 import android.widget.ListView;
11   -import android.widget.Toast;
12   -
13 11 import com.risiko.risiko.R;
14   -
15 12 import java.util.List;
16 13 import adapters.ListAdapterActivities;
17 14 import api.Api;
... ... @@ -46,13 +43,10 @@ public class Activities extends AppCompatActivity {
46 43  
47 44 @Override
48 45 public void onFailure(Call<List<Activity>> call, Throwable t) {
49   - //Something went completely south (maybe you lost internet connection)
50 46 Log.d("Error", t.getMessage());
51 47 }
52 48 });
53   - }
54   -
55   -
  49 + }
56 50  
57 51 private void insertActivities(List<Activity> activities) {
58 52 lv = findViewById(R.id.lv_activities);
... ... @@ -72,7 +66,7 @@ public class Activities extends AppCompatActivity {
72 66 }
73 67  
74 68 @Override
75   - public boolean onCreateOptionsMenu (Menu menu) {
  69 + public boolean onCreateOptionsMenu(Menu menu) {
76 70 getMenuInflater().inflate(R.menu.main, menu);
77 71 return true;
78 72 }
... ... @@ -100,5 +94,4 @@ public class Activities extends AppCompatActivity {
100 94  
101 95 }
102 96 }
103   -
104 97 }
... ...
Risiko/app/src/main/java/activity/EditEvaluation.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.icu.util.Measure;
5   -import android.support.v7.app.AppCompatActivity;
6 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
7 6 import android.support.v7.widget.Toolbar;
  7 +import android.util.Log;
8 8 import android.view.MenuItem;
9 9 import android.widget.ArrayAdapter;
10 10 import android.widget.Button;
11 11 import android.widget.EditText;
12 12 import android.widget.Spinner;
13   -import android.widget.Toast;
14   -
15 13 import com.risiko.risiko.R;
16   -
17 14 import java.text.DateFormat;
18 15 import java.text.SimpleDateFormat;
19 16 import java.util.Calendar;
20 17 import java.util.Date;
21 18 import java.util.Set;
22 19 import java.util.TreeSet;
23   -
24 20 import api.Api;
25 21 import api.TokenEncrypter;
26   -import dataclasses.*;
  22 +import dataclasses.Evaluation;
  23 +import dataclasses.User;
27 24 import retrofit2.Call;
28 25 import retrofit2.Callback;
29 26 import retrofit2.Response;
30 27  
31 28 public class EditEvaluation extends AppCompatActivity {
  29 + Button editEvaluation;
  30 + String token;
32 31 private EditText etTitle;
33 32 private EditText etOutcome;
34 33 private EditText etMeasures;
35 34 private Spinner spinnerConsequence, spinnerProbability;
36   - Button editEvaluation;
37   - String allFieldsChanged, titleChanged, measuresChanged, outcomeChanged, consequenceChanged, probabilityChanged;
38   - String token;
39   -
40 35  
41 36 @Override
42 37 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -57,7 +52,6 @@ public class EditEvaluation extends AppCompatActivity {
57 52 String assosiatedActivity = b.getString("associatedActivity");
58 53 setupSpinners(consequence, probability);
59 54  
60   -
61 55 etTitle = findViewById(R.id.et_editEval_title);
62 56 etOutcome = findViewById(R.id.et_editEval_outcome);
63 57 etMeasures = findViewById(R.id.et_editEval_action);
... ... @@ -89,36 +83,35 @@ public class EditEvaluation extends AppCompatActivity {
89 83  
90 84 Set<String> setInput = new TreeSet();
91 85  
92   - if(!newtitle.equals(title))
  86 + if (!newtitle.equals(title))
93 87 setInput.add("tittel");
94   - if(!newOutcome.equals(outcome))
  88 + if (!newOutcome.equals(outcome))
95 89 setInput.add("utfall");
96   - if(!newMeasures.equals(measures))
  90 + if (!newMeasures.equals(measures))
97 91 setInput.add("tiltak");
98   - if(consequenceValue!=consequence)
  92 + if (consequenceValue != consequence)
99 93 setInput.add("konsekvens");
100   - if(probabilityValue!=probability )
  94 + if (probabilityValue != probability)
101 95 setInput.add("sannsynlighet");
102 96  
103   - StringBuilder sb= new StringBuilder();
  97 + StringBuilder sb = new StringBuilder();
104 98  
105   - for(String tempString:setInput){
  99 + for (String tempString : setInput) {
106 100 sb.append(tempString).append(", ");
107 101 }
108 102  
109 103 String fieldschanged = sb.toString();
110   - System.out.println("FØLGENDE FELT BLE OPPDATERT: " + fieldschanged);
111 104 logchanges(fieldschanged, logDate, id);
112 105  
113 106 Api.getInstance().editEvaluation(id, newtitle, newOutcome, newMeasures, consequenceValue, probabilityValue, assosiatedActivity).enqueue(new Callback<Evaluation>() {
114 107 @Override
115 108 public void onResponse(Call<Evaluation> call, Response<Evaluation> response) {
116   - System.out.println(response);
  109 +
117 110 }
118 111  
119 112 @Override
120 113 public void onFailure(Call<Evaluation> call, Throwable t) {
121   - t.printStackTrace();
  114 + Log.d("Error", t.getMessage());
122 115  
123 116 }
124 117 });
... ... @@ -126,7 +119,6 @@ public class EditEvaluation extends AppCompatActivity {
126 119 }
127 120 finish();
128 121 goBackToActivities();
129   -
130 122 });
131 123 }
132 124  
... ... @@ -142,12 +134,12 @@ public class EditEvaluation extends AppCompatActivity {
142 134 Api.getInstance().newLogEntry(response.body().getName(), date, fieldsChanged, assosiatedEval).enqueue(new Callback<String>() {
143 135 @Override
144 136 public void onResponse(Call<String> call, Response<String> response) {
145   - System.out.println(response);
  137 +
146 138 }
147 139  
148 140 @Override
149 141 public void onFailure(Call<String> call, Throwable t) {
150   - t.printStackTrace();
  142 + Log.d("Error", t.getMessage());
151 143  
152 144 }
153 145 });
... ... @@ -159,10 +151,8 @@ public class EditEvaluation extends AppCompatActivity {
159 151 }
160 152 });
161 153  
162   -
163 154 }
164 155  
165   -
166 156 private void goBackToActivities() {
167 157 Intent intent = new Intent(this, Activities.class);
168 158 startActivity(intent);
... ... @@ -193,19 +183,27 @@ public class EditEvaluation extends AppCompatActivity {
193 183  
194 184 private int getConsequenceValue(String consequence) {
195 185 switch (consequence) {
196   - case "Ufarlig": return 1;
197   - case "Moderate": return 2;
198   - case "Alvorlig": return 3;
199   - default: return -1;
  186 + case "Ufarlig":
  187 + return 1;
  188 + case "Moderate":
  189 + return 2;
  190 + case "Alvorlig":
  191 + return 3;
  192 + default:
  193 + return -1;
200 194 }
201 195 }
202 196  
203 197 private int getProbabilityValue(String probability) {
204 198 switch (probability) {
205   - case "Lav": return 1;
206   - case "Middels": return 2;
207   - case "Stor": return 3;
208   - default: return -1;
  199 + case "Lav":
  200 + return 1;
  201 + case "Middels":
  202 + return 2;
  203 + case "Stor":
  204 + return 3;
  205 + default:
  206 + return -1;
209 207 }
210 208 }
211 209  
... ...
Risiko/app/src/main/java/activity/EditIncident.java
... ... @@ -12,12 +12,9 @@ import android.widget.Button;
12 12 import android.widget.EditText;
13 13 import android.widget.Spinner;
14 14 import android.widget.Toast;
15   -
16 15 import com.risiko.risiko.R;
17   -
18 16 import java.util.HashMap;
19 17 import java.util.List;
20   -
21 18 import api.Api;
22 19 import api.TokenEncrypter;
23 20 import dataclasses.Evaluation;
... ... @@ -93,16 +90,13 @@ public class EditIncident extends AppCompatActivity {
93 90 Api.getInstance().editIncident(id, newdate, newlocation, newtitle, newdescription, associatedRisk).enqueue(new Callback<dataclasses.Incident>() {
94 91 @Override
95 92 public void onResponse(Call<Incident> call, Response<Incident> response) {
96   - System.out.println(response);
97 93  
98 94 }
99 95  
100   -
101 96 @Override
102 97 public void onFailure(Call<Incident> call, Throwable t) {
103   - t.printStackTrace();
  98 + Log.d("Error", t.getMessage());
104 99 }
105   -
106 100 });
107 101 }
108 102  
... ... @@ -110,23 +104,18 @@ public class EditIncident extends AppCompatActivity {
110 104 goBackToIncidents();
111 105  
112 106 });
113   -
114   -
115 107 }
116 108 }
117 109 }
118 110  
119 111 @Override
120 112 public void onFailure(Call<List<dataclasses.Evaluation>> call, Throwable t) {
121   - //Something went completely south (maybe you lost internet connection)
122 113 Toast.makeText(EditIncident.this, "Something went wrong",
123 114 Toast.LENGTH_LONG).show();
124 115 Log.d("Error", t.getMessage());
125 116 }
126 117 });
127   -
128   -
129   - }
  118 + }
130 119  
131 120 private void goBackToIncidents() {
132 121 Intent intent = new Intent(this, activity.Incident.class);
... ... @@ -179,8 +168,6 @@ public class EditIncident extends AppCompatActivity {
179 168  
180 169 }
181 170 }
182   -
183   -
184 171 }
185 172  
186 173  
... ...
Risiko/app/src/main/java/activity/EvaluationLog.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
6 6 import android.support.v7.widget.Toolbar;
  7 +import android.util.Log;
7 8 import android.view.Menu;
8 9 import android.view.MenuItem;
9 10 import android.widget.ListView;
10   -import android.widget.Toast;
11   -
12 11 import com.risiko.risiko.R;
13   -
14 12 import java.util.ArrayList;
15   -import java.util.Date;
16 13 import java.util.List;
17   -
18   -import adapters.ListAdapterActivities;
19 14 import adapters.ListAdapterEvaluationLog;
20 15 import api.Api;
21 16 import api.TokenEncrypter;
22   -import dataclasses.Activity;
23   -import dataclasses.Evaluation;
24 17 import retrofit2.Call;
25 18 import retrofit2.Callback;
26 19 import retrofit2.Response;
... ... @@ -28,7 +21,6 @@ import retrofit2.Response;
28 21 public class EvaluationLog extends AppCompatActivity {
29 22 ListView lv;
30 23  
31   -
32 24 @Override
33 25 protected void onCreate(Bundle savedInstanceState) {
34 26 super.onCreate(savedInstanceState);
... ... @@ -39,36 +31,32 @@ public class EvaluationLog extends AppCompatActivity {
39 31 Intent intent = getIntent();
40 32 Bundle b = intent.getExtras();
41 33 String assosiatedeval = b.getString("assosiatedeval");
42   -/*
43   - List<dataclasses.EvaluationLog> log = new ArrayList<>();
44   - log.add(new dataclasses.EvaluationLog("Ola Nordmann", "2015-02-02", "Alle", assosiatedeval));
45   - log.add(new dataclasses.EvaluationLog("Kari Nordmann", "2015-01-02", "Tittel, konsekvens", assosiatedeval));
46   - insertLog(log);*/
47   -
48   - Api.getInstance().getEvaluationLog(assosiatedeval).enqueue(new Callback<List<dataclasses.EvaluationLog>>() {
49   - @Override
50   - public void onResponse(Call<List<dataclasses.EvaluationLog>> call, Response<List<dataclasses.EvaluationLog>> response) {
51   - if (response.isSuccessful()) {
52   - List<dataclasses.EvaluationLog> log = response.body();
53   - List<dataclasses.EvaluationLog> logs = new ArrayList<>();
54   -
55   - if (log != null) {
56   - for (dataclasses.EvaluationLog e : log) {
57   - logs.add(e);
58   -
59   - }
60   - insertLog(logs);
61   - }
62   - }
63   - }
64   -
65   -
66   - @Override
67   - public void onFailure(Call<List<dataclasses.EvaluationLog>> call, Throwable t) {
68   - t.printStackTrace();
69   -
70   - }
71   - });
  34 +
  35 + Api.getInstance().getEvaluationLog(assosiatedeval).enqueue(new Callback<List<dataclasses.EvaluationLog>>() {
  36 + @Override
  37 + public void onResponse(Call<List<dataclasses.EvaluationLog>> call, Response<List<dataclasses.EvaluationLog>> response) {
  38 + if (response.isSuccessful()) {
  39 + List<dataclasses.EvaluationLog> log = response.body();
  40 + List<dataclasses.EvaluationLog> logs = new ArrayList<>();
  41 +
  42 + if (log != null) {
  43 + for (dataclasses.EvaluationLog e : log) {
  44 + logs.add(e);
  45 +
  46 + }
  47 +
  48 + insertLog(logs);
  49 + }
  50 + }
  51 + }
  52 +
  53 +
  54 + @Override
  55 + public void onFailure(Call<List<dataclasses.EvaluationLog>> call, Throwable t) {
  56 + Log.d("Error", t.getMessage());
  57 +
  58 + }
  59 + });
72 60 }
73 61  
74 62 private void insertLog(List<dataclasses.EvaluationLog> log) {
... ... @@ -76,9 +64,8 @@ public class EvaluationLog extends AppCompatActivity {
76 64 lv.setAdapter(new ListAdapterEvaluationLog(this, log));
77 65 }
78 66  
79   -
80 67 @Override
81   - public boolean onCreateOptionsMenu (Menu menu) {
  68 + public boolean onCreateOptionsMenu(Menu menu) {
82 69 getMenuInflater().inflate(R.menu.main, menu);
83 70 return true;
84 71 }
... ...
Risiko/app/src/main/java/activity/Evaluations.java
... ... @@ -79,7 +79,6 @@ public class Evaluations extends AppCompatActivity {
79 79  
80 80 @Override
81 81 public void onFailure(Call<List<Evaluation>> call, Throwable t) {
82   - //Something went completely south (maybe you lost internet connection)
83 82 Log.d("Error", t.getMessage());
84 83 }
85 84 });
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -14,19 +14,13 @@ import android.view.View;
14 14 import android.widget.Button;
15 15 import android.widget.ListView;
16 16 import android.widget.TextView;
17   -import android.widget.Toast;
18   -
19 17 import com.risiko.risiko.R;
20   -
21   -import java.security.MessageDigest;
22   -import java.security.NoSuchAlgorithmException;
23 18 import java.text.DateFormat;
24 19 import java.text.SimpleDateFormat;
25 20 import java.util.ArrayList;
26 21 import java.util.Calendar;
27 22 import java.util.Date;
28 23 import java.util.List;
29   -
30 24 import adapters.ListAdapterIncidents;
31 25 import api.Api;
32 26 import api.TokenEncrypter;
... ... @@ -56,11 +50,6 @@ public class Incident extends AppCompatActivity {
56 50  
57 51 dbs = new DatabaseSource(this);
58 52  
59   -// ArrayList<dataclasses.Incident> incidentList = new ArrayList<>();
60   -// dbs.getAllIncidents(incidentList);
61   -// insertEvents(incidentList);
62   -
63   -
64 53 Api.getInstance().getAllIncidents()
65 54 .enqueue(new Callback<List<dataclasses.Incident>>() {
66 55  
... ... @@ -103,8 +92,7 @@ public class Incident extends AppCompatActivity {
103 92 Log.d("Error", t.getMessage());
104 93 }
105 94 });
106   - }
107   -
  95 + }
108 96  
109 97 private void insertEvents(List<dataclasses.Incident> incident) {
110 98 DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
... ... @@ -133,6 +121,7 @@ public class Incident extends AppCompatActivity {
133 121  
134 122 @Override
135 123 public void onFailure(Call<String> call, Throwable t) {
  124 + Log.d("Error", t.getMessage());
136 125  
137 126 }
138 127 });
... ... @@ -141,6 +130,7 @@ public class Incident extends AppCompatActivity {
141 130  
142 131 @Override
143 132 public void onFailure(Call<User> call, Throwable t) {
  133 + Log.d("Error", t.getMessage());
144 134  
145 135 }
146 136 });
... ... @@ -181,6 +171,7 @@ public class Incident extends AppCompatActivity {
181 171  
182 172 @Override
183 173 public void onFailure(Call<User> call, Throwable t) {
  174 + Log.d("Error", t.getMessage());
184 175  
185 176 }
186 177 });
... ... @@ -195,7 +186,7 @@ public class Incident extends AppCompatActivity {
195 186  
196 187 @Override
197 188 public void onFailure(Call<Evaluation> call, Throwable t) {
198   - t.printStackTrace();
  189 + Log.d("Error", t.getMessage());
199 190  
200 191 }
201 192 });
... ... @@ -206,10 +197,6 @@ public class Incident extends AppCompatActivity {
206 197 tvLocation.setText(chosenItem.getLocation());
207 198 tvDescription.setText(chosenItem.getDescription());
208 199 addedBy.setText(chosenItem.getCreatedby());
209   -
210   - Evaluation associatedEvaluation = dbs.getEvaluationById(chosenItem.getAssociatedeval());
211   -
212   -
213 200 alertDialogBuilder.setCancelable(false)
214 201 .setNegativeButton(getString(R.string.cancel),
215 202 (dialog, id) -> dialog.cancel());
... ... @@ -236,7 +223,6 @@ public class Incident extends AppCompatActivity {
236 223  
237 224 }
238 225  
239   -
240 226 private void deleteEventDialog() {
241 227 new AlertDialog.Builder(this)
242 228 .setTitle(R.string.delete)
... ... @@ -293,5 +279,4 @@ public class Incident extends AppCompatActivity {
293 279  
294 280 }
295 281 }
296   -
297 282 }
... ...
Risiko/app/src/main/java/activity/Information.java
... ... @@ -6,10 +6,7 @@ import android.os.Bundle;
6 6 import android.support.v7.widget.Toolbar;
7 7 import android.view.Menu;
8 8 import android.view.MenuItem;
9   -import android.widget.Toast;
10   -
11 9 import com.risiko.risiko.R;
12   -
13 10 import api.TokenEncrypter;
14 11  
15 12 public class Information extends AppCompatActivity {
... ...
Risiko/app/src/main/java/activity/MainMenu.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
6 6 import android.support.v7.widget.Toolbar;
7 7 import android.view.Menu;
8 8 import android.view.MenuItem;
... ... @@ -32,7 +32,7 @@ public class MainMenu extends AppCompatActivity {
32 32 toActivityList = findViewById(R.id.btn_to_activitylist);
33 33 toActivityList.setOnClickListener(newview -> startActivity(new Intent(this, Activities.class)));
34 34  
35   - toSequences= findViewById(R.id.btn_to_sequense_of_activities);
  35 + toSequences = findViewById(R.id.btn_to_sequense_of_activities);
36 36 toSequences.setOnClickListener(newview -> startActivity(new Intent(this, SequenceOfActivities.class)));
37 37  
38 38 toEventList = findViewById(R.id.btn_to_events);
... ... @@ -44,7 +44,7 @@ public class MainMenu extends AppCompatActivity {
44 44 }
45 45  
46 46 @Override
47   - public boolean onCreateOptionsMenu (Menu menu) {
  47 + public boolean onCreateOptionsMenu(Menu menu) {
48 48 getMenuInflater().inflate(R.menu.main, menu);
49 49 return true;
50 50 }
... ... @@ -68,12 +68,10 @@ public class MainMenu extends AppCompatActivity {
68 68 return true;
69 69  
70 70  
71   -
72 71 default:
73 72  
74 73 return super.onOptionsItemSelected(item);
75 74  
76 75 }
77 76 }
78   -
79 77 }
... ...
Risiko/app/src/main/java/activity/MainPage.java
... ... @@ -12,17 +12,9 @@ import android.view.View;
12 12 import android.widget.Button;
13 13 import android.widget.EditText;
14 14 import android.widget.TextView;
15   -import android.widget.Toast;
16   -
17 15 import com.risiko.risiko.R;
18   -
19 16 import api.APILoginService;
20   -import api.Api;
21   -import api.TokenEncrypter;
22   -import dataclasses.User;
23   -import retrofit2.Call;
24   -import retrofit2.Callback;
25   -import retrofit2.Response;
  17 +
26 18  
27 19 public class MainPage extends AppCompatActivity {
28 20 Button toMainMenu;
... ... @@ -52,6 +44,7 @@ public class MainPage extends AppCompatActivity {
52 44 * First it checks the string values in password and username. If they pass the test the progress "loading" icon will be shown and the information will be sent to the LoginService.
53 45 *
54 46 */
  47 +
55 48 private void attemptLogin() {
56 49 System.out.println("0");
57 50  
... ...
Risiko/app/src/main/java/activity/NewEvaluation.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
6 6 import android.support.v7.widget.Toolbar;
  7 +import android.util.Log;
7 8 import android.view.Menu;
8 9 import android.view.MenuItem;
9 10 import android.widget.ArrayAdapter;
10 11 import android.widget.Button;
11 12 import android.widget.EditText;
12 13 import android.widget.Spinner;
13   -import android.widget.Toast;
14 14  
15 15 import com.risiko.risiko.R;
16 16  
... ... @@ -26,11 +26,11 @@ import retrofit2.Response;
26 26  
27 27 public class NewEvaluation extends AppCompatActivity {
28 28  
  29 + DatabaseSource dbs;
  30 + String token;
29 31 private EditText etNewEvalTitle, etNewEvalOutcome, etNewEvalAction;
30 32 private Spinner spinnerConsequence, spinnerProbability;
31 33 private Button btnNewEval;
32   - DatabaseSource dbs;
33   - String token;
34 34  
35 35 @Override
36 36 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -72,15 +72,14 @@ public class NewEvaluation extends AppCompatActivity {
72 72 }
73 73  
74 74  
75   - Api.getInstance().newEvaluation(title, UUID.randomUUID().toString() ,activityId,consequenceValue,action,outcome,probabilityValue, response.body().getName()).enqueue(new Callback<String>() {
  75 + Api.getInstance().newEvaluation(title, UUID.randomUUID().toString(), activityId, consequenceValue, action, outcome, probabilityValue, response.body().getName()).enqueue(new Callback<String>() {
76 76 @Override
77 77 public void onResponse(Call<String> call, Response<String> response) {
78   - System.out.println(response);
79 78 }
80 79  
81 80 @Override
82 81 public void onFailure(Call<String> call, Throwable t) {
83   - t.printStackTrace();
  82 + Log.d("Error", t.getMessage());
84 83 }
85 84 });
86 85 }
... ... @@ -90,12 +89,7 @@ public class NewEvaluation extends AppCompatActivity {
90 89 TokenEncrypter.logOut(NewEvaluation.this);
91 90 }
92 91 });
93   - ;
94 92  
95   -
96   -
97   - //Evaluation newEval = new Evaluation(activityId, title, outcome, action, consequenceValue, probabilityValue);
98   - //dbs.insertEvaluation(newEval);
99 93 finish();
100 94 }
101 95 });
... ... @@ -116,19 +110,27 @@ public class NewEvaluation extends AppCompatActivity {
116 110  
117 111 private int getConsequenceValue(String consequence) {
118 112 switch (consequence) {
119   - case "Ufarlig": return 1;
120   - case "Moderate": return 2;
121   - case "Alvorlig": return 3;
122   - default: return -1;
  113 + case "Ufarlig":
  114 + return 1;
  115 + case "Moderate":
  116 + return 2;
  117 + case "Alvorlig":
  118 + return 3;
  119 + default:
  120 + return -1;
123 121 }
124 122 }
125 123  
126 124 private int getProbabilityValue(String probability) {
127 125 switch (probability) {
128   - case "Lav": return 1;
129   - case "Middels": return 2;
130   - case "Stor": return 3;
131   - default: return -1;
  126 + case "Lav":
  127 + return 1;
  128 + case "Middels":
  129 + return 2;
  130 + case "Stor":
  131 + return 3;
  132 + default:
  133 + return -1;
132 134 }
133 135 }
134 136  
... ... @@ -140,7 +142,7 @@ public class NewEvaluation extends AppCompatActivity {
140 142 }
141 143  
142 144 @Override
143   - public boolean onCreateOptionsMenu (Menu menu) {
  145 + public boolean onCreateOptionsMenu(Menu menu) {
144 146 getMenuInflater().inflate(R.menu.main, menu);
145 147 return true;
146 148 }
... ... @@ -168,5 +170,4 @@ public class NewEvaluation extends AppCompatActivity {
168 170  
169 171 }
170 172 }
171   -
172 173 }
... ...
Risiko/app/src/main/java/activity/NewIncident.java
1 1 package activity;
2 2  
3 3 import android.content.Intent;
4   -import android.support.v7.app.AppCompatActivity;
5 4 import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
6 6 import android.support.v7.widget.Toolbar;
7 7 import android.util.Log;
8 8 import android.view.Menu;
... ... @@ -15,7 +15,6 @@ import android.widget.Toast;
15 15  
16 16 import com.risiko.risiko.R;
17 17  
18   -import java.util.ArrayList;
19 18 import java.util.HashMap;
20 19 import java.util.List;
21 20 import java.util.UUID;
... ... @@ -24,7 +23,6 @@ import api.Api;
24 23 import api.TokenEncrypter;
25 24 import database.DatabaseSource;
26 25 import dataclasses.Evaluation;
27   -import dataclasses.Incident;
28 26 import dataclasses.User;
29 27 import retrofit2.Call;
30 28 import retrofit2.Callback;
... ... @@ -58,16 +56,11 @@ public class NewIncident extends AppCompatActivity {
58 56 spinnerAssociatedRisk = findViewById(R.id.spinner_associated_risk);
59 57 spinnerReadAccess = findViewById(R.id.spinner_read_access);
60 58  
61   - //TODO FJERN DENNE MIDLERTIDIGE DELEN FOR LESEAKSESS
62   -
63 59 List<String> list = User.getAllReadAccesses();
64 60 ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(NewIncident.this, android.R.layout.simple_spinner_item, list);
65 61 adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
66 62 spinnerReadAccess.setAdapter(adapter2);
67 63  
68   -
69   -// dbs.getAllEvaluation(evaluations);
70   -
71 64 Api.getInstance().getAllEvaluations()
72 65 .enqueue(new Callback<List<Evaluation>>() {
73 66  
... ... @@ -75,7 +68,7 @@ public class NewIncident extends AppCompatActivity {
75 68 public void onResponse(Call<List<dataclasses.Evaluation>> call, Response<List<dataclasses.Evaluation>> response) {
76 69 if (response.isSuccessful()) {
77 70 List<dataclasses.Evaluation> evaluations = response.body();
78   - if (evaluations != null){
  71 + if (evaluations != null) {
79 72 HashMap<String, String> evalMap = convertToDictionaryWithIdAndTitle(evaluations);
80 73 ArrayAdapter<Object> adapter = new ArrayAdapter<>(NewIncident.this, android.R.layout.simple_spinner_item, evalMap.keySet().toArray());
81 74 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
... ... @@ -93,7 +86,6 @@ public class NewIncident extends AppCompatActivity {
93 86 String associatedRisk = evalMap.get(associatedRiskTitle);
94 87  
95 88  
96   -
97 89 Api.getInstance().getUser(token).enqueue(new Callback<User>() {
98 90 @Override
99 91 public void onResponse(Call<User> call, Response<User> response) {
... ... @@ -113,7 +105,7 @@ public class NewIncident extends AppCompatActivity {
113 105  
114 106 @Override
115 107 public void onFailure(Call<String> call, Throwable t) {
116   - t.printStackTrace();
  108 + Log.d("Error", t.getMessage());
117 109 }
118 110 });
119 111 }
... ... @@ -124,11 +116,6 @@ public class NewIncident extends AppCompatActivity {
124 116 }
125 117 });
126 118  
127   -
128   -
129   -
130   -
131   -// dbs.insertIncident(newIncident);
132 119 finish();
133 120 }
134 121 });
... ... @@ -143,7 +130,6 @@ public class NewIncident extends AppCompatActivity {
143 130  
144 131 @Override
145 132 public void onFailure(Call<List<dataclasses.Evaluation>> call, Throwable t) {
146   - //Something went completely south (maybe you lost internet connection)
147 133 Toast.makeText(NewIncident.this, "Something went wrong",
148 134 Toast.LENGTH_LONG).show();
149 135 Log.d("Error", t.getMessage());
... ... @@ -170,7 +156,7 @@ public class NewIncident extends AppCompatActivity {
170 156 }
171 157  
172 158 @Override
173   - public boolean onCreateOptionsMenu (Menu menu) {
  159 + public boolean onCreateOptionsMenu(Menu menu) {
174 160 getMenuInflater().inflate(R.menu.main, menu);
175 161 return true;
176 162 }
... ... @@ -198,5 +184,4 @@ public class NewIncident extends AppCompatActivity {
198 184  
199 185 }
200 186 }
201   -
202 187 }
... ...
Risiko/app/src/main/java/adapters/ListAdapterAccesslog.java
... ... @@ -30,7 +30,6 @@ public class ListAdapterAccesslog extends ArrayAdapter&lt;Accesslog&gt; {
30 30 }
31 31  
32 32  
33   -
34 33 TextView logDate = convertView.findViewById(R.id.tv_accesslog_date);
35 34 logDate.setText(accesslogg.getDate());
36 35  
... ... @@ -41,14 +40,9 @@ public class ListAdapterAccesslog extends ArrayAdapter&lt;Accesslog&gt; {
41 40 logGroup.setText(accesslogg.getGroupnr());
42 41  
43 42  
44   -
45   -
46 43 return convertView;
47 44 }
48 45  
49   -
50   -
51   -
52 46 }
53 47  
54 48  
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvaluations.java
... ... @@ -7,8 +7,11 @@ import android.view.View;
7 7 import android.view.ViewGroup;
8 8 import android.widget.ArrayAdapter;
9 9 import android.widget.TextView;
  10 +
10 11 import com.risiko.risiko.R;
  12 +
11 13 import java.util.List;
  14 +
12 15 import dataclasses.Evaluation;
13 16  
14 17 public class ListAdapterEvaluations extends ArrayAdapter<Evaluation> {
... ...
Risiko/app/src/main/java/api/Endpoints.java
1 1 package api;
2 2  
3   -import java.util.Date;
4   -import java.util.HashMap;
5 3 import java.util.List;
6   -import java.util.UUID;
7 4  
8 5 import dataclasses.Accesslog;
9 6 import dataclasses.Activity;
... ... @@ -12,7 +9,6 @@ import dataclasses.EvaluationLog;
12 9 import dataclasses.Incident;
13 10 import dataclasses.User;
14 11 import retrofit2.Call;
15   -import retrofit2.http.Body;
16 12 import retrofit2.http.DELETE;
17 13 import retrofit2.http.Field;
18 14 import retrofit2.http.FormUrlEncoded;
... ... @@ -24,22 +20,14 @@ import retrofit2.http.Path;
24 20 /**
25 21 * Interface for API api.Endpoints using Retrofit
26 22 */
27   -public interface Endpoints {
28 23  
  24 +public interface Endpoints {
29 25  
30   - // THE BASEURL HAS TO BE CHANGE TO THE IP-ADDRESS YOU ARE CONNECTED TO AT LOCALHOST
31 26  
32   - //HOS ALI
33   - String BASEURL = "http://172.20.10.4:3000/";
34   -// String BASEURL = "http://172.20.10.2:3000/";
35   -// String BASEURL = "http://192.168.38.200:3000/";
  27 + // OBS: THE BASEURL HAS TO BE CHANGE TO THE IP-ADDRESS YOU ARE CONNECTED TO AT LOCALHOST
36 28  
37   - //HOS KRISTIN
38   -// String BASEURL = "http://192.168.84.71:3000/";
39   - //String BASEURL = "http://172.20.10.2:3000/";
  29 + String BASEURL = "http://172.20.10.2:3000/";
40 30  
41   - //ØYVIN FIX
42   - //String BASEURL ="http://risikoapi.harm.no/";
43 31  
44 32 @FormUrlEncoded
45 33 @POST("login")
... ... @@ -89,13 +77,13 @@ public interface Endpoints {
89 77  
90 78 @FormUrlEncoded
91 79 @PATCH("evaluation/{id}")
92   - Call<Evaluation> editEvaluation(@Path("id") String id, @Field("title") String title, @Field("outcome") String outcome, @Field("measures") String measures, @Field("consequence") int consequence,
93   - @Field("probability") int probability, @Field("associatedActivity") String associatedactivity);
  80 + Call<Evaluation> editEvaluation(@Path("id") String id, @Field("title") String title, @Field("outcome") String outcome, @Field("measures") String measures, @Field("consequence") int consequence,
  81 + @Field("probability") int probability, @Field("associatedActivity") String associatedactivity);
94 82  
95 83 @FormUrlEncoded
96 84 @PATCH("incident/{id}")
97   - Call<Incident> editIncident(@Path("id") String id, @Field("date") String date, @Field("location") String location,
98   - @Field("title") String title, @Field("description") String description, @Field("associatedEval") String associatedEval);
  85 + Call<Incident> editIncident(@Path("id") String id, @Field("date") String date, @Field("location") String location,
  86 + @Field("title") String title, @Field("description") String description, @Field("associatedEval") String associatedEval);
99 87  
100 88 @GET("evaluation/{assosiatedeval}/evaluationlog")
101 89 Call<List<EvaluationLog>> getEvaluationLog(@Path("assosiatedeval") String assosiatedeval);
... ...
Risiko/app/src/main/res/layout/accessloglist.xml
... ... @@ -16,42 +16,38 @@
16 16 android:orientation="horizontal">
17 17  
18 18 <TextView
19   - android:layout_alignParentLeft="true"
20 19 android:id="@+id/tv_accesslog_date"
21 20 android:layout_width="wrap_content"
22 21 android:layout_height="wrap_content"
  22 + android:layout_alignParentLeft="true"
23 23 android:layout_marginRight="10dp"
24   - android:textSize="17dp"
25   - android:text="Dato "/>
  24 + android:text="Dato "
  25 + android:textSize="17dp" />
26 26  
27 27 <TextView
28   - android:layout_alignParentLeft="true"
29