mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Make the drawer prettier
This commit is contained in:
parent
f8bb106b83
commit
ae78930808
14 changed files with 162 additions and 490 deletions
|
|
@ -35,7 +35,6 @@ import fr.free.nrw.commons.HandlerService;
|
|||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.AuthenticatedActivity;
|
||||
import fr.free.nrw.commons.hamburger.HamburgerMenuContainer;
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.upload.UploadService;
|
||||
|
|
@ -48,8 +47,7 @@ public class ContributionsActivity
|
|||
AdapterView.OnItemClickListener,
|
||||
MediaDetailPagerFragment.MediaDetailProvider,
|
||||
FragmentManager.OnBackStackChangedListener,
|
||||
ContributionsListFragment.SourceRefresher,
|
||||
HamburgerMenuContainer {
|
||||
ContributionsListFragment.SourceRefresher {
|
||||
|
||||
private Cursor allContributions;
|
||||
private ContributionsListFragment contributionsList;
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
package fr.free.nrw.commons.hamburger;
|
||||
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
|
||||
public interface HamburgerMenuContainer {
|
||||
void setDrawerListener(ActionBarDrawerToggle listener);
|
||||
void toggleDrawer();
|
||||
boolean isDrawerVisible();
|
||||
}
|
||||
|
|
@ -1,174 +0,0 @@
|
|||
package fr.free.nrw.commons.hamburger;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import fr.free.nrw.commons.AboutActivity;
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.WelcomeActivity;
|
||||
import fr.free.nrw.commons.auth.LoginActivity;
|
||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import fr.free.nrw.commons.nearby.NearbyActivity;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
|
||||
|
||||
public class NavigationBaseFragment extends Fragment {
|
||||
@BindView(R.id.pictureOfTheDay)
|
||||
ImageView pictureOfTheDay;
|
||||
|
||||
@BindView(R.id.upload_item)
|
||||
LinearLayout uploadItem;
|
||||
|
||||
@BindView(R.id.nearby_item)
|
||||
LinearLayout nearbyItem;
|
||||
|
||||
@BindView(R.id.about_item)
|
||||
LinearLayout aboutItem;
|
||||
|
||||
@BindView(R.id.settings_item)
|
||||
LinearLayout settingsItem;
|
||||
|
||||
@BindView(R.id.feedback_item)
|
||||
LinearLayout feedbackItem;
|
||||
|
||||
@BindView(R.id.logout_item)
|
||||
LinearLayout logoutItem;
|
||||
|
||||
@BindView(R.id.introduction_item)
|
||||
LinearLayout introductionItem;
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private RelativeLayout drawerPane;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View hamburgerView = inflater.inflate(R.layout.navigation_drawer_menu, container, false);
|
||||
ButterKnife.bind(this, hamburgerView);
|
||||
showPictureOfTheDay();
|
||||
setupHamburgerMenu();
|
||||
return hamburgerView;
|
||||
}
|
||||
|
||||
private void showPictureOfTheDay() {
|
||||
pictureOfTheDay.setImageDrawable(getResources().getDrawable(R.drawable.commons_logo_large));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
private void setupHamburgerMenu() {
|
||||
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(getActivity(),
|
||||
drawerLayout, R.string.ok, R.string.cancel);
|
||||
if (getActivity() instanceof HamburgerMenuContainer) {
|
||||
((HamburgerMenuContainer) getActivity()).setDrawerListener(drawerToggle);
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.upload_item)
|
||||
protected void onUploadItemClicked() {
|
||||
closeDrawer();
|
||||
ContributionsActivity.startYourself(getActivity());
|
||||
}
|
||||
|
||||
@OnClick(R.id.settings_item)
|
||||
protected void onSettingsItemClicked() {
|
||||
closeDrawer();
|
||||
SettingsActivity.startYourself(getActivity());
|
||||
}
|
||||
|
||||
@OnClick(R.id.about_item)
|
||||
protected void onAboutItemClicked() {
|
||||
closeDrawer();
|
||||
AboutActivity.startYourself(getActivity());
|
||||
}
|
||||
|
||||
@OnClick(R.id.nearby_item)
|
||||
protected void onNearbyItemClicked() {
|
||||
closeDrawer();
|
||||
NearbyActivity.startYourself(getActivity());
|
||||
}
|
||||
|
||||
@OnClick(R.id.introduction_item)
|
||||
protected void onInfoItemClicked() {
|
||||
closeDrawer();
|
||||
WelcomeActivity.startYourself(getActivity());
|
||||
}
|
||||
|
||||
@OnClick(R.id.feedback_item)
|
||||
protected void onFeedbackItemClicked() {
|
||||
closeDrawer();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.logout_item)
|
||||
protected void onLogoutItemClicked() {
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
|
||||
alertDialogBuilder.setMessage(R.string.logout_verification)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
((CommonsApplication)getActivity().getApplicationContext())
|
||||
.clearApplicationData(getContext());
|
||||
Intent nearbyIntent = new Intent
|
||||
(getActivity(), LoginActivity.class);
|
||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(nearbyIntent);
|
||||
getActivity().finish();
|
||||
}
|
||||
});
|
||||
alertDialogBuilder.setNegativeButton(R.string.no,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = alertDialogBuilder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
private void closeDrawer() {
|
||||
if (drawerLayout != null) {
|
||||
drawerLayout.closeDrawer(drawerPane);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDrawerLayout(DrawerLayout drawerLayout, RelativeLayout drawerPane) {
|
||||
this.drawerLayout = drawerLayout;
|
||||
this.drawerPane = drawerPane;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +1,52 @@
|
|||
package fr.free.nrw.commons.theme;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import butterknife.BindView;
|
||||
import fr.free.nrw.commons.AboutActivity;
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.hamburger.HamburgerMenuContainer;
|
||||
import fr.free.nrw.commons.hamburger.NavigationBaseFragment;
|
||||
import fr.free.nrw.commons.utils.FragmentUtils;
|
||||
import fr.free.nrw.commons.WelcomeActivity;
|
||||
import fr.free.nrw.commons.auth.LoginActivity;
|
||||
import fr.free.nrw.commons.contributions.ContributionsActivity;
|
||||
import fr.free.nrw.commons.nearby.NearbyActivity;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
|
||||
import static android.support.v4.view.GravityCompat.START;
|
||||
public class NavigationBaseActivity extends BaseActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
public class NavigationBaseActivity extends BaseActivity implements HamburgerMenuContainer {
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@BindView(R.id.navigation_view)
|
||||
NavigationView navigationView;
|
||||
|
||||
@BindView(R.id.drawer_layout)
|
||||
DrawerLayout drawerLayout;
|
||||
|
||||
@BindView(R.id.drawer_pane)
|
||||
RelativeLayout drawerPane;
|
||||
|
||||
private ActionBarDrawerToggle toggle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
public void initDrawer() {
|
||||
initSubviews();
|
||||
NavigationBaseFragment baseFragment = new NavigationBaseFragment();
|
||||
baseFragment.setDrawerLayout(drawerLayout, drawerPane);
|
||||
FragmentUtils.addAndCommitFragmentWithImmediateExecution(getSupportFragmentManager(),
|
||||
R.id.drawer_fragment,
|
||||
baseFragment);
|
||||
}
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
public void initSubviews() {
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
toggle = new ActionBarDrawerToggle(this,
|
||||
drawerLayout,
|
||||
toolbar,
|
||||
R.string.navigation_drawer_open,
|
||||
R.string.navigation_drawer_close);
|
||||
drawerLayout.setDrawerListener(toggle);
|
||||
toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
|
||||
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawerLayout.addDrawerListener(toggle);
|
||||
toggle.setDrawerIndicatorEnabled(true);
|
||||
toggle.syncState();
|
||||
setDrawerPaneWidth();
|
||||
|
|
@ -74,28 +70,77 @@ public class NavigationBaseActivity extends BaseActivity implements HamburgerMen
|
|||
}
|
||||
|
||||
private void setDrawerPaneWidth() {
|
||||
ViewGroup.LayoutParams params = drawerPane.getLayoutParams();
|
||||
ViewGroup.LayoutParams params = navigationView.getLayoutParams();
|
||||
// set width to lowerBound of 80% of the screen size
|
||||
params.width = (getResources().getDisplayMetrics().widthPixels * 70) / 100;
|
||||
drawerPane.setLayoutParams(params);
|
||||
navigationView.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrawerListener(ActionBarDrawerToggle listener) {
|
||||
drawerLayout.setDrawerListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleDrawer() {
|
||||
if (drawerLayout.isDrawerVisible(START)) {
|
||||
drawerLayout.closeDrawer(START);
|
||||
} else {
|
||||
drawerLayout.openDrawer(START);
|
||||
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_home:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
ContributionsActivity.startYourself(this);
|
||||
return true;
|
||||
case R.id.action_nearby:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
NearbyActivity.startYourself(this);
|
||||
return true;
|
||||
case R.id.action_about:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
AboutActivity.startYourself(this);
|
||||
return true;
|
||||
case R.id.action_settings:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
SettingsActivity.startYourself(this);
|
||||
return true;
|
||||
case R.id.action_introduction:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
WelcomeActivity.startYourself(this);
|
||||
return true;
|
||||
case R.id.action_feedback:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
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(this, R.string.no_email_client, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
case R.id.action_logout:
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.logout_verification)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
((CommonsApplication) getApplicationContext())
|
||||
.clearApplicationData(NavigationBaseActivity.this);
|
||||
Intent nearbyIntent = new Intent(
|
||||
NavigationBaseActivity.this, LoginActivity.class);
|
||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(nearbyIntent);
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawerVisible() {
|
||||
return drawerLayout.isDrawerVisible(START);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue