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

Target API 34 #571

Closed
wants to merge 8 commits into from
Closed
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
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
22 changes: 11 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ dependencies {
implementation(project(":cats"))
implementation(project(":relay"))

implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10")
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:2.0.9")
implementation("com.noveogroup.android:android-logger:1.3.6")

implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("androidx.annotation:annotation:1.7.0") // For @Nullable/@NonNull
implementation("androidx.annotation:annotation:1.7.1") // For @Nullable/@NonNull
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.emoji2:emoji2:1.3.0")
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.6.2")
Expand All @@ -37,9 +37,9 @@ dependencies {

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

val roomVersion = "2.5.2"
val roomVersion = "2.6.1"
implementation("androidx.room:room-runtime:$roomVersion")
annotationProcessor("androidx.room:room-compiler:$roomVersion")
kapt("androidx.room:room-compiler:$roomVersion")
Expand All @@ -51,15 +51,15 @@ dependencies {
// 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.12.5")
implementation("net.danlew:android.joda:2.12.6")

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

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

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

tasks.withType<JavaCompile> {
Expand All @@ -68,14 +68,14 @@ tasks.withType<JavaCompile> {

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

defaultConfig {
versionCode = 1_08_01
versionName = "1.8.1"

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

vectorDrawables.useSupportLibrary = true
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
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
<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 @@ -33,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
38 changes: 31 additions & 7 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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh not really sure, did that commit a while back

I'm assuming that connect() was called too often but this wasn't a problem since if we were connected it was no-op. Now that it checks for permissions and stuff it was easier to fix the too much part than reworking the logic otherwise?

Can't be sure tho


// restore buffers if we have data in the static
// if no data and not going to connect, clear stuff
Expand All @@ -213,13 +224,26 @@ 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
}

@SuppressLint("NewApi") // notificationPermissionChecker is null on incompatible APIs
if (shouldRequestNotificationPermission()) {
showNotificationPermissionRationaleDialog()
return
}

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

@MainThread @CatD fun disconnect() {
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
Loading