Skip to content

Commit

Permalink
Merge pull request #769 from haiwen/remove_open_with_other_files
Browse files Browse the repository at this point in the history
Remove open with other files
  • Loading branch information
freeplant authored Nov 28, 2018
2 parents 7a55af0 + bd288ac commit 3350329
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
21 changes: 12 additions & 9 deletions app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 21 additions & 10 deletions app/src/main/java/com/seafile/seadroid2/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -849,4 +858,6 @@ public static void hideSystemNavigationBar(Activity activity) {
decorView.setSystemUiVisibility(uiOptions);
}
}


}

0 comments on commit 3350329

Please sign in to comment.