Thomas Ross 3 years ago
parent
commit
7f90517617

+ 2
- 2
app/src/main/AndroidManifest.xml View File

@@ -14,9 +14,9 @@
14 14
                 <category android:name="android.intent.category.LAUNCHER"/>
15 15
             </intent-filter>
16 16
         </activity>
17
-        <activity android:name=".AddTeam"
17
+        <activity android:name=".views.AddTeam"
18 18
                   android:screenOrientation="portrait"/> // TODO: Don't do this!
19
-        <activity android:name=".EditTeam"
19
+        <activity android:name=".views.EditTeam"
20 20
                   android:screenOrientation="portrait"/> // TODO: Don't do this!
21 21
     </application>
22 22
 </manifest>

+ 5
- 0
app/src/main/java/io/thomasross/frcscout/GamesManager.java View File

@@ -57,4 +57,9 @@ public class GamesManager
57 57
         }
58 58
         return tasks;
59 59
     }
60
+
61
+    public static int getNumTasks()
62
+    {
63
+        return GamesManager.getTasks().size();
64
+    }
60 65
 }

+ 3
- 2
app/src/main/java/io/thomasross/frcscout/Main.java View File

@@ -18,6 +18,7 @@ import com.google.gson.reflect.TypeToken;
18 18
 import io.thomasross.frcscout.adapters.TeamListAdapter;
19 19
 import io.thomasross.frcscout.loaders.TeamLoader;
20 20
 import io.thomasross.frcscout.models.Team;
21
+import io.thomasross.frcscout.views.AddTeam;
21 22
 
22 23
 import java.lang.reflect.Type;
23 24
 import java.util.ArrayList;
@@ -124,7 +125,7 @@ public class Main extends AppCompatActivity implements LoaderManager.LoaderCallb
124 125
         {
125 126
             String tasksJSON = data.getString(2);
126 127
 
127
-            Type jsonType = new TypeToken<HashMap<String, Boolean>>(){}.getType();
128
+            Type jsonType = new TypeToken<HashMap<String, Boolean>>() {}.getType();
128 129
             Gson gson = new GsonBuilder().create();
129 130
             HashMap<String, Boolean> tasksMap = gson.fromJson(tasksJSON, jsonType);
130 131
 
@@ -143,7 +144,7 @@ public class Main extends AppCompatActivity implements LoaderManager.LoaderCallb
143 144
                 }
144 145
             }
145 146
 
146
-            Team team = new Team(data.getInt(0), data.getString(1), data.getString(2), data.getInt(3), numTasksAble, tasks.size());
147
+            Team team = new Team(data.getInt(0), data.getString(1), data.getString(2), data.getInt(3), numTasksAble);
147 148
             teams.add(team);
148 149
         }
149 150
 

+ 16
- 16
app/src/main/java/io/thomasross/frcscout/TeamsOpenHelper.java View File

@@ -18,18 +18,18 @@ public class TeamsOpenHelper extends SQLiteOpenHelper
18 18
     public void onCreate(SQLiteDatabase db)
19 19
     {
20 20
         db.execSQL("CREATE TABLE " + GamesManager.GAME_2016_TABLE_NAME + " (" +
21
-                "TEAMNUMBER INT NOT NULL, " +
22
-                "TEAMNAME TEXT, " +
23
-                "TASKS TEXT, " +
24
-                "AUTOPTS INT" +
25
-                ");");
21
+                   "TEAMNUMBER INT NOT NULL, " +
22
+                   "TEAMNAME TEXT, " +
23
+                   "TASKS TEXT, " +
24
+                   "AUTOPTS INT" +
25
+                   ");");
26 26
 
27 27
         db.execSQL("CREATE TABLE " + GamesManager.GAME_2017_TABLE_NAME + " (" +
28
-                "TEAMNUMBER INT NOT NULL, " +
29
-                "TEAMNAME TEXT, " +
30
-                "TASKS TEXT, " +
31
-                "AUTOPTS INT" +
32
-                ");");
28
+                   "TEAMNUMBER INT NOT NULL, " +
29
+                   "TEAMNAME TEXT, " +
30
+                   "TASKS TEXT, " +
31
+                   "AUTOPTS INT" +
32
+                   ");");
33 33
     }
34 34
 
35 35
     @Override
@@ -38,7 +38,7 @@ public class TeamsOpenHelper extends SQLiteOpenHelper
38 38
         if (oldVersion < 4)
39 39
         {
40 40
             db.execSQL("ALTER TABLE Teams " +
41
-                    "ADD COLUMN AUTOPTS INT;");
41
+                       "ADD COLUMN AUTOPTS INT;");
42 42
         }
43 43
 
44 44
         if (oldVersion == 4 && newVersion == 5)
@@ -46,11 +46,11 @@ public class TeamsOpenHelper extends SQLiteOpenHelper
46 46
             db.execSQL("ALTER TABLE Teams RENAME TO " + GamesManager.GAME_2016_TABLE_NAME);
47 47
 
48 48
             db.execSQL("CREATE TABLE " + GamesManager.GAME_2017_TABLE_NAME + " (" +
49
-                    "TEAMNUMBER INT NOT NULL, " +
50
-                    "TEAMNAME TEXT, " +
51
-                    "TASKS TEXT, " +
52
-                    "AUTOPTS INT" +
53
-                    ");");
49
+                       "TEAMNUMBER INT NOT NULL, " +
50
+                       "TEAMNAME TEXT, " +
51
+                       "TASKS TEXT, " +
52
+                       "AUTOPTS INT" +
53
+                       ");");
54 54
         }
55 55
     }
56 56
 }

+ 6
- 4
app/src/main/java/io/thomasross/frcscout/adapters/TaskListAdapter.java View File

@@ -1,6 +1,7 @@
1 1
 package io.thomasross.frcscout.adapters;
2 2
 
3 3
 import android.content.Context;
4
+import android.support.annotation.NonNull;
4 5
 import android.view.LayoutInflater;
5 6
 import android.view.View;
6 7
 import android.view.ViewGroup;
@@ -32,8 +33,9 @@ public class TaskListAdapter extends ArrayAdapter<Task>
32 33
         CheckBox able;
33 34
     }
34 35
 
36
+    @NonNull
35 37
     @Override
36
-    public View getView(int position, View convertView, ViewGroup parent)
38
+    public View getView(int position, View convertView, @NonNull ViewGroup parent)
37 39
     {
38 40
         ViewHolder holder;
39 41
 
@@ -53,7 +55,7 @@ public class TaskListAdapter extends ArrayAdapter<Task>
53 55
                 {
54 56
                     CheckBox checkBox = (CheckBox) v;
55 57
                     Task task = (Task) v.getTag();
56
-                    task.isTeamAble = checkBox.isChecked();
58
+                    task.setTeamAble(checkBox.isChecked());
57 59
                 }
58 60
             });
59 61
         }
@@ -63,8 +65,8 @@ public class TaskListAdapter extends ArrayAdapter<Task>
63 65
         }
64 66
 
65 67
         Task task = taskList.get(position);
66
-        holder.able.setChecked(task.isTeamAble);
67
-        holder.able.setText(task.name);
68
+        holder.able.setChecked(task.isTeamAble());
69
+        holder.able.setText(task.getName());
68 70
         holder.able.setTag(task);
69 71
 
70 72
         return convertView;

+ 12
- 6
app/src/main/java/io/thomasross/frcscout/adapters/TeamListAdapter.java View File

@@ -4,12 +4,14 @@ import android.annotation.SuppressLint;
4 4
 import android.content.Context;
5 5
 import android.content.Intent;
6 6
 import android.net.Uri;
7
+import android.support.annotation.NonNull;
7 8
 import android.view.LayoutInflater;
8 9
 import android.view.MenuItem;
9 10
 import android.view.View;
10 11
 import android.view.ViewGroup;
11 12
 import android.widget.*;
12
-import io.thomasross.frcscout.EditTeam;
13
+import io.thomasross.frcscout.views.EditTeam;
14
+import io.thomasross.frcscout.GamesManager;
13 15
 import io.thomasross.frcscout.R;
14 16
 import io.thomasross.frcscout.models.Team;
15 17
 
@@ -38,9 +40,10 @@ public class TeamListAdapter extends ArrayAdapter<Team>
38 40
         this.context = context;
39 41
     }
40 42
 
43
+    @NonNull
41 44
     @SuppressLint("DefaultLocale")
42 45
     @Override
43
-    public View getView(int position, View convertView, ViewGroup parent)
46
+    public View getView(int position, View convertView, @NonNull ViewGroup parent)
44 47
     {
45 48
         final ViewHolder holder;
46 49
         final Team team = teams.get(position);
@@ -62,7 +65,7 @@ public class TeamListAdapter extends ArrayAdapter<Team>
62 65
                 public void onClick(View v)
63 66
                 {
64 67
                     Intent intent = new Intent(context, EditTeam.class);
65
-                    intent.putExtra("io.thomasross.frcscout.teamnumber", team.number);
68
+                    intent.putExtra("io.thomasross.frcscout.teamnumber", team.getNumber());
66 69
                     context.startActivity(intent);
67 70
                 }
68 71
             });
@@ -81,7 +84,8 @@ public class TeamListAdapter extends ArrayAdapter<Team>
81 84
                         @Override
82 85
                         public boolean onMenuItemClick(MenuItem item)
83 86
                         {
84
-                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.thebluealliance.com/team/" + team.number));
87
+                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(
88
+                                    "https://www.thebluealliance.com/team/" + team.getNumber()));
85 89
                             context.startActivity(intent);
86 90
                             return false;
87 91
                         }
@@ -96,8 +100,10 @@ public class TeamListAdapter extends ArrayAdapter<Team>
96 100
             holder = (ViewHolder) convertView.getTag();
97 101
         }
98 102
 
99
-        holder.namenum.setText(String.format("%d - %s", team.number, team.name));
100
-        holder.stats.setText(String.format("%d/%d tasks, %d auto points", team.canDoTasks, team.totalTasks, team.autoPoints));
103
+        holder.namenum.setText(String.format("%d - %s", team.getNumber(), team.getName()));
104
+        holder.stats.setText(
105
+                String.format("%d/%d tasks, %d auto points", team.getCanDoTasks(), GamesManager.getNumTasks(),
106
+                              team.getAutoPoints()));
101 107
 
102 108
         return convertView;
103 109
     }

+ 33
- 3
app/src/main/java/io/thomasross/frcscout/models/Task.java View File

@@ -2,9 +2,9 @@ package io.thomasross.frcscout.models;
2 2
 
3 3
 public class Task
4 4
 {
5
-    public String code;
6
-    public String name;
7
-    public boolean isTeamAble;
5
+    private String code;
6
+    private String name;
7
+    private boolean isTeamAble;
8 8
 
9 9
     public Task(String code, String name, boolean isTeamAble)
10 10
     {
@@ -12,4 +12,34 @@ public class Task
12 12
         this.name = name;
13 13
         this.isTeamAble = isTeamAble;
14 14
     }
15
+
16
+    public String getCode()
17
+    {
18
+        return code;
19
+    }
20
+
21
+    public void setCode(String code)
22
+    {
23
+        this.code = code;
24
+    }
25
+
26
+    public String getName()
27
+    {
28
+        return name;
29
+    }
30
+
31
+    public void setName(String name)
32
+    {
33
+        this.name = name;
34
+    }
35
+
36
+    public boolean isTeamAble()
37
+    {
38
+        return isTeamAble;
39
+    }
40
+
41
+    public void setTeamAble(boolean teamAble)
42
+    {
43
+        isTeamAble = teamAble;
44
+    }
15 45
 }

+ 56
- 8
app/src/main/java/io/thomasross/frcscout/models/Team.java View File

@@ -2,13 +2,12 @@ package io.thomasross.frcscout.models;
2 2
 
3 3
 public class Team
4 4
 {
5
-    public int number;
6
-    public String name;
7
-    public String tasks;
8
-    public int autoPoints;
5
+    private int number;
6
+    private String name;
7
+    private String tasks;
8
+    private int autoPoints;
9 9
 
10
-    public int canDoTasks;
11
-    public int totalTasks;
10
+    private int canDoTasks;
12 11
 
13 12
     public Team(int number, String name, String tasks, int autoPoints)
14 13
     {
@@ -18,13 +17,62 @@ public class Team
18 17
         this.autoPoints = autoPoints;
19 18
     }
20 19
 
21
-    public Team(int number, String name, String tasks, int autoPoints, int canDoTasks, int totalTasks)
20
+    public Team(int number, String name, String tasks, int autoPoints, int canDoTasks)
22 21
     {
23 22
         this.number = number;
24 23
         this.name = name;
25 24
         this.tasks = tasks;
26 25
         this.autoPoints = autoPoints;
27 26
         this.canDoTasks = canDoTasks;
28
-        this.totalTasks = totalTasks;
27
+    }
28
+
29
+    public int getNumber()
30
+    {
31
+        return number;
32
+    }
33
+
34
+    public void setNumber(int number)
35
+    {
36
+        this.number = number;
37
+    }
38
+
39
+    public String getName()
40
+    {
41
+        return name;
42
+    }
43
+
44
+    public void setName(String name)
45
+    {
46
+        this.name = name;
47
+    }
48
+
49
+    public String getTasks()
50
+    {
51
+        return tasks;
52
+    }
53
+
54
+    public void setTasks(String tasks)
55
+    {
56
+        this.tasks = tasks;
57
+    }
58
+
59
+    public int getAutoPoints()
60
+    {
61
+        return autoPoints;
62
+    }
63
+
64
+    public void setAutoPoints(int autoPoints)
65
+    {
66
+        this.autoPoints = autoPoints;
67
+    }
68
+
69
+    public int getCanDoTasks()
70
+    {
71
+        return canDoTasks;
72
+    }
73
+
74
+    public void setCanDoTasks(int canDoTasks)
75
+    {
76
+        this.canDoTasks = canDoTasks;
29 77
     }
30 78
 }

+ 4
- 4
app/src/main/java/io/thomasross/frcscout/tasks/InsertTeamTask.java View File

@@ -47,10 +47,10 @@ public class InsertTeamTask extends AsyncTask<Team, Void, Void>
47 47
         for (Team team : teams)
48 48
         {
49 49
             ContentValues values = new ContentValues();
50
-            values.put("TEAMNUMBER", team.number);
51
-            values.put("TEAMNAME", team.name);
52
-            values.put("TASKS", team.tasks);
53
-            values.put("AUTOPTS", team.autoPoints);
50
+            values.put("TEAMNUMBER", team.getNumber());
51
+            values.put("TEAMNAME", team.getName());
52
+            values.put("TASKS", team.getTasks());
53
+            values.put("AUTOPTS", team.getAutoPoints());
54 54
             writeableDB.insert(GamesManager.getCurrentTableName(), null, values);
55 55
         }
56 56
 

+ 4
- 4
app/src/main/java/io/thomasross/frcscout/tasks/UpdateTeamTask.java View File

@@ -47,10 +47,10 @@ public class UpdateTeamTask extends AsyncTask<Team, Void, Void>
47 47
         for (Team team : params)
48 48
         {
49 49
             ContentValues values = new ContentValues();
50
-            values.put("TEAMNAME", team.name);
51
-            values.put("TASKS", team.tasks);
52
-            values.put("AUTOPTS", team.autoPoints);
53
-            String[] whereArgs = {"" + team.number};
50
+            values.put("TEAMNAME", team.getName());
51
+            values.put("TASKS", team.getTasks());
52
+            values.put("AUTOPTS", team.getAutoPoints());
53
+            String[] whereArgs = {"" + team.getNumber()};
54 54
             writeableDB.update(GamesManager.getCurrentTableName(), values, "TEAMNUMBER = ?", whereArgs);
55 55
         }
56 56
 

app/src/main/java/io/thomasross/frcscout/AddTeam.java → app/src/main/java/io/thomasross/frcscout/views/AddTeam.java View File

@@ -1,4 +1,4 @@
1
-package io.thomasross.frcscout;
1
+package io.thomasross.frcscout.views;
2 2
 
3 3
 import android.os.Bundle;
4 4
 import android.support.v7.app.AppCompatActivity;
@@ -6,6 +6,8 @@ import android.view.Menu;
6 6
 import android.view.MenuItem;
7 7
 import android.widget.EditText;
8 8
 import android.widget.Toast;
9
+import io.thomasross.frcscout.FinishedCallback;
10
+import io.thomasross.frcscout.R;
9 11
 import io.thomasross.frcscout.models.Team;
10 12
 import io.thomasross.frcscout.tasks.InsertTeamTask;
11 13
 

app/src/main/java/io/thomasross/frcscout/EditTeam.java → app/src/main/java/io/thomasross/frcscout/views/EditTeam.java View File

@@ -1,4 +1,4 @@
1
-package io.thomasross.frcscout;
1
+package io.thomasross.frcscout.views;
2 2
 
3 3
 import android.app.AlertDialog;
4 4
 import android.app.LoaderManager;
@@ -13,6 +13,9 @@ import android.widget.*;
13 13
 import com.google.gson.Gson;
14 14
 import com.google.gson.GsonBuilder;
15 15
 import com.google.gson.reflect.TypeToken;
16
+import io.thomasross.frcscout.FinishedCallback;
17
+import io.thomasross.frcscout.GamesManager;
18
+import io.thomasross.frcscout.R;
16 19
 import io.thomasross.frcscout.adapters.TaskListAdapter;
17 20
 import io.thomasross.frcscout.loaders.TeamLoader;
18 21
 import io.thomasross.frcscout.models.Task;
@@ -23,11 +26,12 @@ import io.thomasross.frcscout.tasks.UpdateTeamTask;
23 26
 import java.lang.reflect.Type;
24 27
 import java.util.ArrayList;
25 28
 import java.util.HashMap;
29
+import java.util.Locale;
26 30
 
27
-public class EditTeam extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor>,FinishedCallback
31
+public class EditTeam extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor>, FinishedCallback
28 32
 {
29
-    int teamNumber;
30
-    TaskListAdapter tasksListAdapter;
33
+    private int teamNumber;
34
+    private TaskListAdapter tasksListAdapter;
31 35
 
32 36
     @Override
33 37
     public void onCreate(Bundle savedInstanceState)
@@ -84,7 +88,7 @@ public class EditTeam extends AppCompatActivity implements LoaderManager.LoaderC
84 88
         HashMap<String, Boolean> tasksMap = new HashMap<>();
85 89
         for (Task task : tasks)
86 90
         {
87
-            tasksMap.put(task.code, task.isTeamAble);
91
+            tasksMap.put(task.getCode(), task.isTeamAble());
88 92
         }
89 93
 
90 94
         Gson gson = new GsonBuilder().create();
@@ -136,8 +140,6 @@ public class EditTeam extends AppCompatActivity implements LoaderManager.LoaderC
136 140
         return new TeamLoader(this, null, where, whereArgs);
137 141
     }
138 142
 
139
-
140
-
141 143
     @Override
142 144
     public void onLoadFinished(Loader<Cursor> loader, Cursor data)
143 145
     {
@@ -149,13 +151,13 @@ public class EditTeam extends AppCompatActivity implements LoaderManager.LoaderC
149 151
             EditText teamNameET = (EditText) findViewById(R.id.teamname_edit_ET);
150 152
             EditText autoPointsET = (EditText) findViewById(R.id.autonomouspoints_edit_ET);
151 153
 
152
-            teamNumberET.setText("" + data.getInt(0));
154
+            teamNumberET.setText(String.format(Locale.US, "%d", data.getInt(0)));
153 155
             teamNameET.setText(data.getString(1));
154
-            autoPointsET.setText("" + data.getInt(3));
156
+            autoPointsET.setText(String.format(Locale.US, "%d", data.getInt(3)));
155 157
 
156 158
             String tasksJSON = data.getString(2);
157 159
 
158
-            Type jsonType = new TypeToken<HashMap<String, Boolean>>(){}.getType();
160
+            Type jsonType = new TypeToken<HashMap<String, Boolean>>() {}.getType();
159 161
             Gson gson = new GsonBuilder().create();
160 162
             HashMap<String, Boolean> tasksMap = gson.fromJson(tasksJSON, jsonType);
161 163