With NavigationBaseActivity implemented

This commit is contained in:
maskara 2017-05-15 16:33:08 +02:00
parent 09cd596ff6
commit a6bbc8a33b
12 changed files with 241 additions and 218 deletions

View file

@ -7,9 +7,9 @@ import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
public class AboutActivity extends BaseActivity {
public class AboutActivity extends NavigationBaseActivity {
@BindView(R.id.about_version) TextView versionText;
@Override
@ -20,6 +20,7 @@ public class AboutActivity extends BaseActivity {
ButterKnife.bind(this);
versionText.setText(BuildConfig.VERSION_NAME);
initDrawer();
}
public static void startYourself(Context context) {

View file

@ -12,8 +12,9 @@ import java.io.IOException;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
public abstract class AuthenticatedActivity extends BaseActivity {
public abstract class AuthenticatedActivity extends NavigationBaseActivity {
String accountType;
CommonsApplication app;

View file

@ -16,20 +16,15 @@ 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.support.v7.widget.Toolbar;
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 butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.HandlerService;
@ -37,15 +32,11 @@ 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>,
@ -63,15 +54,6 @@ public class ContributionsActivity
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
private String CONTRIBUTION_SELECTION = "";
@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:
Currently Uploading
@ -144,12 +126,6 @@ public class ContributionsActivity
setContentView(R.layout.activity_contributions);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
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);
@ -164,30 +140,7 @@ public class ContributionsActivity
}
}
requestAuthToken();
NavigationBaseFragment baseFragment = new NavigationBaseFragment();
baseFragment.setDrawerLayout(drawerLayout, drawerPane);
FragmentUtils.addAndCommitFragmentWithImmediateExecution(getSupportFragmentManager(),
R.id.drawer_fragment,
baseFragment);
}
private void initSubviews() {
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 * 70) / 100;
drawerPane.setLayoutParams(params);
initDrawer();
}
@Override
@ -281,15 +234,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();
@ -373,25 +326,6 @@ public class ContributionsActivity
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);
}
public static void startYourself(Context context) {
Intent settingsIntent = new Intent(context, ContributionsActivity.class);
context.startActivity(settingsIntent);

View file

@ -126,46 +126,6 @@ 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;
default:
return super.onOptionsItemSelected(item);
}
@ -203,8 +163,6 @@ public class ContributionsListFragment extends Fragment {
if (!app.deviceHasCamera()) {
menu.findItem(R.id.menu_from_camera).setEnabled(false);
}
//menu.findItem(R.id.menu_refresh).setVisible(false);
}
@Override

View file

@ -30,9 +30,6 @@ public class NavigationBaseFragment extends Fragment {
@BindView(R.id.pictureOfTheDay)
ImageView pictureOfTheDay;
@BindView(R.id.home_item)
TextView homeItem;
@BindView(R.id.upload_item)
TextView uploadItem;
@ -83,7 +80,7 @@ public class NavigationBaseFragment extends Fragment {
}
@OnClick(R.id.upload_item)
protected void onHomeItemClicked() {
protected void onUploadItemClicked() {
closeDrawer();
ContributionsActivity.startYourself(getActivity());
}

View file

@ -27,11 +27,11 @@ 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.theme.NavigationBaseActivity;
import fr.free.nrw.commons.utils.UriSerializer;
import timber.log.Timber;
public class NearbyActivity extends BaseActivity {
public class NearbyActivity extends NavigationBaseActivity {
@BindView(R.id.progressBar)
ProgressBar progressBar;
private boolean isMapViewActive = false;
@ -59,7 +59,7 @@ public class NearbyActivity extends BaseActivity {
curLatLang = locationManager.getLatestLocation();
nearbyAsyncTask = new NearbyAsyncTask(this);
nearbyAsyncTask.execute();
initDrawer();
}
@Override

View file

@ -0,0 +1,82 @@
package fr.free.nrw.commons.theme;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import butterknife.BindView;
import butterknife.ButterKnife;
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 static android.support.v4.view.GravityCompat.START;
public class NavigationBaseActivity extends BaseActivity implements HamburgerMenuContainer {
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.drawer_layout)
DrawerLayout drawerLayout;
@BindView(R.id.drawer_pane)
RelativeLayout drawerPane;
@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);
}
private void initSubviews() {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
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 * 70) / 100;
drawerPane.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);
}
}
@Override
public boolean isDrawerVisible() {
return drawerLayout.isDrawerVisible(START);
}
}

View file

@ -1,71 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_below="@id/toolbar"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:src="@drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/app_name"
style="?android:textAppearanceLarge"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name" />
<TextView
android:id="@+id/about_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content" />
<fr.free.nrw.commons.ui.widget.HtmlTextView
android:id="@+id/about_license"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
style="?android:textAppearanceSmall"
android:gravity="center"
android:text="@string/about_license"
/>
android:text="@string/about_license" />
<fr.free.nrw.commons.ui.widget.HtmlTextView
android:id="@+id/about_improve"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
style="?android:textAppearanceSmall"
android:gravity="center"
android:text="@string/about_improve"
/>
android:text="@string/about_improve" />
<fr.free.nrw.commons.ui.widget.HtmlTextView
android:id="@+id/about_privacy_policy"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
style="?android:textAppearanceSmall"
android:gravity="center"
android:text="@string/about_privacy_policy"
/>
android:text="@string/about_privacy_policy" />
<fr.free.nrw.commons.ui.widget.HtmlTextView
android:id="@+id/about_credits"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
style="?android:textAppearanceSmall"
android:gravity="center"
android:text="@string/about_credits"
/>
android:text="@string/about_credits" />
<TextView
android:id="@+id/about_uploads_to"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:alpha="0.2"
android:gravity="center" />
</LinearLayout>
</RelativeLayout>
<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>

View file

@ -9,8 +9,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/contributions_toolbar"
layout="@layout/contributions_toolbar"
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
@ -20,7 +20,7 @@
android:layout_height="match_parent"
android:id="@+id/contributionsFragmentContainer"
android:orientation="horizontal"
android:layout_below="@id/contributions_toolbar">
android:layout_below="@id/toolbar">
<fragment
android:id="@+id/contributionsListFragment"

View file

@ -1,22 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:orientation="horizontal"
android:layout_below="@id/toolbar">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
android:layout_centerInParent="true" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
android:layout_height="match_parent"></FrameLayout>
</LinearLayout>
</RelativeLayout>
<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>

View file

@ -27,16 +27,6 @@
android:layout_height="0.5dp"
android:background="@android:color/black"/>
<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"