Commit d7644466e84e36f546e35765e26f97faa20dd548

Authored by Ali B
1 parent 3d4574f1

Working on new evaluation and connecting the evaluations to the database. Workin…

…g on going for hardcoded values to getting values from db
Risiko/app/src/main/java/activity/Evaluations.java
... ... @@ -19,6 +19,7 @@ import java.util.List;
19 19  
20 20 import adapters.ListAdapterEvaluations;
21 21  
  22 +import database.DatabaseSource;
22 23 import dataclasses.Evaluation;
23 24  
24 25 public class Evaluations extends AppCompatActivity {
... ... @@ -26,19 +27,22 @@ public class Evaluations extends AppCompatActivity {
26 27 String chosenEvaluation;
27 28 TextView consequence;
28 29 Button addNewEvaluation;
  30 + DatabaseSource dbs;
29 31  
30 32 @Override
31 33 protected void onCreate(Bundle savedInstanceState) {
32 34 super.onCreate(savedInstanceState);
33 35 setContentView(R.layout.activity_evaluations);
  36 + dbs = new DatabaseSource(this);
34 37  
35 38 addNewEvaluation = findViewById(R.id.btn_add_new_evaluation);
36 39 addNewEvaluation.setOnClickListener(view -> startActivity(new Intent(this, NewEvaluation.class)));
37 40  
38 41 //TODO Bytte ut Mockdata på sikt
39 42 ArrayList<Evaluation> evaluationList= new ArrayList<>();
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));
  43 + dbs.getAllEvaluation(evaluationList);
  44 +// evaluationList.add(new Evaluation("Tråkke over", "Skade foten", "Velge riktig skotøy", 1, 3));
  45 +// evaluationList.add(new Evaluation("Falle i elva", "Blir våt", "Ikke gjør det", 1, 1));
42 46 insertEvaluations(evaluationList);
43 47 }
44 48  
... ... @@ -46,16 +50,13 @@ public class Evaluations extends AppCompatActivity {
46 50 private void insertEvaluations(List<Evaluation> evaluations) {
47 51 lv = (ListView) findViewById(R.id.lv_evaluations);
48 52 lv.setAdapter(new ListAdapterEvaluations(this, evaluations));
49   - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
50   - @Override
51   - public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
52   - chosenEvaluation = ((Evaluation) lv.getItemAtPosition(position)).getTitle();
53   - showEvaluationPopup();
54   - }
  53 + lv.setOnItemClickListener((parent, view, position, id) -> {
  54 +// chosenEvaluation = ((Evaluation) lv.getItemAtPosition(position)).getTitle();
  55 + showEvaluationPopup((Evaluation) lv.getItemAtPosition(position));
55 56 });
56 57 }
57 58  
58   - private void showEvaluationPopup() {
  59 + private void showEvaluationPopup(Evaluation evaluation) {
59 60  
60 61 LayoutInflater layoutInflater = LayoutInflater.from(this);
61 62 View promptView = layoutInflater.inflate(R.layout.popup_evaluation, null);
... ... @@ -63,8 +64,7 @@ public class Evaluations extends AppCompatActivity {
63 64 alertDialogBuilder.setView(promptView);
64 65  
65 66 //TODO FINNE EN MÅTE Å KNYTTE SAMMEN POPUP MED DET ELEMENTET SOM
66   - Evaluation evaluati = new Evaluation("Tråkke over", "Skade foten", "Velge riktig skotøy", 1, 2);
67   -
  67 +// Evaluation evaluati = new Evaluation("Tråkke over", "Skade foten", "Velge riktig skotøy", 1, 2);
68 68  
69 69  
70 70 TextView headline = promptView.findViewById(R.id.pop_headline);
... ... @@ -78,10 +78,10 @@ public class Evaluations extends AppCompatActivity {
78 78 TextView probabilityHigh = promptView.findViewById(R.id.pop_probability_high);
79 79  
80 80  
81   - if (evaluati.getProbability() == 3) {
  81 + if (evaluation.getProbability() == 3) {
82 82 probabilityHigh.setTextColor(getResources().getColor(R.color.colorDarkGreen));
83 83 probabilityHigh.setTypeface(Typeface.DEFAULT_BOLD);
84   - } else if(evaluati.getProbability() == 2) {
  84 + } else if(evaluation.getProbability() == 2) {
85 85 probabilityMedium.setTextColor(getResources().getColor(R.color.colorDarkGreen));
86 86 probabilityMedium.setTypeface(Typeface.DEFAULT_BOLD);
87 87 } else {
... ... @@ -90,10 +90,10 @@ public class Evaluations extends AppCompatActivity {
90 90 }
91 91  
92 92  
93   - if (evaluati.getConsequence() == 1) {
  93 + if (evaluation.getConsequence() == 1) {
94 94 consequenceHarmless.setTextColor(getResources().getColor(R.color.colorDarkGreen));
95 95 consequenceHarmless.setTypeface(Typeface.DEFAULT_BOLD);
96   - } else if(evaluati.getConsequence() == 2) {
  96 + } else if(evaluation.getConsequence() == 2) {
97 97 consequenceModerate.setTextColor(getResources().getColor(R.color.colorDarkGreen));
98 98 consequenceModerate.setTypeface(Typeface.DEFAULT_BOLD);
99 99 } else {
... ... @@ -102,10 +102,9 @@ public class Evaluations extends AppCompatActivity {
102 102 }
103 103  
104 104  
105   - headline.setText(evaluati.getTitle());
106   - outcome.setText("- " + evaluati.getOutcome());
107   - measures.setText("- " + evaluati.getMeasures());
108   -
  105 + headline.setText(evaluation.getTitle());
  106 + outcome.setText("- " + evaluation.getOutcome());
  107 + measures.setText("- " + evaluation.getMeasures());
109 108  
110 109 alertDialogBuilder.setCancelable(false)
111 110 .setNegativeButton(getString(R.string.cancel),
... ... @@ -113,8 +112,6 @@ public class Evaluations extends AppCompatActivity {
113 112 AlertDialog alert = alertDialogBuilder.create();
114 113  
115 114 alert.show();
116   -
117   -
118 115 }
119 116  
120 117 }
... ...
Risiko/app/src/main/java/activity/NewEvaluation.java
... ... @@ -2,18 +2,34 @@ package activity;
2 2  
3 3 import android.support.v7.app.AppCompatActivity;
4 4 import android.os.Bundle;
  5 +import android.view.View;
5 6 import android.widget.ArrayAdapter;
  7 +import android.widget.Button;
  8 +import android.widget.EditText;
6 9 import android.widget.Spinner;
  10 +import android.widget.TextView;
7 11  
8 12 import com.risiko.risiko.R;
9 13  
  14 +import database.DatabaseSource;
  15 +import dataclasses.Evaluation;
  16 +
10 17 public class NewEvaluation extends AppCompatActivity {
11 18  
  19 + private EditText etNewEvalTitle, etNewEvalOutcome, etNewEvalAction;
  20 + private Button btnNewEval;
  21 + DatabaseSource dbs;
  22 +
12 23 @Override
13 24 protected void onCreate(Bundle savedInstanceState) {
14 25 super.onCreate(savedInstanceState);
15 26 setContentView(R.layout.activity_new_evaluation);
16 27  
  28 + dbs = new DatabaseSource(this);
  29 + etNewEvalTitle = findViewById(R.id.et_newEval_title);
  30 + etNewEvalOutcome = findViewById(R.id.et_newEval_outcome);
  31 + etNewEvalAction = findViewById(R.id.et_newEval_action);
  32 +
17 33 Spinner consequenceSpinner = (Spinner) findViewById(R.id.spinner_consequence);
18 34 ArrayAdapter<CharSequence> consequenceAdapter = ArrayAdapter.createFromResource(this, R.array.consequence_array, android.R.layout.simple_spinner_item);
19 35 consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
... ... @@ -23,5 +39,27 @@ public class NewEvaluation extends AppCompatActivity {
23 39 ArrayAdapter<CharSequence> associatedRiskAdapter = ArrayAdapter.createFromResource(this, R.array.associated_risk_array, android.R.layout.simple_spinner_item);
24 40 consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
25 41 associatedRiskSpinner.setAdapter(associatedRiskAdapter);
  42 +
  43 + btnNewEval = findViewById(R.id.btn_new_eval);
  44 +
  45 + btnNewEval.setOnClickListener(view -> {
  46 + if (inputAccepted()) {
  47 + String title = etNewEvalTitle.getText().toString();
  48 + String outcome = etNewEvalOutcome.getText().toString();
  49 + String action = etNewEvalAction.getText().toString();
  50 +
  51 + //TODO: Finish this
  52 + Evaluation newEval = new Evaluation(title,outcome,action,)
  53 + dbs.insertEvaluation()
  54 + }
  55 + });
  56 +
  57 + }
  58 +
  59 + private boolean inputAccepted() {
  60 + if (etNewEvalTitle.getText().toString().isEmpty()) return false;
  61 + if (etNewEvalAction.getText().toString().isEmpty()) return false;
  62 + if (etNewEvalOutcome.getText().toString().isEmpty()) return false;
  63 + return true;
26 64 }
27 65 }
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvaluations.java
... ... @@ -29,10 +29,10 @@ public class ListAdapterEvaluations extends ArrayAdapter&lt;Evaluation&gt; {
29 29 evaluationHeadline.setText(evaluation.getTitle());
30 30  
31 31 TextView probability = convertView.findViewById(R.id.tv_probability);
32   - probability.setText(evaluation.getProbability());
  32 + probability.setText(evaluation.getProbability() + "");
33 33  
34 34 TextView consequence = convertView.findViewById(R.id.tv_consequence);
35   - consequence.setText(evaluation.getConsequence());
  35 + consequence.setText(evaluation.getConsequence() + "");
36 36  
37 37 return convertView;
38 38 }
... ...
Risiko/app/src/main/res/layout/activity_new_evaluation.xml
... ... @@ -23,25 +23,28 @@
23 23  
24 24  
25 25 <EditText
26   - android:layout_marginVertical="10dp"
  26 + android:id="@+id/et_newEval_title"
27 27 android:layout_width="match_parent"
28 28 android:layout_height="wrap_content"
  29 + android:layout_marginVertical="10dp"
29 30 android:hint="Tittel:"
30   - android:inputType="text"/>
  31 + android:inputType="text" />
31 32  
32 33 <EditText
33   - android:layout_marginVertical="10dp"
  34 + android:id="@+id/et_newEval_outcome"
34 35 android:layout_width="match_parent"
35 36 android:layout_height="wrap_content"
  37 + android:layout_marginVertical="10dp"
36 38 android:hint="Mulig utfall:"
37   - android:inputType="text"/>
  39 + android:inputType="text" />
38 40  
39 41 <EditText
40   - android:layout_marginVertical="10dp"
  42 + android:id="@+id/et_newEval_action"
41 43 android:layout_width="match_parent"
42 44 android:layout_height="wrap_content"
  45 + android:layout_marginVertical="10dp"
43 46 android:hint="Tiltak:"
44   - android:inputType="text"/>
  47 + android:inputType="text" />
45 48  
46 49 <LinearLayout
47 50 android:padding="10dp"
... ... @@ -91,11 +94,12 @@
91 94 </LinearLayout>
92 95  
93 96 <Button
94   - android:layout_marginTop="30dp"
95   - android:layout_gravity="center"
  97 + android:id="@+id/btn_new_eval"
96 98 android:layout_width="150dp"
97 99 android:layout_height="wrap_content"
98   - android:text="Legg til "/>
  100 + android:layout_gravity="center"
  101 + android:layout_marginTop="30dp"
  102 + android:text="Legg til " />
99 103  
100 104 </LinearLayout>
101 105  
... ...