Skip to content

Commit

Permalink
Add update info (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
jraska authored Oct 21, 2023
1 parent ca4e187 commit 213b736
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions feature/about/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'org.threeten:threetenbp:1.5.1:no-tzdb'

androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation espressoCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.view.View
import android.widget.TextView
import androidx.core.content.pm.PackageInfoCompat
import com.airbnb.epoxy.SimpleEpoxyModel
import java.time.Instant
import java.time.format.DateTimeFormatter.ISO_INSTANT

class VersionInfoModel : SimpleEpoxyModel(R.layout.about_item_version) {
override fun bind(view: View) {
Expand All @@ -15,8 +17,26 @@ class VersionInfoModel : SimpleEpoxyModel(R.layout.about_item_version) {
view.findViewById<TextView>(R.id.version_build_type).text = buildTypeText

val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
val versionText = context.getString(R.string.about_version_name_and_code, packageInfo.versionName, PackageInfoCompat.getLongVersionCode(packageInfo))
val versionText = context.getString(
R.string.about_version_name_and_code,
packageInfo.versionName,
PackageInfoCompat.getLongVersionCode(packageInfo)
)
view.findViewById<TextView>(R.id.version_name_and_code).text = versionText

val firstInstallTimeText = ISO_INSTANT.format(
Instant.ofEpochMilli(packageInfo.firstInstallTime)
)
val lastUpdateTimeText = ISO_INSTANT.format(
Instant.ofEpochMilli(packageInfo.lastUpdateTime)
)

val updateInfoText = context.getString(
R.string.about_version_install_info,
lastUpdateTimeText,
firstInstallTimeText
)
view.findViewById<TextView>(R.id.version_update_info).text = updateInfoText
}

override fun getSpanSize(totalSpanCount: Int, position: Int, itemCount: Int): Int {
Expand Down
10 changes: 10 additions & 0 deletions feature/about/src/main/res/layout/about_item_version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@
tools:text="Build type: release"
/>

<TextView
android:id="@+id/version_update_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/textMain"
android:textSize="@dimen/textMain"
tools:text="Binary built on: 2023-10-21 17:00"
/>

</LinearLayout>
1 change: 1 addition & 0 deletions feature/about/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

<string name="about_version_name_and_code">Version %s (%d)</string>
<string name="about_version_build_type">Build type: %s</string>
<string name="about_version_install_info">Update: %1$s\n Install: %2$s</string>
</resources>

0 comments on commit 213b736

Please sign in to comment.