Skip to content

Commit

Permalink
remove dagger(di)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengxiaopeng committed Nov 5, 2015
1 parent bce49b5 commit 8916495
Show file tree
Hide file tree
Showing 36 changed files with 931 additions and 1,280 deletions.
1 change: 0 additions & 1 deletion build.gradle
Expand Up @@ -7,7 +7,6 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}

Expand Down
13 changes: 1 addition & 12 deletions buildsystem/dependencies.gradle
Expand Up @@ -12,12 +12,10 @@ ext {
androidCompileSdkVersion = 23

//Libraries
daggerVersion = '2.0'
butterKnifeVersion = '7.0.1'
recyclerViewVersion = '21.0.3'
rxJavaVersion = '1.0.14'
rxAndroidVersion = '0.25.0'
javaxAnnotationVersion = '1.0'
rxAndroidVersion = '1.0.1'
gsonVersion = '2.3'
okHttpVersion = '2.5.0'
androidAnnotationsVersion = '20.0.0'
Expand All @@ -33,13 +31,10 @@ ext {


presentationDependencies = [
daggerCompiler: "com.google.dagger:dagger-compiler:${daggerVersion}",
dagger: "com.google.dagger:dagger:${daggerVersion}",
butterKnife: "com.jakewharton:butterknife:${butterKnifeVersion}",
recyclerView: "com.android.support:recyclerview-v7:${recyclerViewVersion}",
rxJava: "io.reactivex:rxjava:${rxJavaVersion}",
rxAndroid: "io.reactivex:rxandroid:${rxAndroidVersion}",
javaxAnnotation: "javax.annotation:jsr250-api:${javaxAnnotationVersion}",
]

presentationTestDependencies = [
Expand All @@ -51,9 +46,6 @@ ext {
]

domainDependencies = [
daggerCompiler: "com.google.dagger:dagger-compiler:${daggerVersion}",
dagger: "com.google.dagger:dagger:${daggerVersion}",
javaxAnnotation: "javax.annotation:jsr250-api:${javaxAnnotationVersion}",
rxJava: "io.reactivex:rxjava:${rxJavaVersion}",
]

Expand All @@ -63,13 +55,10 @@ ext {
]

dataDependencies = [
daggerCompiler: "com.google.dagger:dagger-compiler:${daggerVersion}",
dagger: "com.google.dagger:dagger:${daggerVersion}",
okHttp: "com.squareup.okhttp:okhttp:${okHttpVersion}",
gson: "com.google.code.gson:gson:${gsonVersion}",
rxJava: "io.reactivex:rxjava:${rxJavaVersion}",
rxAndroid: "io.reactivex:rxandroid:${rxAndroidVersion}",
javaxAnnotation: "javax.annotation:jsr250-api:${javaxAnnotationVersion}",
androidAnnotations: "com.android.support:support-annotations:${androidAnnotationsVersion}"
]

Expand Down
4 changes: 0 additions & 4 deletions data/build.gradle
@@ -1,5 +1,4 @@
apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'

android {
def globalConfiguration = rootProject.extensions.getByName("ext")
Expand Down Expand Up @@ -40,9 +39,6 @@ dependencies {
def testDependencies = rootProject.ext.dataTestDependencies

compile project(':domain')
apt dataDependencies.daggerCompiler
provided dataDependencies.javaxAnnotation
compile dataDependencies.dagger
compile dataDependencies.okHttp
compile dataDependencies.gson
compile dataDependencies.rxJava
Expand Down
@@ -1,12 +1,12 @@
/**
* Copyright (C) 2015 Fernando Cejas Open Source Project
*
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -17,131 +17,129 @@

import android.content.Context;
import android.content.SharedPreferences;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.inject.Inject;
import javax.inject.Singleton;

/**
* Helper class to do operations on regular files/directories.
*/
@Singleton
public class FileManager {

@Inject
public FileManager() {}
public FileManager() {
}

/**
* Writes a file to Disk.
* This is an I/O operation and this method executes in the main thread, so it is recommended to
* perform this operation using another thread.
*
* @param file The file to write to Disk.
*/
public void writeToFile(File file, String fileContent) {
if (!file.exists()) {
try {
FileWriter writer = new FileWriter(file);
writer.write(fileContent);
writer.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
/**
* Writes a file to Disk.
* This is an I/O operation and this method executes in the main thread, so it is recommended to
* perform this operation using another thread.
*
* @param file The file to write to Disk.
*/
public void writeToFile(File file, String fileContent) {
if (!file.exists()) {
try {
FileWriter writer = new FileWriter(file);
writer.write(fileContent);
writer.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {

}
}
}
}
}
}

/**
* Reads a content from a file.
* This is an I/O operation and this method executes in the main thread, so it is recommended to
* perform the operation using another thread.
*
* @param file The file to read from.
* @return A string with the content of the file.
*/
public String readFileContent(File file) {
StringBuilder fileContentBuilder = new StringBuilder();
if (file.exists()) {
String stringLine;
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while ((stringLine = bufferedReader.readLine()) != null) {
fileContentBuilder.append(stringLine + "\n");
}
bufferedReader.close();
fileReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Reads a content from a file.
* This is an I/O operation and this method executes in the main thread, so it is recommended to
* perform the operation using another thread.
*
* @param file The file to read from.
* @return A string with the content of the file.
*/
public String readFileContent(File file) {
StringBuilder fileContentBuilder = new StringBuilder();
if (file.exists()) {
String stringLine;
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while ((stringLine = bufferedReader.readLine()) != null) {
fileContentBuilder.append(stringLine + "\n");
}
bufferedReader.close();
fileReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

return fileContentBuilder.toString();
}
return fileContentBuilder.toString();
}

/**
* Returns a boolean indicating whether this file can be found on the underlying file system.
*
* @param file The file to check existence.
* @return true if this file exists, false otherwise.
*/
public boolean exists(File file) {
return file.exists();
}
/**
* Returns a boolean indicating whether this file can be found on the underlying file system.
*
* @param file The file to check existence.
* @return true if this file exists, false otherwise.
*/
public boolean exists(File file) {
return file.exists();
}

/**
* Warning: Deletes the content of a directory.
* This is an I/O operation and this method executes in the main thread, so it is recommended to
* perform the operation using another thread.
*
* @param directory The directory which its content will be deleted.
*/
public void clearDirectory(File directory) {
if (directory.exists()) {
for (File file : directory.listFiles()) {
file.delete();
}
}
}
/**
* Warning: Deletes the content of a directory.
* This is an I/O operation and this method executes in the main thread, so it is recommended to
* perform the operation using another thread.
*
* @param directory The directory which its content will be deleted.
*/
public void clearDirectory(File directory) {
if (directory.exists()) {
for (File file : directory.listFiles()) {
file.delete();
}
}
}

/**
* Write a value to a user preferences file.
*
* @param context {@link android.content.Context} to retrieve android user preferences.
* @param preferenceFileName A file name reprensenting where data will be written to.
* @param key A string for the key that will be used to retrieve the value in the future.
* @param value A long representing the value to be inserted.
*/
public void writeToPreferences(Context context, String preferenceFileName, String key,
long value) {
/**
* Write a value to a user preferences file.
*
* @param context {@link android.content.Context} to retrieve android user preferences.
* @param preferenceFileName A file name reprensenting where data will be written to.
* @param key A string for the key that will be used to retrieve the value in the future.
* @param value A long representing the value to be inserted.
*/
public void writeToPreferences(Context context, String preferenceFileName, String key,
long value) {

SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceFileName,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong(key, value);
editor.apply();
}
SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceFileName,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong(key, value);
editor.apply();
}

/**
* Get a value from a user preferences file.
*
* @param context {@link android.content.Context} to retrieve android user preferences.
* @param preferenceFileName A file name representing where data will be get from.
* @param key A key that will be used to retrieve the value from the preference file.
* @return A long representing the value retrieved from the preferences file.
*/
public long getFromPreferences(Context context, String preferenceFileName, String key) {
SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceFileName,
Context.MODE_PRIVATE);
return sharedPreferences.getLong(key, 0);
}
/**
* Get a value from a user preferences file.
*
* @param context {@link android.content.Context} to retrieve android user preferences.
* @param preferenceFileName A file name representing where data will be get from.
* @param key A key that will be used to retrieve the value from the preference file.
* @return A long representing the value retrieved from the preferences file.
*/
public long getFromPreferences(Context context, String preferenceFileName, String key) {
SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceFileName,
Context.MODE_PRIVATE);
return sharedPreferences.getLong(key, 0);
}
}

0 comments on commit 8916495

Please sign in to comment.