use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class DayScheduleViewHolder method bindSession.
public void bindSession(RealmDataRepository realmRepo) {
String startTimeText = DateConverter.formatDateWithDefault(DateConverter.FORMAT_24H, session.getStartsAt());
String endTimeText = DateConverter.formatDateWithDefault(DateConverter.FORMAT_24H, session.getEndsAt());
String title = Utils.checkStringEmpty(session.getTitle());
startTime.setText(startTimeText);
endTime.setText(endTimeText);
slotTitle.setText(title);
Track sessionTrack = session.getTrack();
if (!RealmDataRepository.isNull(sessionTrack)) {
int storedColor = Color.parseColor(sessionTrack.getColor());
slotTrack.setVisibility(View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
slotTrack.setBackground(context.getDrawable(R.drawable.button_ripple));
}
slotTrack.getBackground().setColorFilter(storedColor, PorterDuff.Mode.SRC_ATOP);
slotTrack.setText(sessionTrack.getName());
if (session.getIsBookmarked()) {
slotBookmark.setImageResource(R.drawable.ic_bookmark_white_24dp);
} else {
slotBookmark.setImageResource(R.drawable.ic_bookmark_border_white_24dp);
}
slotBookmark.setColorFilter(storedColor, PorterDuff.Mode.SRC_ATOP);
final int sessionId = session.getId();
slotBookmark.setOnClickListener(v -> {
if (session.getIsBookmarked()) {
realmRepo.setBookmark(sessionId, false).subscribe();
slotBookmark.setImageResource(R.drawable.ic_bookmark_border_white_24dp);
if (onBookmarkSelectedListener != null)
onBookmarkSelectedListener.showSnackbar(new BookmarkStatus(storedColor, sessionId, CODE_UNDO_REMOVED));
} else {
// TODO: Move all logic to ViewModel
NotificationUtil.createNotification(session, context).subscribe(() -> {
if (onBookmarkSelectedListener != null)
onBookmarkSelectedListener.showSnackbar(new BookmarkStatus(storedColor, sessionId, CODE_UNDO_ADDED));
}, throwable -> {
if (onBookmarkSelectedListener != null)
onBookmarkSelectedListener.showSnackbar(new BookmarkStatus(-1, -1, CODE_ERROR));
});
realmRepo.setBookmark(sessionId, true).subscribe();
slotBookmark.setImageResource(R.drawable.ic_bookmark_white_24dp);
slotBookmark.setColorFilter(storedColor, PorterDuff.Mode.SRC_ATOP);
}
WidgetUpdater.updateWidget(context);
});
slotTrack.setOnClickListener(v -> {
Intent intent = new Intent(context, TrackSessionsActivity.class);
intent.putExtra(ConstantStrings.TRACK, sessionTrack.getName());
intent.putExtra(ConstantStrings.TRACK_ID, sessionTrack.getId());
context.startActivity(intent);
});
itemView.setOnClickListener(v -> {
final String sessionName = session.getTitle();
realmRepo.getTrack(session.getTrack().getId()).addChangeListener((RealmChangeListener<Track>) track -> {
String trackName = track.getName();
Intent intent = new Intent(context, SessionDetailActivity.class);
intent.putExtra(ConstantStrings.SESSION, sessionName);
intent.putExtra(ConstantStrings.TRACK, trackName);
intent.putExtra(ConstantStrings.ID, session.getId());
context.startActivity(intent);
});
});
} else {
slotTrack.setOnClickListener(null);
slotTrack.setVisibility(View.GONE);
itemView.setOnClickListener(v -> {
final String sessionName = session.getTitle();
Intent intent = new Intent(context, SessionDetailActivity.class);
intent.putExtra(ConstantStrings.SESSION, sessionName);
intent.putExtra(ConstantStrings.ID, session.getId());
context.startActivity(intent);
});
Timber.d("This session has no track somehow : " + session + " " + sessionTrack);
}
if (session.getMicrolocation() != null) {
String locationName = Utils.checkStringEmpty(session.getMicrolocation().getName());
slotLocation.setText(locationName);
}
}
use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class BookmarkAlarmService method handleStart.
private void handleStart(Intent intent) {
NotificationManager notificationManager = (NotificationManager) this.getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
int id = intent.getIntExtra(ConstantStrings.SESSION, 0);
String session_date;
Session session = realmRepo.getSessionSync(id);
Intent intent1 = new Intent(this.getApplicationContext(), SessionDetailActivity.class);
intent1.putExtra(ConstantStrings.SESSION, session.getTitle());
intent1.putExtra(ConstantStrings.ID, session.getId());
intent1.putExtra(ConstantStrings.TRACK, session.getTrack().getName());
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
int smallIcon = R.drawable.ic_bookmark_white_24dp;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
smallIcon = R.drawable.ic_noti_bookmark;
String session_timings = String.format("%s - %s", DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getStartsAt()), DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getEndsAt()));
session_date = DateConverter.formatDateWithDefault(DateConverter.FORMAT_DATE_COMPLETE, session.getStartsAt());
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(smallIcon).setLargeIcon(largeIcon).setContentTitle(session.getTitle()).setContentText(session_date + "\n" + session_timings).setAutoCancel(true).setStyle(new NotificationCompat.BigTextStyle().bigText(session_date + "\n" + session_timings)).setContentIntent(pendingNotificationIntent);
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
if (notificationManager != null) {
notificationManager.notify(session.getId(), notificationBuilder.build());
}
}
use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class LocationActivity method setUpcomingSession.
public void setUpcomingSession() {
String upcomingTitle = "";
String track = "";
String color = null;
ZonedDateTime current = ZonedDateTime.now();
for (Session session : sessions) {
ZonedDateTime start = DateConverter.getDate(session.getStartsAt());
if (start.isAfter(current)) {
upcomingTitle = session.getTitle();
track = session.getTrack().getName();
color = session.getTrack().getColor();
break;
}
}
if (!TextUtils.isEmpty(upcomingTitle)) {
int trackColor = Color.parseColor(color);
upcomingSessionTitle.setText(getResources().getString(R.string.upcoming_sess));
TextDrawable drawable = drawableBuilder.build(String.valueOf(track.charAt(0)), trackColor);
trackImageIcon.setImageDrawable(drawable);
trackImageIcon.setBackgroundColor(Color.TRANSPARENT);
upcomingSessionText.setText(upcomingTitle);
} else {
upcomingSessionTitle.setText(getResources().getString(R.string.no_upcoming_Sess));
upcomingSessionDetails.setVisibility(View.GONE);
}
}
use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class BookmarkWidgetRemoteViewsService method onGetViewFactory.
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, BookmarkWidgetProvider.class));
final int appWidgetId = appWidgetIds[0];
return new RemoteViewsFactory() {
private MatrixCursor data = null;
@Override
public void onCreate() {
// Called when your factory is first constructed.
}
@Override
public void onDataSetChanged() {
if (data != null) {
data.close();
}
List<Session> sessions = realmRepo.getBookMarkedSessionsSync();
try {
String[] columns = new String[] { ID, TITLE, START_TIME, END_TIME, DATE };
data = new MatrixCursor(columns);
for (Session session : sessions) {
String start = DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getStartsAt());
String end = DateConverter.formatDateWithDefault(DateConverter.FORMAT_12H, session.getEndsAt());
String date = DateConverter.formatDateWithDefault(DateConverter.FORMAT_DATE_COMPLETE, session.getStartsAt());
data.addRow(new Object[] { id, session.getTitle(), start, end, date });
}
} catch (Exception e) {
Timber.e("Parsing Error Occurred at BookmarkWidgetRemoteViewsService::onDataSetChanged.");
}
}
@Override
public void onDestroy() {
if (data != null) {
data.close();
data = null;
}
}
@Override
public int getCount() {
if (data != null)
return data.getCount();
return 0;
}
@Override
public RemoteViews getViewAt(int position) {
if (position == AdapterView.INVALID_POSITION || data == null || !data.moveToPosition(position)) {
return null;
}
int widgetWidth = getWidgetWidth(appWidgetManager, appWidgetId);
String title = data.getString(INDEX_BOOKMARK_TITLE);
String start = data.getString(INDEX_BOOKMARK_START_TIME);
String end = data.getString(INDEX_BOOKMARK_END_TIME);
String date = data.getString(INDEX_BOOKMARK_DATE);
int id = data.getInt(INDEX_BOOKMARK_ID);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget_list_item);
views.setTextViewText(R.id.title_widget_bookmarks, title);
if (widgetWidth > LESS_DETAIL_SIZE) {
views.setTextViewText(R.id.date_widget_bookmarks, date);
views.setTextViewText(R.id.time_widget_bookmarks, start + " to " + end);
} else {
views.setTextViewText(R.id.date_widget_bookmarks, "");
views.setTextViewText(R.id.time_widget_bookmarks, "");
}
final Intent fillInIntent = new Intent();
fillInIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
fillInIntent.putExtra(ConstantStrings.SESSION, title);
fillInIntent.putExtra(ConstantStrings.ID, id);
views.setOnClickFillInIntent(R.id.widget_list_item, fillInIntent);
return views;
}
@Override
public RemoteViews getLoadingView() {
return new RemoteViews(getPackageName(), R.layout.widget_list_item);
}
@Override
public int getViewTypeCount() {
return 1;
}
@Override
public long getItemId(int position) {
if (data.moveToPosition(position))
return data.getLong(INDEX_BOOKMARK_ID);
return position;
}
@Override
public boolean hasStableIds() {
return true;
}
private int getWidgetWidth(AppWidgetManager appWidgetManager, int appWidgetId) {
return getWidgetWidthFromOptions(appWidgetManager, appWidgetId);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private int getWidgetWidthFromOptions(AppWidgetManager appWidgetManager, int appWidgetId) {
Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
if (options.containsKey(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)) {
return options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
}
return getResources().getDimensionPixelSize(R.dimen.widget_min_resize_width);
}
};
}
use of org.fossasia.openevent.data.Session in project open-event-android by fossasia.
the class TrackSessionsActivity method setUpcomingSession.
public void setUpcomingSession() {
String upcomingTitle = "";
String track = "";
String color = null;
ZonedDateTime current = ZonedDateTime.now();
for (Session session : sessions) {
if (session.getStartDate() != null) {
ZonedDateTime start = DateConverter.getDate(session.getStartsAt());
if (start.isAfter(current)) {
if (session.getTitle() != null)
upcomingTitle = session.getTitle();
if (session.getTrack().getName() != null)
track = session.getTrack().getName();
if (session.getTrack().getColor() != null)
color = session.getTrack().getColor();
break;
}
}
}
if (!TextUtils.isEmpty(upcomingTitle)) {
int trackColor = Color.parseColor(color);
upcomingSessionTitle.setPadding(10, 60, 10, 10);
upcomingSessionTitle.setText(getResources().getString(R.string.upcoming_sess));
TextDrawable drawable = drawableBuilder.build(String.valueOf(track.charAt(0)), trackColor);
trackImageIcon.setImageDrawable(drawable);
trackImageIcon.setBackgroundColor(Color.TRANSPARENT);
upcomingSessionText.setText(upcomingTitle);
} else {
upcomingSessionTitle.setPadding(10, 60, 10, 10);
upcomingSessionTitle.setText(getResources().getString(R.string.no_upcoming_Sess));
upcomingSessionDetails.setVisibility(View.GONE);
}
}
Aggregations