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

@ -1,12 +1,13 @@
package fr.free.nrw.commons;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import fr.free.nrw.commons.theme.BaseActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.theme.BaseActivity;
public class AboutActivity extends BaseActivity {
@BindView(R.id.about_version) TextView versionText;
@ -20,4 +21,9 @@ public class AboutActivity extends BaseActivity {
versionText.setText(BuildConfig.VERSION_NAME);
}
public static void startYourself(Context context) {
Intent settingsIntent = new Intent(context, AboutActivity.class);
context.startActivity(settingsIntent);
}
}

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

View file

@ -1,5 +1,7 @@
package fr.free.nrw.commons.hamburger;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
@ -7,16 +9,27 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
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.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.home_item)
TextView homeItem;
@ -42,13 +55,20 @@ public class NavigationBaseFragment extends Fragment {
private RelativeLayout drawerPane;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
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();
@ -62,9 +82,45 @@ public class NavigationBaseFragment extends Fragment {
}
}
@OnClick(R.id.home_item)
protected void onProfileLayoutClick() {
@OnClick(R.id.upload_item)
protected void onHomeItemClicked() {
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.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();
}
}
private void closeDrawer() {

View file

@ -1,12 +1,9 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@ -20,22 +17,20 @@ import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.UriSerializer;
import fr.free.nrw.commons.R;
import timber.log.Timber;
import java.util.List;
public class NearbyActivity extends BaseActivity {
@BindView(R.id.progressBar)
ProgressBar progressBar;
@ -251,4 +246,9 @@ public class NearbyActivity extends BaseActivity {
fragmentTransaction.replace(R.id.container, fragment);
fragmentTransaction.commit();
}
public static void startYourself(Context context) {
Intent settingsIntent = new Intent(context, NearbyActivity.class);
context.startActivity(settingsIntent);
}
}

View file

@ -1,5 +1,7 @@
package fr.free.nrw.commons.settings;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
@ -51,4 +53,9 @@ public class SettingsActivity extends PreferenceActivity {
return super.onOptionsItemSelected(item);
}
}
public static void startYourself(Context context) {
Intent settingsIntent = new Intent(context, SettingsActivity.class);
context.startActivity(settingsIntent);
}
}

View file

@ -1,5 +0,0 @@
package fr.free.nrw.commons.theme;
public class NavigationBaseActivity extends BaseActivity {
}

View file

@ -5,21 +5,32 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/contributionsFragmentContainer"
android:orientation="horizontal">
android:layout_height="match_parent">
<include
android:id="@+id/contributions_toolbar"
layout="@layout/contributions_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:id="@+id/contributionsListFragment"
android:name="fr.free.nrw.commons.contributions.ContributionsListFragment"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_contributions" />
android:id="@+id/contributionsFragmentContainer"
android:orientation="horizontal"
android:layout_below="@id/contributions_toolbar">
</FrameLayout>
<fragment
android:id="@+id/contributionsListFragment"
android:name="fr.free.nrw.commons.contributions.ContributionsListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_contributions" />
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/drawer_pane"

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="?attr/colorPrimaryDark">
</android.support.v7.widget.Toolbar>

View file

@ -3,81 +3,99 @@
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/home_item"
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_home"/>
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray">
<ImageView
android:id="@+id/pictureOfTheDay"
android:layout_width="match_parent"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:layout_height="140dp" />
</LinearLayout>
<TextView
android:id="@+id/upload_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_upload"/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/black"/>
<TextView
android:id="@+id/nearby_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_nearby"/>
<TextView
android:id="@+id/home_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_home"/>
<TextView
android:id="@+id/about_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_about"/>
<TextView
android:id="@+id/upload_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_upload"/>
<TextView
android:id="@+id/settings_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_settings"/>
<TextView
android:id="@+id/nearby_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_nearby"/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:background="@android:color/white">
</View>
<TextView
android:id="@+id/about_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_about"/>
<TextView
android:id="@+id/feedback_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_feedback"/>
<TextView
android:id="@+id/settings_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_settings"/>
<TextView
android:id="@+id/logout_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_logout"/>
<TextView
android:id="@+id/feedback_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_feedback"/>
<TextView
android:id="@+id/logout_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:text="@string/navigation_item_logout"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -10,25 +10,25 @@
app:showAsAction="ifRoom|withText"
android:icon="?attr/iconPhoto"
/>
<item android:id="@+id/menu_nearby"
android:title="@string/menu_nearby"
app:showAsAction="never"
/>
<item android:id="@+id/menu_refresh"
android:title="@string/menu_refresh"
app:showAsAction="never"
/>
<item android:id="@+id/menu_about"
android:title="@string/menu_about"
app:showAsAction="never"
/>
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
app:showAsAction="never"
/>
<item android:id="@+id/menu_feedback"
android:title="@string/menu_feedback"
app:showAsAction="never"
/>
<!--<item android:id="@+id/menu_nearby"-->
<!--android:title="@string/menu_nearby"-->
<!--app:showAsAction="never"-->
<!--/>-->
<!--<item android:id="@+id/menu_refresh"-->
<!--android:title="@string/menu_refresh"-->
<!--app:showAsAction="never"-->
<!--/>-->
<!--<item android:id="@+id/menu_about"-->
<!--android:title="@string/menu_about"-->
<!--app:showAsAction="never"-->
<!--/>-->
<!--<item android:id="@+id/menu_settings"-->
<!--android:title="@string/menu_settings"-->
<!--app:showAsAction="never"-->
<!--/>-->
<!--<item android:id="@+id/menu_feedback"-->
<!--android:title="@string/menu_feedback"-->
<!--app:showAsAction="never"-->
<!--/>-->
</menu>

View file

@ -185,6 +185,8 @@ Tap this message (or hit back) to skip this step.</string>
<string name="login_failed_2fa_not_supported">Two factor authentication is currently not supported.</string>
<string name="cancel">Cancel</string>
<string name="navigation_drawer_open">Open</string>
<string name="navigation_drawer_close">Close</string>
<string name="navigation_item_home">Home</string>
<string name="navigation_item_upload">Upload</string>
<string name="navigation_item_nearby">Nearby</string>