Skip to content

Commit

Permalink
Fix login token rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Jun 28, 2018
1 parent 9bac16d commit cb14d80
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId 'com.stevenschoen.putionew'
minSdkVersion 21
targetSdkVersion 27
versionCode 132
versionName '4.3.3'
versionCode 133
versionName '4.3.4'
multiDexEnabled true

kapt {
Expand Down
29 changes: 14 additions & 15 deletions app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,26 @@ class PutioActivity : BaseCastActivity() {

registerReceiver(noNetworkReceiver, noNetworkIntentFilter)

if (Build.VERSION.SDK_INT >= 21) {
val jobDispatcher = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
if (jobDispatcher.allPendingJobs.none {
it.id == FileDownloadsMaintenanceService.FILE_DOWNLOADS_MAINTENANCE_JOB_ID
}) {
jobDispatcher.schedule(JobInfo.Builder(
FileDownloadsMaintenanceService.FILE_DOWNLOADS_MAINTENANCE_JOB_ID,
ComponentName(this, FileDownloadsMaintenanceService::class.java))
.setPeriodic(TimeUnit.DAYS.toMillis(2))
.setPersisted(true)
.setRequiresDeviceIdle(true)
.build())
}

val jobDispatcher = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
if (jobDispatcher.allPendingJobs.none {
it.id == FileDownloadsMaintenanceService.FILE_DOWNLOADS_MAINTENANCE_JOB_ID
}) {
jobDispatcher.schedule(JobInfo.Builder(
FileDownloadsMaintenanceService.FILE_DOWNLOADS_MAINTENANCE_JOB_ID,
ComponentName(this, FileDownloadsMaintenanceService::class.java))
.setOverrideDeadline(5000)
.setPeriodic(TimeUnit.DAYS.toMillis(2))
.setPersisted(true)
.setRequiresDeviceIdle(true)
.build())
}

jobDispatcher.schedule(JobInfo.Builder(
FileDownloadsMaintenanceService.FILE_DOWNLOADS_MAINTENANCE_JOB_ID,
ComponentName(this, FileDownloadsMaintenanceService::class.java))
.setOverrideDeadline(5000)
.setPersisted(true)
.setRequiresDeviceIdle(true)
.build())
}

override fun onNewIntent(intent: Intent) {
Expand Down Expand Up @@ -288,6 +286,7 @@ class PutioActivity : BaseCastActivity() {
}

fun logOut() {
(application as PutioApplication).putioUtils = null
sharedPrefs!!.edit().remove("token").apply()
FolderLoader.DiskCache(this).deleteCache()
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import android.support.v4.app.Fragment
import android.support.v7.widget.SearchView
import android.view.*
import android.widget.Toast
import com.stevenschoen.putionew.PutioActivity
import com.stevenschoen.putionew.PutioUtils
import com.stevenschoen.putionew.R
import com.stevenschoen.putionew.model.ResponseOrError
import com.stevenschoen.putionew.model.files.PutioFile
import com.stevenschoen.putionew.putioApp
import com.trello.rxlifecycle2.kotlin.bindToLifecycle
import io.reactivex.android.schedulers.AndroidSchedulers
import retrofit2.HttpException

class FolderFragment : FileListFragment<FileListFragment.Callbacks>() {

Expand Down Expand Up @@ -122,6 +124,9 @@ class FolderFragment : FileListFragment<FileListFragment.Callbacks>() {
is ResponseOrError.NetworkError -> {
PutioUtils.getRxJavaThrowable(response.error).printStackTrace()
Toast.makeText(context, R.string.network_error, Toast.LENGTH_SHORT).show()
if (response.error is HttpException && response.error?.code() == 401) {
(activity as? PutioActivity)?.logOut()
}
}
}
updateViewState()
Expand Down

0 comments on commit cb14d80

Please sign in to comment.