Skip to content

Commit

Permalink
Visual updates to Account screen
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Dec 8, 2018
1 parent ffe3972 commit 135c58b
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 329 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stevenschoen.putionew.fragments
package com.stevenschoen.putionew

import android.content.Intent
import android.content.pm.PackageManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.stevenschoen.putionew.cast.BaseCastActivity
import com.stevenschoen.putionew.files.FileDownloadsMaintenanceService
import com.stevenschoen.putionew.files.FilesFragment
import com.stevenschoen.putionew.files.FolderLoader
import com.stevenschoen.putionew.fragments.AccountFragment
import com.stevenschoen.putionew.account.AccountFragment
import com.stevenschoen.putionew.model.files.PutioFile
import com.stevenschoen.putionew.model.transfers.PutioTransfer
import com.stevenschoen.putionew.transfers.TransfersFragment
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.stevenschoen.putionew.account

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.net.toUri
import com.stevenschoen.putionew.PutioUtils
import com.stevenschoen.putionew.R
import com.stevenschoen.putionew.putioApp
import com.trello.rxlifecycle2.components.support.RxFragment
import com.trello.rxlifecycle2.kotlin.bindToLifecycle
import io.reactivex.android.schedulers.AndroidSchedulers

class AccountFragment : RxFragment() {

private var utils: PutioUtils? = null

private lateinit var diskUsageView: TextView
private lateinit var emailView: TextView
private lateinit var usernameView: TextView
private lateinit var manageOnWebView: View

private lateinit var diskUsageDrawable: DiskUsageDrawable

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

this.utils = putioApp.putioUtils
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = inflater.inflate(R.layout.account, container, false)

diskUsageView = view.findViewById(R.id.account_diskusage)
usernameView = view.findViewById(R.id.account_username)
emailView = view.findViewById(R.id.account_email)
manageOnWebView = view.findViewById(R.id.account_manageonweb)

diskUsageDrawable = DiskUsageDrawable(context!!)
diskUsageView.background = diskUsageDrawable

manageOnWebView.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW, "https://app.put.io/settings/".toUri()))
}

invalidateAccountInfo()

return view
}

fun invalidateAccountInfo() {
utils!!.restInterface.account()
.bindToLifecycle(this)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ accountInfoResponse ->
val account = accountInfoResponse.info
val disk = account.disk

usernameView!!.text = account.username
emailView!!.text = account.mail
diskUsageDrawable.usedFraction = disk.used.toFloat() / disk.size
diskUsageView!!.text = getString(
R.string.x_of_x_free,
PutioUtils.humanReadableByteCount(disk.avail, false),
PutioUtils.humanReadableByteCount(disk.size, false)
)
}, { throwable -> PutioUtils.getRxJavaThrowable(throwable).printStackTrace() })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.stevenschoen.putionew.account

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.drawable.GradientDrawable
import androidx.core.content.ContextCompat
import com.stevenschoen.putionew.R

class DiskUsageDrawable(context: Context) : GradientDrawable() {

private val usedPaint = Paint().apply {
color = ContextCompat.getColor(context, R.color.putio_accent_dark)
}
private val usedRect = Rect()

var usedFraction = 0f
set(value) {
field = value
invalidateSelf()
}

init {
shape = GradientDrawable.RECTANGLE
color = ContextCompat.getColorStateList(context, R.color.putio_accent)
}

override fun draw(canvas: Canvas) {
super.draw(canvas)
canvas.drawRect(
0f,
0f,
usedFraction * bounds.right,
bounds.bottom.toFloat(),
usedPaint
)
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.stevenschoen.putionew.model.account

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize

@Parcelize
data class PutioAccountInfo(
val username: String,
val mail: String,
val disk: DiskInfo
) : Parcelable {

@Parcelize
data class DiskInfo(
val avail: Long,
val size: Long,
val used: Long
) : Parcelable

}
11 changes: 11 additions & 0 deletions app/src/main/res/drawable/ic_open.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
>
<path
android:fillColor="#FF000000"
android:pathData="M19,19H5V5h7V3H5c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2v-7h-2v7zM14,3v2h3.59l-9.83,9.83 1.41,1.41L19,6.41V10h2V3h-7z"
/>
</vector>
6 changes: 0 additions & 6 deletions app/src/main/res/drawable/roundedyellowbg.xml

This file was deleted.

Loading

0 comments on commit 135c58b

Please sign in to comment.