-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
362 changed files
with
3,945 additions
and
1,065 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ Twidere X is still in an early stage and will be periodically re-structuring/ref | |
``` | ||
Twidere X | ||
Copyright (C) 2020 Tlaster <[email protected]> | ||
Copyright (C) 2020-2021 Tlaster <[email protected]> | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/androidTest/java/com/twidere/twiderex/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Twidere X | ||
* | ||
* Copyright (C) 2020 Tlaster <[email protected]> | ||
* Copyright (C) 2020-2021 Tlaster <[email protected]> | ||
* | ||
* This file is part of Twidere X. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Twidere X | ||
* | ||
* Copyright (C) 2020 Tlaster <[email protected]> | ||
* Copyright (C) 2020-2021 Tlaster <[email protected]> | ||
* | ||
* This file is part of Twidere X. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Twidere X | ||
* | ||
* Copyright (C) 2020 Tlaster <[email protected]> | ||
* Copyright (C) 2020-2021 Tlaster <[email protected]> | ||
* | ||
* This file is part of Twidere X. | ||
* | ||
|
@@ -21,7 +21,18 @@ | |
package com.twidere.twiderex | ||
|
||
import android.app.Application | ||
import androidx.hilt.work.HiltWorkerFactory | ||
import androidx.work.Configuration | ||
import dagger.hilt.android.HiltAndroidApp | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class TwidereApp : Application() | ||
class TwidereApp : Application(), Configuration.Provider { | ||
@Inject | ||
lateinit var workerFactory: HiltWorkerFactory | ||
|
||
override fun getWorkManagerConfiguration() = | ||
Configuration.Builder() | ||
.setWorkerFactory(workerFactory) | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Twidere X | ||
* | ||
* Copyright (C) 2020 Tlaster <[email protected]> | ||
* Copyright (C) 2020-2021 Tlaster <[email protected]> | ||
* | ||
* This file is part of Twidere X. | ||
* | ||
|
@@ -20,6 +20,10 @@ | |
*/ | ||
package com.twidere.twiderex | ||
|
||
import android.net.ConnectivityManager | ||
import android.net.Network | ||
import android.net.NetworkCapabilities | ||
import android.net.NetworkRequest | ||
import android.os.Build | ||
import android.os.Bundle | ||
import android.view.WindowManager | ||
|
@@ -31,25 +35,30 @@ import androidx.compose.runtime.livedata.observeAsState | |
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.setContent | ||
import androidx.compose.ui.viewinterop.viewModel | ||
import androidx.core.net.ConnectivityManagerCompat | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.hilt.lifecycle.HiltViewModelFactory | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.navigation.NavHostController | ||
import androidx.navigation.compose.ComposeNavigator | ||
import androidx.navigation.fragment.DialogFragmentNavigator | ||
import com.twidere.twiderex.action.AmbientStatusActions | ||
import com.twidere.twiderex.action.StatusActions | ||
import com.twidere.twiderex.component.foundation.AmbientInAppNotification | ||
import com.twidere.twiderex.di.assisted.AssistedViewModelFactoryHolder | ||
import com.twidere.twiderex.di.assisted.ProvideAssistedFactory | ||
import com.twidere.twiderex.extensions.ProvideNavigationViewModelFactoryMap | ||
import com.twidere.twiderex.launcher.ActivityLauncher | ||
import com.twidere.twiderex.launcher.AmbientLauncher | ||
import com.twidere.twiderex.navigation.Router | ||
import com.twidere.twiderex.notification.InAppNotification | ||
import com.twidere.twiderex.preferences.PreferencesHolder | ||
import com.twidere.twiderex.preferences.ProvidePreferences | ||
import com.twidere.twiderex.providers.AmbientStatusActions | ||
import com.twidere.twiderex.providers.StatusActions | ||
import com.twidere.twiderex.ui.AmbientActiveAccount | ||
import com.twidere.twiderex.ui.AmbientActiveAccountViewModel | ||
import com.twidere.twiderex.ui.AmbientActivity | ||
import com.twidere.twiderex.ui.AmbientApplication | ||
import com.twidere.twiderex.ui.AmbientIsActiveNetworkMetered | ||
import com.twidere.twiderex.ui.AmbientViewModelProviderFactory | ||
import com.twidere.twiderex.ui.AmbientWindow | ||
import com.twidere.twiderex.ui.AmbientWindowPadding | ||
|
@@ -71,6 +80,21 @@ class TwidereXActivity : FragmentActivity() { | |
} | ||
|
||
private lateinit var launcher: ActivityLauncher | ||
private val isActiveNetworkMetered = MutableLiveData(false) | ||
private val networkCallback by lazy { | ||
object : ConnectivityManager.NetworkCallback() { | ||
override fun onCapabilitiesChanged( | ||
network: Network, | ||
networkCapabilities: NetworkCapabilities | ||
) { | ||
isActiveNetworkMetered.postValue( | ||
ConnectivityManagerCompat.isActiveNetworkMetered( | ||
connectivityManager | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Inject | ||
lateinit var statusActions: StatusActions | ||
|
@@ -81,10 +105,21 @@ class TwidereXActivity : FragmentActivity() { | |
@Inject | ||
lateinit var assistedViewModelFactoryHolder: AssistedViewModelFactoryHolder | ||
|
||
@Inject | ||
lateinit var inAppNotification: InAppNotification | ||
|
||
@Inject | ||
lateinit var connectivityManager: ConnectivityManager | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
launcher = ActivityLauncher(activityResultRegistry) | ||
lifecycle.addObserver(launcher) | ||
isActiveNetworkMetered.postValue( | ||
ConnectivityManagerCompat.isActiveNetworkMetered( | ||
connectivityManager | ||
) | ||
) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
window.setDecorFitsSystemWindows(false) | ||
} else { | ||
|
@@ -94,7 +129,9 @@ class TwidereXActivity : FragmentActivity() { | |
setContent { | ||
val accountViewModel = viewModel<ActiveAccountViewModel>() | ||
val account by accountViewModel.account.observeAsState() | ||
val isActiveNetworkMetered by isActiveNetworkMetered.observeAsState(initial = false) | ||
Providers( | ||
AmbientInAppNotification provides inAppNotification, | ||
AmbientLauncher provides launcher, | ||
AmbientWindow provides window, | ||
AmbientViewModelProviderFactory provides defaultViewModelProviderFactory, | ||
|
@@ -103,6 +140,7 @@ class TwidereXActivity : FragmentActivity() { | |
AmbientStatusActions provides statusActions, | ||
AmbientActivity provides this, | ||
AmbientActiveAccountViewModel provides accountViewModel, | ||
AmbientIsActiveNetworkMetered provides isActiveNetworkMetered | ||
) { | ||
ProvidePreferences( | ||
preferencesHolder, | ||
|
@@ -127,4 +165,17 @@ class TwidereXActivity : FragmentActivity() { | |
} | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
connectivityManager.registerNetworkCallback( | ||
NetworkRequest.Builder().build(), | ||
networkCallback, | ||
) | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
connectivityManager.unregisterNetworkCallback(networkCallback) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/kotlin/com/twidere/twiderex/action/ComposeAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Twidere X | ||
* | ||
* Copyright (C) 2020-2021 Tlaster <[email protected]> | ||
* | ||
* 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.action | ||
|
||
import androidx.work.WorkManager | ||
import com.twidere.twiderex.model.ComposeData | ||
import com.twidere.twiderex.model.MicroBlogKey | ||
import com.twidere.twiderex.worker.TwitterComposeWorker | ||
import com.twidere.twiderex.worker.draft.RemoveDraftWorker | ||
import com.twidere.twiderex.worker.draft.SaveDraftWorker | ||
|
||
class ComposeAction( | ||
private val workManager: WorkManager, | ||
) { | ||
fun commit( | ||
accountKey: MicroBlogKey, | ||
data: ComposeData, | ||
) { | ||
workManager | ||
.beginWith(SaveDraftWorker.create(data = data)) | ||
.then(TwitterComposeWorker.create(accountKey = accountKey, data = data)) | ||
.then(RemoveDraftWorker.create(draftId = data.draftId)) | ||
.enqueue() | ||
} | ||
} |
Oops, something went wrong.