Skip to content
Snippets Groups Projects
Commit e000ce5d authored by John Carlson's avatar John Carlson
Browse files

Create local model "Ref" to determine if project is referring to a branch or a...

Create local model "Ref" to determine if project is referring to a branch or a tag. Set the selected tag/branch
parent c343d943
No related branches found
No related tags found
No related merge requests found
Showing
with 155 additions and 38 deletions
Loading
Loading
@@ -119,12 +119,12 @@ dependencies {
compile 'com.github.ivbaranov:materiallettericon:0.2.2'
compile 'com.github.johnkil.android-robototextview:robototextview:2.5.0'
compile 'com.github.alorma:diff-textview:1.3.0'
compile 'com.wdullaer:materialdatetimepicker:2.4.0'
compile 'com.wdullaer:materialdatetimepicker:2.5.0'
compile 'com.wefika:flowlayout:0.4.1'
compile 'com.github.novoda:simple-chrome-custom-tabs:0.1.3-rc1'
compile 'com.afollestad.material-dialogs:core:0.8.6.2'
compile 'com.afollestad.material-dialogs:commons:0.8.6.2'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
 
normalCompile('com.crashlytics.sdk.android:crashlytics:2.6.1@aar') {
transitive = true;
Loading
Loading
Loading
Loading
@@ -3,12 +3,16 @@ package com.commit451.gitlab.activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
 
import com.commit451.gitlab.R;
import com.commit451.gitlab.adapter.PickBranchOrTagPagerAdapter;
import com.commit451.gitlab.model.Ref;
import org.parceler.Parcels;
 
import butterknife.BindView;
import butterknife.ButterKnife;
Loading
Loading
@@ -20,12 +24,14 @@ import butterknife.OnClick;
public class PickBranchOrTagActivity extends AppCompatActivity {
 
private static final String EXTRA_PROJECT_ID = "project_id";
private static final String EXTRA_CURRENT_REF = "current_ref";
 
public static final String EXTRA_REF = "ref";
 
public static Intent newIntent(Context context, long projectId) {
public static Intent newIntent(Context context, long projectId, @Nullable Ref currentRef) {
Intent intent = new Intent(context, PickBranchOrTagActivity.class);
intent.putExtra(EXTRA_PROJECT_ID, projectId);
intent.putExtra(EXTRA_CURRENT_REF, Parcels.wrap(currentRef));
return intent;
}
 
Loading
Loading
@@ -45,7 +51,8 @@ public class PickBranchOrTagActivity extends AppCompatActivity {
setContentView(R.layout.activity_pick_branch_or_tag);
ButterKnife.bind(this);
long projectId = getIntent().getLongExtra(EXTRA_PROJECT_ID, -1);
mViewPager.setAdapter(new PickBranchOrTagPagerAdapter(this, getSupportFragmentManager(), projectId));
Ref currentRef = Parcels.unwrap(getIntent().getParcelableExtra(EXTRA_CURRENT_REF));
mViewPager.setAdapter(new PickBranchOrTagPagerAdapter(this, getSupportFragmentManager(), projectId, currentRef));
mTabLayout.setupWithViewPager(mViewPager);
}
 
Loading
Loading
Loading
Loading
@@ -23,6 +23,7 @@ import com.commit451.gitlab.adapter.ProjectSectionsPagerAdapter;
import com.commit451.gitlab.animation.HideRunnable;
import com.commit451.gitlab.event.ProjectReloadEvent;
import com.commit451.gitlab.fragment.BaseFragment;
import com.commit451.gitlab.model.Ref;
import com.commit451.gitlab.model.api.Branch;
import com.commit451.gitlab.model.api.Project;
import com.commit451.gitlab.navigation.Navigator;
Loading
Loading
@@ -68,7 +69,7 @@ public class ProjectActivity extends BaseActivity {
ViewPager mViewPager;
 
Project mProject;
String mBranchName;
Ref mRef;
 
private final Callback<Project> mProjectCallback = new EasyCallback<Project>() {
@Override
Loading
Loading
@@ -99,7 +100,8 @@ public class ProjectActivity extends BaseActivity {
 
for (int i = 0; i < response.size(); i++) {
if (response.get(i).getName().equals(mProject.getDefaultBranch())) {
mBranchName = response.get(i).getName();
String ref = response.get(i).getName();
mRef = new Ref(Ref.TYPE_BRANCH, ref);
}
}
 
Loading
Loading
@@ -125,7 +127,7 @@ public class ProjectActivity extends BaseActivity {
switch (item.getItemId()) {
case R.id.action_branch:
if (mProject != null) {
Navigator.navigateToPickBranchOrTag(ProjectActivity.this, mProject.getId(), REQUEST_BRANCH_OR_TAG);
Navigator.navigateToPickBranchOrTag(ProjectActivity.this, mProject.getId(), mRef, REQUEST_BRANCH_OR_TAG);
}
return true;
case R.id.action_share:
Loading
Loading
@@ -186,7 +188,7 @@ public class ProjectActivity extends BaseActivity {
switch (requestCode) {
case REQUEST_BRANCH_OR_TAG:
if (resultCode == RESULT_OK) {
mBranchName = data.getStringExtra(PickBranchOrTagActivity.EXTRA_REF);
mRef = Parcels.unwrap(data.getParcelableExtra(PickBranchOrTagActivity.EXTRA_REF));
broadcastLoad();
}
break;
Loading
Loading
@@ -208,7 +210,7 @@ public class ProjectActivity extends BaseActivity {
}
 
private void broadcastLoad() {
App.bus().post(new ProjectReloadEvent(mProject, mBranchName));
App.bus().post(new ProjectReloadEvent(mProject, mRef.getRef()));
}
 
@Override
Loading
Loading
@@ -223,8 +225,11 @@ public class ProjectActivity extends BaseActivity {
super.onBackPressed();
}
 
public String getBranchName() {
return mBranchName;
public String getRef() {
if (mRef == null) {
return null;
}
return mRef.getRef();
}
 
public Project getProject() {
Loading
Loading
package com.commit451.gitlab.adapter;
 
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
 
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.Ref;
import com.commit451.gitlab.model.api.Branch;
import com.commit451.gitlab.model.rss.Entry;
import com.commit451.gitlab.viewHolder.BranchViewHolder;
import com.commit451.gitlab.viewHolder.FeedEntryViewHolder;
 
import java.util.ArrayList;
import java.util.Collection;
Loading
Loading
@@ -24,10 +24,13 @@ public class BranchesAdapter extends RecyclerView.Adapter<BranchViewHolder> {
private Listener mListener;
 
private ArrayList<Branch> mValues;
@Nullable
private Ref mRef;
 
public BranchesAdapter(Listener listener) {
public BranchesAdapter(@Nullable Ref currentRef, Listener listener) {
mListener = listener;
mValues = new ArrayList<>();
mRef = currentRef;
}
 
private final View.OnClickListener mOnItemClickListener = new View.OnClickListener() {
Loading
Loading
@@ -56,7 +59,15 @@ public class BranchesAdapter extends RecyclerView.Adapter<BranchViewHolder> {
@Override
public void onBindViewHolder(final BranchViewHolder holder, int position) {
holder.itemView.setTag(R.id.list_position, position);
holder.bind(getEntry(position));
Branch branch = getEntry(position);
boolean selected = false;
if (mRef != null) {
if (mRef.getType() == Ref.TYPE_BRANCH
&& mRef.getRef().equals(branch.getName())) {
selected = true;
}
}
holder.bind(branch, selected);
}
 
@Override
Loading
Loading
package com.commit451.gitlab.adapter;
 
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
Loading
Loading
@@ -8,6 +9,7 @@ import android.support.v4.app.FragmentPagerAdapter;
import com.commit451.gitlab.R;
import com.commit451.gitlab.fragment.PickBranchFragment;
import com.commit451.gitlab.fragment.PickTagFragment;
import com.commit451.gitlab.model.Ref;
 
/**
* Projects Pager Adapter
Loading
Loading
@@ -16,11 +18,13 @@ public class PickBranchOrTagPagerAdapter extends FragmentPagerAdapter {
 
private String[] mTitles;
private long mProjectId;
private Ref mCurrentRef;
 
public PickBranchOrTagPagerAdapter(Context context, FragmentManager fm, long projectId) {
public PickBranchOrTagPagerAdapter(Context context, FragmentManager fm, long projectId, @Nullable Ref currentRef) {
super(fm);
mTitles = context.getResources().getStringArray(R.array.tabs_branch_tag);
mProjectId = projectId;
mCurrentRef = currentRef;
}
 
@Override
Loading
Loading
@@ -28,9 +32,9 @@ public class PickBranchOrTagPagerAdapter extends FragmentPagerAdapter {
 
switch(position) {
case 0:
return PickBranchFragment.newInstance(mProjectId);
return PickBranchFragment.newInstance(mProjectId, mCurrentRef);
case 1:
return PickTagFragment.newInstance(mProjectId);
return PickTagFragment.newInstance(mProjectId, mCurrentRef);
}
 
throw new IllegalStateException("Position exceeded on view pager");
Loading
Loading
package com.commit451.gitlab.adapter;
 
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
 
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.Ref;
import com.commit451.gitlab.model.api.Tag;
import com.commit451.gitlab.viewHolder.TagViewHolder;
 
Loading
Loading
@@ -22,10 +24,13 @@ public class TagsAdapter extends RecyclerView.Adapter<TagViewHolder> {
private Listener mListener;
 
private ArrayList<Tag> mValues;
@Nullable
private Ref mRef;
 
public TagsAdapter(Listener listener) {
public TagsAdapter(@Nullable Ref ref, Listener listener) {
mListener = listener;
mValues = new ArrayList<>();
mRef = ref;
}
 
private final View.OnClickListener mOnItemClickListener = new View.OnClickListener() {
Loading
Loading
@@ -54,7 +59,15 @@ public class TagsAdapter extends RecyclerView.Adapter<TagViewHolder> {
@Override
public void onBindViewHolder(final TagViewHolder holder, int position) {
holder.itemView.setTag(R.id.list_position, position);
holder.bind(getEntry(position));
Tag tag = getEntry(position);
boolean selected = false;
if (mRef != null) {
if (mRef.getType() == Ref.TYPE_TAG
&& mRef.getRef().equals(tag.getName())) {
selected = true;
}
}
holder.bind(tag, selected);
}
 
@Override
Loading
Loading
Loading
Loading
@@ -17,7 +17,6 @@ import com.commit451.gitlab.activity.ProjectActivity;
import com.commit451.gitlab.adapter.CommitsAdapter;
import com.commit451.gitlab.adapter.DividerItemDecoration;
import com.commit451.easycallback.EasyCallback;
import com.commit451.gitlab.api.GitLabFactory;
import com.commit451.gitlab.event.ProjectReloadEvent;
import com.commit451.gitlab.model.api.Project;
import com.commit451.gitlab.model.api.RepositoryCommit;
Loading
Loading
@@ -156,7 +155,7 @@ public class CommitsFragment extends ButterKnifeFragment {
 
if (getActivity() instanceof ProjectActivity) {
mProject = ((ProjectActivity) getActivity()).getProject();
mBranchName = ((ProjectActivity) getActivity()).getBranchName();
mBranchName = ((ProjectActivity) getActivity()).getRef();
loadData();
} else {
throw new IllegalStateException("Incorrect parent activity");
Loading
Loading
Loading
Loading
@@ -22,7 +22,6 @@ import com.commit451.gitlab.adapter.BreadcrumbAdapter;
import com.commit451.gitlab.adapter.DividerItemDecoration;
import com.commit451.gitlab.adapter.FilesAdapter;
import com.commit451.easycallback.EasyCallback;
import com.commit451.gitlab.api.GitLabFactory;
import com.commit451.gitlab.event.ProjectReloadEvent;
import com.commit451.gitlab.model.api.Project;
import com.commit451.gitlab.model.api.RepositoryTreeObject;
Loading
Loading
@@ -161,7 +160,7 @@ public class FilesFragment extends ButterKnifeFragment {
 
if (getActivity() instanceof ProjectActivity) {
mProject = ((ProjectActivity) getActivity()).getProject();
mBranchName = ((ProjectActivity) getActivity()).getBranchName();
mBranchName = ((ProjectActivity) getActivity()).getRef();
loadData("");
} else {
throw new IllegalStateException("Incorrect parent activity");
Loading
Loading
Loading
Loading
@@ -17,8 +17,11 @@ import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.activity.PickBranchOrTagActivity;
import com.commit451.gitlab.adapter.BranchesAdapter;
import com.commit451.gitlab.model.Ref;
import com.commit451.gitlab.model.api.Branch;
 
import org.parceler.Parcels;
import java.util.List;
 
import butterknife.BindView;
Loading
Loading
@@ -30,11 +33,13 @@ import timber.log.Timber;
public class PickBranchFragment extends ButterKnifeFragment {
 
private static final String EXTRA_PROJECT_ID = "project_id";
private static final String EXTRA_REF = "ref";
 
public static PickBranchFragment newInstance(long projectId) {
public static PickBranchFragment newInstance(long projectId, @Nullable Ref ref) {
PickBranchFragment fragment = new PickBranchFragment();
Bundle args = new Bundle();
args.putLong(EXTRA_PROJECT_ID, projectId);
args.putParcelable(EXTRA_REF, Parcels.wrap(ref));
fragment.setArguments(args);
return fragment;
}
Loading
Loading
@@ -63,11 +68,13 @@ public class PickBranchFragment extends ButterKnifeFragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
 
mBranchesAdapter = new BranchesAdapter(new BranchesAdapter.Listener() {
Ref existingRef = Parcels.unwrap(getArguments().getParcelable(EXTRA_REF));
mBranchesAdapter = new BranchesAdapter(existingRef, new BranchesAdapter.Listener() {
@Override
public void onBranchClicked(Branch entry) {
Intent data = new Intent();
data.putExtra(PickBranchOrTagActivity.EXTRA_REF, entry.getName());
Ref ref = new Ref(Ref.TYPE_BRANCH, entry.getName());
data.putExtra(PickBranchOrTagActivity.EXTRA_REF, Parcels.wrap(ref));
getActivity().setResult(Activity.RESULT_OK, data);
getActivity().finish();
}
Loading
Loading
Loading
Loading
@@ -17,8 +17,11 @@ import com.commit451.gitlab.App;
import com.commit451.gitlab.R;
import com.commit451.gitlab.activity.PickBranchOrTagActivity;
import com.commit451.gitlab.adapter.TagsAdapter;
import com.commit451.gitlab.model.Ref;
import com.commit451.gitlab.model.api.Tag;
 
import org.parceler.Parcels;
import java.util.List;
 
import butterknife.BindView;
Loading
Loading
@@ -30,11 +33,13 @@ import timber.log.Timber;
public class PickTagFragment extends ButterKnifeFragment {
 
private static final String EXTRA_PROJECT_ID = "project_id";
private static final String EXTRA_CURRENT_REF = "current_ref";
 
public static PickTagFragment newInstance(long projectId) {
public static PickTagFragment newInstance(long projectId, @Nullable Ref ref) {
PickTagFragment fragment = new PickTagFragment();
Bundle args = new Bundle();
args.putLong(EXTRA_PROJECT_ID, projectId);
args.putParcelable(EXTRA_CURRENT_REF, Parcels.wrap(ref));
fragment.setArguments(args);
return fragment;
}
Loading
Loading
@@ -63,12 +68,14 @@ public class PickTagFragment extends ButterKnifeFragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
 
mTagsAdapter = new TagsAdapter(new TagsAdapter.Listener() {
Ref ref = Parcels.unwrap(getArguments().getParcelable(EXTRA_CURRENT_REF));
mTagsAdapter = new TagsAdapter(ref, new TagsAdapter.Listener() {
 
@Override
public void onTagClicked(Tag entry) {
Intent data = new Intent();
data.putExtra(PickBranchOrTagActivity.EXTRA_REF, entry.getName());
Ref ref = new Ref(Ref.TYPE_TAG, entry.getName());
data.putExtra(PickBranchOrTagActivity.EXTRA_REF, Parcels.wrap(ref));
getActivity().setResult(Activity.RESULT_OK, data);
getActivity().finish();
}
Loading
Loading
Loading
Loading
@@ -291,7 +291,7 @@ public class ProjectFragment extends ButterKnifeFragment {
 
if (getActivity() instanceof ProjectActivity) {
mProject = ((ProjectActivity) getActivity()).getProject();
mBranchName = ((ProjectActivity) getActivity()).getBranchName();
mBranchName = ((ProjectActivity) getActivity()).getRef();
bindProject(mProject);
loadData();
} else {
Loading
Loading
Loading
Loading
@@ -17,6 +17,9 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
 
/**
* An account, stored locally, which references the needed info to connect to a server
*/
@Parcel
@JsonObject
public class Account implements Comparable<Account>{
Loading
Loading
package com.commit451.gitlab.model;
import android.support.annotation.IntDef;
import org.parceler.Parcel;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Local only model that references either a branch or a tag, and holds its type
*/
@Parcel
public class Ref {
@Retention(RetentionPolicy.SOURCE)
@IntDef({TYPE_BRANCH, TYPE_TAG})
public @interface Type {}
public static final int TYPE_BRANCH = 0;
public static final int TYPE_TAG = 1;
int mType;
String mRef;
protected Ref() {
}
public Ref(@Type int type, String ref) {
mType = type;
mRef = ref;
}
public int getType() {
return mType;
}
public String getRef() {
return mRef;
}
}
Loading
Loading
@@ -5,6 +5,7 @@ import android.app.ActivityOptions;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityOptionsCompat;
import android.view.View;
import android.widget.ImageView;
Loading
Loading
@@ -36,6 +37,7 @@ import com.commit451.gitlab.activity.UserActivity;
import com.commit451.gitlab.activity.WebviewLoginActivity;
import com.commit451.gitlab.data.Prefs;
import com.commit451.gitlab.model.Account;
import com.commit451.gitlab.model.Ref;
import com.commit451.gitlab.model.api.Group;
import com.commit451.gitlab.model.api.Issue;
import com.commit451.gitlab.model.api.MergeRequest;
Loading
Loading
@@ -68,8 +70,8 @@ public class Navigator {
activity.startActivity(ProjectActivity.newIntent(activity, projectId));
}
 
public static void navigateToPickBranchOrTag(Activity activity, long projectId, int requestCode) {
activity.startActivityForResult(PickBranchOrTagActivity.newIntent(activity, projectId), requestCode);
public static void navigateToPickBranchOrTag(Activity activity, long projectId, @Nullable Ref currentRef, int requestCode) {
activity.startActivityForResult(PickBranchOrTagActivity.newIntent(activity, projectId, currentRef), requestCode);
}
 
public static void navigateToStartingActivity(Activity activity) {
Loading
Loading
Loading
Loading
@@ -6,9 +6,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import com.commit451.easel.Easel;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.api.Branch;
import com.commit451.gitlab.model.api.Label;
 
import butterknife.BindView;
import butterknife.ButterKnife;
Loading
Loading
@@ -24,14 +24,23 @@ public class BranchViewHolder extends RecyclerView.ViewHolder {
return new BranchViewHolder(view);
}
 
@BindView(R.id.title) public TextView title;
@BindView(R.id.title)
public TextView title;
int colorHighlighted;
 
public BranchViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
colorHighlighted = Easel.getThemeAttrColor(itemView.getContext(), R.attr.colorControlHighlight);
}
 
public void bind(Branch branch) {
public void bind(Branch branch, boolean selected) {
title.setText(branch.getName());
if (selected) {
itemView.setBackgroundColor(colorHighlighted);
} else {
itemView.setBackground(null);
}
}
}
\ No newline at end of file
Loading
Loading
@@ -6,6 +6,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
import com.commit451.easel.Easel;
import com.commit451.gitlab.R;
import com.commit451.gitlab.model.api.Tag;
 
Loading
Loading
@@ -23,14 +24,23 @@ public class TagViewHolder extends RecyclerView.ViewHolder {
return new TagViewHolder(view);
}
 
@BindView(R.id.title) public TextView title;
@BindView(R.id.title)
public TextView title;
int colorHighlighted;
 
public TagViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
colorHighlighted = Easel.getThemeAttrColor(itemView.getContext(), R.attr.colorControlHighlight);
}
 
public void bind(Tag tag) {
public void bind(Tag tag, boolean selected) {
title.setText(tag.getName());
if (selected) {
itemView.setBackgroundColor(colorHighlighted);
} else {
itemView.setBackground(null);
}
}
}
\ 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