Fixes potential crashes
This commit is contained in:
parent
a1b2db241b
commit
a32d631ba8
|
@ -151,7 +151,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}else{
|
||||
newNotif++;
|
||||
updateNotifCounter();
|
||||
notificationsFragment.updateData(notification);
|
||||
notificationsFragment.refresh(notification);
|
||||
}
|
||||
}else {
|
||||
newNotif++;
|
||||
|
@ -165,7 +165,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}else{
|
||||
newHome++;
|
||||
updateHomeCounter();
|
||||
homeFragment.updateData(status);
|
||||
homeFragment.refresh(status);
|
||||
}
|
||||
}else{
|
||||
newHome++;
|
||||
|
@ -173,10 +173,12 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}else if(eventStreaming == StreamingUserAsyncTask.EventStreaming.DELETE){
|
||||
String id = b.getString("id");
|
||||
if(notificationsFragment.getUserVisibleHint()){
|
||||
if(notificationsFragment != null) {
|
||||
if (notificationsFragment.getUserVisibleHint()) {
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -282,19 +284,19 @@ public class MainActivity extends AppCompatActivity
|
|||
item = navigationView.getMenu().findItem(R.id.nav_home);
|
||||
fragmentTag = "HOME_TIMELINE";
|
||||
if( homeFragment != null && newHome > 0) {
|
||||
newHome = 0;
|
||||
updateHomeCounter();
|
||||
homeFragment.refresh();
|
||||
homeFragment.refresh(null);
|
||||
}
|
||||
newHome = 0;
|
||||
updateHomeCounter();
|
||||
break;
|
||||
case 1:
|
||||
fragmentTag = "NOTIFICATIONS";
|
||||
item = navigationView.getMenu().findItem(R.id.nav_notification);
|
||||
if( notificationsFragment != null && newNotif > 0) {
|
||||
newNotif = 0;
|
||||
updateNotifCounter();
|
||||
notificationsFragment.refresh();
|
||||
notificationsFragment.refresh(null);
|
||||
}
|
||||
newNotif = 0;
|
||||
updateNotifCounter();
|
||||
break;
|
||||
case 2:
|
||||
fragmentTag = "LOCAL_TIMELINE";
|
||||
|
|
|
@ -255,18 +255,36 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
}
|
||||
new_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
public void refresh(){
|
||||
if( notificationsTmp != null){
|
||||
|
||||
public void refresh(Notification notification){
|
||||
|
||||
if( notification != null){
|
||||
if( notificationsTmp != null && notificationsTmp.size() > 0){
|
||||
notificationsTmp.add(0,notification);
|
||||
}else {
|
||||
notificationsTmp = new ArrayList<>();
|
||||
for(Notification notificationTmp: this.notifications){
|
||||
notificationsTmp.add(notificationTmp);
|
||||
}
|
||||
notificationsTmp.add(0,notification);
|
||||
}
|
||||
}else{
|
||||
notificationsTmp = new ArrayList<>();
|
||||
for(Notification notificationTmp: this.notifications){
|
||||
notificationsTmp.add(notificationTmp);
|
||||
}
|
||||
}
|
||||
if( notificationsTmp.size() > 0){
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
notifications = new ArrayList<>();
|
||||
for(Notification notification: notificationsTmp){
|
||||
notifications.add(notification);
|
||||
for(Notification not_tmp: notificationsTmp){
|
||||
notifications.add(not_tmp);
|
||||
}
|
||||
notificationsListAdapter = new NotificationsListAdapter(context,isOnWifi, behaviorWithAttachments, notifications);
|
||||
lv_notifications.setAdapter(notificationsListAdapter);
|
||||
if( notificationsTmp.size() > 0 && textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
}
|
||||
new_data.setVisibility(View.GONE);
|
||||
|
|
|
@ -359,16 +359,32 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
new_data.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void refresh(){
|
||||
if( statusesTmp != null){
|
||||
public void refresh(Status status){
|
||||
if( status != null){
|
||||
if( statusesTmp != null && statusesTmp.size() > 0){
|
||||
statusesTmp.add(0,status);
|
||||
}else {
|
||||
statusesTmp = new ArrayList<>();
|
||||
for(Status statusTmp: this.statuses){
|
||||
statusesTmp.add(statusTmp);
|
||||
}
|
||||
statusesTmp.add(0,status);
|
||||
}
|
||||
}else {
|
||||
statusesTmp = new ArrayList<>();
|
||||
for(Status statusTmp: this.statuses){
|
||||
statusesTmp.add(statusTmp);
|
||||
}
|
||||
}
|
||||
if( statusesTmp != null && statusesTmp.size() > 0){
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
statuses = new ArrayList<>();
|
||||
for(Status status: statusesTmp){
|
||||
statuses.add(status);
|
||||
for(Status st_tmp: statusesTmp){
|
||||
statuses.add(st_tmp);
|
||||
}
|
||||
if( statusesTmp.size() > 0 && textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
if( textviewNoAction.getVisibility() == View.VISIBLE)
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses);
|
||||
lv_status.setAdapter(statusListAdapter);
|
||||
|
|
|
@ -157,7 +157,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}else{
|
||||
newNotif++;
|
||||
updateNotifCounter();
|
||||
notificationsFragment.updateData(notification);
|
||||
notificationsFragment.refresh(notification);
|
||||
}
|
||||
}else {
|
||||
newNotif++;
|
||||
|
@ -171,7 +171,7 @@ public class MainActivity extends AppCompatActivity
|
|||
}else{
|
||||
newHome++;
|
||||
updateHomeCounter();
|
||||
homeFragment.updateData(status);
|
||||
homeFragment.refresh(status);
|
||||
}
|
||||
}else{
|
||||
newHome++;
|
||||
|
@ -179,10 +179,12 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}else if(eventStreaming == StreamingUserAsyncTask.EventStreaming.DELETE){
|
||||
String id = b.getString("id");
|
||||
if(notificationsFragment.getUserVisibleHint()){
|
||||
if(notificationsFragment != null) {
|
||||
if (notificationsFragment.getUserVisibleHint()) {
|
||||
|
||||
}else{
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,19 +292,19 @@ public class MainActivity extends AppCompatActivity
|
|||
item = navigationView.getMenu().findItem(R.id.nav_home);
|
||||
fragmentTag = "HOME_TIMELINE";
|
||||
if( homeFragment != null && newHome > 0) {
|
||||
newHome = 0;
|
||||
updateHomeCounter();
|
||||
homeFragment.refresh();
|
||||
homeFragment.refresh(null);
|
||||
}
|
||||
newHome = 0;
|
||||
updateHomeCounter();
|
||||
break;
|
||||
case 1:
|
||||
fragmentTag = "NOTIFICATIONS";
|
||||
item = navigationView.getMenu().findItem(R.id.nav_notification);
|
||||
if( notificationsFragment != null && newNotif > 0) {
|
||||
newNotif = 0;
|
||||
updateNotifCounter();
|
||||
notificationsFragment.refresh();
|
||||
notificationsFragment.refresh(null);
|
||||
}
|
||||
newNotif = 0;
|
||||
updateNotifCounter();
|
||||
break;
|
||||
case 2:
|
||||
fragmentTag = "LOCAL_TIMELINE";
|
||||
|
|
Loading…
Reference in New Issue