Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version info to About screen #320

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal class AboutActivity : BaseActivity() {
private fun createModels(): List<EpoxyModel<*>>? {
return listOf(
DescriptionModel(viewModel::onProjectDescriptionClick),
VersionInfoModel(),
IconModel(viewModel::onGithubClick, R.drawable.ic_github_about_48dp, R.string.about_github_description),
IconModel(viewModel::onWebClick, R.drawable.ic_web_48dp, R.string.about_web_description),
IconModel(viewModel::onMediumClick, R.drawable.ic_medium_48dp, R.string.about_medium_description),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jraska.github.client.about

import android.view.View
import android.widget.TextView
import androidx.core.content.pm.PackageInfoCompat
import com.airbnb.epoxy.SimpleEpoxyModel

internal class VersionInfoModel : SimpleEpoxyModel(R.layout.about_item_version) {
override fun bind(view: View) {
super.bind(view)

val context = view.context

val buildTypeText = context.getString(R.string.about_version_build_type, BuildConfig.BUILD_TYPE)
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))
view.findViewById<TextView>(R.id.version_name_and_code).text = versionText
}

override fun getSpanSize(totalSpanCount: Int, position: Int, itemCount: Int): Int {
return totalSpanCount
}
}
31 changes: 31 additions & 0 deletions feature/about/src/main/res/layout/about_item_version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/list_selector_background"
android:orientation="vertical"
>

<TextView
android:id="@+id/version_name_and_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/about_app_name"
android:textColor="@color/textMain"
android:textSize="@dimen/textMain"
/>

<TextView
android:id="@+id/version_build_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/textMain"
android:textSize="@dimen/textMain"
tools:text="Build type: release"
/>

</LinearLayout>
3 changes: 3 additions & 0 deletions feature/about/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<string name="about_web_description">Go to Website</string>
<string name="about_medium_description">Go to Medium</string>
<string name="about_twitter_description">Go to Twitter</string>

<string name="about_version_name_and_code">Version %s (%d)</string>
<string name="about_version_build_type">Build type: %s</string>
</resources>