|
3 | 3 | import android.app.DialogFragment; |
4 | 4 | import android.content.Intent; |
5 | 5 | import android.content.SharedPreferences; |
| 6 | +import android.net.Uri; |
6 | 7 | import android.os.Bundle; |
7 | 8 | import android.os.Environment; |
8 | 9 | import android.support.v7.app.AppCompatActivity; |
|
27 | 28 | import com.noticeditorteam.noticeditorandroid.model.NoticeItem; |
28 | 29 |
|
29 | 30 | import java.io.File; |
| 31 | +import java.io.IOException; |
30 | 32 | import java.util.ArrayDeque; |
31 | 33 | import java.util.ArrayList; |
32 | 34 | import java.util.LinkedHashSet; |
@@ -57,17 +59,23 @@ public class NoticeTreeActivity extends AppCompatActivity implements |
57 | 59 | private ArrayDeque<NoticeItem> pathlist = new ArrayDeque<>(); |
58 | 60 | private String path, savepath; |
59 | 61 | private ExportStrategy currentExportStrategy = ExportStrategyHolder.ZIP; |
| 62 | + private RecentFilesService service; |
60 | 63 |
|
61 | 64 | @Override |
62 | 65 | protected void onCreate(Bundle savedInstanceState) { |
63 | 66 | super.onCreate(savedInstanceState); |
64 | 67 | setContentView(R.layout.activity_notice_tree); |
65 | 68 | current = getIntent().getParcelableExtra(ARG_TREE); |
66 | 69 | path = getIntent().getStringExtra(ARG_FILE); |
| 70 | + service = PreferencesRecentFilesService.with(getSharedPreferences(CONFIG_RECENT, MODE_PRIVATE)); |
67 | 71 | if(savedInstanceState != null) { |
68 | 72 | current = savedInstanceState.getParcelable(SAVE_TREE); |
69 | 73 | path = savedInstanceState.getString(SAVE_FILE); |
70 | 74 | } |
| 75 | + if(current == null) { |
| 76 | + current = openDocument(getIntent().getData()); |
| 77 | + path = getIntent().getData().getPath(); |
| 78 | + } |
71 | 79 | if(pathlist.isEmpty()) pathlist.addLast(current); |
72 | 80 | ListView list = (ListView) findViewById(R.id.noticeview); |
73 | 81 | adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new ArrayList<>(current.getChildren())); |
@@ -135,11 +143,21 @@ public boolean onOptionsItemSelected(MenuItem item) { |
135 | 143 |
|
136 | 144 | private void exportDocument(NoticeItem root, String path, ExportStrategy currentExportStrategy) { |
137 | 145 | DocumentFormat.save(root, new File(path), currentExportStrategy); |
138 | | - SharedPreferences preferences = getSharedPreferences(CONFIG_RECENT, MODE_PRIVATE); |
139 | | - RecentFilesService service = PreferencesRecentFilesService.with(preferences); |
140 | 146 | service.addFile(path); |
141 | 147 | } |
142 | 148 |
|
| 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 | + |
143 | 161 | @Override |
144 | 162 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { |
145 | 163 | super.onCreateContextMenu(menu, v, menuInfo); |
|
0 commit comments