use of org.fossasia.openevent.data.Speaker in project open-event-android by fossasia.
the class SpeakersListAdapter method getHeaderId.
@Override
public long getHeaderId(int position) {
sortType = SharedPreferencesUtil.getInt(ConstantStrings.PREF_SORT_SPEAKER, SORTED_BY_NAME);
Speaker current = getItem(position);
String name = current.getName();
String organisation = current.getOrganisation();
String country = current.getCountry();
if (sortType == SORTED_BY_NAME)
return name.toUpperCase().charAt(0);
else if (sortType == SORTED_BY_ORGANIZATION) {
if (!organizations.contains(organisation)) {
organizations.add(organisation);
}
return organizations.indexOf(organisation);
} else {
if (!countries.contains(country)) {
countries.add(country);
}
return countries.indexOf(country);
}
}
use of org.fossasia.openevent.data.Speaker in project open-event-android by fossasia.
the class SpeakersListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(SpeakerViewHolder holder, final int position) {
Speaker current = getItem(position);
String organisation = Utils.checkStringEmpty(current.getOrganisation());
String country = Utils.checkStringEmpty(current.getCountry());
// adding distinct org and country (note size of array will never be greater than 2)
if (!TextUtils.isEmpty(organisation)) {
if (distinctOrganizations.isEmpty()) {
distinctOrganizations.add(organisation);
} else if (distinctOrganizations.size() == 1 && (!organisation.equals(distinctOrganizations.get(0)))) {
distinctOrganizations.add(organisation);
}
}
if (!Utils.isEmpty(country)) {
if (distinctCountry.isEmpty()) {
distinctCountry.add(country);
} else if (distinctCountry.size() == 1 && (!country.equals(distinctCountry.get(0)))) {
distinctCountry.add(country);
}
}
holder.bindSpeaker(current);
}
use of org.fossasia.openevent.data.Speaker in project open-event-android by fossasia.
the class SessionDetailActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_map:
showMap = true;
// Hide all the views except the frame layout and appbar layout
scrollView.setVisibility(View.GONE);
fabSessionBookmark.setVisibility(View.GONE);
menu.setGroupVisible(R.id.menu_group_session_detail, false);
text_title.setText(" ");
appBarLayout.setExpanded(false);
collapsingToolbarLayout.setTitle(location);
mapFragment.setVisibility(View.VISIBLE);
Bundle bundle = new Bundle();
bundle.putBoolean(ConstantStrings.IS_MAP_FRAGMENT_FROM_MAIN_ACTIVITY, false);
bundle.putString(ConstantStrings.LOCATION_NAME, location);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment mapFragment = StrategyRegistry.getInstance().getMapModuleStrategy().getMapModuleFactory().provideMapModule().provideMapFragment();
mapFragment.setArguments(bundle);
fragmentTransaction.replace(R.id.content_frame_session, mapFragment, FRAGMENT_TAG_REST).addToBackStack(null).commit();
return true;
case R.id.action_share:
StringBuilder speakersNameBuilder = new StringBuilder();
boolean firstSpeaker = true;
for (Speaker speaker : session.getSpeakers()) {
if (!firstSpeaker) {
speakersNameBuilder.append(", ");
}
speakersNameBuilder.append(speaker.getName());
firstSpeaker = false;
}
String startTime = DateConverter.formatDateWithDefault(DateConverter.FORMAT_DATE_COMPLETE, session.getStartsAt());
String endTime = DateConverter.formatDateWithDefault(DateConverter.FORMAT_DATE_COMPLETE, session.getEndsAt());
String shareText = String.format(getResources().getString(R.string.session_track_details) + " %s \n" + getResources().getString(R.string.title_details) + " %s \n" + getResources().getString(R.string.start_time_details) + " %s \n" + getResources().getString(R.string.end_time_details) + " %s \n" + getResources().getString(R.string.speakers_details) + " %s \n" + getResources().getString(R.string.location_details) + " %s ", trackName, title, startTime, endTime, speakersNameBuilder.toString(), location) + "\n" + getResources().getString(R.string.description_details) + " " + Views.fromHtml(session.getShortAbstract());
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, shareText);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_links)));
return true;
case R.id.action_add_to_calendar:
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.Events.TITLE, title);
intent.putExtra(CalendarContract.Events.DESCRIPTION, Html.fromHtml(session.getShortAbstract()).toString());
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, DateConverter.formatDateWithDefault(DateConverter.FORMAT_24H, session.getStartsAt()));
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, DateConverter.formatDateWithDefault(DateConverter.FORMAT_24H, session.getEndsAt()));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(this, "This device does not have a calendar app installed", Toast.LENGTH_SHORT).show();
}
default:
}
return super.onOptionsItemSelected(item);
}
use of org.fossasia.openevent.data.Speaker in project open-event-android by fossasia.
the class MainActivity method handleJsonEvent.
@Subscribe
public void handleJsonEvent(final JsonReadEvent jsonReadEvent) {
final String name = jsonReadEvent.getName();
final String json = jsonReadEvent.getJson();
disposable.add(Completable.fromAction(() -> {
ObjectMapper objectMapper = APIClient.getObjectMapper();
// Need separate instance for background thread
Realm realm = Realm.getDefaultInstance();
RealmDataRepository realmDataRepository = RealmDataRepository.getInstance(realm);
switch(name) {
case ConstantStrings.EVENT:
{
Event event = objectMapper.readValue(json, Event.class);
saveEventDates(event);
realmDataRepository.saveEvent(event).subscribe();
realmDataRepository.saveEvent(event).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new EventDownloadEvent(true));
break;
}
case ConstantStrings.TRACKS:
{
List<Track> tracks = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Track.class));
realmDataRepository.saveTracks(tracks).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new TracksDownloadEvent(true));
break;
}
case ConstantStrings.SESSIONS:
{
List<Session> sessions = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Session.class));
for (Session current : sessions) {
current.setStartDate(current.getStartsAt().split("T")[0]);
}
realmDataRepository.saveSessions(sessions).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SessionDownloadEvent(true));
break;
}
case ConstantStrings.SPEAKERS:
{
List<Speaker> speakers = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Speaker.class));
realmRepo.saveSpeakers(speakers).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SpeakerDownloadEvent(true));
break;
}
case ConstantStrings.SPONSORS:
{
List<Sponsor> sponsors = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Sponsor.class));
realmRepo.saveSponsors(sponsors).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SponsorDownloadEvent(true));
break;
}
case ConstantStrings.MICROLOCATIONS:
{
List<Microlocation> microlocations = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, Microlocation.class));
realmRepo.saveLocations(microlocations).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new MicrolocationDownloadEvent(true));
break;
}
case ConstantStrings.SESSION_TYPES:
{
List<SessionType> sessionTypes = objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, SessionType.class));
realmRepo.saveSessionTypes(sessionTypes).subscribe();
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new SessionTypesDownloadEvent(true));
break;
}
default:
}
realm.close();
}).observeOn(Schedulers.computation()).subscribe(() -> Timber.d("Saved event from JSON"), throwable -> {
throwable.printStackTrace();
Timber.e(throwable);
StrategyRegistry.getInstance().getEventBusStrategy().postEventOnUIThread(new RetrofitError(throwable));
}));
}
use of org.fossasia.openevent.data.Speaker in project open-event-android by fossasia.
the class SpeakerViewHolder method bindSpeaker.
public void bindSpeaker(Speaker speaker) {
this.speaker = speaker;
String thumbnail = Utils.parseImageUri(this.speaker.getThumbnailImageUrl());
String name = Utils.checkStringEmpty(speaker.getName());
if (thumbnail == null)
thumbnail = Utils.parseImageUri(this.speaker.getPhotoUrl());
final Palette.PaletteAsyncListener paletteAsyncListener = palette -> {
Palette.Swatch swatch = palette.getVibrantSwatch();
if (speakerTextualInfo != null) {
if (swatch != null) {
// bitmap has vibrant swatch profile
speakerTextualInfo.setBackgroundColor(swatch.getRgb());
} else {
Palette.Swatch swatch2 = palette.getDarkMutedSwatch();
if (swatch2 != null) {
// bitmap has dark muted swatch profile
speakerTextualInfo.setBackgroundColor(swatch2.getRgb());
} else {
speakerTextualInfo.setBackgroundColor(ContextCompat.getColor(context, R.color.color_primary_dark));
}
}
}
};
RequestCreator requestCreator = StrategyRegistry.getInstance().getHttpStrategy().getPicassoWithCache().load(thumbnail);
TextDrawable drawable;
if (isImageCircle) {
requestCreator.transform(new CircleTransform());
drawable = Views.getTextDrawableBuilder().round().build(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
} else {
drawable = Views.getTextDrawableBuilder().buildRect(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
}
final Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
speakerImage.setImageBitmap(bitmap);
if (speakerTextualInfo != null) {
Palette.from(bitmap).generate(paletteAsyncListener);
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
speakerImage.setImageDrawable(drawable);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
speakerImage.setImageDrawable(drawable);
}
};
requestCreator.into(target);
setStringField(speakerName, name);
setStringField(speakerDesignation, String.format("%s %s", speaker.getPosition(), speaker.getOrganisation()));
setStringField(speakerCountry, speaker.getCountry());
}
Aggregations