mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +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); | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 maskara
						maskara