-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from Popalay/popalay/notification-list
Implement Notification list
- Loading branch information
Showing
7 changed files
with
267 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
Houseclub/src/main/java/me/grishka/houseclub/api/methods/GetNotifications.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,22 @@ | ||
package me.grishka.houseclub.api.methods; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import me.grishka.houseclub.api.ClubhouseAPIRequest; | ||
import me.grishka.houseclub.api.model.Notification; | ||
|
||
public class GetNotifications extends ClubhouseAPIRequest<GetNotifications.Response>{ | ||
public GetNotifications(int userID, int pageSize, int page){ | ||
super("GET", "get_notifications", Response.class); | ||
queryParams=new HashMap<>(); | ||
queryParams.put("user_id", userID+""); | ||
queryParams.put("page_size", pageSize+""); | ||
queryParams.put("page", page+""); | ||
} | ||
|
||
public static class Response{ | ||
public List<Notification> notifications; | ||
public int count; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Houseclub/src/main/java/me/grishka/houseclub/api/model/Notification.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,16 @@ | ||
package me.grishka.houseclub.api.model; | ||
|
||
import java.util.Date; | ||
|
||
public class Notification { | ||
public int notificationId; | ||
public boolean inUnread; | ||
public User userProfile; | ||
public int eventId; | ||
public int type; | ||
public Date timeCreated; | ||
public String message; | ||
|
||
public static final int NOTIFICATION_TYPE_USER=1; | ||
public static final int NOTIFICATION_TYPE_EVENT=16; | ||
} |
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
158 changes: 158 additions & 0 deletions
158
Houseclub/src/main/java/me/grishka/houseclub/fragments/NotificationListFragment.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,158 @@ | ||
package me.grishka.houseclub.fragments; | ||
|
||
import android.app.Activity; | ||
import android.content.res.Configuration; | ||
import android.graphics.Bitmap; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.text.format.DateUtils; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import me.grishka.appkit.Nav; | ||
import me.grishka.appkit.fragments.BaseRecyclerFragment; | ||
import me.grishka.appkit.imageloader.ImageLoaderRecyclerAdapter; | ||
import me.grishka.appkit.imageloader.ImageLoaderViewHolder; | ||
import me.grishka.appkit.utils.BindableViewHolder; | ||
import me.grishka.appkit.views.UsableRecyclerView; | ||
import me.grishka.houseclub.R; | ||
import me.grishka.appkit.api.SimpleCallback; | ||
import me.grishka.houseclub.api.ClubhouseSession; | ||
import me.grishka.houseclub.api.methods.GetNotifications; | ||
import me.grishka.houseclub.api.model.FullUser; | ||
import me.grishka.houseclub.api.model.Notification; | ||
|
||
public class NotificationListFragment extends BaseRecyclerFragment<Notification>{ | ||
private NotificationListAdapter adapter; | ||
|
||
public NotificationListFragment(){ | ||
super(50); | ||
} | ||
|
||
@Override | ||
public void onAttach(Activity activity){ | ||
super.onAttach(activity); | ||
loadData(); | ||
setTitle(R.string.notifications_title); | ||
} | ||
|
||
@Override | ||
protected RecyclerView.Adapter getAdapter(){ | ||
if(adapter==null){ | ||
adapter=new NotificationListAdapter(); | ||
} | ||
return adapter; | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle savedInstanceState){ | ||
super.onViewCreated(view, savedInstanceState); | ||
getToolbar().setElevation(0); | ||
} | ||
|
||
@Override | ||
public void onConfigurationChanged(Configuration newConfig){ | ||
super.onConfigurationChanged(newConfig); | ||
getToolbar().setElevation(0); | ||
} | ||
|
||
@Override | ||
protected void doLoadData(int offset, int count){ | ||
currentRequest=new GetNotifications(getArguments().getInt("id"), 50, offset/50+1) | ||
.setCallback(new SimpleCallback<GetNotifications.Response>(this){ | ||
@Override | ||
public void onSuccess(GetNotifications.Response result){ | ||
currentRequest=null; | ||
onDataLoaded(result.notifications, data.size()+preloadedData.size()+result.notifications.size()<result.count); | ||
} | ||
}) | ||
.exec(); | ||
} | ||
|
||
private class NotificationListAdapter extends RecyclerView.Adapter<NotificationViewHolder> implements ImageLoaderRecyclerAdapter{ | ||
|
||
@NonNull | ||
@Override | ||
public NotificationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){ | ||
return new NotificationViewHolder(); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull NotificationViewHolder holder, int position){ | ||
holder.bind(data.get(position)); | ||
} | ||
|
||
@Override | ||
public int getItemCount(){ | ||
return data.size(); | ||
} | ||
|
||
@Override | ||
public int getImageCountForItem(int position){ | ||
return data.get(position).userProfile.photoUrl!=null ? 1 : 0; | ||
} | ||
|
||
@Override | ||
public String getImageURL(int position, int image){ | ||
return data.get(position).userProfile.photoUrl; | ||
} | ||
} | ||
|
||
private class NotificationViewHolder extends BindableViewHolder<Notification> implements ImageLoaderViewHolder, UsableRecyclerView.Clickable{ | ||
|
||
public TextView name, message, time; | ||
public Button followBtn; | ||
public ImageView photo; | ||
private Drawable placeholder=new ColorDrawable(0xFF808080); | ||
|
||
public NotificationViewHolder(){ | ||
super(getActivity(), R.layout.notification_list_row); | ||
|
||
name=findViewById(R.id.name); | ||
message=findViewById(R.id.message); | ||
time=findViewById(R.id.time); | ||
photo=findViewById(R.id.photo); | ||
} | ||
|
||
@Override | ||
public void onBind(Notification item){ | ||
itemView.setAlpha(item.inUnread?1F:0.5F); | ||
name.setText(item.userProfile.name); | ||
message.setText(item.message); | ||
time.setText(DateUtils.getRelativeTimeSpanString(item.timeCreated.getTime())); | ||
|
||
if(item.userProfile.photoUrl!=null) | ||
imgLoader.bindViewHolder(adapter, this, getAdapterPosition()); | ||
else | ||
photo.setImageDrawable(placeholder); | ||
} | ||
|
||
@Override | ||
public void setImage(int index, Bitmap bitmap){ | ||
photo.setImageBitmap(bitmap); | ||
} | ||
|
||
@Override | ||
public void clearImage(int index){ | ||
photo.setImageDrawable(placeholder); | ||
} | ||
|
||
@Override | ||
public void onClick(){ | ||
Bundle args=new Bundle(); | ||
args.putInt("id", item.userProfile.userId); | ||
Nav.go(getActivity(), ProfileFragment.class, args); | ||
} | ||
} | ||
} |
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,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#000" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
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" /> | ||
</vector> |
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,53 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:paddingLeft="16dp" | ||
android:paddingTop="8dp" | ||
android:paddingRight="16dp" | ||
android:paddingBottom="8dp"> | ||
|
||
<me.grishka.houseclub.views.SquircleImageView | ||
android:id="@+id/photo" | ||
android:layout_width="28dp" | ||
android:layout_height="28dp" | ||
android:layout_marginRight="12dp" | ||
tools:src="#0f0" /> | ||
|
||
<LinearLayout | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_vertical" | ||
android:layout_weight="1" | ||
android:layout_marginRight="4dp" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/name" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:ellipsize="end" | ||
android:fontFamily="sans-serif-medium" | ||
android:singleLine="true" | ||
android:textSize="14dp" | ||
tools:text="User Name" /> | ||
|
||
<TextView | ||
android:id="@+id/message" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textSize="13dp" | ||
tools:text="bio" /> | ||
|
||
</LinearLayout> | ||
|
||
<TextView | ||
android:id="@+id/time" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textSize="12dp" | ||
tools:text="18h ago" /> | ||
|
||
</LinearLayout> |
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