Skip to content

Commit

Permalink
Extract hard-coded bundle params names
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattia PRIMAVERA authored and Tunous committed Mar 24, 2018
1 parent a2d62a0 commit 397eea9
Show file tree
Hide file tree
Showing 34 changed files with 442 additions and 299 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@

public class CollaboratorListFragment extends PagedDataBaseFragment<User> implements
RootAdapter.OnItemClickListener<User> {
private static final String EXTRA_OWNER = "owner";
private static final String EXTRA_REPO = "repo";

public static CollaboratorListFragment newInstance(String owner, String repo) {
CollaboratorListFragment f = new CollaboratorListFragment();
Bundle args = new Bundle();
args.putString("owner", owner);
args.putString("repo", repo);
args.putString(EXTRA_OWNER, owner);
args.putString(EXTRA_REPO, repo);
f.setArguments(args);
return f;
}

@Override
protected Single<Response<Page<User>>> loadPage(int page, boolean bypassCache) {
String owner = getArguments().getString("owner");
String repo = getArguments().getString("repo");
String owner = getArguments().getString(EXTRA_OWNER);
String repo = getArguments().getString(EXTRA_REPO);
final RepositoryCollaboratorService service =
ServiceFactory.get(RepositoryCollaboratorService.class, bypassCache);
return service.getCollaborators(owner, repo, page);
Expand Down
47 changes: 27 additions & 20 deletions app/src/main/java/com/gh4a/fragment/CommitCompareFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package com.gh4a.fragment;

import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -36,10 +32,23 @@
import com.meisolsson.githubsdk.model.CommitCompare;
import com.meisolsson.githubsdk.service.repositories.RepositoryCommitService;

import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;

import io.reactivex.Single;

public class CommitCompareFragment extends ListDataBaseFragment<Commit> implements
RootAdapter.OnItemClickListener<Commit> {
private static final String EXTRA_OWNER = "owner";
private static final String EXTRA_REPO = "repo";
private static final String EXTRA_BASE = "base";
private static final String EXTRA_BASE_LABEL = "base_label";
private static final String EXTRA_HEAD = "head";
private static final String EXTRA_HEAD_LABEL = "head_label";
private static final String EXTRA_PR = "pr";
private static final int REQUEST_COMMIT = 2000;

public static CommitCompareFragment newInstance(String repoOwner, String repoName,
String baseRef, String headRef) {
return newInstance(repoOwner, repoName, -1, null, baseRef, null, headRef);
Expand All @@ -49,21 +58,19 @@ public static CommitCompareFragment newInstance(String repoOwner, String repoNam
int pullRequestNumber, String baseRefLabel, String baseRef,
String headRefLabel, String headRef) {
Bundle args = new Bundle();
args.putString("owner", repoOwner);
args.putString("repo", repoName);
args.putString("base", baseRef);
args.putString("base_label", baseRefLabel);
args.putString("head", headRef);
args.putString("head_label", headRefLabel);
args.putInt("pr", pullRequestNumber);
args.putString(EXTRA_OWNER, repoOwner);
args.putString(EXTRA_REPO, repoName);
args.putString(EXTRA_BASE, baseRef);
args.putString(EXTRA_BASE_LABEL, baseRefLabel);
args.putString(EXTRA_HEAD, headRef);
args.putString(EXTRA_HEAD_LABEL, headRefLabel);
args.putInt(EXTRA_PR, pullRequestNumber);

CommitCompareFragment f = new CommitCompareFragment();
f.setArguments(args);
return f;
}

private static final int REQUEST_COMMIT = 2000;

private String mRepoOwner;
private String mRepoName;
private String mBase;
Expand All @@ -77,13 +84,13 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle args = getArguments();
mRepoOwner = args.getString("owner");
mRepoName = args.getString("repo");
mBase = args.getString("base");
mBaseLabel = args.getString("base_label");
mHead = args.getString("head");
mHeadLabel = args.getString("head_label");
mPullRequestNumber = args.getInt("pr", -1);
mRepoOwner = args.getString(EXTRA_OWNER);
mRepoName = args.getString(EXTRA_REPO);
mBase = args.getString(EXTRA_BASE);
mBaseLabel = args.getString(EXTRA_BASE_LABEL);
mHead = args.getString(EXTRA_HEAD);
mHeadLabel = args.getString(EXTRA_HEAD_LABEL);
mPullRequestNumber = args.getInt(EXTRA_PR, -1);
}

@Override
Expand Down
41 changes: 25 additions & 16 deletions app/src/main/java/com/gh4a/fragment/CommitFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,30 @@
import java.util.List;

public class CommitFragment extends LoadingFragmentBase implements OnClickListener {
private static final String EXTRA_OWNER = "owner";
private static final String EXTRA_REPO = "repo";
private static final String EXTRA_SHA = "sha";
private static final String EXTRA_COMMIT = "commit";
private static final String EXTRA_COMMENTS = "comments";
private static final String STATUS_ADDED = "added";
private static final String STATUS_MODIFIED = "modified";
private static final String STATUS_RENAMED = "renamed";
private static final String STATUS_REMOVED = "removed";
private static final int REQUEST_DIFF_VIEWER = 1000;

public static CommitFragment newInstance(String repoOwner, String repoName, String commitSha,
Commit commit, List<GitComment> comments) {
CommitFragment f = new CommitFragment();

Bundle args = new Bundle();
args.putString("owner", repoOwner);
args.putString("repo", repoName);
args.putString("sha", commitSha);
args.putString(EXTRA_OWNER, repoOwner);
args.putString(EXTRA_REPO, repoName);
args.putString(EXTRA_SHA, commitSha);
// Commit objects can be huge, depending on the number of patches attached to it.
// In order to avoid TransactionTooLargeExceptions being thrown when the activity we're
// attached to is recreated, store the data in compressed form
IntentUtils.putParcelableToBundleCompressed(args, "commit", commit, 100000);
args.putParcelableArrayList("comments", new ArrayList<>(comments));
IntentUtils.putParcelableToBundleCompressed(args, EXTRA_COMMIT, commit, 100000);
args.putParcelableArrayList(EXTRA_COMMENTS, new ArrayList<>(comments));
f.setArguments(args);
return f;
}
Expand All @@ -60,8 +71,6 @@ public interface CommentUpdateListener {
void onCommentsUpdated();
}

private static final int REQUEST_DIFF_VIEWER = 1000;

private String mRepoOwner;
private String mRepoName;
private String mObjectSha;
Expand All @@ -73,11 +82,11 @@ public interface CommentUpdateListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
mRepoOwner = args.getString("owner");
mRepoName = args.getString("repo");
mObjectSha = args.getString("sha");
mCommit = IntentUtils.readCompressedParcelableFromBundle(args, "commit");
mComments = args.getParcelableArrayList("comments");
mRepoOwner = args.getString(EXTRA_OWNER);
mRepoName = args.getString(EXTRA_REPO);
mObjectSha = args.getString(EXTRA_SHA);
mCommit = IntentUtils.readCompressedParcelableFromBundle(args, EXTRA_COMMIT);
mComments = args.getParcelableArrayList(EXTRA_COMMENTS);
}

@Override
Expand Down Expand Up @@ -197,19 +206,19 @@ protected void fillStats(List<GitHubFile> files, List<? extends PositionalCommen
final LinearLayout parent;

switch (file.status()) {
case "added":
case STATUS_ADDED:
parent = llAdded;
added++;
break;
case "modified":
case STATUS_MODIFIED:
parent = llChanged;
changed++;
break;
case "renamed":
case STATUS_RENAMED:
parent = llRenamed;
renamed++;
break;
case "removed":
case STATUS_REMOVED:
parent = llDeleted;
deleted++;
break;
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/java/com/gh4a/fragment/CommitListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public interface ContextSelectionCallback {

private static final int REQUEST_COMMIT = 2000;
private static final int MENU_SELECT_AS_BASE = Menu.FIRST + 2;
private static final String EXTRA_OWNER = "owner";
private static final String EXTRA_REPO = "repo";
private static final String EXTRA_REF = "ref";
private static final String EXTRA_PATH = "path";

private String mRepoOwner;
private String mRepoName;
Expand All @@ -71,10 +75,10 @@ public static CommitListFragment newInstance(String repoOwner, String repoName,
CommitListFragment f = new CommitListFragment();

Bundle args = new Bundle();
args.putString("owner", repoOwner);
args.putString("repo", repoName);
args.putString("ref", ref);
args.putString("path", filePath);
args.putString(EXTRA_OWNER, repoOwner);
args.putString(EXTRA_REPO, repoName);
args.putString(EXTRA_REF, ref);
args.putString(EXTRA_PATH, filePath);
f.setArguments(args);

return f;
Expand All @@ -83,10 +87,10 @@ public static CommitListFragment newInstance(String repoOwner, String repoName,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRepoOwner = getArguments().getString("owner");
mRepoName = getArguments().getString("repo");
mRef = getArguments().getString("ref");
mFilePath = getArguments().getString("path");
mRepoOwner = getArguments().getString(EXTRA_OWNER);
mRepoName = getArguments().getString(EXTRA_REPO);
mRef = getArguments().getString(EXTRA_REF);
mFilePath = getArguments().getString(EXTRA_PATH);
}

@Override
Expand Down
38 changes: 23 additions & 15 deletions app/src/main/java/com/gh4a/fragment/CommitNoteFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public class CommitNoteFragment extends ListDataBaseFragment<GitComment> impleme
CommitNoteAdapter.OnCommentAction<GitComment>,
EditorBottomSheet.Callback, EditorBottomSheet.Listener {

private static final String EXTRA_OWNER = "owner";
private static final String EXTRA_REPO = "repo";
private static final String EXTRA_SHA = "sha";
private static final String EXTRA_COMMIT_AUTHOR = "commit_author";
private static final String EXTRA_COMMITTER = "committer";
private static final String EXTRA_COMMENTS = "comments";
private static final String EXTRA_INITIAL_COMMENT = "initial_comment";

public static CommitNoteFragment newInstance(String repoOwner, String repoName,
String commitSha, Commit commit,
List<GitComment> allComments, IntentUtils.InitialCommentMarker initialComment) {
Expand All @@ -53,13 +61,13 @@ public static CommitNoteFragment newInstance(String repoOwner, String repoName,
}

Bundle args = new Bundle();
args.putString("owner", repoOwner);
args.putString("repo", repoName);
args.putString("sha", commitSha);
args.putParcelable("commit_author", commit.author());
args.putParcelable("committer", commit.committer());
args.putParcelableArrayList("comments", comments);
args.putParcelable("initial_comment", initialComment);
args.putString(EXTRA_OWNER, repoOwner);
args.putString(EXTRA_REPO, repoName);
args.putString(EXTRA_SHA, commitSha);
args.putParcelable(EXTRA_COMMIT_AUTHOR, commit.author());
args.putParcelable(EXTRA_COMMITTER, commit.committer());
args.putParcelableArrayList(EXTRA_COMMENTS, comments);
args.putParcelable(EXTRA_INITIAL_COMMENT, initialComment);

f.setArguments(args);
return f;
Expand All @@ -85,13 +93,13 @@ public interface CommentUpdateListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
mRepoOwner = args.getString("owner");
mRepoName = args.getString("repo");
mObjectSha = args.getString("sha");
mCommitAuthor = args.getParcelable("commit_author");
mCommitter = args.getParcelable("committer");
mInitialComment = args.getParcelable("initial_comment");
args.remove("initial_comment");
mRepoOwner = args.getString(EXTRA_OWNER);
mRepoName = args.getString(EXTRA_REPO);
mObjectSha = args.getString(EXTRA_SHA);
mCommitAuthor = args.getParcelable(EXTRA_COMMIT_AUTHOR);
mCommitter = args.getParcelable(EXTRA_COMMITTER);
mInitialComment = args.getParcelable(EXTRA_INITIAL_COMMENT);
args.remove(EXTRA_INITIAL_COMMENT);
}

@Override
Expand Down Expand Up @@ -227,7 +235,7 @@ protected int getEmptyTextResId() {

@Override
protected Single<List<GitComment>> onCreateDataSingle(boolean bypassCache) {
List<GitComment> comments = getArguments().getParcelableArrayList("comments");
List<GitComment> comments = getArguments().getParcelableArrayList(EXTRA_COMMENTS);
if (comments != null && !comments.isEmpty()) {
return Single.just(comments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public interface CommitSelectionCallback {
private static final String STATE_KEY_DIR_STACK = "dir_stack";
private static final String STATE_KEY_CONTENT_CACHE_PREFIX = "content_cache_";
private static final String STATE_KEY_INITIAL_PATH = "initial_path";
private static final String EXTRA_REPOSITORY = "repository";
private static final String EXTRA_REF = "ref";
private static final String EXTRA_INITIAL_PATH = "initialpath";
private static final int LOADER_MODULEMAP = 100;

private RxLoader mRxLoader;
private PathBreadcrumbs mBreadcrumbs;
Expand Down Expand Up @@ -81,9 +85,9 @@ public static ContentListContainerFragment newInstance(Repository repository,
ContentListContainerFragment f = new ContentListContainerFragment();

Bundle args = new Bundle();
args.putParcelable("repository", repository);
args.putString("ref", ref);
args.putString("initialpath", initialPath);
args.putParcelable(EXTRA_REPOSITORY, repository);
args.putString(EXTRA_REF, ref);
args.putString(EXTRA_INITIAL_PATH, initialPath);
f.setArguments(args);
return f;
}
Expand All @@ -93,8 +97,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mRxLoader = new RxLoader(getActivity(), getLoaderManager());
mRepository = getArguments().getParcelable("repository");
mSelectedRef = getArguments().getString("ref");
mRepository = getArguments().getParcelable(EXTRA_REPOSITORY);
mSelectedRef = getArguments().getString(EXTRA_REF);
mStateSaved = false;

if (savedInstanceState != null) {
Expand All @@ -115,7 +119,7 @@ public void onCreate(Bundle savedInstanceState) {
} else {
mDirStack.push("");

String initialPath = getArguments().getString("initialpath");
String initialPath = getArguments().getString(EXTRA_INITIAL_PATH);
if (initialPath != null) {
mInitialPathToLoad = new ArrayList<>();
int pos = initialPath.indexOf("/");
Expand Down Expand Up @@ -152,7 +156,7 @@ public void onRefresh() {
}

public void setRef(String ref) {
getArguments().putString("ref", ref);
getArguments().putString(EXTRA_REF, ref);
mSelectedRef = ref;
mGitModuleMap = null;

Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/com/gh4a/fragment/ContentListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class ContentListFragment extends ListDataBaseFragment<Content> implement
RootAdapter.OnItemClickListener<Content> {
private static final int MENU_HISTORY = Menu.FIRST + 1;
private static final int REQUEST_FILE_HISTORY = 1000;
private static final String EXTRA_REPO = "repo";
private static final String EXTRA_PATH = "path";
private static final String EXTRA_REF = "ref";
private static final String EXTRA_CONTENTS = "contents";

private static final Comparator<Content> COMPARATOR = (lhs, rhs) -> {
boolean lhsIsDir = lhs.type() == ContentType.Directory;
Expand Down Expand Up @@ -89,10 +93,10 @@ public static ContentListFragment newInstance(Repository repository,
ContentListFragment f = new ContentListFragment();

Bundle args = new Bundle();
args.putString("path", path != null ? path : "");
args.putString("ref", ref);
args.putParcelable("repo", repository);
args.putParcelableArrayList("contents", contents);
args.putString(EXTRA_PATH, path != null ? path : "");
args.putString(EXTRA_REF, ref);
args.putParcelable(EXTRA_REPO, repository);
args.putParcelableArrayList(EXTRA_CONTENTS, contents);
f.setArguments(args);

return f;
Expand All @@ -101,9 +105,9 @@ public static ContentListFragment newInstance(Repository repository,
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRepository = getArguments().getParcelable("repo");
mPath = getArguments().getString("path");
mRef = getArguments().getString("ref");
mRepository = getArguments().getParcelable(EXTRA_REPO);
mPath = getArguments().getString(EXTRA_PATH);
mRef = getArguments().getString(EXTRA_REF);
if (StringUtils.isBlank(mRef)) {
mRef = mRepository.defaultBranch();
}
Expand Down
Loading

0 comments on commit 397eea9

Please sign in to comment.