mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 06:42:21 -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(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 androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.BuildConfig;
|
import org.kiwix.kiwixmobile.BuildConfig;
|
||||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.data.ZimContentProvider;
|
import org.kiwix.kiwixmobile.data.ZimContentProvider;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
@ -40,7 +39,6 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -61,8 +59,7 @@ public class AddNoteDialog extends DialogFragment implements ConfirmationAlertDi
|
|||||||
|
|
||||||
public static String TAG = "AddNoteDialog";
|
public static String TAG = "AddNoteDialog";
|
||||||
|
|
||||||
@Inject
|
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||||
SharedPreferenceUtil sharedPreferenceUtil;
|
|
||||||
|
|
||||||
@BindView(R.id.add_note_toolbar)
|
@BindView(R.id.add_note_toolbar)
|
||||||
Toolbar toolbar; // Displays options for the note dialog
|
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 noteFileExists = false;
|
||||||
private boolean noteEdited = false; // Keeps track of state of the note (whether edited since last save)
|
private boolean noteEdited = false; // Keeps track of state of the note (whether edited since last save)
|
||||||
|
|
||||||
public AddNoteDialog() {
|
public AddNoteDialog(SharedPreferenceUtil sharedPreferenceUtil) {
|
||||||
super();
|
this.sharedPreferenceUtil = sharedPreferenceUtil;
|
||||||
KiwixApplication.getApplicationComponent().inject(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -171,7 +167,7 @@ public class AddNoteDialog extends DialogFragment implements ConfirmationAlertDi
|
|||||||
|
|
||||||
if(previousInstance == null) {
|
if(previousInstance == null) {
|
||||||
// Custom AlertDialog for taking user confirmation before closing note dialog in case of unsaved changes
|
// 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);
|
newFragment.show(getActivity().getSupportFragmentManager(), ConfirmationAlertDialogFragment.TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,11 +8,9 @@ import androidx.appcompat.app.AlertDialog;
|
|||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
|
||||||
import org.kiwix.kiwixmobile.R;
|
import org.kiwix.kiwixmobile.R;
|
||||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by @Aditya-Sood as a part of GSoC 2019
|
* Created by @Aditya-Sood as a part of GSoC 2019
|
||||||
@ -29,15 +27,15 @@ import javax.inject.Inject;
|
|||||||
public class ConfirmationAlertDialogFragment extends DialogFragment {
|
public class ConfirmationAlertDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public static String TAG = "ConfirmationAlertDialog";
|
public static String TAG = "ConfirmationAlertDialog";
|
||||||
@Inject SharedPreferenceUtil sharedPreferenceUtil;
|
|
||||||
private int stringResource;
|
private SharedPreferenceUtil sharedPreferenceUtil;
|
||||||
|
private int stringResourceId;
|
||||||
private String parentDialogFragmentTAG;
|
private String parentDialogFragmentTAG;
|
||||||
|
|
||||||
public ConfirmationAlertDialogFragment(String dialogFragmentTAG, int resourceId) {
|
public ConfirmationAlertDialogFragment(SharedPreferenceUtil sharedPreferenceUtil, String parentDialogFragmentTAG, int stringResourceId) {
|
||||||
super();
|
this.sharedPreferenceUtil = sharedPreferenceUtil;
|
||||||
parentDialogFragmentTAG = dialogFragmentTAG;
|
this.parentDialogFragmentTAG = parentDialogFragmentTAG;
|
||||||
stringResource = resourceId;
|
this.stringResourceId = stringResourceId;
|
||||||
KiwixApplication.getApplicationComponent().inject(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -52,7 +50,7 @@ public class ConfirmationAlertDialogFragment extends DialogFragment {
|
|||||||
builder = new AlertDialog.Builder(getActivity());
|
builder = new AlertDialog.Builder(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setMessage(stringResource)
|
builder.setMessage(stringResourceId)
|
||||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
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()
|
/* 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)
|
* 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
|
dialogFragment.show(fragmentTransaction, AddNoteDialog.TAG); // For DialogFragments, show() handles the fragment commit and display
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user