Skip to content
Snippets Groups Projects
Commit c6eb61ad authored by Jawn's avatar Jawn
Browse files

New implementation of nav drawer

parent daecf961
No related branches found
No related tags found
No related merge requests found
Showing
with 87 additions and 255 deletions
Loading
Loading
@@ -39,6 +39,7 @@ dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup:otto:1.3.8'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.jakewharton.timber:timber:3.1.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
Loading
Loading
Loading
Loading
@@ -2,6 +2,9 @@ package com.commit451.gitlab;
 
import android.app.Application;
 
import com.commit451.gitlab.tools.Repository;
import com.squareup.otto.Bus;
import net.danlew.android.joda.JodaTimeAndroid;
 
/**
Loading
Loading
@@ -10,9 +13,18 @@ import net.danlew.android.joda.JodaTimeAndroid;
*/
public class GitLabApp extends Application {
 
private static Bus bus;
public static Bus bus() {
if (bus == null) {
bus = new Bus();
}
return bus;
}
@Override
public void onCreate() {
super.onCreate();
Repository.init(this);
JodaTimeAndroid.init(this);
}
}
Loading
Loading
@@ -12,20 +12,17 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner;
 
import com.commit451.gitlab.adapter.DrawerAdapter;
import com.commit451.gitlab.events.CloseDrawerEvent;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.fragments.CommitsFragment;
import com.commit451.gitlab.fragments.FilesFragment;
import com.commit451.gitlab.fragments.IssuesFragment;
Loading
Loading
@@ -37,6 +34,7 @@ import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.Repository;
import com.commit451.gitlab.tools.RetrofitHelper;
import com.commit451.gitlab.views.GitLabNavigationView;
import com.squareup.otto.Subscribe;
 
import java.lang.reflect.Field;
import java.util.ArrayList;
Loading
Loading
@@ -49,15 +47,13 @@ import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
 
public class MainActivity extends BaseActivity implements ActionBar.OnNavigationListener, OnItemClickListener {
public class MainActivity extends BaseActivity {
 
@Bind(R.id.toolbar) Toolbar toolbar;
@Bind(R.id.tabs) TabLayout tabs;
@Bind(R.id.branch_spinner) Spinner branchSpinner;
@Bind(R.id.drawer_layout) DrawerLayout drawerLayout;
@Bind(R.id.navigation_view) GitLabNavigationView navigationView;
@Bind(R.id.left_drawer) LinearLayout drawerLeft;
@Bind(R.id.left_drawer_list) ListView drawerList;
@Bind(R.id.pager) ViewPager viewPager;
 
private final AdapterView.OnItemSelectedListener spinnerItemSelectedListener = new AdapterView.OnItemSelectedListener() {
Loading
Loading
@@ -71,6 +67,8 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
@Override
public void onNothingSelected(AdapterView<?> parent) { }
};
EventReceiver eventReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
Loading
Loading
@@ -78,6 +76,9 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
 
eventReceiver = new EventReceiver();
GitLabApp.bus().register(eventReceiver);
toolbar.setNavigationIcon(R.drawable.ic_menu);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
Loading
Loading
@@ -100,8 +101,6 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
}
});
drawerList.setOnItemClickListener(this);
// Workaround that forces the overflow menu
try {
ViewConfiguration config = ViewConfiguration.get(this);
Loading
Loading
@@ -115,8 +114,6 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
ex.printStackTrace();
}
Repository.init(this);
if(!Repository.isLoggedIn())
startActivity(new Intent(this, LoginActivity.class));
else
Loading
Loading
@@ -135,30 +132,11 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
viewPager.setOffscreenPageLimit(3);
tabs.setupWithViewPager(viewPager);
}
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Repository.selectedBranch = Repository.branches.get(itemPosition);
Repository.setLastBranch(Repository.selectedBranch.getName());
loadData();
return true;
}
 
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(Repository.selectedProject == null || !Repository.selectedProject.equals(Repository.projects.get(position))) {
Repository.selectedProject = Repository.projects.get(position);
Repository.setLastProject(Repository.selectedProject.toString());
Repository.issueAdapter = null;
Repository.userAdapter = null;
Repository.drawerAdapter.notifyDataSetChanged();
Repository.getService().getBranches(Repository.selectedProject.getId(), branchesCallback);
}
if(drawerLayout.isDrawerOpen(drawerLeft)) {
drawerLayout.closeDrawer(drawerLeft);
}
protected void onDestroy() {
GitLabApp.bus().unregister(eventReceiver);
super.onDestroy();
}
 
public void hideSoftKeyboard() {
Loading
Loading
@@ -252,13 +230,13 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
Locale l = Locale.getDefault();
switch(position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
return getString(R.string.title_section1);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
return getString(R.string.title_section2);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
return getString(R.string.title_section3);
case 3:
return getString(R.string.title_section4).toUpperCase(l);
return getString(R.string.title_section4);
}
return null;
}
Loading
Loading
@@ -277,7 +255,7 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
@Override
public void success(List<Group> groups, Response resp) {
Repository.groups = new ArrayList<Group>(groups);
Repository.groups = new ArrayList<>(groups);
Repository.getService().getUsers(usersCallback);
}
Loading
Loading
@@ -285,7 +263,6 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
@Override
public void failure(RetrofitError e) {
RetrofitHelper.printDebugInfo(MainActivity.this, e);
Repository.getService().getUsers(usersCallback);
}
};
Loading
Loading
@@ -333,9 +310,6 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
}
}
Repository.drawerAdapter = new DrawerAdapter(MainActivity.this, Repository.projects);
drawerList.setAdapter(Repository.drawerAdapter);
if(Repository.selectedProject != null)
Repository.getService().getBranches(Repository.selectedProject.getId(), branchesCallback);
else {
Loading
Loading
@@ -407,4 +381,17 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
.show();
}
};
private class EventReceiver {
@Subscribe
public void onCloseDrawerEvent(CloseDrawerEvent event) {
drawerLayout.closeDrawers();
}
@Subscribe
public void onProjectChanged(ProjectChangedEvent event) {
Repository.getService().getBranches(Repository.selectedProject.getId(), branchesCallback);
}
}
}
package com.commit451.gitlab.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.Project;
import com.commit451.gitlab.model.User;
import com.commit451.gitlab.tools.Repository;
import java.util.ArrayList;
public class DrawerAdapter extends BaseAdapter implements Filterable {
private LayoutInflater inflater;
private Filter filter = new FilterByName();
private ArrayList<Project> projects;
private ArrayList<Project> allProjects;
public DrawerAdapter(Context context, ArrayList<Project> projects) {
this.projects = projects;
this.allProjects = new ArrayList<Project>(projects);
if(context != null)
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return projects.size();
}
@Override
public Project getItem(int position) {
return projects.get(position);
}
@Override
public long getItemId(int position) {
return projects.get(position).getId();
}
public int getPosition(User user) {
return projects.indexOf(user);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) convertView = inflater.inflate(R.layout.simple_list_item, parent, false);
final float scale = convertView.getResources().getDisplayMetrics().density;
convertView.setMinimumHeight((int) (48 * scale + 0.5f));
final TextView text = (TextView) convertView.findViewById(R.id.text);
text.setText(projects.get(position).toString());
text.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
v.setSelected(true);
}
});
if(Repository.selectedProject != null && Repository.selectedProject.equals(projects.get(position))) {
text.setTextColor(convertView.getResources().getColor(android.R.color.primary_text_light));
text.setCompoundDrawablesWithIntrinsicBounds(null, null, convertView.getResources().getDrawable(R.drawable.ic_selected), null);
}
else {
text.setTextColor(convertView.getResources().getColor(android.R.color.secondary_text_light));
text.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}
return convertView;
}
@Override
public Filter getFilter() {
return filter;
}
private class FilterByName extends Filter {
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
projects.clear();
for(Project project : (ArrayList<Project>) results.values)
projects.add(project);
notifyDataSetChanged();
}
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults result = new FilterResults();
if(constraint == null || constraint.length() == 0) {
result.values = allProjects;
result.count = allProjects.size();
}
else {
ArrayList<Project> filteredList = new ArrayList<Project>();
for(Project project : allProjects) {
if(project.toString().toLowerCase().contains(constraint.toString().toLowerCase()))
filteredList.add(project);
}
result.values = filteredList;
result.count = filteredList.size();
}
return result;
}
}
}
Loading
Loading
@@ -4,8 +4,12 @@ import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
 
import com.commit451.gitlab.GitLabApp;
import com.commit451.gitlab.R;
import com.commit451.gitlab.events.CloseDrawerEvent;
import com.commit451.gitlab.events.ProjectChangedEvent;
import com.commit451.gitlab.model.Project;
import com.commit451.gitlab.tools.Repository;
import com.commit451.gitlab.viewHolders.ProjectViewHolder;
 
import java.util.List;
Loading
Loading
@@ -29,9 +33,16 @@ public class ProjectsAdapter extends RecyclerView.Adapter<ProjectViewHolder> {
@Override
public void onClick(View v) {
int position = (int) v.getTag(R.id.list_position);
//do the things
if(Repository.selectedProject == null || !Repository.selectedProject.equals(Repository.projects.get(position))) {
//TODO make the event bus control most of this. NO MORE STATIC UI
Repository.selectedProject = Repository.projects.get(position);
Repository.setLastProject(Repository.selectedProject.toString());
Repository.issueAdapter = null;
Repository.userAdapter = null;
notifyDataSetChanged();
}
GitLabApp.bus().post(new CloseDrawerEvent());
GitLabApp.bus().post(new ProjectChangedEvent(position));
}
};
 
Loading
Loading
package com.commit451.gitlab.events;
/**
* Close the drawer!
* Created by Jawn on 7/28/2015.
*/
public class CloseDrawerEvent {
}
package com.commit451.gitlab.events;
/**
* We switched to a different project
* Created by Jawn on 7/28/2015.
*/
public class ProjectChangedEvent {
public int position;
public ProjectChangedEvent(int position) {
this.position = position;
}
}
package com.commit451.gitlab.tools;
 
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.view.Surface;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
 
import com.commit451.gitlab.adapter.DrawerAdapter;
import com.commit451.gitlab.adapter.IssuesAdapter;
import com.commit451.gitlab.adapter.UserAdapter;
import com.commit451.gitlab.model.Branch;
Loading
Loading
@@ -54,8 +49,7 @@ public class Repository {
public static DiffLine selectedCommit;
public static DiffLine newestCommit;
public static DrawerAdapter drawerAdapter;
public static IssuesAdapter issueAdapter;
public static UserAdapter userAdapter;
Loading
Loading
@@ -85,8 +79,7 @@ public class Repository {
selectedUser = null;
newestCommit = null;
drawerAdapter = null;
issueAdapter = null;
userAdapter = null;
}
Loading
Loading
@@ -192,67 +185,6 @@ public class Repository {
listView.setLayoutParams(params);
listView.requestLayout();
}
public static int getScreenOrientation(Activity activity) {
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
int orientation;
// if the device's natural orientation is portrait:
if ((rotation == Surface.ROTATION_0
|| rotation == Surface.ROTATION_180) && height > width ||
(rotation == Surface.ROTATION_90
|| rotation == Surface.ROTATION_270) && width > height) {
switch(rotation) {
case Surface.ROTATION_0:
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
break;
case Surface.ROTATION_90:
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
break;
case Surface.ROTATION_180:
orientation =
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
break;
case Surface.ROTATION_270:
orientation =
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
break;
default:
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
break;
}
}
// if the device's natural orientation is landscape or if the device
// is square:
else {
switch(rotation) {
case Surface.ROTATION_0:
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
break;
case Surface.ROTATION_90:
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
break;
case Surface.ROTATION_180:
orientation =
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
break;
case Surface.ROTATION_270:
orientation =
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
break;
default:
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
break;
}
}
return orientation;
}
public static void resetService() {
service = null;
Loading
Loading
app/src/main/res/drawable-hdpi/ic_copy.png

526 B

app/src/main/res/drawable-hdpi/ic_selected.png

2.16 KiB

app/src/main/res/drawable-mdpi/ic_copy.png

378 B

app/src/main/res/drawable-mdpi/ic_selected.png

1.67 KiB

app/src/main/res/drawable-xhdpi/ic_copy.png

677 B

app/src/main/res/drawable-xhdpi/ic_selected.png

2.67 KiB

app/src/main/res/drawable-xxhdpi/ic_copy.png

920 B

app/src/main/res/drawable-xxxhdpi/ic_copy.png

1.44 KiB

Loading
Loading
@@ -45,27 +45,13 @@
android:layout_height="match_parent" />
 
</LinearLayout>
<LinearLayout
android:id="@+id/left_drawer"
<com.commit451.gitlab.views.GitLabNavigationView
android:id="@+id/navigation_view"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:background="?android:attr/colorForegroundInverse">
<ListView
android:id="@+id/left_drawer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:dividerHeight="1dp" />
<com.commit451.gitlab.views.GitLabNavigationView
android:id="@+id/navigation_view"
android:layout_width="300dp"
android:layout_height="match_parent"/>
</LinearLayout>
android:clickable="true"
android:background="?android:attr/colorForegroundInverse"/>
 
</android.support.v4.widget.DrawerLayout>
\ No newline at end of file
Loading
Loading
@@ -6,7 +6,8 @@
 
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="192dp"
android:scaleType="fitXY"
android:src="@drawable/header_image"
android:tint="?attr/colorPrimary"
android:background="?attr/colorAccent"
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment