Prevent double notifications
Check timelines for updates on resume
This commit is contained in:
parent
2bbd46e841
commit
daf7e6ed6a
|
@ -109,7 +109,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
|||
}
|
||||
|
||||
private void buildNotification(Notification body) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
Intent resultIntent = new Intent(this, MainActivity.class);
|
||||
resultIntent.putExtra("tab_position", 1);
|
||||
|
@ -121,7 +121,8 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
|||
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_notify)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(resultPendingIntent);
|
||||
.setContentIntent(resultPendingIntent)
|
||||
.setDefaults(0); // So it doesn't ring twice, notify only in Target callback
|
||||
|
||||
final Integer mId = (int)(System.currentTimeMillis() / 1000);
|
||||
|
||||
|
@ -129,6 +130,19 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
|||
@Override
|
||||
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
|
||||
builder.setLargeIcon(bitmap);
|
||||
|
||||
if (preferences.getBoolean("notificationAlertSound", true)) {
|
||||
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
|
||||
}
|
||||
|
||||
if (preferences.getBoolean("notificationStyleVibrate", false)) {
|
||||
builder.setVibrate(new long[] { 500, 500 });
|
||||
}
|
||||
|
||||
if (preferences.getBoolean("notificationStyleLight", false)) {
|
||||
builder.setLights(0xFF00FF8F, 300, 1000);
|
||||
}
|
||||
|
||||
((NotificationManager) (getSystemService(NOTIFICATION_SERVICE))).notify(mId, builder.build());
|
||||
}
|
||||
|
||||
|
@ -148,18 +162,6 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
|||
.placeholder(R.drawable.avatar_default)
|
||||
.into(mTarget);
|
||||
|
||||
if (preferences.getBoolean("notificationAlertSound", true)) {
|
||||
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
|
||||
}
|
||||
|
||||
if (preferences.getBoolean("notificationStyleVibrate", false)) {
|
||||
builder.setVibrate(new long[] { 500, 500 });
|
||||
}
|
||||
|
||||
if (preferences.getBoolean("notificationStyleLight", false)) {
|
||||
builder.setLights(0xFF00FF8F, 300, 1000);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
builder.setVisibility(android.app.Notification.VISIBILITY_PRIVATE);
|
||||
builder.setCategory(android.app.Notification.CATEGORY_SOCIAL);
|
||||
|
|
|
@ -117,6 +117,12 @@ public class NotificationsFragment extends SFragment implements
|
|||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
sendFetchNotificationsRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
|
||||
|
|
|
@ -138,6 +138,12 @@ public class TimelineFragment extends SFragment implements
|
|||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
sendFetchTimelineRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (jumpToTopAllowed()) {
|
||||
|
|
|
@ -21,20 +21,30 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ViewTagActivity extends BaseActivity {
|
||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_view_tag);
|
||||
|
||||
ButterKnife.bind(this);
|
||||
|
||||
String hashtag = getIntent().getStringExtra("hashtag");
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar bar = getSupportActionBar();
|
||||
|
||||
if (bar != null) {
|
||||
bar.setTitle(String.format(getString(R.string.title_tag), hashtag));
|
||||
bar.setDisplayHomeAsUpEnabled(true);
|
||||
bar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
|
@ -42,4 +52,15 @@ public class ViewTagActivity extends BaseActivity {
|
|||
fragmentTransaction.add(R.id.fragment_container, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home: {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue