Skip to content

Commit

Permalink
Merge pull request #1931 from TeamAmaze/TranceLove/bugfix/1920
Browse files Browse the repository at this point in the history
Display snackbar when there is no network connectivity
  • Loading branch information
VishalNehra authored Jul 16, 2020
2 parents 3f0c5cc + 162b7d6 commit b590f3a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 22 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ dependencies {
androidTestImplementation 'junit:junit:4.12'//tests the app logic
testImplementation 'junit:junit:4.12'//tests the app logic
testImplementation "org.robolectric:robolectric:$robolectricVersion"//tests android interaction
testImplementation "org.robolectric:shadows-multidex:$robolectricVersion"//tests android interaction
testImplementation "org.robolectric:shadows-httpclient:$robolectricVersion"//tests android interaction

testImplementation "org.apache.sshd:sshd-core:1.7.0"
Expand Down
38 changes: 18 additions & 20 deletions app/src/main/java/com/amaze/filemanager/filesystem/PasteHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,24 @@ private void dismissSnackbar(boolean shouldClearPasteData) {

private void showSnackbar() {
snackbar =
Snackbar.make(
mainActivity.findViewById(R.id.content_frame),
getSnackbarContent(),
BaseTransientBottomBar.LENGTH_INDEFINITE)
.setAction(
R.string.paste,
v -> {
String path = mainActivity.getCurrentMainFragment().getCurrentPath();
ArrayList<HybridFileParcelable> arrayList = new ArrayList<>(Arrays.asList(paths));
boolean move = operation == PasteHelper.OPERATION_CUT;
new PrepareCopyTask(
mainActivity.getCurrentMainFragment(),
path,
move,
mainActivity,
mainActivity.isRootExplorer())
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
dismissSnackbar(true);
});
snackbar.show();
Utils.showThemedSnackbar(
mainActivity,
getSnackbarContent(),
BaseTransientBottomBar.LENGTH_INDEFINITE,
R.string.paste,
() -> {
String path = mainActivity.getCurrentMainFragment().getCurrentPath();
ArrayList<HybridFileParcelable> arrayList = new ArrayList<>(Arrays.asList(paths));
boolean move = operation == PasteHelper.OPERATION_CUT;
new PrepareCopyTask(
mainActivity.getCurrentMainFragment(),
path,
move,
mainActivity,
mainActivity.isRootExplorer())
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
dismissSnackbar(true);
});
Utils.invalidateFab(mainActivity, () -> dismissSnackbar(true), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.amaze.filemanager.ui.fragments;

import static android.provider.Settings.ACTION_WIFI_SETTINGS;
import static com.amaze.filemanager.asynchronous.services.ftp.FtpService.FtpReceiverActions.STARTED_FROM_TILE;

import java.io.IOException;
Expand All @@ -39,6 +40,8 @@
import com.amaze.filemanager.ui.notifications.FtpNotification;
import com.amaze.filemanager.utils.OneCharacterCharSequence;
import com.amaze.filemanager.utils.Utils;
import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;

import android.content.BroadcastReceiver;
Expand Down Expand Up @@ -90,6 +93,7 @@ public class FtpServerFragment extends Fragment {
private Spanned spannedStatusNoConnection, spannedStatusConnected, spannedStatusUrl;
private Spanned spannedStatusSecure, spannedStatusNotRunning;
private ImageButton ftpPasswordVisibleButton;
private Snackbar snackbar;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -317,13 +321,15 @@ public void onReceive(Context context, Intent intent) {
|| FtpService.isEnabledWifiHotspot(getContext())) {
// connected to Wi-Fi or eth
ftpBtn.setEnabled(true);
dismissSnackbar();
} else {
// Wi-Fi or eth connection lost
stopServer();
statusText.setText(spannedStatusNoConnection);
ftpBtn.setEnabled(true);
ftpBtn.setEnabled(false);
ftpBtn.setText(getResources().getString(R.string.start_ftp).toUpperCase());
promptUserToEnableWireless(netInfo);
}
}
};
Expand Down Expand Up @@ -390,6 +396,7 @@ public void onPause() {
super.onPause();
getContext().unregisterReceiver(mWifiReceiver);
EventBus.getDefault().unregister(this);
dismissSnackbar();
}

/** Update UI widgets after change in shared preferences */
Expand Down Expand Up @@ -656,4 +663,25 @@ private void setSecurePreference(boolean isSecureEnabled) {
.putBoolean(FtpService.KEY_PREFERENCE_SECURE, isSecureEnabled)
.apply();
}

private void promptUserToEnableWireless(@Nullable NetworkInfo ni) {
// No wifi, no data, no connection at all
if (ni == null || !ni.isConnected()) {
snackbar =
Utils.showThemedSnackbar(
(MainActivity) getActivity(),
getString(R.string.ftp_server_prompt_connect_to_network),
BaseTransientBottomBar.LENGTH_INDEFINITE,
R.string.ftp_server_open_settings,
() -> startActivity(new Intent(ACTION_WIFI_SETTINGS)));
snackbar.show();
}
}

private void dismissSnackbar() {
if (snackbar != null) {
snackbar.dismiss();
snackbar = null;
}
}
}
21 changes: 21 additions & 0 deletions app/src/main/java/com/amaze/filemanager/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.amaze.filemanager.R;
import com.amaze.filemanager.filesystem.HybridFileParcelable;
import com.amaze.filemanager.ui.activities.MainActivity;
import com.amaze.filemanager.ui.theme.AppTheme;
import com.google.android.material.snackbar.Snackbar;
import com.leinardi.android.speeddial.SpeedDialView;
import com.leinardi.android.speeddial.UiUtils;

Expand Down Expand Up @@ -329,4 +331,23 @@ public void onToggleChanged(boolean isOpen) {
mainActivity.getFAB().setOnChangeListener(null);
}
}

public static Snackbar showThemedSnackbar(
MainActivity mainActivity,
CharSequence text,
int length,
int actionTextId,
Runnable actionCallback) {
Snackbar snackbar =
Snackbar.make(mainActivity.findViewById(R.id.content_frame), text, length)
.setAction(actionTextId, v -> actionCallback.run());
if (mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
snackbar
.getView()
.setBackgroundColor(mainActivity.getResources().getColor(android.R.color.white));
snackbar.setTextColor(mainActivity.getResources().getColor(android.R.color.black));
}
snackbar.show();
return snackbar;
}
}
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_ftp.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ftpserver_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@
<string name="choose_folder">Choose This Folder</string>
<string name="folder_go_up_one_level" translatable="false">..</string>
<string name="some_files_failed_invalid_operation">Some files failed due to invalid operation</string>
<string name="ftp_server_prompt_connect_to_network">Connect to a network or enable AP</string>
<string name="ftp_server_open_settings">Open settings</string>
<string name="move">Move</string>
</resources>

0 comments on commit b590f3a

Please sign in to comment.