31
31
import com .pranavpandey .android .dynamic .util .DynamicFileUtils ;
32
32
import com .pranavpandey .android .dynamic .util .concurrent .DynamicResult ;
33
33
import com .pranavpandey .android .dynamic .util .concurrent .DynamicTask ;
34
+ import com .pranavpandey .android .dynamic .util .concurrent .task .ContextTask ;
34
35
35
36
/**
36
37
* A {@link DynamicTask} to perform the theme related operations.
37
38
*
38
39
* @param <V> The type of the dynamic app theme.
39
40
*/
40
41
public abstract class ThemeExportTask <V extends DynamicAppTheme >
41
- extends DynamicTask <Void , Void , Uri > {
42
+ extends ContextTask <Void , Void , Uri > {
42
43
43
44
/**
44
45
* Theme action to perform the operation accordingly.
@@ -55,6 +56,11 @@ public abstract class ThemeExportTask<V extends DynamicAppTheme>
55
56
*/
56
57
private final ThemeListener <V > mThemeListener ;
57
58
59
+ /**
60
+ * The dynamic theme returned by the listener.
61
+ */
62
+ private final V mDynamicTheme ;
63
+
58
64
/**
59
65
* Constructor to initialize an object of this class.
60
66
*
@@ -63,8 +69,14 @@ public abstract class ThemeExportTask<V extends DynamicAppTheme>
63
69
*/
64
70
public ThemeExportTask (@ Theme .Action int themeAction ,
65
71
@ Nullable ThemeListener <V > themeListener ) {
72
+ super (themeListener != null && themeListener .getThemePreview () != null
73
+ ? themeListener .getThemePreview ().getContext () : null );
74
+
66
75
this .mThemeAction = themeAction ;
67
76
this .mThemeListener = themeListener ;
77
+ this .mDynamicTheme = getThemeListener () != null
78
+ || getThemeListener ().getThemePreview () != null
79
+ ? themeListener .getThemePreview ().getDynamicTheme () : null ;
68
80
}
69
81
70
82
@ Override
@@ -85,35 +97,24 @@ protected void onPreExecute() {
85
97
86
98
@ Override
87
99
protected @ Nullable Uri doInBackground (@ Nullable Void params ) {
88
- if (getThemeListener () == null ) {
89
- return null ;
90
- }
91
-
92
- if (getThemeListener ().getThemePreview () == null ) {
100
+ if (getContext () == null || getThemeListener () == null || getDynamicTheme () == null ) {
93
101
return null ;
94
102
}
95
103
96
104
if (getThemeAction () == Theme .Action .SHARE_CODE
97
105
|| getThemeAction () == Theme .Action .SAVE_CODE ) {
98
- mThemeBitmap = DynamicCodeUtils .generateThemeCode (
99
- getThemeListener ().getThemePreview ().getDynamicTheme (),
100
- DynamicResourceUtils .getDrawable (
101
- getThemeListener ().getThemePreview ().getContext (),
102
- getThemeListener ().getThemePreview ().getDynamicTheme ().isDynamicColor ()
103
- ? R .drawable .adt_ic_app : R .drawable .ads_ic_style ));
106
+ mThemeBitmap = DynamicCodeUtils .generateThemeCode (getDynamicTheme (),
107
+ DynamicResourceUtils .getDrawable (getContext (), getDynamicTheme ()
108
+ .isDynamicColor () ? R .drawable .adt_ic_app : R .drawable .ads_ic_style ));
104
109
}
105
110
106
111
if (getThemeAction () == Theme .Action .SHARE_FILE
107
112
|| getThemeAction () == Theme .Action .SAVE_FILE ) {
108
- return DynamicFileUtils .getUriFromFile (
109
- getThemeListener ().getThemePreview ().getContext (),
110
- DynamicThemeUtils .requestThemeFile (
111
- getThemeListener ().getThemePreview ().getContext (), Theme .NAME ,
112
- getThemeListener ().getThemePreview ()
113
- .getDynamicTheme ().toDynamicString ()));
113
+ return DynamicFileUtils .getUriFromFile (getContext (),
114
+ DynamicThemeUtils .requestThemeFile (getContext (), Theme .NAME ,
115
+ getDynamicTheme ().toDynamicString ()));
114
116
} else {
115
- return DynamicFileUtils .getBitmapUri (
116
- getThemeListener ().getThemePreview ().getContext (),
117
+ return DynamicFileUtils .getBitmapUri (getContext (),
117
118
getThemeBitmap (), Theme .Key .SHARE , Theme .EXTENSION_IMAGE );
118
119
}
119
120
}
@@ -156,6 +157,15 @@ protected void onPostExecute(@Nullable DynamicResult<Uri> result) {
156
157
return mThemeListener ;
157
158
}
158
159
160
+ /**
161
+ * Get the dynamic theme returned by the listener.
162
+ *
163
+ * @return The dynamic theme returned by the listener.
164
+ */
165
+ public @ Nullable V getDynamicTheme () {
166
+ return mDynamicTheme ;
167
+ }
168
+
159
169
/**
160
170
* Get the theme bitmap used by this task.
161
171
*
0 commit comments