mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
With support for navigation drawer
This commit is contained in:
parent
27682433ac
commit
e40d2aabb2
10 changed files with 316 additions and 24 deletions
|
|
@ -16,32 +16,41 @@ import android.support.v4.app.LoaderManager;
|
|||
import android.support.v4.content.CursorLoader;
|
||||
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.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Adapter;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
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.hamburger.NavigationBaseFragment;
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import fr.free.nrw.commons.upload.UploadService;
|
||||
import fr.free.nrw.commons.utils.FragmentUtils;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.support.v4.view.GravityCompat.START;
|
||||
|
||||
public class ContributionsActivity
|
||||
extends AuthenticatedActivity
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>,
|
||||
AdapterView.OnItemClickListener,
|
||||
MediaDetailPagerFragment.MediaDetailProvider,
|
||||
FragmentManager.OnBackStackChangedListener,
|
||||
ContributionsListFragment.SourceRefresher {
|
||||
ContributionsListFragment.SourceRefresher,
|
||||
HamburgerMenuContainer {
|
||||
|
||||
private Cursor allContributions;
|
||||
private ContributionsListFragment contributionsList;
|
||||
|
|
@ -50,6 +59,10 @@ public class ContributionsActivity
|
|||
private boolean isUploadServiceConnected;
|
||||
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
|
||||
private String CONTRIBUTION_SELECTION = "";
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private RelativeLayout drawerPane;
|
||||
|
||||
/*
|
||||
This sorts in the following order:
|
||||
Currently Uploading
|
||||
|
|
@ -119,9 +132,10 @@ public class ContributionsActivity
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setTitle(R.string.title_activity_contributions);
|
||||
setContentView(R.layout.activity_contributions);
|
||||
|
||||
initSubviews();
|
||||
|
||||
// Activity can call methods in the fragment by acquiring a reference to the Fragment from FragmentManager, using findFragmentById()
|
||||
contributionsList = (ContributionsListFragment)getSupportFragmentManager().findFragmentById(R.id.contributionsListFragment);
|
||||
|
||||
|
|
@ -136,6 +150,24 @@ public class ContributionsActivity
|
|||
}
|
||||
}
|
||||
requestAuthToken();
|
||||
NavigationBaseFragment baseFragment = new NavigationBaseFragment();
|
||||
baseFragment.setDrawerLayout(drawerLayout, drawerPane);
|
||||
FragmentUtils.addAndCommitFragmentWithImmediateExecution(getSupportFragmentManager(),
|
||||
R.id.drawer_fragment,
|
||||
baseFragment);
|
||||
}
|
||||
|
||||
private void initSubviews() {
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawerPane = (RelativeLayout) findViewById(R.id.drawer_pane);
|
||||
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;
|
||||
drawerPane.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -229,15 +261,15 @@ public class ContributionsActivity
|
|||
((CursorAdapter)contributionsList.getAdapter()).swapCursor(cursor);
|
||||
}
|
||||
|
||||
if (cursor.getCount() == 0
|
||||
&& Locale.getDefault().getISO3Language().equals(Locale.ENGLISH.getISO3Language())) {
|
||||
//cursor count is zero and language is english -
|
||||
// we need to set the message for 0 case explicitly.
|
||||
getSupportActionBar().setSubtitle(getResources()
|
||||
.getString(R.string.contributions_subtitle_zero));
|
||||
} else {
|
||||
getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.contributions_subtitle, cursor.getCount(), cursor.getCount()));
|
||||
}
|
||||
// if (cursor.getCount() == 0
|
||||
// && Locale.getDefault().getISO3Language().equals(Locale.ENGLISH.getISO3Language())) {
|
||||
// //cursor count is zero and language is english -
|
||||
// // we need to set the message for 0 case explicitly.
|
||||
// getSupportActionBar().setSubtitle(getResources()
|
||||
// .getString(R.string.contributions_subtitle_zero));
|
||||
// } else {
|
||||
// getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.contributions_subtitle, cursor.getCount(), cursor.getCount()));
|
||||
// }
|
||||
|
||||
contributionsList.clearSyncMessage();
|
||||
notifyAndMigrateDataSetObservers();
|
||||
|
|
@ -320,4 +352,23 @@ public class ContributionsActivity
|
|||
public void refreshSource() {
|
||||
getSupportLoaderManager().restartLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDrawerListener(ActionBarDrawerToggle listener) {
|
||||
drawerLayout.setDrawerListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleDrawer() {
|
||||
if (drawerLayout.isDrawerVisible(START)) {
|
||||
drawerLayout.closeDrawer(START);
|
||||
} else {
|
||||
drawerLayout.openDrawer(START);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrawerVisible() {
|
||||
return drawerLayout.isDrawerVisible(START);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package fr.free.nrw.commons.hamburger;
|
||||
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
|
||||
public interface HamburgerMenuContainer {
|
||||
void setDrawerListener(ActionBarDrawerToggle listener);
|
||||
void toggleDrawer();
|
||||
boolean isDrawerVisible();
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package fr.free.nrw.commons.hamburger;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
|
||||
public class NavigationBaseFragment extends Fragment {
|
||||
@BindView(R.id.home_item)
|
||||
TextView homeItem;
|
||||
|
||||
@BindView(R.id.upload_item)
|
||||
TextView uploadItem;
|
||||
|
||||
@BindView(R.id.nearby_item)
|
||||
TextView nearbyItem;
|
||||
|
||||
@BindView(R.id.about_item)
|
||||
TextView aboutItem;
|
||||
|
||||
@BindView(R.id.settings_item)
|
||||
TextView settingsItem;
|
||||
|
||||
@BindView(R.id.feedback_item)
|
||||
TextView feedbackItem;
|
||||
|
||||
@BindView(R.id.logout_item)
|
||||
TextView logoutItem;
|
||||
|
||||
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);
|
||||
setupHamburgerMenu();
|
||||
return hamburgerView;
|
||||
}
|
||||
|
||||
@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.home_item)
|
||||
protected void onProfileLayoutClick() {
|
||||
closeDrawer();
|
||||
}
|
||||
|
||||
private void closeDrawer() {
|
||||
if (drawerLayout != null) {
|
||||
drawerLayout.closeDrawer(drawerPane);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDrawerLayout(DrawerLayout drawerLayout, RelativeLayout drawerPane) {
|
||||
this.drawerLayout = drawerLayout;
|
||||
this.drawerPane = drawerPane;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,14 +3,19 @@ package fr.free.nrw.commons.theme;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.hamburger.NavigationBaseFragment;
|
||||
import fr.free.nrw.commons.utils.FragmentUtils;
|
||||
|
||||
public class BaseActivity extends AppCompatActivity {
|
||||
boolean currentTheme;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
if(Utils.isDarkTheme(this)){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package fr.free.nrw.commons.theme;
|
||||
|
||||
public class NavigationBaseActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class FragmentUtils {
|
||||
|
||||
public static boolean addAndCommitFragmentWithImmediateExecution(
|
||||
@NonNull FragmentManager fragmentManager,
|
||||
@IdRes int containerViewId,
|
||||
@NonNull Fragment fragment) {
|
||||
if (fragment.isAdded()) {
|
||||
Timber.w("Could not add fragment. The fragment is already added.");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
fragmentManager.beginTransaction()
|
||||
.add(containerViewId, fragment)
|
||||
.commitNow();
|
||||
return true;
|
||||
} catch (IllegalStateException e) {
|
||||
Timber.e(e, "Could not add & commit fragment. " +
|
||||
"Did you mean to call commitAllowingStateLoss?");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/contributionsFragmentContainer"
|
||||
>
|
||||
android:orientation="horizontal">
|
||||
|
||||
<fragment
|
||||
android:name="fr.free.nrw.commons.contributions.ContributionsListFragment"
|
||||
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>
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/drawer_pane"
|
||||
android:layout_width="320dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/drawer_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
83
app/src/main/res/layout/navigation_drawer_menu.xml
Normal file
83
app/src/main/res/layout/navigation_drawer_menu.xml
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<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/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/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/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/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"/>
|
||||
|
||||
<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/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>
|
||||
|
|
@ -184,4 +184,12 @@ Tap this message (or hit back) to skip this step.</string>
|
|||
<string name="set_limit">Set Recent Upload Limit</string>
|
||||
<string name="login_failed_2fa_not_supported">Two factor authentication is currently not supported.</string>
|
||||
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="navigation_item_home">Home</string>
|
||||
<string name="navigation_item_upload">Upload</string>
|
||||
<string name="navigation_item_nearby">Nearby</string>
|
||||
<string name="navigation_item_about">About</string>
|
||||
<string name="navigation_item_settings">Settings</string>
|
||||
<string name="navigation_item_feedback">Feedback</string>
|
||||
<string name="navigation_item_logout">Logout</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<resources>
|
||||
|
||||
<style name="DarkAppTheme" parent="Theme.AppCompat">
|
||||
<style name="DarkAppTheme" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="mainBackground">@color/main_background_dark</item>
|
||||
<item name="semitransparentText">@color/commons_app_blue_dark</item>
|
||||
<item name="commonsAppBlue">@color/activity_welcome_background_dark</item>
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
<item name="spinnerTheme">@style/DarkSpinnerTheme</item>
|
||||
</style>
|
||||
|
||||
<style name="LightAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="LightAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="mainBackground">@color/main_background_light</item>
|
||||
<item name="semitransparentText">@color/commons_app_blue_light</item>
|
||||
<item name="commonsAppBlue">@color/activity_welcome_background_light</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue