Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖

Jake Lee JakeSteam

🤖
View GitHub Profile
@JakeSteam
JakeSteam / ItemAdapter.kt
Last active Oct 6, 2021
Creating a grid RecyclerView with quick drag and drop item swapping, Room / LiveData support, and more!
View ItemAdapter.kt
class ItemAdapter(
private val itemClickListener: (OwnedItem) -> Unit,
private val itemSaver: (List<OwnedItem>) -> Unit
) : RecyclerView.Adapter<ItemViewHolder>() {
val items = ArrayList<OwnedItem>()
fun setItems(newItems: List<OwnedItem>) {
val result = calculateDiff(newItems)
items.clear()
View MyClass.kt
package uk.co.jakelee.apodwallpaper.example
import uk.co.jakelee.apodwallpaper.BuildConfig
class MyClass() {
val key = BuildConfig.APOD_API_KEY
}
View MainActivity.kt
private var animatorSet: AnimatorSet? = null
private fun startAnimation(target: ImageView) {
val animationLayers = target.drawable as LayerDrawable
val moveImageViewLeft = ObjectAnimator.ofFloat(target, View.TRANSLATION_X, -200f).setDuration(6000)
val moveImageViewRight = ObjectAnimator.ofFloat(target, View.TRANSLATION_X, 0f).setDuration(6000)
val redCircle = animationLayers.findDrawableByLayerId(R.id.red_circle) as GradientDrawable
val redCircleFadeOut = ObjectAnimator.ofInt(redCircle, "alpha", 255, 100).setDuration(1000)
val redCircleFadeIn = ObjectAnimator.ofInt(redCircle, "alpha", 100, 255).setDuration(100)
@JakeSteam
JakeSteam / build.sh
Created Apr 26, 2020
Posting a Slack message from Travis CI
View build.sh
# Environment variables
REPO=${TRAVIS_REPO_SLUG}
BRANCH=${TRAVIS_BRANCH}
COMMIT_HASH=${TRAVIS_COMMIT}
COMMIT_HASH_SHORT=${COMMIT_HASH:0:7}
COMMIT_MESSAGE=${TRAVIS_COMMIT_MESSAGE}
IS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}
BUILD_DIR=${TRAVIS_BUILD_DIR}
BUILD_NUMBER=${TRAVIS_BUILD_NUMBER}
BUILD_URL=${TRAVIS_BUILD_WEB_URL}
View .travis.yml
# Overall config
dist: xenial
language: android
# Android version config
android:
components:
- build-tools-28.0.3
- android-28
View .travis.yml
# Overall config
dist: xenial
language: android
# Android version config
android:
components:
- build-tools-28.0.3
- android-28
@JakeSteam
JakeSteam / .travis.yml
Last active Dec 15, 2020
Creating app bundles and APKs on Travis CI (for https://wp.me/paoKlI-Gk)
View .travis.yml
# Overall config
dist: xenial
language: android
# Android version config
android:
components:
- build-tools-28.0.3
- android-28
View AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.jakelee.updatelistener">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
@JakeSteam
JakeSteam / AndroidManifest.xml
Created Apr 28, 2019
"How to programmatically change your Android app icon and name" for http://blog.jakelee.co.uk/programmatically-changing-app-icon
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.jakelee.dynamiciconchanging">
<application
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
@JakeSteam
JakeSteam / SettingsFragment.kt
Created Mar 18, 2019
Automatically adding build time to your Android app
View SettingsFragment.kt
private fun setupVersionInfo() {
findPreference(getString(R.string.pref_version)).title = "V${BuildConfig.VERSION_NAME}"
findPreference(getString(R.string.pref_version)).summary = String.format(
getString(R.string.version_summary),
BuildConfig.VERSION_CODE,
SimpleDateFormat("dd MMM yyy", Locale.US).format(BuildConfig.BUILD_TIME)
)
}