Ask save changes standard reply

This commit is contained in:
M66B
2018-11-13 15:14:14 +01:00
parent 691eb212b4
commit eecd3c10dd
6 changed files with 97 additions and 33 deletions

View File

@@ -35,6 +35,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer;
public class FragmentAnswer extends FragmentEx {
@@ -84,6 +85,8 @@ public class FragmentAnswer extends FragmentEx {
}
});
((ActivityBase) getActivity()).addBackPressedListener(onBackPressedListener);
// Initialize
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
@@ -91,6 +94,12 @@ public class FragmentAnswer extends FragmentEx {
return view;
}
@Override
public void onDestroyView() {
((ActivityBase) getActivity()).removeBackPressedListener(onBackPressedListener);
super.onDestroyView();
}
@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -187,4 +196,31 @@ public class FragmentAnswer extends FragmentEx {
}
}.load(this, args);
}
private void handleExit() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_ask_save)
.setPositiveButton(R.string.title_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onActionSave();
}
})
.setNegativeButton(R.string.title_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
ActivityBase.IBackPressedListener onBackPressedListener = new ActivityBase.IBackPressedListener() {
@Override
public boolean onBackPressed() {
handleExit();
return true;
}
};
}