diff --git a/app/build.gradle b/app/build.gradle index 65365a20c..bfc791ad8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { targetSdkVersion rootProject.ext.targetSdkVersion compileSdk rootProject.ext.compileSdkVersion - versionCode 155 + versionCode 156 versionName "3.0.5" multiDexEnabled true @@ -32,11 +32,6 @@ android { } } - lintOptions { - abortOnError false - disable 'MissingTranslation' - } - compileOptions { sourceCompatibility JavaVersion.VERSION_17 @@ -324,5 +319,9 @@ android { } + lint { + abortOnError false + disable 'MissingTranslation' + } } diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java b/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java index 1339a861f..c4b6341a8 100644 --- a/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java +++ b/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java @@ -1,14 +1,10 @@ package com.seafile.seadroid2.framework.util; import android.app.Activity; -import android.app.ActivityManager; import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.graphics.BitmapFactory; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.NetworkInfo.DetailedState; import android.net.Uri; import android.net.http.SslCertificate; import android.os.Build; @@ -43,7 +39,6 @@ import java.security.cert.X509Certificate; import java.text.DecimalFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -52,8 +47,7 @@ public class Utils { public static final String MIME_APPLICATION_OCTET_STREAM = "application/octet-stream"; public static final String AUTHORITY = BuildConfig.APPLICATION_ID; - public static final String AUTHORITY_OF_DOCUMENTS = BuildConfig.APPLICATION_ID + ".documents"; - public static final String PATH_SEPERATOR = "/"; + // public static final String NOGROUP = "$nogroup"; public static final String PERSONAL_REPO = "personal_repo"; public static final String SHARED_REPO = "shared_repo"; @@ -168,33 +162,6 @@ public static boolean isTextFile(File file) { return false; } - public static boolean isNetworkOn() { - ConnectivityManager connMgr = (ConnectivityManager) SeadroidApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); - if (networkInfo == null) { - return false; - } - 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; - } - - public static boolean isWiFiOn() { - 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; - } - return false; - } - public static String pathJoin(String first, String... rest) { StringBuilder result = new StringBuilder(first); for (String b : rest) { @@ -213,7 +180,7 @@ public static String pathJoin(String first, String... rest) { return result.toString(); } - public static String removeLastPathSeperator(String path) { + public static String removeLastPathSeparator(String path) { if (TextUtils.isEmpty(path)) return null; int size = path.length(); @@ -269,17 +236,6 @@ public static String translateCommitTime(long timestampInMillis) { } } - /** - * Translate create time - */ - public static String translateTime() { - long now = System.currentTimeMillis(); - Date d = new Date(now); - SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); - return fmt.format(d); - } - - public static long now() { return System.currentTimeMillis(); } @@ -545,22 +501,7 @@ public static void hideSystemNavigationBar(Activity activity) { } - public static boolean isServiceRunning(Context context, String ServiceName) { - if (TextUtils.isEmpty(ServiceName)) { - return false; - } - ActivityManager myManager = (ActivityManager) context - .getSystemService(Context.ACTIVITY_SERVICE); - ArrayList runningService = (ArrayList) myManager - .getRunningServices(30); - for (int i = 0; i < runningService.size(); i++) { - if (runningService.get(i).service.getClassName().toString() - .equals(ServiceName)) { - return true; - } - } - return false; - } + public static void startCameraSyncJob(Context context) { // JobScheduler mJobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); diff --git a/app/src/main/java/com/seafile/seadroid2/provider/DocumentIdParser.java b/app/src/main/java/com/seafile/seadroid2/provider/DocumentIdParser.java index d713e4030..6dc3fa130 100644 --- a/app/src/main/java/com/seafile/seadroid2/provider/DocumentIdParser.java +++ b/app/src/main/java/com/seafile/seadroid2/provider/DocumentIdParser.java @@ -17,11 +17,8 @@ package com.seafile.seadroid2.provider; -import android.content.Context; - import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.account.SupportAccountManager; -import com.seafile.seadroid2.framework.util.Utils; import java.io.FileNotFoundException; import java.util.List; @@ -40,7 +37,7 @@ public class DocumentIdParser { /** used to separate serverName, RepoId and Path. */ - private static final String DOC_SEPERATOR = "::::"; + private static final String DOC_SEPARATOR = "::::"; private static final String STARRED_FILE_REPO_ID = "starred-file-magic-repo"; private static final String ROOT_REPO_ID = "root-magic-repo"; @@ -52,7 +49,7 @@ public class DocumentIdParser { * @throws java.io.FileNotFoundException if the documentId is bogus or the account doesn't exist */ public static Account getAccountFromId(String documentId) throws FileNotFoundException { - String[] list = documentId.split(DOC_SEPERATOR, 2); + String[] list = documentId.split(DOC_SEPARATOR, 2); if (list.length > 0) { String server = list[0]; @@ -74,7 +71,7 @@ public static Account getAccountFromId(String documentId) throws FileNotFoundExc * @return the repoId, might be empty string (if documentId isn't containing one) */ public static String getRepoIdFromId(String documentId) { - String[] list = documentId.split(DOC_SEPERATOR, 3); + String[] list = documentId.split(DOC_SEPARATOR, 3); if (list.length>1) { String repoId = list[1]; return repoId; @@ -92,13 +89,13 @@ public static String getRepoIdFromId(String documentId) { * @return a file path */ public static String getPathFromId(String documentId) { - String[] list = documentId.split(DOC_SEPERATOR, 3); + String[] list = documentId.split(DOC_SEPARATOR, 3); if (list.length > 2) { String path = list[2]; if (path.length() > 0) return path; } - return Utils.PATH_SEPERATOR; + return SeafileProvider.PATH_SEPARATOR; } /** @@ -111,9 +108,9 @@ public static String getPathFromId(String documentId) { */ public static String buildId(Account a, String repoId, String path) { if (repoId != null && path != null) - return a.getSignature() + DOC_SEPERATOR + repoId + DOC_SEPERATOR + path; + return a.getSignature() + DOC_SEPARATOR + repoId + DOC_SEPARATOR + path; else if (repoId != null) - return a.getSignature() + DOC_SEPERATOR + repoId; + return a.getSignature() + DOC_SEPARATOR + repoId; else return a.getSignature(); } @@ -125,11 +122,11 @@ else if (repoId != null) * @returns a documentId */ public static String buildRootId(Account a) { - return a.getSignature() + DOC_SEPERATOR + ROOT_REPO_ID; + return a.getSignature() + DOC_SEPARATOR + ROOT_REPO_ID; } public static String buildStarredFilesId(Account a) { - return a.getSignature() + DOC_SEPERATOR + STARRED_FILE_REPO_ID; + return a.getSignature() + DOC_SEPARATOR + STARRED_FILE_REPO_ID; } public static boolean isRoot(String documentId) { diff --git a/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java b/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java index 275cac4d9..afcccb1be 100644 --- a/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java +++ b/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java @@ -40,8 +40,10 @@ import android.util.Log; import com.blankj.utilcode.util.CollectionUtils; +import com.blankj.utilcode.util.NetworkUtils; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.request.RequestOptions; +import com.seafile.seadroid2.BuildConfig; import com.seafile.seadroid2.R; import com.seafile.seadroid2.SeadroidApplication; import com.seafile.seadroid2.account.Account; @@ -101,6 +103,11 @@ public class SeafileProvider extends DocumentsProvider { public static final String DEBUG_TAG = "SeafileProvider"; + public static final String PATH_SEPARATOR = "/"; + public static final String AUTHORITY_OF_DOCUMENTS = BuildConfig.APPLICATION_ID + ".documents"; + + public static final Uri NOTIFICATION_URI = DocumentsContract.buildRootsUri(AUTHORITY_OF_DOCUMENTS); + private static final String[] SUPPORTED_ROOT_PROJECTION = new String[]{ Root.COLUMN_ROOT_ID, Root.COLUMN_FLAGS, @@ -126,12 +133,10 @@ public class SeafileProvider extends DocumentsProvider { */ private boolean returnCachedData = false; - private Set reachableAccounts = new ConcurrentSkipListSet(); + private final Set reachableAccounts = new ConcurrentSkipListSet(); private android.accounts.AccountManager androidAccountManager; - public static final Uri NOTIFICATION_URI = DocumentsContract.buildRootsUri(Utils.AUTHORITY_OF_DOCUMENTS); - private final Map REPO_MAP = new HashMap<>(); private RepoModel getRepoModelSync(String repoId) throws FileNotFoundException { @@ -346,7 +351,7 @@ public Cursor queryDocument(String documentId, String[] projection) throws FileN if (DocumentIdParser.isStarredFiles(documentId)) { includeStarredFilesRepo(result, account); - } else if (path.equals(Utils.PATH_SEPERATOR)) { + } else if (path.equals(PATH_SEPARATOR)) { // this is the base of the repository. this is special, as we give back the information // about the repository itself, not some directory in it. includeRepo(result, account, repoModel); @@ -435,9 +440,9 @@ public ParcelFileDescriptor openDocument(final String documentId, final String m } //local don't exists - - if (!Utils.isNetworkOn()) + if (!NetworkUtils.isConnected()) { throw new FileNotFoundException(); + } // open the file. this might involve talking to the seafile server. this will hang until // it is done. @@ -915,7 +920,7 @@ private void includeStarredFileDirent(MatrixCursor result, Account account, Star private void fetchDirentAsync(Account account, RepoModel repoModel, final String path, MatrixCursor result) { String id = DocumentIdParser.buildId(account, repoModel.repo_id, path); - final Uri uri = DocumentsContract.buildChildDocumentsUri(Utils.AUTHORITY_OF_DOCUMENTS, id); + final Uri uri = DocumentsContract.buildChildDocumentsUri(AUTHORITY_OF_DOCUMENTS, id); result.setNotificationUri(getContext().getContentResolver(), uri); @@ -952,7 +957,7 @@ public void accept(Throwable throwable) throws Exception { private void fetchStarredAsync(Account account, MatrixCursor result) { String id = DocumentIdParser.buildStarredFilesId(account); - final Uri uri = DocumentsContract.buildChildDocumentsUri(Utils.AUTHORITY_OF_DOCUMENTS, id); + final Uri uri = DocumentsContract.buildChildDocumentsUri(AUTHORITY_OF_DOCUMENTS, id); result.setNotificationUri(getContext().getContentResolver(), uri); Single> listSingle = Objs.getStarredSingleFromServer(account); @@ -989,7 +994,7 @@ public void accept(Throwable throwable) throws Exception { */ private void fetchReposAsync(Account account, MatrixCursor result) { String id = DocumentIdParser.buildId(account, null, null); - final Uri uri = DocumentsContract.buildChildDocumentsUri(Utils.AUTHORITY_OF_DOCUMENTS, id); + final Uri uri = DocumentsContract.buildChildDocumentsUri(AUTHORITY_OF_DOCUMENTS, id); result.setNotificationUri(getContext().getContentResolver(), uri); Single> resultSingle = Objs.getReposSingleFromServer(account); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnActivity.java index 0ff14c42c..182b2ccaa 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnActivity.java @@ -12,6 +12,7 @@ import android.widget.Button; import android.widget.EditText; +import com.blankj.utilcode.util.NetworkUtils; import com.blankj.utilcode.util.RegexUtils; import com.blankj.utilcode.util.ToastUtils; import com.seafile.seadroid2.R; @@ -101,11 +102,15 @@ private boolean isServerUrlValid(String serverUrl) { } private String getServerUrl() { - String serverUrl = mServerUrlEt.getText().toString().trim(); - return serverUrl; + return mServerUrlEt.getText().toString().trim(); } private void openAuthorizePage(String serverUrl) { + if (!NetworkUtils.isConnected()) { + ToastUtils.showLong(R.string.network_down); + return; + } + Intent intent = new Intent(this, SingleSignOnAuthorizeActivity.class); intent.putExtra(SeafileAuthenticatorActivity.SINGLE_SIGN_ON_SERVER_URL, serverUrl); intent.putExtras(getIntent()); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnAuthorizeActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnAuthorizeActivity.java index 5801c7c20..1820a3298 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnAuthorizeActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/account/SingleSignOnAuthorizeActivity.java @@ -24,6 +24,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.lifecycle.Observer; +import com.blankj.utilcode.util.NetworkUtils; import com.blankj.utilcode.util.ToastUtils; import com.seafile.seadroid2.R; import com.seafile.seadroid2.SeadroidApplication; @@ -91,7 +92,7 @@ private void openAuthorizePage(String url) { serverUrl = url; - if (!Utils.isNetworkOn()) { + if (!NetworkUtils.isConnected()) { ToastUtils.showLong(R.string.network_down); return; } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/dialog/SslConfirmDialog.java b/app/src/main/java/com/seafile/seadroid2/ui/dialog/SslConfirmDialog.java index fc1e7ea64..747149ce7 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/dialog/SslConfirmDialog.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/dialog/SslConfirmDialog.java @@ -1,27 +1,14 @@ package com.seafile.seadroid2.ui.dialog; import android.annotation.SuppressLint; - -import androidx.appcompat.app.AlertDialog; - import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; +import android.util.Log; import androidx.fragment.app.DialogFragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.google.android.gms.common.internal.Objects; import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import com.google.common.base.Preconditions; -import com.google.common.cache.CacheBuilder; -import com.google.common.collect.Collections2; -import com.google.common.collect.ComparisonChain; -import com.google.common.collect.Ordering; import com.seafile.seadroid2.R; import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.databinding.DialogSslConfirmBinding; diff --git a/app/src/main/java/com/seafile/seadroid2/ui/dialog_fragment/CopyMoveDialogFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/dialog_fragment/CopyMoveDialogFragment.java index ae5bc30f0..46e3d8156 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/dialog_fragment/CopyMoveDialogFragment.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/dialog_fragment/CopyMoveDialogFragment.java @@ -61,10 +61,10 @@ protected void initView(LinearLayout containerView) { String strMsg = getString(strMsgId); String srcDir = Utils.pathJoin(ctx.srcRepoName, ctx.srcDir); - String srcDirPath = Utils.removeLastPathSeperator(srcDir); + String srcDirPath = Utils.removeLastPathSeparator(srcDir); String dstPath = Utils.pathJoin(ctx.dstRepoName, ctx.dstDir); - String dstDirPath = Utils.removeLastPathSeperator(dstPath); + String dstDirPath = Utils.removeLastPathSeparator(dstPath); //set message TextView tvMessage = containerView.findViewById(R.id.message_view); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview/ImagePreviewActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview/ImagePreviewActivity.java index c12b09d83..48394b47b 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview/ImagePreviewActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/media/image_preview/ImagePreviewActivity.java @@ -21,6 +21,7 @@ import com.blankj.utilcode.util.BarUtils; import com.blankj.utilcode.util.CollectionUtils; +import com.blankj.utilcode.util.NetworkUtils; import com.blankj.utilcode.util.ToastUtils; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.seafile.seadroid2.R; @@ -288,7 +289,7 @@ public void onActionStatus(boolean isDone) { } private void starFile() { - if (!Utils.isNetworkOn()) { + if (!NetworkUtils.isConnected()) { ToastUtils.showLong(R.string.network_down); return; } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/sdoc/SDocWebViewActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/sdoc/SDocWebViewActivity.java index 2a1d4f43b..39cf80e1e 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/sdoc/SDocWebViewActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/sdoc/SDocWebViewActivity.java @@ -2,10 +2,8 @@ import android.content.Context; import android.content.Intent; - import android.content.res.Configuration; import android.os.Bundle; - import android.text.TextUtils; import android.view.View; import android.webkit.ValueCallback; @@ -24,7 +22,6 @@ import com.blankj.utilcode.util.ActivityUtils; import com.blankj.utilcode.util.GsonUtils; import com.blankj.utilcode.util.ToastUtils; -import com.google.android.gms.tasks.Continuation; import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.account.SupportAccountManager; import com.seafile.seadroid2.annotation.Unstable; @@ -44,11 +41,6 @@ import com.seafile.seadroid2.view.webview.PreloadWebView; import com.seafile.seadroid2.view.webview.SeaWebView; -import org.json.JSONException; -import org.json.JSONObject; - -import kotlin.Pair; - @Unstable public class SDocWebViewActivity extends BaseActivityWithVM { private ActivitySeaWebviewProBinding binding; @@ -61,6 +53,9 @@ public class SDocWebViewActivity extends BaseActivityWithVM { private SDocProfileConfigModel configModel; + /** + * not support, please use SeaWebViewActivity instead + */ public static void openSdoc(Context context, String repoName, String repoID, String path) { Intent intent = new Intent(context, SeaWebViewActivity.class); intent.putExtra("previewType", WebViewPreviewType.SDOC.name()); diff --git a/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java b/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java index e6e9d330d..54ed1a95d 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java @@ -26,6 +26,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.blankj.utilcode.util.CollectionUtils; +import com.blankj.utilcode.util.NetworkUtils; import com.blankj.utilcode.util.ToastUtils; import com.chad.library.adapter4.BaseQuickAdapter; import com.chad.library.adapter4.QuickAdapterHelper; @@ -320,7 +321,7 @@ public boolean onOptionsItemSelected(MenuItem item) { private String lastQuery = null; private void loadNext(String query, boolean isRefresh) { - if (!Utils.isNetworkOn()) { + if (!NetworkUtils.isConnected()) { ToastUtils.showLong(R.string.network_down); return; } diff --git a/app/src/main/res/layout/single_sign_on_welcome_layout.xml b/app/src/main/res/layout/single_sign_on_welcome_layout.xml index a22dd2bba..f5e9c7790 100644 --- a/app/src/main/res/layout/single_sign_on_welcome_layout.xml +++ b/app/src/main/res/layout/single_sign_on_welcome_layout.xml @@ -32,7 +32,7 @@ android:orientation="horizontal" android:paddingBottom="10dp"> -