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

MainActivity also uses toolbar. Remove the title on the commits tab

parent 9c6492d4
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -14,19 +14,17 @@
android:theme="@style/AppTheme" >
 
<activity
android:name="com.commit451.gitlab.MainActivity" >
android:name="com.commit451.gitlab.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.commit451.gitlab.LoginActivity"
android:theme="@style/AppThemeNoAB" />
android:name="com.commit451.gitlab.LoginActivity" />
<activity
android:name="com.commit451.gitlab.FileActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/AppThemeNoAB"
android:parentActivityName="com.commit451.gitlab.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
Loading
Loading
@@ -35,7 +33,6 @@
<activity
android:name="com.commit451.gitlab.IssueActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/AppThemeNoAB"
android:parentActivityName="com.commit451.gitlab.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
Loading
Loading
@@ -44,7 +41,6 @@
<activity
android:name="com.commit451.gitlab.DiffActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/AppThemeNoAB"
android:parentActivityName="com.commit451.gitlab.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
Loading
Loading
package com.commit451.gitlab;
 
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
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.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Loading
Loading
@@ -23,6 +23,7 @@ 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.fragments.CommitsFragment;
Loading
Loading
@@ -50,30 +51,62 @@ import retrofit.RetrofitError;
import retrofit.client.Response;
 
public class MainActivity extends BaseActivity implements ActionBar.OnNavigationListener, OnItemClickListener {
@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.left_drawer) LinearLayout drawerLeft;
@Bind(R.id.left_drawer_list) ListView drawerList;
@Bind(R.id.pager) ViewPager viewPager;
 
private ActionBar actionBar;
private ActionBarDrawerToggle drawerToggle;
private final AdapterView.OnItemSelectedListener spinnerItemSelectedListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Repository.selectedBranch = Repository.branches.get(position);
Repository.setLastBranch(Repository.selectedBranch.getName());
loadData();
}
 
private boolean rotationLocked = false;
@Override
public void onNothingSelected(AdapterView<?> parent) { }
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
toolbar.setNavigationIcon(R.drawable.ic_menu);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(GravityCompat.START);
}
});
toolbar.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
if(drawerLayout.isDrawerOpen(drawerLeft))
drawerLayout.closeDrawer(drawerLeft);
else
drawerLayout.openDrawer(drawerLeft);
return true;
case R.id.action_logout:
Repository.setLoggedIn(false);
startActivity(new Intent(MainActivity.this, LoginActivity.class));
return true;
default:
return false;
}
}
});
drawerList.setOnItemClickListener(this);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close);
drawerLayout.setDrawerListener(drawerToggle);
// Workaround that forces the overflow menu
try {
Loading
Loading
@@ -106,18 +139,7 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
// Set up the ViewPager with the sections adapter.
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(3);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
tabs.setupWithViewPager(viewPager);
}
@Override
Loading
Loading
@@ -157,7 +179,7 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
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))) {
Loading
Loading
@@ -166,10 +188,10 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
Repository.issueAdapter = null;
Repository.userAdapter = null;
Repository.drawerAdapter.notifyDataSetChanged();
Repository.getService().getBranches(Repository.selectedProject.getId(), branchesCallback);
}
if(drawerLayout.isDrawerOpen(drawerLeft)) {
drawerLayout.closeDrawer(drawerLeft);
}
Loading
Loading
@@ -328,7 +350,7 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
@Override
public void success(List<Project> projects, Response resp) {
Repository.projects = new ArrayList<Project>(projects);
Repository.projects = new ArrayList<>(projects);
 
if(Repository.projects.size() != 0) {
if(Repository.getLastProject().length() == 0)
Loading
Loading
@@ -374,7 +396,7 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
if(pd != null && pd.isShowing())
pd.cancel();
Repository.branches = new ArrayList<Branch>(branches);
Repository.branches = new ArrayList<>(branches);
Branch[] spinnerData = new Branch[Repository.branches.size()];
int selectedBranchIndex = -1;
Loading
Loading
@@ -387,16 +409,13 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
else if(selectedBranchIndex == -1 && Repository.selectedProject != null && spinnerData[i].getName().equals(Repository.selectedProject.getDefaultBranch()))
selectedBranchIndex = i;
}
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
 
Context context = actionBar.getThemedContext();
if(context == null) context = MainActivity.this;
// Set up the dropdown list navigation in the action bar.
actionBar.setListNavigationCallbacks(new ArrayAdapter<Branch>(context, android.R.layout.simple_list_item_1, android.R.id.text1, spinnerData), MainActivity.this);
if(selectedBranchIndex >= 0)
actionBar.setSelectedNavigationItem(selectedBranchIndex);
branchSpinner.setAdapter(new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, spinnerData));
if (selectedBranchIndex >= 0) {
branchSpinner.setSelection(selectedBranchIndex);
}
branchSpinner.setOnItemSelectedListener(spinnerItemSelectedListener);
if(Repository.branches.size() == 0) {
Repository.selectedBranch = null;
Loading
Loading
@@ -412,10 +431,6 @@ public class MainActivity extends BaseActivity implements ActionBar.OnNavigation
if(e.getResponse().getStatus() == 500) {
Repository.selectedBranch = null;
loadData();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
return;
}
 
Loading
Loading
package com.commit451.gitlab.fragments;
 
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.HeaderViewListAdapter;
import android.widget.ListView;
 
Loading
Loading
@@ -32,9 +29,8 @@ import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
 
public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener, OnItemClickListener {
public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, OnItemClickListener {
 
private EditText repoUrl;
@Bind(R.id.fragmentList) ListView listView;
@Bind(R.id.swipe_layout) SwipeRefreshLayout swipeLayout;
Loading
Loading
@@ -46,17 +42,6 @@ public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRe
ButterKnife.bind(this, view);
listView.setOnItemClickListener(this);
repoUrl = new EditText(getActivity());
repoUrl.setClickable(true);
repoUrl.setCursorVisible(false);
repoUrl.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_copy, 0);
repoUrl.setFocusable(false);
repoUrl.setFocusableInTouchMode(false);
repoUrl.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
repoUrl.setMaxLines(1);
repoUrl.setOnClickListener(this);
repoUrl.setPadding(26, 26, 26, 26);
listView.addHeaderView(repoUrl);
 
swipeLayout.setOnRefreshListener(this);
 
Loading
Loading
@@ -80,9 +65,7 @@ public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRe
public void loadData() {
if(Repository.selectedProject == null)
return;
repoUrl.setText("git@" + Repository.getServerUrl().replaceAll("http://", "").replaceAll("https://", "") + ":" + Repository.selectedProject.getPathWithNamespace() + ".git");
if(Repository.selectedBranch == null) {
if(swipeLayout != null && swipeLayout.isRefreshing())
swipeLayout.setRefreshing(false);
Loading
Loading
@@ -124,15 +107,6 @@ public class CommitsFragment extends Fragment implements SwipeRefreshLayout.OnRe
listView.setAdapter(null);
}
};
@Override
public void onClick(View v) {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", repoUrl.getText().toString());
clipboard.setPrimaryClip(clip);
Crouton.makeText(this.getActivity(), R.string.copy_notification, Style.CONFIRM).show();
}
public boolean onBackPressed() {
return false;
Loading
Loading
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
 
<RelativeLayout
<LinearLayout
android:id="@+id/main_content_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent"
android:orientation="vertical">
 
<android.support.v4.view.ViewPager
android:id="@+id/pager"
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" >
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/branch_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</android.support.v7.widget.Toolbar>
 
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
</RelativeLayout>
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/left_drawer"
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@
 
<ListView
android:id="@+id/fragmentList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
android:layout_width="match_parent"
android:layout_height="match_parent" />
 
</com.commit451.gitlab.views.GitLabSwipeRefreshLayout>
\ No newline at end of file
Loading
Loading
@@ -20,10 +20,10 @@
 
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_issue_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="bottom|right"
android:src="@drawable/ic_add"
android:layout_margin="@dimen/padding_normal"/>
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/padding_normal"
android:src="@drawable/ic_add" />
 
</FrameLayout>
Loading
Loading
@@ -3,4 +3,6 @@
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="padding_normal">16dp</dimen>
<dimen name="actionbarSize">56dp</dimen>
<dimen name="doubleActionbarSize">112dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/grey</item>
<item name="colorPrimaryDark">@color/grey_dark</item>
Loading
Loading
@@ -9,11 +9,4 @@
<item name="colorAccent">@color/orange</item>
</style>
 
<style name="AppThemeNoAB" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/grey</item>
<item name="colorPrimaryDark">@color/grey_dark</item>
<item name="android:navigationBarColor">?attr/colorPrimaryDark</item>
<item name="colorAccent">@color/orange</item>
</style>
</resources>
\ No newline at end of file
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