Skip to content

Commit

Permalink
Fixe Scroll bug. Added ads only in MainActivity. Changed layout of Ma…
Browse files Browse the repository at this point in the history
…tchDetailsActivity.
  • Loading branch information
samidhtalsania committed Feb 21, 2015
1 parent e43a0c3 commit d182c85
Show file tree
Hide file tree
Showing 231 changed files with 374 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class MyDaoGenerator {

public static void main(String args[]) throws Exception {
Schema schema = new Schema(1, "greendao");
schema.enableKeepSectionsByDefault();

Entity box = schema.addEntity("Match");
box.addIdProperty();
box.addStringProperty("t1");
Expand Down
1 change: 1 addition & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="greendao-1.3.7" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="play-services-6.5.87" level="project" />
<orderEntry type="library" exported="" name="okio-1.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ dependencies {
compile 'joda-time:joda-time:2.6'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'de.greenrobot:greendao:1.3.7'
compile 'com.google.android.gms:play-services:6.+'

}
5 changes: 5 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-keepclassmembers class * extends de.greenrobot.dao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
package="com.bluealeaf.dota2ticker" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


<application
android:name=".bus.BusProvider"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand All @@ -28,6 +33,10 @@
<receiver android:name=".notification.NotificationActivity">

</receiver>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />

</application>

</manifest>
33 changes: 24 additions & 9 deletions app/src/main/java-gen/greendao/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import android.os.Parcel;
import android.os.Parcelable;

// KEEP INCLUDES - put your custom includes here
// KEEP INCLUDES END


/**
* Entity mapped to table MATCH.
*/
Expand All @@ -25,15 +29,10 @@ public Match(Long id) {
this.id = id;
}

public Match(Long id, String t1, String t2, String t1c, String t2c, Long ETA, Boolean alarm_set) {
this.id = id;
this.t1 = t1;
this.t2 = t2;
this.t1c = t1c;
this.t2c = t2c;
this.ETA = ETA;
this.alarm_set = alarm_set;
}
// KEEP FIELDS - put your custom fields here
// KEEP FIELDS END



public Long getId() {
return id;
Expand Down Expand Up @@ -91,12 +90,15 @@ public void setAlarm_set(Boolean alarm_set) {
this.alarm_set = alarm_set;
}

// KEEP METHODS - put your custom methods here

@Override
public int describeContents() {
return 0;
}

@Override

public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(t1);
Expand All @@ -119,4 +121,17 @@ private Match(Parcel in){
t1 = in.readString();
t2 = in.readString();
}


public Match(Long id, String t1, String t2, String t1c, String t2c, Long ETA, Boolean alarm_set) {
this.id = id;
this.t1 = t1;
this.t2 = t2;
this.t1c = t1c;
this.t2c = t2c;
this.ETA = ETA;
this.alarm_set = alarm_set;
}
// KEEP METHODS END

}
85 changes: 67 additions & 18 deletions app/src/main/java/com/bluealeaf/dota2ticker/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.bluealeaf.dota2ticker;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

Expand All @@ -16,6 +19,9 @@
import com.bluealeaf.dota2ticker.events.NoNewMatchesEvent;
import com.bluealeaf.dota2ticker.events.PassMatchListFromDBEvent;
import com.bluealeaf.dota2ticker.events.UpdateMatchesEvent;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.squareup.otto.Subscribe;

import java.util.ArrayList;
Expand All @@ -39,25 +45,42 @@ public class MainActivity extends ActionBarActivity {

private boolean isSwiped = false;

private Context mContext;

private static final String tag = MainActivity.class.getName();

private AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
// .detectDiskReads()
// .detectDiskWrites()
// .detectNetwork() // or .detectAll() for all detectable problems
// .penaltyLog()
// .build());
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
// .detectLeakedSqlLiteObjects()
// .detectLeakedClosableObjects()
// .penaltyLog()
// .penaltyDeath()
// .build());

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
mAdView.setVisibility(View.VISIBLE);
}
});

mContext = this;

}


Expand All @@ -76,14 +99,30 @@ protected void onResume() {
swipeRefreshLayout.setColorSchemeResources(
R.color.blue, R.color.purple,
R.color.green, R.color.orange);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener(){
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

@Override
public void onRefresh() {
BusProvider.getBusInstance().post(new GetIdFromDbEvent(OkHttpClientConst.FORCE_NETWORK));
isSwiped = true;
matches.clear();
BusProvider.getBusInstance().post(new GetIdFromDbEvent(OkHttpClientConst.FORCE_NETWORK));

}
});
listView.setItemsCanFocus(true);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Match match = (Match)listView.getItemAtPosition(position);
Intent intent = new Intent(mContext,MatchDetailsActivity.class);
intent.putExtra("MATCH_ID", match);
Log.d(tag,"Clicked");
startActivity(intent);

}
});

mAdView.resume();

//Register subscribed event
BusProvider.getBusInstance().register(this);
Expand All @@ -94,11 +133,20 @@ public void onRefresh() {
@Override
protected void onPause() {
super.onPause();
Log.d(tag,"pause");
mAdView.pause();

//Unregister subscribed event
BusProvider.getBusInstance().unregister(this);
}

public void onDestroy() {
// Destroy the AdView.
mAdView.destroy();

super.onDestroy();
}


@Subscribe
public void OnListReceivedFromDb(PassMatchListFromDBEvent event){
updateMatches(event.getMatchList());
Expand All @@ -113,7 +161,6 @@ public void OnListReceived(UpdateMatchesEvent event){
}

if(isSwiped){
Toast.makeText(this,"Updated",Toast.LENGTH_LONG).show();
isSwiped = false;
}

Expand All @@ -128,6 +175,8 @@ public int compare(Match lhs, Match rhs) {
adapter.notifyDataSetChanged();
}



Log.d(tag,"OnListReceived");

}
Expand All @@ -149,7 +198,7 @@ public void OnNoNewMatchesReceived(NoNewMatchesEvent event){
swipeRefreshLayout.setRefreshing(false);
isSwiped = false;
}
Toast.makeText(this,"Updated",Toast.LENGTH_LONG).show();

adapter.notifyDataSetChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ImageView;
import android.widget.TextView;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import greendao.Match;


Expand All @@ -16,14 +20,58 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_match_details);
Match match = getIntent().getParcelableExtra("MATCH_ID");
TextView textView = (TextView) findViewById(R.id.data);
getActionBar().setHomeButtonEnabled(true);

if(match != null){

TextView teamOne = (TextView) findViewById(R.id.t1Bold);
TextView teamTwo = (TextView) findViewById(R.id.t2Bold);

ImageView teamOneImg = (ImageView) findViewById(R.id.t1Logo);
ImageView teamTwoImg = (ImageView) findViewById(R.id.t2Logo);

teamOne.setText(match.getT1());
teamTwo.setText(match.getT2());

int t1Resource = this.getResources().getIdentifier(this.getPackageName()+":drawable/"+match.getT1().replace(" ","_").toLowerCase()+"_60px",null,null);
int t2Resource = this.getResources().getIdentifier(this.getPackageName()+":drawable/"+match.getT2().replace(" ","_").toLowerCase()+"_60px",null,null);

if(t1Resource == 0){
t1Resource = this.getResources().getIdentifier(this.getPackageName()+":drawable/unknown_30px",null,null);
}

if(t2Resource == 0){
t2Resource = this.getResources().getIdentifier(this.getPackageName()+":drawable/unknown_30px",null,null);
}

teamOneImg.setImageResource(t1Resource);
teamTwoImg.setImageResource(t2Resource);

TextView status = (TextView) findViewById(R.id.matchStatus);


long temp = match.getETA() - DateTime.now(DateTimeZone.UTC).getMillis();
temp /= 1000;
long hours = temp / 3600;
long mins = (temp % 3600) / 60;

StringBuilder sb = new StringBuilder();
sb.append(String.valueOf(hours)).append("h").append(" ").append(String.valueOf(mins)).append("m");

if(DateTime.now(DateTimeZone.UTC).getMillis() > match.getETA()-30000){
status.setText("LIVE");
}
else{
status.setText(sb.toString());
status.setTextColor(getResources().getColor(R.color.black));
}

this.setTitle(match.getT1() + " VS " + match.getT2());

textView.setText(match.getT1()+" vs. "+match.getT2());
}
else {
textView.setText("No match found.");
TextView status = (TextView) findViewById(R.id.matchStatus);
status.setText("No match");
}
}

Expand Down
Loading

0 comments on commit d182c85

Please sign in to comment.