Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request namibsun/android/bundesliga-tippspiel-android!1
  • Loading branch information
namboy94 committed Sep 4, 2018
2 parents 08f471a + 485f902 commit f3064f1
Show file tree
Hide file tree
Showing 21 changed files with 290 additions and 163 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
V 1.1.0:
- Now uses V2 of the API
V 1.0.5:
- Small project fixes
V 1.0.4:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG-de-DE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
V 1.1.0:
- Verwendet nun V2 der API
V 1.0.5:
- Kleine Projekt-Fixes
V 1.0.4:
Expand Down
18 changes: 18 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License
along with bundesliga-tippspiel-android. If not, see <http://www.gnu.org/licenses/>.
*/

apply plugin: "com.android.application"
apply plugin: "kotlin-android"

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
Expand All @@ -38,3 +41,18 @@ android {
exclude 'META-INF/*'
}
}

dependencies {
api "com.android.support:appcompat-v7:27.1.1"
api "com.android.support:support-v4:27.1.1"
api "com.android.support:cardview-v7:27.1.1"
api "org.jetbrains.anko:anko-commons:0.10.5"
api 'com.google.code.gson:gson:2.8.5'
api "com.squareup.okhttp3:okhttp:3.10.0"
testImplementation 'org.json:json:20180130'
// api project(':lib')
}

apply from: "$rootDir/gradle-config/jacoco-android.gradle"
apply from: "$rootDir/gradle-config/dokka-android.gradle"
apply from: "$rootDir/gradle-config/ktlint.gradle"
8 changes: 3 additions & 5 deletions app/src/main/kotlin/net/namibsun/hktipp/BetActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class BetActivity : AppCompatActivity() {

Log.i("BetActivity", "Updating Data")

val username = this.username!!
val apiKey = this.apiKey!!
val matchday = this.matchDay

Expand All @@ -149,8 +148,8 @@ class BetActivity : AppCompatActivity() {

try {

val matches = getMatches(username, apiKey, matchday)
val bets = getBets(username, apiKey, matchday)
val matches = getMatches(apiKey, matchday)
val bets = getBets(apiKey, matchday)
Log.i("BetActivity", "Data successfully fetched")

// Update Matchday (Only has an effect if matchday == -1). Also reset BetViews
Expand All @@ -166,7 +165,6 @@ class BetActivity : AppCompatActivity() {
this@BetActivity.setUiElementEnabledState(true)
}
} catch (e: IOException) { // If failed to fetch data, log out
Log.e("BetActivity", "Failed to fetch data")
this@BetActivity.runOnUiThread {
showErrorDialog(this@BetActivity,
R.string.bets_fetching_error_title,
Expand Down Expand Up @@ -256,7 +254,7 @@ class BetActivity : AppCompatActivity() {
this.findViewById<View>(R.id.bets_progress).visibility = View.VISIBLE

this.doAsync {
val result = placeBets(this@BetActivity.username!!, this@BetActivity.apiKey!!, json)
val result = placeBets(this@BetActivity.apiKey!!, json)
this@BetActivity.runOnUiThread {
if (!result) {
showErrorDialog(this@BetActivity,
Expand Down
32 changes: 23 additions & 9 deletions app/src/main/kotlin/net/namibsun/hktipp/LeaderboardActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import android.view.View
import android.widget.LinearLayout
import android.widget.ProgressBar
import org.jetbrains.anko.doAsync
import net.namibsun.hktipp.helper.post
import net.namibsun.hktipp.helper.request
import net.namibsun.hktipp.helper.HTTPMETHOD
import net.namibsun.hktipp.views.LeaderboardEntryView
import org.json.JSONObject
import org.json.JSONArray

/**
* Activity that displays the current leadeboard of the hk-tippspiel website
Expand All @@ -39,6 +40,11 @@ class LeaderboardActivity : AppCompatActivity() {
*/
private var username: String? = null

/**
* The API Key of the logged in user
*/
private var apiKey: String? = null

/**
* Initializes the Activity. Populates the leaderboard.
* @param savedInstanceState: The Instance Information of the app.
Expand All @@ -49,10 +55,16 @@ class LeaderboardActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

this.username = intent.extras.getString("username")
this.apiKey = intent.extras.getString("api_key")

this.findViewById<ProgressBar>(R.id.leaderboard_progress).visibility = View.VISIBLE
this.doAsync {
val rankings = post("get_rankings", "").getJSONObject("data")
val rankings = request(
"leaderboard",
HTTPMETHOD.GET,
mutableMapOf(),
this@LeaderboardActivity.apiKey
).getJSONObject("data").getJSONArray("leaderboard")
this@LeaderboardActivity.runOnUiThread {
this@LeaderboardActivity.populateList(rankings)
}
Expand All @@ -63,18 +75,20 @@ class LeaderboardActivity : AppCompatActivity() {
* Populates the leaderboard with custom leaderboard entry views
* @param rankings: The JSON ranking data
*/
private fun populateList(rankings: JSONObject) {
private fun populateList(rankings: JSONArray) {
this.findViewById<ProgressBar>(R.id.leaderboard_progress).visibility = View.INVISIBLE

val list = this.findViewById<LinearLayout>(R.id.leaderboard_list)
list.removeAllViews()

for (position in rankings.keys()) {
val userData = rankings.getJSONObject(position)
for (i in 0..(rankings.length() - 1)) {
val rankData = rankings.getJSONArray(i)
val userData = rankData.getJSONObject(0)
val name = userData.getString("username")
val points = userData.getInt("points")
val view = LeaderboardEntryView(this, position, name, "$points")
val points = rankData.getInt(1)
val rank = i + 1
val view = LeaderboardEntryView(this, "$rank", name, "$points")
list.addView(view)
}
}
}
}
19 changes: 10 additions & 9 deletions app/src/main/kotlin/net/namibsun/hktipp/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import net.namibsun.hktipp.helper.getApiKeyFromSharedPreferences
import net.namibsun.hktipp.helper.getUsernameFromPreferences
import net.namibsun.hktipp.helper.storeApiKeyInSharedPreferences
import net.namibsun.hktipp.helper.storeUsernameInSharedPreferences
import net.namibsun.hktipp.helper.post
import net.namibsun.hktipp.helper.request
import net.namibsun.hktipp.helper.HTTPMETHOD
import org.jetbrains.anko.doAsync
import org.json.JSONObject

Expand Down Expand Up @@ -70,7 +71,7 @@ class LoginActivity : AppCompatActivity() {
}

this.findViewById<View>(R.id.login_screen_register_button).setOnClickListener {
val uri = Uri.parse("https://hk-tippspiel.com/signup.php")
val uri = Uri.parse("https://hk-tippspiel.com/register")
val intent = Intent(Intent.ACTION_VIEW, uri)
this.startActivity(intent)
}
Expand All @@ -97,12 +98,11 @@ class LoginActivity : AppCompatActivity() {
// Log in or authorize the existing API Key
val response = if (apiKey != "" && password == "******") {
Log.i("LoginActivity", "Authorizing existing API key")
val json = "{\"username\":\"$username\", \"api_key\":\"$apiKey\"}"
post("authorize", json)
request("authorize", HTTPMETHOD.GET, mutableMapOf(), apiKey)
} else {
Log.i("LoginActivity", "Attempting to log in using password")
val json = "{\"username\":\"$username\", \"password\":\"$password\"}"
post("request_api_key", json)
val json = mutableMapOf<String, Any>("username" to username, "password" to password)
request("api_key", HTTPMETHOD.POST, json)
}

this@LoginActivity.runOnUiThread {
Expand All @@ -124,13 +124,14 @@ class LoginActivity : AppCompatActivity() {
*/
private fun handleLoginResponse(response: JSONObject, username: String, apiKey: String?) {

if (response.getString("status") == "success") { // Login successful
if (response.getString("status") == "ok") { // Login successful

Log.i("LoginActivity", "Login Successful")

// Check for valid API key
val validApiKey = if (response.has("key")) {
response.getString("key") // Login API Action
val responseData = response.getJSONObject("data")
val validApiKey = if (responseData.has("api_key")) {
responseData.getString("api_key") // Login API Action
} else {
apiKey!! // Authorize API Action
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class SingleMatchActivity : AppCompatActivity() {
this.findViewById<View>(R.id.single_match_goals_progress).visibility = View.VISIBLE
this.doAsync {
val goals = getGoalsForMatch(
this@SingleMatchActivity.username!!,
this@SingleMatchActivity.apiKey!!,
this@SingleMatchActivity.matchData!!.id
)
Expand All @@ -161,7 +160,6 @@ class SingleMatchActivity : AppCompatActivity() {
this.findViewById<View>(R.id.single_match_bets_progress).visibility = View.VISIBLE
this.doAsync {
val bets = getBetsForMatch(
this@SingleMatchActivity.username!!,
this@SingleMatchActivity.apiKey!!,
this@SingleMatchActivity.matchData!!.id
)
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/kotlin/net/namibsun/hktipp/data/GoalData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ class GoalData(data: JSONObject) : Serializable {
*/
val minute = data.getInt("minute")

/**
* The minute of extra time in which the goal was scored
*/
val minuteEt = data.getInt("minute_et")

/**
* Indicates if the goal was an own goal or not
*/
val ownGoal = data.getBoolean("owngoal")
val ownGoal = data.getBoolean("own_goal")

/**
* Indicates if the goal was scored via penalty shot or not
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/kotlin/net/namibsun/hktipp/data/MatchData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ class MatchData(data: JSONObject) : Serializable {
*/
val awayTeam = TeamData(data.getJSONObject("away_team")!!)

/**
* The current score of the home team
*/
val homeCurrentScore = data.getInt("home_current_score")

/**
* The current score of the away team
*/
val awayCurrentScore = data.getInt("away_current_score")

/**
* The home team's half-time score
*/
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/net/namibsun/hktipp/data/TeamData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TeamData(data: JSONObject) : Serializable {
/**
* The shortform version of the team's name
*/
val shortName = data.getString("shortname")!!
val shortName = data.getString("short_name")!!

/**
* The team's 3-letter abbreviation
Expand All @@ -51,5 +51,5 @@ class TeamData(data: JSONObject) : Serializable {
/**
* The path to the team's icon
*/
val iconPath = data.getString("icon")!!
val iconPath = data.getString("icon_png")!!
}
Loading

0 comments on commit f3064f1

Please sign in to comment.