Skip to content

Commit

Permalink
Modernize a bit (#3171)
Browse files Browse the repository at this point in the history
* Remove redundant ignore file

* Add .gitattributes

* Generate new wrapper

* Apply plugins in `plugins`

* Adopt new dsl

* Enable stable config cache

* Ignore all build folders

* Enable build scan

* Disable buildFeatures flags by default

* Migrate to nonTransitive R class

* Tweak flags

* Bump AGP to 7.4.0

* Bump deps

* Run `ktlintFormat`

* Add an icon for IDEA to display

* Revert "Bump deps"

This reverts commit bc0d5b69d59f70289d5d5c4887a85e6af23cc662.

* Revert "Enable build scan"

This reverts commit 1568e5e84f1ee51064b3f426b1da0cf35fb67856.

* Remove com.android.library

* Enable Gradle cache

* Enable room incremental build

* Cleanups

* Cleanups

* Add .editorconfig

* Defer clean task

* Migrate `flavorDimensions`

* Merge instance-build.gradle into app's build.gradle

* Declare compileOptions & kotlinOptions

* Bump jvmTarget to 17

* Fix conflicts

* Xmx4g

* Rename output apks

* Revert "Bump jvmTarget to 17"

This reverts commit e4d1543bda65b6d2979ae0712bceee33fa8298a6.
  • Loading branch information
Goooler authored Feb 4, 2023
1 parent be93565 commit 3592318
Show file tree
Hide file tree
Showing 28 changed files with 241 additions and 215 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yml,yaml}]
indent_size = 2
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text=auto eol=lf

*.bat text eol=crlf
*.jar binary
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/local.properties
/.idea
.DS_Store
/build
build
/captures
.externalNativeBuild
app/release
app/release
app-release.apk
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions app/.gitignore

This file was deleted.

99 changes: 57 additions & 42 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'

apply from: "../instance-build.gradle"

def getGitSha = {
def stdout = new ByteArrayOutputStream()
try {
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
} catch (Exception e) {
return "unknown"
}
return stdout.toString().trim()
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.kotlin.parcelize)
}

final def gitSha = providers.exec {
commandLine('git', 'rev-parse', '--short=7', 'HEAD')
}.standardOutput.asText.get().trim()

// The app name
final def APP_NAME = "Tusky"
// The application id. Must be unique, e.g. based on your domain
final def APP_ID = "com.keylesspalace.tusky"
// url of a custom app logo. Recommended size at least 600x600. Keep empty to use the Tusky elephant friend.
final def CUSTOM_LOGO_URL = ""
// e.g. mastodon.social. Keep empty to not suggest any instance on the signup screen
final def CUSTOM_INSTANCE = ""
// link to your support account. Will be linked on the about page when not empty.
final def SUPPORT_ACCOUNT_URL = "https://mastodon.social/@Tusky"

android {
compileSdkVersion 33
compileSdk 33
namespace "com.keylesspalace.tusky"
defaultConfig {
applicationId APP_ID
namespace "com.keylesspalace.tusky"
minSdkVersion 23
targetSdkVersion 33
minSdk 23
targetSdk 33
versionCode 100
versionName "21.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -35,12 +38,6 @@ android {
buildConfigField("String", "CUSTOM_LOGO_URL", "\"$CUSTOM_LOGO_URL\"")
buildConfigField("String", "CUSTOM_INSTANCE", "\"$CUSTOM_INSTANCE\"")
buildConfigField("String", "SUPPORT_ACCOUNT_URL", "\"$SUPPORT_ACCOUNT_URL\"")

kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
}
buildTypes {
release {
Expand All @@ -51,20 +48,22 @@ android {
debug {}
}

flavorDimensions "color"
flavorDimensions += "color"
productFlavors {
blue {}
green {
resValue "string", "app_name", APP_NAME + " Test"
applicationIdSuffix ".test"
versionNameSuffix "-" + getGitSha()
versionNameSuffix "-" + gitSha
}
}

lintOptions {
lint {
disable 'MissingTranslation'
}
buildFeatures {
buildConfig true
resValues true
viewBinding true
}
testOptions {
Expand All @@ -74,17 +73,18 @@ android {
}
unitTests.all {
systemProperty 'robolectric.logging.enabled', 'true'
}
}
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}

packagingOptions {
// Exclude unneeded files added by libraries
exclude 'LICENSE_OFL'
exclude 'LICENSE_UNICODE'
}
// Exclude unneeded files added by libraries
packagingOptions.resources.excludes += [
'LICENSE_OFL',
'LICENSE_UNICODE',
]

bundle {
language {
// bundle all languages in every apk so the dynamic language switching works
Expand All @@ -95,6 +95,26 @@ android {
includeInApk false
includeInBundle false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}
applicationVariants.configureEach { variant ->
variant.outputs.configureEach {
outputFileName = "Tusky_${variant.versionName}_${variant.versionCode}_${gitSha}_" +
"${variant.flavorName}_${buildType.name}.apk"
}
}
}

kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
arg("room.incremental", "true")
}
}

// library versions are in PROJECT_ROOT/gradle/libs.versions.toml
Expand Down Expand Up @@ -132,11 +152,7 @@ dependencies {
implementation libs.photoview

implementation libs.bundles.material.drawer
implementation libs.material.typeface, {
artifact {
type = "aar"
}
}
implementation libs.material.typeface

implementation libs.image.cropper

Expand All @@ -156,5 +172,4 @@ dependencies {
androidTestImplementation libs.espresso.core
androidTestImplementation libs.androidx.room.testing
androidTestImplementation libs.androidx.test.junit

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
/* set the taskdescription programmatically, the theme would turn it blue */
String appName = getString(R.string.app_name);
Bitmap appIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
int recentsBackgroundColor = MaterialColors.getColor(this, R.attr.colorSurface, Color.BLACK);
int recentsBackgroundColor = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, Color.BLACK);

setTaskDescription(new ActivityManager.TaskDescription(appName, appIcon, recentsBackgroundColor));

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
startActivityWithSlideInAnimation(AnnouncementsActivity.newIntent(context))
}
badgeStyle = BadgeStyle().apply {
textColor = ColorHolder.fromColor(MaterialColors.getColor(binding.mainDrawer, R.attr.colorOnPrimary))
color = ColorHolder.fromColor(MaterialColors.getColor(binding.mainDrawer, R.attr.colorPrimary))
textColor = ColorHolder.fromColor(MaterialColors.getColor(binding.mainDrawer, com.google.android.material.R.attr.colorOnPrimary))
color = ColorHolder.fromColor(MaterialColors.getColor(binding.mainDrawer, androidx.appcompat.R.attr.colorPrimary))
}
},
DividerDrawerItem(),
Expand Down Expand Up @@ -618,7 +618,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje

private fun setupTabs(selectNotificationTab: Boolean) {
val activeTabLayout = if (preferences.getString("mainNavPosition", "top") == "bottom") {
val actionBarSize = getDimension(this, R.attr.actionBarSize)
val actionBarSize = getDimension(this, androidx.appcompat.R.attr.actionBarSize)
val fabMargin = resources.getDimensionPixelSize(R.dimen.fabMargin)
(binding.composeButton.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = actionBarSize + fabMargin
binding.topNav.hide()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidI
* Load colors and dimensions from resources
*/
private fun loadResources() {
toolbarColor = MaterialColors.getColor(this, R.attr.colorSurface, Color.BLACK)
toolbarColor = MaterialColors.getColor(this, com.google.android.material.R.attr.colorSurface, Color.BLACK)
statusBarColorTransparent = getColor(R.color.transparent_statusbar_background)
statusBarColorOpaque = MaterialColors.getColor(this, R.attr.colorPrimaryDark, Color.BLACK)
statusBarColorOpaque = MaterialColors.getColor(this, androidx.appcompat.R.attr.colorPrimaryDark, Color.BLACK)
avatarSize = resources.getDimension(R.dimen.account_activity_avatar_size)
titleVisibleHeight = resources.getDimensionPixelSize(R.dimen.account_activity_scroll_title_visible_height)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AccountMediaGridAdapter(
}
) {

private val baseItemBackgroundColor = MaterialColors.getColor(context, R.attr.colorSurface, Color.BLACK)
private val baseItemBackgroundColor = MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, Color.BLACK)
private val videoIndicator = AppCompatResources.getDrawable(context, R.drawable.ic_play_indicator)
private val mediaHiddenDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_hide_media_24dp)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.viewdata.AttachmentViewData
import javax.inject.Inject

class AccountMediaViewModel @Inject constructor (
class AccountMediaViewModel @Inject constructor(
api: MastodonApi
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AnnouncementAdapter(
item.reactions.forEachIndexed { i, reaction ->
(
chips.getChildAt(i)?.takeUnless { it.id == R.id.addReactionChip } as Chip?
?: Chip(ContextThemeWrapper(chips.context, R.style.Widget_MaterialComponents_Chip_Choice)).apply {
?: Chip(ContextThemeWrapper(chips.context, com.google.android.material.R.style.Widget_MaterialComponents_Chip_Choice)).apply {
isCheckable = true
checkedIcon = null
chips.addView(this, i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class ComposeActivity :
}

private fun setupAvatar(activeAccount: AccountEntity) {
val actionBarSizeAttr = intArrayOf(R.attr.actionBarSize)
val actionBarSizeAttr = intArrayOf(androidx.appcompat.R.attr.actionBarSize)
val a = obtainStyledAttributes(null, actionBarSizeAttr)
val avatarSize = a.getDimensionPixelSize(0, 1)
a.recycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun showAddPollDialog(
var durations = context.resources.getIntArray(R.array.poll_duration_values).toList()
val durationLabels = context.resources.getStringArray(R.array.poll_duration_names).filterIndexed { index, _ -> durations[index] in minDuration..maxDuration }
binding.pollDurationSpinner.adapter = ArrayAdapter(context, android.R.layout.simple_spinner_item, durationLabels).apply {
setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item)
setDropDownViewResource(androidx.appcompat.R.layout.support_simple_spinner_dropdown_item)
}
durations = durations.filter { it in minDuration..maxDuration }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.keylesspalace.tusky.entity.HashTag
import com.keylesspalace.tusky.network.MastodonApi
import javax.inject.Inject

class FollowedTagsViewModel @Inject constructor (
class FollowedTagsViewModel @Inject constructor(
api: MastodonApi
) : ViewModel(), Injectable {
val tags: MutableList<HashTag> = mutableListOf()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/keylesspalace/tusky/db/Converters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import javax.inject.Singleton

@ProvidedTypeConverter
@Singleton
class Converters @Inject constructor (
class Converters @Inject constructor(
private val gson: Gson
) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright 2020 Tusky Contributors
*
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private fun openLinkInBrowser(uri: Uri?, context: Context) {
* @param context context
*/
fun openLinkInCustomTab(uri: Uri, context: Context) {
val toolbarColor = MaterialColors.getColor(context, R.attr.colorSurface, Color.BLACK)
val toolbarColor = MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, Color.BLACK)
val navigationbarColor = MaterialColors.getColor(context, android.R.attr.navigationBarColor, Color.BLACK)
val navigationbarDividerColor = MaterialColors.getColor(context, R.attr.dividerColor, Color.BLACK)
val colorSchemeParams = CustomTabColorSchemeParams.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LicenseCard
init {
val binding = CardLicenseBinding.inflate(LayoutInflater.from(context), this)

setCardBackgroundColor(MaterialColors.getColor(context, R.attr.colorSurface, Color.BLACK))
setCardBackgroundColor(MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, Color.BLACK))

val a = context.theme.obtainStyledAttributes(attrs, R.styleable.LicenseCard, 0, 0)

Expand Down
26 changes: 8 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath libs.android.gradle.plugin
classpath libs.kotlin.gradle.plugin
classpath libs.ktlint.gradle
}
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.ktlint) apply false
}

allprojects {
apply plugin: "org.jlleitschuh.gradle.ktlint"
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
apply plugin: libs.plugins.ktlint.get().pluginId
}

task clean(type: Delete) {
tasks.register('clean') {
delete rootProject.buildDir
}
28 changes: 14 additions & 14 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.

org.gradle.jvmargs=-Xmx4096m

org.gradle.caching=true
org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8
# use parallel execution
org.gradle.parallel=true
# https://docs.gradle.org/7.6/userguide/configuration_cache.html
org.gradle.unsafe.configuration-cache=true

# https://blog.jetbrains.com/kotlin/2022/07/a-new-approach-to-incremental-compilation-in-kotlin/
kotlin.incremental.useClasspathSnapshot=true

# Disable buildFeatures flags by default
android.defaults.buildfeatures.aidl=false
android.defaults.buildfeatures.buildconfig=false
android.defaults.buildfeatures.renderscript=false
android.defaults.buildfeatures.resvalues=false
android.defaults.buildfeatures.shaders=false
android.enableR8.fullMode=true
android.nonTransitiveRClass=true
android.useAndroidX=true
Loading

0 comments on commit 3592318

Please sign in to comment.