Skip to content

Commit

Permalink
Merge pull request #57 from kaczmarkiewiczp/dev
Browse files Browse the repository at this point in the history
Implement Open as and use custom dialogs
  • Loading branch information
patrykcoding authored Apr 25, 2018
2 parents f875a05 + bf88495 commit 566e08d
Show file tree
Hide file tree
Showing 17 changed files with 691 additions and 141 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Credits/Libraries
- [Font Awesome Icons](https://fontawesome.com/) - The iconic SVG, font, and CSS toolkit
- [Markdown View](https://github.com/falnatsheh/MarkdownView) - MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.
- [Material Design Icons](https://github.com/Templarian/MaterialDesign) - 2200+ Material Design Icons from the Community
- [Material Dialogs](https://github.com/afollestad/material-dialogs) - A beautiful, fluid, and customizable dialogs API
- [rclone](https://github.com/ncw/rclone) - "rsync for cloud storage"
- [Toasty](https://github.com/GrenderG/Toasty) - The usual Toast, but with steroids
- Icon made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [Flaticon](https://www.flaticon.com)
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies {
implementation "com.android.support:support-compat:27.1.1"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation "com.leinardi.android:speed-dial:1.0-alpha03"
implementation 'ru.bartwell:exfilepicker:2.4'
implementation "com.mikepenz:aboutlibraries:6.0.8"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ca.pkay.rcloneexplorer;
package ca.pkay.rcloneexplorer.Dialogs;

import android.annotation.SuppressLint;
import android.app.Dialog;
Expand All @@ -10,13 +10,16 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import ca.pkay.rcloneexplorer.Items.FileItem;
import ca.pkay.rcloneexplorer.R;
import ca.pkay.rcloneexplorer.Rclone;
import es.dmoral.toasty.Toasty;

public class FilePropertiesDialog extends DialogFragment {
Expand All @@ -40,8 +43,8 @@ public FilePropertiesDialog() {
public Dialog onCreateDialog(Bundle savedInstanceState) {
asyncTasks = new AsyncTask[2];
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = getActivity().getLayoutInflater();
view = inflater.inflate(R.layout.file_properties_popup, null);
LayoutInflater inflater = ((FragmentActivity)context).getLayoutInflater();
view = inflater.inflate(R.layout.dialog_file_properties, null);

((TextView)view.findViewById(R.id.filename)).setText(fileItem.getName());
((TextView)view.findViewById(R.id.file_modtime)).setText(fileItem.getHumanReadableModTime());
Expand Down
159 changes: 159 additions & 0 deletions app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/InputDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package ca.pkay.rcloneexplorer.Dialogs;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import ca.pkay.rcloneexplorer.R;

public class InputDialog extends DialogFragment {

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

private Context context;
private EditText editText;
private String title;
private int titleId;
private String message;
private int messageId;
private String positiveText;
private int positiveTextId;
private String negativeText;
private int negativeTextId;
private String filledText;
private int inputType;
private OnPositive onPositiveListener;

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = ((FragmentActivity)context).getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_input, null);
editText = view.findViewById(R.id.dialog_input);
builder.setView(view);
if (title != null) {
builder.setTitle(title);
} else if (titleId > 1) {
builder.setTitle(titleId);
}
if (message != null) {
builder.setMessage(message);
} else if (messageId > 1) {
builder.setMessage(messageId);
}
if (positiveText != null) {
builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String input = editText.getText().toString();
onPositiveListener.onPositive(input);
}
});
} else if (positiveTextId > 1) {
builder.setPositiveButton(positiveTextId, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String input = editText.getText().toString();
onPositiveListener.onPositive(input);
}
});
}
if (negativeText != null) {
builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
});
} else if (negativeTextId > 1) {
builder.setNegativeButton(negativeTextId, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
});
}
if (filledText != null) {
editText.setText(filledText, TextView.BufferType.EDITABLE);
editText.setSelection(editText.getText().length());
}
if (inputType > 0) {
editText.setInputType(inputType);
}

return builder.create();
}

public InputDialog setContext(Context context) {
this.context = context;
return this;
}

public InputDialog setFilledText(String text) {
filledText = text;
return this;
}

public InputDialog setInputType(int type) {
inputType = type;
return this;
}

public InputDialog setTitle(String title) {
this.title = title;
return this;
}

public InputDialog setTitle(int id) {
this.titleId = id;
return this;
}

public InputDialog setMessage(String message) {
this.message = message;
return this;
}

public InputDialog setMessage(int id) {
this.messageId = id;
return this;
}

public InputDialog setPositiveButton(String text) {
positiveText = text;
return this;
}

public InputDialog setPositiveButton(int id) {
positiveTextId = id;
return this;
}

public InputDialog setNegativeButton(String text) {
negativeText = text;
return this;
}

public InputDialog setNegativeButton(int id) {
negativeTextId = id;
return this;
}

public InputDialog setOnPositiveListener(OnPositive l) {
onPositiveListener = l;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package ca.pkay.rcloneexplorer.Dialogs;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;

import ca.pkay.rcloneexplorer.R;

public class LoadingDialog extends DialogFragment {

public interface OnNegative {
void onNegative();
}


private Context context;
private OnNegative onNegativeListener;
private Boolean cancelable;
private String title;
private int titleId;
private String negativeText;

public LoadingDialog() {
cancelable = false;
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = ((FragmentActivity)context).getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_loading_indicator, null);
builder.setCancelable(cancelable);
if (title != null) {
builder.setTitle(title);
} else if (titleId > 0) {
builder.setTitle(titleId);
}
if (negativeText != null) {
builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onNegativeListener.onNegative();
}
});
}
builder.setView(view);
return builder.create();
}

public LoadingDialog setContext(Context context) {
this.context = context;
return this;
}

public LoadingDialog setTitle(String title) {
this.title = title;
return this;
}

public LoadingDialog setTitle(int id) {
titleId = id;
return this;
}


public LoadingDialog setNegativeButton(String text) {
negativeText = text;
return this;
}


public LoadingDialog setCanCancel(Boolean cancelable) {
this.cancelable = cancelable;
return this;
}


public LoadingDialog setOnNegativeListener(OnNegative l) {
onNegativeListener = l;
return this;
}
}
78 changes: 78 additions & 0 deletions app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/OpenAsDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ca.pkay.rcloneexplorer.Dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;

import ca.pkay.rcloneexplorer.R;

public class OpenAsDialog extends DialogFragment {

public interface OnClickListener {
void onClickText();
void onClickAudio();
void onClickVideo();
void onClickImage();
}

private Context context;
private View view;
private OnClickListener listener;

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = ((FragmentActivity)context).getLayoutInflater();
view = inflater.inflate(R.layout.dialog_open_as, null);
setListeners();
builder.setView(view);
return builder.create();
}

private void setListeners() {
view.findViewById(R.id.open_as_text).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClickText();
}
});

view.findViewById(R.id.open_as_audio).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClickAudio();
}
});

view.findViewById(R.id.open_as_video).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClickVideo();
}
});

view.findViewById(R.id.open_as_image).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onClickImage();
}
});
}

public OpenAsDialog setOnClickListener(OnClickListener l) {
listener = l;
return this;
}

public OpenAsDialog setContext(Context context) {
this.context = context;
return this;
}
}
Loading

0 comments on commit 566e08d

Please sign in to comment.