• 1000
Диалог обратной связи. java public class FeedBackDialog extends DialogFragment implements View.OnClickListener {
private static final String TAG = "Feedback";
public EditText fname,fmobile,faddress, fmessage;
public Button fsubmit , fcancel;
private ImainActivity imainActivity;
@Override
public void onClick(View v) {
switch (v.getId ()){
case R.id.fsubmit:{
String name= fname.getText ().toString ();
String mobile= fname.getText ().toString ();
String address= fname.getText ().toString ();
String message = fmessage.getText ().toString ();
if(!name.equals ( "" ) && !mobile.equals ( "" ) && !address.equals ( "" ) && !message.equals ( "" )){
ImainActivity imainActivity = new ImainActivity ( ) {
@Override
public void createNewFeedback(String name, String mobile, String address, String message) {
FirebaseFirestore db = FirebaseFirestore.getInstance ();
DocumentReference feedbackDocRef= db.collection ( "FeedBacks" ).document ();
String userId = FirebaseAuth.getInstance ().getCurrentUser ().getUid ();
FeedbackData feedbackData = new FeedbackData ( );
feedbackData.setFname ( name );
feedbackData.setFmobile ( mobile );
feedbackData.setFaddress ( address );
feedbackData.setFmessage ( message );
Date timestamp = null;
feedbackData.setTimestamp ( timestamp );
feedbackData.setUserid(userId);
feedbackDocRef.set ( feedbackData ).addOnCompleteListener ( new OnCompleteListener <Void> ( ) {
@Override
public void onComplete(@NonNull Task <Void> task) {
if(task.isSuccessful ()){
Toast.makeText ( getApplicationContext(), "Feedback Send Successfully!", Toast.LENGTH_SHORT ).show ( );
}else{
Toast.makeText ( getApplicationContext(), "Feedback didn't Send.", Toast.LENGTH_SHORT ).show ( );
}
}
} ).addOnFailureListener ( new OnFailureListener ( ) {
@Override
public void onFailure(@NonNull Exception e) {
}
} );
}
};
imainActivity.createNewFeedback ( name,mobile,address,message );
getDialog ().dismiss ();
}else{
Toast.makeText ( getActivity (), "Enter All Fields...", Toast.LENGTH_SHORT ).show ( );
}break;
}
case R.id.fcancel:{
getDialog ().dismiss ();
break;
}
case R.id.btn_close:{
getDialog ().dismiss ();
break;
}
default:
throw new IllegalStateException ( "Unexpected value: " + v.getId ( ) );
}
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach ( context );
imainActivity = (ImainActivity) getActivity ();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
int style = DialogFragment.STYLE_NO_TITLE;
int theme = android.R.style.Theme_Holo_Light_Dialog;
setStyle ( style,theme );
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_feedback, container, false);
fname = view.findViewById(R.id.fname);
fmobile = view.findViewById ( R.id.fmobile );
faddress = view.findViewById ( R.id.faddress );
fmessage = view.findViewById(R.id.fmessage);
fsubmit = view.findViewById(R.id.fsubmit);
fcancel = view.findViewById(R.id.fcancel);
fcancel.setOnClickListener(this);
fsubmit.setOnClickListener(this);
getDialog().setTitle("Feedback");
return view;
}
}