Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Sep 1, 2021
2 parents 4689f3a + 61604f7 commit e5f5b50
Show file tree
Hide file tree
Showing 19 changed files with 427 additions and 69 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
with:
name: build-reports
path: ./app/build/reports

- name: Upload build mapping
uses: actions/upload-artifact@v2
with:
name: build-mapping
path: ./app/build/outputs/mapping

unit-test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ For 1.6.0, we're planning to build an experimatal desktop version, this is a big

- Experimatal desktop version.
- Mute and block support.
- Optimizing video play for timelien.
- Optimizing video play for timeline.
- Bug fixes.
- UI/UX tweaking.
- Stability.
Expand Down
13 changes: 5 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ buildscript {

if (enableGoogleVariant) {
// START Non-FOSS component
classpath("com.google.gms:google-services:4.3.5")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.5.2")
classpath("com.google.gms:google-services:4.3.10")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.7.1")
// END Non-FOSS component
}
}
Expand Down Expand Up @@ -113,7 +113,8 @@ android {
if (hasSigningProps) {
signingConfig = signingConfigs.getByName("twidere")
}
isMinifyEnabled = false
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand Down Expand Up @@ -174,10 +175,6 @@ protobuf {
}
}

// TODO: workaround for https://github.com/google/ksp/issues/518
evaluationDependsOn(":assistedProcessor")
evaluationDependsOn(":routeProcessor")

dependencies {
android()
kotlinSerialization()
Expand All @@ -197,7 +194,7 @@ dependencies {
if (enableGoogleVariant) {
// START Non-FOSS component
val googleImplementation by configurations
googleImplementation(platform("com.google.firebase:firebase-bom:26.1.0"))
googleImplementation(platform("com.google.firebase:firebase-bom:28.4.0"))
googleImplementation("com.google.firebase:firebase-analytics-ktx")
googleImplementation("com.google.firebase:firebase-crashlytics-ktx")
googleImplementation("com.google.android.play:core-ktx:1.8.1")
Expand Down
81 changes: 80 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,83 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations

# kotlinx-serialization-json specific. Add this if you have java.lang.NoClassDefFoundError kotlinx.serialization.json.JsonObjectSerializer
-keepclassmembers class kotlinx.serialization.json.** {
*** Companion;
}
-keepclasseswithmembers class kotlinx.serialization.json.** {
kotlinx.serialization.KSerializer serializer(...);
}

-keep,includedescriptorclasses class com.twidere.services.**$$serializer { *; }
-keepclassmembers class com.twidere.services.** {
*** Companion;
}
-keepclasseswithmembers class com.twidere.services.** {
kotlinx.serialization.KSerializer serializer(...);
}

-keep,includedescriptorclasses class com.twidere.twiderex.**$$serializer { *; }
-keepclassmembers class com.twidere.twiderex.** {
*** Companion;
}
-keepclasseswithmembers class com.twidere.twiderex.** {
kotlinx.serialization.KSerializer serializer(...);
}

-keepclassmembers class * extends androidx.datastore.preferences.protobuf.GeneratedMessageLite {
<fields>;
}


# ServiceLoader support
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}

# Most of volatile fields are updated with AFU and should not be mangled
-keepclassmembers class kotlinx.coroutines.** {
volatile <fields>;
}

# Same story for the standard library's SafeContinuation that also uses AtomicReferenceFieldUpdater
-keepclassmembers class kotlin.coroutines.SafeContinuation {
volatile <fields>;
}

# These classes are only required by kotlinx.coroutines.debug.AgentPremain, which is only loaded when
# kotlinx-coroutines-core is used as a Java agent, so these are not needed in contexts where ProGuard is used.
-dontwarn java.lang.instrument.ClassFileTransformer
-dontwarn sun.misc.SignalHandler
-dontwarn java.lang.instrument.Instrumentation
-dontwarn sun.misc.Signal

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-dontwarn org.conscrypt.ConscryptHostnameVerifier

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

-keeppackagenames org.jsoup.nodes

-keep class * extends com.google.protobuf.GeneratedMessageLite { *; }

-keep class com.twidere.services.nitter.model.**

-keepclassmembers class ** {
@moe.tlaster.hson.annotations.HtmlSerializable public *;
}
43 changes: 9 additions & 34 deletions app/src/main/kotlin/com/twidere/twiderex/TwidereXActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ package com.twidere.twiderex

import android.content.Intent
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.net.Uri
import android.os.Bundle
import android.view.WindowManager
Expand Down Expand Up @@ -55,7 +52,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.core.net.ConnectivityManagerCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.lifecycleScope
Expand All @@ -78,6 +74,7 @@ import com.twidere.twiderex.ui.LocalIsActiveNetworkMetered
import com.twidere.twiderex.ui.LocalWindow
import com.twidere.twiderex.ui.LocalWindowInsetsController
import com.twidere.twiderex.utils.CustomTabSignInChannel
import com.twidere.twiderex.utils.IsActiveNetworkMeteredLiveData
import com.twidere.twiderex.utils.LocalPlatformResolver
import com.twidere.twiderex.utils.PlatformResolver
import com.twidere.twiderex.viewmodel.ActiveAccountViewModel
Expand All @@ -92,19 +89,6 @@ class TwidereXActivity : ComponentActivity() {
private val navController by lazy {
NavController()
}
private val isActiveNetworkMetered = MutableStateFlow(false)
private val networkCallback by lazy {
object : ConnectivityManager.NetworkCallback() {
override fun onCapabilitiesChanged(
network: Network,
networkCapabilities: NetworkCapabilities
) {
isActiveNetworkMetered.value = ConnectivityManagerCompat.isActiveNetworkMetered(
connectivityManager
)
}
}
}

@Inject
lateinit var viewModelHolder: TwidereXActivityAssistedViewModelHolder
Expand All @@ -124,15 +108,19 @@ class TwidereXActivity : ComponentActivity() {
@Inject
lateinit var platformResolver: PlatformResolver

private val isActiveNetworkMetered = MutableStateFlow(false)
private val isActiveNetworkMeteredLiveData by lazy {
IsActiveNetworkMeteredLiveData(connectivityManager = connectivityManager)
}

@OptIn(ExperimentalAnimationApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
isActiveNetworkMetered.value = ConnectivityManagerCompat.isActiveNetworkMetered(
connectivityManager
)

WindowCompat.setDecorFitsSystemWindows(window, false)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
isActiveNetworkMeteredLiveData.observe(this) {
isActiveNetworkMetered.value = it
}
setContent {
var showSplash by rememberSaveable { mutableStateOf(true) }
LaunchedEffect(Unit) {
Expand Down Expand Up @@ -230,19 +218,6 @@ class TwidereXActivity : ComponentActivity() {
}
}

override fun onStart() {
super.onStart()
connectivityManager.registerNetworkCallback(
NetworkRequest.Builder().build(),
networkCallback,
)
}

override fun onStop() {
super.onStop()
connectivityManager.unregisterNetworkCallback(networkCallback)
}

override fun onResume() {
super.onResume()
lifecycleScope.launchWhenResumed {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.twidere.services.http.config.HttpConfigClientFactory
import com.twidere.services.mastodon.MastodonService
import com.twidere.services.microblog.MicroBlogService
import com.twidere.services.twitter.TwitterService
import com.twidere.twiderex.model.MicroBlogKey
import com.twidere.twiderex.model.cred.Credentials
import com.twidere.twiderex.model.cred.OAuth2Credentials
import com.twidere.twiderex.model.cred.OAuthCredentials
Expand All @@ -39,7 +40,7 @@ class TwidereServiceFactory(private val configProvider: TwidereHttpConfigProvide
instance = TwidereServiceFactory(configProvider)
}

fun createApiService(type: PlatformType, credentials: Credentials, host: String = ""): MicroBlogService {
fun createApiService(type: PlatformType, credentials: Credentials, accountKey: MicroBlogKey): MicroBlogService {
return instance?.let {
when (type) {
PlatformType.Twitter -> {
Expand All @@ -51,7 +52,8 @@ class TwidereServiceFactory(private val configProvider: TwidereHttpConfigProvide
consumer_secret = it.consumer_secret,
access_token = it.access_token,
access_token_secret = it.access_token_secret,
httpClientFactory = createHttpClientFactory()
httpClientFactory = createHttpClientFactory(),
accountId = accountKey.id
)
}
}
Expand All @@ -62,7 +64,7 @@ class TwidereServiceFactory(private val configProvider: TwidereHttpConfigProvide
it as OAuth2Credentials
}.let {
MastodonService(
host,
accountKey.host,
it.access_token,
httpClientFactory = createHttpClientFactory()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data class AccountDetails(
TwidereServiceFactory.createApiService(
type = type,
credentials = credentials,
host = accountKey.host
accountKey = accountKey
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Twidere X
*
* Copyright (C) 2020-2021 Tlaster <tlaster@outlook.com>
*
* This file is part of Twidere X.
*
* Twidere X is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Twidere X is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Twidere X. If not, see <http://www.gnu.org/licenses/>.
*/
package com.twidere.twiderex.utils

import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import androidx.core.net.ConnectivityManagerCompat
import androidx.lifecycle.LiveData

class IsActiveNetworkMeteredLiveData(
private val connectivityManager: ConnectivityManager,
) : LiveData<Boolean>() {
private val request = NetworkRequest.Builder().build()
private val networkCallback by lazy {
object : ConnectivityManager.NetworkCallback() {
override fun onCapabilitiesChanged(
network: Network,
networkCapabilities: NetworkCapabilities
) {
updateValue()
}
}
}

private fun updateValue() {
postValue(
ConnectivityManagerCompat.isActiveNetworkMetered(
connectivityManager
)
)
}

override fun onActive() {
super.onActive()
updateValue()
connectivityManager.registerNetworkCallback(
request,
networkCallback,
)
}

override fun onInactive() {
super.onInactive()
connectivityManager.unregisterNetworkCallback(networkCallback)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class TwitterSignInViewModel @AssistedInject constructor(
access_token = accessToken.oauth_token,
access_token_secret = accessToken.oauth_token_secret
),
accountKey = MicroBlogKey.Empty
) as TwitterService
).verifyCredentials()
if (user != null) {
Expand Down
Loading

0 comments on commit e5f5b50

Please sign in to comment.