mirror of
https://github.com/nextcloud/android.git
synced 2024-12-21 08:24:08 +03:00
Check network connection when file item clicked
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
4f23372d67
commit
bfccb3bd38
5 changed files with 69 additions and 33 deletions
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Alper Ozturk
|
||||
* Copyright (C) 2023 Alper Ozturk
|
||||
* Copyright (C) 2023 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.client.network
|
||||
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
|
||||
object ConnectivityObserver {
|
||||
|
||||
fun isConnected(context: Context): Boolean {
|
||||
val connectivityManager: ConnectivityManager =
|
||||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
val nw = connectivityManager.activeNetwork
|
||||
val actNw = connectivityManager.getNetworkCapabilities(nw) ?: return false
|
||||
|
||||
return when {
|
||||
actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
|
||||
actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
|
||||
actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
|
||||
actNw.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH) -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ import com.google.android.material.snackbar.Snackbar;
|
|||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager;
|
||||
import com.nextcloud.client.network.ConnectivityObserver;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.utils.EditorUtils;
|
||||
import com.owncloud.android.MainApp;
|
||||
|
@ -240,6 +241,12 @@ public abstract class FileActivity extends DrawerActivity
|
|||
}
|
||||
}
|
||||
|
||||
public void checkInternetConnection() {
|
||||
if (ConnectivityObserver.INSTANCE.isConnected(this)) {
|
||||
hideInfoBox();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
|
|
@ -1273,29 +1273,26 @@ public class FileDisplayActivity extends FileActivity
|
|||
|
||||
String synchFolderRemotePath =
|
||||
intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
|
||||
RemoteOperationResult synchResult = (RemoteOperationResult)
|
||||
RemoteOperationResult syncResult = (RemoteOperationResult)
|
||||
DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
|
||||
boolean sameAccount = getAccount() != null &&
|
||||
accountName.equals(getAccount().name) && getStorageManager() != null;
|
||||
|
||||
if (sameAccount) {
|
||||
|
||||
if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
|
||||
mSyncInProgress = true;
|
||||
|
||||
} else {
|
||||
OCFile currentFile = (getFile() == null) ? null :
|
||||
getStorageManager().getFileByPath(getFile().getRemotePath());
|
||||
getStorageManager().getFileByEncryptedRemotePath(getFile().getRemotePath());
|
||||
OCFile currentDir = (getCurrentDir() == null) ? null :
|
||||
getStorageManager().getFileByPath(getCurrentDir().getRemotePath());
|
||||
getStorageManager().getFileByEncryptedRemotePath(getCurrentDir().getRemotePath());
|
||||
|
||||
if (currentDir == null) {
|
||||
// current folder was removed from the server
|
||||
DisplayUtils.showSnackMessage(
|
||||
getActivity(),
|
||||
R.string.sync_current_folder_was_removed,
|
||||
synchFolderRemotePath
|
||||
);
|
||||
synchFolderRemotePath);
|
||||
|
||||
browseToRoot();
|
||||
|
||||
|
@ -1320,35 +1317,21 @@ public class FileDisplayActivity extends FileActivity
|
|||
!RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event);
|
||||
|
||||
if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.equals(event) &&
|
||||
synchResult != null) {
|
||||
syncResult != null) {
|
||||
|
||||
if (synchResult.isSuccess()) {
|
||||
if (syncResult.isSuccess()) {
|
||||
hideInfoBox();
|
||||
} else {
|
||||
// TODO refactor and make common
|
||||
if (checkForRemoteOperationError(synchResult)) {
|
||||
if (checkForRemoteOperationError(syncResult)) {
|
||||
requestCredentialsUpdate(context);
|
||||
} else {
|
||||
switch (synchResult.getCode()) {
|
||||
case SSL_RECOVERABLE_PEER_UNVERIFIED:
|
||||
showUntrustedCertDialog(synchResult);
|
||||
break;
|
||||
|
||||
case MAINTENANCE_MODE:
|
||||
showInfoBox(R.string.maintenance_mode);
|
||||
break;
|
||||
|
||||
case NO_NETWORK_CONNECTION:
|
||||
showInfoBox(R.string.offline_mode);
|
||||
break;
|
||||
|
||||
case HOST_NOT_AVAILABLE:
|
||||
showInfoBox(R.string.host_not_available);
|
||||
break;
|
||||
|
||||
default:
|
||||
// nothing to do
|
||||
break;
|
||||
switch (syncResult.getCode()) {
|
||||
case SSL_RECOVERABLE_PEER_UNVERIFIED -> showUntrustedCertDialog(syncResult);
|
||||
case MAINTENANCE_MODE -> showInfoBox(R.string.maintenance_mode);
|
||||
case NO_NETWORK_CONNECTION -> showInfoBox(R.string.offline_mode);
|
||||
case HOST_NOT_AVAILABLE -> showInfoBox(R.string.host_not_available);
|
||||
default -> hideInfoBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1374,8 +1357,8 @@ public class FileDisplayActivity extends FileActivity
|
|||
}
|
||||
}
|
||||
|
||||
if (synchResult != null && synchResult.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {
|
||||
mLastSslUntrustedServerResult = synchResult;
|
||||
if (syncResult != null && syncResult.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {
|
||||
mLastSslUntrustedServerResult = syncResult;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
// avoid app crashes after changing the serial id of RemoteOperationResult
|
||||
|
|
|
@ -219,7 +219,6 @@ public abstract class ToolbarActivity extends BaseActivity implements Injectable
|
|||
/**
|
||||
* Hides the toolbar's info box.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public final void hideInfoBox() {
|
||||
mInfoBox.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ import com.nextcloud.client.documentscan.DocumentScanActivity;
|
|||
import com.nextcloud.client.editimage.EditImageActivity;
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.network.ConnectivityObserver;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.utils.Throttler;
|
||||
import com.nextcloud.common.NextcloudClient;
|
||||
|
@ -976,6 +977,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
|
||||
@Override
|
||||
public void onItemClicked(OCFile file) {
|
||||
((FileActivity) mContainerActivity).checkInternetConnection();
|
||||
|
||||
if (getCommonAdapter().isMultiSelect()) {
|
||||
toggleItemToCheckedList(file);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue