Skip to content

Commit

Permalink
Merge pull request #132 from kaczmarkiewiczp/dev
Browse files Browse the repository at this point in the history
Dialog crash fixes
  • Loading branch information
patrykcoding authored Jun 19, 2018
2 parents 1754f48 + 8558ad0 commit 9e4c81a
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 113 deletions.
61 changes: 54 additions & 7 deletions app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/InputDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@
public class InputDialog extends DialogFragment {

public interface OnPositive {
void onPositive(String input);
void onPositive(String tag, String input);
}

private final String SAVED_TITLE = "ca.pkay.rcexplorer.InputDialog.TITLE";
private final String SAVED_TITLE_ID = "ca.pkay.rcexplorer.InputDialog.TITLE_ID";
private final String SAVED_MESSAGE = "ca.pkay.rcexplorer.InputDialog.MESSAGE";
private final String SAVED_MESSAGE_ID = "ca.pkay.rcexplorer.InputDialog.MESSAGE_ID";
private final String SAVED_POSITIVE_TEXT_ID = "ca.pkay.rcexplorer.InputDialog.POSITIVE_TEXT_ID";
private final String SAVED_NEGATIVE_TEXT_ID = "ca.pkay.rcexplorer.InputDialog.NEGATIVE_TEXT_ID";
private final String SAVED_FILLED_TEXT = "ca.pkay.rcexplorer.InputDialog.FILLED_TEXT";
private final String SAVED_INPUT_TYPE = "ca.pkay.rcexplorer.InputDialog.INPUT_TYPE";
private final String SAVED_TAG = "ca.pkay.rcexplorer.InputDialog.TAG";
private final String SAVED_IS_DARK_THEME = "ca.pkay.rcexplorer.InputDialog.IS_DARK_THEME";
private Context context;
private EditText editText;
private String title;
Expand All @@ -32,6 +42,7 @@ public interface OnPositive {
private String filledText;
private int inputType;
private Boolean isDarkTheme;
private String tag;
private OnPositive onPositiveListener;

public InputDialog() {
Expand All @@ -41,6 +52,23 @@ public InputDialog() {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (savedInstanceState != null) {
title = savedInstanceState.getString(SAVED_TITLE);
titleId = savedInstanceState.getInt(SAVED_TITLE_ID);
message = savedInstanceState.getString(SAVED_MESSAGE);
messageId = savedInstanceState.getInt(SAVED_MESSAGE_ID);
positiveTextId = savedInstanceState.getInt(SAVED_POSITIVE_TEXT_ID);
negativeTextId = savedInstanceState.getInt(SAVED_NEGATIVE_TEXT_ID);
filledText = savedInstanceState.getString(SAVED_FILLED_TEXT);
inputType = savedInstanceState.getInt(SAVED_INPUT_TYPE);
tag = savedInstanceState.getString(SAVED_TAG);
isDarkTheme = savedInstanceState.getBoolean(SAVED_IS_DARK_THEME);
}

if (getParentFragment() != null) {
onPositiveListener = (OnPositive) getParentFragment();
}

AlertDialog.Builder builder;

if (isDarkTheme) {
Expand All @@ -67,7 +95,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
@Override
public void onClick(DialogInterface dialog, int which) {
String input = editText.getText().toString();
onPositiveListener.onPositive(input);
onPositiveListener.onPositive(tag, input);
}
});
}
Expand All @@ -90,9 +118,29 @@ public void onClick(DialogInterface dialog, int which) {
return builder.create();
}

public InputDialog setContext(Context context) {
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_TITLE, title);
outState.putInt(SAVED_TITLE_ID, titleId);
outState.putString(SAVED_MESSAGE, message);
outState.putInt(SAVED_MESSAGE_ID, messageId);
outState.putInt(SAVED_POSITIVE_TEXT_ID, positiveTextId);
outState.putInt(SAVED_NEGATIVE_TEXT_ID, negativeTextId);
outState.putString(SAVED_FILLED_TEXT, filledText);
outState.putInt(SAVED_INPUT_TYPE, inputType);
outState.putString(SAVED_TAG, tag);
outState.putBoolean(SAVED_IS_DARK_THEME, isDarkTheme);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
return this;

if (context instanceof OnPositive) {
onPositiveListener = (OnPositive) context;
}
}

public InputDialog setFilledText(String text) {
Expand Down Expand Up @@ -141,9 +189,8 @@ public InputDialog setDarkTheme(Boolean darkTheme) {
return this;
}

public InputDialog setOnPositiveListener(OnPositive l) {
onPositiveListener = l;
public InputDialog setTag(String tag) {
this.tag = tag;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public interface OnNegative {
void onNegative();
}

private final String SAVED_CANCELABLE = "ca.pkay.rcexplorer.LoadingDialog.CANCELABLE";
private final String SAVED_IS_DARK_THEME = "ca.pkay.rcexplorer.LoadingDialog.IS_DARK_THEME";
private final String SAVED_TITLE = "ca.pkay.rcexplorer.LoadingDialog.TITLE";
private final String SAVED_TITLE_ID = "ca.pkay.rcexplorer.LoadingDialog.TITLE_ID";
private final String SAVED_NEGATIVE_TEXT = "ca.pkay.rcexplorer.NEGATIVE_TEXT";
private final String SAVED_NEGATIVE_TEXT_ID = "ca.pkay.rcexplorer.NEGATIVE_TEXT_ID";
private Context context;
private OnNegative onNegativeListener;
private Boolean cancelable;
Expand All @@ -36,6 +42,15 @@ public LoadingDialog() {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (savedInstanceState != null) {
cancelable = savedInstanceState.getBoolean(SAVED_CANCELABLE);
isDarkTheme = savedInstanceState.getBoolean(SAVED_IS_DARK_THEME);
title = savedInstanceState.getString(SAVED_TITLE);
titleId = savedInstanceState.getInt(SAVED_TITLE_ID);
negativeText = savedInstanceState.getString(SAVED_NEGATIVE_TEXT);
negativeTextId = savedInstanceState.getInt(SAVED_NEGATIVE_TEXT_ID);
}

AlertDialog.Builder builder;

if (isDarkTheme) {
Expand Down Expand Up @@ -68,11 +83,23 @@ public void onClick(DialogInterface dialog, int which) {
}
builder.setView(view);
return builder.create();
}
}

public LoadingDialog setContext(Context context) {
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(SAVED_CANCELABLE, cancelable);
outState.putBoolean(SAVED_IS_DARK_THEME, isDarkTheme);
outState.putString(SAVED_TITLE, title);
outState.putInt(SAVED_TITLE_ID, titleId);
outState.putString(SAVED_NEGATIVE_TEXT, negativeText);
outState.putInt(SAVED_NEGATIVE_TEXT_ID, negativeTextId);
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
return this;
}

public LoadingDialog setTitle(String title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
import ca.pkay.rcloneexplorer.Items.DirectoryObject;
import ca.pkay.rcloneexplorer.Items.FileItem;
import ca.pkay.rcloneexplorer.Items.RemoteItem;
import ca.pkay.rcloneexplorer.MainActivity;
import ca.pkay.rcloneexplorer.R;
import ca.pkay.rcloneexplorer.Rclone;
import ca.pkay.rcloneexplorer.RecyclerViewAdapters.FileExplorerRecyclerViewAdapter;
import es.dmoral.toasty.Toasty;
import jp.wasabeef.recyclerview.animators.LandingAnimator;

public class RemoteDestinationDialog extends DialogFragment implements SwipeRefreshLayout.OnRefreshListener,
FileExplorerRecyclerViewAdapter.OnClickListener {
FileExplorerRecyclerViewAdapter.OnClickListener,
InputDialog.OnPositive {

public interface OnDestinationSelectedListener {
void onDestinationSelected(String path);
Expand Down Expand Up @@ -237,31 +237,32 @@ public void onFileOptionsClicked(View view, FileItem fileItem) {
private void onCreateNewDirectory() {
if (getFragmentManager() != null) {
new InputDialog()
.setContext(context)
.setTitle(R.string.create_new_folder)
.setMessage(R.string.type_new_folder_name)
.setNegativeButton(R.string.cancel)
.setPositiveButton(R.string.okay_confirmation)
.setDarkTheme(isDarkTheme)
.setOnPositiveListener(new InputDialog.OnPositive() {
@Override
public void onPositive(String input) {
if (input.trim().length() == 0) {
return;
}
String newDir;
if (directoryObject.getCurrentPath().equals("//" + remote.getName())) {
newDir = input;
} else {
newDir = directoryObject.getCurrentPath() + "/" + input;
}
newDirTask = new MakeDirectoryTask().execute(newDir);
}
})
.show(getFragmentManager(), "input dialog");
.show(getChildFragmentManager(), "input dialog");
}
}

/*
* Input Dialog callback
*/
@Override
public void onPositive(String tag, String input) {
if (input.trim().length() == 0) {
return;
}
String newDir;
if (directoryObject.getCurrentPath().equals("//" + remote.getName())) {
newDir = input;
} else {
newDir = directoryObject.getCurrentPath() + "/" + input;
}
newDirTask = new MakeDirectoryTask().execute(newDir);
}

private void goUp() {
if (pathStack.isEmpty()) {
dismiss();
Expand Down
Loading

0 comments on commit 9e4c81a

Please sign in to comment.