Commit 4bc8045736490ce0d95632006fdae2e646ebba6f

Authored by kristinlaahneolsen
1 parent ac812b32

Laget adapter til vurderinger, men foreløpig bare hardkodet data for å teste det…

… i tilhørende aktivitet
Risiko/.idea/vcs.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project version="4">
3 3 <component name="VcsDirectoryMappings">
4   - <mapping directory="$PROJECT_DIR$" vcs="Git" />
  4 + <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5 5 </component>
6 6 </project>
7 7 \ No newline at end of file
... ...
Risiko/app/src/main/AndroidManifest.xml
... ... @@ -20,7 +20,8 @@
20 20 <activity android:name="activity.Activities" />
21 21 <activity android:name="activity.Events" />
22 22 <activity android:name="activity.NewEvent" />
23   - <activity android:name="activity.NewEvaluation"></activity>
  23 + <activity android:name="activity.NewEvaluation" />
  24 + <activity android:name="activity.Evaluations"></activity>
24 25 </application>
25 26  
26 27 </manifest>
27 28 \ No newline at end of file
... ...
Risiko/app/src/main/java/activity/Activities.java
1 1 package activity;
2 2  
  3 +import android.content.Intent;
3 4 import android.support.v7.app.AppCompatActivity;
4 5 import android.os.Bundle;
5 6 import android.view.View;
... ... @@ -14,7 +15,7 @@ import dataclasses.Activity;
14 15  
15 16 public class Activities extends AppCompatActivity {
16 17 ListView lv;
17   - int chosenActivityId;
  18 + String chosenActivity;
18 19  
19 20 @Override
20 21 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -32,19 +33,22 @@ public class Activities extends AppCompatActivity {
32 33 }
33 34  
34 35  
35   -
36   -
37   -
38 36 private void insertActivities(List<Activity> activities) {
39 37 lv = (ListView) findViewById(R.id.lv_activities);
40 38 lv.setAdapter(new ListAdapterActivities(this, activities));
41 39 lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
42 40 @Override
43 41 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
44   - chosenActivityId = ((Activity) lv.getItemAtPosition(position)).getId();
45   - //DOSOMETHING
46   -
  42 + chosenActivity = ((Activity) lv.getItemAtPosition(position)).getNameOfActivity();
  43 + goToChosenActivity();
47 44 }
48 45 });
49 46 }
  47 +
  48 +
  49 + private void goToChosenActivity() {
  50 + Intent intent = new Intent(this, Evaluations.class);
  51 + intent.putExtra("NAME_OF_CHOSEN_ACTIVITY", chosenActivity);
  52 + startActivity(intent);
  53 + }
50 54 }
... ...
Risiko/app/src/main/java/activity/Evaluations.java 0 → 100644
  1 +package activity;
  2 +
  3 +import android.support.v7.app.AppCompatActivity;
  4 +import android.os.Bundle;
  5 +import android.view.View;
  6 +import android.widget.AdapterView;
  7 +import android.widget.ListView;
  8 +
  9 +import com.risiko.risiko.R;
  10 +
  11 +import java.util.ArrayList;
  12 +import java.util.List;
  13 +
  14 +import adapters.ListAdapterEvaluations;
  15 +
  16 +import dataclasses.Evaluation;
  17 +
  18 +public class Evaluations extends AppCompatActivity {
  19 + ListView lv;
  20 + String chosenEvaluation;
  21 +
  22 + @Override
  23 + protected void onCreate(Bundle savedInstanceState) {
  24 + super.onCreate(savedInstanceState);
  25 + setContentView(R.layout.activity_evaluations);
  26 +
  27 + //TODO Bytte ut Mockdata på sikt
  28 + ArrayList<Evaluation> evaluationList= new ArrayList<>();
  29 + evaluationList.add(new Evaluation("Tråkke over", "Velge riktig skotøy", "Ufarlig", "Stor"));
  30 + evaluationList.add(new Evaluation("Falle i elva", "Ikke gjør det", "Ufarlig", "Liten"));
  31 + insertEvaluations(evaluationList);
  32 + }
  33 +
  34 +
  35 + private void insertEvaluations(List<Evaluation> evaluations) {
  36 + lv = (ListView) findViewById(R.id.lv_evaluations);
  37 + lv.setAdapter(new ListAdapterEvaluations(this, evaluations));
  38 + lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  39 + @Override
  40 + public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  41 + chosenEvaluation = ((Evaluation) lv.getItemAtPosition(position)).getHeadline();
  42 + //TODO
  43 + }
  44 + });
  45 + }
  46 +
  47 +}
... ...
Risiko/app/src/main/java/adapters/ListAdapterEvaluations.java 0 → 100644
  1 +package adapters;
  2 +
  3 +import android.content.Context;
  4 +import android.support.annotation.NonNull;
  5 +import android.view.LayoutInflater;
  6 +import android.view.View;
  7 +import android.view.ViewGroup;
  8 +import android.widget.ArrayAdapter;
  9 +import android.widget.TextView;
  10 +import com.risiko.risiko.R;
  11 +import java.util.List;
  12 +import dataclasses.Evaluation;
  13 +
  14 +public class ListAdapterEvaluations extends ArrayAdapter<Evaluation> {
  15 +
  16 + public ListAdapterEvaluations(@NonNull Context context, List<Evaluation> evaluations) {
  17 + super(context, R.layout.activity_evaluations, evaluations);
  18 + }
  19 +
  20 + @NonNull
  21 + @Override
  22 + public View getView(int position, View convertView, @NonNull ViewGroup parent) {
  23 + Evaluation evaluation = getItem(position);
  24 + if (convertView == null) {
  25 + convertView = LayoutInflater.from(getContext()).inflate(R.layout.evaluationlist, parent, false);
  26 + }
  27 +
  28 + TextView evaluationHeadline = convertView.findViewById(R.id.tv_headline);
  29 + evaluationHeadline.setText(evaluation.getHeadline());
  30 +
  31 + TextView probability = convertView.findViewById(R.id.tv_probability);
  32 + probability.setText(evaluation.getProbability());
  33 +
  34 + TextView consequence = convertView.findViewById(R.id.tv_consequence);
  35 + consequence.setText(evaluation.getConsequence());
  36 +
  37 + return convertView;
  38 + }
  39 +
  40 +}
  41 +
  42 +
  43 +
... ...
Risiko/app/src/main/java/dataclasses/Evaluation.java 0 → 100644
  1 +package dataclasses;
  2 +
  3 +/**
  4 + * Created by kristinlaahneolsen on 25.09.2018.
  5 + */
  6 +
  7 +public class Evaluation {
  8 + String headline;
  9 + String measures;
  10 + String consequence;
  11 + String probability;
  12 +
  13 + public Evaluation() {
  14 + }
  15 +
  16 +
  17 + public Evaluation(String headline, String measures, String consequence, String probability) {
  18 + this.headline = headline;
  19 + this.measures = measures;
  20 + this.consequence = consequence;
  21 + this.probability = probability;
  22 + }
  23 +
  24 +
  25 + public String getHeadline() {
  26 + return headline;
  27 + }
  28 +
  29 + public void setHeadline(String headline) {
  30 + this.headline = headline;
  31 + }
  32 +
  33 + public String getMeasures() {
  34 + return measures;
  35 + }
  36 +
  37 + public void setMeasures(String measures) {
  38 + this.measures = measures;
  39 + }
  40 +
  41 + public String getConsequence() {
  42 + return consequence;
  43 + }
  44 +
  45 + public void setConsequence(String consequence) {
  46 + this.consequence = consequence;
  47 + }
  48 +
  49 + public String getProbability() {
  50 + return probability;
  51 + }
  52 +
  53 + public void setProbability(String probability) {
  54 + this.probability = probability;
  55 + }
  56 +
  57 +
  58 +
  59 + }
... ...
Risiko/app/src/main/res/layout/activity_evaluations.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent">
  7 +
  8 + <TextView
  9 + android:id="@+id/tv_nameOfActivity"
  10 + android:layout_width="wrap_content"
  11 + android:layout_height="wrap_content"
  12 + android:text="Overskrift på aktivitet"
  13 + android:textStyle="bold"
  14 + android:textSize="25dp"
  15 + app:layout_constraintLeft_toLeftOf="parent"
  16 + app:layout_constraintRight_toRightOf="parent"
  17 + app:layout_constraintTop_toTopOf="parent"
  18 + android:layout_marginTop="25dp"/>
  19 +
  20 + <Button
  21 + android:id="@+id/btn_add_new_evaluation"
  22 + android:layout_width="match_parent"
  23 + android:layout_height="wrap_content"
  24 + android:layout_marginHorizontal="25dp"
  25 + android:text="@string/add_evaluation"
  26 + app:layout_constraintLeft_toLeftOf="parent"
  27 + app:layout_constraintRight_toRightOf="parent"
  28 + app:layout_constraintTop_toBottomOf="@id/tv_nameOfActivity"/>
  29 +
  30 + <TextView
  31 + android:layout_width="wrap_content"
  32 + android:layout_height="wrap_content"
  33 + android:text="@string/all_evaluations"
  34 + android:textStyle="bold"
  35 + app:layout_constraintLeft_toLeftOf="parent"
  36 + app:layout_constraintRight_toRightOf="parent"
  37 + app:layout_constraintTop_toBottomOf="@id/btn_add_new_evaluation"/>
  38 +
  39 + <android.support.constraint.ConstraintLayout
  40 + android:layout_width="match_parent"
  41 + android:layout_height="match_parent"
  42 + android:layout_marginTop="120dp">
  43 +
  44 +
  45 + <android.support.v4.widget.SwipeRefreshLayout
  46 + xmlns:android="http://schemas.android.com/apk/res/android"
  47 + android:id="@+id/swiperefresh"
  48 + android:layout_width="match_parent"
  49 + android:layout_height="match_parent">
  50 +
  51 +
  52 + <LinearLayout
  53 + android:layout_width="match_parent"
  54 + android:layout_height="match_parent"
  55 + android:orientation="vertical">
  56 +
  57 + <ListView
  58 + android:id="@+id/lv_evaluations"
  59 + android:layout_margin="10dp"
  60 + android:layout_width="match_parent"
  61 + android:layout_height="match_parent">
  62 + </ListView>
  63 +
  64 + </LinearLayout>
  65 + </android.support.v4.widget.SwipeRefreshLayout>
  66 +
  67 + </android.support.constraint.ConstraintLayout>
  68 +
  69 +</android.support.constraint.ConstraintLayout>
  70 +
... ...
Risiko/app/src/main/res/layout/evaluationlist.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:layout_margin="20dp"
  6 + android:orientation="vertical">
  7 +
  8 + <LinearLayout
  9 + android:layout_width="match_parent"
  10 + android:layout_height="wrap_content"
  11 + android:orientation="horizontal">
  12 +
  13 +
  14 + <TextView
  15 + android:id="@+id/tv_headline"
  16 + android:layout_width="wrap_content"
  17 + android:layout_height="wrap_content"
  18 + android:layout_marginBottom="10dp"
  19 + android:text="Navn på vurdering"
  20 + android:textSize="20dp" />
  21 +
  22 + <ImageView
  23 + android:layout_width="35dp"
  24 + android:layout_height="35dp"
  25 + android:background="@drawable/ic_arrow_right" />
  26 +
  27 + </LinearLayout>
  28 +
  29 + <LinearLayout
  30 + android:layout_width="match_parent"
  31 + android:layout_height="wrap_content"
  32 + android:orientation="horizontal">
  33 +
  34 + <TextView
  35 + android:id="@+id/tv_probability"
  36 + android:layout_width="wrap_content"
  37 + android:layout_height="wrap_content"
  38 + android:text="@string/sannsynlighet" />
  39 +
  40 + <TextView
  41 + android:layout_width="wrap_content"
  42 + android:layout_height="wrap_content"
  43 + android:text=" , " />
  44 +
  45 +
  46 + <TextView
  47 + android:id="@+id/tv_consequence"
  48 + android:layout_width="wrap_content"
  49 + android:layout_height="wrap_content"
  50 + android:text="@string/konsekvens" />
  51 + </LinearLayout>
  52 +
  53 +</LinearLayout>
0 54 \ No newline at end of file
... ...
Risiko/app/src/main/res/values/strings.xml
1 1 <resources>
2 2 <string name="app_name">Risiko</string>
  3 + <string name="sannsynlighet">Sannsynlighet</string>
  4 + <string name="konsekvens">Konsekvens</string>
  5 + <string name="add_evaluation">Legg til vurdering +</string>
  6 + <string name="all_evaluations">Alle vurderinger:</string>
3 7 </resources>
... ...