Skip to content

Commit

Permalink
ADD: added firebase database methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bxute committed Apr 12, 2018
1 parent 72e6767 commit 0fb742f
Show file tree
Hide file tree
Showing 39 changed files with 952 additions and 110 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
implementation 'com.google.android.gms:play-services-ads:12.0.1'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.google.firebase:firebase-database:12.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}







apply plugin: 'com.google.gms.google-services'
25 changes: 19 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".main.KitiAppMain"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".KitiAppMain"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HomeActivity" />
<activity android:name=".LoginActivity">
<activity android:name=".activity.OptionsActivity" />
<activity android:name=".activity.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BannerAdActivity" />
<activity android:name=".InterstitalAdActivity" />
<activity android:name=".VideoAdActivity"></activity>
<activity android:name=".activity.BannerAdActivity" />
<activity android:name=".activity.InterstitalAdActivity" />
<activity android:name=".activity.VideoAdActivity" />

<service
android:name=".scheduler.ShowAdJobService"
android:exported="false">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE" />
</intent-filter>
</service>

<activity
android:name=".activity.MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

</manifest>
32 changes: 0 additions & 32 deletions app/src/main/java/app/kiti/com/kitiapp/HomeActivity.java

This file was deleted.

46 changes: 0 additions & 46 deletions app/src/main/java/app/kiti/com/kitiapp/PreferenceManager.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package app.kiti.com.kitiapp;
package app.kiti.com.kitiapp.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

import app.kiti.com.kitiapp.R;
import app.kiti.com.kitiapp.firebase.SyncManager;
import app.kiti.com.kitiapp.utils.FirebaseDataField;

public class BannerAdActivity extends AppCompatActivity {

// TODO: 4/11/2018 Put Production App id to ads, after testing

private AdView mAdView;
private SyncManager syncManager;
public static final String TAG = BannerAdActivity.class.getSimpleName();

@Override
Expand All @@ -28,26 +34,30 @@ private void init() {
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(adListener);
syncManager = new SyncManager();

}

private AdListener adListener = new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Log.d(TAG,"Ad Loaded");
Log.d(TAG, "Ad Loaded");
}

@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
Log.d(TAG,"Failed to Load ad");
Log.d(TAG, "Failed to Load ad");
}

@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
Log.d(TAG,"Ad Opened");
Log.d(TAG, "Ad Opened");
syncManager.setAdClick(FirebaseDataField.BANNER_AD);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.kiti.com.kitiapp;
package app.kiti.com.kitiapp.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand All @@ -9,10 +9,15 @@
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;

import app.kiti.com.kitiapp.R;
import app.kiti.com.kitiapp.firebase.SyncManager;
import app.kiti.com.kitiapp.utils.FirebaseDataField;

public class InterstitalAdActivity extends AppCompatActivity {

public static final String TAG = InterstitalAdActivity.class.getSimpleName();
private InterstitialAd mInterstitialAd;
private SyncManager syncManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -38,6 +43,7 @@ private void init() {
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(adListener);
syncManager = new SyncManager();

}

Expand All @@ -60,6 +66,8 @@ public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
Log.d(TAG, "Ad Opened");
syncManager.setAdClick(FirebaseDataField.INTERSTITAL_AD);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.kiti.com.kitiapp;
package app.kiti.com.kitiapp.activity;

import android.content.Intent;
import android.os.Bundle;
Expand All @@ -22,6 +22,8 @@

import java.util.concurrent.TimeUnit;

import app.kiti.com.kitiapp.preference.PreferenceManager;
import app.kiti.com.kitiapp.R;
import butterknife.BindView;
import butterknife.ButterKnife;

Expand Down Expand Up @@ -142,7 +144,7 @@ public void onComplete(@NonNull Task<AuthResult> task) {
}

private void navigateToHomePage() {
Intent homeIntent = new Intent(this, HomeActivity.class);
Intent homeIntent = new Intent(this,MainActivity.class);
startActivity(homeIntent);
}

Expand Down
108 changes: 108 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package app.kiti.com.kitiapp.activity;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;

import app.kiti.com.kitiapp.R;
import app.kiti.com.kitiapp.firebase.SyncManager;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

private SyncManager syncManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
syncManager = new SyncManager();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.earning) {
// Handle the camera action
} else if (id == R.id.pending) {

} else if (id == R.id.history) {

} else if (id == R.id.help) {

} else if (id == R.id.about_us) {

}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

private void attachBalanceListener(){

DatabaseReference balanceRef = syncManager.getBalanceNodeRef();
if(balanceRef!=null){
balanceRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String balance = (String) dataSnapshot.getValue();
//set value to UI
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}else{
//show error
}
}

}
Loading

0 comments on commit 0fb742f

Please sign in to comment.