mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
With NavigationBaseActivity implemented
This commit is contained in:
parent
09cd596ff6
commit
a6bbc8a33b
12 changed files with 241 additions and 218 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue