2011-05-23 18:59:34 +00:00
|
|
|
package com.dougkeen.bart;
|
|
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.view.View;
|
2011-07-11 19:19:21 +00:00
|
|
|
import android.widget.CheckBox;
|
2011-05-23 18:59:34 +00:00
|
|
|
|
2012-07-16 15:06:31 +00:00
|
|
|
import com.dougkeen.bart.data.RoutesColumns;
|
|
|
|
import com.dougkeen.bart.model.Constants;
|
|
|
|
import com.dougkeen.bart.model.Station;
|
2011-05-23 18:59:34 +00:00
|
|
|
|
2012-09-05 17:34:00 +00:00
|
|
|
public class AddRouteDialogFragment extends AbstractRouteSelectionFragment {
|
|
|
|
public AddRouteDialogFragment(String title) {
|
|
|
|
super(title);
|
|
|
|
}
|
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
@Override
|
2012-09-05 17:34:00 +00:00
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
final View checkboxText = getDialog().findViewById(
|
|
|
|
R.id.return_checkbox_text);
|
|
|
|
final View checkbox = getDialog().findViewById(R.id.return_checkbox);
|
2012-07-22 14:57:17 +00:00
|
|
|
checkboxText.setVisibility(View.VISIBLE);
|
|
|
|
checkbox.setVisibility(View.VISIBLE);
|
|
|
|
checkboxText.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
checkbox.performClick();
|
|
|
|
}
|
|
|
|
});
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-07-16 15:06:31 +00:00
|
|
|
@Override
|
|
|
|
protected void onOkButtonClick(Station origin, Station destination) {
|
2011-05-23 18:59:34 +00:00
|
|
|
ContentValues values = new ContentValues();
|
2011-05-27 21:06:58 +00:00
|
|
|
values.put(RoutesColumns.FROM_STATION.string, origin.abbreviation);
|
|
|
|
values.put(RoutesColumns.TO_STATION.string, destination.abbreviation);
|
2011-05-23 18:59:34 +00:00
|
|
|
|
2012-09-05 17:34:00 +00:00
|
|
|
Uri newUri = getActivity().getContentResolver().insert(
|
2011-05-23 18:59:34 +00:00
|
|
|
Constants.FAVORITE_CONTENT_URI, values);
|
2011-07-11 19:19:21 +00:00
|
|
|
|
2012-09-05 17:34:00 +00:00
|
|
|
if (((CheckBox) getDialog().findViewById(R.id.return_checkbox))
|
|
|
|
.isChecked()) {
|
2011-07-11 19:19:21 +00:00
|
|
|
values = new ContentValues();
|
|
|
|
values.put(RoutesColumns.FROM_STATION.string,
|
|
|
|
destination.abbreviation);
|
|
|
|
values.put(RoutesColumns.TO_STATION.string, origin.abbreviation);
|
|
|
|
|
2012-09-05 17:34:00 +00:00
|
|
|
getActivity().getContentResolver().insert(
|
|
|
|
Constants.FAVORITE_CONTENT_URI, values);
|
2011-07-11 19:19:21 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 17:34:00 +00:00
|
|
|
dismiss();
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
2012-09-05 17:34:00 +00:00
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|