@ -3,6 +3,8 @@ package awais.instagrabber.dialogs;
import android.app.Dialog ;
import android.app.Dialog ;
import android.content.Context ;
import android.content.Context ;
import android.os.Bundle ;
import android.os.Bundle ;
import android.text.method.LinkMovementMethod ;
import android.widget.TextView ;
import androidx.annotation.NonNull ;
import androidx.annotation.NonNull ;
import androidx.annotation.Nullable ;
import androidx.annotation.Nullable ;
@ -24,17 +26,40 @@ public class ConfirmDialogFragment extends DialogFragment {
@NonNull
@NonNull
public static ConfirmDialogFragment newInstance ( final int requestCode ,
public static ConfirmDialogFragment newInstance ( final int requestCode ,
@StringRes final int title ,
@StringRes final int title ,
@StringRes final int message ,
@NonNull final CharSequence message ,
@StringRes final int positiveText ,
@StringRes final int positiveText ,
@StringRes final int negativeText ,
@StringRes final int negativeText ,
@StringRes final int neutralText ) {
@StringRes final int neutralText ) {
return newInstance ( requestCode , title , 0 , message , positiveText , negativeText , neutralText ) ;
}
@NonNull
public static ConfirmDialogFragment newInstance ( final int requestCode ,
@StringRes final int title ,
@StringRes final int messageResId ,
@StringRes final int positiveText ,
@StringRes final int negativeText ,
@StringRes final int neutralText ) {
return newInstance ( requestCode , title , messageResId , null , positiveText , negativeText , neutralText ) ;
}
@NonNull
private static ConfirmDialogFragment newInstance ( final int requestCode ,
@StringRes final int title ,
@StringRes final int messageResId ,
@Nullable final CharSequence message ,
@StringRes final int positiveText ,
@StringRes final int negativeText ,
@StringRes final int neutralText ) {
Bundle args = new Bundle ( ) ;
Bundle args = new Bundle ( ) ;
args . putInt ( "requestCode" , requestCode ) ;
args . putInt ( "requestCode" , requestCode ) ;
if ( title ! = 0 ) {
if ( title ! = 0 ) {
args . putInt ( "title" , title ) ;
args . putInt ( "title" , title ) ;
}
}
if ( message ! = 0 ) {
args . putInt ( "message" , message ) ;
if ( messageResId ! = 0 ) {
args . putInt ( "messageResId" , messageResId ) ;
} else if ( message ! = null ) {
args . putCharSequence ( "message" , message ) ;
}
}
if ( positiveText ! = 0 ) {
if ( positiveText ! = 0 ) {
args . putInt ( "positive" , positiveText ) ;
args . putInt ( "positive" , positiveText ) ;
@ -67,7 +92,8 @@ public class ConfirmDialogFragment extends DialogFragment {
public Dialog onCreateDialog ( @Nullable final Bundle savedInstanceState ) {
public Dialog onCreateDialog ( @Nullable final Bundle savedInstanceState ) {
final Bundle arguments = getArguments ( ) ;
final Bundle arguments = getArguments ( ) ;
int title = 0 ;
int title = 0 ;
int message = 0 ;
int messageResId = 0 ;
CharSequence message = null ;
int neutralButtonText = 0 ;
int neutralButtonText = 0 ;
int negativeButtonText = 0 ;
int negativeButtonText = 0 ;
@ -75,7 +101,8 @@ public class ConfirmDialogFragment extends DialogFragment {
final int requestCode ;
final int requestCode ;
if ( arguments ! = null ) {
if ( arguments ! = null ) {
title = arguments . getInt ( "title" , 0 ) ;
title = arguments . getInt ( "title" , 0 ) ;
message = arguments . getInt ( "message" , 0 ) ;
messageResId = arguments . getInt ( "messageResId" , 0 ) ;
message = arguments . getCharSequence ( "message" , null ) ;
positiveButtonText = arguments . getInt ( "positive" , defaultPositiveButtonText ) ;
positiveButtonText = arguments . getInt ( "positive" , defaultPositiveButtonText ) ;
negativeButtonText = arguments . getInt ( "negative" , 0 ) ;
negativeButtonText = arguments . getInt ( "negative" , 0 ) ;
neutralButtonText = arguments . getInt ( "neutral" , 0 ) ;
neutralButtonText = arguments . getInt ( "neutral" , 0 ) ;
@ -92,7 +119,9 @@ public class ConfirmDialogFragment extends DialogFragment {
if ( title ! = 0 ) {
if ( title ! = 0 ) {
builder . setTitle ( title ) ;
builder . setTitle ( title ) ;
}
}
if ( message ! = 0 ) {
if ( messageResId ! = 0 ) {
builder . setMessage ( messageResId ) ;
} else if ( message ! = null ) {
builder . setMessage ( message ) ;
builder . setMessage ( message ) ;
}
}
if ( negativeButtonText ! = 0 ) {
if ( negativeButtonText ! = 0 ) {
@ -110,6 +139,15 @@ public class ConfirmDialogFragment extends DialogFragment {
return builder . create ( ) ;
return builder . create ( ) ;
}
}
@Override
public void onStart ( ) {
super . onStart ( ) ;
final Dialog dialog = getDialog ( ) ;
if ( dialog = = null ) return ;
final TextView view = dialog . findViewById ( android . R . id . message ) ;
view . setMovementMethod ( LinkMovementMethod . getInstance ( ) ) ;
}
public interface ConfirmDialogFragmentCallback {
public interface ConfirmDialogFragmentCallback {
void onPositiveButtonClicked ( int requestCode ) ;
void onPositiveButtonClicked ( int requestCode ) ;