fix npe after rotate screen

This commit is contained in:
Skalii 2021-03-06 18:52:13 +02:00
parent 7a5ffdeeb6
commit 9c9acaed4d
4 changed files with 18 additions and 17 deletions

View file

@ -23,6 +23,7 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.ColorRes; import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
@ -97,7 +98,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
invalidateListView(activity); invalidateListView(activity);
startLoadLiveMapsAsyncTask(); startLoadLiveMapsAsyncTask(getMyApplication());
} }
@Override @Override
@ -109,7 +110,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
public void downloadHasFinished() { public void downloadHasFinished() {
invalidateListView(getMyActivity()); invalidateListView(getMyActivity());
updateUpdateAllButton(); updateUpdateAllButton();
startLoadLiveMapsAsyncTask(); startLoadLiveMapsAsyncTask(getMyApplication());
} }
@Override @Override
@ -222,8 +223,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
stopLoadLiveMapsAsyncTask(); stopLoadLiveMapsAsyncTask();
} }
private void startLoadLiveMapsAsyncTask() { private void startLoadLiveMapsAsyncTask(OsmandApplication app) {
loadLiveMapsTask = new LoadLiveMapsTask(listAdapter, this); loadLiveMapsTask = new LoadLiveMapsTask(listAdapter, app);
loadLiveMapsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); loadLiveMapsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@ -256,6 +257,11 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
return (DownloadActivity) getActivity(); return (DownloadActivity) getActivity();
} }
@Nullable
public OsmandApplication getMyApplication() {
return getMyActivity().getMyApplication();
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
@ -272,10 +278,6 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
} }
} }
public OsmandApplication getMyApplication() {
return getMyActivity().getMyApplication();
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == RELOAD_ID) { if (item.getItemId() == RELOAD_ID) {
@ -287,8 +289,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
} }
@Override @Override
public void onUpdateStates() { public void onUpdateStates(OsmandApplication app) {
startLoadLiveMapsAsyncTask(); startLoadLiveMapsAsyncTask(app);
} }
private class UpdateIndexAdapter extends ArrayAdapter<IndexItem> { private class UpdateIndexAdapter extends ArrayAdapter<IndexItem> {
@ -428,10 +430,9 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
private final UpdateIndexAdapter adapter; private final UpdateIndexAdapter adapter;
private final LocalIndexHelper helper; private final LocalIndexHelper helper;
public LoadLiveMapsTask(UpdateIndexAdapter adapter, public LoadLiveMapsTask(UpdateIndexAdapter adapter, OsmandApplication app) {
UpdatesIndexFragment fragment) {
this.adapter = adapter; this.adapter = adapter;
helper = new LocalIndexHelper(fragment.getMyApplication()); helper = new LocalIndexHelper(app);
} }
@Override @Override

View file

@ -96,7 +96,7 @@ public class LiveUpdatesClearDialogFragment extends MenuBottomSheetDialogFragmen
} }
public interface OnRefreshLiveUpdates { public interface OnRefreshLiveUpdates {
void onUpdateStates(); void onUpdateStates(OsmandApplication app);
} }
@Override @Override
@ -105,7 +105,7 @@ public class LiveUpdatesClearDialogFragment extends MenuBottomSheetDialogFragmen
Fragment fragment = getTargetFragment(); Fragment fragment = getTargetFragment();
if (fragment instanceof OnRefreshLiveUpdates) { if (fragment instanceof OnRefreshLiveUpdates) {
((OnRefreshLiveUpdates) fragment).onUpdateStates(); ((OnRefreshLiveUpdates) fragment).onUpdateStates(app);
} }
dismiss(); dismiss();

View file

@ -222,7 +222,7 @@ public class LiveUpdatesFragmentNew extends BaseOsmAndDialogFragment implements
super.onDismiss(dialog); super.onDismiss(dialog);
Fragment target = getTargetFragment(); Fragment target = getTargetFragment();
if (target instanceof OnRefreshLiveUpdates) { if (target instanceof OnRefreshLiveUpdates) {
((OnRefreshLiveUpdates) target).onUpdateStates(); ((OnRefreshLiveUpdates) target).onUpdateStates(app);
} }
} }

View file

@ -475,7 +475,7 @@ public class LiveUpdatesSettingsDialogFragmentNew extends MenuBottomSheetDialogF
} }
@Override @Override
public void onUpdateStates() { public void onUpdateStates(OsmandApplication app) {
final OnLiveUpdatesForLocalChange confirmationInterface = (OnLiveUpdatesForLocalChange) getTargetFragment(); final OnLiveUpdatesForLocalChange confirmationInterface = (OnLiveUpdatesForLocalChange) getTargetFragment();
if (confirmationInterface != null) { if (confirmationInterface != null) {
confirmationInterface.updateList(); confirmationInterface.updateList();