diff --git a/app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java b/app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java index 10a00e33a..d8adb347e 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java @@ -199,18 +199,21 @@ public static void showFile(final BaseActivity activity, File file, boolean isOp String name = file.getName(); String suffix = name.substring(name.lastIndexOf('.') + 1).toLowerCase(); - if (!isOpenWith) { - //Open markdown and txt files in MarkdownActivity - if ("md".equals(suffix) || "markdown".equals(suffix) || "txt".equals(suffix)) { - startMarkdownActivity(activity, file.getPath()); - activity.overridePendingTransition(0, 0); - return; - } + + //Open markdown and txt files in MarkdownActivity + boolean isTextMime = Utils.isTextMimeType(name); + if (isTextMime && !isOpenWith) { + startMarkdownActivity(activity, file.getPath()); + activity.overridePendingTransition(0, 0); + return; } String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix); - if (mime==null) - mime = "*/*"; // forces app chooser dialog on unknown type + if (mime == null && isTextMime) { + mime = "text/*"; // set .md .markdown .txt file type// + } else if (mime == null) { + mime = "*/*"; // forces app chooser dialog on unknown type// + } Intent open = new Intent(Intent.ACTION_VIEW); open.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/fragment/ReposFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/fragment/ReposFragment.java index 08d9aefcd..cdcb71f61 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/fragment/ReposFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/fragment/ReposFragment.java @@ -252,6 +252,10 @@ public void onClick(DialogInterface dialog, int which) { menu.findItem(R.id.delete).setVisible(false); menu.findItem(R.id.move).setVisible(false); } + if (!Utils.isTextMimeType(filename)) { + Menu menu = builder.build().getMenu(); + menu.findItem(R.id.open).setVisible(false); + } builder.show(); SeafRepo repo = getDataManager().getCachedRepoByID(repoID); if (repo != null && repo.encrypted) { diff --git a/app/src/main/java/com/seafile/seadroid2/util/Utils.java b/app/src/main/java/com/seafile/seadroid2/util/Utils.java index 58c048b7a..fb48d69d0 100644 --- a/app/src/main/java/com/seafile/seadroid2/util/Utils.java +++ b/app/src/main/java/com/seafile/seadroid2/util/Utils.java @@ -333,19 +333,19 @@ public static boolean isNetworkOn() { ConnectivityManager connMgr = (ConnectivityManager) SeadroidApplication.getAppContext().getSystemService( Context.CONNECTIVITY_SERVICE); - - NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - if(wifi != null && wifi.isAvailable() - && wifi.getDetailedState() == DetailedState.CONNECTED) { - return true; + NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); + if (networkInfo == null) { + return false; } - - NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); - if(mobile != null && mobile.isAvailable() - && mobile.getDetailedState() == DetailedState.CONNECTED) { + if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { + String extraInfo = networkInfo.getExtraInfo(); + if (!TextUtils.isEmpty(extraInfo)) { + return true; + } + } + if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } - return false; } @@ -733,6 +733,15 @@ public final static boolean isValidEmail(CharSequence target) { return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches(); } + public static boolean isTextMimeType(String fileName) { + String suffix = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase(); + //file is markdown or txt + if ("md".equals(suffix) || "markdown".equals(suffix) || "txt".equals(suffix)) { + return true; + } + return false; + } + private static long lastClickTime; /** @@ -849,4 +858,6 @@ public static void hideSystemNavigationBar(Activity activity) { decorView.setSystemUiVisibility(uiOptions); } } + + }