Skip to content

Commit

Permalink
Issue #88 #47 - Implements the the editing of the track details durin…
Browse files Browse the repository at this point in the history
…g the finalization
  • Loading branch information
GrazianoCapelli committed Apr 24, 2021
1 parent 02541e2 commit 84b20c2
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
class DatabaseHandler extends SQLiteOpenHelper {

// All Static variables

// Database Version
private static final int DATABASE_VERSION = 2; // Updated to 2 in v2.1.3 (code 14)
// Updated to 2 in v2.1.3 (version code 14)
// Updated to 3 in v3.0.0 (version code 38)
private static final int DATABASE_VERSION = 3;

private static final int LOCATION_TYPE_LOCATION = 1;
private static final int LOCATION_TYPE_PLACEMARK = 2;

Expand Down Expand Up @@ -128,6 +132,7 @@ class DatabaseHandler extends SQLiteOpenHelper {
private static final String KEY_TRACK_TYPE = "type";

private static final String KEY_TRACK_VALIDMAP = "validmap";
private static final String KEY_TRACK_DESCRIPTION = "description";



Expand Down Expand Up @@ -179,7 +184,8 @@ public void onCreate(SQLiteDatabase db) {
+ KEY_TRACK_NUMBEROFLOCATIONS + " INTEGER," // 37
+ KEY_TRACK_NUMBEROFPLACEMARKS + " INTEGER," // 38
+ KEY_TRACK_VALIDMAP + " INTEGER," // 39
+ KEY_TRACK_TYPE + " INTEGER " + ")"; // 40
+ KEY_TRACK_TYPE + " INTEGER," // 40
+ KEY_TRACK_DESCRIPTION + " TEXT" + ")"; // 41
db.execSQL(CREATE_TRACKS_TABLE);

String CREATE_LOCATIONS_TABLE = "CREATE TABLE " + TABLE_LOCATIONS + "("
Expand Down Expand Up @@ -220,6 +226,8 @@ public void onCreate(SQLiteDatabase db) {
+ TABLE_LOCATIONS + " ADD COLUMN " + KEY_LOCATION_NUMBEROFSATELLITESUSEDINFIX + " INTEGER DEFAULT " + NOT_AVAILABLE + ";";
private static final String DATABASE_ALTER_TABLE_PLACEMARKS_TO_V2 = "ALTER TABLE "
+ TABLE_PLACEMARKS + " ADD COLUMN " + KEY_LOCATION_NUMBEROFSATELLITESUSEDINFIX + " INTEGER DEFAULT " + NOT_AVAILABLE + ";";
private static final String DATABASE_ALTER_TABLE_TRACKS_TO_V3 = "ALTER TABLE "
+ TABLE_TRACKS + " ADD COLUMN " + KEY_TRACK_DESCRIPTION + " TEXT DEFAULT \"\";";

// Upgrading database
@Override
Expand All @@ -242,9 +250,10 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//Log.w("myApp", "[#] DatabaseHandler.java - onUpgrade: from version 1 to 2 ...");
db.execSQL(DATABASE_ALTER_TABLE_LOCATIONS_TO_V2);
db.execSQL(DATABASE_ALTER_TABLE_PLACEMARKS_TO_V2);
//case 2:
case 2:
//upgrade from version 2 to 3
// db.execSQL(DATABASE_ALTER_TEAM_TO_V3);
//Log.w("myApp", "[#] DatabaseHandler.java - onUpgrade: from version 2 to 3 ...");
db.execSQL(DATABASE_ALTER_TABLE_TRACKS_TO_V3);

//and so on.. do not add breaks so that switch will
//start at oldVersion, and run straight through to the latest
Expand All @@ -254,6 +263,81 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

// ----------------------------------------------------------------------- LOCATIONS AND PLACEMARKS


// Add new Location and update the corresponding track
public void updateTrack(Track track) {
SQLiteDatabase db = this.getWritableDatabase();

ContentValues trkvalues = new ContentValues();
trkvalues.put(KEY_TRACK_NAME, track.getName());

trkvalues.put(KEY_TRACK_FROM, "");
trkvalues.put(KEY_TRACK_TO, "");

trkvalues.put(KEY_TRACK_START_LATITUDE, track.getStart_Latitude());
trkvalues.put(KEY_TRACK_START_LONGITUDE, track.getStart_Longitude());
trkvalues.put(KEY_TRACK_START_ALTITUDE, track.getStart_Altitude());
trkvalues.put(KEY_TRACK_START_ACCURACY, track.getStart_Accuracy());
trkvalues.put(KEY_TRACK_START_SPEED, track.getStart_Speed());
trkvalues.put(KEY_TRACK_START_TIME, track.getStart_Time());

trkvalues.put(KEY_TRACK_LASTFIX_TIME, track.getLastFix_Time());

trkvalues.put(KEY_TRACK_END_LATITUDE, track.getEnd_Latitude());
trkvalues.put(KEY_TRACK_END_LONGITUDE, track.getEnd_Longitude());
trkvalues.put(KEY_TRACK_END_ALTITUDE, track.getEnd_Altitude());
trkvalues.put(KEY_TRACK_END_ACCURACY, track.getEnd_Accuracy());
trkvalues.put(KEY_TRACK_END_SPEED, track.getEnd_Speed());
trkvalues.put(KEY_TRACK_END_TIME, track.getEnd_Time());

trkvalues.put(KEY_TRACK_LASTSTEPDST_LATITUDE, track.getLastStepDistance_Latitude());
trkvalues.put(KEY_TRACK_LASTSTEPDST_LONGITUDE, track.getLastStepDistance_Longitude());
trkvalues.put(KEY_TRACK_LASTSTEPDST_ACCURACY, track.getLastStepDistance_Accuracy());

trkvalues.put(KEY_TRACK_LASTSTEPALT_ALTITUDE, track.getLastStepAltitude_Altitude());
trkvalues.put(KEY_TRACK_LASTSTEPALT_ACCURACY, track.getLastStepAltitude_Accuracy());

trkvalues.put(KEY_TRACK_MIN_LATITUDE, track.getMin_Latitude());
trkvalues.put(KEY_TRACK_MIN_LONGITUDE, track.getMin_Longitude());

trkvalues.put(KEY_TRACK_MAX_LATITUDE, track.getMax_Latitude());
trkvalues.put(KEY_TRACK_MAX_LONGITUDE, track.getMax_Longitude());

trkvalues.put(KEY_TRACK_DURATION, track.getDuration());
trkvalues.put(KEY_TRACK_DURATION_MOVING, track.getDuration_Moving());

trkvalues.put(KEY_TRACK_DISTANCE, track.getDistance());
trkvalues.put(KEY_TRACK_DISTANCE_INPROGRESS, track.getDistanceInProgress());
trkvalues.put(KEY_TRACK_DISTANCE_LASTALTITUDE, track.getDistanceLastAltitude());

trkvalues.put(KEY_TRACK_ALTITUDE_UP, track.getAltitude_Up());
trkvalues.put(KEY_TRACK_ALTITUDE_DOWN, track.getAltitude_Down());
trkvalues.put(KEY_TRACK_ALTITUDE_INPROGRESS, track.getAltitude_InProgress());

trkvalues.put(KEY_TRACK_SPEED_MAX, track.getSpeedMax());
trkvalues.put(KEY_TRACK_SPEED_AVERAGE, track.getSpeedAverage());
trkvalues.put(KEY_TRACK_SPEED_AVERAGEMOVING, track.getSpeedAverageMoving());

trkvalues.put(KEY_TRACK_NUMBEROFLOCATIONS, track.getNumberOfLocations());
trkvalues.put(KEY_TRACK_NUMBEROFPLACEMARKS, track.getNumberOfPlacemarks());
trkvalues.put(KEY_TRACK_TYPE, track.getType());

trkvalues.put(KEY_TRACK_VALIDMAP, track.getValidMap());
trkvalues.put(KEY_TRACK_DESCRIPTION, track.getDescription());

try {
db.beginTransaction();
db.update(TABLE_TRACKS, trkvalues, KEY_ID + " = ?",
new String[] { String.valueOf(track.getId()) }); // Update the corresponding Track
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}

//Log.w("myApp", "[#] DatabaseHandler.java - addLocation: Location " + track.getNumberOfLocations() + " added into track " + track.getID());
}


// Add new Location and update the corresponding track
public void addLocationToTrack(LocationExtended location, Track track) {
SQLiteDatabase db = this.getWritableDatabase();
Expand All @@ -276,6 +360,7 @@ public void addLocationToTrack(LocationExtended location, Track track) {

ContentValues trkvalues = new ContentValues();
trkvalues.put(KEY_TRACK_NAME, track.getName());

trkvalues.put(KEY_TRACK_FROM, "");
trkvalues.put(KEY_TRACK_TO, "");

Expand Down Expand Up @@ -328,6 +413,7 @@ public void addLocationToTrack(LocationExtended location, Track track) {
trkvalues.put(KEY_TRACK_TYPE, track.getType());

trkvalues.put(KEY_TRACK_VALIDMAP, track.getValidMap());
trkvalues.put(KEY_TRACK_DESCRIPTION, track.getDescription());

try {
db.beginTransaction();
Expand Down Expand Up @@ -418,6 +504,7 @@ public void addPlacemarkToTrack(LocationExtended placemark, Track track) {
trkvalues.put(KEY_TRACK_TYPE, track.getType());

trkvalues.put(KEY_TRACK_VALIDMAP, track.getValidMap());
trkvalues.put(KEY_TRACK_DESCRIPTION, track.getDescription());

try {
db.beginTransaction();
Expand Down Expand Up @@ -770,6 +857,7 @@ public long addTrack(Track track) {
trkvalues.put(KEY_TRACK_TYPE, track.getType());

trkvalues.put(KEY_TRACK_VALIDMAP, track.getValidMap());
trkvalues.put(KEY_TRACK_DESCRIPTION, track.getDescription());

long TrackID;
// Inserting Row
Expand Down Expand Up @@ -851,7 +939,8 @@ public Track getTrack(long TrackID) {
cursor.getLong(38),

cursor.getInt(39),
cursor.getInt(40));
cursor.getInt(40),
cursor.getString(41));
}
cursor.close();
}
Expand Down Expand Up @@ -961,7 +1050,8 @@ public List<Track> getTracksList(long startNumber, long endNumber) {
cursor.getLong(38),

cursor.getInt(39),
cursor.getInt(40));
cursor.getInt(40),
cursor.getString(41));

trackList.add(trk); // Add Track to list
} while (cursor.moveToNext());
Expand Down Expand Up @@ -1106,7 +1196,8 @@ public List<Track> getTracksList() {
cursor.getLong(38),
cursor.getInt(39),
cursor.getInt(40));
cursor.getInt(40),
cursor.getString(41));
trackList.add(trk); // Add Track to list
} while (cursor.moveToNext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ public void onPause() {
public void onToggleRecord() {
if (isAdded()) {
if (!gpsApplication.getBottomBarLocked()) {
final boolean grs = gpsApplication.getRecording();
boolean newRecordingState = !grs;
gpsApplication.setRecording(newRecordingState);
EventBus.getDefault().post(EventBusMSG.UPDATE_TRACK);

if (newRecordingState) setButtonToClickedState(TVRecordButton, R.drawable.ic_pause_24, R.string.pause);
else setButtonToNormalState(TVRecordButton, R.drawable.ic_record_24, R.string.record);
if (!gpsApplication.getStopFlag()) {
final boolean grs = gpsApplication.getRecording();
boolean newRecordingState = !grs;
gpsApplication.setRecording(newRecordingState);
EventBus.getDefault().post(EventBusMSG.UPDATE_TRACK);

if (newRecordingState)
setButtonToClickedState(TVRecordButton, R.drawable.ic_pause_24, R.string.pause);
else
setButtonToNormalState(TVRecordButton, R.drawable.ic_record_24, R.string.record);
}
} else {
EventBus.getDefault().post(EventBusMSG.TOAST_BOTTOM_BAR_LOCKED);
}
Expand All @@ -148,14 +152,15 @@ public void onToggleRecord() {
public void onRequestAnnotation() {
if (isAdded()) {
if (!gpsApplication.getBottomBarLocked()) {
final boolean pr = gpsApplication.getPlacemarkRequest();
boolean newPlacemarkRequestState = !pr;
gpsApplication.setPlacemarkRequest(newPlacemarkRequestState);

if (newPlacemarkRequestState) setButtonToClickedState(TVAnnotateButton, 0, 0);
else setButtonToNormalState(TVAnnotateButton, 0, 0);
if (!gpsApplication.getStopFlag()) {
final boolean pr = gpsApplication.getPlacemarkRequest();
boolean newPlacemarkRequestState = !pr;
gpsApplication.setPlacemarkRequest(newPlacemarkRequestState);

} else {
if (newPlacemarkRequestState) setButtonToClickedState(TVAnnotateButton, 0, 0);
else setButtonToNormalState(TVAnnotateButton, 0, 0);
}
} else {
EventBus.getDefault().post(EventBusMSG.TOAST_BOTTOM_BAR_LOCKED);
}
}
Expand All @@ -166,11 +171,19 @@ public void onRequestStop() {
if (isAdded()) {
if (!gpsApplication.getBottomBarLocked()) {
if (!gpsApplication.getStopFlag()) {
gpsApplication.setStopFlag(true);
setButtonToClickedState(TVStopButton, 0, 0);
gpsApplication.setStopFlag(true);
gpsApplication.setRecording(false);
gpsApplication.setPlacemarkRequest(false);
EventBus.getDefault().post(EventBusMSG.UPDATE_TRACK);

//gpsApplication.setTrackToEdit(gpsApplication.getCurrentTrack());

FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTrackPropertiesDialog tpDialog = new FragmentTrackPropertiesDialog();
tpDialog.setTrackToEdit(gpsApplication.getCurrentTrack());
tpDialog.setTitleResource(R.string.finalize_track);
tpDialog.setIsAFinalization(true);
tpDialog.show(fm, "");
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,67 @@
package eu.basicairdata.graziano.gpslogger;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;

import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;

import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;

import static eu.basicairdata.graziano.gpslogger.GPSApplication.NOT_AVAILABLE;

public class FragmentTrackPropertiesDialog extends DialogFragment {

EditText DescEditText;
private EditText DescEditText;
private ImageView[] tracktypeImageView = new ImageView[7];
private int selectedTrackType = NOT_AVAILABLE; // The track type selected by the user
private Track _trackToEdit = null; // The track to edit
private int _title = 0; // The resource id for the title
private boolean _isAFinalization = false; // True if the "OK" button finalize the track and creates a new one


public void setTrackToEdit(Track trackToEdit) {
_trackToEdit = trackToEdit;
}


public void setTitleResource(int titleResource) {
_title = titleResource;
}


public void setIsAFinalization(boolean isAFinalization) {
_isAFinalization = isAFinalization;
}


//@SuppressLint("InflateParams")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder createPlacemarkAlert = new AlertDialog.Builder(getActivity());
createPlacemarkAlert.setTitle(R.string.finalize_track);
if (_title != 0) createPlacemarkAlert.setTitle(_title);
//createPlacemarkAlert.setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_stop_24, getActivity().getTheme()));

LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.fragment_track_properties_dialog, null);

DescEditText = view.findViewById(R.id.track_description);
if (!_trackToEdit.getDescription().isEmpty()) {
DescEditText.setText(_trackToEdit.getDescription());
}
//DescEditText.setHint(getString(R.string.track_id) + " " + String.valueOf(GPSApplication.getInstance().getCurrentTrack().getId()));
// DescEditText.postDelayed(new Runnable()
// {
Expand All @@ -66,19 +93,52 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
// }
// }, 200);

tracktypeImageView[Track.TRACK_TYPE_STEADY ] = view.findViewById(R.id.tracktype_steady);
tracktypeImageView[Track.TRACK_TYPE_MOUNTAIN ] = view.findViewById(R.id.tracktype_mountain);
tracktypeImageView[Track.TRACK_TYPE_WALK ] = view.findViewById(R.id.tracktype_walk);
tracktypeImageView[Track.TRACK_TYPE_RUN ] = view.findViewById(R.id.tracktype_run);
tracktypeImageView[Track.TRACK_TYPE_BICYCLE ] = view.findViewById(R.id.tracktype_bicycle);
tracktypeImageView[Track.TRACK_TYPE_CAR ] = view.findViewById(R.id.tracktype_car);
tracktypeImageView[Track.TRACK_TYPE_FLIGHT ] = view.findViewById(R.id.tracktype_flight);

// Disable all images
for (int i = 0; i< tracktypeImageView.length; i++) {
tracktypeImageView[i].setColorFilter(getResources().getColor(R.color.textColorRecControlDisabled), PorterDuff.Mode.SRC_IN);
tracktypeImageView[i].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i < tracktypeImageView.length; i++) {
if (view == tracktypeImageView[i]) {
tracktypeImageView[i].setColorFilter(getResources().getColor(R.color.textColorRecControlPrimary), PorterDuff.Mode.SRC_IN);
selectedTrackType = i;
} else
tracktypeImageView[i].setColorFilter(getResources().getColor(R.color.textColorRecControlDisabled), PorterDuff.Mode.SRC_IN);
}
}
});
}
// Activate the right image
if (_trackToEdit.getTrackType() != Track.TRACK_TYPE_ND)
tracktypeImageView[_trackToEdit.getTrackType()].setColorFilter(getResources().getColor(R.color.textColorRecControlPrimary), PorterDuff.Mode.SRC_IN);

createPlacemarkAlert.setView(view)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int id) {
if (isAdded()) {
String PlacemarkDescription = DescEditText.getText().toString();
final GPSApplication gpsApp = GPSApplication.getInstance();
//gpsApp.setPlacemarkDescription(PlacemarkDescription.trim());
gpsApp.setRecording(false);
EventBus.getDefault().post(EventBusMSG.NEW_TRACK);
Toast.makeText(getActivity(), getString(R.string.toast_track_saved_into_tracklist), Toast.LENGTH_SHORT).show();
//Log.w("myApp", "[#] FragmentPlacemarkDialog.java - posted ADD_PLACEMARK: " + PlacemarkDescription);
String trackDescription = DescEditText.getText().toString();
_trackToEdit.setDescription (trackDescription.trim());
if (selectedTrackType != NOT_AVAILABLE) _trackToEdit.setTrackType(selectedTrackType); // the user selected a track type!
GPSApplication.getInstance().GPSDataBase.updateTrack(_trackToEdit);
if (_isAFinalization) {
// a request to finalize a track
EventBus.getDefault().post(EventBusMSG.NEW_TRACK);
Toast.makeText(getActivity(), getString(R.string.toast_track_saved_into_tracklist), Toast.LENGTH_SHORT).show();
} else {
EventBus.getDefault().post(EventBusMSG.UPDATE_TRACKLIST);
// TODO: update only the selected track!
}
}
}
})
Expand Down
Loading

0 comments on commit 84b20c2

Please sign in to comment.