mirror of https://github.com/tasks/tasks
Use support fragments
parent
df501ff335
commit
ff40202128
@ -0,0 +1,47 @@
|
||||
package org.tasks.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.todoroo.astrid.gtasks.GtasksList;
|
||||
import com.todoroo.astrid.gtasks.GtasksListService;
|
||||
|
||||
import org.tasks.dialogs.DialogBuilder;
|
||||
import org.tasks.gtasks.GoogleTaskListSelectionHandler;
|
||||
import org.tasks.injection.InjectingNativeDialogFragment;
|
||||
import org.tasks.injection.NativeDialogFragmentComponent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.tasks.activities.SupportGoogleTaskListPicker.createDialog;
|
||||
|
||||
public class NativeGoogleTaskListPicker extends InjectingNativeDialogFragment {
|
||||
|
||||
@Inject DialogBuilder dialogBuilder;
|
||||
@Inject GtasksListService gtasksListService;
|
||||
|
||||
private GoogleTaskListSelectionHandler handler;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return createDialog(dialogBuilder, gtasksListService, new GoogleTaskListSelectionHandler() {
|
||||
@Override
|
||||
public void selectedList(GtasksList list) {
|
||||
handler.selectedList(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
handler = (GoogleTaskListSelectionHandler) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(NativeDialogFragmentComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import org.tasks.activities.GoogleTaskListSelectionDialog;
|
||||
import org.tasks.activities.SupportGoogleTaskListPicker;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
@Subcomponent(modules = DialogFragmentModule.class)
|
||||
public interface DialogFragmentComponent extends BaseDialogFragmentComponent {
|
||||
|
||||
void inject(GoogleTaskListSelectionDialog googleTaskListSelectionDialog);
|
||||
void inject(SupportGoogleTaskListPicker supportGoogleTaskListPicker);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import org.tasks.activities.NativeGoogleTaskListPicker;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
@Subcomponent(modules = NativeDialogFragmentModule.class)
|
||||
public interface NativeDialogFragmentComponent extends BaseNativeDialogFragmentComponent {
|
||||
void inject(NativeGoogleTaskListPicker nativeGoogleTaskListPicker);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package org.tasks.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.tasks.injection.InjectingNativeDialogFragment;
|
||||
import org.tasks.injection.NativeDialogFragmentComponent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class NativeThemePickerDialog extends InjectingNativeDialogFragment implements ThemePickerDialog.ThemePickerCallback {
|
||||
|
||||
private static final String EXTRA_PALETTE = "extra_palette";
|
||||
|
||||
public static NativeThemePickerDialog newNativeThemePickerDialog(ThemePickerDialog.ColorPalette palette) {
|
||||
NativeThemePickerDialog dialog = new NativeThemePickerDialog();
|
||||
dialog.palette = palette;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Inject ThemePickerDialog themePickerDialog;
|
||||
|
||||
private ThemePickerDialog.ColorPalette palette;
|
||||
private ThemePickerDialog.ThemePickerCallback callback;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
palette = (ThemePickerDialog.ColorPalette) savedInstanceState.getSerializable(EXTRA_PALETTE);
|
||||
}
|
||||
return themePickerDialog.createDialog(palette, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
callback = (ThemePickerDialog.ThemePickerCallback) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
outState.putSerializable(EXTRA_PALETTE, palette);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(NativeDialogFragmentComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void themePicked(ThemePickerDialog.ColorPalette palette, int index) {
|
||||
callback.themePicked(palette, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiateThemePurchase() {
|
||||
callback.initiateThemePurchase();
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package org.tasks.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.tasks.injection.DialogFragmentComponent;
|
||||
import org.tasks.injection.InjectingDialogFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class SupportThemePickerDialog extends InjectingDialogFragment implements ThemePickerDialog.ThemePickerCallback {
|
||||
|
||||
private static final String EXTRA_PALETTE = "extra_palette";
|
||||
|
||||
public static SupportThemePickerDialog newSupportThemePickerDialog(ThemePickerDialog.ColorPalette palette) {
|
||||
SupportThemePickerDialog dialog = new SupportThemePickerDialog();
|
||||
dialog.palette = palette;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Inject ThemePickerDialog themePickerDialog;
|
||||
|
||||
private ThemePickerDialog.ColorPalette palette;
|
||||
private ThemePickerDialog.ThemePickerCallback callback;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
palette = (ThemePickerDialog.ColorPalette) savedInstanceState.getSerializable(EXTRA_PALETTE);
|
||||
}
|
||||
return themePickerDialog.createDialog(palette, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
callback = (ThemePickerDialog.ThemePickerCallback) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
outState.putSerializable(EXTRA_PALETTE, palette);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(DialogFragmentComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void themePicked(ThemePickerDialog.ColorPalette palette, int index) {
|
||||
callback.themePicked(palette, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiateThemePurchase() {
|
||||
callback.initiateThemePurchase();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import org.tasks.dialogs.NativeThemePickerDialog;
|
||||
import org.tasks.locale.LocalePickerDialog;
|
||||
|
||||
public interface BaseNativeDialogFragmentComponent {
|
||||
void inject(NativeThemePickerDialog themePickerDialog);
|
||||
|
||||
void inject(LocalePickerDialog localePickerDialog);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.DialogFragment;
|
||||
|
||||
public abstract class InjectingNativeDialogFragment extends DialogFragment {
|
||||
private boolean injected;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
if (!injected) {
|
||||
inject(((InjectingActivity) activity)
|
||||
.getComponent()
|
||||
.plus(new NativeDialogFragmentModule(this)));
|
||||
injected = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void inject(NativeDialogFragmentComponent component);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.DialogFragment;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class NativeDialogFragmentModule {
|
||||
private DialogFragment dialogFragment;
|
||||
|
||||
public NativeDialogFragmentModule(DialogFragment dialogFragment) {
|
||||
this.dialogFragment = dialogFragment;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public Activity getActivity() {
|
||||
return dialogFragment.getActivity();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue