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; package fr.free.nrw.commons;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.widget.TextView;
import fr.free.nrw.commons.theme.BaseActivity;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import fr.free.nrw.commons.theme.BaseActivity;
public class AboutActivity extends BaseActivity { public class AboutActivity extends BaseActivity {
@BindView(R.id.about_version) TextView versionText; @BindView(R.id.about_version) TextView versionText;
@ -20,4 +21,9 @@ public class AboutActivity extends BaseActivity {
versionText.setText(BuildConfig.VERSION_NAME); 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.CursorAdapter;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -28,6 +29,8 @@ import android.widget.RelativeLayout;
import java.util.ArrayList; import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.HandlerService; import fr.free.nrw.commons.HandlerService;
import fr.free.nrw.commons.Media; import fr.free.nrw.commons.Media;
@ -60,8 +63,14 @@ public class ContributionsActivity
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>(); private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
private String CONTRIBUTION_SELECTION = ""; private String CONTRIBUTION_SELECTION = "";
private DrawerLayout drawerLayout; @BindView(R.id.contributions_toolbar)
private RelativeLayout drawerPane; Toolbar toolbar;
@BindView(R.id.drawer_layout)
DrawerLayout drawerLayout;
@BindView(R.id.drawer_pane)
RelativeLayout drawerPane;
/* /*
This sorts in the following order: This sorts in the following order:
@ -133,6 +142,11 @@ public class ContributionsActivity
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contributions); setContentView(R.layout.activity_contributions);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
initSubviews(); initSubviews();
@ -158,15 +172,21 @@ public class ContributionsActivity
} }
private void initSubviews() { private void initSubviews() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,
drawerPane = (RelativeLayout) findViewById(R.id.drawer_pane); drawerLayout,
toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawerLayout.setDrawerListener(toggle);
toggle.setDrawerIndicatorEnabled(true);
toggle.syncState();
setDrawerPaneWidth(); setDrawerPaneWidth();
} }
private void setDrawerPaneWidth() { private void setDrawerPaneWidth() {
ViewGroup.LayoutParams params = drawerPane.getLayoutParams(); ViewGroup.LayoutParams params = drawerPane.getLayoutParams();
// set width to lowerBound of 80% of the screen size // 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); drawerPane.setLayoutParams(params);
} }
@ -371,4 +391,9 @@ public class ContributionsActivity
public boolean isDrawerVisible() { public boolean isDrawerVisible() {
return drawerLayout.isDrawerVisible(START); 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: case R.id.menu_from_camera:
controller.startCameraCapture(); controller.startCameraCapture();
return true; return true;
case R.id.menu_settings: // case R.id.menu_settings:
Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class); // Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class);
startActivity(settingsIntent); // startActivity(settingsIntent);
return true; // return true;
case R.id.menu_about: // case R.id.menu_about:
Intent aboutIntent = new Intent(getActivity(), AboutActivity.class); // Intent aboutIntent = new Intent(getActivity(), AboutActivity.class);
startActivity(aboutIntent); // startActivity(aboutIntent);
return true; // return true;
case R.id.menu_feedback: // case R.id.menu_feedback:
Intent feedbackIntent = new Intent(Intent.ACTION_SEND); // Intent feedbackIntent = new Intent(Intent.ACTION_SEND);
feedbackIntent.setType("message/rfc822"); // feedbackIntent.setType("message/rfc822");
feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CommonsApplication.FEEDBACK_EMAIL }); // feedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { CommonsApplication.FEEDBACK_EMAIL });
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, BuildConfig.VERSION_NAME)); // feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(CommonsApplication.FEEDBACK_EMAIL_SUBJECT, BuildConfig.VERSION_NAME));
try { // try {
startActivity(feedbackIntent); // startActivity(feedbackIntent);
} // }
catch (ActivityNotFoundException e) { // catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), R.string.no_email_client, Toast.LENGTH_SHORT).show(); // Toast.makeText(getActivity(), R.string.no_email_client, Toast.LENGTH_SHORT).show();
} // }
return true; // return true;
case R.id.menu_nearby: // case R.id.menu_nearby:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this.getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // 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 // //See http://stackoverflow.com/questions/33169455/onrequestpermissionsresult-not-being-called-in-dialog-fragment
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 2); // requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 2);
return true; // return true;
} else { // } else {
Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class); // Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class);
startActivity(nearbyIntent); // startActivity(nearbyIntent);
return true; // return true;
} // }
} // }
else { // else {
Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class); // Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class);
startActivity(nearbyIntent); // startActivity(nearbyIntent);
return true; // return true;
} // }
case R.id.menu_refresh: // case R.id.menu_refresh:
((SourceRefresher)getActivity()).refreshSource(); // ((SourceRefresher)getActivity()).refreshSource();
return true; // return true;
default: default:
return super.onOptionsItemSelected(item); 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_from_camera).setEnabled(false);
} }
menu.findItem(R.id.menu_refresh).setVisible(false); //menu.findItem(R.id.menu_refresh).setVisible(false);
} }
@Override @Override

View file

@ -1,5 +1,7 @@
package fr.free.nrw.commons.hamburger; package fr.free.nrw.commons.hamburger;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
@ -7,16 +9,27 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; 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.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 { public class NavigationBaseFragment extends Fragment {
@BindView(R.id.pictureOfTheDay)
ImageView pictureOfTheDay;
@BindView(R.id.home_item) @BindView(R.id.home_item)
TextView homeItem; TextView homeItem;
@ -42,13 +55,20 @@ public class NavigationBaseFragment extends Fragment {
private RelativeLayout drawerPane; private RelativeLayout drawerPane;
@Override @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); View hamburgerView = inflater.inflate(R.layout.navigation_drawer_menu, container, false);
ButterKnife.bind(this, hamburgerView); ButterKnife.bind(this, hamburgerView);
showPictureOfTheDay();
setupHamburgerMenu(); setupHamburgerMenu();
return hamburgerView; return hamburgerView;
} }
private void showPictureOfTheDay() {
pictureOfTheDay.setImageDrawable(getResources().getDrawable(R.drawable.commons_logo_large));
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -62,9 +82,45 @@ public class NavigationBaseFragment extends Fragment {
} }
} }
@OnClick(R.id.home_item) @OnClick(R.id.upload_item)
protected void onProfileLayoutClick() { protected void onHomeItemClicked() {
closeDrawer(); 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() { private void closeDrawer() {

View file

@ -1,12 +1,9 @@
package fr.free.nrw.commons.nearby; package fr.free.nrw.commons.nearby;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.location.LocationManager; import android.location.LocationManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -20,22 +17,20 @@ import android.view.View;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; 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.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager; import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.theme.BaseActivity; import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.UriSerializer; import fr.free.nrw.commons.utils.UriSerializer;
import fr.free.nrw.commons.R;
import timber.log.Timber; import timber.log.Timber;
import java.util.List;
public class NearbyActivity extends BaseActivity { public class NearbyActivity extends BaseActivity {
@BindView(R.id.progressBar) @BindView(R.id.progressBar)
ProgressBar progressBar; ProgressBar progressBar;
@ -251,4 +246,9 @@ public class NearbyActivity extends BaseActivity {
fragmentTransaction.replace(R.id.container, fragment); fragmentTransaction.replace(R.id.container, fragment);
fragmentTransaction.commit(); 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; package fr.free.nrw.commons.settings;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -51,4 +53,9 @@ public class SettingsActivity extends PreferenceActivity {
return super.onOptionsItemSelected(item); 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,12 +5,22 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
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" />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/contributionsFragmentContainer" android:id="@+id/contributionsFragmentContainer"
android:orientation="horizontal"> android:orientation="horizontal"
android:layout_below="@id/contributions_toolbar">
<fragment <fragment
android:id="@+id/contributionsListFragment" android:id="@+id/contributionsListFragment"
@ -20,6 +30,7 @@
tools:layout="@layout/fragment_contributions" /> tools:layout="@layout/fragment_contributions" />
</FrameLayout> </FrameLayout>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/drawer_pane" 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,6 +3,30 @@
android:orientation="vertical" android:layout_width="match_parent" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
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>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/black"/>
<TextView <TextView
android:id="@+id/home_item" android:id="@+id/home_item"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -53,14 +77,6 @@
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:text="@string/navigation_item_settings"/> android:text="@string/navigation_item_settings"/>
<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 <TextView
android:id="@+id/feedback_item" android:id="@+id/feedback_item"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -81,3 +97,5 @@
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:text="@string/navigation_item_logout"/> android:text="@string/navigation_item_logout"/>
</LinearLayout> </LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -10,25 +10,25 @@
app:showAsAction="ifRoom|withText" app:showAsAction="ifRoom|withText"
android:icon="?attr/iconPhoto" android:icon="?attr/iconPhoto"
/> />
<item android:id="@+id/menu_nearby" <!--<item android:id="@+id/menu_nearby"-->
android:title="@string/menu_nearby" <!--android:title="@string/menu_nearby"-->
app:showAsAction="never" <!--app:showAsAction="never"-->
/> <!--/>-->
<item android:id="@+id/menu_refresh" <!--<item android:id="@+id/menu_refresh"-->
android:title="@string/menu_refresh" <!--android:title="@string/menu_refresh"-->
app:showAsAction="never" <!--app:showAsAction="never"-->
/> <!--/>-->
<item android:id="@+id/menu_about" <!--<item android:id="@+id/menu_about"-->
android:title="@string/menu_about" <!--android:title="@string/menu_about"-->
app:showAsAction="never" <!--app:showAsAction="never"-->
/> <!--/>-->
<item android:id="@+id/menu_settings" <!--<item android:id="@+id/menu_settings"-->
android:title="@string/menu_settings" <!--android:title="@string/menu_settings"-->
app:showAsAction="never" <!--app:showAsAction="never"-->
/> <!--/>-->
<item android:id="@+id/menu_feedback" <!--<item android:id="@+id/menu_feedback"-->
android:title="@string/menu_feedback" <!--android:title="@string/menu_feedback"-->
app:showAsAction="never" <!--app:showAsAction="never"-->
/> <!--/>-->
</menu> </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="login_failed_2fa_not_supported">Two factor authentication is currently not supported.</string>
<string name="cancel">Cancel</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_home">Home</string>
<string name="navigation_item_upload">Upload</string> <string name="navigation_item_upload">Upload</string>
<string name="navigation_item_nearby">Nearby</string> <string name="navigation_item_nearby">Nearby</string>