added badges for repos to close #86 and made a separate commits filter by branch to improve #118 and #100

This commit is contained in:
Kosh 2017-03-11 19:37:22 +08:00
parent 7ead042c71
commit bf808502c0
9 changed files with 173 additions and 32 deletions

View File

@ -10,12 +10,14 @@ import com.fastaccess.data.dao.RepoModel;
import com.fastaccess.helper.ParseDateFormat;
import com.fastaccess.ui.widgets.AvatarLayout;
import com.fastaccess.ui.widgets.FontTextView;
import com.fastaccess.ui.widgets.RoundBackgroundSpan;
import com.fastaccess.ui.widgets.SpannableBuilder;
import com.fastaccess.ui.widgets.recyclerview.BaseRecyclerAdapter;
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder;
import java.text.NumberFormat;
import butterknife.BindColor;
import butterknife.BindString;
import butterknife.BindView;
@ -31,6 +33,9 @@ public class ReposViewHolder extends BaseViewHolder<RepoModel> {
@BindView(R.id.forks) FontTextView forks;
@Nullable @BindView(R.id.avatarLayout) AvatarLayout avatarLayout;
@BindString(R.string.forked) String forked;
@BindString(R.string.private_repo) String privateRepo;
@BindColor(R.color.material_indigo_700) int forkColor;
@BindColor(R.color.material_deep_purple_700) int privateColor;
private boolean isStarred;
private boolean withImage;
@ -50,8 +55,16 @@ public class ReposViewHolder extends BaseViewHolder<RepoModel> {
}
@Override public void bind(@NonNull RepoModel repo) {
if (repo.isFork()) {
title.setText(SpannableBuilder.builder().bold(forked).append(" ").append(repo.getName()));
if (repo.isFork() && !isStarred) {
title.setText(SpannableBuilder.builder()
.append(" " + forked + " ", new RoundBackgroundSpan(forkColor, 5))
.append(" ")
.append(repo.getName()));
} else if (repo.isPrivateX()) {
title.setText(SpannableBuilder.builder()
.append(" " + privateRepo + " ", new RoundBackgroundSpan(forkColor, 5))
.append(" ")
.append(repo.getName()));
} else {
title.setText(!isStarred ? repo.getName() : repo.getFullName());
}

View File

@ -1,7 +1,5 @@
package com.fastaccess.ui.modules.repos.code;
import android.support.annotation.NonNull;
import com.fastaccess.ui.base.mvp.BaseMvp;
/**
@ -14,8 +12,6 @@ public interface RepoCodePagerMvp {
boolean canPressBack();
void onBackPressed();
void onBranchChanged(@NonNull String branch);
}
interface Presenter extends BaseMvp.FAPresenter {}

View File

@ -14,7 +14,6 @@ import com.fastaccess.helper.Bundler;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.ui.adapter.FragmentsPagerAdapter;
import com.fastaccess.ui.base.BaseFragment;
import com.fastaccess.ui.modules.repos.code.commit.RepoCommitsView;
import com.fastaccess.ui.modules.repos.code.files.paths.RepoFilePathView;
import com.fastaccess.ui.widgets.ViewPagerView;
@ -78,13 +77,4 @@ public class RepoCodePagerView extends BaseFragment<RepoCodePagerMvp.View, RepoC
pathView.onBackPressed();
}
}
@Override public void onBranchChanged(@NonNull String branch) {
if (pager != null && pager.getAdapter() != null) {
RepoCommitsView commitsView = (RepoCommitsView) pager.getAdapter().instantiateItem(pager, 2);
if (commitsView != null) {
commitsView.changeBranch(branch);
}
}
}
}

View File

@ -4,12 +4,14 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import com.fastaccess.data.dao.BranchesModel;
import com.fastaccess.data.dao.CommitModel;
import com.fastaccess.provider.rest.loadmore.OnLoadMore;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Kosh on 03 Dec 2016, 3:45 PM
@ -22,7 +24,11 @@ interface RepoCommitsMvp {
@NonNull OnLoadMore getLoadMore();
void changeBranch(@NonNull String branch);
void setBranchesData(@NonNull List<BranchesModel> branches, boolean firstTime);
void showBranchesProgress();
void hideBranchesProgress();
}
interface Presenter extends BaseMvp.FAPresenter,
@ -32,8 +38,13 @@ interface RepoCommitsMvp {
@NonNull ArrayList<CommitModel> getCommits();
@NonNull ArrayList<BranchesModel> getBranches();
void onWorkOffline();
void onBranchChanged(@NonNull String branch);
String getDefaultBranch();
}
}

View File

@ -6,10 +6,10 @@ import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import com.fastaccess.data.dao.BranchesModel;
import com.fastaccess.data.dao.CommitModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.Logger;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.BaseMvp;
@ -25,6 +25,7 @@ import java.util.ArrayList;
class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements RepoCommitsMvp.Presenter {
private ArrayList<CommitModel> commits = new ArrayList<>();
private ArrayList<BranchesModel> branches = new ArrayList<>();
private String login;
private String repoId;
private String branch;
@ -80,7 +81,21 @@ class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements
repoId = bundle.getString(BundleConstant.ID);
login = bundle.getString(BundleConstant.EXTRA);
branch = bundle.getString(BundleConstant.EXTRA_TWO);
Logger.e(branch);
if (branches.isEmpty()) {
makeRestCall(RestProvider.getRepoService()
.getBranches(login, repoId)
.doOnSubscribe(() -> sendToView(RepoCommitsMvp.View::showBranchesProgress)),
response -> {
if (response != null && response.getItems() != null) {
branches.clear();
branches.addAll(response.getItems());
sendToView(view -> {
view.setBranchesData(branches, true);
view.hideBranchesProgress();
});
}
});
}
if (!InputHelper.isEmpty(login) && !InputHelper.isEmpty(repoId)) {
onCallApi(1, null);
}
@ -90,6 +105,10 @@ class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements
return commits;
}
@NonNull @Override public ArrayList<BranchesModel> getBranches() {
return branches;
}
@Override public void onWorkOffline() {
if (commits.isEmpty()) {
manageSubscription(RxHelper.getObserver(CommitModel.getCommits(repoId, login))
@ -109,6 +128,10 @@ class RepoCommitsPresenter extends BasePresenter<RepoCommitsMvp.View> implements
}
}
@Override public String getDefaultBranch() {
return branch;
}
@Override public void onItemClick(int position, View v, CommitModel item) {
CommitPagerView.createIntentForOffline(v.getContext(), item);
}

View File

@ -1,22 +1,32 @@
package com.fastaccess.ui.modules.repos.code.commit;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.AppCompatSpinner;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ProgressBar;
import com.fastaccess.R;
import com.fastaccess.data.dao.BranchesModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.Bundler;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.provider.rest.loadmore.OnLoadMore;
import com.fastaccess.ui.adapter.CommitsAdapter;
import com.fastaccess.ui.base.BaseFragment;
import com.fastaccess.ui.modules.repos.RepoPagerMvp;
import com.fastaccess.ui.widgets.StateLayout;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
import java.util.List;
import butterknife.BindView;
import butterknife.OnItemSelected;
/**
* Created by Kosh on 03 Dec 2016, 3:56 PM
@ -26,8 +36,11 @@ public class RepoCommitsView extends BaseFragment<RepoCommitsMvp.View, RepoCommi
@BindView(R.id.recycler) DynamicRecyclerView recycler;
@BindView(R.id.refresh) SwipeRefreshLayout refresh;
@BindView(R.id.stateLayout) StateLayout stateLayout;
@BindView(R.id.branches) AppCompatSpinner branches;
@BindView(R.id.branchesProgress) ProgressBar branchesProgress;
private OnLoadMore onLoadMore;
private CommitsAdapter adapter;
private RepoPagerMvp.View repoCallback;
public static RepoCommitsView newInstance(@NonNull String repoId, @NonNull String login, @NonNull String branch) {
RepoCommitsView view = new RepoCommitsView();
@ -39,6 +52,27 @@ public class RepoCommitsView extends BaseFragment<RepoCommitsMvp.View, RepoCommi
return view;
}
@OnItemSelected(R.id.branches) void onBranchSelected(int position) {
if (repoCallback.hasUserInteractedWithView()) {
String ref = ((BranchesModel) branches.getItemAtPosition(position)).getName();
getPresenter().onBranchChanged(ref);
}
}
@Override public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof RepoPagerMvp.View) {
repoCallback = (RepoPagerMvp.View) context;
} else if (getParentFragment() instanceof RepoPagerMvp.View) {
repoCallback = (RepoPagerMvp.View) getParentFragment();
}
}
@Override public void onDetach() {
repoCallback = null;
super.onDetach();
}
@Override public void onNotifyAdapter() {
hideProgress();
@ -46,7 +80,7 @@ public class RepoCommitsView extends BaseFragment<RepoCommitsMvp.View, RepoCommi
}
@Override protected int fragmentLayout() {
return R.layout.small_grid_refresh_list;
return R.layout.commit_with_branch_layout;
}
@Override protected void onFragmentCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
@ -66,6 +100,7 @@ public class RepoCommitsView extends BaseFragment<RepoCommitsMvp.View, RepoCommi
} else if (getPresenter().getCommits().isEmpty() && !getPresenter().isApiCalled()) {
onRefresh();
}
setBranchesData(getPresenter().getBranches(), false);
}
@NonNull @Override public RepoCommitsPresenter providePresenter() {
@ -84,6 +119,7 @@ public class RepoCommitsView extends BaseFragment<RepoCommitsMvp.View, RepoCommi
@Override public void showErrorMessage(@NonNull String msgRes) {
hideProgress();
hideBranchesProgress();
stateLayout.showReload(adapter.getItemCount());
super.showErrorMessage(msgRes);
}
@ -95,8 +131,33 @@ public class RepoCommitsView extends BaseFragment<RepoCommitsMvp.View, RepoCommi
return onLoadMore;
}
@Override public void changeBranch(@NonNull String branch) {
getPresenter().onBranchChanged(branch);
@Override public void setBranchesData(@NonNull List<BranchesModel> branchesData, boolean firstTime) {
branchesProgress.setVisibility(View.GONE);
ArrayAdapter<BranchesModel> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, branchesData);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
branches.setAdapter(adapter);
if (firstTime) {
if (!InputHelper.isEmpty(getPresenter().getDefaultBranch())) {
int index = -1;
for (int i = 0; i < branchesData.size(); i++) {
if (branchesData.get(i).getName().equals(getPresenter().getDefaultBranch())) {
index = i;
break;
}
}
if (index != -1) {
branches.setSelection(index, true);
}
}
}
}
@Override public void showBranchesProgress() {
branchesProgress.setVisibility(View.VISIBLE);
}
@Override public void hideBranchesProgress() {
branchesProgress.setVisibility(View.GONE);
}
@Override public void onRefresh() {

View File

@ -22,7 +22,6 @@ import com.fastaccess.helper.Logger;
import com.fastaccess.ui.adapter.RepoFilePathsAdapter;
import com.fastaccess.ui.base.BaseFragment;
import com.fastaccess.ui.modules.repos.RepoPagerMvp;
import com.fastaccess.ui.modules.repos.code.RepoCodePagerMvp;
import com.fastaccess.ui.modules.repos.code.files.RepoFilesView;
import java.util.List;
@ -48,7 +47,6 @@ public class RepoFilePathView extends BaseFragment<RepoFilePathMvp.View, RepoFil
private RepoFilePathsAdapter adapter;
private RepoFilesView repoFilesView;
private RepoPagerMvp.View repoCallback;
private RepoCodePagerMvp.View codePagerCallback;
public static RepoFilePathView newInstance(@NonNull String login, @NonNull String repoId, @Nullable String path, @NonNull String defaultBranch) {
RepoFilePathView view = new RepoFilePathView();
@ -74,9 +72,6 @@ public class RepoFilePathView extends BaseFragment<RepoFilePathMvp.View, RepoFil
ref = ((BranchesModel) branches.getItemAtPosition(position)).getName();
getRepoFilesView().onSetData(getPresenter().getLogin(), getPresenter().getRepoId(), "", ref, true);
onBackClicked();
if (codePagerCallback != null) {
codePagerCallback.onBranchChanged(ref);
}
}
}
@ -87,11 +82,6 @@ public class RepoFilePathView extends BaseFragment<RepoFilePathMvp.View, RepoFil
} else if (getParentFragment() instanceof RepoPagerMvp.View) {
repoCallback = (RepoPagerMvp.View) getParentFragment();
}
if (context instanceof RepoCodePagerMvp.View) {
codePagerCallback = (RepoCodePagerMvp.View) context;
} else if (getParentFragment() instanceof RepoCodePagerMvp.View) {
codePagerCallback = (RepoCodePagerMvp.View) getParentFragment();
}
}
@Override public void onDetach() {

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/grid_spacing"
android:background="@color/universal_primary_dark_color"
android:clickable="true"
android:orientation="horizontal"
android:paddingBottom="@dimen/spacing_micro"
android:paddingEnd="@dimen/spacing_xs_large"
android:paddingStart="@dimen/spacing_xs_large"
android:paddingTop="@dimen/spacing_micro">
<com.fastaccess.ui.widgets.ForegroundImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/switch_branch"
android:padding="@dimen/spacing_normal"
android:src="@drawable/ic_branch"/>
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/branches"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/spacing_xs_large"
android:layout_marginStart="@dimen/spacing_xs_large"
android:layout_weight="1"
android:spinnerMode="dialog"
app:backgroundTint="?colorAccent"
tools:entries="@array/notification_types"/>
<ProgressBar
android:id="@+id/branchesProgress"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:visibility="gone"/>
</LinearLayout>
<include layout="@layout/small_grid_refresh_list"/>
</LinearLayout>

View File

@ -239,4 +239,5 @@
<string name="back_button_summary">Disable pressing the back button twice to exit FastHub.</string>
<string name="back_button_title">Back Button Behavior</string>
<string name="unsaved_data_warning">Any unsaved data will be discarded.</string>
<string name="private_repo">Private</string>
</resources>