Skip to content

Commit

Permalink
Merge branch 'sdk-34' into v1.9-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
oakkitten committed Jan 19, 2024
2 parents fd80e93 + 4820634 commit f795384
Show file tree
Hide file tree
Showing 22 changed files with 457 additions and 127 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ jobs:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Install Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Checkout repository
uses: actions/checkout@v2
with:
Expand All @@ -19,6 +25,12 @@ jobs:
name: Build release apk
runs-on: ubuntu-latest
steps:
- name: Install Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Checkout repository
uses: actions/checkout@v2
with:
Expand Down
53 changes: 27 additions & 26 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,63 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.20")

// these two are required for logging within the relay module. todo remove?
implementation("org.slf4j:slf4j-api:1.7.36")
implementation("org.slf4j:slf4j-api:2.0.9")
implementation("com.noveogroup.android:android-logger:1.3.6")

implementation("androidx.core:core-ktx:1.8.0")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("androidx.annotation:annotation:1.3.0") // For @Nullable/@NonNull
implementation("androidx.appcompat:appcompat:1.4.2")
implementation("androidx.emoji2:emoji2:1.1.0")
implementation("androidx.preference:preference-ktx:1.2.0") // preference fragment & al
implementation("androidx.annotation:annotation:1.7.1") // For @Nullable/@NonNull
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.emoji2:emoji2:1.4.0")
implementation("androidx.preference:preference-ktx:1.2.1") // preference fragment & al
implementation("androidx.legacy:legacy-preference-v14:1.0.0") // styling for the fragment
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
implementation("androidx.lifecycle:lifecycle-common-java8:2.4.1")
implementation("androidx.sharetarget:sharetarget:1.2.0-rc01")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-common-java8:2.6.2")
implementation("androidx.sharetarget:sharetarget:1.2.0")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")

implementation("com.github.bumptech.glide:glide:4.13.2")
kapt("com.github.bumptech.glide:compiler:4.13.2")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.github.bumptech.glide:glide:4.16.0")
kapt("com.github.bumptech.glide:compiler:4.16.0")
implementation("com.squareup.okhttp3:okhttp:4.12.0")

val roomVersion = "2.4.2"
val roomVersion = "2.6.1"
implementation("androidx.room:room-runtime:$roomVersion")
annotationProcessor("androidx.room:room-compiler:$roomVersion")
kapt("androidx.room:room-compiler:$roomVersion")

implementation("org.yaml:snakeyaml:1.30")
implementation("org.yaml:snakeyaml:2.2")

implementation("org.bouncycastle:bcpkix-jdk15on:1.70")

// needed for thread-safe date formatting as SimpleDateFormat isn"t thread-safe
// the alternatives, including apache commons and threetenabp, seem to be much slower
// todo perhaps replace with core library desugaring, if it"s fast
implementation("net.danlew:android.joda:2.10.14")
implementation("net.danlew:android.joda:2.12.6")

implementation("org.greenrobot:eventbus:3.3.1")

debugImplementation("org.aspectj:aspectjrt:1.9.9.1")
debugImplementation("com.squareup.leakcanary:leakcanary-android:2.9.1")
debugImplementation("org.aspectj:aspectjrt:1.9.20.1")
debugImplementation("com.squareup.leakcanary:leakcanary-android:2.12")

testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.8.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.1")
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

android {
compileSdk = 31
namespace = "com.ubergeek42.WeechatAndroid"
compileSdk = 34

defaultConfig {
versionCode = 1_08_01
versionName = "1.8.1"

minSdk = 21
targetSdk = 31
targetSdk = 34
buildConfigField("String", "VERSION_BANNER", "\"" + versionBanner() + "\"")

vectorDrawables.useSupportLibrary = true
Expand All @@ -87,7 +88,7 @@ android {
}

kotlinOptions {
jvmTarget = "11"
jvmTarget = "17"
}
}

Expand Down Expand Up @@ -133,8 +134,8 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}

Expand Down Expand Up @@ -211,7 +212,7 @@ fun weave(classPath: Iterable<File>, aspectPath: Iterable<File>, input: Iterable
val weaving: Configuration by configurations.creating

dependencies {
weaving("org.aspectj:aspectjtools:1.9.9.1")
weaving("org.aspectj:aspectjtools:1.9.20.1")
}

// historical note: the problem with weaving Kotlin and Java in-place is that:
Expand Down
8 changes: 8 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
-dontwarn java.beans.PropertyDescriptor


# Gets rid of the warning,
# Missing class com.google.errorprone.annotations.Immutable
# (referenced from: com.google.crypto.tink.util.Bytes)
# Should be safe to use. See:
# https://github.com/google/tink/issues/536
# https://issuetracker.google.com/issues/195752905
-dontwarn com.google.errorprone.annotations.Immutable

# ~*~*~*~ Historical rules, left here for lamenting and general amusement ~*~*~*~

# Looks like we aren't getting warnings anymore!
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.ubergeek42.WeechatAndroid">
xmlns:tools="http://schemas.android.com/tools">

<uses-sdk tools:overrideLibrary="android.support.v14.preference" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
Expand All @@ -34,7 +35,9 @@
android:requestLegacyExternalStorage="true"
android:windowSoftInputMode="adjustResize">

<service android:name=".service.RelayService" />
<service
android:name=".service.RelayService"
android:foregroundServiceType="dataSync" />

<activity
android:name=".WeechatActivity"
Expand Down
41 changes: 32 additions & 9 deletions app/src/main/java/com/ubergeek42/WeechatAndroid/WeechatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
package com.ubergeek42.WeechatAndroid

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
Expand Down Expand Up @@ -53,14 +54,19 @@ import com.ubergeek42.WeechatAndroid.dialogs.ScrollableDialog
import com.ubergeek42.WeechatAndroid.fragments.BufferFragment
import com.ubergeek42.WeechatAndroid.fragments.BufferFragmentContainer
import com.ubergeek42.WeechatAndroid.media.CachePersist
import com.ubergeek42.WeechatAndroid.notifications.NotificationPermissionChecker
import com.ubergeek42.WeechatAndroid.notifications.shortcuts
import com.ubergeek42.WeechatAndroid.notifications.shouldRequestNotificationPermission
import com.ubergeek42.WeechatAndroid.notifications.showNotificationPermissionRationaleDialog
import com.ubergeek42.WeechatAndroid.notifications.statistics
import com.ubergeek42.WeechatAndroid.relay.BufferList
import com.ubergeek42.WeechatAndroid.service.Events.ExceptionEvent
import com.ubergeek42.WeechatAndroid.service.Events.StateChangedEvent
import com.ubergeek42.WeechatAndroid.service.P
import com.ubergeek42.WeechatAndroid.service.RelayService
import com.ubergeek42.WeechatAndroid.service.getSystemTrustedCertificateChain
import com.ubergeek42.WeechatAndroid.service.showAlarmPermissionRationaleDialog
import com.ubergeek42.WeechatAndroid.service.shouldRequestExactAlarmPermission
import com.ubergeek42.WeechatAndroid.upload.Config
import com.ubergeek42.WeechatAndroid.upload.InsertAt
import com.ubergeek42.WeechatAndroid.upload.ShareObject
Expand Down Expand Up @@ -127,6 +133,11 @@ class WeechatActivity : AppCompatActivity(), CutePageChangeListener,

private val toolbarController = ToolbarController(this).apply { observeLifecycle() }

val notificationPermissionChecker = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> NotificationPermissionChecker(this)
else -> null
}

init { WeechatActivityFullScreenController(this).observeLifecycle() }

////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -199,7 +210,7 @@ class WeechatActivity : AppCompatActivity(), CutePageChangeListener,

menuBackgroundDrawable = ContextCompat.getDrawable(this, R.drawable.bg_popup_menu)!!

if (P.isServiceAlive()) connect()
if (savedInstanceState == null && P.isServiceAlive()) connect()

// restore buffers if we have data in the static
// if no data and not going to connect, clear stuff
Expand All @@ -213,13 +224,25 @@ class WeechatActivity : AppCompatActivity(), CutePageChangeListener,

@MainThread @CatD(linger = true) fun connect() {
P.loadConnectionPreferences()
val error = P.validateConnectionPreferences()
if (error != 0) {
Toaster.ErrorToast.show(error)
} else {
kitty.debug("proceeding!")
RelayService.startWithAction(this, RelayService.ACTION_START)

val errorStringId = P.validateConnectionPreferences()
if (errorStringId != 0) {
Toaster.ErrorToast.show(errorStringId)
return
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && shouldRequestExactAlarmPermission()) {
showAlarmPermissionRationaleDialog()
return
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && shouldRequestNotificationPermission()) {
showNotificationPermissionRationaleDialog()
return
}

kitty.debug("proceeding!")
RelayService.startWithAction(this, RelayService.ACTION_START)
}

@MainThread @CatD fun disconnect() {
Expand Down Expand Up @@ -462,7 +485,7 @@ class WeechatActivity : AppCompatActivity(), CutePageChangeListener,
@MainThread @Cat("Menu") override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_actionbar, menu)

val menuHotlist = menu.findItem(R.id.menu_hotlist).actionView
val menuHotlist = menu.findItem(R.id.menu_hotlist).actionView!!
uiHot = menuHotlist.findViewById(R.id.hotlist_hot)

// set color of the border around the [2] badge on the bell, as well as text color
Expand Down Expand Up @@ -548,7 +571,7 @@ class WeechatActivity : AppCompatActivity(), CutePageChangeListener,
})
menu.findItem(R.id.menu_connection_state).title = connectionStateTitle

val menuHotlist = menu.findItem(R.id.menu_hotlist).actionView
val menuHotlist = menu.findItem(R.id.menu_hotlist).actionView!!
val bellImage = menuHotlist.findViewById<ImageView>(R.id.hotlist_bell)
bellImage.setImageResource(if (P.optimizeTraffic) R.drawable.ic_toolbar_bell_cracked else R.drawable.ic_toolbar_bell)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.ubergeek42.WeechatAndroid.dialogs

import android.app.Dialog
import android.content.Context
import android.widget.ScrollView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatTextView
import com.ubergeek42.WeechatAndroid.R

private class ButtonInfo(
val title: CharSequence,
val onClickListener: () -> Unit
)

private class ScrollableDialogInfo(
var text: CharSequence? = null,
var title: CharSequence? = null,
var positiveButton: ButtonInfo? = null,
var negativeButton: ButtonInfo? = null,
)

interface ScrollableDialogBuilder {
fun setTitle(title: CharSequence)
fun setTitle(titleResourceId: Int)
fun setText(text: CharSequence)
fun setText(textResourceId: Int)
fun setPositiveButton(title: CharSequence, onClickListener: () -> Unit)
fun setPositiveButton(titleResourceId: Int, onClickListener: () -> Unit)
fun setNegativeButton(title: CharSequence, onClickListener: () -> Unit)
fun setNegativeButton(titleResourceId: Int, onClickListener: () -> Unit)
}

private class ScrollableDialogBuilderImpl(val context: Context) : ScrollableDialogBuilder {
val info = ScrollableDialogInfo()
override fun setTitle(title: CharSequence) {
info.title = title
}

override fun setTitle(titleResourceId: Int) {
info.title = context.getString(titleResourceId)
}

override fun setText(text: CharSequence) {
info.text = text
}

override fun setText(textResourceId: Int) {
info.text = context.getString(textResourceId)
}

override fun setPositiveButton(title: CharSequence, onClickListener: () -> Unit) {
info.positiveButton = ButtonInfo(title, onClickListener)
}

override fun setPositiveButton(titleResourceId: Int, onClickListener: () -> Unit) {
info.positiveButton = ButtonInfo(context.getString(titleResourceId), onClickListener)
}

override fun setNegativeButton(title: CharSequence, onClickListener: () -> Unit) {
info.negativeButton = ButtonInfo(title, onClickListener)
}

override fun setNegativeButton(titleResourceId: Int, onClickListener: () -> Unit) {
info.negativeButton = ButtonInfo(context.getString(titleResourceId), onClickListener)
}
}

fun Context.createScrollableDialog(builderBlock: ScrollableDialogBuilder.() -> Unit): Dialog {
val info = ScrollableDialogBuilderImpl(this).apply(builderBlock).info

val padding = resources.getDimension(R.dimen.dialog_padding_full).toInt()
val scrollView = ScrollView(this)
scrollView.addView(AppCompatTextView(this).apply { text = info.text })
scrollView.setPadding(padding, padding / 2, padding, 0)

val builder: AlertDialog.Builder = FancyAlertDialogBuilder(this)
.setTitle(info.title)
.setView(scrollView)

info.positiveButton?.let {
builder.setPositiveButton(it.title) { _, _ -> it.onClickListener() }
}

info.negativeButton?.let {
builder.setNegativeButton(it.title) { _, _ -> it.onClickListener() }
}

return builder.create()
}
Loading

0 comments on commit f795384

Please sign in to comment.