use of com.cmput301w18t05.taskzilla.controller.NewTaskController in project Taskzilla by CMPUT301W18T05.
the class NewTaskActivity method onCreate.
/**
* Activity uses the activity_new_task.xml layout
* New tasks are created through NewTaskController
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
setTitle("Add a Task");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_task);
AppColors appColors = AppColors.getInstance();
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap);
mapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
newTaskController = new NewTaskController(this, getApplicationContext());
currentLocationButton = findViewById(R.id.currentLocationButton);
Button cancel = findViewById(R.id.CancelButton);
Button addTask = findViewById(R.id.addTaskButton);
final EditText taskName = findViewById(R.id.TaskName);
final EditText taskDescription = findViewById(R.id.Description);
addPhotoButton = findViewById(R.id.AddPhotoButton);
autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
/**
* When user select a location
* Set hint and set place
* @param place
*/
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
autocompleteFragment.setHint(place.getName());
taskLocation = place.getLatLng();
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
taskLocation = null;
Log.i("err", "An error occurred: " + status);
}
});
photos = new ArrayList<>();
recyclerPhotosView = findViewById(R.id.listOfPhotos);
layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerPhotosView.setLayoutManager(layoutManager);
recyclerPhotosViewAdapter = new RecyclerViewAdapter(this, photos, new CustomOnItemClick() {
@Override
public void onColumnClicked(final int position) {
// taken from https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android
// 2018-03-16
AlertDialog.Builder alert = new AlertDialog.Builder(NewTaskActivity.this);
alert.setTitle("Delete Photo");
alert.setMessage("Are you sure you want to delete this photo?");
// DELETE CODE
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
photos.remove(position);
dialogInterface.dismiss();
recyclerPhotosViewAdapter.notifyDataSetChanged();
}
});
// DELETE CANCEL CODE
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alert.show();
}
});
recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
autocompleteFragment.setHint("Task Location");
getLocation();
autocompleteFragment.setBoundsBias(new LatLngBounds(new LatLng(lat - 0.25, lon - 0.25), new LatLng(lat + 0.25, lon + 0.25)));
/* cancel button */
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
newTaskController.cancelTask();
}
});
currentLocationButton.setOnClickListener(new View.OnClickListener() {
/**
* Set loaction to the users current location
* @param view
*/
@Override
public void onClick(View view) {
setCurrentLocation();
}
});
/* add task button */
addTask.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
newTaskController.addTask(taskName.getText().toString(), cUser, taskDescription.getText().toString(), taskLocation, photos);
}
});
addPhotoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AddPhotoButtonClicked();
}
});
}
Aggregations