Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added a possibility to fork repositories #314

Closed
wants to merge 1 commit into from

2 participants

@atermenji

Tested this on several repos and forking works as expected. Though I have not found a way to check if that repo is already forked by a user.
Refs #106

I've closed my previous PR (#255) accidentally.

@jonan jonan referenced this pull request from a commit in jonan/ForkHub
@jonan jonan Add forking support.
Closes #106, #500, #314
3870365
@jonan jonan referenced this pull request
Merged

Add forking support #612

@fadils
Owner

Closed via #612

@fadils fadils closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 21, 2013
  1. @atermenji
This page is out of date. Refresh to see the latest.
View
5 app/res/menu/repository_star.xml → app/res/menu/repository_view.xml
@@ -20,5 +20,10 @@
android:id="@+id/m_star"
android:showAsAction="never"
android:title="@string/star"/>
+
+ <item
+ android:id="@+id/m_fork"
+ android:showAsAction="never"
+ android:title="@string/fork" />
</menu>
View
3  app/res/values/strings.xml
@@ -46,6 +46,7 @@
<string name="error_unstarring_repository">Unstarring failed</string>
<string name="error_checking_starring_status">Checking starring status failed</string>
<string name="error_rendering_markdown">Rendering markdown failed</string>
+ <string name="error_forking_repository">Forking failed</string>
<!-- -->
@@ -184,6 +185,7 @@
<string name="unfollow">Unfollow</string>
<string name="star">Star</string>
<string name="unstar">Unstar</string>
+ <string name="fork">Fork</string>
<string name="members">Members</string>
<string name="closing_issue">Closing Issue…</string>
<string name="reopening_issue">Reopening Issue…</string>
@@ -233,6 +235,7 @@
<string name="unfollowing_user">Unfollowing…</string>
<string name="starring_repository">Starring…</string>
<string name="unstarring_repository">Unstarring…</string>
+ <string name="forking_repository">Forking…</string>
<!-- Tab titles, should be as short as possible -->
<string name="tab_repositories">repositories</string>
View
63 app/src/main/java/com/github/mobile/core/repo/ForkRepositoryTask.java
@@ -0,0 +1,63 @@
+package com.github.mobile.core.repo;
+
+import org.eclipse.egit.github.core.IRepositoryIdProvider;
+import org.eclipse.egit.github.core.Repository;
+import org.eclipse.egit.github.core.service.RepositoryService;
+
+import android.accounts.Account;
+import android.content.Context;
+import android.util.Log;
+
+import com.github.mobile.R.string;
+import com.github.mobile.ui.ProgressDialogTask;
+import com.google.inject.Inject;
+
+/**
+ * Task to fork a repository
+ */
+public class ForkRepositoryTask extends ProgressDialogTask<Repository> {
+
+ private static final String TAG = "ForkRepositoryTask";
+
+ @Inject
+ private RepositoryService service;
+
+ private final IRepositoryIdProvider repo;
+
+ /**
+ * Create task for context and id provider
+ *
+ * @param context
+ * @param repo
+ */
+ public ForkRepositoryTask(Context context, IRepositoryIdProvider repo) {
+ super(context);
+
+ this.repo = repo;
+ }
+
+ /**
+ * Execute the task with a progress dialog displaying.
+ * <p>
+ * This method must be called from the main thread.
+ */
+ public void start() {
+ showIndeterminate(string.forking_repository);
+
+ execute();
+ }
+
+ @Override
+ protected Repository run(Account account) throws Exception {
+ service.forkRepository(repo);
+
+ return null;
+ }
+
+ @Override
+ protected void onException(Exception e) throws RuntimeException {
+ super.onException(e);
+
+ Log.d(TAG, "Exception forking repository", e);
+ }
+}
View
26 app/src/main/java/com/github/mobile/ui/repo/RepositoryViewActivity.java
@@ -37,6 +37,7 @@
import com.github.mobile.R.layout;
import com.github.mobile.R.menu;
import com.github.mobile.R.string;
+import com.github.mobile.core.repo.ForkRepositoryTask;
import com.github.mobile.core.repo.RefreshRepositoryTask;
import com.github.mobile.core.repo.RepositoryUtils;
import com.github.mobile.core.repo.StarRepositoryTask;
@@ -125,7 +126,7 @@ protected void onException(Exception e) throws RuntimeException {
@Override
public boolean onCreateOptionsMenu(Menu optionsMenu) {
- getSupportMenuInflater().inflate(menu.repository_star, optionsMenu);
+ getSupportMenuInflater().inflate(menu.repository_view, optionsMenu);
return super.onCreateOptionsMenu(optionsMenu);
}
@@ -172,6 +173,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
case id.m_star:
starRepository();
return true;
+ case id.m_fork:
+ forkRepository();
+ return true;
case android.R.id.home:
finish();
Intent intent = new Intent(this, HomeActivity.class);
@@ -270,4 +274,24 @@ protected void onSuccess(Boolean watching) throws Exception {
}
}.execute();
}
+
+ private void forkRepository() {
+ new ForkRepositoryTask(this, repository) {
+
+ @Override
+ protected void onSuccess(Repository e) throws Exception {
+ super.onSuccess(e);
+
+ setResult(RESOURCE_CHANGED);
+ }
+
+ @Override
+ protected void onException(Exception e) throws RuntimeException {
+ super.onException(e);
+
+ ToastUtils.show(RepositoryViewActivity.this,
+ string.error_forking_repository);
+ }
+ }.start();
+ }
}
Something went wrong with that request. Please try again.