Integrated navigation drawer in the contributions activity

This commit is contained in:
maskara 2017-05-15 15:19:05 +02:00
parent e40d2aabb2
commit 09cd596ff6
12 changed files with 297 additions and 165 deletions

View file

@ -18,6 +18,7 @@ import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -28,6 +29,8 @@ import android.widget.RelativeLayout;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.HandlerService;
import fr.free.nrw.commons.Media;
@ -60,8 +63,14 @@ public class ContributionsActivity
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
private String CONTRIBUTION_SELECTION = "";
private DrawerLayout drawerLayout;
private RelativeLayout drawerPane;
@BindView(R.id.contributions_toolbar)
Toolbar toolbar;
@BindView(R.id.drawer_layout)
DrawerLayout drawerLayout;
@BindView(R.id.drawer_pane)
RelativeLayout drawerPane;
/*
This sorts in the following order:
@ -133,6 +142,11 @@ public class ContributionsActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contributions);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
initSubviews();
@ -158,15 +172,21 @@ public class ContributionsActivity
}
private void initSubviews() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerPane = (RelativeLayout) findViewById(R.id.drawer_pane);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
drawerLayout,
toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawerLayout.setDrawerListener(toggle);
toggle.setDrawerIndicatorEnabled(true);
toggle.syncState();
setDrawerPaneWidth();
}
private void setDrawerPaneWidth() {
ViewGroup.LayoutParams params = drawerPane.getLayoutParams();
// set width to lowerBound of 80% of the screen size
params.width = (getResources().getDisplayMetrics().widthPixels * 80) / 100;
params.width = (getResources().getDisplayMetrics().widthPixels * 70) / 100;
drawerPane.setLayoutParams(params);
}
@ -371,4 +391,9 @@ public class ContributionsActivity
public boolean isDrawerVisible() {
return drawerLayout.isDrawerVisible(START);
}
public static void startYourself(Context context) {
Intent settingsIntent = new Intent(context, ContributionsActivity.class);
context.startActivity(settingsIntent);
}
}

View file

@ -126,46 +126,46 @@ public class ContributionsListFragment extends Fragment {
case R.id.menu_from_camera:
controller.startCameraCapture();
return true;
case R.id.menu_settings:
Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class);
startActivity(settingsIntent);
return true;
case R.id.menu_about:
Intent aboutIntent = new Intent(getActivity(), AboutActivity.class);
startActivity(aboutIntent);
return true;
case R.id.menu_feedback:
Intent feedbackIntent = new Intent(Intent.ACTION_SEND);
feedbackIntent.setType("message/rfc822");
feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CommonsApplication.FEEDBACK_EMAIL });
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, BuildConfig.VERSION_NAME));
try {
startActivity(feedbackIntent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), R.string.no_email_client, Toast.LENGTH_SHORT).show();
}
return true;
case R.id.menu_nearby:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
//See http://stackoverflow.com/questions/33169455/onrequestpermissionsresult-not-being-called-in-dialog-fragment
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 2);
return true;
} else {
Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class);
startActivity(nearbyIntent);
return true;
}
}
else {
Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class);
startActivity(nearbyIntent);
return true;
}
case R.id.menu_refresh:
((SourceRefresher)getActivity()).refreshSource();
return true;
// case R.id.menu_settings:
// Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class);
// startActivity(settingsIntent);
// return true;
// case R.id.menu_about:
// Intent aboutIntent = new Intent(getActivity(), AboutActivity.class);
// startActivity(aboutIntent);
// return true;
// case R.id.menu_feedback:
// Intent feedbackIntent = new Intent(Intent.ACTION_SEND);
// feedbackIntent.setType("message/rfc822");
// feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CommonsApplication.FEEDBACK_EMAIL });
// feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, BuildConfig.VERSION_NAME));
// try {
// startActivity(feedbackIntent);
// }
// catch (ActivityNotFoundException e) {
// Toast.makeText(getActivity(), R.string.no_email_client, Toast.LENGTH_SHORT).show();
// }
// return true;
// case R.id.menu_nearby:
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// if (ContextCompat.checkSelfPermission(this.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// //See http://stackoverflow.com/questions/33169455/onrequestpermissionsresult-not-being-called-in-dialog-fragment
// requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 2);
// return true;
// } else {
// Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class);
// startActivity(nearbyIntent);
// return true;
// }
// }
// else {
// Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class);
// startActivity(nearbyIntent);
// return true;
// }
// case R.id.menu_refresh:
// ((SourceRefresher)getActivity()).refreshSource();
// return true;
default:
return super.onOptionsItemSelected(item);
}
@ -204,7 +204,7 @@ public class ContributionsListFragment extends Fragment {
menu.findItem(R.id.menu_from_camera).setEnabled(false);
}
menu.findItem(R.id.menu_refresh).setVisible(false);
//menu.findItem(R.id.menu_refresh).setVisible(false);
}
@Override