mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Check if user visited noifications activity after last notification came
This commit is contained in:
parent
a759741c86
commit
1906579d33
4 changed files with 42 additions and 47 deletions
|
|
@ -223,12 +223,12 @@ public class ContributionsActivity extends AuthenticatedActivity implements Frag
|
|||
pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
|
||||
}
|
||||
|
||||
public void updateNotificationIcon(int unreadNotificationListSize) {
|
||||
if (unreadNotificationListSize==0) {
|
||||
isThereUnreadNotifications = false;
|
||||
public void updateNotificationIcon(boolean isThereUnreadNotifications) {
|
||||
if (!isThereUnreadNotifications) {
|
||||
this.isThereUnreadNotifications = false;
|
||||
menu.findItem(R.id.notifications).setIcon(ContextCompat.getDrawable(this, R.drawable.ic_notifications_white_24dp));
|
||||
} else {
|
||||
isThereUnreadNotifications = true;
|
||||
this.isThereUnreadNotifications = true;
|
||||
menu.findItem(R.id.notifications).setIcon(ContextCompat.getDrawable(this, R.drawable.ic_notifications_white_with_marker));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -388,11 +388,11 @@ public class ContributionsFragment
|
|||
|
||||
/**
|
||||
* Updates notification indicator on toolbar to indicate there are unread notifications
|
||||
* @param unreadNotifications
|
||||
* @param isThereUnreadNotifications true if user checked notifications before last notification date
|
||||
*/
|
||||
public void updateNotificationsNotification(List<Notification> unreadNotifications) {
|
||||
public void updateNotificationsNotification(boolean isThereUnreadNotifications) {
|
||||
Log.d("deneme","notification updates are called");
|
||||
((ContributionsActivity)getActivity()).updateNotificationIcon(unreadNotifications.size());
|
||||
((ContributionsActivity)getActivity()).updateNotificationIcon(isThereUnreadNotifications);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.support.design.widget.Snackbar;
|
|||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RelativeLayout;
|
||||
|
|
@ -18,6 +19,7 @@ import com.pedrogomez.renderers.RVRendererAdapter;
|
|||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -89,7 +91,8 @@ public class NotificationActivity extends NavigationBaseActivity {
|
|||
Timber.d("Add notifications");
|
||||
|
||||
// Store when add notification is called last
|
||||
long currentDate = Calendar.getInstance().getTime().getTime();
|
||||
long currentDate = new Date(System.currentTimeMillis()).getTime();
|
||||
Log.d("denemeee", "current date"+currentDate);
|
||||
getSharedPreferences("prefs", MODE_PRIVATE).edit().putLong("last_read_notification_date", currentDate).apply();
|
||||
Timber.d("Set last notification read date to current date:"+ currentDate);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,24 @@
|
|||
package fr.free.nrw.commons.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import fr.free.nrw.commons.contributions.ContributionsFragment;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* This asynctask will check unread notifications after a date (date user check notifications last)
|
||||
*/
|
||||
|
||||
public class UnreadNotificationsCheckAsync extends AsyncTask<Void, Void, List<Notification>> {
|
||||
public class UnreadNotificationsCheckAsync extends AsyncTask<Void, Void, Notification> {
|
||||
|
||||
WeakReference<ContributionsActivity> context;
|
||||
NotificationController notificationController;
|
||||
|
|
@ -31,54 +30,47 @@ public class UnreadNotificationsCheckAsync extends AsyncTask<Void, Void, List<No
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<Notification> doInBackground(Void... voids) {
|
||||
List<Notification> unreadNotifications = null;
|
||||
protected Notification doInBackground(Void... voids) {
|
||||
Notification lastNotification = null;
|
||||
|
||||
Date currentDate = Calendar.getInstance().getTime();
|
||||
Date lastReadNotificationDateStored =
|
||||
new Date(context.get()
|
||||
.getSharedPreferences("prefs",0)
|
||||
.getLong("last_read_notification_date", 0));
|
||||
|
||||
if (currentDate.after(lastReadNotificationDateStored)) {
|
||||
Timber.d("You may have unread notifications since"+lastReadNotificationDateStored);
|
||||
Log.d("deneme","You may have unread notifications since"+lastReadNotificationDateStored +"++curr date is:"+currentDate);
|
||||
|
||||
//TODO: fetch latest notification of user and save latest notification date to shared preferences
|
||||
//TODO: pass latest notification update date here. So that you will get notifications after that date
|
||||
|
||||
try {
|
||||
unreadNotifications = findUnreadNotifications(notificationController.getNotifications());
|
||||
Log.d("deneme","notifications is:"+unreadNotifications);
|
||||
for (Notification notification : unreadNotifications) {
|
||||
Log.d("deneme", notification.notificationText);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
// This case is not possible ever?
|
||||
Timber.d("You read all notifications of your at"+lastReadNotificationDateStored +"++curr date is:"+currentDate);
|
||||
try {
|
||||
lastNotification = findLastNotification(notificationController.getNotifications());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return unreadNotifications;
|
||||
|
||||
return lastNotification;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Notification> unreadNotification) {
|
||||
super.onPostExecute(unreadNotification);
|
||||
protected void onPostExecute(Notification lastNotification) {
|
||||
super.onPostExecute(lastNotification);
|
||||
|
||||
Date lastNotificationCheckDate = new Date(context.get()
|
||||
.getSharedPreferences("prefs",0)
|
||||
.getLong("last_read_notification_date", 0));
|
||||
Timber.d("You may have unread notifications since"+lastNotificationCheckDate);
|
||||
|
||||
boolean isThereUnreadNotifications;
|
||||
|
||||
Date lastReadNotificationDate = new java.util.Date(Long.parseLong(lastNotification.dateWithYear)*1000);
|
||||
|
||||
if (lastNotificationCheckDate.before(lastReadNotificationDate)) {
|
||||
isThereUnreadNotifications = true;
|
||||
} else {
|
||||
isThereUnreadNotifications = false;
|
||||
}
|
||||
|
||||
// Check if activity is still running
|
||||
if (context.get().getWindow().getDecorView().isShown() && !context.get().isFinishing()) {
|
||||
// Check if fragment is not null and visible
|
||||
if (context.get().isContributionsFragmentVisible && context.get().contributionsActivityPagerAdapter.contributionsFragment != null) {
|
||||
(context.get().contributionsActivityPagerAdapter.contributionsFragment).updateNotificationsNotification(unreadNotification);
|
||||
(context.get().contributionsActivityPagerAdapter.contributionsFragment).updateNotificationsNotification(isThereUnreadNotifications);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Notification> findUnreadNotifications(List<Notification> allNotifications) {
|
||||
// TODO: only return notifications after last read date
|
||||
return allNotifications;
|
||||
private Notification findLastNotification(List<Notification> allNotifications) {
|
||||
return allNotifications.get(allNotifications.size()-1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue