mirror of
https://github.com/NiciDieNase/chaosflix
synced 2025-02-17 05:28:24 +00:00
Merge branch 'feature/downloadUi' into develop
This commit is contained in:
commit
94a2573558
9 changed files with 107 additions and 86 deletions
|
@ -11,12 +11,13 @@ import android.content.IntentFilter
|
|||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.database.sqlite.SQLiteConstraintException
|
||||
import androidx.databinding.ObservableField
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.preference.PreferenceManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import android.util.Log
|
||||
import de.nicidienase.chaosflix.R
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Recording
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEvent
|
||||
|
@ -69,26 +70,18 @@ class OfflineItemManager(
|
|||
val bytesTotalIndex = cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)
|
||||
val bytesTotal = cursor.getInt(bytesTotalIndex)
|
||||
|
||||
val statusText: String =
|
||||
val statusIconRes: Int =
|
||||
when (status) {
|
||||
DownloadManager.STATUS_RUNNING -> "Running"
|
||||
DownloadManager.STATUS_FAILED -> "Failed"
|
||||
DownloadManager.STATUS_PAUSED -> "Paused"
|
||||
DownloadManager.STATUS_SUCCESSFUL -> "Successful"
|
||||
DownloadManager.STATUS_PENDING -> "Pending"
|
||||
else -> "UNKNOWN"
|
||||
DownloadManager.STATUS_RUNNING -> R.drawable.ic_download
|
||||
DownloadManager.STATUS_FAILED -> R.drawable.ic_error
|
||||
DownloadManager.STATUS_PAUSED -> R.drawable.ic_paused
|
||||
DownloadManager.STATUS_SUCCESSFUL -> R.drawable.ic_done
|
||||
DownloadManager.STATUS_PENDING -> R.drawable.ic_download
|
||||
else -> R.drawable.ic_error
|
||||
}
|
||||
if (downloadStatus.containsKey(id)) {
|
||||
val item = downloadStatus[id]
|
||||
item?.statusText?.set(statusText)
|
||||
item?.currentBytes?.set(bytesSoFar)
|
||||
item?.totalBytes?.set(bytesTotal)
|
||||
item?.status = status
|
||||
} else {
|
||||
downloadStatus.put(
|
||||
id,
|
||||
DownloadStatus(statusText, bytesSoFar, bytesTotal, status))
|
||||
}
|
||||
val statusIcon = applicationContext.resources.getDrawable(statusIconRes, null)
|
||||
|
||||
downloadStatus[id] = DownloadStatus(status, statusIcon, bytesSoFar, bytesTotal)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
}
|
||||
|
@ -163,21 +156,11 @@ class OfflineItemManager(
|
|||
}
|
||||
|
||||
inner class DownloadStatus(
|
||||
statusText: String = "",
|
||||
currentBytes: Int = 0,
|
||||
totalBytes: Int = 0,
|
||||
var status: Int = DownloadManager.STATUS_FAILED
|
||||
) {
|
||||
val statusText: ObservableField<String> = ObservableField()
|
||||
val currentBytes: ObservableField<Int> = ObservableField()
|
||||
val totalBytes: ObservableField<Int> = ObservableField()
|
||||
|
||||
init {
|
||||
this.statusText.set(statusText)
|
||||
this.currentBytes.set(currentBytes)
|
||||
this.totalBytes.set(totalBytes)
|
||||
}
|
||||
}
|
||||
val status: Int = DownloadManager.STATUS_PENDING,
|
||||
val statusIcon: Drawable = applicationContext.resources.getDrawable(R.drawable.ic_download, null),
|
||||
val currentBytes: Int = 0,
|
||||
val totalBytes: Int = 0
|
||||
)
|
||||
|
||||
class DownloadCancelHandler(
|
||||
val context: Context,
|
||||
|
|
9
common/src/main/res/drawable/ic_done.xml
Normal file
9
common/src/main/res/drawable/ic_done.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<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="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
|
||||
</vector>
|
9
common/src/main/res/drawable/ic_download.xml
Normal file
9
common/src/main/res/drawable/ic_download.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<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,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
|
||||
</vector>
|
9
common/src/main/res/drawable/ic_error.xml
Normal file
9
common/src/main/res/drawable/ic_error.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<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="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
|
||||
</vector>
|
9
common/src/main/res/drawable/ic_paused.xml
Normal file
9
common/src/main/res/drawable/ic_paused.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<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="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM11,16L9,16L9,8h2v8zM15,16h-2L13,8h2v8z"/>
|
||||
</vector>
|
|
@ -13,6 +13,9 @@
|
|||
<color name="background_gradient_end">#888888</color>
|
||||
<color name="transparent_black_35">#59000000</color>
|
||||
<color name="transparent_black_70">#B3000000</color>
|
||||
<color name="transparent_white_70">#B3FFFFFF</color>
|
||||
<color name="black">#000000</color>
|
||||
<color name="white">#FFFFFF</color>
|
||||
|
||||
<color name="download_icon_tint">#686868</color>
|
||||
</resources>
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/download_progress_bar"
|
||||
tools:text="Title"/>
|
||||
tools:text="Titles can be longer to, but we won't fit more than two lines" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subtitle_text"
|
||||
|
@ -69,41 +69,38 @@
|
|||
android:text="@{event.subtitle}"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:layout_constraintEnd_toEndOf="@+id/title_text"
|
||||
app:layout_constraintStart_toStartOf="@+id/title_text"
|
||||
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
||||
tools:text="Subtitle"/>
|
||||
tools:text="Subtitles could be very long and span multiple lines, the rest of the layout should addapt accordingly" />
|
||||
|
||||
<TextView
|
||||
<ImageView
|
||||
android:id="@+id/tag_text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="bottom|right"
|
||||
android:paddingRight="8dp"
|
||||
android:text="@{downloadStatus.statusText}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
||||
tools:text="Tag"/>
|
||||
android:layout_height="0dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:src="@{downloadStatus.status}"
|
||||
android:background="@color/transparent_white_70"
|
||||
app:layout_constraintBottom_toTopOf="@+id/download_progress_bar"
|
||||
app:layout_constraintEnd_toEndOf="@+id/imageView"
|
||||
app:layout_constraintStart_toStartOf="@id/imageView"
|
||||
app:layout_constraintTop_toTopOf="@id/imageView"
|
||||
tools:srcCompat="@drawable/ic_download" />
|
||||
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@drawable/button_rect_normal"
|
||||
app:layout_constraintBottom_toTopOf="@+id/title_text"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView"
|
||||
app:srcCompat="@drawable/ic_delete_dark"/>
|
||||
app:srcCompat="@drawable/ic_delete_dark" />
|
||||
|
||||
|
||||
<ProgressBar
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
|
||||
|
||||
</FrameLayout>
|
||||
<!--</android.support.design.widget.CoordinatorLayout>-->
|
||||
|
||||
<com.google.android.material.navigation.NavigationView
|
||||
android:id="@+id/navigation_view"
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<data>
|
||||
<import type="android.view.View"/>
|
||||
|
||||
<import type="android.view.View" />
|
||||
|
||||
<variable
|
||||
name="item"
|
||||
type="de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEventView"/>
|
||||
type="de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEventView" />
|
||||
|
||||
<variable
|
||||
name="downloadStatus"
|
||||
type="de.nicidienase.chaosflix.common.OfflineItemManager.DownloadStatus"/>
|
||||
type="de.nicidienase.chaosflix.common.OfflineItemManager.DownloadStatus" />
|
||||
</data>
|
||||
|
||||
<FrameLayout
|
||||
|
@ -38,15 +39,15 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="@dimen/thumbnail_width"
|
||||
android:layout_height="@dimen/thumbnail_height"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:scaleType="centerCrop"
|
||||
app:layout_constraintEnd_toStartOf="@+id/title_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/unknown"
|
||||
tools:srcCompat="@drawable/unknown" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_text"
|
||||
|
@ -55,10 +56,10 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="3"
|
||||
android:text="@{item.title}"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Title"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintEnd_toStartOf="@+id/button_delete"
|
||||
app:layout_constraintStart_toEndOf="@+id/imageView"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView"
|
||||
|
@ -69,42 +70,43 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:text="@{item.subtitle}"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintBottom_toTopOf="@+id/download_progress_bar"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/title_text"
|
||||
app:layout_constraintStart_toStartOf="@+id/title_text"
|
||||
app:layout_constraintTop_toBottomOf="@+id/title_text"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
android:maxLines="3"
|
||||
android:ellipsize="end"
|
||||
tools:text="Subtitles could be very long and span multiple lines, the rest of the layout should addapt accordingly" />
|
||||
|
||||
|
||||
<TextView
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/tag_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:gravity="bottom|end"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@{downloadStatus.statusText}"
|
||||
app:layout_constraintBottom_toTopOf="@+id/download_progress_bar"
|
||||
app:layout_constraintEnd_toEndOf="@+id/button_delete"
|
||||
app:layout_constraintStart_toStartOf="@+id/button_delete"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button_delete"
|
||||
tools:text="Tag" />
|
||||
android:background="@color/transparent_white_70"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/imageView"
|
||||
app:layout_constraintEnd_toEndOf="@+id/imageView"
|
||||
app:layout_constraintStart_toStartOf="@+id/imageView"
|
||||
app:layout_constraintTop_toTopOf="@+id/imageView"
|
||||
android:src="@{downloadStatus.statusIcon}"
|
||||
android:tint="@color/download_icon_tint"
|
||||
tools:srcCompat="@drawable/ic_download" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@drawable/button_rect_normal"
|
||||
android:contentDescription="@string/delete_item"
|
||||
android:padding="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_delete_dark" />
|
||||
|
@ -116,10 +118,11 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:max="@{safeUnbox(downloadStatus.totalBytes)}"
|
||||
android:progress="@{safeUnbox(downloadStatus.currentBytes)}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/imageView"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView"
|
||||
tools:max="10"
|
||||
tools:progress="5" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue