Skip to content
Snippets Groups Projects
Commit 52eccae4 authored by Ivan Xie Ng (irx521)'s avatar Ivan Xie Ng (irx521)
Browse files

Updated new AddEventActivity to handle add and remove tags from textview, also...

Updated new AddEventActivity to handle add and remove tags from textview, also updated Start and End Date.
parent 413058f7
No related branches found
No related tags found
2 merge requests!34Reviews for events are done. The reviews for events and restaurents have been...,!30Updated new AddEventActivity to handle add and remove tags from textview, also...
......@@ -6,6 +6,7 @@ import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
......@@ -15,19 +16,19 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;
public class AddEventActivity extends AppCompatActivity implements View.OnClickListener {
......@@ -36,20 +37,23 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
//This is to handle the return code from next activity
ActivityResultLauncher<Intent> mStartForResult;
EditText eventName, eventDate, startEvent, endEvent, eventLocation, eventDescription, eventTags;
EditText eventName,startEvent, endEvent, eventLocation, eventDescription, eventTags;
DatePickerDialog eventDateTextView;
ImageView eventImage;
Button btnGallery, btn_cancel, btn_create;
Button btnGallery, btn_reset, btn_create;
List<String> tagList;
TextView tagTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_event);
tagList = new ArrayList<>();
// Initialize the views in the layout
eventName = (EditText) findViewById(R.id.event_name);
eventDate = (EditText) findViewById(R.id.event_date);
startEvent = (EditText) findViewById(R.id.event_start_time);
endEvent = (EditText) findViewById(R.id.event_end_time);
startEvent = (EditText) findViewById(R.id.event_start_date);
endEvent = (EditText) findViewById(R.id.event_end_date);
eventLocation = (EditText) findViewById(R.id.event_location);
eventDescription = (EditText) findViewById(R.id.event_description);
eventImage = (ImageView) findViewById(R.id.event_image);
......@@ -58,7 +62,75 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
eventDate.setOnClickListener(new View.OnClickListener() {
ImageButton addTagButton = findViewById(R.id.add_tagBtn);
ImageButton removeTagButton = findViewById(R.id.remove_tagBtn);
tagTextView = findViewById(R.id.tag_textView);
// add tag button listener to add tag to the list of tags for the event and display it in the text view
addTagButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String someString = eventTags.getText().toString();
//Clear existing
eventTags.setText("");
String[] split = someString.split("[, ]");
for (String tag : split) {
if (!Objects.equals(tag, "")) {
if (!tagList.contains(tag)) {
tagList.add(tag);
removeTagButton.setVisibility(View.VISIBLE);
}
}
}
if (!tagList.isEmpty()) {
StringBuilder tagString = new StringBuilder();
for (int i = 0; i < tagList.size(); i++) {
if (i > 0) tagString.append(" ");
tagString.append(tagList.get(i));
}
tagTextView.setText(tagString);
// set remove tag button to visible if there are tags in the list
removeTagButton.setVisibility(View.VISIBLE);
}
}
});
// set remove tag button invisible if no tags are added
if (tagList.isEmpty()) {
removeTagButton.setVisibility(View.INVISIBLE);
}
// remove tag button listener to remove tag from tag list and update tag text view
removeTagButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// get the tag to remove from the input field
if (!tagList.isEmpty()) {
tagList.remove(tagList.size() - 1);
// update tag list text view
if (!tagList.isEmpty()) {
StringBuilder tagString = new StringBuilder();
for (int i = 0; i < tagList.size(); i++) {
if (i > 0) tagString.append(", ");
tagString.append(tagList.get(i));
}
tagTextView.setText(tagString);
} else {
tagTextView.setText("No tags added yet");
// set remove tag button invisible if no tags are added
removeTagButton.setVisibility(View.INVISIBLE);
}
}
}
});
startEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
......@@ -69,12 +141,38 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
eventDateTextView = new DatePickerDialog(AddEventActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
eventDate.setText(dayOfMonth + "/" + (month + 1) + "/" + year);
startEvent.setText(dayOfMonth + "/" + (month + 1) + "/" + year);
}
}, year, month, day);
// show only future dates in the date picker dialog
eventDateTextView.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
eventDateTextView.show();
}
});
endEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
eventDateTextView = new DatePickerDialog(AddEventActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
endEvent.setText(dayOfMonth + "/" + (month + 1) + "/" + year);
}
}, year, month, day);
// show only future dates in the date picker dialog
eventDateTextView.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
eventDateTextView.show();
}
});
/*
*This is the callback for when the next activity closes.
*/
......@@ -110,24 +208,32 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
// Set the click listener for the button to cancel the event
btn_cancel = (Button) findViewById(R.id.btn_cancel);
btn_cancel.setOnClickListener(new View.OnClickListener() {
btn_reset = (Button) findViewById(R.id.btn_reset);
btn_reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Dialog to confirm cancel event
AlertDialog.Builder builder = new AlertDialog.Builder(AddEventActivity.this);
builder.setMessage("Are you sure you want to cancel this event?")
builder.setMessage("Are you sure you want to reset the data form?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Cancel the event
finish();
eventName.setText("");
startEvent.setText("");
endEvent.setText("");
eventLocation.setText("");
eventDescription.setText("");
eventTags.setText("");
tagTextView.setText("");
eventImage.setImageResource(R.drawable.ic_baseline_add_a_photo_24);
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
......@@ -135,9 +241,6 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
}
});
}
......@@ -189,27 +292,26 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
// Pop up alert dialog to show if the user wants to create the event
builder.setMessage(" Are you sure you want to create this event?" +
"\n\n Event Name: " + eventName.getText().toString() +
"\n Event Date: " + eventDate.getText().toString() +
"\n Event Start Time: " + startEvent.getText().toString() +
"\n Event End Time: " + endEvent.getText().toString() +
// "\n Event Start Date: " + eventDate.getText().toString() +
// "\n Event End Date: " + eventDate.getText().toString() +
"\n Event Start Date: " + startEvent.getText().toString() +
"\n Event End Date: " + endEvent.getText().toString() +
"\n Event Location: " + eventLocation.getText().toString() +
"\n Event Description: " + eventDescription.getText().toString()+
"\n Event Tags: "+eventTags.getText().toString())
"\n Event Tags: "+ tagTextView.getText().toString())
.setCancelable(true)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// If the user clicks yes go back to the main activity
//Intent intent = new Intent(AddEventActivity.this, ViewEvent.class);
Intent intent = new Intent();
intent.putExtra("name", eventName.getText().toString());
intent.putExtra("date", eventDate.getText().toString());
intent.putExtra("startTime", startEvent.getText().toString());
intent.putExtra("endTime", endEvent.getText().toString());
intent.putExtra("startDate", startEvent.getText().toString());
intent.putExtra("endDate", endEvent.getText().toString());
intent.putExtra("location", eventLocation.getText().toString());
intent.putExtra("description", eventDescription.getText().toString());
String tagString = eventTags.getText().toString();
String tagString = tagTextView.getText().toString();
String[] tags = tagString.split("[, ]");
if (tags.length > 0){
int count = 0;
......@@ -226,6 +328,7 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
// TODO: 11/4/2022 Add the image to the intent
//startActivity(intent);
setResult(RESULT_OK, intent);
finish();
......@@ -237,8 +340,7 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// If the user clicks no, close the dialog box
// If the user clicks no, do nothing
dialog.cancel();
}
});
......@@ -248,6 +350,8 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
}
}
// Validate the fields in the layout to make sure they are not empty
......@@ -257,19 +361,26 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
Toast.makeText(this, "Please enter event name", Toast.LENGTH_SHORT).show();
return false;
}
if (eventDate.getText().toString().isEmpty()) {
eventDate.setError("Please enter event date");
Toast.makeText(this, "Please enter event date", Toast.LENGTH_SHORT).show();
if (startEvent.getText().toString().isEmpty()) {
startEvent.setError("Please enter event start date");
Toast.makeText(this, "Please enter event start date", Toast.LENGTH_SHORT).show();
return false;
}
if (startEvent.getText().toString().isEmpty()) {
startEvent.setError("Please enter event start time");
Toast.makeText(this, "Please enter event start time", Toast.LENGTH_SHORT).show();
// validate user input in the date fields are in correct date format dd/mm/yyyy
if (!startEvent.getText().toString().matches("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[0-9]{4}$")) {
startEvent.setError("Please enter Start date in correct format");
Toast.makeText(this, "Please enter Start date in correct format", Toast.LENGTH_SHORT).show();
return false;
}
if (endEvent.getText().toString().isEmpty()) {
endEvent.setError("Please enter event end time");
Toast.makeText(this, "Please enter event end time", Toast.LENGTH_SHORT).show();
endEvent.setError("Please enter event end date");
Toast.makeText(this, "Please enter event end date", Toast.LENGTH_SHORT).show();
return false;
}
// validate user input in the date fields are in correct date format dd/mm/yyyy
if (!endEvent.getText().toString().matches("^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[0-9]{4}$")) {
endEvent.setError("Please enter End date in correct format");
Toast.makeText(this, "Please enter End date in correct format", Toast.LENGTH_SHORT).show();
return false;
}
if (eventLocation.getText().toString().isEmpty()) {
......@@ -282,6 +393,12 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
Toast.makeText(this, "Please enter event description", Toast.LENGTH_SHORT).show();
return false;
}
if (tagTextView.getText().toString().equals("No tags added yet")) {
eventTags.setError("Please enter event tags");
Toast.makeText(this, "Please enter event tags", Toast.LENGTH_SHORT).show();
return false;
}
// TODO: 11/4/2022 Validate the image to make sure it is not empty
......@@ -301,9 +418,9 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// If the user clicks yes go back to the main activity
//Intent intent = new Intent(AddEventActivity.this, MainActivity.class);
//startActivity(intent);
// send the user back to the main activity
Intent intent = new Intent();
setResult(RESULT_CANCELED, intent);
finish();
}
})
......@@ -318,4 +435,6 @@ public class AddEventActivity extends AppCompatActivity implements View.OnClickL
// Show the alert dialog
alert.show();
}
}
\ No newline at end of file
......@@ -18,9 +18,12 @@ import android.os.Parcelable;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
......@@ -41,10 +44,11 @@ public class MainActivity extends AppCompatActivity implements CustomAdapter.Ite
private ArrayList<String> additionEvent;
private int currentTabPosition = 0; //Initial tab position
private String finalYear, finalMonth, finalDay;
private String finalYear, finalMonth, finalDay,finalYear2, finalMonth2, finalDay2;
private List<String> tagString= new ArrayList<>();
private EventRestoSuperClass eventRestoSelected = null;
//This is to handle the return code from next activity
......@@ -159,9 +163,9 @@ public class MainActivity extends AppCompatActivity implements CustomAdapter.Ite
if (result.getResultCode() == RESULT_OK){
if (results!=null){
dataMap.put("name", results.get("name").toString());
dataMap.put("date", results.get("date").toString());
dataMap.put("startTime", results.get("startTime").toString());
dataMap.put("endTime", results.get("endTime").toString());
// dataMap.put("date", results.get("date").toString());
dataMap.put("startDate", results.get("startDate").toString());
dataMap.put("endDate", results.get("endDate").toString());
dataMap.put("location", results.get("location").toString());
dataMap.put("description", results.get("description").toString());
if (results.get("tagSize") != "0"){
......@@ -177,9 +181,11 @@ public class MainActivity extends AppCompatActivity implements CustomAdapter.Ite
}
}
String[] tag = tagString.toArray(new String[0]);
translateDate(dataMap.get("date"));
GregorianCalendar startDate =new GregorianCalendar(Integer.valueOf(finalYear),Integer.valueOf(finalMonth),Integer.valueOf(finalDay));
GregorianCalendar endDate =new GregorianCalendar(Integer.valueOf(finalYear),Integer.valueOf(finalMonth),Integer.valueOf(finalDay)+1);
// translateDate(dataMap.get("date"));
translateDate((dataMap.get("startDate")));
translateEndDate((dataMap.get("endDate")));
GregorianCalendar startDate =new GregorianCalendar(Integer.parseInt(finalYear),Integer.parseInt(finalMonth),Integer.parseInt(finalDay));
GregorianCalendar endDate =new GregorianCalendar(Integer.parseInt(finalYear2),Integer.parseInt(finalMonth2),Integer.parseInt(finalDay2));
Event event = new Event(dataMap.get("name"),startDate,endDate,dataMap.get("location"),dataMap.get("description"),new String[]{"twitter", "facebook", "discord"},tag, null, "sometime for new event.");
//You have to validate date at point of entry see
mModel.addEventToList(event);
......@@ -395,4 +401,25 @@ public class MainActivity extends AppCompatActivity implements CustomAdapter.Ite
}
public void translateEndDate(String end_event_date) {
String day = "", month = "", year = "";
for (int i = 0; i < end_event_date.length(); i++) {
char ch = end_event_date.charAt(i);
if (end_event_date.charAt(i) == '/' && i <= 2) {
day = day + year;
year = "";
}
if (end_event_date.charAt(i) == '/' && i <= 5) {
month = month + year;
year = "";
}
year = year + ch;
if (end_event_date.charAt(i) == '/') {
year = "";
}
finalYear2 = year;
finalMonth2 = month;
finalDay2= day;
}
}
}
\ No newline at end of file
......@@ -103,7 +103,7 @@
android:textColor="@color/colorBlack" />
</LinearLayout>
<!-- Event Date Linear Layout with horizontal orientation and weightSum-->
<!-- Event Start Date Linear Layout with horizontal orientation and weightSum-->
<LinearLayout
android:id="@+id/thirdLayout"
android:layout_width="match_parent"
......@@ -120,17 +120,18 @@
android:layout_weight="0.6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="@string/event_date_label"
android:text="Start date"
android:textColor="@color/colorBlack" />
<EditText
android:id="@+id/event_date"
android:id="@+id/event_start_date"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_weight="1.4"
android:background="@color/editText"
android:hint="@string/date_hint"
android:inputType="date"
android:imeOptions="actionNext"
android:paddingStart="10dp"
android:singleLine="true"
......@@ -138,52 +139,17 @@
</LinearLayout>
<!-- Start Time Linear Layout with horizontal orientation and weightSum -->
<LinearLayout
android:id="@+id/fourthLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- Event End Date Linear Layout with horizontal orientation and weightSum-->
<!-- Start Time TextView and EditText-->
<TextView
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:layout_weight="0.6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="@string/start_time_label"
android:textColor="@color/colorBlack" />
<EditText
android:id="@+id/event_start_time"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_weight="1.4"
android:background="@color/editText"
android:hint="@string/hh_mm"
android:imeOptions="actionNext"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColor="@color/colorBlack" />
</LinearLayout>
<!-- End Time Linear Layout with horizontal orientation and weightSum -->
<LinearLayout
android:id="@+id/fifthLayout"
android:id="@+id/fourthLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- End Time TextView and EditText -->
<!-- Event End Date TextView and EditText -->
<TextView
android:layout_width="0dp"
android:layout_height="50dp"
......@@ -191,19 +157,20 @@
android:layout_weight="0.6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="@string/end_time_label"
android:text="End date"
android:textColor="@color/colorBlack" />
<EditText
android:id="@+id/event_end_time"
android:id="@+id/event_end_date"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_weight="1.4"
android:background="@color/editText"
android:hint="@string/hh_mm"
android:hint="@string/date_hint"
android:inputType="date"
android:imeOptions="actionNext"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:singleLine="true"
android:textColor="@color/colorBlack" />
</LinearLayout>
......@@ -255,7 +222,7 @@
<!-- Event Tags TextView and EditText -->
<TextView
android:layout_width="0dp"
android:layout_width="19dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:layout_weight="0.6"
......@@ -271,16 +238,70 @@
android:layout_marginLeft="10dp"
android:layout_weight="1.4"
android:background="@color/editText"
android:hint="Tag name"
android:hint="Add your Tag"
android:imeOptions="actionNext"
android:paddingLeft="10dp"
android:singleLine="true"
android:textColor="@color/colorBlack" />
<ImageButton
android:id="@+id/add_tagBtn"
android:layout_width="37dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_weight="0.1"
android:background="@android:color/transparent"
android:src="@drawable/ic_baseline_add_circle_24"
android:textColor="@color/colorBlack" />
</LinearLayout>
<LinearLayout
android:id="@+id/eight3Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="2">
<!-- Event Tags TextView and EditText -->
<TextView
android:layout_width="78dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:layout_weight="0.6"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Added Tags:"
android:textColor="@color/colorBlack" />
<TextView
android:id="@+id/tag_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="No Tags Added Yet"
android:textColor="@color/colorBlack">
</TextView>
<ImageButton
android:id="@+id/remove_tagBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:src="@drawable/ic_baseline_remove_circle_24" />
</LinearLayout>
<!-- Event Image Linear Layout with horizontal orientation and weightSum -->
<LinearLayout
android:id="@+id/eightLayout"
android:id="@+id/eight2Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
......@@ -327,13 +348,14 @@
android:textColor="@color/colorWhite" />
<Button
android:id="@+id/btn_cancel"
android:id="@+id/btn_reset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@color/purple_200"
android:text="@string/cancel_text"
android:textColor="@color/colorWhite" />
android:backgroundTint="@color/teal_700"
android:text="Reset"
android:textColor="@color/white" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment