Skip to content

Commit

Permalink
Merge branch 'develop' into aa/fix/calculate-storage-percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
tomastiminskas committed Jan 5, 2024
2 parents 4193fd9 + 7566f1b commit 8b729da
Show file tree
Hide file tree
Showing 46 changed files with 544 additions and 52 deletions.
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# ChangeLog

# Version 1.0.0-beta13 (2023-12-13)
- Adds ability to delete Sphinx account

# Version 1.0.0-beta12 (2023-12-13)
- Improves push notifications handling
- Enables Create Tribe for virtual nodes

# Version 1.0.0-beta11 (2023-11-17)
- Fixes crashes
- Fixes Out of Memory issues

# Version 1.0.0-beta10 (2023-11-03)
- Fixes issue on invoice tag

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ kapt.include.compile.classpath=false
# Enable In Logcat to determine Kapt
#kapt.verbose=true

VERSION_NAME=1.0.0-beta10
VERSION_NAME=1.0.0-beta13

# The trailing 2 digits are for `alpha##` releases. For example:
# 4.4.1-alpha02 = 441102 where `102` stands for alpha02
# 4.4.1-beta01 = 441201 where `201` stands for beta01
# 4.4.1-rc01 = 441301 where `301` stands for rc01
VERSION_CODE=100210
VERSION_CODE=100213


# Kotlin-Android submodule
KA_VERSION_NAME=1.0.0-beta10
KA_VERSION_NAME=1.0.0-beta13

# The trailing 2 digits are for `alpha##` releases. For example:
# 4.4.1-alpha02 = 441102 where `102` stands for alpha02
# 4.4.1-beta01 = 441201 where `201` stands for beta01
# 4.4.1-rc01 = 441301 where `301` stands for rc01
KA_VERSION_CODE=100210
KA_VERSION_CODE=100213
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:theme="@style/AppLaunchTheme"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:largeHeap="true"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.os.Build
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
Expand All @@ -27,12 +26,12 @@ import dagger.hilt.android.AndroidEntryPoint
import dev.chrisbanes.insetter.applyInsetter
import io.matthewnelson.android_feature_navigation.requests.PopBackStack
import io.matthewnelson.android_feature_viewmodel.updateViewState
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import chat.sphinx.resources.R as R_common


@AndroidEntryPoint
internal class MainActivity: MotionLayoutNavigationActivity<
class MainActivity: MotionLayoutNavigationActivity<
MainViewState,
MainViewModel,
PrimaryNavigationDriver,
Expand Down Expand Up @@ -72,6 +71,8 @@ internal class MainActivity: MotionLayoutNavigationActivity<
private var statusBarInsets: InsetPadding? = null
private var navigationBarInsets: InsetPadding? = null
private var keyboardInsets: InsetPadding? = null

var isActive = false
}

override val statusBarInsetHeight: InsetPadding by lazy(LazyThreadSafetyMode.NONE) {
Expand Down Expand Up @@ -122,6 +123,10 @@ internal class MainActivity: MotionLayoutNavigationActivity<
binding.viewMainInputLock.setOnClickListener { viewModel }
askNotificationPermission()
addWindowInsetChangeListener()

intent.extras?.getString("chat_id")?.toLongOrNull()?.let { chatId ->
handlePushNotification(chatId)
}
}

override fun onStart() {
Expand Down Expand Up @@ -165,7 +170,11 @@ internal class MainActivity: MotionLayoutNavigationActivity<
}
}

override fun onResume() {
super.onResume()

isActive = true
}

override fun onStop() {
super.onStop()
Expand All @@ -175,6 +184,8 @@ internal class MainActivity: MotionLayoutNavigationActivity<
if (sessionDepth == 0) {
viewModel.saveContentFeedStatuses()
}

isActive = false
}

override fun onNewIntent(intent: Intent) {
Expand All @@ -183,6 +194,8 @@ internal class MainActivity: MotionLayoutNavigationActivity<
intent.dataString?.let { deepLink ->
handleDeepLink(deepLink)
}

setIntent(intent)
}

private fun askNotificationPermission() {
Expand All @@ -203,12 +216,19 @@ internal class MainActivity: MotionLayoutNavigationActivity<
}
}
}

private fun handleDeepLink(deepLink: String) {
onStopSupervisor.scope.launch(viewModel.mainImmediate) {
viewModel.handleDeepLink(deepLink)
}
}

private fun handlePushNotification(chatId: Long) {
onStopSupervisor.scope.launch(viewModel.mainImmediate) {
viewModel.handlePushNotification(chatId)
}
}

override suspend fun onViewStateFlowCollect(viewState: MainViewState) {
when (viewState) {
is MainViewState.DetailScreenActive -> {
Expand Down Expand Up @@ -237,16 +257,16 @@ internal class MainActivity: MotionLayoutNavigationActivity<
// To Handle swipe behaviour
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
transitionInProgress = false
if (
currentId == MainViewState.DetailScreenInactive.endSetId &&
detailNavController.previousBackStackEntry != null
) {
lifecycleScope.launch {
viewModel.detailDriver.submitNavigationRequest(
PopBackStack(R.id.navigation_detail_blank_fragment)
)
}
if (
currentId == MainViewState.DetailScreenInactive.endSetId &&
detailNavController.previousBackStackEntry != null
) {
lifecycleScope.launch {
viewModel.detailDriver.submitNavigationRequest(
PopBackStack(R.id.navigation_detail_blank_fragment)
)
}
}
}

override fun onBackPressed() {
Expand Down Expand Up @@ -295,6 +315,8 @@ internal class MainActivity: MotionLayoutNavigationActivity<

viewModel.syncActions()
viewModel.getDeleteExcessFileIfApplicable()

isActive = false
}

override var isKeyboardVisible: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import chat.sphinx.wrapper_common.StorageData
import chat.sphinx.wrapper_common.StorageLimit.DEFAULT_STORAGE_LIMIT
import chat.sphinx.wrapper_common.StorageLimit.STORAGE_LIMIT_KEY
import chat.sphinx.wrapper_common.calculateUserStorageLimit
import chat.sphinx.wrapper_common.chat.PushNotificationLink
import chat.sphinx.wrapper_common.toFileSize
import dagger.hilt.android.lifecycle.HiltViewModel
import io.matthewnelson.android_feature_activity.NavigationViewModel
Expand All @@ -36,7 +37,7 @@ import kotlinx.coroutines.flow.collect
import javax.inject.Inject

@HiltViewModel
internal class MainViewModel @Inject constructor(
class MainViewModel @Inject constructor(
private val authenticationCoordinator: AuthenticationCoordinator,
private val authenticationStateManager: AuthenticationStateManager,
val authenticationDriver: AuthenticationNavigationDriver,
Expand Down Expand Up @@ -88,6 +89,20 @@ internal class MainViewModel @Inject constructor(
}
}

suspend fun handlePushNotification(chatId: Long) {
val pushNotificationLink = PushNotificationLink("sphinx.chat://?action=push&chatId=$chatId")

if (authenticationStateManager.authenticationStateFlow.value == AuthenticationState.NotRequired) {
navigationDriver.submitNavigationRequest(
ToDashboardScreen(
popUpToId = R.id.main_primary_nav_graph,
updateBackgroundLoginTime = false,
deepLink = pushNotificationLink.value
)
)
}
}

fun syncActions() {
actionsRepository.syncActions()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.navigation.NavController
import io.matthewnelson.concept_navigation.NavigationRequest
import io.matthewnelson.feature_navigation.NavigationDriver

internal class AuthenticationNavigationDriver: NavigationDriver<NavController>(replayCacheSize = 1) {
class AuthenticationNavigationDriver: NavigationDriver<NavController>(replayCacheSize = 1) {
override suspend fun whenTrueExecuteRequest(request: NavigationRequest<NavController>): Boolean {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.matthewnelson.android_feature_navigation.requests.PopBackStack
import io.matthewnelson.concept_navigation.NavigationRequest
import io.matthewnelson.feature_navigation.NavigationDriver

internal class DetailNavigationDriver: NavigationDriver<NavController>(replayCacheSize = 2) {
class DetailNavigationDriver: NavigationDriver<NavController>(replayCacheSize = 2) {
override suspend fun whenTrueExecuteRequest(request: NavigationRequest<NavController>): Boolean {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.navigation.NavController
import io.matthewnelson.concept_navigation.NavigationRequest
import io.matthewnelson.feature_navigation.NavigationDriver

internal class PrimaryNavigationDriver: NavigationDriver<NavController>(replayCacheSize = 5) {
class PrimaryNavigationDriver: NavigationDriver<NavController>(replayCacheSize = 5) {
override suspend fun whenTrueExecuteRequest(request: NavigationRequest<NavController>): Boolean {
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package chat.sphinx.activitymain.navigation.navigators.primary

import chat.sphinx.activitymain.R
import chat.sphinx.activitymain.navigation.drivers.DetailNavigationDriver
import chat.sphinx.activitymain.navigation.drivers.PrimaryNavigationDriver
import chat.sphinx.example.manage_storage.navigation.ToManageStorageDetail
import chat.sphinx.onboard_welcome.navigation.ToOnBoardWelcomeScreen
import chat.sphinx.qr_code.navigation.ToQRCodeDetail
import chat.sphinx.profile.navigation.ProfileNavigator
import javax.inject.Inject
Expand All @@ -23,4 +25,10 @@ internal class ProfileNavigatorImpl @Inject constructor(
override suspend fun toManageStorageDetail() {
detailDriver.submitNavigationRequest(ToManageStorageDetail())
}

override suspend fun toOnBoardWelcomeScreen() {
navigationDriver.submitNavigationRequest(
ToOnBoardWelcomeScreen(popUpToId = R.id.main_primary_nav_graph)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chat.sphinx.activitymain.R
import io.matthewnelson.android_concept_views.MotionLayoutViewState

@Suppress("ClassName")
internal sealed class MainViewState: MotionLayoutViewState<MainViewState>() {
sealed class MainViewState: MotionLayoutViewState<MainViewState>() {

object DetailScreenActive: MainViewState() {
override val startSetId: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<string name="decryption_error">DECRYPTION ERROR...</string>
<string name="null_name_error">ERROR: NULL NAME</string>
<string name="public_key">Pampublikong susi</string>
<string name="confirm">Confirm</string>
<string name="cancel">Cancel</string>
<string name="_1">1</string>
<string name="_2">2</string>
<string name="_3">3</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<string name="null_name_error">ERROR: NOMBRE VACÍO</string>
<string name="public_key">Clave Pública</string>
<string name="loading_dots">Cargando ...</string>
<string name="confirm">Confirmar</string>
<string name="cancel">Cancelar</string>

<!-- Media Type Labels -->
<string name="media_type_label_audio">Audio</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="decryption_error">復号エラー</string>
<string name="null_name_error">エラー: NULL NAME</string>
<string name="public_key">公開鍵</string>
<string name="confirm">Confirm</string>
<string name="cancel">Cancel</string>
<string name="loading_dots">Loading ...</string>

<!-- Media Type Labels -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="decryption_error">解密失敗...</string>
<string name="null_name_error">錯誤: 無填 姓名</string>
<string name="public_key">節點住址</string>
<string name="confirm">Confirm</string>
<string name="cancel">Cancel</string>
<string name="loading_dots">Loading ...</string>

<!-- Media Type Labels -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<string name="decryption_error">DECRYPTION ERROR...</string>
<string name="null_name_error">ERROR: NULL NAME</string>
<string name="public_key">Public Key</string>
<string name="confirm">Confirm</string>
<string name="cancel">Cancel</string>

<!-- Number Pad -->
<string name="_1" translatable="false">1</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package chat.sphinx.wrapper_common.chat

@Suppress("NOTHING_TO_INLINE")
inline fun String.toPushNotificationLink(): PushNotificationLink? =
try {
PushNotificationLink(this)
} catch (e: IllegalArgumentException) {
null
}

inline val String.isValidPushNotificationLink: Boolean
get() = isNotEmpty() && matches("^${PushNotificationLink.REGEX}\$".toRegex())

@JvmInline
value class PushNotificationLink(val value: String) {

companion object {
const val REGEX = "sphinx\\.chat:\\/\\/\\?action=push&chatId=.*"
const val CHAT_ID = "chatId"
}

init {
require(value.isValidPushNotificationLink) {
"Invalid Push Notification Link"
}
}

inline val chatId : Long?
get() = (getComponent(CHAT_ID) ?: "").trim().toLongOrNull()

fun getComponent(k: String): String? {
val components = value.replace("sphinx.chat://", "").split("&")
for (component in components) {
val subComponents = component.split("=")
val key:String? = if (subComponents.isNotEmpty()) subComponents.elementAtOrNull(0) else null
val value:String? = if (subComponents.size > 1) subComponents.elementAtOrNull(1) else null

if (key == k) return value
}
return null
}

}
Loading

0 comments on commit 8b729da

Please sign in to comment.