Skip to content

Commit

Permalink
refactor #605 Use longVersionCode instead of versionCode.
Browse files Browse the repository at this point in the history
  • Loading branch information
toastkidjp committed Aug 19, 2020
1 parent ea63257 commit 27c0898
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/jp/toastkid/yobidashi/launcher/Adapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package jp.toastkid.yobidashi.launcher
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import jp.toastkid.lib.preference.PreferenceApplier
import jp.toastkid.yobidashi.R
import jp.toastkid.yobidashi.databinding.ItemAppLauncherBinding
import jp.toastkid.yobidashi.libs.Toaster
import jp.toastkid.lib.preference.PreferenceApplier
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -23,7 +25,7 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.*
import java.util.ArrayList

/**
* RecyclerView's adapter.
Expand Down Expand Up @@ -84,7 +86,7 @@ internal class Adapter(private val context: Context, private val parent: View)
holder.setPackageName(info.packageName)
try {
val packageInfo = packageManager.getPackageInfo(info.packageName, PackageManager.GET_META_DATA)
holder.setVersionInformation("${packageInfo.versionName} (${packageInfo.versionCode})")
holder.setVersionInformation("${packageInfo.versionName} (${extractVersionCode(packageInfo)})")
holder.setInstalledMs(packageInfo.firstInstallTime)
} catch (e: PackageManager.NameNotFoundException) {
Timber.e(e)
Expand All @@ -93,6 +95,13 @@ internal class Adapter(private val context: Context, private val parent: View)
setOnClick(holder, info)
}

private fun extractVersionCode(packageInfo: PackageInfo) =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
packageInfo.longVersionCode
} else {
packageInfo.versionCode.toLong()
}

/**
* Set on click actions.
*
Expand Down

0 comments on commit 27c0898

Please sign in to comment.