Skip to content

Commit

Permalink
feat: Implement notifications section
Browse files Browse the repository at this point in the history
  • Loading branch information
ShridharGoel committed Jun 7, 2019
1 parent e0d2a92 commit 28d9939
Show file tree
Hide file tree
Showing 21 changed files with 663 additions and 2 deletions.
Expand Up @@ -7,7 +7,9 @@
import com.eventyay.organizer.data.image.ImageUploadApi;
import com.eventyay.organizer.data.faq.FaqApi;
import com.eventyay.organizer.data.feedback.FeedbackApi;
import com.eventyay.organizer.data.notification.NotificationApi;
import com.eventyay.organizer.data.order.OrderApi;
import com.eventyay.organizer.data.role.RoleApi;
import com.eventyay.organizer.data.session.SessionApi;
import com.eventyay.organizer.data.speaker.SpeakerApi;
import com.eventyay.organizer.data.speakerscall.SpeakersCallApi;
Expand Down Expand Up @@ -114,4 +116,16 @@ OrderApi providesOrderApi(Retrofit retrofit) {
ImageUploadApi providesImageUploadApi(Retrofit retrofit) {
return retrofit.create(ImageUploadApi.class);
}

@Provides
@Singleton
RoleApi providesRoleApi(Retrofit retrofit) {
return retrofit.create(RoleApi.class);
}

@Provides
@Singleton
NotificationApi providesNotificationApi(Retrofit retrofit) {
return retrofit.create(NotificationApi.class);
}
}
Expand Up @@ -6,6 +6,7 @@
import com.eventyay.organizer.data.db.DbFlowDatabaseChangeListener;
import com.eventyay.organizer.data.event.Event;
import com.eventyay.organizer.data.faq.Faq;
import com.eventyay.organizer.data.notification.Notification;
import com.eventyay.organizer.data.session.Session;
import com.eventyay.organizer.data.speaker.Speaker;
import com.eventyay.organizer.data.speakerscall.SpeakersCall;
Expand Down Expand Up @@ -68,4 +69,9 @@ DatabaseChangeListener<SpeakersCall> providesSpeakerCallChangeListener() {
DatabaseChangeListener<Event> providesEventChangeListener() {
return new DbFlowDatabaseChangeListener<>(Event.class);
}

@Provides
DatabaseChangeListener<Notification> providesNotificationsChangeListener() {
return new DbFlowDatabaseChangeListener<>(Notification.class);
}
}
Expand Up @@ -10,8 +10,11 @@
import com.eventyay.organizer.data.faq.Faq;
import com.eventyay.organizer.data.feedback.Feedback;
import com.eventyay.organizer.data.network.HostSelectionInterceptor;
import com.eventyay.organizer.data.notification.Notification;
import com.eventyay.organizer.data.order.Order;
import com.eventyay.organizer.data.order.OrderStatistics;
import com.eventyay.organizer.data.role.Role;
import com.eventyay.organizer.data.role.RoleInvite;
import com.eventyay.organizer.data.session.Session;
import com.eventyay.organizer.data.speaker.Speaker;
import com.eventyay.organizer.data.speakerscall.SpeakersCall;
Expand Down Expand Up @@ -64,7 +67,8 @@ ObjectMapper providesObjectMapper() {
Class[] providesMappedClasses() {
return new Class[]{Event.class, Attendee.class, Ticket.class, User.class, EventStatistics.class,
Faq.class, Copyright.class, Feedback.class, Track.class, Session.class, Sponsor.class,
Speaker.class, SpeakersCall.class, Order.class, OrderStatistics.class, OnSiteTicket.class};
Speaker.class, SpeakersCall.class, Order.class, OrderStatistics.class, OnSiteTicket.class,
RoleInvite.class, Role.class, Notification.class};
}

@Provides
Expand Down
Expand Up @@ -12,8 +12,12 @@
import com.eventyay.organizer.data.faq.FaqRepositoryImpl;
import com.eventyay.organizer.data.feedback.FeedbackRepository;
import com.eventyay.organizer.data.feedback.FeedbackRepositoryImpl;
import com.eventyay.organizer.data.notification.NotificationRepository;
import com.eventyay.organizer.data.notification.NotificationRepositoryImpl;
import com.eventyay.organizer.data.order.OrderRepository;
import com.eventyay.organizer.data.order.OrderRepositoryImpl;
import com.eventyay.organizer.data.role.RoleRepository;
import com.eventyay.organizer.data.role.RoleRepositoryImpl;
import com.eventyay.organizer.data.session.SessionRepository;
import com.eventyay.organizer.data.session.SessionRepositoryImpl;
import com.eventyay.organizer.data.speaker.SpeakerRepository;
Expand Down Expand Up @@ -93,4 +97,11 @@ public abstract class RepoModule {
@Singleton
abstract OrderRepository bindsOrderRepository(OrderRepositoryImpl orderRepository);

@Binds
@Singleton
abstract RoleRepository bindsRoleRepository(RoleRepositoryImpl roleRepository);

@Binds
@Singleton
abstract NotificationRepository bindsNotificationRepository(NotificationRepositoryImpl notificationRepository);
}
Expand Up @@ -20,12 +20,15 @@
import com.eventyay.organizer.core.feedback.list.FeedbackListViewModel;
import com.eventyay.organizer.core.main.EventViewModel;
import com.eventyay.organizer.core.main.OrganizerViewModel;
import com.eventyay.organizer.core.notification.list.NotificationsViewModel;
import com.eventyay.organizer.core.orders.create.CreateOrderViewModel;
import com.eventyay.organizer.core.orders.detail.OrderDetailViewModel;
import com.eventyay.organizer.core.orders.list.OrdersViewModel;
import com.eventyay.organizer.core.organizer.detail.OrganizerDetailViewModel;
import com.eventyay.organizer.core.organizer.password.ChangePasswordViewModel;
import com.eventyay.organizer.core.organizer.update.UpdateOrganizerInfoViewModel;
import com.eventyay.organizer.core.role.list.RoleListViewModel;
import com.eventyay.organizer.core.role.invite.RoleInviteViewModel;
import com.eventyay.organizer.core.settings.autocheckin.AutoCheckInViewModel;
import com.eventyay.organizer.core.settings.restriction.TicketSettingsViewModel;
import com.eventyay.organizer.core.share.ShareEventViewModel;
Expand Down Expand Up @@ -204,6 +207,21 @@ public abstract class ViewModelModule {
@ViewModelKey(FeedbackListViewModel.class)
public abstract ViewModel bindFeedbackListViewModel(FeedbackListViewModel feedbackListViewModel);

@Binds
@IntoMap
@ViewModelKey(RoleInviteViewModel.class)
public abstract ViewModel bindRoleInvitesViewModel(RoleInviteViewModel roleInviteViewModel);

@Binds
@IntoMap
@ViewModelKey(RoleListViewModel.class)
public abstract ViewModel bindRoleListViewModel(RoleListViewModel roleListViewModel);

@Binds
@IntoMap
@ViewModelKey(NotificationsViewModel.class)
public abstract ViewModel bindNotificationsViewModel(NotificationsViewModel notificationsViewModel);

@Binds
public abstract ViewModelProvider.Factory bindViewModelFactory(OrgaViewModelFactory factory);

Expand Down
Expand Up @@ -10,6 +10,7 @@
import com.eventyay.organizer.core.faq.create.CreateFaqFragment;
import com.eventyay.organizer.core.faq.list.FaqListFragment;
import com.eventyay.organizer.core.feedback.list.FeedbackListFragment;
import com.eventyay.organizer.core.notification.list.NotificationsFragment;
import com.eventyay.organizer.core.orders.detail.OrderDetailFragment;
import com.eventyay.organizer.core.orders.list.OrdersFragment;
import com.eventyay.organizer.core.settings.SettingsFragment;
Expand Down Expand Up @@ -119,5 +120,10 @@ public abstract class MainFragmentBuildersModule {
// Share
@ContributesAndroidInjector
abstract ShareEventFragment contributeShareEventFragment();

// Notification

@ContributesAndroidInjector
abstract NotificationsFragment contributeNotificationsFragment();
}

Expand Up @@ -21,6 +21,7 @@
import com.eventyay.organizer.common.mvp.view.BaseFragment;
import com.eventyay.organizer.core.event.create.CreateEventActivity;
import com.eventyay.organizer.core.event.list.pager.ListPageFragment;
import com.eventyay.organizer.core.notification.list.NotificationsFragment;
import com.eventyay.organizer.data.ContextUtils;
import com.eventyay.organizer.databinding.EventListFragmentBinding;
import com.eventyay.organizer.ui.ViewUtils;
Expand Down Expand Up @@ -116,6 +117,14 @@ public void openCreateEventFragment() {
startActivity(intent);
}

public void openNotificationsFragment() {

getFragmentManager().beginTransaction()
.replace(R.id.fragment_container, NotificationsFragment.newInstance())
.addToBackStack(null)
.commit();
}

@Override
public void onStop() {
super.onStop();
Expand Down Expand Up @@ -146,6 +155,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.sortByEventDate:
eventsViewModel.sortBy(SORTBYDATE);
return true;
case R.id.notifications:
openNotificationsFragment();
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down
@@ -0,0 +1,44 @@
package com.eventyay.organizer.core.notification.list;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.eventyay.organizer.R;
import com.eventyay.organizer.core.notification.list.viewholder.NotificationsViewHolder;
import com.eventyay.organizer.data.notification.Notification;

import java.util.List;

public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsViewHolder> {

public final List<Notification> notifications;

public NotificationsAdapter(NotificationsViewModel notificationsViewModel) {
this.notifications = notificationsViewModel.getNotifications();
}

@NonNull
@Override
public NotificationsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
NotificationsViewHolder notificationsViewHolder= new NotificationsViewHolder(
DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()),
R.layout.notification_item, viewGroup, false));

return notificationsViewHolder;
}

@Override
public void onBindViewHolder(@NonNull NotificationsViewHolder notificationsViewHolder, int position) {
notificationsViewHolder.bind(notifications.get(position));
}

@Override
public int getItemCount() {
return notifications.size();
}

}
@@ -0,0 +1,147 @@
package com.eventyay.organizer.core.notification.list;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.eventyay.organizer.BR;
import com.eventyay.organizer.R;
import com.eventyay.organizer.common.mvp.view.BaseFragment;
import com.eventyay.organizer.data.notification.Notification;
import com.eventyay.organizer.databinding.NotificationsFragmentBinding;
import com.eventyay.organizer.ui.ViewUtils;

import java.util.List;

import javax.inject.Inject;

public class NotificationsFragment extends BaseFragment implements NotificationsView {

private Context context;

@Inject
ViewModelProvider.Factory viewModelFactory;

private NotificationsAdapter notificationsAdapter;
private NotificationsFragmentBinding binding;
private SwipeRefreshLayout refreshLayout;

private NotificationsViewModel notificationsViewModel;

public static NotificationsFragment newInstance() {
return new NotificationsFragment();
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

context = getContext();
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.notifications_fragment, container, false);
notificationsViewModel = ViewModelProviders.of(this, viewModelFactory).get(NotificationsViewModel.class);

return binding.getRoot();
}

@Override
public void onStart() {
super.onStart();
setupRecyclerView();
setupRefreshListener();
notificationsViewModel.getProgress().observe(this, this::showProgress);
notificationsViewModel.getSuccess().observe(this, this::showMessage);
notificationsViewModel.getError().observe(this, this::showError);
notificationsViewModel.getNotificationsLiveData().observe(this, this::showResults);
notificationsViewModel.loadNotifications(false);
notificationsViewModel.listenChanges();
}

@Override
protected int getTitle() {
return R.string.notifications;
}

@Override
public void onStop() {
super.onStop();
refreshLayout.setOnRefreshListener(null);
notificationsViewModel.getNotificationsChangeListener().stopListening();
}

private void setupRecyclerView() {

notificationsAdapter = new NotificationsAdapter(notificationsViewModel);

RecyclerView recyclerView = binding.notificationsRecyclerView;
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(notificationsAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
}


private void setupRefreshListener() {
refreshLayout = binding.swipeContainer;
refreshLayout.setColorSchemeColors(getResources().getColor(R.color.color_accent));
refreshLayout.setOnRefreshListener(() -> {
refreshLayout.setRefreshing(false);
notificationsViewModel.loadNotifications(true);
});
}

@Override
public void showError(String error) {
ViewUtils.showSnackbar(binding.getRoot(), error);
}

@Override
public void showProgress(boolean show) {
ViewUtils.showView(binding.progressBar, show);
}

@Override
public void onRefreshComplete(boolean success) {
refreshLayout.setRefreshing(false);
if (success)
ViewUtils.showSnackbar(binding.notificationsRecyclerView, R.string.refresh_complete);
}

private void showMessage(String message) {
ViewUtils.showSnackbar(binding.getRoot(), message);
}

@Override
public void showResults(List<Notification> notifications) {
if(notifications.isEmpty()) {
showEmptyView(true);
return;
} else {
showEmptyView(false);
}
notificationsAdapter.notifyDataSetChanged();
}

@Override
public void showEmptyView(boolean show) {
ViewUtils.showView(binding.emptyView, show);
}
}
@@ -0,0 +1,18 @@
package com.eventyay.organizer.core.notification.list;

import com.eventyay.organizer.data.notification.Notification;

import java.util.List;

public interface NotificationsView {

void showError(String error);

void showProgress(boolean show);

void onRefreshComplete(boolean success);

void showResults(List<Notification> notifications);

void showEmptyView(boolean show);
}

0 comments on commit 28d9939

Please sign in to comment.