Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from brookmg/v0.2.1
Browse files Browse the repository at this point in the history
V0.2.1
  • Loading branch information
brookmg authored Jan 18, 2019
2 parents 97b71ae + b4090ac commit 53b6776
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

DummyResponses.java
league_dummy.html
2 changes: 1 addition & 1 deletion .idea/copyright/Apache2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "io.brookmg.soccerethiopia"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionCode apiMajorVersion * 1_000_000 + apiMinorVersion * 1_000 + apiBuildVersion
versionName String.valueOf(apiMajorVersion) + "." + String.valueOf(apiMinorVersion) + "." + String.valueOf(apiBuildVersion)
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
26 changes: 25 additions & 1 deletion app/src/main/java/io/brookmg/soccerethiopia/SampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,31 @@ protected void onCreate(Bundle savedInstanceState) {
new SoccerEthiopiaApi(this).getLeagueScheduleOfWeek(5,
scheduleItems -> {
for (LeagueScheduleItem item : scheduleItems) {
Log.v("data_league" , item.getGameWeek() + " | " + item.getGameDetail() + " | " + item.getGameDate() + " | " + item.getGameStatus());
Log.v("data_league_week_5" , item.getGameWeek() + " | " + item.getGameDetail() + " | " + item.getGameDate() + " | " + item.getGameStatus());
}
},
error -> Log.e("Error_League" , error));

new SoccerEthiopiaApi(this).getThisWeekLeagueSchedule(
scheduleItems -> {
for (LeagueScheduleItem item : scheduleItems) {
Log.v("data_this_week" , item.getGameWeek() + " | " + item.getGameDetail() + " | " + item.getGameDate() + " | " + item.getGameStatus());
}
},
error -> Log.e("Error_League" , error));

new SoccerEthiopiaApi(this).getLastWeekLeagueSchedule(
scheduleItems -> {
for (LeagueScheduleItem item : scheduleItems) {
Log.v("data_last_week" , item.getGameWeek() + " | " + item.getGameDetail() + " | " + item.getGameDate() + " | " + item.getGameStatus());
}
},
error -> Log.e("Error_League" , error));

new SoccerEthiopiaApi(this).getNextWeekLeagueSchedule(
scheduleItems -> {
for (LeagueScheduleItem item : scheduleItems) {
Log.v("data_next_week" , item.getGameWeek() + " | " + item.getGameDetail() + " | " + item.getGameDate() + " | " + item.getGameStatus());
}
},
error -> Log.e("Error_League" , error));
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ buildscript {
}
}

ext {
apiMajorVersion = 0
apiMinorVersion = 2
apiBuildVersion = 1
}

allprojects {
repositories {
google()
Expand Down
5 changes: 3 additions & 2 deletions soccerethiopiaapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"

versionCode apiMajorVersion * 1_000_000 + apiMinorVersion * 1_000 + apiBuildVersion
versionName String.valueOf(apiMajorVersion) + "." + String.valueOf(apiMinorVersion) + "." + String.valueOf(apiBuildVersion)

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,31 @@ public void getLeagueScheduleOfWeek ( int week , LeagueScheduleFetch.OnLeagueSch
LeagueScheduleFetch.getLeagueScheduleOfWeek(week, mainRequestQueue, processed, error);
}

/**
* Main Function to get this week's league schedule for current session
* @param processed - a callback to handle the processed array-list
* @param error - a callback to handle any error
*/
public void getThisWeekLeagueSchedule ( LeagueScheduleFetch.OnLeagueScheduleDataProcessed processed, StandingFetch.OnError error) {
LeagueScheduleFetch.getThisWeekLeagueSchedule(mainRequestQueue , processed , error);
}

/**
* Main Function to get this week's league schedule for current session
* @param processed - a callback to handle the processed array-list
* @param error - a callback to handle any error
*/
public void getLastWeekLeagueSchedule ( LeagueScheduleFetch.OnLeagueScheduleDataProcessed processed, StandingFetch.OnError error) {
LeagueScheduleFetch.getLastWeekLeagueSchedule(mainRequestQueue , processed , error);
}

/**
* Main Function to get this week's league schedule for current session
* @param processed - a callback to handle the processed array-list
* @param error - a callback to handle any error
*/
public void getNextWeekLeagueSchedule ( LeagueScheduleFetch.OnLeagueScheduleDataProcessed processed, StandingFetch.OnError error) {
LeagueScheduleFetch.getNextWeekLeagueSchedule(mainRequestQueue , processed , error);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public class LeagueItemStatus {
@IntDef(value = {STATUS_TOOK_PLACE , STATUS_POSTPONED, STATUS_CANCELLED, STATUS_NORMAL})
public @interface GameStatus{}

public static final int STATUS_TOOK_PLACE = 101, STATUS_CANCELLED = 102, STATUS_POSTPONED = 103, STATUS_NORMAL = 104;
public static final int STATUS_TOOK_PLACE = 101;
private static final int STATUS_CANCELLED = 102;
public static final int STATUS_POSTPONED = 103;
public static final int STATUS_NORMAL = 104;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2019 Brook Mezgebu
*
* 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
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.brookmg.soccerethiopiaapi.network;

import android.support.annotation.Nullable;
import com.android.volley.Cache;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;

import java.io.UnsupportedEncodingException;

/**
* Created by BrookMG on 1/13/2019 in io.brookmg.soccerethiopiaapi.network
* inside the project SoccerEthiopia .
*/
@SuppressWarnings("unused")
class CachedStringRequest extends StringRequest {

private long cacheHitButRefreshed = 3 * 60 * 1000;
private long cacheExpired = 24 * 60 * 60 * 1000;


public CachedStringRequest(int method, String url, Response.Listener<String> listener, @Nullable Response.ErrorListener errorListener) {
super(method, url, listener, errorListener);
}

public CachedStringRequest(int method, String url, Response.Listener<String> listener, @Nullable Response.ErrorListener errorListener, long cacheHitButRefreshed) {
super(method, url, listener, errorListener);
this.cacheHitButRefreshed = cacheHitButRefreshed;
}

public CachedStringRequest(int method, String url, Response.Listener<String> listener, @Nullable Response.ErrorListener errorListener, long cacheHitButRefreshed, long cacheExpired) {
super(method, url, listener, errorListener);
this.cacheExpired = cacheExpired;
this.cacheHitButRefreshed = cacheHitButRefreshed;
}

@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
try {
Cache.Entry entry = (HttpHeaderParser.parseCacheHeaders(response) == null) ? new Cache.Entry() : HttpHeaderParser.parseCacheHeaders(response);
long now = System.currentTimeMillis();

final long softExpired = now + cacheHitButRefreshed;
final long ttl = now + cacheExpired;

entry.softTtl = softExpired;
entry.ttl = ttl;
entry.data = response.data;

String header = response.headers.get("Date");
if (header != null) entry.serverDate = HttpHeaderParser.parseDateAsEpoch(header);

header = response.headers.get("Last-Modified");
if (header != null) entry.lastModified = HttpHeaderParser.parseDateAsEpoch(header);

entry.responseHeaders = response.headers;
return Response.success(new String(response.data , HttpHeaderParser.parseCharset(response.headers)) , entry);

} catch (UnsupportedEncodingException encodingEx) {
return Response.error(new ParseError(encodingEx));
}
}
}
Loading

1 comment on commit 53b6776

@brookmg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO BREAKING CHANGES.
Added functionalities:
getThisWeekLeagueSchedule(...)
getLastWeekLeagueSchedule(...)
getNextWeekLeagueSchedule(...)

Please sign in to comment.