Skip to content

Commit 7226090

Browse files
committed
Added associations for .zip and .json. Close #2.
1 parent e05abbb commit 7226090

3 files changed

Lines changed: 62 additions & 3 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,45 @@
2323
<category android:name="android.intent.category.LAUNCHER" />
2424
</intent-filter>
2525
</activity>
26-
<activity android:name=".activities.NoticeTreeActivity" />
26+
<activity
27+
android:name=".activities.NoticeTreeActivity"
28+
android:label="@string/app_name">
29+
<intent-filter>
30+
<action android:name="android.intent.action.VIEW" />
31+
32+
<category android:name="android.intent.category.DEFAULT" />
33+
<data android:scheme="file" />
34+
<data android:host="*" />
35+
<data android:mimeType="*/*" />
36+
<data android:pathPattern=".*\\.json" />
37+
</intent-filter>
38+
<intent-filter>
39+
<action android:name="android.intent.action.VIEW" />
40+
41+
<category android:name="android.intent.category.DEFAULT" />
42+
<data android:scheme="http" />
43+
<data android:host="*" />
44+
<data android:mimeType="application/json" />
45+
</intent-filter>
46+
<intent-filter>
47+
<action android:name="android.intent.action.VIEW" />
48+
49+
<category android:name="android.intent.category.DEFAULT" />
50+
<data android:scheme="file" />
51+
<data android:host="*" />
52+
<data android:mimeType="*/*" />
53+
<data android:pathPattern=".*\\.zip" />
54+
</intent-filter>
55+
<intent-filter>
56+
<action android:name="android.intent.action.VIEW" />
57+
58+
<category android:name="android.intent.category.DEFAULT" />
59+
<data android:scheme="http" />
60+
<data android:host="*" />
61+
<data android:mimeType="application/octet-stream" />
62+
</intent-filter>
63+
64+
</activity>
2765
<activity
2866
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
2967
android:label="@string/app_name"

app/src/main/java/com/noticeditorteam/noticeditorandroid/activities/MainActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ private void openDocument(String path) {
134134

135135
private void rebuildRecentFilesList() {
136136
List<String> toRemove = new ArrayList<>();
137+
List<String> toAdd = new ArrayList<>();
137138
for(String path : filesService.getAllFiles()) {
138139
File notice = new File(path);
140+
toAdd.add(path);
139141
if(!notice.exists()) toRemove.add(path);
140142
}
143+
filesService.addAll(toAdd);
141144
filesService.removeAll(toRemove);
142145
}
143146
}

app/src/main/java/com/noticeditorteam/noticeditorandroid/activities/NoticeTreeActivity.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.app.DialogFragment;
44
import android.content.Intent;
55
import android.content.SharedPreferences;
6+
import android.net.Uri;
67
import android.os.Bundle;
78
import android.os.Environment;
89
import android.support.v7.app.AppCompatActivity;
@@ -27,6 +28,7 @@
2728
import com.noticeditorteam.noticeditorandroid.model.NoticeItem;
2829

2930
import java.io.File;
31+
import java.io.IOException;
3032
import java.util.ArrayDeque;
3133
import java.util.ArrayList;
3234
import java.util.LinkedHashSet;
@@ -57,17 +59,23 @@ public class NoticeTreeActivity extends AppCompatActivity implements
5759
private ArrayDeque<NoticeItem> pathlist = new ArrayDeque<>();
5860
private String path, savepath;
5961
private ExportStrategy currentExportStrategy = ExportStrategyHolder.ZIP;
62+
private RecentFilesService service;
6063

6164
@Override
6265
protected void onCreate(Bundle savedInstanceState) {
6366
super.onCreate(savedInstanceState);
6467
setContentView(R.layout.activity_notice_tree);
6568
current = getIntent().getParcelableExtra(ARG_TREE);
6669
path = getIntent().getStringExtra(ARG_FILE);
70+
service = PreferencesRecentFilesService.with(getSharedPreferences(CONFIG_RECENT, MODE_PRIVATE));
6771
if(savedInstanceState != null) {
6872
current = savedInstanceState.getParcelable(SAVE_TREE);
6973
path = savedInstanceState.getString(SAVE_FILE);
7074
}
75+
if(current == null) {
76+
current = openDocument(getIntent().getData());
77+
path = getIntent().getData().getPath();
78+
}
7179
if(pathlist.isEmpty()) pathlist.addLast(current);
7280
ListView list = (ListView) findViewById(R.id.noticeview);
7381
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new ArrayList<>(current.getChildren()));
@@ -135,11 +143,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
135143

136144
private void exportDocument(NoticeItem root, String path, ExportStrategy currentExportStrategy) {
137145
DocumentFormat.save(root, new File(path), currentExportStrategy);
138-
SharedPreferences preferences = getSharedPreferences(CONFIG_RECENT, MODE_PRIVATE);
139-
RecentFilesService service = PreferencesRecentFilesService.with(preferences);
140146
service.addFile(path);
141147
}
142148

149+
private NoticeItem openDocument(Uri uri) {
150+
File notice = new File(uri.getPath());
151+
try {
152+
NoticeItem item = DocumentFormat.open(notice);
153+
service.addFile(uri.getPath());
154+
return item;
155+
} catch (IOException e) {
156+
e.printStackTrace();
157+
return null;
158+
}
159+
}
160+
143161
@Override
144162
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
145163
super.onCreateContextMenu(menu, v, menuInfo);

0 commit comments

Comments
 (0)