diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/FileUtils.java b/app/src/main/java/com/wbrawner/simplemarkdown/FileUtils.java
index c6ab284..1e35052 100644
--- a/app/src/main/java/com/wbrawner/simplemarkdown/FileUtils.java
+++ b/app/src/main/java/com/wbrawner/simplemarkdown/FileUtils.java
@@ -15,6 +15,7 @@ import android.support.v7.app.AppCompatActivity;
public class FileUtils {
public static final int WRITE_PERMISSION_REQUEST = 0;
+ public static final int OPEN_FILE_REQUEST = 1;
private Activity mContext;
diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java
index 29b1d6d..ef194bd 100644
--- a/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java
+++ b/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java
@@ -39,13 +39,15 @@ import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity
-implements ActivityCompat.OnRequestPermissionsResultCallback {
+ implements ActivityCompat.OnRequestPermissionsResultCallback {
public static final String AUTHORITY = "com.wbrawner.simplemarkdown.fileprovider";
private static final int REQUEST_WRITE_STORAGE = 0;
private static File mFilesDir;
- @BindView(R.id.pager) ViewPager pager;
- @BindView(R.id.layout_tab) TabLayout tabLayout;
+ @BindView(R.id.pager)
+ ViewPager pager;
+ @BindView(R.id.layout_tab)
+ TabLayout tabLayout;
private static final String TAG = MainActivity.class.getSimpleName();
private static String fileName;
@@ -178,6 +180,9 @@ implements ActivityCompat.OnRequestPermissionsResultCallback {
}
}
break;
+ case R.id.action_load:
+ requestOpen();
+ break;
}
return super.onOptionsItemSelected(item);
}
@@ -189,6 +194,24 @@ implements ActivityCompat.OnRequestPermissionsResultCallback {
.sendBroadcast(saveIntent);
}
+ private void requestOpen() {
+ Intent openIntent = new Intent(Intent.ACTION_GET_CONTENT);
+ openIntent.setType("*/*");
+ openIntent.addCategory(Intent.CATEGORY_OPENABLE);
+ try {
+ startActivityForResult(
+ Intent.createChooser(
+ openIntent,
+ getString(R.string.open_file)
+ ),
+ FileUtils.OPEN_FILE_REQUEST
+ );
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(MainActivity.this, R.string.no_filebrowser, Toast.LENGTH_SHORT)
+ .show();
+ }
+ }
+
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
@@ -256,4 +279,18 @@ implements ActivityCompat.OnRequestPermissionsResultCallback {
else
pager.setCurrentItem(EditPagerAdapter.FRAGMENT_EDIT);
}
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case FileUtils.OPEN_FILE_REQUEST:
+ if (resultCode == RESULT_OK) {
+ Uri fileUri = data.getData();
+ Intent loadIntent = new Intent(EditFragment.LOAD_ACTION);
+ loadIntent.putExtra("fileUri", fileUri.toString());
+ LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(loadIntent);
+ }
+ }
+ super.onActivityResult(requestCode, resultCode, data);
+ }
}
diff --git a/app/src/main/res/menu/menu_edit.xml b/app/src/main/res/menu/menu_edit.xml
index e673dbe..4d99a82 100644
--- a/app/src/main/res/menu/menu_edit.xml
+++ b/app/src/main/res/menu/menu_edit.xml
@@ -11,9 +11,14 @@
android:id="@+id/action_share"
android:icon="@android:drawable/ic_menu_share"
app:showAsAction="always" />
+
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7d439cd..c89ac24 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -16,4 +16,7 @@
Share file to...
Unable to save file without permissions
File saved to %1$s
+ Load
+ Select a file to open
+ No file browser apps found