1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
package ml.docilealligator.infinityforreddit;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.OptIn;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.database.StandaloneDatabaseProvider;
import androidx.media3.datasource.cache.LeastRecentlyUsedCacheEvictor;
import androidx.media3.datasource.cache.SimpleCache;
import androidx.preference.PreferenceManager;
import java.io.File;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import javax.inject.Named;
import javax.inject.Singleton;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LoopAvailableExoCreator;
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.videoautoplay.Config;
import ml.docilealligator.infinityforreddit.videoautoplay.ExoCreator;
import ml.docilealligator.infinityforreddit.videoautoplay.MediaSourceBuilder;
import ml.docilealligator.infinityforreddit.videoautoplay.ToroExo;
@Module
abstract class AppModule {
@Binds
abstract Context providesContext(Application application);
@Provides
@Singleton
static RedditDataRoomDatabase provideRedditDataRoomDatabase(Application application) {
return RedditDataRoomDatabase.create(application);
}
@Provides
@Named("default")
@Singleton
static SharedPreferences provideSharedPreferences(Application application) {
return PreferenceManager.getDefaultSharedPreferences(application);
}
@Provides
@Named("light_theme")
@Singleton
static SharedPreferences provideLightThemeSharedPreferences(Application application) {
return application.getSharedPreferences(CustomThemeSharedPreferencesUtils.LIGHT_THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("dark_theme")
@Singleton
static SharedPreferences provideDarkThemeSharedPreferences(Application application) {
return application.getSharedPreferences(CustomThemeSharedPreferencesUtils.DARK_THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("amoled_theme")
@Singleton
static SharedPreferences provideAmoledThemeSharedPreferences(Application application) {
return application.getSharedPreferences(CustomThemeSharedPreferencesUtils.AMOLED_THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("sort_type")
static SharedPreferences provideSortTypeSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.SORT_TYPE_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("post_layout")
static SharedPreferences providePostLayoutSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("post_feed_scrolled_position_cache")
static SharedPreferences providePostFeedScrolledPositionSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("main_activity_tabs")
static SharedPreferences provideMainActivityTabsSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("nsfw_and_spoiler")
static SharedPreferences provideNsfwAndSpoilerSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("bottom_app_bar")
static SharedPreferences provideBottoappBarSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.BOTTOM_APP_BAR_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("post_history")
static SharedPreferences providePostHistorySharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.POST_HISTORY_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("current_account")
static SharedPreferences provideCurrentAccountSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.CURRENT_ACCOUNT_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("navigation_drawer")
static SharedPreferences provideNavigationDrawerSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.NAVIGATION_DRAWER_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("post_details")
static SharedPreferences providePostDetailsSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.POST_DETAILS_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("security")
@Singleton
static SharedPreferences provideSecuritySharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.SECURITY_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Named("internal")
@Singleton
static SharedPreferences provideInternalSharedPreferences(Application application) {
return application.getSharedPreferences(SharedPreferencesUtils.INTERNAL_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
}
@Provides
@Singleton
static CustomThemeWrapper provideCustomThemeWrapper(@Named("light_theme") SharedPreferences lightThemeSharedPreferences,
@Named("dark_theme") SharedPreferences darkThemeSharedPreferences,
@Named("amoled_theme") SharedPreferences amoledThemeSharedPreferences) {
return new CustomThemeWrapper(lightThemeSharedPreferences, darkThemeSharedPreferences, amoledThemeSharedPreferences);
}
@Provides
@Named("app_cache_dir")
static File providesAppCache(Application application) {
return application.getCacheDir();
}
@Provides
@Named("exo_player_cache")
static File providesExoPlayerCache(@Named("app_cache_dir") File appCache) {
return new File(appCache, "/exoplayer");
}
@OptIn(markerClass = UnstableApi.class)
@Provides
static StandaloneDatabaseProvider provideExoDatabaseProvider(Application application) {
return new StandaloneDatabaseProvider(application);
}
@OptIn(markerClass = UnstableApi.class)
@Provides
@Singleton
static SimpleCache provideSimpleCache(StandaloneDatabaseProvider standaloneDatabaseProvider,
@Named("exo_player_cache") File exoPlayerCache) {
return new SimpleCache(exoPlayerCache,
new LeastRecentlyUsedCacheEvictor(200 * 1024 * 1024),
standaloneDatabaseProvider);
}
@OptIn(markerClass = UnstableApi.class)
@Provides
static Config providesMediaConfig(Application application, SimpleCache simpleCache) {
return new Config.Builder(application)
.setMediaSourceBuilder(MediaSourceBuilder.DEFAULT)
.setCache(simpleCache)
.build();
}
@Provides
static ToroExo providesToroExo(Application application) {
return ToroExo.with(application);
}
@OptIn(markerClass = UnstableApi.class)
@Provides
@Singleton
static ExoCreator provideExoCreator(Config config,
ToroExo toroExo,
@Named("default") SharedPreferences sharedPreferences) {
return new LoopAvailableExoCreator(toroExo, config, sharedPreferences);
}
@Provides
@Singleton
static Executor provideExecutor() {
return Executors.newFixedThreadPool(4);
}
}
|