Skip to content

Commit

Permalink
Implement the feed
Browse files Browse the repository at this point in the history
This commit was a few days coming
  • Loading branch information
19lmyers committed Dec 6, 2016
1 parent 3118406 commit 9a5a3ce
Show file tree
Hide file tree
Showing 23 changed files with 546 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<service
android:name=".bluetooth.BluetoothQuickTileService"
android:icon="@drawable/ic_bluetooth_searching_white_24dp"
android:label="Bluetooth Server"
android:label="ThunderScout Bluetooth Server"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/team980/thunderscout/ThunderScout.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void onCreate() { //This isn't why loading is slow
super.onCreate();
Log.d("THUNDERSCOUT", "Application.onCreate");

Log.d("THUNDERSCOUT", "Fetching shared prefences");
Log.d("THUNDERSCOUT", "Fetching shared preferences");
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
boolean runServer = sharedPref.getBoolean("enable_bt_server", false);

Expand All @@ -112,7 +112,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
Log.d("PREFLISTEN", "enabling BT server");
startService(new Intent(this, BluetoothServerService.class));
} else {
Log.d("PREFLISTEN", "enabling BT server");
Log.d("PREFLISTEN", "disabling BT server");
stopService(new Intent(this, BluetoothServerService.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ public void onStartListening() {
//TODO this should reflect error states better...
tile.setIcon(Icon.createWithResource(this,
R.drawable.ic_bluetooth_searching_white_24dp));
tile.setLabel("Bluetooth server is enabled"); //TODO be more concise
tile.setState(Tile.STATE_ACTIVE);
} else {
tile.setIcon(Icon.createWithResource(this,
R.drawable.ic_bluetooth_disabled_white_24dp));
tile.setLabel("Bluetooth server is disabled");
tile.setState(Tile.STATE_INACTIVE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

import com.team980.thunderscout.data.ScoutData;
import com.team980.thunderscout.data.task.ScoutDataWriteTask;
import com.team980.thunderscout.feed.EntryOperationWrapper;
import com.team980.thunderscout.feed.EntryOperationWrapper.EntryOperationStatus;
import com.team980.thunderscout.feed.EntryOperationWrapper.EntryOperationType;
import com.team980.thunderscout.feed.FeedEntry;
import com.team980.thunderscout.feed.task.FeedDataWriteTask;
import com.team980.thunderscout.util.TSNotificationBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -94,10 +99,15 @@ protected void onPostExecute(ScoutData o) {
if (o != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

FeedEntry feedEntry = new FeedEntry(FeedEntry.EntryType.SERVER_RECEIVED_MATCH, System.currentTimeMillis());

if (prefs.getBoolean("bt_send_to_local_storage", true)) {
//Put the fetched ScoutData in the local database
ScoutDataWriteTask writeTask = new ScoutDataWriteTask(o, context);
writeTask.execute();

feedEntry.addOperation(new EntryOperationWrapper(EntryOperationType.SAVED_TO_LOCAL_STORAGE,
EntryOperationStatus.OPERATION_SUCCESSFUL)); //TODO determine this based on callback?
}

if (prefs.getBoolean("bt_send_to_bt_server", false)) {
Expand All @@ -108,8 +118,11 @@ protected void onPostExecute(ScoutData o) {
SheetsUpdateTask task = new SheetsUpdateTask(context);
task.execute(o);
}*/

FeedDataWriteTask feedDataWriteTask = new FeedDataWriteTask(feedEntry, context);
feedDataWriteTask.execute();
} else {
Log.d("ServerConnectionTask", "Failed to start ScoutDataWriteTask!");
Log.d("ServerConnectionTask", "Failed to start FeedDataWriteTask!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ScoutData implements Serializable {
/**
* ScoutData Version 2
*/
private static final long serialVersionUID = 2;
private static final long serialVersionUID = 2; //TODO increment in 2017, or when data changes

public static final String SOURCE_LOCAL_DEVICE = "This device";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import android.provider.BaseColumns;

public final class ServerDataContract {
public final class ScoutDataContract {
// To prevent someone from accidentally instantiating the contract class,
// give it an empty constructor.
private ServerDataContract() {
private ScoutDataContract() {
}

/* Inner class that defines the table contents */
public static abstract class ScoutDataTable implements BaseColumns {
public static final String TABLE_NAME = "server_data";
public static final String TABLE_NAME = "scout_data";

public static final String COLUMN_NAME_TEAM_NUMBER = "team";
public static final String COLUMN_NAME_DATE_ADDED = "date_added";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import static com.team980.thunderscout.data.ServerDataContract.ScoutDataTable;
import static com.team980.thunderscout.data.ScoutDataContract.ScoutDataTable;

public class ServerDataDbHelper extends SQLiteOpenHelper {
public class ScoutDataDbHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
public static final int DATABASE_VERSION = 1;
public static final int DATABASE_VERSION = 2016; //Set this to the year of the game

public static final String DATABASE_NAME = "ThunderScout.db";
public static final String DATABASE_NAME = "ThunderScout_SCOUTDATA.db";

private static final String TEXT_TYPE = " TEXT";
private static final String FLOAT_TYPE = " REAL";
Expand Down Expand Up @@ -42,7 +42,7 @@ public class ServerDataDbHelper extends SQLiteOpenHelper {
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + ScoutDataTable.TABLE_NAME;

public ServerDataDbHelper(Context context) {
public ScoutDataDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import android.os.AsyncTask;
import android.widget.Toast;

import com.team980.thunderscout.data.ServerDataContract.ScoutDataTable;
import com.team980.thunderscout.data.ServerDataDbHelper;
import com.team980.thunderscout.data.ScoutDataContract.ScoutDataTable;
import com.team980.thunderscout.data.ScoutDataDbHelper;
import com.team980.thunderscout.info.LocalDataAdapter;

public class ScoutDataClearTask extends AsyncTask<Void, Integer, Void> {
Expand All @@ -28,7 +28,7 @@ protected void onPreExecute() {
@Override
public Void doInBackground(Void... params) {

SQLiteDatabase db = new ServerDataDbHelper(context).getWritableDatabase();
SQLiteDatabase db = new ScoutDataDbHelper(context).getWritableDatabase();

int rowsDeleted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import android.widget.Toast;

import com.team980.thunderscout.data.ScoutData;
import com.team980.thunderscout.data.ServerDataContract.ScoutDataTable;
import com.team980.thunderscout.data.ServerDataDbHelper;
import com.team980.thunderscout.data.ScoutDataContract.ScoutDataTable;
import com.team980.thunderscout.data.ScoutDataDbHelper;
import com.team980.thunderscout.info.LocalDataAdapter;
import com.team980.thunderscout.info.ThisDeviceFragment;

Expand Down Expand Up @@ -43,10 +43,9 @@ protected void onPreExecute() {
@Override
public Void doInBackground(Void... params) {

SQLiteDatabase db = new ServerDataDbHelper(context).getWritableDatabase();
SQLiteDatabase db = new ScoutDataDbHelper(context).getWritableDatabase();

StringBuilder where = new StringBuilder("date_added IN (");
//TODO build WHERE clause
for (ScoutData data : dataToDelete) {
where.append(data.getDateAdded()).append(",");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import com.team980.thunderscout.ThunderScout;
import com.team980.thunderscout.data.ScoutData;
import com.team980.thunderscout.data.ServerDataContract.ScoutDataTable;
import com.team980.thunderscout.data.ServerDataDbHelper;
import com.team980.thunderscout.data.ScoutDataContract.ScoutDataTable;
import com.team980.thunderscout.data.ScoutDataDbHelper;
import com.team980.thunderscout.data.enumeration.Defense;
import com.team980.thunderscout.data.enumeration.ScalingStats;
import com.team980.thunderscout.info.LocalDataAdapter;
Expand Down Expand Up @@ -59,7 +59,7 @@ public void run() {
@Override
public Void doInBackground(Void... params) {

SQLiteDatabase db = new ServerDataDbHelper(context).getReadableDatabase();
SQLiteDatabase db = new ScoutDataDbHelper(context).getReadableDatabase();

// Define a projection that specifies which columns from the database
// you will actually use after this query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import com.team980.thunderscout.ThunderScout;
import com.team980.thunderscout.data.ScoutData;
import com.team980.thunderscout.data.ServerDataContract;
import com.team980.thunderscout.data.ServerDataDbHelper;
import com.team980.thunderscout.data.ScoutDataContract;
import com.team980.thunderscout.data.ScoutDataDbHelper;
import com.team980.thunderscout.data.enumeration.ScalingStats;
import com.team980.thunderscout.info.ThisDeviceFragment;
import com.team980.thunderscout.match.ScoutingFlowActivity;
Expand Down Expand Up @@ -50,42 +50,42 @@ protected void onPreExecute() {
protected Void doInBackground(Void[] params) {

// Gets the data repository in write mode
SQLiteDatabase db = new ServerDataDbHelper(context).getWritableDatabase();
SQLiteDatabase db = new ScoutDataDbHelper(context).getWritableDatabase();

// Create a new map of values, where column names are the keys
ContentValues values = new ContentValues();

// Init
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_TEAM_NUMBER, data.getTeamNumber());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_DATE_ADDED, data.getDateAdded());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_DATA_SOURCE, data.getDataSource());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_TEAM_NUMBER, data.getTeamNumber());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_DATE_ADDED, data.getDateAdded());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_DATA_SOURCE, data.getDataSource());

// Auto
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_AUTO_DEFENSE_CROSSED, data.getAutoDefenseCrossed().toString());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_AUTO_DEFENSE_CROSSED, data.getAutoDefenseCrossed().toString());

values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_AUTO_LOW_GOALS, data.getAutoLowGoals());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_AUTO_HIGH_GOALS, data.getAutoHighGoals());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_AUTO_MISSED_GOALS, data.getAutoMissedGoals());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_AUTO_LOW_GOALS, data.getAutoLowGoals());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_AUTO_HIGH_GOALS, data.getAutoHighGoals());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_AUTO_MISSED_GOALS, data.getAutoMissedGoals());

// Teleop
byte[] listDefenseCrossings = ThunderScout.serializeObject(data.getTeleopDefenseCrossings());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_DEFENSE_CROSSINGS, listDefenseCrossings);
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_DEFENSE_CROSSINGS, listDefenseCrossings);

values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_LOW_GOALS, data.getTeleopLowGoals());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_HIGH_GOALS, data.getTeleopHighGoals());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_MISSED_GOALS, data.getTeleopMissedGoals());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_LOW_GOALS, data.getTeleopLowGoals());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_HIGH_GOALS, data.getTeleopHighGoals());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_TELEOP_MISSED_GOALS, data.getTeleopMissedGoals());

// Summary
ScalingStats scalingStats = data.getScalingStats();
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_SCALING_STATS, scalingStats.toString());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_CHALLENGED_TOWER, data.hasChallengedTower());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_TROUBLE_WITH, data.getTroubleWith());
values.put(ServerDataContract.ScoutDataTable.COLUMN_NAME_COMMENTS, data.getComments());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_SCALING_STATS, scalingStats.toString());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_CHALLENGED_TOWER, data.hasChallengedTower());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_TROUBLE_WITH, data.getTroubleWith());
values.put(ScoutDataContract.ScoutDataTable.COLUMN_NAME_COMMENTS, data.getComments());

try {
// Insert the new row
db.insertOrThrow(
ServerDataContract.ScoutDataTable.TABLE_NAME,
ScoutDataContract.ScoutDataTable.TABLE_NAME,
null,
values);
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,23 @@ public void addFeedEntry(FeedEntry entryToAdd) {
feedEntries.add(entryToAdd);
notifyParentItemInserted(feedEntries.lastIndexOf(entryToAdd)); //This makes sense

//TODO insert child list items?

Collections.sort(feedEntries); //sort by date
}

/**
* Removes all the entries from the list.
* Called when we delete things.
*/
public void clearEntries() {
if (feedEntries.size() == 0) {
//list is empty
return;
}

notifyParentItemRangeRemoved(0, feedEntries.size());
getParentItemList().removeAll(feedEntries);
}

public class FeedEntryViewHolder extends ParentViewHolder {

private ImageView icon;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.team980.thunderscout.feed;

import com.team980.thunderscout.R;
import com.team980.thunderscout.match.ScoutingFlowActivity;

import java.io.Serializable;

/**
* A wrapper for an operation
* Required for ExpandableRecyclerView ;/
*/
public class EntryOperationWrapper {
public class EntryOperationWrapper implements Serializable {
private EntryOperationType type;
private EntryOperationStatus status;

/**
* Serialization UID
*/
private static final long serialVersionUID = 1; //should never need to change this

public EntryOperationWrapper(EntryOperationType t, EntryOperationStatus s) {
type = t;
status = s;
Expand Down Expand Up @@ -43,6 +51,17 @@ public String toString() {
return name;
}

public static EntryOperationType fromOperationId(String operationId) {
switch (operationId) {
case ScoutingFlowActivity.OPERATION_SAVE_THIS_DEVICE:
return EntryOperationType.SAVED_TO_LOCAL_STORAGE;
case ScoutingFlowActivity.OPERATION_SEND_BLUETOOTH:
return EntryOperationType.SENT_TO_BLUETOOTH_SERVER;
default:
return null;
}
}

public int getIcon() {
return icon;
}
Expand All @@ -54,7 +73,7 @@ public int getIcon() {
public enum EntryOperationStatus {
OPERATION_SUCCESSFUL("Operation successful"), //success
OPERATION_FAILED("Operation failed"), //fail
OPERATION_ABORTED("Operation aborted by user"); //user canceled operation (NYI)
OPERATION_ABORTED("Operation failed and aborted by user"); //user cancelled operation after failure

private String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.team980.thunderscout.feed;

import android.provider.BaseColumns;

public final class FeedDataContract {
// To prevent someone from accidentally instantiating the contract class,
// give it an empty constructor.
private FeedDataContract() {
}

/* Inner class that defines the table contents */
public static abstract class FeedDataTable implements BaseColumns {
public static final String TABLE_NAME = "feed_data";

public static final String COLUMN_NAME_ENTRY_TYPE = "entry_type";
public static final String COLUMN_NAME_ENTRY_DATE = "entry_date";
public static final String COLUMN_NAME_ENTRY_OPERATIONS = "entry_operations";
}
}

Loading

0 comments on commit 9a5a3ce

Please sign in to comment.