Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display pending updates in the status messages #372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions app/src/main/java/org/traccar/client/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
Expand All @@ -27,8 +28,10 @@

public class DatabaseHelper extends SQLiteOpenHelper {

public static final int DATABASE_VERSION = 3;
public static final String DATABASE_NAME = "traccar.db";
private static final int DATABASE_VERSION = 3;
private static final String DATABASE_NAME = "traccar.db";
private static final String TABLE_NAME = "position";
private static final String DROP_QUERY = "DROP TABLE IF EXISTS " + TABLE_NAME + ";";

public interface DatabaseHandler<T> {
void onComplete(boolean success, T result);
Expand All @@ -39,7 +42,7 @@ private static abstract class DatabaseAsyncTask<T> extends AsyncTask<Void, Void,
private DatabaseHandler<T> handler;
private RuntimeException error;

public DatabaseAsyncTask(DatabaseHandler<T> handler) {
DatabaseAsyncTask(DatabaseHandler<T> handler) {
this.handler = handler;
}

Expand Down Expand Up @@ -70,7 +73,7 @@ public DatabaseHelper(Context context) {

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE position (" +
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"deviceId TEXT," +
"time INTEGER," +
Expand All @@ -86,12 +89,12 @@ public void onCreate(SQLiteDatabase db) {

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS position;");
db.execSQL(DROP_QUERY);
onCreate(db);
}

public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS position;");
db.execSQL(DROP_QUERY);
onCreate(db);
}

Expand All @@ -108,7 +111,7 @@ public void insertPosition(Position position) {
values.put("battery", position.getBattery());
values.put("mock", position.getMock() ? 1 : 0);

db.insertOrThrow("position", null, values);
db.insertOrThrow(TABLE_NAME, null, values);
}

public void insertPositionAsync(final Position position, DatabaseHandler<Void> handler) {
Expand All @@ -124,7 +127,7 @@ protected Void executeMethod() {
public Position selectPosition() {
Position position = new Position();

Cursor cursor = db.rawQuery("SELECT * FROM position ORDER BY id LIMIT 1", null);
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " ORDER BY id LIMIT 1", null);
try {
if (cursor.getCount() > 0) {

Expand Down Expand Up @@ -162,7 +165,7 @@ protected Position executeMethod() {
}

public void deletePosition(long id) {
if (db.delete("position", "id = ?", new String[] { String.valueOf(id) }) != 1) {
if (db.delete(TABLE_NAME, "id = ?", new String[] { String.valueOf(id) }) != 1) {
throw new SQLException();
}
}
Expand All @@ -177,4 +180,8 @@ protected Void executeMethod() {
}.execute();
}

public long getLocationsCount() {
return DatabaseUtils.queryNumEntries(db, TABLE_NAME);
}

}
7 changes: 6 additions & 1 deletion app/src/main/java/org/traccar/client/TrackingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ public void stop() {

@Override
public void onPositionUpdate(Position position) {
StatusActivity.addMessage(context.getString(R.string.status_location_update));
if (position != null) {
write(position);
long count = databaseHelper.getLocationsCount();
if (count > 0) {
StatusActivity.addMessage(context.getString(R.string.status_location_update) + " (" + count + ")");
} else {
StatusActivity.addMessage(context.getString(R.string.status_location_update));
}
}
}

Expand Down