Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//noinspection GradleCompatible
apply plugin: 'kotlin-multiplatform'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-kapt'
Expand All @@ -11,8 +10,8 @@ android {
applicationId "com.bogdan.codeforceswatcher"
minSdkVersion 21
targetSdkVersion 29
versionCode 24
versionName "1.4.4"
versionCode 25
versionName "1.4.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
Expand All @@ -30,6 +29,7 @@ android {
signingConfig signingConfigs.releaseConfig
}
debug {
matchingFallbacks = ['release']
applicationIdSuffix ".debug"
}
}
Expand All @@ -41,6 +41,12 @@ android {
exclude "**/*.kotlin_module"
exclude 'META-INF/*.kotlin_module'
}
sourceSets {
main {
java.srcDirs += 'src/main/kotlin'
res.srcDirs += 'src/main/res'
}
}
}

kotlin {
Expand Down Expand Up @@ -83,8 +89,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
implementation 'androidx.room:room-runtime:2.2.1'
kapt 'androidx.room:room-compiler:2.2.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
Expand All @@ -95,6 +99,8 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2"

implementation "com.squareup.okhttp3:logging-interceptor:4.2.1"
implementation "com.squareup.sqldelight:android-driver:$sqlDelight_version"
implementation "com.squareup.sqldelight:sqlite-driver:$sqlDelight_version"
}

apply plugin: 'com.google.gms.google-services'
20 changes: 13 additions & 7 deletions app/src/main/java/com/bogdan/codeforceswatcher/CwApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import com.bogdan.codeforceswatcher.features.users.redux.requests.Source
import com.bogdan.codeforceswatcher.features.users.redux.requests.UsersRequests
import com.bogdan.codeforceswatcher.receiver.StartAlarm
import com.bogdan.codeforceswatcher.redux.middlewares.appMiddleware
import com.bogdan.codeforceswatcher.redux.reducers.appReducer
import com.bogdan.codeforceswatcher.redux.middlewares.toastMiddleware
import com.bogdan.codeforceswatcher.redux.middlewares.notificationMiddleware
import com.bogdan.codeforceswatcher.room.RoomController
import com.bogdan.codeforceswatcher.redux.middlewares.toastMiddleware
import com.bogdan.codeforceswatcher.redux.reducers.appReducer
import com.bogdan.codeforceswatcher.room.DatabaseController
import com.bogdan.codeforceswatcher.util.PersistenceController
import com.bogdan.codeforceswatcher.util.Prefs
import com.google.firebase.analytics.FirebaseAnalytics
import com.squareup.sqldelight.android.AndroidSqliteDriver
import io.xorum.codeforceswatcher.CWDatabase
import redux.sqlDriver
import tw.geothings.rekotlin.Store

val store = Store(
reducer = ::appReducer,
state = RoomController.fetchAppState(),
state = DatabaseController.fetchAppState(),
middleware = listOf(
appMiddleware, notificationMiddleware, toastMiddleware
)
Expand All @@ -33,12 +36,12 @@ class CwApp : Application() {

app = this

RoomController.onAppCreated()
initDatabase()
DatabaseController.onAppCreated()
PersistenceController.onAppCreated()
FirebaseAnalytics.getInstance(this)

val prefs = Prefs.get()

fetchData()

if (prefs.readAlarm().isEmpty()) {
Expand All @@ -61,8 +64,11 @@ class CwApp : Application() {
sendBroadcast(intent)
}

companion object {
private fun initDatabase() {
sqlDriver = AndroidSqliteDriver(CWDatabase.Schema, app.applicationContext, "database")
}

companion object {
lateinit var app: CwApp
private set
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.core.text.HtmlCompat
import com.bogdan.codeforceswatcher.CwApp
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.features.actions.models.CFAction
import com.bogdan.codeforceswatcher.features.users.models.User
import io.xorum.codeforceswatcher.features.users.models.User
import com.bogdan.codeforceswatcher.network.RestClient
import com.bogdan.codeforceswatcher.network.getUsers
import com.bogdan.codeforceswatcher.network.models.UsersRequestResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package com.bogdan.codeforceswatcher.features.add_user.redux.requests

import com.bogdan.codeforceswatcher.CwApp
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.features.users.models.User
import com.bogdan.codeforceswatcher.network.getUsers
import com.bogdan.codeforceswatcher.network.models.UsersRequestResult
import com.bogdan.codeforceswatcher.redux.Request
import com.bogdan.codeforceswatcher.redux.actions.ToastAction
import com.bogdan.codeforceswatcher.room.DatabaseClient
import com.bogdan.codeforceswatcher.store
import io.xorum.codeforceswatcher.db.DatabaseQueries
import io.xorum.codeforceswatcher.features.users.models.User
import tw.geothings.rekotlin.Action

class AddUserRequests {
Expand All @@ -22,14 +22,15 @@ class AddUserRequests {
}

private fun addUser(user: User) {
val foundUser = DatabaseClient.userDao.getAll()
val foundUser = DatabaseQueries.Users.getAll()
.find { currentUser -> currentUser.handle == user.handle }

if (foundUser == null) {
user.id = DatabaseClient.userDao.insert(user)
user.id = DatabaseQueries.Users.insert(user)
store.dispatch(Success(user))
} else
} else {
store.dispatch(Failure(CwApp.app.getString(R.string.user_already_added)))
}
}

data class Success(val user: User) : Action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.features.contests.models.Contest
import io.xorum.codeforceswatcher.features.contests.models.Contest
import kotlinx.android.synthetic.main.view_contest_item.view.*
import java.text.SimpleDateFormat
import java.util.*
Expand All @@ -31,7 +31,7 @@ class ContestsAdapter(
val contest = items[position]
with(holder) {
tvContestName.text = contest.name
tvContestTime.text = getDateTime(contest.time)
tvContestTime.text = getDateTime(contest.startTimeSeconds)

onClickListener = { itemClickListener.invoke(contest) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.features.contests.models.Contest
import io.xorum.codeforceswatcher.features.contests.models.Contest
import com.bogdan.codeforceswatcher.features.contests.redux.requests.ContestsRequests
import com.bogdan.codeforceswatcher.features.contests.redux.states.ContestsState
import com.bogdan.codeforceswatcher.store
Expand Down Expand Up @@ -44,7 +44,7 @@ class ContestsFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener,

override fun newState(state: ContestsState) {
swipeRefreshLayout.isRefreshing = (state.status == ContestsState.Status.PENDING)
contestsAdapter.setItems(state.contests.filter { it.phase == "BEFORE" }.sortedBy(Contest::time))
contestsAdapter.setItems(state.contests.filter { it.phase == "BEFORE" }.sortedBy(Contest::startTimeSeconds))
}

override fun onRefresh() {
Expand Down Expand Up @@ -74,8 +74,8 @@ class ContestsFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener,
}

private fun addContestToCalendar(contest: Contest) {
val timeStart = getCalendarTime(contest.time)
val timeEnd = getCalendarTime(contest.time + contest.duration)
val timeStart = getCalendarTime(contest.startTimeSeconds)
val timeEnd = getCalendarTime(contest.startTimeSeconds + contest.durationSeconds)
val encodeName = URLEncoder.encode(contest.name)
val calendarEventLink =
"${CALENDAR_LINK}?action=TEMPLATE&text=$encodeName&dates=$timeStart/$timeEnd&details=${CODEFORCES_LINK}"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.bogdan.codeforceswatcher.features.contests.redux.requests

import com.bogdan.codeforceswatcher.CwApp
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.features.contests.models.Contest
import io.xorum.codeforceswatcher.features.contests.models.Contest
import com.bogdan.codeforceswatcher.network.RestClient
import com.bogdan.codeforceswatcher.redux.Request
import com.bogdan.codeforceswatcher.redux.actions.ToastAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bogdan.codeforceswatcher.features.contests.redux.requests

import com.bogdan.codeforceswatcher.features.contests.models.Contest
import io.xorum.codeforceswatcher.features.contests.models.Contest
import com.google.gson.annotations.SerializedName

data class ContestsResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bogdan.codeforceswatcher.features.contests.redux.states

import com.bogdan.codeforceswatcher.features.contests.models.Contest
import io.xorum.codeforceswatcher.features.contests.models.Contest
import tw.geothings.rekotlin.StateType

data class ContestsState(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.features.problems.models.Problem
import com.bogdan.codeforceswatcher.store
import io.xorum.codeforceswatcher.features.problems.models.Problem
import com.bogdan.codeforceswatcher.util.Analytics
import kotlinx.android.synthetic.main.activity_web_page.*
import java.lang.IllegalStateException

class ProblemActivity : AppCompatActivity() {

private lateinit var pageTitle: String
private lateinit var link: String

private val problem: Problem

This comment was marked as resolved.

get() = store.state.problems.problems.find { it.id == intent.getLongExtra(PROBLEM_ID, 0) }
?: throw IllegalStateException()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_web_page)
Expand All @@ -39,8 +45,6 @@ class ProblemActivity : AppCompatActivity() {
}

private fun initData() {
val problem = intent.getSerializableExtra(PROBLEM_ID) as Problem

pageTitle = getString(R.string.problem_name_with_index, problem.contestId, problem.index, problem.name)
link = buildPageLink(problem)
}
Expand Down Expand Up @@ -123,9 +127,9 @@ class ProblemActivity : AppCompatActivity() {
companion object {
private const val PROBLEM_ID = "problem_id"

fun newIntent(context: Context, problem: Problem): Intent {
fun newIntent(context: Context, problemId: Long): Intent {
val intent = Intent(context, ProblemActivity::class.java)
intent.putExtra(PROBLEM_ID, problem)
intent.putExtra(PROBLEM_ID, problemId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.features.problems.models.Problem
import io.xorum.codeforceswatcher.features.problems.models.Problem
import com.bogdan.codeforceswatcher.features.problems.redux.requests.ProblemsRequests
import com.bogdan.codeforceswatcher.store
import kotlinx.android.synthetic.main.view_problem_item.view.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ProblemsFragment : Fragment(), StoreSubscriber<ProblemsState>, SwipeRefres

private fun initViews() {
swipeRefreshLayout.setOnRefreshListener(this)
problemsAdapter = ProblemsAdapter(requireContext(), { startActivity(ProblemActivity.newIntent(requireContext(), it)) })
problemsAdapter = ProblemsAdapter(requireContext()) { startActivity(ProblemActivity.newIntent(requireContext(), it.id)) }
recyclerView.adapter = problemsAdapter
}

Expand Down

This file was deleted.

Loading