Skip to content

Commit

Permalink
Merge pull request orgzly-revived#339 from amberin/target-api-34-and-…
Browse files Browse the repository at this point in the history
…upgrade-deps

Target API 34 and upgrade some Android dependencies
  • Loading branch information
amberin authored Oct 15, 2024
2 parents 3e279f7 + c200061 commit 01c7c95
Show file tree
Hide file tree
Showing 22 changed files with 171 additions and 72 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: 'kotlin-kapt'
android {
namespace 'com.orgzly'

compileSdkVersion 33
compileSdk 34

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode 221
versionName "1.8.27"
applicationId = "com.orgzlyrevived"
Expand Down
57 changes: 56 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

-dontwarn org.joda.convert.**

-dontwarn org.eclipse.jgit.**
-dontwarn com.jcraft.**
-dontwarn org.slf4j.**

Expand All @@ -59,3 +58,59 @@

-keepnames public class * extends org.eclipse.jgit.nls.TranslationBundle
-keepclassmembers class * extends org.eclipse.jgit.nls.TranslationBundle { *; }

# Added when upgrading to AGP 8
-keep public class org.apache.sshd.common.**
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.CheckReturnValue
-dontwarn com.google.errorprone.annotations.Immutable
-dontwarn java.lang.management.ManagementFactory
-dontwarn java.lang.management.RuntimeMXBean
-dontwarn javax.management.InstanceAlreadyExistsException
-dontwarn javax.management.InstanceNotFoundException
-dontwarn javax.management.JMException
-dontwarn javax.management.MBeanException
-dontwarn javax.management.MBeanRegistrationException
-dontwarn javax.management.MBeanServer
-dontwarn javax.management.MalformedObjectNameException
-dontwarn javax.management.NotCompliantMBeanException
-dontwarn javax.management.ObjectInstance
-dontwarn javax.management.ObjectName
-dontwarn javax.management.ReflectionException
-dontwarn javax.security.auth.login.CredentialException
-dontwarn javax.security.auth.login.FailedLoginException
-dontwarn org.apache.sshd.sftp.SftpModuleProperties
-dontwarn org.apache.sshd.sftp.client.SftpClient$Attributes
-dontwarn org.apache.sshd.sftp.client.SftpClient$CloseableHandle
-dontwarn org.apache.sshd.sftp.client.SftpClient$CopyMode
-dontwarn org.apache.sshd.sftp.client.SftpClient$DirEntry
-dontwarn org.apache.sshd.sftp.client.SftpClient$Handle
-dontwarn org.apache.sshd.sftp.client.SftpClient
-dontwarn org.apache.sshd.sftp.client.SftpClientFactory
-dontwarn org.apache.sshd.sftp.common.SftpException
-dontwarn org.bouncycastle.crypto.prng.RandomGenerator
-dontwarn org.bouncycastle.crypto.prng.VMPCRandomGenerator
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.bouncycastle.openssl.PEMDecryptorProvider
-dontwarn org.bouncycastle.openssl.PEMEncryptedKeyPair
-dontwarn org.bouncycastle.openssl.PEMKeyPair
-dontwarn org.bouncycastle.openssl.PEMParser
-dontwarn org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter
-dontwarn org.bouncycastle.openssl.jcajce.JcaPEMWriter
-dontwarn org.bouncycastle.openssl.jcajce.JcePEMDecryptorProviderBuilder
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.conscrypt.ConscryptHostnameVerifier
-dontwarn org.ietf.jgss.GSSContext
-dontwarn org.ietf.jgss.GSSCredential
-dontwarn org.ietf.jgss.GSSException
-dontwarn org.ietf.jgss.GSSManager
-dontwarn org.ietf.jgss.GSSName
-dontwarn org.ietf.jgss.MessageProp
-dontwarn org.ietf.jgss.Oid
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE
-dontwarn sun.security.x509.X509Key
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ private ActivityScenario<BookChooserActivity> startActivityWithCreateShortcutAct
return ActivityScenario.launch(intent);
}

private ActivityScenario<BookChooserActivity> startActivityForResult() {
Intent intent = new Intent(context, BookChooserActivity.class);
intent.setAction(Intent.ACTION_CREATE_SHORTCUT);
return ActivityScenario.launchActivityForResult(intent);
}

@Before
public void setUp() throws Exception {
super.setUp();
Expand Down Expand Up @@ -60,7 +66,7 @@ public void testLongClickChoosesBook() {

@Test
public void testCreateShortcut() {
ActivityScenario<BookChooserActivity> scenario = startActivityWithCreateShortcutAction();
ActivityScenario<BookChooserActivity> scenario = startActivityForResult();

onView(allOf(withText("book-one"), isDisplayed())).perform(click());

Expand Down
29 changes: 16 additions & 13 deletions app/src/androidTest/java/com/orgzly/android/espresso/GitRepoTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.orgzly.android.espresso

import android.os.SystemClock
import androidx.core.net.toUri
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso
Expand Down Expand Up @@ -63,19 +64,21 @@ class GitRepoTest : OrgzlyTest() {
testUtils.setupBook("book-1", "...")
testUtils.setupBook("book-2", "...")
testUtils.setupBook("book-3", "...")
ActivityScenario.launch(MainActivity::class.java)
sync()
assertEquals(3, dataRepository.getBooks().size)
onBook(0, R.id.item_book_link_repo).check(ViewAssertions.matches(withText(repo.url)))
onBook(1, R.id.item_book_link_repo).check(ViewAssertions.matches(withText(repo.url)))
onBook(2, R.id.item_book_link_repo).check(ViewAssertions.matches(withText(repo.url)))
onBook(0).perform(ViewActions.longClick())
onBook(1).perform(ViewActions.click())
onBook(2).perform(ViewActions.click())
contextualToolbarOverflowMenu().perform(ViewActions.click())
Espresso.onView(withText(R.string.delete)).perform(ViewActions.click())
Espresso.onView(withId(R.id.delete_linked_checkbox)).perform(ViewActions.click())
Espresso.onView(withText(R.string.delete)).perform(ViewActions.click())
assertEquals(0, dataRepository.getBooks().size)
ActivityScenario.launch(MainActivity::class.java).use {
sync()
SystemClock.sleep(500)
onBook(0, R.id.item_book_link_repo).check(ViewAssertions.matches(withText(repo.url)))
onBook(1, R.id.item_book_link_repo).check(ViewAssertions.matches(withText(repo.url)))
onBook(2, R.id.item_book_link_repo).check(ViewAssertions.matches(withText(repo.url)))
onBook(0).perform(ViewActions.longClick())
onBook(1).perform(ViewActions.click())
onBook(2).perform(ViewActions.click())
contextualToolbarOverflowMenu().perform(ViewActions.click())
Espresso.onView(withText(R.string.delete)).perform(ViewActions.click())
Espresso.onView(withId(R.id.delete_linked_checkbox)).perform(ViewActions.click())
Espresso.onView(withText(R.string.delete)).perform(ViewActions.click())
assertEquals(0, dataRepository.getBooks().size)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public void testClickingNote() {
defaultSetUp();

onView(allOf(withText("book-two"), isDisplayed())).perform(click());
SystemClock.sleep(200);
searchForTextCloseKeyboard("b.book-two Note");
onView(withId(R.id.fragment_query_search_view_flipper)).check(matches(isDisplayed()));
onNotesInSearch().check(matches(recyclerViewItemCount(29)));
Expand Down Expand Up @@ -385,7 +384,6 @@ public void testInheritedAndOwnTag() {
scenario = ActivityScenario.launch(MainActivity.class);

onView(allOf(withText("notebook-1"), isDisplayed())).perform(click());
SystemClock.sleep(200);
searchForTextCloseKeyboard("t.tag1 t.tag2");
onView(withId(R.id.fragment_query_search_view_flipper)).check(matches(isDisplayed()));
onNotesInSearch().check(matches(recyclerViewItemCount(3)));
Expand Down Expand Up @@ -617,7 +615,6 @@ public void testSearchForTagOrTag() {
scenario = ActivityScenario.launch(MainActivity.class);

onView(allOf(withText("notebook"), isDisplayed())).perform(click());
SystemClock.sleep(200);
searchForTextCloseKeyboard("tn.a or tn.b");
onView(withId(R.id.fragment_query_search_view_flipper)).check(matches(isDisplayed()));
onNotesInSearch().check(matches(recyclerViewItemCount(2)));
Expand Down Expand Up @@ -726,7 +723,6 @@ public void testSearchWithState() {
scenario = ActivityScenario.launch(MainActivity.class);

onView(allOf(withText("notebook"), isDisplayed())).perform(click());
SystemClock.sleep(200);
searchForTextCloseKeyboard(".it.none");
onView(withId(R.id.fragment_query_search_view_flipper)).check(matches(isDisplayed()));
onNotesInSearch().check(matches(recyclerViewItemCount(3)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ public static ViewInteraction contextualToolbarOverflowMenu() {
}

public static void searchForTextCloseKeyboard(String str) {
SystemClock.sleep(200);
onView(isRoot()).perform(waitId(R.id.search_view, 5000));
onView(allOf(withId(R.id.search_view), isDisplayed())).perform(click());
SystemClock.sleep(200);
onView(isRoot()).perform(waitId(R.id.search_src_text, 5000));
onView(withId(R.id.search_src_text)).perform(replaceText(str), pressKey(KeyEvent.KEYCODE_ENTER));
closeSoftKeyboardWithDelay();
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/orgzly/android/data/DataRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import android.os.Handler
import android.text.TextUtils
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.map
import androidx.localbroadcastmanager.content.LocalBroadcastManager

Check warning on line 15 in app/src/main/java/com/orgzly/android/data/DataRepository.kt

View workflow job for this annotation

GitHub Actions / localUnitTests

'LocalBroadcastManager' is deprecated. Deprecated in Java

Check warning on line 15 in app/src/main/java/com/orgzly/android/data/DataRepository.kt

View workflow job for this annotation

GitHub Actions / localUnitTests

'LocalBroadcastManager' is deprecated. Deprecated in Java
import androidx.sqlite.db.SupportSQLiteQuery
import androidx.sqlite.db.SupportSQLiteQueryBuilder
Expand Down Expand Up @@ -2119,7 +2119,7 @@ class DataRepository @Inject constructor(
* Return all known tags
*/
fun selectAllTagsLiveData(): LiveData<List<String>> {
return Transformations.map(db.note().getDistinctTagsLiveData()) { tagsList ->
return db.note().getDistinctTagsLiveData().map { tagsList ->
tagsList.flatMap { Note.dbDeSerializeTags(it) }.distinct().sorted()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;

import com.orgzly.android.App;
import com.orgzly.android.ui.notifications.Notifications;
Expand Down Expand Up @@ -103,7 +104,12 @@ public void onReceive(Context context, Intent intent) {
intentFilter.addAction(ACTION_REJECT_REMOTE_HOST_KEY);
intentFilter.addAction(ACTION_ACCEPT_REMOTE_HOST_KEY);
intentFilter.addAction(ACTION_ACCEPT_AND_STORE_REMOTE_HOST_KEY);
context.registerReceiver(broadcastReceiver, intentFilter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(broadcastReceiver, intentFilter,
Context.RECEIVER_EXPORTED);
} else {
context.registerReceiver(broadcastReceiver, intentFilter);
}

// Send the notification and wait up to 30 seconds for the user to respond
Notifications.showSshRemoteHostKeyPrompt(context, uri, items);
Expand Down Expand Up @@ -132,4 +138,4 @@ public void onReceive(Context context, Intent intent) {
return questions.get(0).getValue();
}
}
}
}
13 changes: 9 additions & 4 deletions app/src/main/java/com/orgzly/android/sync/SyncRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import android.content.Intent
import androidx.core.content.ContextCompat.startActivity
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import androidx.work.*
import androidx.lifecycle.map
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.workDataOf
import com.orgzly.BuildConfig
import com.orgzly.R
import com.orgzly.android.App
Expand Down Expand Up @@ -83,8 +88,8 @@ object SyncRunner {
}

@JvmStatic
fun onStateChange(tag: String): LiveData<SyncState> {
return Transformations.map(onAllWorkInfo()) { workInfoList ->
fun onStateChange(tag: String): LiveData<SyncState?> {
return onAllWorkInfo().map { workInfoList ->
syncStateFromWorkInfoList(workInfoList).also { state ->
logStateChange(tag, state, workInfoList)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class SyncProgressViewModel : ViewModel() {
init {
viewModelScope.launch {
SyncRunner.onStateChange("sync-view-model").asFlow().collect {
_syncState.tryEmit(it)
if (it != null) {
_syncState.tryEmit(it)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.orgzly.android.ui.books

import android.net.Uri
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.map
import androidx.lifecycle.switchMap
import com.orgzly.BuildConfig
import com.orgzly.android.App
import com.orgzly.android.BookFormat
Expand Down Expand Up @@ -48,8 +49,8 @@ class BooksViewModel(private val dataRepository: DataRepository) : CommonViewMod

val viewState = MutableLiveData<ViewState>(ViewState.LOADING)

val data = Transformations.switchMap(booksParams) {
Transformations.map(dataRepository.getBooksLiveData()) { books ->
val data = booksParams.switchMap {
dataRepository.getBooksLiveData().map { books ->
viewState.value = if (books.isNotEmpty()) {
ViewState.LOADED
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.orgzly.android.ui.main
import android.net.Uri
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.switchMap
import com.orgzly.BuildConfig
import com.orgzly.R
import com.orgzly.android.App
Expand All @@ -15,14 +15,21 @@ import com.orgzly.android.db.entity.SavedSearch
import com.orgzly.android.prefs.AppPreferences
import com.orgzly.android.ui.CommonViewModel
import com.orgzly.android.ui.SingleLiveEvent
import com.orgzly.android.usecase.*
import com.orgzly.android.usecase.BookScrollToNote
import com.orgzly.android.usecase.BookSparseTreeForNote
import com.orgzly.android.usecase.LinkFindTarget
import com.orgzly.android.usecase.NoteFindWithProperty
import com.orgzly.android.usecase.NoteUpdateClockingState
import com.orgzly.android.usecase.SavedSearchExport
import com.orgzly.android.usecase.SavedSearchImport
import com.orgzly.android.usecase.UseCaseRunner
import com.orgzly.android.util.LogUtils
import java.io.File

class MainActivityViewModel(private val dataRepository: DataRepository) : CommonViewModel() {
private val booksParams = MutableLiveData<String>()

private val booksSubject: LiveData<List<BookView>> = Transformations.switchMap(booksParams) {
private val booksSubject: LiveData<List<BookView>> = booksParams.switchMap {
dataRepository.getBooksLiveData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlin.math.atan2
*/
open class OnSwipeListener : SimpleOnGestureListener() {
override fun onFling(
e1: MotionEvent,
e1: MotionEvent?,
e2: MotionEvent,
velocityX: Float,
velocityY: Float
Expand All @@ -33,7 +33,7 @@ open class OnSwipeListener : SimpleOnGestureListener() {
// C => it's a DOWN swipe
// D => it's a LEFT swipe

val x1 = e1.x
val x1 = e1!!.x
val y1 = e1.y
val x2 = e2.x
val y2 = e2.y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.orgzly.android.ui.notes.book

import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.switchMap
import com.orgzly.android.App
import com.orgzly.android.data.DataRepository
import com.orgzly.android.db.entity.Book
import com.orgzly.android.db.entity.NoteView
import com.orgzly.android.ui.AppBar
import com.orgzly.android.ui.CommonViewModel
import com.orgzly.android.ui.SingleLiveEvent
import com.orgzly.android.ui.AppBar
import com.orgzly.android.usecase.BookCycleVisibility
import com.orgzly.android.usecase.UseCaseRunner

Expand All @@ -34,7 +34,7 @@ class BookViewModel(private val dataRepository: DataRepository, val bookId: Long

data class Data(val book: Book?, val notes: List<NoteView>?)

val data = Transformations.switchMap(params) { _ ->
val data = params.switchMap { _ ->
MediatorLiveData<Data>().apply {
addSource(dataRepository.getBookLiveData(bookId)) {
value = Data(it, value?.notes)
Expand Down
Loading

0 comments on commit 01c7c95

Please sign in to comment.