Skip to content

Commit

Permalink
Fixed the crash in some time open setting pager,Fixed some crash in g…
Browse files Browse the repository at this point in the history
…oogle play,change sign-On login ui
  • Loading branch information
SaudM committed Dec 9, 2017
1 parent c7c1480 commit 9cce55b
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 137 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ app/seed.txt
out/

*.store
*.jks
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/com/seafile/seadroid2/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ protected void onCancelled() {
if (uploadStateListener != null) {
uploadStateListener.onFileUploadCancelled(taskID);
}
uploadStateListener.onFileUploadCancelled(taskID);
}

public String getDir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
129 changes: 20 additions & 109 deletions app/src/main/java/com/seafile/seadroid2/util/FileMimeUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.seafile.seadroid2.util;

import android.media.MediaMetadataRetriever;

import java.io.File;
import java.util.HashMap;

Expand Down Expand Up @@ -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;
}
}
18 changes: 17 additions & 1 deletion app/src/main/java/com/seafile/seadroid2/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,30 @@ 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)
return false;
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(
Expand Down
Binary file removed app/src/main/res/drawable-xhdpi/shibboleth.png
Binary file not shown.
4 changes: 2 additions & 2 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
<dimen name="long_btn_height">60dp</dimen> <!-- Button -->
<dimen name="long_btn_padding_top">0dp</dimen>
<dimen name="long_btn_padding_bottom">7dp</dimen>
<dimen name="long_btn_margin_left">30dp</dimen>
<dimen name="long_btn_margin_right">30dp</dimen>
<dimen name="long_btn_margin_left">20dp</dimen>
<dimen name="long_btn_margin_right">20dp</dimen>
<dimen name="long_btn_txt_size">18sp</dimen>

<dimen name="btn_height">60dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<string name="open_as">Open as</string>
<string name="select_upload_files">Select files to upload</string>
<string name="storage_removed">Storage was removed</string>
<string name="storage_space_insufficient">Insufficient storage space</string>
<string name="error_selecting_file">Error when selecting file</string>
<plurals name="n_upload_files_selected">
<item quantity="one">%1$d file selected</item>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9cce55b

Please sign in to comment.