Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singleton scope separation #164

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# along with Butter. If not, see <http://www.gnu.org/licenses/>.
#

CHECKSTYLE_MAX_ERRORS=760
CHECKSTYLE_MAX_ERRORS=747
32 changes: 28 additions & 4 deletions base/src/main/java/butter/droid/base/BaseApplicationComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,37 @@

package butter.droid.base;

import butter.droid.base.manager.beaming.BeamPlayerNotificationService;
import butter.droid.base.torrent.TorrentService;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import butter.droid.base.manager.network.NetworkManager;
import butter.droid.base.manager.prefs.PrefManager;
import com.google.gson.Gson;
import okhttp3.OkHttpClient;

public interface BaseApplicationComponent {

void inject(BeamPlayerNotificationService service);
Context context();

void inject(TorrentService service);
OkHttpClient okHttpClient();

Gson gson();

SharedPreferences sharedPreferences();

Resources resources();

ConnectivityManager connectivityManager();

WifiManager wifiManager();

NetworkManager networkManager();

PrefManager prefManager();

TelephonyManager telephonyManager();

}
10 changes: 3 additions & 7 deletions base/src/main/java/butter/droid/base/BaseApplicationModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;

import javax.inject.Singleton;

import butter.droid.base.content.ObscuredSharedPreferences;
import butter.droid.base.data.DataModule;
import butter.droid.base.manager.ManagerModule;
import butter.droid.base.providers.ProviderModule;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;

@Module(
includes = {
DataModule.class,
ManagerModule.class,
ProviderModule.class,
AndroidModule.class,
ManagerModule.class,
DataModule.class
}
)
public class BaseApplicationModule {
Expand Down
59 changes: 59 additions & 0 deletions base/src/main/java/butter/droid/base/BaseInternalComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* This file is part of Butter.
*
* Butter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Butter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Butter. If not, see <http://www.gnu.org/licenses/>.
*/

package butter.droid.base;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import butter.droid.base.manager.internal.beaming.BeamPlayerNotificationService;
import butter.droid.base.manager.internal.vlc.PlayerManager;
import butter.droid.base.providers.media.VodoProvider;
import butter.droid.base.torrent.TorrentService;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import okhttp3.OkHttpClient;

public interface BaseInternalComponent {

void inject(BeamPlayerNotificationService service);

void inject(TorrentService service);

Context context();

Picasso picasso();

VodoProvider vodoProvider();

OkHttpClient okHttpClient();

Gson gson();

PlayerManager playerManager();

SharedPreferences sharedPreferences();

Resources resources();

ConnectivityManager connectivityManager();

WifiManager wifiManager();

}
30 changes: 30 additions & 0 deletions base/src/main/java/butter/droid/base/BaseInternalModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of Butter.
*
* Butter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Butter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Butter. If not, see <http://www.gnu.org/licenses/>.
*/

package butter.droid.base;

import butter.droid.base.data.internal.InternalDataModule;
import butter.droid.base.manager.internal.InternalManagerModule;
import dagger.Module;

@Module(includes = {
InternalDataModule.class,
InternalManagerModule.class,
})
public class BaseInternalModule {

}
24 changes: 12 additions & 12 deletions base/src/main/java/butter/droid/base/ButterApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@
import android.net.Uri;
import android.support.multidex.MultiDex;
import android.support.v4.app.NotificationCompat;

import com.sjl.foreground.Foreground;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.picasso.Picasso;

import java.io.File;

import javax.inject.Inject;

import butter.droid.base.content.preferences.PreferencesHandler;
import butter.droid.base.manager.beaming.BeamManager;
import butter.droid.base.manager.updater.ButterUpdateManager;
import butter.droid.base.manager.internal.beaming.BeamManager;
import butter.droid.base.manager.internal.updater.ButterUpdateManager;
import butter.droid.base.torrent.TorrentService;
import butter.droid.base.utils.FileUtils;
import butter.droid.base.utils.LocaleUtils;
import butter.droid.base.utils.StorageUtils;
import butter.droid.base.utils.VersionUtils;
import com.sjl.foreground.Foreground;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.picasso.Picasso;
import java.io.File;
import javax.inject.Inject;
import timber.log.Timber;

public abstract class ButterApplication extends Application implements ButterUpdateManager.Listener {
Expand All @@ -69,6 +65,8 @@ public void onCreate() {
super.onCreate();
sThis = this;

inject();

sDefSystemLanguage = LocaleUtils.getCurrentAsString();

LeakCanary.install(this);
Expand Down Expand Up @@ -150,7 +148,9 @@ public void updateAvailable(String updateFile) {
}
}

public abstract BaseApplicationComponent getComponent();
public abstract BaseInternalComponent getComponent();

protected abstract void inject();

public static ButterApplication getAppContext() {
return sThis;
Expand Down
44 changes: 44 additions & 0 deletions base/src/main/java/butter/droid/base/Internal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of Butter.
*
* Butter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Butter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Butter. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* This file is part of Butter.
*
* Butter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Butter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Butter. If not, see <http://www.gnu.org/licenses/>.
*/

package butter.droid.base;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.inject.Scope;

@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface Internal {
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class PlayerTestConstants {
"Open dialog"
};

public final static String[] FILES = new String[]{
public final static String[] FILES = new String[] {
"https://get.butterproject.org/nwtests/Spider-Man_2_720p_24fps_surround_ac3.mp4",
"https://get.butterproject.org/nwtests/Spider-Man_2_720p_24fps_mp3.mp4",
"https://get.butterproject.org/nwtests/Spider-Man_2_1080p_24fps_surround_ac3.mp4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package butter.droid.base.content.preferences;

import static butter.droid.base.content.preferences.Prefs.DEFAULT_PROVIDER;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
Expand All @@ -11,32 +13,27 @@
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.text.format.DateFormat;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.inject.Inject;

import butter.droid.base.ButterApplication;
import butter.droid.base.Constants;
import butter.droid.base.R;
import butter.droid.base.content.preferences.PrefItem.SubtitleGenerator;
import butter.droid.base.content.preferences.Prefs.PrefKey;
import butter.droid.base.manager.internal.provider.ProviderManager;
import butter.droid.base.manager.internal.updater.ButterUpdateManager;
import butter.droid.base.manager.internal.vlc.VLCOptions;
import butter.droid.base.manager.prefs.PrefManager;
import butter.droid.base.manager.provider.ProviderManager;
import butter.droid.base.manager.updater.ButterUpdateManager;
import butter.droid.base.manager.vlc.VLCOptions;
import butter.droid.base.providers.subs.SubsProvider;
import butter.droid.base.utils.LocaleUtils;
import butter.droid.base.utils.StorageUtils;
import dagger.Reusable;

import static butter.droid.base.content.preferences.Prefs.DEFAULT_PROVIDER;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.inject.Inject;

@Reusable
public class PreferencesHandler {
Expand Down
23 changes: 3 additions & 20 deletions base/src/main/java/butter/droid/base/data/DataModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@

package butter.droid.base.data;

import android.content.Context;

import butter.droid.base.content.preferences.PreferencesHandler;
import com.google.gson.Gson;
import com.jakewharton.picasso.OkHttp3Downloader;
import com.squareup.picasso.Picasso;

import dagger.Module;
import dagger.Provides;
import java.io.File;
import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import butter.droid.base.content.preferences.PreferencesHandler;
import dagger.Module;
import dagger.Provides;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;
Expand All @@ -54,16 +47,6 @@ public class DataModule {
.build();
}

@Provides @Singleton public OkHttp3Downloader provideOkHttpDownloader(OkHttpClient client) {
return new OkHttp3Downloader(client);
}

@Provides @Singleton public Picasso providePicasso(Context context, OkHttp3Downloader okHttpDownloader) {
return new Picasso.Builder(context)
.downloader(okHttpDownloader)
.build();
}

@Provides @Singleton public Gson provideGson() {
return new Gson();
}
Expand Down
Loading