Revert "Revert "Merge pull request #1024 from neslihanturan/displayNotificationsUI""

This reverts commit d253db5444.
This commit is contained in:
maskara 2018-01-21 14:54:25 +05:30
parent b21d1e3fbb
commit d78c7befbd
16 changed files with 357 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.auth.SignupActivity;
import fr.free.nrw.commons.contributions.ContributionsActivity;
import fr.free.nrw.commons.nearby.NearbyActivity;
import fr.free.nrw.commons.notification.NotificationActivity;
import fr.free.nrw.commons.settings.SettingsActivity;
import fr.free.nrw.commons.upload.MultipleShareActivity;
import fr.free.nrw.commons.upload.ShareActivity;
@ -43,4 +44,6 @@ public abstract class ActivityBuilderModule {
@ContributesAndroidInjector
abstract NearbyActivity bindNearbyActivity();
@ContributesAndroidInjector
abstract NotificationActivity bindNotificationActivity();
}

View file

@ -0,0 +1,26 @@
package fr.free.nrw.commons.notification;
/**
* Created by root on 18.12.2017.
*/
public class Notification {
public NotificationType notificationType;
public String notificationText;
Notification (NotificationType notificationType, String notificationText) {
this.notificationType = notificationType;
this.notificationText = notificationText;
}
public enum NotificationType {
/* Added for test purposes, needs to be rescheduled after implementing
fetching notifications from server */
edit,
mention,
message,
block;
}
}

View file

@ -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()));
}
}

View file

@ -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<Notification> create(List<Notification> notifications) {
RendererBuilder<Notification> builder = new RendererBuilder<Notification>()
.bind(Notification.class, new NotificationRenderer(listener));
ListAdapteeCollection<Notification> collection = new ListAdapteeCollection<>(
notifications != null ? notifications : Collections.<Notification>emptyList());
return new RVRendererAdapter<>(builder, collection);
}
}

View file

@ -0,0 +1,23 @@
package fr.free.nrw.commons.notification;
import java.util.ArrayList;
import java.util.List;
/**
* Created by root on 19.12.2017.
*/
public class NotificationController {
public static List<Notification> loadNotifications() {
List<Notification> notifications = new ArrayList<>();
notifications.add(new Notification(Notification.NotificationType.message, "notification 1"));
notifications.add(new Notification(Notification.NotificationType.edit, "notification 2"));
notifications.add(new Notification(Notification.NotificationType.mention, "notification 3"));
notifications.add(new Notification(Notification.NotificationType.message, "notification 4"));
notifications.add(new Notification(Notification.NotificationType.edit, "notification 5"));
notifications.add(new Notification(Notification.NotificationType.mention, "notification 6"));
notifications.add(new Notification(Notification.NotificationType.message, "notification 7"));
return notifications;
}
}

View file

@ -0,0 +1,70 @@
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<Notification> {
@BindView(R.id.title) TextView title;
@BindView(R.id.description) TextView description;
@BindView(R.id.time) TextView time;
@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();
title.setText(notification.notificationText);
time.setText("3d");
description.setText("Example notification description");
switch (notification.notificationType) {
case edit:
icon.setImageResource(R.drawable.ic_edit_black_24dp);
break;
case message:
icon.setImageResource(R.drawable.ic_message_black_24dp);
break;
case mention:
icon.setImageResource(R.drawable.ic_chat_bubble_black_24px);
break;
default:
icon.setImageResource(R.drawable.round_icon_unknown);
}
}
public interface NotificationClicked{
void notificationClicked(Notification notification);
}
}

View file

@ -27,6 +27,7 @@ import fr.free.nrw.commons.auth.AccountUtil;
import fr.free.nrw.commons.auth.LoginActivity;
import fr.free.nrw.commons.contributions.ContributionsActivity;
import fr.free.nrw.commons.nearby.NearbyActivity;
import fr.free.nrw.commons.notification.NotificationActivity;
import fr.free.nrw.commons.settings.SettingsActivity;
import timber.log.Timber;
@ -143,6 +144,10 @@ public abstract class NavigationBaseActivity extends BaseActivity
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
.show();
return true;
case R.id.action_notifications:
drawerLayout.closeDrawer(navigationView);
startActivityWithFlags(this, NotificationActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
return true;
default:
Timber.e("Unknown option [%s] selected from the navigation menu", itemId);
return false;