From 135c58b0e2d8429957495790615e2b900c6b1b41 Mon Sep 17 00:00:00 2001 From: Steven Schoen Date: Fri, 7 Dec 2018 20:47:05 -0800 Subject: [PATCH] Visual updates to Account screen --- .../putionew/{fragments => }/AboutFragment.kt | 2 +- .../stevenschoen/putionew/PutioActivity.kt | 2 +- .../putionew/account/AccountFragment.kt | 75 +++++++++++++ .../putionew/account/DiskUsageDrawable.kt | 40 +++++++ .../putionew/fragments/AccountFragment.java | 75 ------------- .../model/account/PutioAccountInfo.java | 102 ------------------ .../model/account/PutioAccountInfo.kt | 20 ++++ app/src/main/res/drawable/ic_open.xml | 11 ++ app/src/main/res/drawable/roundedyellowbg.xml | 6 -- app/src/main/res/layout-h400dp/account.xml | 54 ---------- .../main/res/layout-large/aboutactivity.xml | 2 +- app/src/main/res/layout/aboutactivity.xml | 2 +- app/src/main/res/layout/account.xml | 100 ++++++++++------- app/src/main/res/layout/account_storage.xml | 46 -------- app/src/main/res/values/strings.xml | 2 +- 15 files changed, 210 insertions(+), 329 deletions(-) rename app/src/main/java/com/stevenschoen/putionew/{fragments => }/AboutFragment.kt (98%) create mode 100644 app/src/main/java/com/stevenschoen/putionew/account/AccountFragment.kt create mode 100644 app/src/main/java/com/stevenschoen/putionew/account/DiskUsageDrawable.kt delete mode 100644 app/src/main/java/com/stevenschoen/putionew/fragments/AccountFragment.java delete mode 100644 app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.java create mode 100644 app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.kt create mode 100644 app/src/main/res/drawable/ic_open.xml delete mode 100644 app/src/main/res/drawable/roundedyellowbg.xml delete mode 100644 app/src/main/res/layout-h400dp/account.xml delete mode 100644 app/src/main/res/layout/account_storage.xml diff --git a/app/src/main/java/com/stevenschoen/putionew/fragments/AboutFragment.kt b/app/src/main/java/com/stevenschoen/putionew/AboutFragment.kt similarity index 98% rename from app/src/main/java/com/stevenschoen/putionew/fragments/AboutFragment.kt rename to app/src/main/java/com/stevenschoen/putionew/AboutFragment.kt index d142c961..6ddf26a6 100644 --- a/app/src/main/java/com/stevenschoen/putionew/fragments/AboutFragment.kt +++ b/app/src/main/java/com/stevenschoen/putionew/AboutFragment.kt @@ -1,4 +1,4 @@ -package com.stevenschoen.putionew.fragments +package com.stevenschoen.putionew import android.content.Intent import android.content.pm.PackageManager diff --git a/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt b/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt index 412ea2f8..33d85236 100644 --- a/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt +++ b/app/src/main/java/com/stevenschoen/putionew/PutioActivity.kt @@ -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 diff --git a/app/src/main/java/com/stevenschoen/putionew/account/AccountFragment.kt b/app/src/main/java/com/stevenschoen/putionew/account/AccountFragment.kt new file mode 100644 index 00000000..d0345ee6 --- /dev/null +++ b/app/src/main/java/com/stevenschoen/putionew/account/AccountFragment.kt @@ -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() }) + } +} diff --git a/app/src/main/java/com/stevenschoen/putionew/account/DiskUsageDrawable.kt b/app/src/main/java/com/stevenschoen/putionew/account/DiskUsageDrawable.kt new file mode 100644 index 00000000..0fd60268 --- /dev/null +++ b/app/src/main/java/com/stevenschoen/putionew/account/DiskUsageDrawable.kt @@ -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 + ) + } + +} diff --git a/app/src/main/java/com/stevenschoen/putionew/fragments/AccountFragment.java b/app/src/main/java/com/stevenschoen/putionew/fragments/AccountFragment.java deleted file mode 100644 index b65c9193..00000000 --- a/app/src/main/java/com/stevenschoen/putionew/fragments/AccountFragment.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.stevenschoen.putionew.fragments; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import com.stevenschoen.putionew.PutioApplication; -import com.stevenschoen.putionew.PutioUtils; -import com.stevenschoen.putionew.R; -import com.stevenschoen.putionew.model.account.PutioAccountInfo; -import com.stevenschoen.putionew.model.responses.AccountInfoResponse; -import com.trello.rxlifecycle2.components.support.RxFragment; - -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.annotations.NonNull; -import io.reactivex.functions.Consumer; - -public class AccountFragment extends RxFragment { - - private PutioUtils utils; - - private TextView textDiskTotal; - private TextView textDiskFree; - private TextView textEmail; - private TextView textName; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - this.utils = ((PutioApplication) getActivity().getApplication()).getPutioUtils(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - final View view = inflater.inflate(R.layout.account, container, false); - - textName = view.findViewById(R.id.text_behind_accountname); - textEmail = view.findViewById(R.id.text_behind_accountemail); - textDiskFree = view.findViewById(R.id.text_storage_amountfree); - textDiskTotal = view.findViewById(R.id.text_storage_amounttotal); - - invalidateAccountInfo(); - - return view; - } - - public void invalidateAccountInfo() { - utils.getRestInterface().account() - .compose(this.bindToLifecycle()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Consumer() { - @Override - public void accept(@NonNull AccountInfoResponse accountInfoResponse) throws Exception { - PutioAccountInfo account = accountInfoResponse.getInfo(); - PutioAccountInfo.DiskInfo disk = account.getDisk(); - - textName.setText(account.getUsername()); - textEmail.setText(account.getMail()); - textDiskFree.setText( - PutioUtils.humanReadableByteCount(disk.getAvail(), false)); - textDiskTotal.setText(getString(R.string.total_is, - PutioUtils.humanReadableByteCount(disk.getSize(), false))); - } - }, new Consumer() { - @Override - public void accept(@NonNull Throwable throwable) throws Exception { - PutioUtils.getRxJavaThrowable(throwable).printStackTrace(); - } - }); - } -} diff --git a/app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.java b/app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.java deleted file mode 100644 index ec039877..00000000 --- a/app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.stevenschoen.putionew.model.account; - -import android.os.Parcel; -import android.os.Parcelable; - -public class PutioAccountInfo implements Parcelable { - public static final Creator CREATOR = new Creator() { - public PutioAccountInfo createFromParcel(Parcel in) { - return new PutioAccountInfo(in); - } - - public PutioAccountInfo[] newArray(int size) { - return new PutioAccountInfo[size]; - } - }; - private String username; - private String mail; - private DiskInfo disk; - - public PutioAccountInfo(Parcel in) { - readFromParcel(in); - } - - public String getUsername() { - return this.username; - } - - public String getMail() { - return this.mail; - } - - public DiskInfo getDisk() { - return this.disk; - } - - @Override - public int describeContents() { - return 0; - } - - private void readFromParcel(Parcel in) { - this.username = in.readString(); - this.mail = in.readString(); - this.disk = in.readParcelable(ClassLoader.getSystemClassLoader()); - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeString(username); - out.writeString(mail); - out.writeParcelable(disk, 0); - } - - public static class DiskInfo implements Parcelable { - public static final Creator CREATOR = new Creator() { - public DiskInfo createFromParcel(Parcel in) { - return new DiskInfo(in); - } - - public DiskInfo[] newArray(int size) { - return new DiskInfo[size]; - } - }; - private long avail; - private long size; - private long used; - - public DiskInfo(Parcel in) { - readFromParcel(in); - } - - public long getAvail() { - return avail; - } - - public long getSize() { - return size; - } - - public long getUsed() { - return used; - } - - @Override - public int describeContents() { - return 0; - } - - private void readFromParcel(Parcel in) { - this.avail = in.readLong(); - this.size = in.readLong(); - this.used = in.readLong(); - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeLong(this.avail); - out.writeLong(this.size); - out.writeLong(this.used); - } - } -} diff --git a/app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.kt b/app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.kt new file mode 100644 index 00000000..6bcb3e8a --- /dev/null +++ b/app/src/main/java/com/stevenschoen/putionew/model/account/PutioAccountInfo.kt @@ -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 + +} diff --git a/app/src/main/res/drawable/ic_open.xml b/app/src/main/res/drawable/ic_open.xml new file mode 100644 index 00000000..6c762272 --- /dev/null +++ b/app/src/main/res/drawable/ic_open.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable/roundedyellowbg.xml b/app/src/main/res/drawable/roundedyellowbg.xml deleted file mode 100644 index c4c49d1c..00000000 --- a/app/src/main/res/drawable/roundedyellowbg.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - diff --git a/app/src/main/res/layout-h400dp/account.xml b/app/src/main/res/layout-h400dp/account.xml deleted file mode 100644 index e68d3aaf..00000000 --- a/app/src/main/res/layout-h400dp/account.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout-large/aboutactivity.xml b/app/src/main/res/layout-large/aboutactivity.xml index c09a74cf..5a94a267 100644 --- a/app/src/main/res/layout-large/aboutactivity.xml +++ b/app/src/main/res/layout-large/aboutactivity.xml @@ -6,7 +6,7 @@ > - + android:layout_marginTop="24dp" + android:text="@string/logged_in_as" + android:textAppearance="@style/TextAppearance.MaterialComponents.Overline" + app:layout_constraintStart_toStartOf="@+id/account_diskusage" + app:layout_constraintTop_toTopOf="parent" + /> - - + - + android:layout_marginBottom="16dp" + android:textAppearance="@style/TextAppearance.MaterialComponents.Caption" + app:layout_constraintStart_toStartOf="@+id/account_loggedinas" + app:layout_constraintTop_toBottomOf="@+id/account_username" + tools:text="account@email.com" + /> - + - + - - - + diff --git a/app/src/main/res/layout/account_storage.xml b/app/src/main/res/layout/account_storage.xml deleted file mode 100644 index b9ee6585..00000000 --- a/app/src/main/res/layout/account_storage.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 70b89355..eb214d09 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -73,7 +73,6 @@ Successfully logged in! Folder name %d selected - Total: %s Loading… Created on %1$s at %2$s Accessed on %1$s at %2$s @@ -113,6 +112,7 @@ You don\'t have any transfers Add some stuff by clicking the \'add\' button below! Downloading + %1$s of %2$s free Uploading torrent