Fix some potential crashes

This commit is contained in:
tom79 2019-08-24 17:33:10 +02:00
parent bc76990488
commit 0a2c75d64a
4 changed files with 30 additions and 13 deletions

View File

@ -1626,7 +1626,7 @@ public abstract class BaseMainActivity extends BaseActivity
//Refresh home if needed
if( dateAllowed.after(date) ) {
for (ManageTimelines tl : timelines) {
if (tl.getType() == ManageTimelines.Type.HOME && mPageReferenceMap.containsKey(tl.getPosition())) {
if (tl.getType() == ManageTimelines.Type.HOME && mPageReferenceMap != null && mPageReferenceMap.containsKey(tl.getPosition())) {
DisplayStatusFragment homeTimeline = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if (homeTimeline != null) {
homeTimeline.retrieveMissingHome();

View File

@ -463,9 +463,11 @@ public class ManageTimelines {
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu menu) {
TabLayoutNotificationsFragment tabLayoutNotificationsFragment = (TabLayoutNotificationsFragment) mPageReferenceMap.get(tl.getPosition());
assert tabLayoutNotificationsFragment != null;
tabLayoutNotificationsFragment.refreshAll();
if( mPageReferenceMap != null) {
TabLayoutNotificationsFragment tabLayoutNotificationsFragment = (TabLayoutNotificationsFragment) mPageReferenceMap.get(tl.getPosition());
assert tabLayoutNotificationsFragment != null;
tabLayoutNotificationsFragment.refreshAll();
}
}
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@ -564,12 +566,14 @@ public class ManageTimelines {
@Override
public void onDismiss(PopupMenu menu) {
if(changes[0]) {
FragmentTransaction fragTransaction = ((MainActivity)context).getSupportFragmentManager().beginTransaction();
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
assert displayStatusFragment != null;
fragTransaction.detach(displayStatusFragment);
fragTransaction.attach(displayStatusFragment);
fragTransaction.commit();
if( mPageReferenceMap != null) {
FragmentTransaction fragTransaction = ((MainActivity) context).getSupportFragmentManager().beginTransaction();
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
assert displayStatusFragment != null;
fragTransaction.detach(displayStatusFragment);
fragTransaction.attach(displayStatusFragment);
fragTransaction.commit();
}
}
}
});
@ -608,8 +612,10 @@ public class ManageTimelines {
final MenuItem itemShowBoosts = menu.findItem(R.id.action_show_boosts);
final MenuItem itemShowReplies = menu.findItem(R.id.action_show_replies);
final MenuItem itemFilter = menu.findItem(R.id.action_filter);
if( mPageReferenceMap == null) {
return;
}
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if(tl.getType() != Type.HOME){
itemShowBoosts.setVisible(false);
itemShowReplies.setVisible(false);
@ -789,6 +795,8 @@ public class ManageTimelines {
@Override
public void onDismiss(PopupMenu menu) {
if(changes[0]) {
if( mPageReferenceMap == null)
return;
FragmentTransaction fragTransaction = ((MainActivity)context).getSupportFragmentManager().beginTransaction();
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if( displayStatusFragment == null)
@ -1013,6 +1021,8 @@ public class ManageTimelines {
});
changes[0] = true;
FragmentTransaction fragTransaction = ((MainActivity)context).getSupportFragmentManager().beginTransaction();
if( mPageReferenceMap == null)
return true;
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if( displayStatusFragment == null)
return false;
@ -1053,6 +1063,8 @@ public class ManageTimelines {
@Override
public boolean onMenuItemClick(MenuItem item) {
FragmentTransaction fragTransaction = ((MainActivity)context).getSupportFragmentManager().beginTransaction();
if( mPageReferenceMap == null)
return true;
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if( displayStatusFragment == null)
return false;
@ -1135,6 +1147,8 @@ public class ManageTimelines {
public void onDismiss(PopupMenu menu) {
if(changes[0]) {
FragmentTransaction fragTransaction = ((MainActivity)context).getSupportFragmentManager().beginTransaction();
if( mPageReferenceMap == null)
return;
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if( displayStatusFragment == null)
return;

View File

@ -1902,7 +1902,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<ManageTimelines> timelines = new TimelinesDAO(context, db).getDisplayedTimelines();
for(ManageTimelines tl: timelines) {
if( tl.getType() == ManageTimelines.Type.HOME) {
if( tl.getType() == ManageTimelines.Type.HOME && mPageReferenceMap != null) {
DisplayStatusFragment homeFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if (homeFragment != null)
homeFragment.fetchMore(status.getId());
@ -1924,7 +1924,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<ManageTimelines> timelines = new TimelinesDAO(context, db).getDisplayedTimelines();
for(ManageTimelines tl: timelines) {
if( tl.getType() == ManageTimelines.Type.HOME) {
if( tl.getType() == ManageTimelines.Type.HOME && mPageReferenceMap != null) {
DisplayStatusFragment homeFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
if (homeFragment != null) {
fetch_all_more = true;

View File

@ -265,6 +265,9 @@ public class DisplayFiltersFragment extends Fragment implements OnFilterActionIn
MainActivity.filters = apiResponse.getFilters();
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<ManageTimelines> timelines = new TimelinesDAO(context, db).getDisplayedTimelines();
if( mPageReferenceMap == null) {
return;
}
for(ManageTimelines tl: timelines) {
if( tl.getType() == ManageTimelines.Type.HOME || tl.getType() == ManageTimelines.Type.LOCAL || tl.getType() == ManageTimelines.Type.PUBLIC) {
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());