mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
list the events of the picked day
This commit is contained in:
@@ -63,11 +63,11 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||||||
mCallback.eventInserted();
|
mCallback.eventInserted();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Event> getEvents(int fromTS, int toTS) {
|
public void getEvents(int fromTS, int toTS) {
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
final String selection = COL_START_TS + " >= ? AND " + COL_START_TS + " <= ?";
|
final String selection = COL_START_TS + " <= ? AND " + COL_END_TS + " >= ?";
|
||||||
final String[] selectionArgs = {String.valueOf(fromTS), String.valueOf(toTS)};
|
final String[] selectionArgs = {String.valueOf(toTS), String.valueOf(fromTS)};
|
||||||
final Cursor cursor = mDb.query(TABLE_NAME, mProjection, selection, selectionArgs, null, null, null);
|
final Cursor cursor = mDb.query(TABLE_NAME, mProjection, selection, selectionArgs, null, null, COL_START_TS);
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
@@ -81,10 +81,12 @@ public class DBHelper extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
return events;
|
mCallback.gotEvents(events);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DBOperationsListener {
|
public interface DBOperationsListener {
|
||||||
void eventInserted();
|
void eventInserted();
|
||||||
|
|
||||||
|
void gotEvents(List<Event> events);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,69 @@
|
|||||||
|
package com.simplemobiletools.calendar;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.simplemobiletools.calendar.models.Event;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
|
public class EventsAdapter extends BaseAdapter {
|
||||||
|
private final List<Event> mEvents;
|
||||||
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
|
public EventsAdapter(Context context, List<Event> events) {
|
||||||
|
mEvents = events;
|
||||||
|
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
ViewHolder viewHolder;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = mInflater.inflate(R.layout.event_item, parent, false);
|
||||||
|
viewHolder = new ViewHolder(convertView);
|
||||||
|
convertView.setTag(viewHolder);
|
||||||
|
} else {
|
||||||
|
viewHolder = (ViewHolder) convertView.getTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Event event = mEvents.get(position);
|
||||||
|
viewHolder.eventTitle.setText(event.getTitle());
|
||||||
|
viewHolder.eventStart.setText(Formatter.getTime(event.getStartTS()));
|
||||||
|
viewHolder.eventEnd.setText(Formatter.getTime(event.getEndTS()));
|
||||||
|
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mEvents.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(int position) {
|
||||||
|
return mEvents.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ViewHolder {
|
||||||
|
@BindView(R.id.event_item_title) TextView eventTitle;
|
||||||
|
@BindView(R.id.event_item_start) TextView eventStart;
|
||||||
|
@BindView(R.id.event_item_end) TextView eventEnd;
|
||||||
|
|
||||||
|
public ViewHolder(View view) {
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.calendar;
|
package com.simplemobiletools.calendar;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.format.DateTimeFormat;
|
import org.joda.time.format.DateTimeFormat;
|
||||||
import org.joda.time.format.DateTimeFormatter;
|
import org.joda.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
@@ -21,7 +22,12 @@ public class Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DateTime getDateTime(String dayCode) {
|
public static DateTime getDateTime(String dayCode) {
|
||||||
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(Constants.DATE_PATTERN);
|
final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(Constants.DATE_PATTERN).withZone(DateTimeZone.UTC);
|
||||||
return dateTimeFormatter.parseDateTime(dayCode);
|
return dateTimeFormatter.parseDateTime(dayCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getTime(int ts) {
|
||||||
|
final DateTime dateTime = new DateTime(ts * 1000L, DateTimeZone.UTC);
|
||||||
|
return getEventTime(dateTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,18 +4,28 @@ import android.content.Intent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.simplemobiletools.calendar.Constants;
|
import com.simplemobiletools.calendar.Constants;
|
||||||
|
import com.simplemobiletools.calendar.DBHelper;
|
||||||
|
import com.simplemobiletools.calendar.EventsAdapter;
|
||||||
import com.simplemobiletools.calendar.Formatter;
|
import com.simplemobiletools.calendar.Formatter;
|
||||||
import com.simplemobiletools.calendar.R;
|
import com.simplemobiletools.calendar.R;
|
||||||
|
import com.simplemobiletools.calendar.models.Event;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.joda.time.DateTimeZone;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
public class DetailsActivity extends AppCompatActivity {
|
public class DetailsActivity extends AppCompatActivity implements DBHelper.DBOperationsListener {
|
||||||
@BindView(R.id.details_date) TextView mDateTV;
|
@BindView(R.id.details_date) TextView mDateTV;
|
||||||
|
@BindView(R.id.details_events) ListView mEventsList;
|
||||||
|
|
||||||
private String dayCode;
|
private String dayCode;
|
||||||
|
|
||||||
@@ -37,10 +47,38 @@ public class DetailsActivity extends AppCompatActivity {
|
|||||||
mDateTV.setText(date);
|
mDateTV.setText(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
checkEvents();
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.details_fab)
|
@OnClick(R.id.details_fab)
|
||||||
public void fabClicked(View view) {
|
public void fabClicked(View view) {
|
||||||
final Intent intent = new Intent(getApplicationContext(), EventActivity.class);
|
final Intent intent = new Intent(getApplicationContext(), EventActivity.class);
|
||||||
intent.putExtra(Constants.DAY_CODE, dayCode);
|
intent.putExtra(Constants.DAY_CODE, dayCode);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkEvents() {
|
||||||
|
final DateTime dateTime = Formatter.getDateTime(dayCode).withZone(DateTimeZone.UTC);
|
||||||
|
final int startTS = (int) (dateTime.getMillis() / 1000);
|
||||||
|
final int endTS = (int) (dateTime.plusDays(1).minusMinutes(1).getMillis() / 1000);
|
||||||
|
DBHelper.newInstance(getApplicationContext(), this).getEvents(startTS, endTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateEvents(List<Event> events) {
|
||||||
|
final EventsAdapter adapter = new EventsAdapter(this, events);
|
||||||
|
mEventsList.setAdapter(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventInserted() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gotEvents(List<Event> events) {
|
||||||
|
updateEvents(events);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,8 @@ import com.simplemobiletools.calendar.models.Event;
|
|||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
@@ -190,4 +192,9 @@ public class EventActivity extends AppCompatActivity implements DBHelper.DBOpera
|
|||||||
Utils.showToast(getApplicationContext(), R.string.event_added);
|
Utils.showToast(getApplicationContext(), R.string.event_added);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gotEvents(List<Event> events) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.design.widget.CoordinatorLayout
|
<android.support.design.widget.CoordinatorLayout
|
||||||
android:id="@+id/details_holder"
|
android:id="@+id/details_coordinator"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginTop="@dimen/activity_margin">
|
android:layout_marginTop="@dimen/activity_margin">
|
||||||
|
|
||||||
<TextView
|
<RelativeLayout
|
||||||
android:id="@+id/details_date"
|
android:id="@+id/details_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:textSize="@dimen/month_text_size"/>
|
<TextView
|
||||||
|
android:id="@+id/details_date"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:text="January 1 1970"
|
||||||
|
android:textSize="@dimen/month_text_size"/>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/details_events"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/details_date"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<android.support.design.widget.FloatingActionButton
|
<android.support.design.widget.FloatingActionButton
|
||||||
android:id="@+id/details_fab"
|
android:id="@+id/details_fab"
|
||||||
|
36
app/src/main/res/layout/event_item.xml
Normal file
36
app/src/main/res/layout/event_item.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/event_item_holder"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="@dimen/event_padding"
|
||||||
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
android:paddingTop="@dimen/event_padding">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/event_item_start"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="13:00"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/event_item_end"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/event_item_start"
|
||||||
|
android:text="15:00"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/event_item_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
|
android:layout_toRightOf="@+id/event_item_start"
|
||||||
|
android:text="Event title"
|
||||||
|
android:textSize="@dimen/day_text_size"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@@ -2,6 +2,7 @@
|
|||||||
<dimen name="activity_margin">16dp</dimen>
|
<dimen name="activity_margin">16dp</dimen>
|
||||||
<dimen name="social_padding">8dp</dimen>
|
<dimen name="social_padding">8dp</dimen>
|
||||||
<dimen name="social_logo">40dp</dimen>
|
<dimen name="social_logo">40dp</dimen>
|
||||||
|
<dimen name="event_padding">8dp</dimen>
|
||||||
|
|
||||||
<dimen name="min_widget_width">250dp</dimen>
|
<dimen name="min_widget_width">250dp</dimen>
|
||||||
<dimen name="min_widget_height">250dp</dimen>
|
<dimen name="min_widget_height">250dp</dimen>
|
||||||
|
Reference in New Issue
Block a user