Skip to content

Commit

Permalink
Merge pull request #1032 from zhwanng/v3.0.5
Browse files Browse the repository at this point in the history
remove unused import
  • Loading branch information
zhwanng authored Nov 4, 2024
2 parents 83bebbd + 9f736a3 commit 4f39727
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 120 deletions.
11 changes: 5 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
compileSdk rootProject.ext.compileSdkVersion

versionCode 155
versionCode 156
versionName "3.0.5"
multiDexEnabled true

Expand All @@ -32,11 +32,6 @@ android {
}
}

lintOptions {
abortOnError false
disable 'MissingTranslation'
}


compileOptions {
sourceCompatibility JavaVersion.VERSION_17
Expand Down Expand Up @@ -324,5 +319,9 @@ android {


}
lint {
abortOnError false
disable 'MissingTranslation'
}

}
65 changes: 3 additions & 62 deletions app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<ActivityManager.RunningServiceInfo> runningService = (ArrayList<ActivityManager.RunningServiceInfo>) 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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];

Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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();
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -126,12 +133,10 @@ public class SeafileProvider extends DocumentsProvider {
*/
private boolean returnCachedData = false;

private Set<Account> reachableAccounts = new ConcurrentSkipListSet<Account>();
private final Set<Account> reachableAccounts = new ConcurrentSkipListSet<Account>();

private android.accounts.AccountManager androidAccountManager;

public static final Uri NOTIFICATION_URI = DocumentsContract.buildRootsUri(Utils.AUTHORITY_OF_DOCUMENTS);

private final Map<String, RepoModel> REPO_MAP = new HashMap<>();

private RepoModel getRepoModelSync(String repoId) throws FileNotFoundException {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<List<StarredModel>> listSingle = Objs.getStarredSingleFromServer(account);
Expand Down Expand Up @@ -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<List<BaseModel>> resultSingle = Objs.getReposSingleFromServer(account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +92,7 @@ private void openAuthorizePage(String url) {

serverUrl = url;

if (!Utils.isNetworkOn()) {
if (!NetworkUtils.isConnected()) {
ToastUtils.showLong(R.string.network_down);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 4f39727

Please sign in to comment.