removing gist from profile gist list when its deleted as mentioned in #19, removed handling view stuff from presenters in comments presenter.

This commit is contained in:
Kosh 2017-02-27 12:00:59 +08:00
parent badae3d8b1
commit 75889f530f
20 changed files with 132 additions and 116 deletions

View File

@ -14,6 +14,7 @@ public class PrefGetter {
private static final String FILE_OPTION_GUIDE = "file_option_guide";
private static final String COMMENTS_GUIDE = "comments_guide";
private static final String REPO_GUIDE = "repo_guide";
private static final String MARKDOWNDOWN_GUIDE = "markdowndown_guide";
public static void setToken(@NonNull String token) {
PrefHelper.set(TOKEN, token);
@ -64,4 +65,10 @@ public class PrefGetter {
PrefHelper.set(REPO_GUIDE, true);
return isShowed;
}
public static boolean isEditorHintShowed() {
boolean isShowed = PrefHelper.getBoolean(MARKDOWNDOWN_GUIDE);
PrefHelper.set(MARKDOWNDOWN_GUIDE, true);
return isShowed;
}
}

View File

@ -12,6 +12,7 @@ import com.fastaccess.data.dao.CommentsModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.Bundler;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.PrefGetter;
import com.fastaccess.helper.ViewHelper;
import com.fastaccess.provider.markdown.MarkDownProvider;
import com.fastaccess.ui.base.BaseActivity;
@ -23,6 +24,7 @@ import butterknife.BindView;
import butterknife.OnClick;
import butterknife.OnTextChanged;
import icepick.State;
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
/**
* Created by Kosh on 27 Nov 2016, 1:32 AM
@ -83,7 +85,6 @@ public class EditorView extends BaseActivity<EditorMvp.View, EditorPresenter> im
}
}
@OnClick({R.id.headerOne, R.id.headerTwo, R.id.headerThree, R.id.bold, R.id.italic,
R.id.strikethrough, R.id.bullet, R.id.header, R.id.code, R.id.numbered,
R.id.quote, R.id.link, R.id.image}) void onActions(View v) {
@ -123,10 +124,21 @@ public class EditorView extends BaseActivity<EditorMvp.View, EditorPresenter> im
issueNumber = bundle.getInt(BundleConstant.EXTRA_THREE);
}
commentId = bundle.getLong(BundleConstant.EXTRA_FOUR);
editText.setText(bundle.getString(BundleConstant.EXTRA));
String textToUpdate = bundle.getString(BundleConstant.EXTRA);
editText.setText(textToUpdate);
if (!InputHelper.isEmpty(textToUpdate)) {
editText.setSelection(InputHelper.toString(editText).length());
}
}
}
if (!PrefGetter.isEditorHintShowed()) {
new MaterialTapTargetPrompt.Builder(this)
.setTarget(viewCode)
.setPrimaryText(R.string.view_code)
.setSecondaryText(R.string.click_to_toggle_highlighting)
.setCaptureTouchEventOutsidePrompt(true)
.show();
}
}
@Override public void onSendResultAndFinish(@NonNull CommentsModel commentModel, boolean isNew) {

View File

@ -29,6 +29,8 @@ interface GistMvp {
@Nullable GistsModel getGist();
@NonNull String gistId();
void onActivityCreated(@Nullable Intent intent);
void onDeleteGist();

View File

@ -28,6 +28,10 @@ class GistPresenter extends BasePresenter<GistMvp.View> implements GistMvp.Prese
return gist;
}
@NonNull @Override public String gistId() {
return gistId;
}
@SuppressWarnings("unchecked") @Override public void onActivityCreated(@Nullable Intent intent) {
if (intent == null || intent.getExtras() == null) {
return;

View File

@ -144,6 +144,13 @@ public class GistView extends BaseActivity<GistMvp.View, GistPresenter>
@Override public void onSuccessDeleted() {
hideProgress();
if (getPresenter().getGist() != null) {
Intent intent = new Intent();
GistsModel gistsModel = new GistsModel();
gistsModel.setUrl(getPresenter().getGist().getUrl());
intent.putExtras(Bundler.start().put(BundleConstant.ITEM, gistsModel).end());
setResult(RESULT_OK, intent);
}
finish();
}

View File

@ -1,6 +1,5 @@
package com.fastaccess.ui.modules.gists.gist.comments;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -9,10 +8,8 @@ import android.support.v4.widget.SwipeRefreshLayout;
import com.fastaccess.data.dao.CommentsModel;
import com.fastaccess.data.dao.UserModel;
import com.fastaccess.provider.rest.loadmore.OnLoadMore;
import com.fastaccess.ui.adapter.CommentsAdapter;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
import java.util.ArrayList;
@ -49,8 +46,6 @@ interface GistCommentsMvp {
@NonNull ArrayList<CommentsModel> getComments();
void onActivityResult(int requestCode, int resultCode, @Nullable Intent data,
@NonNull DynamicRecyclerView recycler, @NonNull CommentsAdapter adapter);
void onHandleDeletion(@Nullable Bundle bundle);

View File

@ -80,31 +80,6 @@ class GistCommentsPresenter extends BasePresenter<GistCommentsMvp.View> implemen
return comments;
}
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data,
@NonNull DynamicRecyclerView recycler, @NonNull CommentsAdapter adapter) {
if (resultCode == Activity.RESULT_OK && data != null) {
if (requestCode == BundleConstant.REQUEST_CODE) {
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
CommentsModel commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (isNew) {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(commentsModel);
if (position != -1) {
adapter.swapItem(commentsModel, position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
}
}
}
}
@Override public void onHandleDeletion(@Nullable Bundle bundle) {
if (bundle != null) {

View File

@ -1,5 +1,6 @@
package com.fastaccess.ui.modules.gists.gist.comments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -172,7 +173,28 @@ public class GistCommentsView extends BaseFragment<GistCommentsMvp.View, GistCom
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
getPresenter().onActivityResult(requestCode, resultCode, data, recycler, adapter);
if (resultCode == Activity.RESULT_OK && data != null) {
if (requestCode == BundleConstant.REQUEST_CODE) {
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
CommentsModel commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (isNew) {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(commentsModel);
if (position != -1) {
adapter.swapItem(commentsModel, position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
}
}
}
}
@Override public void onMessageDialogActionClicked(boolean isOk, @Nullable Bundle bundle) {

View File

@ -20,6 +20,8 @@ interface ProfileGistsMvp {
void onNotifyAdapter();
@NonNull OnLoadMore<String> getLoadMore();
void onStartGistView(@NonNull String gistId);
}
interface Presenter extends BaseMvp.FAPresenter,

View File

@ -7,7 +7,6 @@ import android.view.View;
import com.fastaccess.data.dao.GistsModel;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.modules.gists.gist.GistView;
import java.util.ArrayList;
@ -89,7 +88,7 @@ class ProfileGistsPresenter extends BasePresenter<ProfileGistsMvp.View> implemen
}
@Override public void onItemClick(int position, View v, GistsModel item) {
v.getContext().startActivity(GistView.createIntent(v.getContext(), item.getGistId()));
if (getView() != null) getView().onStartGistView(item.getGistId());
}
@Override public void onItemLongClick(int position, View v, GistsModel item) {

View File

@ -1,5 +1,7 @@
package com.fastaccess.ui.modules.profile.gists;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -8,12 +10,13 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import com.fastaccess.R;
import com.fastaccess.data.dao.GistsModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.Bundler;
import com.fastaccess.helper.Logger;
import com.fastaccess.provider.rest.loadmore.OnLoadMore;
import com.fastaccess.ui.adapter.GistsAdapter;
import com.fastaccess.ui.base.BaseFragment;
import com.fastaccess.ui.modules.gists.gist.GistView;
import com.fastaccess.ui.widgets.StateLayout;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
@ -96,9 +99,20 @@ public class ProfileGistsView extends BaseFragment<ProfileGistsMvp.View, Profile
return onLoadMore;
}
@Override public void onDestroyView() {
recycler.removeOnScrollListener(getLoadMore());
super.onDestroyView();
@Override public void onStartGistView(@NonNull String gistId) {
startActivityForResult(GistView.createIntent(getContext(), gistId), BundleConstant.REQUEST_CODE);
}
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == BundleConstant.REQUEST_CODE) {
if (data != null && data.getExtras() != null) {
GistsModel gistsModel = data.getExtras().getParcelable(BundleConstant.ITEM);
if (gistsModel != null && adapter != null) {
adapter.removeItem(gistsModel);
}
}
}
}
@Override public void onClick(View view) {

View File

@ -1,6 +1,5 @@
package com.fastaccess.ui.modules.repos.code.commit.details.comments;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -9,10 +8,8 @@ import android.support.v4.widget.SwipeRefreshLayout;
import com.fastaccess.data.dao.CommentsModel;
import com.fastaccess.data.dao.UserModel;
import com.fastaccess.provider.rest.loadmore.OnLoadMore;
import com.fastaccess.ui.adapter.CommentsAdapter;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
import java.util.ArrayList;
@ -52,9 +49,6 @@ interface CommitCommentsMvp {
@NonNull ArrayList<CommentsModel> getComments();
void onActivityResult(int requestCode, int resultCode, @Nullable Intent data,
@NonNull DynamicRecyclerView recycler, @NonNull CommentsAdapter adapter);
void onHandleDeletion(@Nullable Bundle bundle);
void onWorkOffline();

View File

@ -1,7 +1,5 @@
package com.fastaccess.ui.modules.repos.code.commit.details.comments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -12,9 +10,7 @@ import com.fastaccess.data.dao.CommentsModel;
import com.fastaccess.data.dao.LoginModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.adapter.CommentsAdapter;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
import java.util.ArrayList;
@ -80,33 +76,6 @@ class CommitCommentsPresenter extends BasePresenter<CommitCommentsMvp.View> impl
return comments;
}
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data,
@NonNull DynamicRecyclerView recycler,
@NonNull CommentsAdapter adapter) {
if (resultCode == Activity.RESULT_OK && data != null) {
if (requestCode == BundleConstant.REQUEST_CODE) {
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
CommentsModel commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (isNew) {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(commentsModel);
if (position != -1) {
adapter.swapItem(commentsModel, position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
}
}
}
}
@Override public void onHandleDeletion(@Nullable Bundle bundle) {
if (bundle != null) {
long commId = bundle.getLong(BundleConstant.EXTRA, 0);

View File

@ -1,5 +1,6 @@
package com.fastaccess.ui.modules.repos.code.commit.details.comments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -167,7 +168,28 @@ public class CommitCommentsView extends BaseFragment<CommitCommentsMvp.View, Com
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
getPresenter().onActivityResult(requestCode, resultCode, data, recycler, adapter);
if (resultCode == Activity.RESULT_OK && data != null) {
if (requestCode == BundleConstant.REQUEST_CODE) {
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
CommentsModel commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (isNew) {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(commentsModel);
if (position != -1) {
adapter.swapItem(commentsModel, position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
}
}
}
}
@Override public void onMessageDialogActionClicked(boolean isOk, @Nullable Bundle bundle) {

View File

@ -1,6 +1,5 @@
package com.fastaccess.ui.modules.repos.issues.issue.details.comments;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -9,10 +8,8 @@ import android.support.v4.widget.SwipeRefreshLayout;
import com.fastaccess.data.dao.CommentsModel;
import com.fastaccess.data.dao.UserModel;
import com.fastaccess.provider.rest.loadmore.OnLoadMore;
import com.fastaccess.ui.adapter.CommentsAdapter;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
import java.util.ArrayList;
@ -53,9 +50,6 @@ interface IssueCommentsMvp {
@NonNull ArrayList<CommentsModel> getComments();
void onActivityResult(int requestCode, int resultCode, @Nullable Intent data,
@NonNull DynamicRecyclerView recycler, @NonNull CommentsAdapter adapter);
void onWorkOffline();
void onHandleDeletion(@Nullable Bundle bundle);

View File

@ -1,7 +1,5 @@
package com.fastaccess.ui.modules.repos.issues.issue.details.comments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -12,10 +10,8 @@ import com.fastaccess.data.dao.CommentsModel;
import com.fastaccess.data.dao.LoginModel;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.adapter.CommentsAdapter;
import com.fastaccess.ui.base.mvp.BaseMvp;
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView;
import java.util.ArrayList;
@ -90,32 +86,6 @@ class IssueCommentsPresenter extends BasePresenter<IssueCommentsMvp.View> implem
return comments;
}
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data,
@NonNull DynamicRecyclerView recycler, @NonNull CommentsAdapter adapter) {
if (resultCode == Activity.RESULT_OK && data != null) {
if (requestCode == BundleConstant.REQUEST_CODE) {
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
CommentsModel commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (isNew) {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(commentsModel);
if (position != -1) {
adapter.swapItem(commentsModel, position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
}
}
}
}
@Override public void onWorkOffline() {
if (comments.isEmpty()) {
manageSubscription(CommentsModel.getIssueComments(repoId(), login(), String.valueOf(number))

View File

@ -1,5 +1,6 @@
package com.fastaccess.ui.modules.repos.issues.issue.details.comments;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -168,7 +169,28 @@ public class IssueCommentsView extends BaseFragment<IssueCommentsMvp.View, Issue
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
getPresenter().onActivityResult(requestCode, resultCode, data, recycler, adapter);
if (resultCode == Activity.RESULT_OK && data != null) {
if (requestCode == BundleConstant.REQUEST_CODE) {
Bundle bundle = data.getExtras();
if (bundle != null) {
boolean isNew = bundle.getBoolean(BundleConstant.EXTRA);
CommentsModel commentsModel = bundle.getParcelable(BundleConstant.ITEM);
if (isNew) {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
} else {
int position = adapter.getItem(commentsModel);
if (position != -1) {
adapter.swapItem(commentsModel, position);
recycler.smoothScrollToPosition(position);
} else {
adapter.addItem(commentsModel);
recycler.smoothScrollToPosition(adapter.getItemCount());
}
}
}
}
}
}
@Override public void onMessageDialogActionClicked(boolean isOk, @Nullable Bundle bundle) {

View File

@ -100,6 +100,7 @@ public abstract class BaseRecyclerAdapter<M, VH extends BaseViewHolder,
public void addItem(M item) {
data.add(item);
notifyItemInserted(getItemCount() - 1);
notifyItemRangeInserted(getItemCount() - 1, getItemCount());
}
@SuppressWarnings("WeakerAccess") public void addItems(List<M> items) {
@ -110,6 +111,7 @@ public abstract class BaseRecyclerAdapter<M, VH extends BaseViewHolder,
@SuppressWarnings("WeakerAccess") public void removeItem(int position) {
data.remove(position);
notifyItemRemoved(position);
notifyItemRangeRemoved(position, getItemCount());
}
public void removeItem(M item) {

View File

@ -247,7 +247,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@null"
android:contentDescription="@string/preview"
android:foreground="?selectableItemBackgroundBorderless"
android:padding="@dimen/spacing_normal"
android:scaleType="centerCrop"

View File

@ -174,4 +174,8 @@
<string name="fork_repo_hint">Click here to fork repo.</string>
<string name="no_url">No url found.</string>
<string name="last_updated">Last Updated</string>
<string name="preview">Preview</string>
<string name="view_code">Syntax Highlighter</string>
<string name="click_to_toggle_highlighting">Click here to toggle Syntax Highlighting.\nYou can scroll the Markdown editor icons for more
markdown options.</string>
</resources>