Skip to content

Commit 0cddfdb

Browse files
committed
Add support for sharing files
1 parent c1b6a7f commit 0cddfdb

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

app/res/menu/file_view.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2012 GitHub Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
18+
19+
<item
20+
android:id="@+id/m_wrap"
21+
android:showAsAction="never"
22+
android:title="@string/enable_wrapping"/>
23+
<item
24+
android:id="@+id/m_share"
25+
android:icon="@drawable/menu_share"
26+
android:showAsAction="never"
27+
android:title="@string/share"/>
28+
29+
</menu>

app/src/main/java/com/github/mobile/ui/code/RepositoryCodeFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,6 @@ public void onItemClick(AdapterView<?> parent, View view, int position,
314314
setFolder(tree, (Folder) entry);
315315
else
316316
startActivity(BranchFileViewActivity.createIntent(repository,
317-
tree.branch, entry.name, entry.entry.getSha()));
317+
tree.branch, entry.entry.getPath(), entry.entry.getSha()));
318318
}
319319
}

app/src/main/java/com/github/mobile/ui/commit/CommitFileViewActivity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.github.mobile.core.commit.CommitUtils;
4040
import com.github.mobile.util.AvatarLoader;
4141
import com.github.mobile.util.PreferenceUtils;
42+
import com.github.mobile.util.ShareUtils;
4243
import com.github.mobile.util.SourceEditor;
4344
import com.github.mobile.util.ToastUtils;
4445
import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockActivity;
@@ -124,7 +125,7 @@ protected void onCreate(Bundle savedInstanceState) {
124125

125126
@Override
126127
public boolean onCreateOptionsMenu(final Menu optionsMenu) {
127-
getSupportMenuInflater().inflate(menu.code_view, optionsMenu);
128+
getSupportMenuInflater().inflate(menu.file_view, optionsMenu);
128129

129130
MenuItem wrapItem = optionsMenu.findItem(id.m_wrap);
130131
if (PreferenceUtils.getCodePreferences(this).getBoolean(WRAP, false))
@@ -149,11 +150,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
149150
PreferenceUtils.save(PreferenceUtils.getCodePreferences(this)
150151
.edit().putBoolean(WRAP, editor.getWrap()));
151152
return true;
153+
case id.m_share:
154+
shareFile();
155+
return true;
152156
default:
153157
return super.onOptionsItemSelected(item);
154158
}
155159
}
156160

161+
private void shareFile() {
162+
String id = repo.generateId();
163+
startActivity(ShareUtils.create(
164+
path + " at " + CommitUtils.abbreviate(commit) + " on " + id,
165+
"https://github.com/" + id + "/blob/" + commit + '/' + path));
166+
}
167+
157168
private void loadContent() {
158169
new RefreshBlobTask(repo, sha, this) {
159170

app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
import com.github.mobile.R.menu;
3737
import com.github.mobile.R.string;
3838
import com.github.mobile.core.code.RefreshBlobTask;
39+
import com.github.mobile.core.commit.CommitUtils;
3940
import com.github.mobile.util.AvatarLoader;
4041
import com.github.mobile.util.PreferenceUtils;
42+
import com.github.mobile.util.ShareUtils;
4143
import com.github.mobile.util.SourceEditor;
4244
import com.github.mobile.util.ToastUtils;
4345
import com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockActivity;
@@ -82,6 +84,8 @@ public static Intent createIntent(Repository repository, String branch,
8284
private String sha;
8385

8486
@InjectExtra(EXTRA_PATH)
87+
private String path;
88+
8589
private String file;
8690

8791
@InjectExtra(EXTRA_HEAD)
@@ -104,6 +108,7 @@ protected void onCreate(Bundle savedInstanceState) {
104108

105109
setContentView(layout.commit_file_view);
106110

111+
file = CommitUtils.getName(path);
107112
editor = new SourceEditor(codeView);
108113
editor.setWrap(PreferenceUtils.getCodePreferences(this).getBoolean(
109114
WRAP, false));
@@ -118,7 +123,7 @@ protected void onCreate(Bundle savedInstanceState) {
118123

119124
@Override
120125
public boolean onCreateOptionsMenu(final Menu optionsMenu) {
121-
getSupportMenuInflater().inflate(menu.code_view, optionsMenu);
126+
getSupportMenuInflater().inflate(menu.file_view, optionsMenu);
122127

123128
MenuItem wrapItem = optionsMenu.findItem(id.m_wrap);
124129
if (PreferenceUtils.getCodePreferences(this).getBoolean(WRAP, false))
@@ -143,11 +148,20 @@ public boolean onOptionsItemSelected(MenuItem item) {
143148
PreferenceUtils.save(PreferenceUtils.getCodePreferences(this)
144149
.edit().putBoolean(WRAP, editor.getWrap()));
145150
return true;
151+
case id.m_share:
152+
shareFile();
153+
return true;
146154
default:
147155
return super.onOptionsItemSelected(item);
148156
}
149157
}
150158

159+
private void shareFile() {
160+
String id = repo.generateId();
161+
startActivity(ShareUtils.create(path + " at " + branch + " on " + id,
162+
"https://github.com/" + id + "/blob/" + branch + '/' + path));
163+
}
164+
151165
private void loadContent() {
152166
new RefreshBlobTask(repo, sha, this) {
153167

0 commit comments

Comments
 (0)