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

add GoogleAnalytics and Dagger #16

Merged
merged 1 commit into from May 13, 2016
Jump to file or symbol
Failed to load files and symbols.
+162 −27
Diff settings

Always

Just for now

View
@@ -9,6 +9,7 @@ buildscript {
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'
repositories {
maven { url 'https://maven.fabric.io/public' }
@@ -46,6 +47,7 @@ android {
debug {
applicationIdSuffix ".debug"
ext.enableCrashlytics = false
buildConfigField("String", "GA_TRACKING_ID", "\"UA-77698878-2\"")
}
develop {
@@ -60,20 +62,29 @@ android {
betaDistributionGroupAliases = "beta_tester"
betaDistributionReleaseNotes = releaseNotes
}
buildConfigField("String", "GA_TRACKING_ID", "\"UA-77698878-2\"")
}
release {
minifyEnabled false
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
buildConfigField("String", "GA_TRACKING_ID", "\"UA-77698878-1\"")
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
// Google
compile 'com.google.android.gms:play-services-base:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
//DI
compile 'com.google.dagger:dagger:2.2'
apt 'com.google.dagger:dagger-compiler:2.2'
provided 'javax.annotation:jsr250-api:1.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
transitive = true;
@@ -2,7 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bowyer.app.playermanage">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:name=".PlayerApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
@@ -15,10 +19,12 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="io.fabric.ApiKey"
android:value="fd468741ae1b6b1421dbf1ae93231c7f66bc467b" />
</application>
<meta-data
android:name="io.fabric.ApiKey"
android:value="fd468741ae1b6b1421dbf1ae93231c7f66bc467b"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
@@ -0,0 +1,66 @@
package com.bowyer.app.playermanage;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import javax.inject.Inject;
public class AnalyticsTracker {
final Tracker tracker;
@Inject public AnalyticsTracker(Tracker tracker) {
this.tracker = tracker;
}
public void sendScreenView(String screenName) {
tracker.setScreenName(screenName);
tracker.send(new HitBuilders.ScreenViewBuilder().build());
}
public void sendEvent(Category category, Action action) {
if (category == null || action == null) {
return;
}
tracker.send(new HitBuilders.EventBuilder(category.getCategoty(), action.getAction()).build());
}
public void sendEvent(Category category, Action action, String label) {
if (category == null || action == null) {
return;
}
tracker.send(
new HitBuilders.EventBuilder(category.getCategoty(), action.getAction()).setLabel(label)
.build());
}
public enum Category {
DEFAULT("default");
String categoty;
Category(String categoty) {
this.categoty = categoty;
}
public String getCategoty() {
return categoty;
}
}
public enum Action {
ADD_PLAYER_FAB_TAP("add-player-fab-tap"),
SEARCH_PLAYER_TAP("search-player-tap"),
EXPAND_SEARCH_PLAYER("expand-search-player"),
PLAYER_SEX_TAP("player-sex-tap"),
PLAYER_SAVE("player-save");
String action;
Action(String action) {
this.action = action;
}
public String getAction() {
return action;
}
}
}
@@ -2,16 +2,20 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;
import javax.inject.Inject;
public class MainActivity extends AppCompatActivity {
@Inject AnalyticsTracker mAnalyticsTracker;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!BuildConfig.DEBUG) {
Fabric.with(this, new Crashlytics());
}
setContentView(R.layout.activity_main);
PlayerApplication.getComponent(getApplicationContext()).inject(this);
}
@Override protected void onResume() {
super.onResume();
mAnalyticsTracker.sendScreenView(this.getLocalClassName());
}
}
@@ -0,0 +1,9 @@
package com.bowyer.app.playermanage;
import dagger.Component;
import javax.inject.Singleton;
@Singleton @Component(modules = PlayerModule.class) public interface PlayerAppComponent {
void inject(MainActivity activity);
}
@@ -0,0 +1,23 @@
package com.bowyer.app.playermanage;
import android.app.Application;
import android.content.Context;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;
public class PlayerApplication extends Application {
private PlayerAppComponent playerAppComponent;
@Override public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG) {
Fabric.with(this, new Crashlytics());
}
playerAppComponent = DaggerPlayerAppComponent.builder()
.playerModule(new PlayerModule(this)).build();
}
public static PlayerAppComponent getComponent(Context context) {
return ((PlayerApplication) context.getApplicationContext()).playerAppComponent;
}
}
@@ -0,0 +1,29 @@
package com.bowyer.app.playermanage;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
@Module public final class PlayerModule {
private final Application application;
PlayerModule(Application application) {
this.application = application;
}
@Provides @Singleton Application provideApplication() {
return application;
}
@Singleton @Provides public Tracker provideGoogleAnalyticsTracker(Application application) {
GoogleAnalytics ga = GoogleAnalytics.getInstance(application);
Tracker tracker = ga.newTracker(BuildConfig.GA_TRACKING_ID);
tracker.enableAdvertisingIdCollection(true);
tracker.enableExceptionReporting(true);
return tracker;
}
}

This file was deleted.

Oops, something went wrong.
View
@@ -3,10 +3,11 @@
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
ProTip! Use n and p to navigate between commits in a pull request.