From 76ee338a200eea46223a4486a50cddc5c1b07c95 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Wed, 20 Dec 2017 19:28:36 +0300 Subject: [PATCH] Construct recyler list logic according to Renderers library of pedrovgs --- .../notification/NotificationActivity.java | 50 ++++++++++++++ .../NotificationAdapterFactory.java | 30 ++++++++ .../notification/NotificationRenderer.java | 69 +++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java create mode 100644 app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterFactory.java create mode 100644 app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java new file mode 100644 index 000000000..9da69e0eb --- /dev/null +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java @@ -0,0 +1,50 @@ +package fr.free.nrw.commons.notification; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.Optional; +import fr.free.nrw.commons.R; +import fr.free.nrw.commons.theme.NavigationBaseActivity; + +/** + * Created by root on 18.12.2017. + */ + +public class NotificationActivity extends NavigationBaseActivity { + NotificationAdapterFactory notificationAdapterFactory; + + @Nullable + @BindView(R.id.listView) RecyclerView recyclerView; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_notification); + ButterKnife.bind(this); + initListView(); + addNotifications(); + initDrawer(); + } + + private void initListView() { + recyclerView = findViewById(R.id.listView); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + notificationAdapterFactory = new NotificationAdapterFactory(new NotificationRenderer.NotificationClicked() { + @Override + public void notificationClicked(Notification notification) { + + } + }); + } + + private void addNotifications() { + + recyclerView.setAdapter(notificationAdapterFactory.create(NotificationController.loadNotifications())); + } +} diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterFactory.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterFactory.java new file mode 100644 index 000000000..83a60dcfb --- /dev/null +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationAdapterFactory.java @@ -0,0 +1,30 @@ +package fr.free.nrw.commons.notification; + +import android.support.annotation.NonNull; + +import com.pedrogomez.renderers.ListAdapteeCollection; +import com.pedrogomez.renderers.RVRendererAdapter; +import com.pedrogomez.renderers.RendererBuilder; + +import java.util.Collections; +import java.util.List; + +/** + * Created by root on 19.12.2017. + */ + +class NotificationAdapterFactory { + private NotificationRenderer.NotificationClicked listener; + + NotificationAdapterFactory(@NonNull NotificationRenderer.NotificationClicked listener) { + this.listener = listener; + } + + public RVRendererAdapter create(List notifications) { + RendererBuilder builder = new RendererBuilder() + .bind(Notification.class, new NotificationRenderer(listener)); + ListAdapteeCollection collection = new ListAdapteeCollection<>( + notifications != null ? notifications : Collections.emptyList()); + return new RVRendererAdapter<>(builder, collection); + } +} diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java new file mode 100644 index 000000000..201d00ff4 --- /dev/null +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java @@ -0,0 +1,69 @@ +package fr.free.nrw.commons.notification; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.pedrogomez.renderers.Renderer; + +import butterknife.BindView; +import butterknife.ButterKnife; +import fr.free.nrw.commons.R; + +/** + * Created by root on 19.12.2017. + */ + +public class NotificationRenderer extends Renderer { + @BindView(R.id.tvName) + TextView tvName; + @BindView(R.id.tvDesc) TextView tvDesc; + @BindView(R.id.distance) TextView distance; + @BindView(R.id.icon) + ImageView icon; + private NotificationClicked listener; + + + NotificationRenderer(NotificationClicked listener) { + this.listener = listener; + } + + @Override + protected void setUpView(View view) { } + + @Override + protected void hookListeners(View rootView) { + rootView.setOnClickListener(v -> listener.notificationClicked(getContent())); + } + + @Override + protected View inflate(LayoutInflater layoutInflater, ViewGroup viewGroup) { + View inflatedView = layoutInflater.inflate(R.layout.item_notification, viewGroup, false); + ButterKnife.bind(this, inflatedView); + return inflatedView; + } + + @Override + public void render() { + Notification notification = getContent(); + tvName.setText(notification.notificationText); + switch (notification.notificationType) { + case edit: + icon.setImageResource(R.drawable.round_icon_unknown); + case message: + icon.setImageResource(R.drawable.round_icon_unknown); + case mention: + icon.setImageResource(R.drawable.round_icon_unknown); + case block: + icon.setImageResource(R.drawable.round_icon_unknown); + default: + icon.setImageResource(R.drawable.round_icon_unknown); + } + } + + public interface NotificationClicked{ + void notificationClicked(Notification notification); + } +}