Skip to content

Commit

Permalink
Fixed switch bug. Added notification and on click activity for notifi…
Browse files Browse the repository at this point in the history
…cation.
  • Loading branch information
samidhtalsania committed Feb 1, 2015
1 parent dafdb47 commit e43a0c3
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class MyDaoGenerator {

public static void main(String args[]) throws Exception {
Schema schema = new Schema(2, "greendao");
Schema schema = new Schema(1, "greendao");
Entity box = schema.addEntity("Match");
box.addIdProperty();
box.addStringProperty("t1");
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bluealeaf.dota2ticker" >

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

<application
android:name=".bus.BusProvider"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".bus.BusProvider">
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MatchDetailsActivity"
android:label="@string/title_activity_match_details"
android:parentActivityName=".MainActivity">
</activity>
<receiver android:name=".notification.NotificationActivity">

</receiver>
</application>

</manifest>
4 changes: 2 additions & 2 deletions app/src/main/java-gen/greendao/DaoMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 2): knows all DAOs.
* Master of DAO (schema version 1): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 2;
public static final int SCHEMA_VERSION = 1;

/** Creates underlying database table using DAOs. */
public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
Expand Down
34 changes: 33 additions & 1 deletion app/src/main/java-gen/greendao/Match.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package greendao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit.

import android.os.Parcel;
import android.os.Parcelable;

/**
* Entity mapped to table MATCH.
*/
public class Match {
public class Match implements Parcelable{

private Long id;
private String t1;
Expand Down Expand Up @@ -87,4 +91,32 @@ public void setAlarm_set(Boolean alarm_set) {
this.alarm_set = alarm_set;
}

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

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(t1);
dest.writeString(t2);
}

public static final Parcelable.Creator<Match> CREATOR = new Parcelable.Creator<Match>() {
@Override
public Match createFromParcel(Parcel source) {
return new Match(source);
}

@Override
public Match[] newArray(int size) {
return new Match[size];
}
};
private Match(Parcel in){
id = in.readLong();
t1 = in.readString();
t2 = in.readString();
}
}
85 changes: 45 additions & 40 deletions app/src/main/java/com/bluealeaf/dota2ticker/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bluealeaf.dota2ticker;

import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
Expand Down Expand Up @@ -42,13 +43,34 @@ public class MainActivity extends ActionBarActivity {

@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());

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
matches = new ArrayList<greendao.Match>();
}



@Override
protected void onResume() {
super.onResume();

listView = (ListView) findViewById(R.id.match_list_view);
matches = new ArrayList<greendao.Match>();
adapter = new MatchListAdapter(this,matches);
listView.setAdapter(adapter);

Log.d(tag,String.valueOf(matches.size()));

swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipeRefreshLayout.setColorSchemeResources(
Expand All @@ -62,93 +84,76 @@ public void onRefresh() {
isSwiped = true;
}
});
}


@Override
protected void onResume() {
super.onResume();
//Register subscribed event
BusProvider.getBusInstance().register(this);
//Post an event to get List of Matches
BusProvider.getBusInstance().post(new GetIdFromDbEvent(OkHttpClientConst.FORCE_CACHE));
}



@Override
protected void onPause() {
super.onPause();
Log.d(tag,"pause");
//Unregister subscribed event
BusProvider.getBusInstance().unregister(this);
}

@Subscribe
public void OnListReceivedFromDb(PassMatchListFromDBEvent event){
Log.d(tag, "OnListReceivedFromDb");
// Log.d(tag,String.valueOf(event.getMatchList().size()));
if(matches.size() != 0){
matches.clear();

}
updateMatches(event.getMatchList());
Log.d(tag,String.valueOf(matches.size()));
adapter.notifyDataSetChanged();
}

@Subscribe
public void OnListReceived(UpdateMatchesEvent event){

Log.d(tag, "OnListReceived");
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
}

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

if(isSwiped){
Toast.makeText(this,"Updated",Toast.LENGTH_LONG).show();
isSwiped = false;
}
if (event.getMatches().size() != 0) {
updateMatches(event.getMatches());
Collections.sort(matches, new Comparator<Match>() {
@Override
public int compare(Match lhs, Match rhs) {
return lhs.getETA().compareTo(rhs.getETA());
}
});
adapter.notifyDataSetChanged();
}

if (event.getMatches().size() != 0) {
updateMatches(event.getMatches());
Collections.sort(matches, new Comparator<Match>() {
@Override
public int compare(Match lhs, Match rhs) {
return lhs.getETA().compareTo(rhs.getETA());
}
});
Log.d(tag, String.valueOf(matches.size()));
adapter.notifyDataSetChanged();
}
Log.d(tag,"OnListReceived");

}

@Subscribe
public void OnConnectionError(ConnectionErrorEvent event){
Log.d(tag, "OnConnectionError");
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
isSwiped = false;
}
Toast.makeText(this,event.getMessage(),Toast.LENGTH_LONG).show();
adapter.notifyDataSetChanged();
Log.d(tag,"OnConnectionError");
}

@Subscribe
public void OnNoNewMatchesReceived(NoNewMatchesEvent event){
Log.d(tag, "OnNoNewMatchesReceived");
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
isSwiped = false;
}
Log.d(tag, String.valueOf(matches.size()));
Toast.makeText(this,"Updated",Toast.LENGTH_LONG).show();
adapter.notifyDataSetChanged();
}

private synchronized void updateMatches(List<Match> matches){
Log.d(tag,"matches");
this.matches.addAll(matches);
Log.d(tag,String.valueOf(this.matches.size()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.bluealeaf.dota2ticker;

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

import greendao.Match;


public class MatchDetailsActivity extends ActionBarActivity {

private Match match ;

@Override
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);
if(match != null){


textView.setText(match.getT1()+" vs. "+match.getT2());
}
else {
textView.setText("No match found.");
}
}


}
Loading

0 comments on commit e43a0c3

Please sign in to comment.