-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from kaczmarkiewiczp/dev
Implement Open as and use custom dialogs
- Loading branch information
Showing
17 changed files
with
691 additions
and
141 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/InputDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/LoadingDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
78
app/src/main/java/ca/pkay/rcloneexplorer/Dialogs/OpenAsDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.