Switch map button accoding to map and list

This commit is contained in:
Neslihan 2017-05-14 15:51:50 +03:00
parent bb47332a37
commit dc1b04f3ed
13 changed files with 34 additions and 10 deletions

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons.nearby;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuInflater;
@ -71,6 +72,11 @@ public class NearbyActivity extends BaseActivity {
return true;
case R.id.action_map:
showMapView();
if (isMapViewActive) {
item.setIcon(R.drawable.ic_list_white_24dp);
} else {
item.setIcon(R.drawable.ic_map_white_24dp);
}
return true;
default:
return super.onOptionsItemSelected(item);
@ -83,9 +89,16 @@ public class NearbyActivity extends BaseActivity {
if (nearbyAsyncTask.getStatus() == AsyncTask.Status.FINISHED) {
setMapFragment();
}
} else {
isMapViewActive = false;
if (nearbyAsyncTask.getStatus() == AsyncTask.Status.FINISHED) {
setListFragment();
}
}
}
@Override
protected void onResume() {
super.onResume();
@ -160,22 +173,22 @@ public class NearbyActivity extends BaseActivity {
* Calls fragment for map view.
*/
public void setMapFragment() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
NearbyMapFragment fragment = new NearbyMapFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = new NearbyMapFragment();
fragment.setArguments(bundle);
ft.add(R.id.container, fragment);
ft.commit();
fragmentTransaction.replace(R.id.container, fragment);
fragmentTransaction.commit();
}
/**
* Calls fragment for list view.
*/
public void setListFragment() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
NearbyListFragment fragment = new NearbyListFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = new NearbyListFragment();
fragment.setArguments(bundle);
ft.add(R.id.container, fragment);
ft.commit();
fragmentTransaction.replace(R.id.container, fragment);
fragmentTransaction.commit();
}
}