Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement notifications section
- Loading branch information
1 parent
e0d2a92
commit 28d9939
Showing
21 changed files
with
663 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/eventyay/organizer/core/notification/list/NotificationsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
147 changes: 147 additions & 0 deletions
147
app/src/main/java/com/eventyay/organizer/core/notification/list/NotificationsFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/eventyay/organizer/core/notification/list/NotificationsView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Oops, something went wrong.