mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Refactor: Use Field-injection for SharedPreferenceUtil in AddNoteDialog and ConfirmationAlertDialogFragment
* Replaced previously used constructor-injection with field-injection * Minor refactoring: Remove extra super() calls & use same names for constructor parameters as member variables
This commit is contained in:
parent
62c4655622
commit
5723554c53
@ -64,7 +64,4 @@ public interface ApplicationComponent {
|
||||
|
||||
void inject(AutoCompleteAdapter autoCompleteAdapter);
|
||||
|
||||
void inject(AddNoteDialog addNoteDialog);
|
||||
|
||||
void inject(ConfirmationAlertDialogFragment confirmationAlertDialogFragment);
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import org.kiwix.kiwixmobile.BuildConfig;
|
||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.data.ZimContentProvider;
|
||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||
@ -40,7 +39,6 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@ -61,8 +59,7 @@ public class AddNoteDialog extends DialogFragment implements ConfirmationAlertDi
|
||||
|
||||
public static String TAG = "AddNoteDialog";
|
||||
|
||||
@Inject
|
||||
SharedPreferenceUtil sharedPreferenceUtil;
|
||||
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||
|
||||
@BindView(R.id.add_note_toolbar)
|
||||
Toolbar toolbar; // Displays options for the note dialog
|
||||
@ -78,9 +75,8 @@ public class AddNoteDialog extends DialogFragment implements ConfirmationAlertDi
|
||||
private boolean noteFileExists = false;
|
||||
private boolean noteEdited = false; // Keeps track of state of the note (whether edited since last save)
|
||||
|
||||
public AddNoteDialog() {
|
||||
super();
|
||||
KiwixApplication.getApplicationComponent().inject(this);
|
||||
public AddNoteDialog(SharedPreferenceUtil sharedPreferenceUtil) {
|
||||
this.sharedPreferenceUtil = sharedPreferenceUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -171,7 +167,7 @@ public class AddNoteDialog extends DialogFragment implements ConfirmationAlertDi
|
||||
|
||||
if(previousInstance == null) {
|
||||
// Custom AlertDialog for taking user confirmation before closing note dialog in case of unsaved changes
|
||||
DialogFragment newFragment = new ConfirmationAlertDialogFragment(TAG, R.string.confirmation_alert_dialog_message);
|
||||
DialogFragment newFragment = new ConfirmationAlertDialogFragment(sharedPreferenceUtil, TAG, R.string.confirmation_alert_dialog_message);
|
||||
newFragment.show(getActivity().getSupportFragmentManager(), ConfirmationAlertDialogFragment.TAG);
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,9 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Created by @Aditya-Sood as a part of GSoC 2019
|
||||
@ -29,15 +27,15 @@ import javax.inject.Inject;
|
||||
public class ConfirmationAlertDialogFragment extends DialogFragment {
|
||||
|
||||
public static String TAG = "ConfirmationAlertDialog";
|
||||
@Inject SharedPreferenceUtil sharedPreferenceUtil;
|
||||
private int stringResource;
|
||||
|
||||
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||
private int stringResourceId;
|
||||
private String parentDialogFragmentTAG;
|
||||
|
||||
public ConfirmationAlertDialogFragment(String dialogFragmentTAG, int resourceId) {
|
||||
super();
|
||||
parentDialogFragmentTAG = dialogFragmentTAG;
|
||||
stringResource = resourceId;
|
||||
KiwixApplication.getApplicationComponent().inject(this);
|
||||
public ConfirmationAlertDialogFragment(SharedPreferenceUtil sharedPreferenceUtil, String parentDialogFragmentTAG, int stringResourceId) {
|
||||
this.sharedPreferenceUtil = sharedPreferenceUtil;
|
||||
this.parentDialogFragmentTAG = parentDialogFragmentTAG;
|
||||
this.stringResourceId = stringResourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,7 +50,7 @@ public class ConfirmationAlertDialogFragment extends DialogFragment {
|
||||
builder = new AlertDialog.Builder(getActivity());
|
||||
}
|
||||
|
||||
builder.setMessage(stringResource)
|
||||
builder.setMessage(stringResourceId)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -996,7 +996,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
||||
/* Since the DialogFragment is never added to the back-stack, so findFragmentByTag()
|
||||
* returning null means that the AddNoteDialog is currently not on display (as doesn't exist)
|
||||
**/
|
||||
AddNoteDialog dialogFragment = new AddNoteDialog();
|
||||
AddNoteDialog dialogFragment = new AddNoteDialog(sharedPreferenceUtil);
|
||||
dialogFragment.show(fragmentTransaction, AddNoteDialog.TAG); // For DialogFragments, show() handles the fragment commit and display
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user