mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Lock screen during loading to prevent AsyncTask screen config crash
This commit is contained in:
parent
c77eb007d7
commit
c9e8513b8e
1 changed files with 18 additions and 3 deletions
|
|
@ -3,6 +3,8 @@ package fr.free.nrw.commons.nearby;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -103,6 +105,7 @@ public class NearbyListFragment extends ListFragment {
|
|||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
lockScreenOrientation();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -120,11 +123,10 @@ public class NearbyListFragment extends ListFragment {
|
|||
@Override
|
||||
protected void onPostExecute(List<Place> result) {
|
||||
super.onPostExecute(result);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
unlockScreenOrientation();
|
||||
|
||||
mAdapter = new NearbyAdapter(getActivity(), places);
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
ListView listview = (ListView) getView().findViewById(R.id.listview);
|
||||
listview.setAdapter(mAdapter);
|
||||
|
||||
|
|
@ -153,6 +155,19 @@ public class NearbyListFragment extends ListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void lockScreenOrientation() {
|
||||
int currentOrientation = getResources().getConfiguration().orientation;
|
||||
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
} else {
|
||||
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
}
|
||||
|
||||
private void unlockScreenOrientation() {
|
||||
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||
}
|
||||
|
||||
private class NearbyAdapter extends ArrayAdapter<Place> {
|
||||
|
||||
public List<Place> placesList;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue