this commit fixes #702 , fixes small PR changes files count and kick start enterprise impl

This commit is contained in:
Kosh 2017-06-26 11:31:09 +08:00
parent e354939dad
commit b4232dec66
18 changed files with 162 additions and 70 deletions

View File

@ -9,4 +9,5 @@
<string name="amlod_theme_purchase" translatable="false">android.test.purchased</string>
<string name="midnight_blue_theme_purchase" translatable="false">android.test.purchased</string>
<string name="theme_bluish_purchase" translatable="false">android.test.purchased</string>
<string name="fasthub_pro_purchase" translatable="false">fasthub_pro</string>
</resources>

View File

@ -10,6 +10,7 @@ import com.annimon.stream.Stream;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Observable;
import lombok.Getter;
import lombok.Setter;
@ -24,23 +25,30 @@ import lombok.Setter;
public CommitFileChanges() {}
public static Observable<CommitFileChanges> constructToObservable(@Nullable List<CommitFileModel> files) {
if (files == null || files.isEmpty()) return Observable.empty();
return Observable.fromIterable(files).map(CommitFileChanges::getCommitFileChanges);
}
@NonNull public static List<CommitFileChanges> construct(@Nullable List<CommitFileModel> files) {
if (files == null || files.isEmpty()) {
return new ArrayList<>();
}
return Stream.of(files)
.map(m -> {
CommitFileChanges model = new CommitFileChanges();
model.setLinesModel(CommitLinesModel.getLines(m.getPatch()));
if (m.getPatch() != null) {
m.setPatch("fake");
}
model.setCommitFileModel(m);
return model;
})
.map(CommitFileChanges::getCommitFileChanges)
.toList();
}
@NonNull private static CommitFileChanges getCommitFileChanges(CommitFileModel m) {
CommitFileChanges model = new CommitFileChanges();
model.setLinesModel(CommitLinesModel.getLines(m.getPatch()));
if (m.getPatch() != null) {
m.setPatch("fake");
}
model.setCommitFileModel(m);
return model;
}
@Override public int describeContents() { return 0; }
@Override public void writeToParcel(Parcel dest, int flags) {

View File

@ -2,8 +2,6 @@ package com.fastaccess.ui.adapter.viewholder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.transition.ChangeBounds;
import android.support.transition.TransitionManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
@ -119,9 +117,6 @@ public class GroupedReviewsViewHolder extends BaseViewHolder<TimelineModel> impl
}
private void onToggle(boolean expanded, boolean animate) {
if (animate) {
TransitionManager.beginDelayedTransition(viewGroup, new ChangeBounds());
}
if (!expanded) {
minimized.setVisibility(View.GONE);
patch.setText("");

View File

@ -2,15 +2,13 @@ package com.fastaccess.ui.adapter.viewholder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.transition.ChangeBounds;
import android.support.transition.TransitionManager;
import android.view.View;
import android.view.ViewGroup;
import com.fastaccess.R;
import com.fastaccess.data.dao.CommitFileChanges;
import com.fastaccess.data.dao.CommitFileModel;
import com.fastaccess.data.dao.CommitLinesModel;
import com.fastaccess.data.dao.CommitFileChanges;
import com.fastaccess.helper.Logger;
import com.fastaccess.ui.adapter.CommitLinesAdapter;
import com.fastaccess.ui.adapter.callback.OnToggleView;
@ -98,9 +96,6 @@ public class PullRequestFilesViewHolder extends BaseViewHolder<CommitFileChanges
}
private void onToggle(boolean expanded, boolean animate, int position) {
if (animate) {
TransitionManager.beginDelayedTransition(viewGroup, new ChangeBounds());
}
if (!expanded) {
patch.swapAdapter(null, true);
patch.setVisibility(View.GONE);
@ -112,6 +107,9 @@ public class PullRequestFilesViewHolder extends BaseViewHolder<CommitFileChanges
if (model.getLinesModel() != null && !model.getLinesModel().isEmpty()) {
patch.setAdapter(new CommitLinesAdapter(model.getLinesModel(), this));
patch.setVisibility(View.VISIBLE);
} else {
patch.swapAdapter(null, true);
patch.setVisibility(View.GONE);
}
}
name.setMaxLines(5);

View File

@ -189,7 +189,7 @@ public abstract class BaseActivity<V extends BaseMvp.FAView, P extends BasePrese
ProgressDialogFragment.TAG);
if (fragment == null) {
isProgressShowing = true;
fragment = ProgressDialogFragment.newInstance(msg, false);
fragment = ProgressDialogFragment.newInstance(msg, true);
fragment.show(getSupportFragmentManager(), ProgressDialogFragment.TAG);
}
}

View File

@ -69,12 +69,10 @@ public class CommitFilesFragment extends BaseFragment<CommitFilesMvp.View, Commi
}
@Override public void onNotifyAdapter(@Nullable List<CommitFileChanges> items) {
stateLayout.hideReload();
if (items == null || items.isEmpty()) {
adapter.clear();
return;
hideProgress();
if (items != null) {
adapter.insertItems(items);
}
adapter.insertItems(items);
}
@Override public void onCommentAdded(@NonNull Comment newComment) {
@ -84,6 +82,15 @@ public class CommitFilesFragment extends BaseFragment<CommitFilesMvp.View, Commi
}
}
@Override public void clearAdapter() {
refresh.setRefreshing(true);
adapter.clear();
}
@Override public void hideProgress() {
refresh.setRefreshing(false);
}
@Override protected int fragmentLayout() {
return R.layout.micro_grid_refresh_list;
}
@ -95,7 +102,7 @@ public class CommitFilesFragment extends BaseFragment<CommitFilesMvp.View, Commi
adapter = new CommitFilesAdapter(getPresenter().getFiles(), this, this);
adapter.setListener(getPresenter());
recycler.setAdapter(adapter);
if (savedInstanceState == null) {
if (savedInstanceState == null || adapter.isEmpty()) {
getPresenter().onFragmentCreated(getArguments());
}
}
@ -122,6 +129,7 @@ public class CommitFilesFragment extends BaseFragment<CommitFilesMvp.View, Commi
}
@Override public void onPatchClicked(int groupPosition, int childPosition, View v, CommitFileModel commit, CommitLinesModel item) {
if (item.getText().startsWith("@@")) return;
AddReviewDialogFragment.Companion.newInstance(item, Bundler.start().put(BundleConstant.ITEM, commit.getBlobUrl())
.put(BundleConstant.EXTRA, commit.getFilename())
.end())

View File

@ -27,6 +27,8 @@ interface CommitFilesMvp {
void onNotifyAdapter(@Nullable List<CommitFileChanges> items);
void onCommentAdded(@NonNull Comment newComment);
void clearAdapter();
}
interface Presenter extends BaseMvp.FAPresenter, BaseViewHolder.OnItemClickListener<CommitFileChanges> {

View File

@ -20,6 +20,7 @@ import com.fastaccess.helper.AppHelper;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.modules.code.CodeViewerActivity;
@ -76,7 +77,8 @@ class CommitFilesPresenter extends BasePresenter<CommitFilesMvp.View> implements
if (commitFiles != null) {
manageObservable(Observable.just(commitFiles)
.map(CommitFileChanges::construct)
.doFinally(() -> CommitFilesSingleton.getInstance().clear())
.doOnSubscribe(disposable -> sendToView(CommitFilesMvp.View::clearAdapter))
.doFinally(() -> sendToView(BaseMvp.FAView::hideProgress))
.doOnNext(commitFileChanges -> sendToView(view -> view.onNotifyAdapter(commitFileChanges))));
}
@ -104,4 +106,9 @@ class CommitFilesPresenter extends BasePresenter<CommitFilesMvp.View> implements
nameParser.getName(), sha, commentRequestModel), newComment -> sendToView(view -> view.onCommentAdded(newComment)));
}
}
@Override protected void onDestroy() {
CommitFilesSingleton.getInstance().clear();
super.onDestroy();
}
}

View File

@ -21,6 +21,7 @@ import com.fastaccess.data.dao.FragmentPagerAdapterModel;
import com.fastaccess.data.dao.LabelModel;
import com.fastaccess.data.dao.MilestoneModel;
import com.fastaccess.data.dao.ReviewRequestModel;
import com.fastaccess.data.dao.model.Login;
import com.fastaccess.data.dao.model.PullRequest;
import com.fastaccess.data.dao.model.User;
import com.fastaccess.data.dao.types.IssueState;
@ -160,6 +161,8 @@ public class PullRequestPagerActivity extends BaseActivity<PullRequestPagerMvp.V
}
} else if (requestCode == BundleConstant.REVIEW_REQUEST_CODE) {
onUpdateTimeline();
getPresenter().getCommitComment().clear();
AnimHelper.mimicFabVisibility(false, prReviewHolder, null);
}
}
}
@ -407,11 +410,14 @@ public class PullRequestPagerActivity extends BaseActivity<PullRequestPagerMvp.V
private void addPrReview(@NonNull View view) {
PullRequest pullRequest = getPresenter().getPullRequest();
if (pullRequest == null) return;
User author = pullRequest.getHead().getAuthor() != null ? pullRequest.getHead().getAuthor() :
pullRequest.getHead().getUser() != null ? pullRequest.getHead().getUser() : pullRequest.getUser(); // fallback to user object
ReviewRequestModel requestModel = new ReviewRequestModel();
requestModel.setComments(getPresenter().getCommitComment().isEmpty() ? null : getPresenter().getCommitComment());
requestModel.setCommitId(pullRequest.getHead().getSha());
boolean isAuthor = author != null && Login.getUser().getLogin().equalsIgnoreCase(author.getLogin());
ReviewChangesActivity.Companion.startForResult(this, view, requestModel, getPresenter().getRepoId(),
getPresenter().getLogin(), pullRequest.getNumber());
getPresenter().getLogin(), pullRequest.getNumber(), isAuthor);
}
private void initTabs(@NonNull PullRequest pullRequest) {

View File

@ -164,6 +164,7 @@ public class PullRequestFilesFragment extends BaseFragment<PullRequestFilesMvp.V
}
@Override public void onPatchClicked(int groupPosition, int childPosition, View v, CommitFileModel commit, CommitLinesModel item) {
if (item.getText().startsWith("@@")) return;
AddReviewDialogFragment.Companion.newInstance(item, Bundler.start().put(BundleConstant.ITEM, commit.getFilename()).end())
.show(getChildFragmentManager(), "AddReviewDialogFragment");
}

View File

@ -10,8 +10,8 @@ import android.view.View;
import android.widget.PopupMenu;
import com.fastaccess.R;
import com.fastaccess.data.dao.CommitFileModel;
import com.fastaccess.data.dao.CommitFileChanges;
import com.fastaccess.data.dao.CommitFileModel;
import com.fastaccess.helper.ActivityHelper;
import com.fastaccess.helper.AppHelper;
import com.fastaccess.helper.BundleConstant;
@ -74,9 +74,11 @@ class PullRequestFilesPresenter extends BasePresenter<PullRequestFilesMvp.View>
if (repoId == null || login == null) return;
makeRestCall(RestProvider.getPullRequestService().getPullRequestFiles(login, repoId, number, page)
.flatMap(commitFileModelPageable -> {
if (commitFileModelPageable != null && commitFileModelPageable.getItems() != null) {
if (commitFileModelPageable != null) {
lastPage = commitFileModelPageable.getLast();
return Observable.just(CommitFileChanges.construct(commitFileModelPageable.getItems()));
if (commitFileModelPageable.getItems() != null) {
return Observable.just(CommitFileChanges.construct(commitFileModelPageable.getItems()));
}
}
return Observable.empty();
}),

View File

@ -3,6 +3,7 @@ package com.fastaccess.ui.modules.reviews.changes
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.annotation.StringRes
import android.support.design.widget.TextInputLayout
import android.support.v7.widget.Toolbar
import android.view.Menu
@ -12,18 +13,17 @@ import android.widget.Spinner
import com.evernote.android.state.State
import com.fastaccess.R
import com.fastaccess.data.dao.ReviewRequestModel
import com.fastaccess.helper.ActivityHelper
import com.fastaccess.helper.BundleConstant
import com.fastaccess.helper.Bundler
import com.fastaccess.helper.InputHelper
import com.fastaccess.helper.*
import com.fastaccess.provider.theme.ThemeEngine
import com.fastaccess.ui.base.BaseActivity
import com.fastaccess.ui.widgets.dialog.ProgressDialogFragment
/**
* Created by Kosh on 25 Jun 2017, 1:25 AM
*/
class ReviewChangesActivity : BaseActivity<ReviewChangesMvp.View, ReviewChangesPresenter>(), ReviewChangesMvp.View {
val toolbar: Toolbar by lazy { findViewById(R.id.toolbar) as Toolbar }
val spinner: Spinner by lazy { findViewById(R.id.reviewMethod) as Spinner }
val editText: TextInputLayout by lazy { findViewById(R.id.editText) as TextInputLayout }
@ -32,6 +32,7 @@ class ReviewChangesActivity : BaseActivity<ReviewChangesMvp.View, ReviewChangesP
@State var repoId: String? = null
@State var owner: String? = null
@State var number: Long? = null
@State var isProgressShowing: Boolean = false
override fun layout(): Int = R.layout.add_review_dialog_layout
@ -46,11 +47,17 @@ class ReviewChangesActivity : BaseActivity<ReviewChangesMvp.View, ReviewChangesP
override fun onCreate(savedInstanceState: Bundle?) {
ThemeEngine.applyDialogTheme(this)
super.onCreate(savedInstanceState)
setToolbarIcon(R.drawable.ic_clear)
val bundle = intent.extras!!
reviewRequest = bundle.getParcelable(BundleConstant.EXTRA)
repoId = bundle.getString(BundleConstant.EXTRA_TWO)
owner = bundle.getString(BundleConstant.EXTRA_THREE)
number = bundle.getLong(BundleConstant.ID)
val isAuthor = bundle.getBoolean(BundleConstant.EXTRA_FOUR)
if (isAuthor) {
spinner.setSelection(2, true)
spinner.isEnabled = false
}
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
@ -83,17 +90,58 @@ class ReviewChangesActivity : BaseActivity<ReviewChangesMvp.View, ReviewChangesP
showErrorMessage(getString(R.string.network_error))
}
override fun showProgress(@StringRes resId: Int) {
var msg = getString(R.string.in_progress)
if (resId != 0) {
msg = getString(resId)
}
if (!isProgressShowing && !isFinishing) {
var fragment = AppHelper.getFragmentByTag(supportFragmentManager,
ProgressDialogFragment.TAG) as ProgressDialogFragment?
if (fragment == null) {
isProgressShowing = true
fragment = ProgressDialogFragment.newInstance(msg, false)
fragment.show(supportFragmentManager, ProgressDialogFragment.TAG)
}
}
}
override fun hideProgress() {
val fragment = AppHelper.getFragmentByTag(supportFragmentManager, ProgressDialogFragment.TAG) as ProgressDialogFragment?
if (fragment != null) {
isProgressShowing = false
fragment.dismiss()
}
}
override fun showMessage(titleRes: Int, msgRes: Int) {
hideProgress()
super.showMessage(titleRes, msgRes)
}
override fun showMessage(titleRes: String, msgRes: String) {
hideProgress()
super.showMessage(titleRes, msgRes)
}
override fun showErrorMessage(msgRes: String) {
hideProgress()
super.showErrorMessage(msgRes)
}
companion object {
/**
* val repoId = bundle.getString(BundleConstant.EXTRA_TWO)
* val owner = bundle.getString(BundleConstant.EXTRA_THREE)
* val number = bundle.getLong(BundleConstant.ID)
*/
fun startForResult(activity: Activity, view: View, reviewChanges: ReviewRequestModel, repoId: String, owner: String, number: Long) {
fun startForResult(activity: Activity, view: View, reviewChanges: ReviewRequestModel, repoId: String, owner: String, number: Long,
isAuthor: Boolean) {
val bundle = Bundler.start()
.put(BundleConstant.EXTRA, reviewChanges)
.put(BundleConstant.EXTRA_TWO, repoId)
.put(BundleConstant.EXTRA_THREE, owner)
.put(BundleConstant.EXTRA_FOUR, isAuthor)
.put(BundleConstant.ID, number)
.end()
val intent = Intent(activity, ReviewChangesActivity::class.java)

View File

@ -11,12 +11,12 @@ class ReviewChangesPresenter : BasePresenter<ReviewChangesMvp.View>(), ReviewCha
override fun onSubmit(reviewRequest: ReviewRequestModel, repoId: String, owner: String, number: Long, comment: String, method: String) {
reviewRequest.body = comment
reviewRequest.event = method
reviewRequest.event = method.replace(" ", "_").toUpperCase()
makeRestCall(RestProvider.getReviewService().submitPrReview(owner, repoId, number, reviewRequest), {
if (it.isSuccessful && it.code() == 200) {
sendToView { it.onSuccessfullySubmitted() }
} else {
sendToView { it.onErrorSubmitting()}
sendToView { it.onErrorSubmitting() }
}
})
}

View File

@ -20,15 +20,13 @@ import android.text.style.TypefaceSpan;
import com.fastaccess.App;
import com.fastaccess.R;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DiffLineSpan extends MetricAffectingSpan implements LineBackgroundSpan {
private Rect rect = new Rect();
private final int color;
public static Pattern HUNK_TITLE = Pattern.compile("@@ -(\\d+),(\\d)+ \\+(\\d+),(\\d)+.*");
public static Pattern HUNK_TITLE = Pattern.compile("^.*-([0-9]+)(?:,([0-9]+))? \\+([0-9]+)(?:,([0-9]+))?.*$");
private DiffLineSpan(int color) {
this.color = color;
@ -72,7 +70,6 @@ public class DiffLineSpan extends MetricAffectingSpan implements LineBackgroundS
if (split.length > 0) {
int lines = split.length;
int index = -1;
int lineNo = -1;
for (int i = 0; i < lines; i++) {
if (truncate && (lines - i) > 3) continue;
String token = split[i];
@ -83,28 +80,15 @@ public class DiffLineSpan extends MetricAffectingSpan implements LineBackgroundS
int color = Color.TRANSPARENT;
if (token.startsWith("@@")) {
color = patchRefColor;
Matcher matcher = HUNK_TITLE.matcher(token.trim());
if (matcher.matches()) {
try {
int leftLineNo = Math.abs(Integer.parseInt(matcher.group(1))) - 1;
int rightLineNo = Integer.parseInt(matcher.group(1)) - 1;
lineNo = leftLineNo <= 0 ? rightLineNo : leftLineNo;
} catch (NumberFormatException e) {e.printStackTrace();}
}
} else if (firstChar == '+') {
++lineNo;
color = patchAdditionColor;
} else if (firstChar == '-') {
++lineNo;
color = patchDeletionColor;
} else {
++lineNo;
}
index = token.indexOf("\\ No newline at end of file");
if (index != -1) {
token = token.replace("\\ No newline at end of file", "");
}
Logger.e(lineNo);
SpannableString spannableDiff = new SpannableString(token);
if (color != Color.TRANSPARENT) {
DiffLineSpan span = new DiffLineSpan(color);

View File

@ -35,8 +35,9 @@ public class ProgressDialogFragment extends DialogFragment {
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage(getArguments().getString("msg"));
// progressDialog.setCancelable(getArguments().getBoolean("isCancelable"));
// setCancelable(getArguments().getBoolean("isCancelable"));
boolean isCancelable = getArguments().getBoolean("isCancelable");
progressDialog.setCancelable(isCancelable);
setCancelable(isCancelable);
if (getActivity() != null && !getActivity().isFinishing()) {
progressDialog.setOnShowListener(dialogInterface -> AnimHelper.revealDialog(progressDialog, 200));
}

View File

@ -95,16 +95,45 @@
android:paddingStart="@dimen/spacing_large"
android:text="@string/or_character"/>
<com.fastaccess.ui.widgets.FontTextView
android:id="@+id/accessToken"
style="@style/TextAppearance.AppCompat.Title"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:layout_marginBottom="@dimen/spacing_normal"
android:layout_marginTop="@dimen/spacing_normal"
android:gravity="center"
android:padding="@dimen/spacing_xs_large"
android:text="@string/access_token"
android:textColor="@color/material_pink_700"/>
android:orientation="horizontal">
<com.fastaccess.ui.widgets.FontTextView
android:id="@+id/accessToken"
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackground"
android:gravity="center"
android:paddingStart="@dimen/spacing_xs_large"
android:text="@string/access_token"
android:textColor="@color/material_pink_700"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/left_border">
<com.fastaccess.ui.widgets.FontTextView
android:id="@+id/enterprise"
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:gravity="center"
android:padding="@dimen/spacing_xs_large"
android:text="@string/enterprise"
android:textColor="@color/material_purple_700"/>
</LinearLayout>
</LinearLayout>
<com.fastaccess.ui.widgets.FontTextView
style="@style/TextAppearance.AppCompat.Small"
@ -146,14 +175,15 @@
android:id="@+id/language_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_grey_200"
android:layout_gravity="bottom">
android:layout_gravity="bottom"
android:background="@color/material_grey_200">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.5"
android:background="@color/material_light_white"/>
<com.fastaccess.ui.widgets.FontTextView
android:id="@+id/language_selector_clicker"
style="@style/TextAppearance.AppCompat.Medium"

View File

@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="@dimen/grid_spacing"
android:background="?card_background"
android:paddingTop="@dimen/spacing_normal"
@ -17,9 +16,9 @@
<LinearLayout
android:id="@+id/toggleHolder"
android:layout_marginEnd="@dimen/spacing_micro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing_micro"
android:orientation="horizontal">
<com.fastaccess.ui.widgets.AvatarLayout

View File

@ -84,6 +84,8 @@
<string name="rebase" translatable="false">Rebase</string>
<string name="pull_request_reviews" translatable="false">Pull Request Reviews</string>
<string name="review_changes" translatable="false">Review Changes</string>
<string name="enterprise" translatable="false">Enterprise</string>
<!-- END OF DO NOT COPY -->
<string name="in_progress">Loading, please wait…</string>
<string name="action">Action</string>
@ -421,7 +423,7 @@
<string name="basic_login">Login via basic auth</string>
<string name="no_orgs_description">If you are actually tied to an organizations and you can\'t see them here please follow link
below.\nhttps://help.github.com/articles/about-third-party-application-restrictions\nPS: You could use Access token to login which will
grant FastHub access to see list your organizations.\nYou could also open up https://github.com/settings/applications and look for
grant FastHub access to list your organizations.\nYou could also open up https://github.com/settings/applications and look for
FastHub, open it then scroll to Organization access and click on Grant Button.</string>
<string name="insert">Insert</string>
<string name="select">Select</string>