Skip to content

Commit

Permalink
disabled favorite feature below 23 version
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Dec 5, 2023
1 parent b479ac2 commit bd57caf
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.alfresco.content.common.EntryListener
import com.alfresco.content.data.BrowseRepository
import com.alfresco.content.data.Entry
import com.alfresco.content.data.FavoritesRepository
import com.alfresco.content.data.SearchRepository
import com.alfresco.content.data.Settings
import com.alfresco.coroutines.asFlow
import com.alfresco.events.on
Expand Down Expand Up @@ -152,10 +153,14 @@ class ContextualActionsViewModel(
private fun sharedActions(entry: Entry, entries: List<Entry>): List<Action> {
val actions = mutableListOf<Action>()
// Added Favorite Action
if (entries.any { !it.isFavorite }) {
actions.add(ActionAddFavorite(entry, entries))
} else {
actions.add(ActionRemoveFavorite(entry, entries))
val version = SearchRepository().getPrefsServerVersion()

if (version.toInt() >= 23) {
if (entries.any { !it.isFavorite }) {
actions.add(ActionAddFavorite(entry, entries))
} else {
actions.add(ActionRemoveFavorite(entry, entries))
}
}

// Added Start Process Action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ContextualActionsViewModelTest {
val viewModel = ContextualActionsViewModel(initialState, mockContext, settings)

withState(viewModel) { newState ->
viewModel.makeMultiActions(newState.entries)
viewModel.makeMultiActions(newState)
assertEquals(1, newState.actions.size)

newState.actions.forEach {
Expand All @@ -81,7 +81,7 @@ class ContextualActionsViewModelTest {
val viewModel = ContextualActionsViewModel(initialState, mockContext, settings)

withState(viewModel) { newState ->
viewModel.makeMultiActions(newState.entries)
viewModel.makeMultiActions(newState)
assertEquals(1, newState.actions.size)

newState.actions.forEach {
Expand Down
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins{
plugins {
id('com.android.application')
id('kotlin-android')
id('kotlin-kapt')
Expand Down Expand Up @@ -54,6 +54,8 @@ android {
viewBinding = true
}



compileOptions {
coreLibraryDesugaringEnabled true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class LoginActivity : com.alfresco.auth.activity.LoginActivity() {
navigateToMain()
}
} catch (ex: Exception) {
ex.printStackTrace()
onError(R.string.auth_error_wrong_credentials)
}
}
Expand All @@ -51,7 +52,7 @@ class LoginActivity : com.alfresco.auth.activity.LoginActivity() {
authConfig.jsonSerialize(),
endpoint,
person.displayName ?: "",
person.email,
person.email ?: "",
myFiles,
)
} else {
Expand All @@ -67,7 +68,7 @@ class LoginActivity : com.alfresco.auth.activity.LoginActivity() {
person.id,
credentials.authState,
person.displayName ?: "",
person.email,
person.email ?: person.company?.email ?: "",
myFiles,
)
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ buildscript {
classpath libs.gradleVersionsPlugin
classpath libs.gradleLicensePlugin


}
}

Expand Down
76 changes: 67 additions & 9 deletions data/src/main/kotlin/com/alfresco/content/data/SearchRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.alfresco.content.data

import android.content.Context
import android.content.SharedPreferences
import android.net.Uri
import androidx.preference.PreferenceManager
import com.alfresco.auth.AuthConfig
import com.alfresco.auth.DiscoveryService
import com.alfresco.content.apis.AdvanceSearchInclude
import com.alfresco.content.apis.FacetSearchInclude
import com.alfresco.content.apis.QueriesApi
Expand All @@ -25,6 +28,7 @@ import com.alfresco.events.EventBus
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class SearchRepository {

Expand Down Expand Up @@ -212,15 +216,68 @@ class SearchRepository {
null
}

suspend fun getRecents(skipCount: Int, maxItems: Int) =
ResponsePaging.with(
searchService.recentFiles(
session.account.id,
MAX_RECENT_FILES_AGE,
skipCount,
maxItems,
),
)
suspend fun getRecents(skipCount: Int, maxItems: Int): ResponsePaging {
val version = getServerVersion()

if (version.toInt() >= 23) {
return ResponsePaging.with(
searchService.recentFiles(
session.account.id,
MAX_RECENT_FILES_AGE,
skipCount,
maxItems,
true,
),
)
} else {
return ResponsePaging.with(
searchService.recentFiles(
session.account.id,
MAX_RECENT_FILES_AGE,
skipCount,
maxItems,
),
)
}
}

fun getPrefsServerVersion(): String {
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
return sharedPrefs.getString(SERVER_VERSION, "") ?: ""
}

private fun saveServerVersion(serverVersion: String) {
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
val editor = sharedPrefs.edit()
editor.putString(SERVER_VERSION, serverVersion)
editor.apply()
}

private suspend fun getServerVersion(): String {
val version = getPrefsServerVersion()
if (version.isNullOrEmpty()) {
val acc = session.account

val authConfig = AuthConfig.jsonDeserialize(acc.authConfig)

authConfig?.let { config ->

val discoveryService = DiscoveryService(context, config)

val contentServiceDetailsObj = withContext(Dispatchers.IO) {
discoveryService.getContentServiceDetails(Uri.parse(acc.serverUrl).host ?: "")
}

val serverVersion = contentServiceDetailsObj?.version?.split(".")?.get(0) ?: ""
saveServerVersion(serverVersion)
return serverVersion
}

return ""
} else {
return version
}
}

/**
* Get AppConfigModel from the internal storage or from assets
Expand Down Expand Up @@ -275,5 +332,6 @@ class SearchRepository {
const val RECENT_SEARCH_KEY = "recent_searches"
const val MAX_RECENT_FILES_AGE = 30
const val MAX_RECENT_SEARCHES = 15
const val SERVER_VERSION = "server_version"
}
}
21 changes: 18 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ coil = "2.4.0"
coroutines = "1.7.1"
epoxy = "5.1.3"
exoplayer = "2.14.0"
kotlin = "1.8.0"
kotlin = "1.9.20"
lifecycle = "2.6.1"
navigation = "2.6.0"
okhttp = "4.11.0"
test = "1.5.0"
activity-compose = "1.7.0"
compose-bom = "2023.03.00"


moshi = "1.15.0"
retrofit = "2.9.0"

[libraries]
alfresco-auth = "com.alfresco.android:auth:0.8.1-SNAPSHOT"
alfresco-content = "com.alfresco.android:content:0.3.3-SNAPSHOT"
alfresco-content = "com.alfresco.android:content:0.3.4-SNAPSHOT"
alfresco-contentKtx = "com.alfresco.android:content-ktx:0.3.2-SNAPSHOT"
alfresco-process = "com.alfresco.android:process:0.1.1-SNAPSHOT"

Expand Down Expand Up @@ -119,4 +125,13 @@ spotless = "com.diffplug.spotless:spotless-plugin-gradle:6.19.0"

subsamplingimageview = "com.davemorrissey.labs:subsampling-scale-image-view:3.10.0"

timber = "com.jakewharton.timber:timber:5.0.1"
timber = "com.jakewharton.timber:timber:5.0.1"
activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
ui = { group = "androidx.compose.ui", name = "ui" }
ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
material3 = { group = "androidx.compose.material3", name = "material3" }
1 change: 1 addition & 0 deletions process-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
107 changes: 107 additions & 0 deletions process-app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.alfresco.content.process'
compileSdk 33

defaultConfig {
minSdk 26
targetSdk 33
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = "1.5.4"
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation libs.androidx.lifecycle.runtime
implementation libs.activity.compose
implementation platform(libs.compose.bom)
implementation libs.ui
implementation libs.ui.graphics
implementation libs.ui.tooling.preview
implementation libs.material3
androidTestImplementation platform(libs.compose.bom)
androidTestImplementation libs.ui.test.junit4
debugImplementation libs.ui.tooling
debugImplementation libs.ui.test.manifest

dependencies {

// val composeBom = platform("androidx.compose:compose-bom:2023.10.01")
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01"))

// Choose one of the following:
// Material Design 3
implementation("androidx.compose.material3:material3")
// or Material Design 2
implementation("androidx.compose.material:material")
// or skip Material Design and build directly on top of foundational components
implementation("androidx.compose.foundation:foundation")
// or only import the main APIs for the underlying toolkit systems,
// such as input and measurement/layout
implementation("androidx.compose.ui:ui")

// Android Studio Preview support
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")

// UI Tests
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-test-manifest")

// Optional - Included automatically by material, only add when you need
// the icons but not the material library (e.g. when using Material3 or a
// custom design system based on Foundation)
implementation("androidx.compose.material:material-icons-core")
// Optional - Add full set of material icons
implementation("androidx.compose.material:material-icons-extended")
// Optional - Add window size utils
implementation("androidx.compose.material3:material3-window-size-class")

// Optional - Integration with activities
implementation("androidx.activity:activity-compose:1.8.1")
// Optional - Integration with ViewModels
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
// Optional - Integration with LiveData
implementation("androidx.compose.runtime:runtime-livedata")
// Optional - Integration with RxJava
implementation("androidx.compose.runtime:runtime-rxjava2")

}


}
12 changes: 12 additions & 0 deletions process-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity
android:name=".ProcessFormActivity"
android:exported="false"
android:label="@string/title_activity_process_form"
android:theme="@style/Theme.Alfrescomobileworkspaceandroid" />
</application>

</manifest>
Loading

0 comments on commit bd57caf

Please sign in to comment.