Skip to content

Commit

Permalink
Issue #88 #47 - Retains the state of the track properties dialog on s…
Browse files Browse the repository at this point in the history
…creen rotation
  • Loading branch information
GrazianoCapelli committed Apr 24, 2021
1 parent 84b20c2 commit 54d7c54
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {

// -----------------------------------------------------------------------------------------
// We use the Semantic Versioning (https://semver.org/):
versionName '2.3.3'
versionName '2.4.0'
versionCode 37
// -----------------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void onRequestStop() {

FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTrackPropertiesDialog tpDialog = new FragmentTrackPropertiesDialog();
tpDialog.setTrackToEdit(gpsApplication.getCurrentTrack());
gpsApplication.setTrackToEdit(gpsApplication.getCurrentTrack());
tpDialog.setTitleResource(R.string.finalize_track);
tpDialog.setIsAFinalization(true);
tpDialog.show(fm, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ public class FragmentTrackPropertiesDialog extends DialogFragment {

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

private static final String KEY_SELTRACKTYPE = "selectedTrackType";
private static final String KEY_TITLE = "_title";
private static final String KEY_ISFINALIZATION = "_isFinalization";

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


public void setTitleResource(int titleResource) {
Expand All @@ -65,11 +66,34 @@ public void setIsAFinalization(boolean isAFinalization) {
}


//@SuppressLint("InflateParams")
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);

outState.putInt(KEY_SELTRACKTYPE, selectedTrackType);
outState.putInt(KEY_TITLE, _title);
outState.putBoolean(KEY_ISFINALIZATION, _isAFinalization);
}



//@SuppressLint("InflateParams")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder createPlacemarkAlert = new AlertDialog.Builder(getActivity());

_trackToEdit = GPSApplication.getInstance().getTrackToEdit();

if (savedInstanceState != null) {
_title = savedInstanceState.getInt(KEY_TITLE, 0);
selectedTrackType = savedInstanceState.getInt(KEY_SELTRACKTYPE, NOT_AVAILABLE);
_isAFinalization = savedInstanceState.getBoolean(KEY_ISFINALIZATION, false);
} else {
selectedTrackType = _trackToEdit.getTrackType();
}

if (_title != 0) createPlacemarkAlert.setTitle(_title);
//createPlacemarkAlert.setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_stop_24, getActivity().getTheme()));

Expand Down Expand Up @@ -118,8 +142,8 @@ public void onClick(View view) {
});
}
// Activate the right image
if (_trackToEdit.getTrackType() != Track.TRACK_TYPE_ND)
tracktypeImageView[_trackToEdit.getTrackType()].setColorFilter(getResources().getColor(R.color.textColorRecControlPrimary), PorterDuff.Mode.SRC_IN);
if (selectedTrackType != Track.TRACK_TYPE_ND)
tracktypeImageView[selectedTrackType].setColorFilter(getResources().getColor(R.color.textColorRecControlPrimary), PorterDuff.Mode.SRC_IN);

createPlacemarkAlert.setView(view)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ public void run() {
private LocationExtended _currentLocationExtended = null;
private LocationExtended _currentPlacemark = null;
private Track _currentTrack = null;
private Track trackToEdit = null; // The Track that the user selected to edit with the "Track Properties Dialog

private final List<Track> _ArrayListTracks = Collections.synchronizedList(new ArrayList<Track>());

Thumbnailer Th;
Expand Down Expand Up @@ -668,6 +670,14 @@ public void setTrackViewer(AppInfo trackViewer) {
TrackViewer = trackViewer;
}

public Track getTrackToEdit() {
return trackToEdit;
}

public void setTrackToEdit(Track trackToEdit) {
this.trackToEdit = trackToEdit;
}

// ------------------------------------------------------------------------ Utility

private void DeleteFile(String filename) {
Expand Down

0 comments on commit 54d7c54

Please sign in to comment.