diff --git a/.gitignore b/.gitignore
index e3e740471..aac5a753a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,3 +52,4 @@ app/seed.txt
out/
*.store
+*.jks
diff --git a/README.md b/README.md
index 5f7712f03..85f6b7cce 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,7 @@ You will get `app/build/outputs/apk/seafile-${versionName}.apk` after the build
### Prerequisites
* Android Studio
-* OpenJDK 7 / OracleJDK 7
+* OpenJDK 8 / OracleJDK 8
### Import project
diff --git a/app/src/main/java/com/seafile/seadroid2/SettingsManager.java b/app/src/main/java/com/seafile/seadroid2/SettingsManager.java
index 768ede9b6..955aa483c 100644
--- a/app/src/main/java/com/seafile/seadroid2/SettingsManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/SettingsManager.java
@@ -18,16 +18,17 @@
public final class SettingsManager {
private static final String DEBUG_TAG = "SettingsManager";
-
private static SettingsManager instance;
- private static SharedPreferences.Editor editor;
+ private SharedPreferences settingsSharedPref;
private static SharedPreferences sharedPref;
+ private static SharedPreferences.Editor editor;
private SettingsManager() {
+ settingsSharedPref = PreferenceManager.getDefaultSharedPreferences(SeadroidApplication.getAppContext());
+ sharedPref = SeadroidApplication.getAppContext().getSharedPreferences(AccountManager.SHARED_PREF_NAME, Context.MODE_PRIVATE);
+ editor = sharedPref.edit();
}
- private SharedPreferences settingsSharedPref = PreferenceManager
- .getDefaultSharedPreferences(SeadroidApplication.getAppContext());
// Account
public static final String SETTINGS_ACCOUNT_INFO_KEY = "account_info_user_key";
@@ -98,12 +99,9 @@ public static SettingsManager instance() {
synchronized (SettingsManager.class) {
if (instance == null) {
instance = new SettingsManager();
- sharedPref = SeadroidApplication.getAppContext().getSharedPreferences(AccountManager.SHARED_PREF_NAME, Context.MODE_PRIVATE);
- editor = sharedPref.edit();
}
}
}
-
return instance;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/data/StorageManager.java b/app/src/main/java/com/seafile/seadroid2/data/StorageManager.java
index a358321fc..84f2fb708 100644
--- a/app/src/main/java/com/seafile/seadroid2/data/StorageManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/data/StorageManager.java
@@ -18,7 +18,6 @@
import org.apache.commons.io.FileUtils;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -247,7 +246,7 @@ public final void setStorageDir(int id) {
}
notifyAndroidGalleryDirectoryChange(FileUtils.listFiles(newMediaDir, null, true));
- } catch (IOException e) {
+ } catch (Exception e) {
Log.e(DEBUG_TAG, "Could not move cache to new location", e);
return;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java b/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java
index a5f1121d6..61f9b4e99 100644
--- a/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java
+++ b/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java
@@ -7,7 +7,6 @@
import com.seafile.seadroid2.data.DataManager;
import com.seafile.seadroid2.data.SeafCachedFile;
import com.seafile.seadroid2.data.SeafRepo;
-import com.seafile.seadroid2.util.FileMimeUtils;
import com.seafile.seadroid2.util.Utils;
import org.apache.commons.io.monitor.FileAlterationListener;
@@ -127,16 +126,13 @@ public void onFileChange(File file) {
SeafCachedFile cachedFile = watchedFiles.get(path);
if (cachedFile != null) {
// office or txt file need to update file
- String fileMime = FileMimeUtils.getFileMime(file);
- boolean needUpdateFile = FileMimeUtils.isOfficeOrTextFile(fileMime);
- // file size is change ,
- if (file.length() == cachedFile.fileOriginalSize && !needUpdateFile) {
- Log.d(DEBUG_TAG, "ignore file size not change " + path);
+ boolean isTextFile = Utils.isTextFile(file);
+ //if file is not TextFile and file size not changed, do not update
+ if (file.length() == cachedFile.fileOriginalSize && !isTextFile) {
return;
- } else {
- cachedFile.fileOriginalSize = file.length();
}
+ cachedFile.fileOriginalSize = file.length();
final SeafRepo repo = dataManager.getCachedRepoByID(cachedFile.repoID);
if (repo != null && repo.canLocalDecrypt()) {
listener.onCachedBlocksChanged(account, cachedFile, file, repo.encVersion);
diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java
index 7ff6e54f9..146734c28 100644
--- a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java
+++ b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java
@@ -124,7 +124,6 @@ protected void onCancelled() {
if (uploadStateListener != null) {
uploadStateListener.onFileUploadCancelled(taskID);
}
- uploadStateListener.onFileUploadCancelled(taskID);
}
public String getDir() {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/activity/MarkdownActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/activity/MarkdownActivity.java
index fd2585381..b0673dcf9 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/activity/MarkdownActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/activity/MarkdownActivity.java
@@ -96,7 +96,7 @@ private void edit() {
uri = Uri.parse(path);
}
- String mime = FileMimeUtils.getFileMime(new File(path));
+ String mime = FileMimeUtils.getMimeType(new File(path));
editAsMarkDown.setDataAndType(uri, mime);
if (pm.queryIntentActivities(editAsMarkDown, 0).size() > 0) {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java b/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java
index fe842a80c..47a089f39 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/adapter/SeafItemAdapter.java
@@ -352,7 +352,14 @@ private void setFileView(SeafDirent dirent, Viewholder viewHolder, int position)
if (repoName == null || repoID == null)
return;
- File file = dataManager.getLocalRepoFile(repoName, repoID, filePath);
+ File file = null;
+ try {
+ file = dataManager.getLocalRepoFile(repoName, repoID, filePath);
+ } catch (RuntimeException e) {
+ mActivity.showShortToast(mActivity, mActivity.getResources().getString(R.string.storage_space_insufficient));
+ e.printStackTrace();
+ return;
+ }
boolean cacheExists = false;
if (file.exists()) {
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 32c4adf67..d1335bfa4 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
@@ -475,9 +475,9 @@ public void run() {
String repoID = getNavContext().getRepoID();
String repoName = getNavContext().getRepoName();
String currentDir = getNavContext().getDirPath();
-
- adapter.setDownloadTaskList(ts.getDownloadTaskInfosByPath(repoID, currentDir));
-
+ if (ts != null) {
+ adapter.setDownloadTaskList(ts.getDownloadTaskInfosByPath(repoID, currentDir));
+ }
// Log.d(DEBUG_TAG, "timer post refresh signal " + System.currentTimeMillis());
mTimer.postDelayed(this, 1 * 3500);
}
diff --git a/app/src/main/java/com/seafile/seadroid2/util/FileMimeUtils.java b/app/src/main/java/com/seafile/seadroid2/util/FileMimeUtils.java
index 325f747e4..73ae170e1 100644
--- a/app/src/main/java/com/seafile/seadroid2/util/FileMimeUtils.java
+++ b/app/src/main/java/com/seafile/seadroid2/util/FileMimeUtils.java
@@ -1,5 +1,7 @@
package com.seafile.seadroid2.util;
+import android.media.MediaMetadataRetriever;
+
import java.io.File;
import java.util.HashMap;
@@ -40,121 +42,30 @@ public class FileMimeUtils {
needUpdateFileMime.put(".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12");
needUpdateFileMime.put(".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12");
needUpdateFileMime.put(".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12");
- needUpdateFileMime.put(".c", "text/plain");
- needUpdateFileMime.put(".conf", "text/plain");
- needUpdateFileMime.put(".cpp", "text/plain");
- needUpdateFileMime.put(".h", "text/plain");
- needUpdateFileMime.put(".java", "text/plain");
- needUpdateFileMime.put(".log", "text/plain");
- needUpdateFileMime.put(".htm", "text/html");
- needUpdateFileMime.put(".html", "text/html");
- needUpdateFileMime.put(".prop", "text/plain");
- needUpdateFileMime.put(".rc", "text/plain");
- needUpdateFileMime.put(".sh", "text/plain");
- needUpdateFileMime.put(".txt", "text/plain");
- needUpdateFileMime.put(".md", "text/markdown");
- needUpdateFileMime.put(".markdown", "text/x-markdown");
- needUpdateFileMime.put(".md1", "text/vnd.daringfireball.markdown");
- needUpdateFileMime.put(".md2", " text/x-web-markdown");
needUpdateFileMime.put(".wps", "application/vnd.ms-works");
}
- private static String[][] MIME_MapTable = {
- //{last name, MIME type}
- {".3gp", "video/3gpp"},
- {".apk", "application/vnd.android.package-archive"},
- {".asf", "video/x-ms-asf"},
- {".avi", "video/x-msvideo"},
- {".bin", "application/octet-stream"},
- {".bmp", "image/bmp"},
- {".c", "text/plain"},
- {".class", "application/octet-stream"},
- {".conf", "text/plain"},
- {".cpp", "text/plain"},
- {".doc", "application/msword"},
- {".exe", "application/octet-stream"},
- {".gif", "image/gif"},
- {".gtar", "application/x-gtar"},
- {".gz", "application/x-gzip"},
- {".h", "text/plain"},
- {".htm", "text/html"},
- {".html", "text/html"},
- {".jar", "application/java-archive"},
- {".java", "text/plain"},
- {".jpeg", "image/jpeg"},
- {".jpg", "image/jpeg"},
- {".js", "application/x-javascript"},
- {".log", "text/plain"},
- {".m3u", "audio/x-mpegurl"},
- {".m4a", "audio/mp4a-latm"},
- {".m4b", "audio/mp4a-latm"},
- {".m4p", "audio/mp4a-latm"},
- {".m4u", "video/vnd.mpegurl"},
- {".m4v", "video/x-m4v"},
- {".mov", "video/quicktime"},
- {".mp2", "audio/x-mpeg"},
- {".mp3", "audio/x-mpeg"},
- {".mp4", "video/mp4"},
- {".mpc", "application/vnd.mpohun.certificate"},
- {".mpe", "video/mpeg"},
- {".mpeg", "video/mpeg"},
- {".mpg", "video/mpeg"},
- {".mpg4", "video/mp4"},
- {".mpga", "audio/mpeg"},
- {".msg", "application/vnd.ms-outlook"},
- {".ogg", "audio/ogg"},
- {".pdf", "application/pdf"},
- {".png", "image/png"},
- {".pps", "application/vnd.ms-powerpoint"},
- {".ppt", "application/vnd.ms-powerpoint"},
- {".prop", "text/plain"},
- {".rar", "application/x-rar-compressed"},
- {".rc", "text/plain"},
- {".rmvb", "audio/x-pn-realaudio"},
- {".rtf", "application/rtf"},
- {".sh", "text/plain"},
- {".tar", "application/x-tar"},
- {".tgz", "application/x-compressed"},
- {".txt", "text/plain"},
- {".wav", "audio/x-wav"},
- {".wma", "audio/x-ms-wma"},
- {".wmv", "audio/x-ms-wmv"},
- {".wps", "application/vnd.ms-works"},
-// {".xml", "text/xml"},
- {".xml", "text/plain"},
- {".z", "application/x-compress"},
- {".zip", "application/zip"},
- {".md", "text/markdown"},
- {".markdown", "text/x-markdown"},
- {"", "*/*"}
- };
-
- public static String getFileMime(File file) {
- String type = "*/*";
- String fName = file.getName();
- //get "." index in file name
- int dotIndex = fName.lastIndexOf(".");
- if (dotIndex < 0) {
- return type;
- }
- /* get last name */
- String end = fName.substring(dotIndex, fName.length()).toLowerCase();
- if (end == "")
- return type;
- // find MIME file type 。
- for (int i = 0; i < MIME_MapTable.length; i++) {
- if (end.equals(MIME_MapTable[i][0]))
- type = MIME_MapTable[i][1];
- }
- return type;
-
- }
-
-
public static boolean isOfficeOrTextFile(String mime) {
return needUpdateFileMime.containsValue(mime);
}
-
+ public static String getMimeType(File file) {
+ String mime = "text/plain";
+ String filePath = file.getAbsolutePath();
+ MediaMetadataRetriever mmr = new MediaMetadataRetriever();
+ if (filePath != null) {
+ try {
+ mmr.setDataSource(filePath);
+ mime = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE);
+ } catch (IllegalStateException e) {
+ return mime;
+ } catch (IllegalArgumentException e) {
+ return mime;
+ } catch (RuntimeException e) {
+ return mime;
+ }
+ }
+ return mime;
+ }
}
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 02bb42dc3..58c048b7a 100644
--- a/app/src/main/java/com/seafile/seadroid2/util/Utils.java
+++ b/app/src/main/java/com/seafile/seadroid2/util/Utils.java
@@ -305,7 +305,7 @@ public static boolean isVideoFile(String name) {
if (name == null)
return false;
String suffix = name.substring(name.lastIndexOf('.') + 1).toLowerCase();
- if (suffix == null || suffix.length() == 0)
+ if (TextUtils.isEmpty(suffix))
return false;
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
if (mime == null)
@@ -313,6 +313,22 @@ public static boolean isVideoFile(String name) {
return mime.contains("video/");
}
+ public static boolean isTextFile(File file) {
+ if (file != null) {
+ String fileName = file.getName();
+ if (!TextUtils.isEmpty(fileName)) {
+ String suffix = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase();
+ if (!TextUtils.isEmpty(suffix)) {
+ String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
+ if (!TextUtils.isEmpty(mime)) {
+ return mime.contains("text/") || FileMimeUtils.isOfficeOrTextFile(mime);
+ }
+ }
+ }
+ }
+ return false;
+ }
+
public static boolean isNetworkOn() {
ConnectivityManager connMgr = (ConnectivityManager)
SeadroidApplication.getAppContext().getSystemService(
diff --git a/app/src/main/res/drawable-xhdpi/shibboleth.png b/app/src/main/res/drawable-xhdpi/shibboleth.png
deleted file mode 100644
index 55a0961a3..000000000
Binary files a/app/src/main/res/drawable-xhdpi/shibboleth.png and /dev/null differ
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index b37ca63e4..34e5a842a 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -126,8 +126,8 @@
60dp
0dp
7dp
- 30dp
- 30dp
+ 20dp
+ 20dp
18sp
60dp
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8acb441cf..c43cd99dd 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -226,6 +226,7 @@
Open as
Select files to upload
Storage was removed
+ Insufficient storage space
Error when selecting file
- %1$d file selected
diff --git a/build.gradle b/build.gradle
index 319f17bcc..246177712 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.0.0'
+ classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files