mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 07:30:13 -04:00
DynamicDialogFragment can now have 1 to 3 buttons - to be tested
This commit is contained in:
@@ -90,9 +90,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// Set the arguments
|
// Set the arguments
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putBoolean("neutral", false);
|
args.putInt("button_count", 1);
|
||||||
args.putString("button_positive", getString(R.string.new_task_save));
|
args.putString("button_negative", getString(R.string.task_list_ok));
|
||||||
args.putString("button_negative", getString(R.string.new_task_cancel));
|
|
||||||
taskListFragment.setArguments(args);
|
taskListFragment.setArguments(args);
|
||||||
|
|
||||||
if (getResources().getBoolean(R.bool.large_layout))
|
if (getResources().getBoolean(R.bool.large_layout))
|
||||||
@@ -143,7 +142,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt("list", currentTabPosition);
|
args.putInt("list", currentTabPosition);
|
||||||
args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false));
|
args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false));
|
||||||
args.putBoolean("neutral", false);
|
args.putInt("button_count", 2);
|
||||||
args.putString("button_positive", getString(R.string.new_task_save));
|
args.putString("button_positive", getString(R.string.new_task_save));
|
||||||
args.putString("button_negative", getString(R.string.new_task_cancel));
|
args.putString("button_negative", getString(R.string.new_task_cancel));
|
||||||
args.putString("button_neutral", getString(R.string.new_task_delete));
|
args.putString("button_neutral", getString(R.string.new_task_delete));
|
||||||
|
@@ -30,16 +30,17 @@ import com.wismna.geoffroy.donext.R;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class DynamicDialogFragment extends DialogFragment {
|
public abstract class DynamicDialogFragment extends DialogFragment {
|
||||||
boolean mHasNeutralButton = false;
|
int mButtonCount = 2;
|
||||||
int mContentLayoutId = 0;
|
int mContentLayoutId = 0;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
// This part is only needed on small layouts (large layouts use onCreateDialog)
|
// This part is only needed on small layouts (large layouts use onCreateDialog)
|
||||||
if (!getShowsDialog()) {
|
if (!getShowsDialog()) {
|
||||||
View view = inflater.inflate(R.layout.fragment_dynamic_dialog, container, false);
|
View view = inflater.inflate(R.layout.fragment_dynamic_dialog, container, false);
|
||||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||||
|
assert activity != null;
|
||||||
activity.setSupportActionBar(setToolbarTitle(view));
|
activity.setSupportActionBar(setToolbarTitle(view));
|
||||||
|
|
||||||
ActionBar actionBar = activity.getSupportActionBar();
|
ActionBar actionBar = activity.getSupportActionBar();
|
||||||
@@ -66,13 +67,9 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
// Set the dialog buttons
|
// Set the dialog buttons
|
||||||
|
assert args != null;
|
||||||
|
// Add action buttons
|
||||||
builder.setView(view)
|
builder.setView(view)
|
||||||
// Add action buttons
|
|
||||||
.setPositiveButton(args.getString("button_positive"), new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
onPositiveButtonClick(view);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(args.getString("button_negative"), new DialogInterface.OnClickListener() {
|
.setNegativeButton(args.getString("button_negative"), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
// Send the negative button event back to the host activity
|
// Send the negative button event back to the host activity
|
||||||
@@ -81,7 +78,14 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
onNegativeButtonClick();
|
onNegativeButtonClick();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (mHasNeutralButton) {
|
if (mButtonCount == 2) {
|
||||||
|
builder.setPositiveButton(args.getString("button_positive"), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
onPositiveButtonClick(view);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (mButtonCount == 3) {
|
||||||
builder.setNeutralButton(args.getString("button_neutral"), new DialogInterface.OnClickListener() {
|
builder.setNeutralButton(args.getString("button_neutral"), new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
@@ -105,13 +109,20 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
public void onPrepareOptionsMenu(Menu menu) {
|
public void onPrepareOptionsMenu(Menu menu) {
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
// Show the neutral button if needed
|
// Show the neutral button if needed
|
||||||
if (!mHasNeutralButton) {
|
if (mButtonCount < 3) {
|
||||||
menu.removeItem(R.id.menu_neutral_button);
|
menu.removeItem(R.id.menu_neutral_button);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
menu.findItem(R.id.menu_neutral_button).setTitle(args.getString("button_neutral"));
|
menu.findItem(R.id.menu_neutral_button).setTitle(args.getString("button_neutral"));
|
||||||
}
|
}
|
||||||
menu.findItem(R.id.menu_positive_button).setTitle(args.getString("button_positive"));
|
|
||||||
|
// Show the positive button if needed
|
||||||
|
if (mButtonCount < 2) {
|
||||||
|
menu.removeItem(R.id.menu_positive_button);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
menu.findItem(R.id.menu_positive_button).setTitle(args.getString("button_positive"));
|
||||||
|
}
|
||||||
super.onPrepareOptionsMenu(menu);
|
super.onPrepareOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +135,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
// Hide the keyboard if present
|
// Hide the keyboard if present
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||||
|
assert imm != null;
|
||||||
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
if (id == R.id.menu_positive_button) {
|
if (id == R.id.menu_positive_button) {
|
||||||
|
@@ -58,7 +58,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
|||||||
mContentLayoutId = R.layout.content_task_form;
|
mContentLayoutId = R.layout.content_task_form;
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
mHasNeutralButton = args.getBoolean("neutral");
|
mButtonCount = args.getInt("button_count");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +106,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
|||||||
|
|
||||||
// Auto set list value to current tab
|
// Auto set list value to current tab
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
|
assert args != null;
|
||||||
int id = args.getInt("list");
|
int id = args.getInt("list");
|
||||||
spinner.setSelection(id);
|
spinner.setSelection(id);
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ public class TaskListsFragment extends DynamicDialogFragment implements
|
|||||||
|
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
mHasNeutralButton = args.getBoolean("neutral");
|
mButtonCount = args.getInt("button_count");
|
||||||
}
|
}
|
||||||
|
|
||||||
mContentLayoutId = R.layout.fragment_tasklists;
|
mContentLayoutId = R.layout.fragment_tasklists;
|
||||||
|
@@ -59,4 +59,5 @@
|
|||||||
<string name="task_list_edit_list_hint">Nom de la liste</string>
|
<string name="task_list_edit_list_hint">Nom de la liste</string>
|
||||||
<string name="incompatible_sdk_version">Sorry, your Android version is not supported.</string>
|
<string name="incompatible_sdk_version">Sorry, your Android version is not supported.</string>
|
||||||
<string name="action_history">Historique</string>
|
<string name="action_history">Historique</string>
|
||||||
|
<string name="task_list_ok">OK</string>
|
||||||
</resources>
|
</resources>
|
@@ -82,4 +82,5 @@
|
|||||||
<!-- TODO: Remove or change this placeholder text -->
|
<!-- TODO: Remove or change this placeholder text -->
|
||||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||||
<string name="title_activity_main2">Main2Activity</string>
|
<string name="title_activity_main2">Main2Activity</string>
|
||||||
|
<string name="task_list_ok">OK</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user