-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
210 additions
and
329 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...choen/putionew/fragments/AboutFragment.kt → ...om/stevenschoen/putionew/AboutFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/stevenschoen/putionew/account/AccountFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() }) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/stevenschoen/putionew/account/DiskUsageDrawable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
|
||
} |
75 changes: 0 additions & 75 deletions
75
app/src/main/java/com/stevenschoen/putionew/fragments/AccountFragment.java
This file was deleted.
Oops, something went wrong.
102 changes: 0 additions & 102 deletions
102
app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.