Skip to content

Commit

Permalink
Dagger port (#96)
Browse files Browse the repository at this point in the history
* First Android Studio cleanup

* Removed unused imports

* Class structure, fields can be local

* Simplified equals() return

* Java language level migration aids

* Fixed Javadoc issues

* Redundant initializer

* Removed redundant initializers

* Not annotated method overrides method annotated with @nonnull

* Performance issues StringBuilder can be replaced with String

* Statements with empty body

* argsValues is never null

* Improved updater

Simplified logic.
Fixed dereference of 'channel' may produce 'java.lang.NullPointerException'.

* Fixed getPath() may produce 'java.lang.NullPointerException'
Removed unneded try

* Fixed ignored method results

* Use "L"  to indicate a long value

* oneway to interface method

* Removed redundant character escape

* Redundant variable declaration

* Declaration acces can be weaker, changed to private

* Redundant and unused throws clause

* Fixed Javadoc after redundant and unused throws clause fixes

*  Return value of the methods are never used, fixed Javadoc

* Remove unnecessary throws declarations

* Method always return 1

Moved to a public static variable

* CPU_ABI is deprecated, aded compat util classes

* Fixes for locale deprecation

* Fixes for getAllNetworkInfo() deprecation

* Simplified return

* Fix for Settings.System.ANDROID_ID deprecation

* Fix for 'getDrawable(int)' is deprecated

* CPU_ABI is deprecated

* Fix for 'getDrawable(int)' is deprecated

* Fix for deprecated decode

* Removed Locales from compat

Moved to LocaleUtils

* Fixed deprecations for StatFs

* Unused import

* Simplified return

* Boolean method 'isAdded' is always inverted

* Field converted to local

* Performance: used SparseArray instead of HashMap

* Ellipsis string can be replaced with ellipsis character

* Fields requires API level 16 (current min is 15)

* Butterknife update

* Fix apk build

With gradle => 2.2 the apks are generated aligned so we need this changes to assemble the apks correctly to be found by the Jenkins archiving post-built step.

* Java language migration aids

* Unused imports

* Unchecked cast

* Simplified and improved Updater

Using the parser is faster than using a POJO with fromJson

* Jackson as JSON parser

Added dep in build file and POJOS to deserialize the movies JSON, it is tons of times faster than GSON.

* Removed updater POJO

 We parse the JSON directly with the Jackson parser because is very small and simple.

* Removed invalid lines from manifest, meta-data for API < 16 compat

* Removed NameValuePair

* We separate the media response treatment for each media provider

* MediaProvider acts as a really base provider for Media

We move all implementation to the superclass, now the code is more clear.

* Primitive type can not be nullable

* Lazy initialization of subs provider

* Removed GSON dep

* Methods can not be nullable, optional instead

* Simplified catch for all exceptions

* Return the default static navigation index

* member variables to local

* Removed unused method

* Removed unused method, modified access to inner classes

* Modified acces to getVideoPlayerApps to package, format with language

* Simplified catch, modified accesses

* Missing ACCESS_WIFI_STATE permission

* Proper Media.Torrent initialization

* Inheritance is cool

* Removed Created for Javadoc

* Fix for access to member variables

* Known if the app is in debug mode

* Picasso image loading modifications

We use fit instead resize the image, is faster.
We set the default image as the placeholder when loading a new image.

* Better Picasso initialization

* Cancel previous Picasso requests before a new one

* Prevent NPE when no image poster

* Added missing deleted check and URL rewrite for fantart

* Picasso improvements

MemoryPolicy.NO_CACHE - We do not cache images on memory to avoid big memory consumption

centerCrop - Scale the image honoring the aspect ratio until it fills the size. Crop either the top and bottom or left and right so it matches the size exactly.

* Updated butterknife dep for mobile module

* Removed the placeholder due to unexpected results on  scrolling

* debugable != BuildConfig.DEBUG, fixed cacheSize type, increased cache

* Removed unused import

* Removed the custom downloader for Picasso due to cache troubles

square/picasso#1185

* Each provider uses an own tag for request instead of the default

* Each provider cancels their own requests

* We clear old items before change genere.
Member variables to local.
Removed deprecated methods.

* Force the getMediaCallTag method impl for all MediaProvider subclasses

* Fixed deprecation

* Fix #20 Removed genre comparision

To solve the load of not initialized fragments on change genre we always load the results because does not affect performance and ensure that the movies with that genre are loaded into the MediaListFragment when we clicked on the navigation item

* Removed GSON reference

* Fixed onAttach(Activity activity) deprecation warning

* Simplified isLoading return, fixed  getPosition deprecation warning, modified acceses

* Removed the JsonProperty annotation from getters and setters

* Port to dagger

* Fixed the Url getter for Torrent object

* Fixed setOnTabSelectedListener deprecation warning

* Handle holder visibility if the Item is a VPNNavDrawerItem

* Fixed getColor deprecation warnings

* Added missing nullable import during merge
  • Loading branch information
vzamanillo authored and team-pct committed Dec 2, 2016
1 parent 0fc4fe6 commit 105dab5
Show file tree
Hide file tree
Showing 101 changed files with 2,245 additions and 1,137 deletions.
24 changes: 16 additions & 8 deletions base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {
packagingOptions {
exclude 'META-INF/beans.xml'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
}

lintOptions {
Expand All @@ -58,29 +59,36 @@ dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'

compile 'com.jakewharton.timber:timber:3.1.0'
compile 'com.squareup.okhttp:okhttp:2.6.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.6.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.jakewharton:butterknife-compiler:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.jakewharton.timber:timber:4.1.2'
compile "com.squareup.okhttp:okhttp:${rootProject.ext.okHttpVersion}"
compile "com.squareup.okhttp:okhttp-urlconnection:${rootProject.ext.okHttpVersion}"
compile "com.squareup.picasso:picasso:${rootProject.ext.picassoVersion}"
compile "com.jakewharton:butterknife:${rootProject.ext.butterknifeVersion}"

compile ('com.uwetrottmann:trakt-java:4.5.2'){
exclude group: 'org.json', module: 'json'
}
compile 'com.github.gabrielemariotti.changeloglib:changelog:2.0.0'
compile 'com.github.gabrielemariotti.changeloglib:changelog:2.1.0'

compile 'com.koushikdutta.async:androidasync:2.1.9'

compile 'com.github.sv244:torrentstream-android:1.1.1'

compile 'de.timroes:aXMLRPC:1.8.1'

compile "com.google.dagger:dagger:${rootProject.ext.daggerVersion}"

compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'

annotationProcessor "com.google.dagger:dagger-compiler:${rootProject.ext.daggerVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${rootProject.ext.butterknifeVersion}"

provided "javax.annotation:javax.annotation-api:${rootProject.ext.javaxAnnotationVersion}"

compile project(':vlc')
compile project(':connectsdk')


}
49 changes: 49 additions & 0 deletions base/src/main/java/butter/droid/base/BaseApplicationModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 javax.inject.Singleton;

import butter.droid.base.data.DataModule;
import butter.droid.base.manager.ManagerModule;
import dagger.Module;
import dagger.Provides;

@Module(
includes = {
DataModule.class,
ManagerModule.class
}
)
public class BaseApplicationModule {

private final ButterApplication application;

public BaseApplicationModule(ButterApplication application) {
this.application = application;
}

@Provides
@Singleton
public Context provideContext() {
return application;
}

}
103 changes: 42 additions & 61 deletions base/src/main/java/butter/droid/base/ButterApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,68 @@
import com.sjl.foreground.Foreground;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import butter.droid.base.beaming.BeamManager;
import butter.droid.base.content.preferences.Prefs;
import butter.droid.base.manager.updater.ButterUpdateManager;
import butter.droid.base.torrent.TorrentService;
import butter.droid.base.updater.ButterUpdater;
import butter.droid.base.utils.FileUtils;
import butter.droid.base.utils.LocaleUtils;
import butter.droid.base.utils.PrefUtils;
import butter.droid.base.utils.StorageUtils;
import butter.droid.base.utils.VersionUtils;
import timber.log.Timber;

public class ButterApplication extends Application implements ButterUpdater.Listener {
public class ButterApplication extends Application implements ButterUpdateManager.Listener {

private static OkHttpClient sHttpClient;
private static String sDefSystemLanguage;
private static Application sThis;
private static ButterApplication sThis;
private static boolean debugable;

@Inject
Picasso picasso;
@Inject
ButterUpdateManager updateManager;

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

public static ButterApplication getAppContext() {
return sThis;
}

public static String getSystemLanguage() {
return sDefSystemLanguage;
}

public static String getStreamDir() {
File path = new File(PrefUtils.get(getAppContext(), Prefs.STORAGE_LOCATION, StorageUtils.getIdealCacheDirectory(getAppContext()).toString()));
File directory = new File(path, "/torrents/");
return directory.toString();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
sDefSystemLanguage = LocaleUtils.getCurrentAsString();
}

@Override
public void onTerminate() {
// Just, so that it exists. Cause it is not executed in production, the whole application is closed anyways on OS level.
BeamManager.getInstance(getAppContext()).onDestroy();
super.onTerminate();
}

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -81,7 +113,8 @@ public void onCreate() {
Timber.plant(new Timber.DebugTree());
}

ButterUpdater.getInstance(this, this).checkUpdates(false);
updateManager.setListener(this);
updateManager.checkUpdates(false);

if(VersionUtils.isUsingCorrectBuild()) {
TorrentService.start(this);
Expand All @@ -102,55 +135,7 @@ public void onCreate() {
Timber.d("StorageLocations: " + StorageUtils.getAllStorageLocations());
Timber.i("Chosen cache location: " + directory);

Picasso.setSingletonInstance(new Picasso.Builder(getAppContext()).build());
Picasso.with(getAppContext()).setIndicatorsEnabled(debugable || BuildConfig.DEBUG);
Picasso.with(getAppContext()).setLoggingEnabled(debugable || BuildConfig.DEBUG);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
sDefSystemLanguage = LocaleUtils.getCurrentAsString();
}

@Override
public void onTerminate() {
// Just, so that it exists. Cause it is not executed in production, the whole application is closed anyways on OS level.
BeamManager.getInstance(getAppContext()).onDestroy();
super.onTerminate();
}

public static String getSystemLanguage() {
return sDefSystemLanguage;
}

public static OkHttpClient getHttpClient() {
if (sHttpClient == null) {
sHttpClient = new OkHttpClient();
sHttpClient.setConnectTimeout(30, TimeUnit.SECONDS);
sHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
sHttpClient.setRetryOnConnectionFailure(true);

long cacheSize = 10 * 1024 * 1024;
File cacheLocation = new File(PrefUtils.get(ButterApplication.getAppContext(), Prefs.STORAGE_LOCATION, StorageUtils.getIdealCacheDirectory(ButterApplication.getAppContext()).toString()));
if (!cacheLocation.mkdirs()){
Timber.w("Could not create directory: " + cacheLocation.getAbsolutePath());
}
com.squareup.okhttp.Cache cache = null;
try {
cache = new com.squareup.okhttp.Cache(cacheLocation, cacheSize);
} catch (Exception e) {
e.printStackTrace();
}
sHttpClient.setCache(cache);
}
return sHttpClient;
}

public static String getStreamDir() {
File path = new File(PrefUtils.get(getAppContext(), Prefs.STORAGE_LOCATION, StorageUtils.getIdealCacheDirectory(getAppContext()).toString()));
File directory = new File(path, "/torrents/");
return directory.toString();
Picasso.setSingletonInstance(picasso);
}

@Override
Expand All @@ -166,18 +151,14 @@ public void updateAvailable(String updateFile) {
.setDefaults(NotificationCompat.DEFAULT_ALL);

Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setDataAndType(Uri.parse("file://" + updateFile), ButterUpdater.ANDROID_PACKAGE);
notificationIntent.setDataAndType(Uri.parse("file://" + updateFile), ButterUpdateManager.ANDROID_PACKAGE);

notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0));

nm.notify(ButterUpdater.NOTIFICATION_ID, notificationBuilder.build());
nm.notify(ButterUpdateManager.NOTIFICATION_ID, notificationBuilder.build());
}
}

public static Context getAppContext() {
return sThis;
}

public static boolean isDebugable() {
return debugable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import butter.droid.base.R;
import butter.droid.base.compat.SupportedArchitectures;
import butter.droid.base.fragments.dialog.ChangeLogDialogFragment;
import butter.droid.base.updater.ButterUpdater;
import butter.droid.base.manager.provider.ProviderManager;
import butter.droid.base.manager.updater.ButterUpdateManager;
import butter.droid.base.utils.LocaleUtils;
import butter.droid.base.utils.PrefUtils;
import butter.droid.base.utils.StorageUtils;
Expand All @@ -46,15 +47,15 @@ interface OnSelectionListener {

class ItemsGenerator {

public static List<PrefItem> generate(final PreferencesHandler handler, boolean isTV) {
public static List<PrefItem> generate(final PreferencesHandler handler, ButterUpdateManager updateManager, boolean isTV) {
if(!(handler instanceof Context)) {
return new ArrayList<>();
}

return generate((Context) handler, handler, isTV);
return generate((Context) handler, handler, updateManager, isTV);
}

public static List<PrefItem> generate(final Context context, final PreferencesHandler handler, boolean isTV) {
public static List<PrefItem> generate(final Context context, final PreferencesHandler handler, final ButterUpdateManager updateManager, boolean isTV) {
List<PrefItem> prefItems = new ArrayList<>();

prefItems.add(PrefItem.newBuilder(context).setTitleResource(R.string.general).build());
Expand All @@ -68,8 +69,8 @@ public static List<PrefItem> generate(final Context context, final PreferencesHa
prefItems.add(PrefItem.newBuilder(context)
.setIconResource(R.drawable.ic_prefs_default_view)
.setTitleResource(R.string.default_view)
.setPreferenceKey(Prefs.DEFAULT_VIEW)
.setDefaultValue(0)
.setPreferenceKey(Prefs.DEFAULT_PROVIDER)
.setDefaultValue(ProviderManager.PROVIDER_TYPE_MOVIE)
.setOnClickListener(new PrefItem.OnClickListener() {
@Override
public void onClick(final PrefItem item) {
Expand Down Expand Up @@ -648,18 +649,18 @@ public String get(PrefItem item) {
prefItems.add(PrefItem.newBuilder(context)
.setIconResource(R.drawable.ic_prefs_check_update)
.setTitleResource(R.string.check_for_updates)
.setPreferenceKey(ButterUpdater.LAST_UPDATE_CHECK)
.setPreferenceKey(ButterUpdateManager.LAST_UPDATE_CHECK)
.setDefaultValue(1)
.setOnClickListener(new PrefItem.OnClickListener() {
@Override
public void onClick(final PrefItem item) {
ButterUpdater.getInstance(context).checkUpdatesManually();
updateManager.checkUpdatesManually();
}
})
.setSubtitleGenerator(new PrefItem.SubtitleGenerator() {
@Override
public String get(PrefItem item) {
long timeStamp = Long.parseLong(PrefUtils.get(context, ButterUpdater.LAST_UPDATE_CHECK, "0"));
long timeStamp = Long.parseLong(PrefUtils.get(context, ButterUpdateManager.LAST_UPDATE_CHECK, "0"));
Calendar cal = Calendar.getInstance(Locale.getDefault());
cal.setTimeInMillis(timeStamp);
String time = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault()).format(timeStamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Prefs {
public static final String REMOVE_CACHE = "remove_cache";
public static final String HW_ACCELERATION = "hw_acceleration";
public static final String AUTOMATIC_UPDATES = "auto_updates";
public static final String DEFAULT_VIEW = "default_view";
public static final String DEFAULT_PROVIDER = "default_provider";
public static final String DEFAULT_PLAYER = "default_player";
public static final String DEFAULT_PLAYER_NAME = "default_player_name";
public static final String INSTALLED_VERSION = "installed_version";
Expand Down
Loading

0 comments on commit 105dab5

Please sign in to comment.