Skip to content

Commit 031e53c

Browse files
author
Vivek Maskara
authored
Merge pull request #1024 from neslihanturan/displayNotificationsUI
UI to display notifications
2 parents 0aa20ef + 7abb530 commit 031e53c

16 files changed

+357
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
android:label="@string/title_activity_nearby"
8888
android:parentActivityName=".contributions.ContributionsActivity" />
8989

90+
<activity
91+
android:name=".notification.NotificationActivity"
92+
android:label="@string/navigation_item_notification" />
93+
9094
<service android:name=".upload.UploadService" />
9195

9296
<service

app/src/main/java/fr/free/nrw/commons/di/ActivityBuilderModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import fr.free.nrw.commons.auth.SignupActivity;
99
import fr.free.nrw.commons.contributions.ContributionsActivity;
1010
import fr.free.nrw.commons.nearby.NearbyActivity;
11+
import fr.free.nrw.commons.notification.NotificationActivity;
1112
import fr.free.nrw.commons.settings.SettingsActivity;
1213
import fr.free.nrw.commons.upload.MultipleShareActivity;
1314
import fr.free.nrw.commons.upload.ShareActivity;
@@ -43,4 +44,6 @@ public abstract class ActivityBuilderModule {
4344
@ContributesAndroidInjector
4445
abstract NearbyActivity bindNearbyActivity();
4546

47+
@ContributesAndroidInjector
48+
abstract NotificationActivity bindNotificationActivity();
4649
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package fr.free.nrw.commons.notification;
2+
3+
/**
4+
* Created by root on 18.12.2017.
5+
*/
6+
7+
public class Notification {
8+
public NotificationType notificationType;
9+
public String notificationText;
10+
11+
12+
Notification (NotificationType notificationType, String notificationText) {
13+
this.notificationType = notificationType;
14+
this.notificationText = notificationText;
15+
}
16+
17+
18+
public enum NotificationType {
19+
/* Added for test purposes, needs to be rescheduled after implementing
20+
fetching notifications from server */
21+
edit,
22+
mention,
23+
message,
24+
block;
25+
}
26+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package fr.free.nrw.commons.notification;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.support.v7.widget.LinearLayoutManager;
6+
import android.support.v7.widget.RecyclerView;
7+
8+
import butterknife.BindView;
9+
import butterknife.ButterKnife;
10+
import butterknife.Optional;
11+
import fr.free.nrw.commons.R;
12+
import fr.free.nrw.commons.theme.NavigationBaseActivity;
13+
14+
/**
15+
* Created by root on 18.12.2017.
16+
*/
17+
18+
public class NotificationActivity extends NavigationBaseActivity {
19+
NotificationAdapterFactory notificationAdapterFactory;
20+
21+
@Nullable
22+
@BindView(R.id.listView) RecyclerView recyclerView;
23+
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_notification);
29+
ButterKnife.bind(this);
30+
initListView();
31+
addNotifications();
32+
initDrawer();
33+
}
34+
35+
private void initListView() {
36+
recyclerView = findViewById(R.id.listView);
37+
recyclerView.setLayoutManager(new LinearLayoutManager(this));
38+
notificationAdapterFactory = new NotificationAdapterFactory(new NotificationRenderer.NotificationClicked() {
39+
@Override
40+
public void notificationClicked(Notification notification) {
41+
42+
}
43+
});
44+
}
45+
46+
private void addNotifications() {
47+
48+
recyclerView.setAdapter(notificationAdapterFactory.create(NotificationController.loadNotifications()));
49+
}
50+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package fr.free.nrw.commons.notification;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.pedrogomez.renderers.ListAdapteeCollection;
6+
import com.pedrogomez.renderers.RVRendererAdapter;
7+
import com.pedrogomez.renderers.RendererBuilder;
8+
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
/**
13+
* Created by root on 19.12.2017.
14+
*/
15+
16+
class NotificationAdapterFactory {
17+
private NotificationRenderer.NotificationClicked listener;
18+
19+
NotificationAdapterFactory(@NonNull NotificationRenderer.NotificationClicked listener) {
20+
this.listener = listener;
21+
}
22+
23+
public RVRendererAdapter<Notification> create(List<Notification> notifications) {
24+
RendererBuilder<Notification> builder = new RendererBuilder<Notification>()
25+
.bind(Notification.class, new NotificationRenderer(listener));
26+
ListAdapteeCollection<Notification> collection = new ListAdapteeCollection<>(
27+
notifications != null ? notifications : Collections.<Notification>emptyList());
28+
return new RVRendererAdapter<>(builder, collection);
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package fr.free.nrw.commons.notification;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* Created by root on 19.12.2017.
8+
*/
9+
10+
public class NotificationController {
11+
12+
public static List<Notification> loadNotifications() {
13+
List<Notification> notifications = new ArrayList<>();
14+
notifications.add(new Notification(Notification.NotificationType.message, "notification 1"));
15+
notifications.add(new Notification(Notification.NotificationType.edit, "notification 2"));
16+
notifications.add(new Notification(Notification.NotificationType.mention, "notification 3"));
17+
notifications.add(new Notification(Notification.NotificationType.message, "notification 4"));
18+
notifications.add(new Notification(Notification.NotificationType.edit, "notification 5"));
19+
notifications.add(new Notification(Notification.NotificationType.mention, "notification 6"));
20+
notifications.add(new Notification(Notification.NotificationType.message, "notification 7"));
21+
return notifications;
22+
}
23+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package fr.free.nrw.commons.notification;
2+
3+
import android.view.LayoutInflater;
4+
import android.view.View;
5+
import android.view.ViewGroup;
6+
import android.widget.ImageView;
7+
import android.widget.TextView;
8+
9+
import com.pedrogomez.renderers.Renderer;
10+
11+
import butterknife.BindView;
12+
import butterknife.ButterKnife;
13+
import fr.free.nrw.commons.R;
14+
15+
/**
16+
* Created by root on 19.12.2017.
17+
*/
18+
19+
public class NotificationRenderer extends Renderer<Notification> {
20+
@BindView(R.id.title) TextView title;
21+
@BindView(R.id.description) TextView description;
22+
@BindView(R.id.time) TextView time;
23+
@BindView(R.id.icon) ImageView icon;
24+
private NotificationClicked listener;
25+
26+
27+
NotificationRenderer(NotificationClicked listener) {
28+
this.listener = listener;
29+
}
30+
31+
@Override
32+
protected void setUpView(View view) { }
33+
34+
@Override
35+
protected void hookListeners(View rootView) {
36+
rootView.setOnClickListener(v -> listener.notificationClicked(getContent()));
37+
}
38+
39+
@Override
40+
protected View inflate(LayoutInflater layoutInflater, ViewGroup viewGroup) {
41+
View inflatedView = layoutInflater.inflate(R.layout.item_notification, viewGroup, false);
42+
ButterKnife.bind(this, inflatedView);
43+
return inflatedView;
44+
}
45+
46+
@Override
47+
public void render() {
48+
Notification notification = getContent();
49+
title.setText(notification.notificationText);
50+
time.setText("3d");
51+
description.setText("Example notification description");
52+
switch (notification.notificationType) {
53+
case edit:
54+
icon.setImageResource(R.drawable.ic_edit_black_24dp);
55+
break;
56+
case message:
57+
icon.setImageResource(R.drawable.ic_message_black_24dp);
58+
break;
59+
case mention:
60+
icon.setImageResource(R.drawable.ic_chat_bubble_black_24px);
61+
break;
62+
default:
63+
icon.setImageResource(R.drawable.round_icon_unknown);
64+
}
65+
}
66+
67+
public interface NotificationClicked{
68+
void notificationClicked(Notification notification);
69+
}
70+
}

app/src/main/java/fr/free/nrw/commons/theme/NavigationBaseActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import fr.free.nrw.commons.auth.LoginActivity;
2828
import fr.free.nrw.commons.contributions.ContributionsActivity;
2929
import fr.free.nrw.commons.nearby.NearbyActivity;
30+
import fr.free.nrw.commons.notification.NotificationActivity;
3031
import fr.free.nrw.commons.settings.SettingsActivity;
3132
import timber.log.Timber;
3233

@@ -143,6 +144,10 @@ public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
143144
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
144145
.show();
145146
return true;
147+
case R.id.action_notifications:
148+
drawerLayout.closeDrawer(navigationView);
149+
startActivityWithFlags(this, NotificationActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
150+
return true;
146151
default:
147152
Timber.e("Unknown option [%s] selected from the navigation menu", itemId);
148153
return false;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:pathData="M4,2C2.9,2 2,2.9 2,4L2,22L6,18L20,18C21.1,18 22,17.1 22,16L22,4C22,2.9 21.1,2 20,2L4,2zM12.496,4.098C13.408,4.098 14.236,4.273 14.98,4.623C15.725,4.969 16.347,5.47 16.848,6.125C17.153,6.524 17.384,6.956 17.539,7.424C17.698,7.888 17.775,8.376 17.775,8.889C17.775,9.991 17.444,10.849 16.781,11.459C16.118,12.069 15.183,12.375 13.975,12.375L13.736,12.375L13.736,11.434C13.614,11.722 13.417,11.949 13.145,12.111C12.876,12.27 12.559,12.35 12.197,12.35C11.497,12.35 10.928,12.098 10.488,11.594C10.053,11.085 9.836,10.423 9.836,9.609C9.836,8.796 10.055,8.134 10.494,7.625C10.934,7.116 11.501,6.863 12.197,6.863C12.559,6.863 12.876,6.945 13.145,7.107C13.417,7.27 13.614,7.496 13.736,7.785L13.736,6.984L15.012,6.984L15.012,11.215C15.516,11.138 15.912,10.895 16.201,10.488C16.49,10.077 16.635,9.553 16.635,8.914C16.635,8.507 16.575,8.125 16.457,7.771C16.339,7.413 16.16,7.086 15.92,6.789C15.533,6.293 15.051,5.911 14.469,5.643C13.891,5.374 13.263,5.238 12.588,5.238C12.116,5.238 11.664,5.302 11.232,5.428C10.801,5.55 10.403,5.731 10.037,5.971C9.435,6.369 8.965,6.887 8.627,7.521C8.293,8.152 8.127,8.836 8.127,9.572C8.127,10.179 8.234,10.748 8.449,11.281C8.669,11.81 8.986,12.279 9.396,12.686C9.803,13.084 10.268,13.388 10.793,13.596C11.322,13.807 11.886,13.912 12.484,13.912C12.997,13.912 13.511,13.816 14.023,13.625C14.536,13.434 14.972,13.175 15.334,12.85L15.258,14.324C14.96,14.491 14.648,14.63 14.322,14.742C13.724,14.954 13.115,15.061 12.496,15.061C11.743,15.061 11.035,14.925 10.367,14.656C9.7,14.392 9.105,14.007 8.584,13.498C8.063,12.989 7.667,12.4 7.395,11.732C7.122,11.061 6.984,10.341 6.984,9.572C6.984,8.832 7.124,8.126 7.4,7.455C7.677,6.784 8.071,6.194 8.584,5.686C9.097,5.181 9.694,4.79 10.373,4.514C11.057,4.237 11.764,4.098 12.496,4.098zM12.412,7.998C12.054,7.998 11.766,8.143 11.551,8.432C11.339,8.716 11.232,9.105 11.232,9.598C11.232,10.098 11.339,10.492 11.551,10.781C11.766,11.07 12.058,11.215 12.424,11.215C12.786,11.215 13.075,11.07 13.291,10.781C13.507,10.488 13.613,10.094 13.613,9.598C13.613,9.105 13.503,8.716 13.283,8.432C13.068,8.143 12.778,7.998 12.412,7.998z"
8+
android:fillColor="#000000"/>
9+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
9+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/>
9+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FF000000"
8+
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z"/>
9+
</vector>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/drawer_layout"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<RelativeLayout
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent">
11+
12+
<include
13+
android:id="@+id/toolbar"
14+
layout="@layout/toolbar"
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content" />
17+
18+
<android.support.v7.widget.RecyclerView
19+
android:id="@+id/listView"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent"
22+
android:layout_below="@id/toolbar"
23+
/>
24+
</RelativeLayout>
25+
26+
<android.support.design.widget.NavigationView
27+
android:id="@+id/navigation_view"
28+
android:layout_width="wrap_content"
29+
android:layout_height="match_parent"
30+
android:layout_gravity="start"
31+
app:headerLayout="@layout/drawer_header"
32+
app:menu="@menu/drawer"/>
33+
34+
</android.support.v4.widget.DrawerLayout>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:foreground="?selectableItemBackground"
7+
android:minHeight="72dp"
8+
>
9+
10+
<ImageView
11+
android:id="@+id/icon"
12+
android:layout_width="40dp"
13+
android:layout_height="40dp"
14+
android:layout_marginLeft="16dp"
15+
android:layout_marginStart="16dp"
16+
android:layout_marginTop="16dp"
17+
android:background="@android:color/white"
18+
android:contentDescription="@string/no_image_found"
19+
android:scaleType="centerCrop"
20+
android:src="@drawable/empty_photo"
21+
android:tint="@color/primaryDarkColor"
22+
/>
23+
24+
<TextView
25+
android:id="@+id/time"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:layout_alignParentEnd="true"
29+
android:layout_alignParentRight="true"
30+
android:layout_marginLeft="16dp"
31+
android:layout_marginRight="16dp"
32+
android:layout_marginTop="16dp"
33+
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
34+
tools:text="@string/placeholder_place_distance"
35+
/>
36+
37+
<TextView
38+
android:id="@+id/title"
39+
android:layout_width="match_parent"
40+
android:layout_height="wrap_content"
41+
android:layout_alignTop="@id/time"
42+
android:layout_marginLeft="16dp"
43+
android:layout_marginStart="16dp"
44+
android:layout_toEndOf="@id/icon"
45+
android:layout_toLeftOf="@id/time"
46+
android:layout_toRightOf="@id/icon"
47+
android:layout_toStartOf="@id/time"
48+
android:ellipsize="end"
49+
android:maxLines="2"
50+
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
51+
tools:text="@string/placeholder_place_name"
52+
/>
53+
54+
<TextView
55+
android:id="@+id/description"
56+
android:layout_width="match_parent"
57+
android:layout_height="wrap_content"
58+
android:layout_alignEnd="@id/time"
59+
android:layout_alignLeft="@id/title"
60+
android:layout_alignRight="@id/time"
61+
android:layout_alignStart="@id/title"
62+
android:layout_below="@id/title"
63+
android:layout_marginBottom="16dp"
64+
android:ellipsize="end"
65+
android:maxLines="4"
66+
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
67+
tools:text="@string/placeholder_place_description"
68+
/>
69+
70+
</RelativeLayout>

0 commit comments

Comments
 (0)