Skip to content

Commit

Permalink
Mobileapps 1008 (#46)
Browse files Browse the repository at this point in the history
* Mobileapps 950 (#59)

* applied filter and showing result

* Mobileapps 988 (#61)

* fixed search and scrollable issue.

1. Title drawer is not showing
2. Search input field will show if more than 10 items
3. Implement scroll to facet component value if item is more than 10.

* reset filter and showing results (#60)

* Mobileapps 970 (#62)

* reset filter and showing results

* fixed search and scrollable issue.

1. Title drawer is not showing
2. Search input field will show if more than 10 items
3. Implement scroll to facet component value if item is more than 10.

* fixed facet value update issue

* display format updated for chips, added title for date picker

* display format updated for chips, added title for date picker

* codacy correction

* review correction

* Mobileapps 994 (#63)

* reset filter and showing results

* Mobileapps 993 (#64)

* reset filter and showing results

* fixed search and scrollable issue.

1. Title drawer is not showing
2. Search input field will show if more than 10 items
3. Implement scroll to facet component value if item is more than 10.

* fixed facet value update issue

* display format updated for chips, added title for date picker

* display format updated for chips, added title for date picker

* codacy correction

* added facet format

* removed 0 count chip value if no facet chip selected

* added space between editext and softinputkeyboard

* codacy correction

* fixed loader issue (#65)

* merged community code with enterprise

Co-authored-by: AnniNygren <[email protected]>
  • Loading branch information
aman-alfresco and AnniNygren authored Dec 21, 2021
1 parent a69bde7 commit 274f00d
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.alfresco.content.actions.ActionUploadMedia
import com.alfresco.content.data.AuthenticationRepository
import com.alfresco.content.data.OfflineRepository
import com.alfresco.content.data.PeopleRepository
import com.alfresco.content.data.SearchRepository
import com.alfresco.content.data.SyncService
import com.alfresco.content.network.ConnectivityTracker
import com.alfresco.content.session.Session
Expand Down Expand Up @@ -72,7 +71,6 @@ class MainActivityViewModel(

// Cleanup unused db entries
cleanupStorage(session)
loadAppConfig(session, true)
syncService = configureSync(context, viewModelScope)
}

Expand Down Expand Up @@ -121,18 +119,6 @@ class MainActivityViewModel(
}
}

private fun loadAppConfig(session: Session, launch: Boolean) {
viewModelScope.launch {
ConnectivityTracker
.networkAvailable
.let {
if (it.value) {
SearchRepository(session).fetchAndSaveAppConfig(launch)
}
}
}
}

companion object : MavericksViewModelFactory<MainActivityViewModel, MainActivityState> {

override fun create(
Expand Down
15 changes: 4 additions & 11 deletions common/src/main/kotlin/com/alfresco/content/ContextExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.view.inputmethod.InputMethodManager
import androidx.core.content.getSystemService
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.google.android.material.textfield.TextInputEditText

inline fun <reified T : Context> Context.findBaseContext(): T? {
var ctx: Context? = this
Expand All @@ -30,22 +29,16 @@ fun FragmentActivity.hideSoftInput() {
}
}

/**
* show keyboard on TextInputEditText request
*/
fun TextInputEditText.showSoftInput(context: Context) {
this.requestFocus()
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?)?.toggleSoftInput(
InputMethodManager.SHOW_FORCED, 0
)
}

fun Fragment.hideSoftInput() = requireActivity().hideSoftInput()

/**
* @return the localised string from string.xml if found otherwise the same name
*/
fun Context.getLocalizedName(name: String): String {

if (name.matches(".*\\d.*".toRegex()))
return name

val stringResource = resources.getIdentifier(name.lowercase(), "string", packageName)
return if (stringResource != 0)
getString(stringResource)
Expand Down
77 changes: 12 additions & 65 deletions data/src/main/kotlin/com/alfresco/content/data/FacetContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import com.alfresco.content.models.GenericFacetResponse
import com.alfresco.content.models.GenericMetric
import com.alfresco.content.models.GenericValue
import com.alfresco.content.models.ResponseConsistency
import com.alfresco.content.models.ResultBuckets
import com.alfresco.content.models.ResultBucketsBuckets
import com.alfresco.content.models.ResultSetContext
import com.alfresco.content.models.ResultSetContextFacetQueries
import kotlinx.parcelize.Parcelize

/**
Expand All @@ -36,9 +34,7 @@ data class FacetContext(
@Parcelize
data class FacetResponse(
val consistency: Consistency,
var facetQueries: List<FacetQueries>? = null,
var facetFields: List<FacetFields>? = null,
var facetIntervals: List<FacetIntervals>? = null
var facets: List<Facets>? = null
) : Parcelable {
companion object {
/**
Expand All @@ -47,9 +43,7 @@ data class FacetResponse(
fun with(result: ResultSetContext?): FacetResponse {
return FacetResponse(
consistency = Consistency.with(result?.consistency),
facetQueries = result?.facetQueries?.map { FacetQueries.wth(it) } ?: emptyList(),
facetFields = result?.facetsFields?.map { FacetFields.with(it) } ?: emptyList(),
facetIntervals = result?.facets?.map { FacetIntervals.with(it) } ?: emptyList()
facets = result?.facets?.map { Facets.with(it) } ?: emptyList()
)
}
}
Expand All @@ -71,68 +65,27 @@ data class Consistency(var lastTxId: Int? = null) : Parcelable {
}

/**
* Mark as FacetFields class
*/
@Parcelize
data class FacetFields(
val label: String? = null,
var buckets: List<Buckets>? = null
) : Parcelable {
companion object {
/**
* returns the FacetFields type of data
*/
fun with(result: ResultBuckets): FacetFields {
return FacetFields(result.label,
result.buckets?.map { Buckets.with(it) } ?: emptyList()
)
}

/**
* returns the update FacetFields using the new value
*/
fun updateFacetFieldBucket(result: FacetFields, listBucket: MutableList<Buckets>): FacetFields {
return FacetFields(
result.label, listBucket
)
}
}
}

/**
* Mark as FacetQueries class
* Mark as FacetIntervals class
*/
@Parcelize
data class FacetQueries(
data class Facets(
var label: String? = null,
var filterQuery: String? = null,
var count: Int? = null
var type: String? = null,
var buckets: List<Buckets>? = null
) : Parcelable {
companion object {
/**
* returns the FacetQueries type of data
* returns the Facets type of data
*/
fun wth(result: ResultSetContextFacetQueries): FacetQueries {
return FacetQueries(result.label, result.filterQuery, result.count)
fun with(result: GenericFacetResponse): Facets {
return Facets(result.label, result.type, result.buckets?.map { Buckets.with(it) } ?: emptyList())
}
}
}

/**
* Mark as FacetIntervals class
*/
@Parcelize
data class FacetIntervals(
var label: String? = null,
var type: String? = null,
var buckets: List<Buckets>? = null
) : Parcelable {
companion object {
/**
* returns the FacetIntervals type of data
* filter bucket list value with count not equal to zero and returns the update Facet obj
*/
fun with(result: GenericFacetResponse): FacetIntervals {
return FacetIntervals(result.label, result.type, result.buckets?.map { Buckets.with(it) } ?: emptyList())
fun filterZeroCount(result: Facets): Facets {
return Facets(result.label, result.type, result.buckets?.filter { bucket -> bucket.metrics?.get(0)?.value?.count != "0" })
}
}
}
Expand Down Expand Up @@ -164,12 +117,6 @@ data class Buckets(
return Buckets(result.label, result.filterQuery, metrics = result.metrics?.map { Metric.with(it) } ?: emptyList(),
bucketInfo = result.bucketInfo?.let { BucketInfo.with(it) })
}
/**
* returns the update Buckets after set the count value to 0
*/
fun updateFieldBucketCount(result: Buckets): Buckets {
return Buckets(label = result.label, filterQuery = result.filterQuery, count = 0, display = result.display)
}

/**
* returns the update Buckets after set the Metrics count value to 0
Expand Down
38 changes: 3 additions & 35 deletions data/src/main/kotlin/com/alfresco/content/data/SearchRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class SearchRepository(val session: Session = SessionManager.requireSession) {
includeFacetFieldsFrom(searchFacetData.searchFacetFields),
includeFacetQueriesFrom(searchFacetData.searchFacetQueries),
includeFacetIntervalsFrom(searchFacetData.searchFacetIntervals)
)
),
"V2"
)
)
} else {
Expand Down Expand Up @@ -156,39 +157,7 @@ class SearchRepository(val session: Session = SessionManager.requireSession) {
/**
* Get AppConfigModel from the internal storage or from assets
*/
fun getAppConfig(): AppConfigModel = if (isAppConfigExistOnLocal(context)) {
val jsonFileString = retrieveJSONFromInternalDirectory(context)
getModelFromStringJSON(jsonFileString)
} else {
val jsonFileString = getJsonDataFromAsset(context, APP_CONFIG_JSON) ?: ""
getModelFromStringJSON(jsonFileString)
}

/**
* @property launch
* Fetch App config from server and save to internal directory
*/
suspend fun fetchAndSaveAppConfig(launch: Boolean) {
if (launch || isTimeToFetchConfig(getAppConfigLastFetchTime())) {
saveAppConfigFetchTime()
val configModel = appConfigService.getAppConfig()
val jsonString = getJSONFromModel(configModel)
saveJSONToInternalDirectory(context, jsonString)
}
}

private fun getAppConfigLastFetchTime(): Long {
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
return sharedPrefs.getLong(APP_CONFIG_FETCH_TIME_KEY, 0L)
}

private fun saveAppConfigFetchTime() {
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)

val editor = sharedPrefs.edit()
editor.putLong(APP_CONFIG_FETCH_TIME_KEY, System.currentTimeMillis())
editor.apply()
}
fun getAppConfig(): AppConfigModel = getModelFromStringJSON(getJsonDataFromAsset(context, APP_CONFIG_JSON) ?: "")

fun getRecentSearches(): List<String> {
val sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context)
Expand Down Expand Up @@ -236,7 +205,6 @@ class SearchRepository(val session: Session = SessionManager.requireSession) {

private companion object {
const val RECENT_SEARCH_KEY = "recent_searches"
const val APP_CONFIG_FETCH_TIME_KEY = "app_config_fetch_time"
const val MAX_RECENT_FILES_AGE = 30
const val MAX_RECENT_SEARCHES = 15
}
Expand Down
18 changes: 9 additions & 9 deletions search/src/main/assets/app.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"expanded": true,
"intervals": [
{
"label": "The Created",
"label": "The.Created.mobileapps",
"field": "cm:created",
"sets": [
{
Expand All @@ -213,7 +213,7 @@
]
},
{
"label": "TheModified",
"label": "The.Modified.mobileapps",
"field": "cm:modified",
"sets": [
{
Expand Down Expand Up @@ -450,7 +450,7 @@
{
"field": "content.size",
"mincount": 1,
"label": "Folder Size",
"label": "Folder.Size.mobileapps",
"settings": {
"allowUpdateOnChange": false,
"hideDefaultAction": true,
Expand All @@ -460,7 +460,7 @@
{
"field": "creator",
"mincount": 1,
"label": "Folder created",
"label": "Folder.creator.mobileapps",
"settings": {
"allowUpdateOnChange": false,
"hideDefaultAction": true
Expand All @@ -469,7 +469,7 @@
{
"field": "modifier",
"mincount": 1,
"label": "Folder Modifier",
"label": "Folder.Modifier.mobileapps",
"settings": {
"allowUpdateOnChange": false,
"hideDefaultAction": true
Expand All @@ -478,7 +478,7 @@
{
"field": "created",
"mincount": 1,
"label": "Folder Created",
"label": "Folder.Created.mobileapps",
"settings": {
"allowUpdateOnChange": false,
"hideDefaultAction": true
Expand Down Expand Up @@ -541,7 +541,7 @@
"expanded": true,
"intervals": [
{
"label": "The Created",
"label": "The.Created.mobileapps",
"field": "cm:created",
"sets": [
{
Expand All @@ -568,7 +568,7 @@
}
},
{
"label": "The Modified",
"label": "The.Modified.mobileapps",
"field": "cm:modified",
"sets": [
{
Expand Down Expand Up @@ -1466,4 +1466,4 @@
"ai:textLines"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ enum class ChipComponentType(val component: String) {
NUMBER_RANGE("number-range"),
DATE_RANGE("date-range"),
RADIO("radio"),
FACET_QUERIES("facet-queries"),
FACET_FIELDS("facet-fields"),
FACET_INTERVALS("facet-intervals"),
FACETS("facets"),
None("none")
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,30 @@ class ListViewFilterChips @JvmOverloads constructor(
binding.chip.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(23))
binding.chip.ellipsize = TextUtils.TruncateAt.END
}
if (dataObj.selectedName.isNotEmpty())
binding.chip.text = dataObj.selectedName.wrapWithLimit(20, ",")
else
binding.chip.text = dataObj.category?.name
binding.chip.text = if (dataObj.selectedName.isNotEmpty()) dataObj.selectedName.wrapWithLimit(20) else dataObj.category?.name
}
ChipComponentType.FACET_FIELDS.component -> {
binding.chip.text = if (dataObj.selectedName.isNotEmpty()) dataObj.selectedName.wrapWithLimit(20, ",") else context.getLocalizedName(dataObj.fieldsItem?.label ?: "")
}
ChipComponentType.FACET_INTERVALS.component -> {
binding.chip.text = if (dataObj.selectedName.isNotEmpty()) dataObj.selectedName.wrapWithLimit(20, ",") else context.getLocalizedName(dataObj.intervalsItem?.label ?: "")
ChipComponentType.FACETS.component -> {
binding.chip.text = if (dataObj.selectedName.isNotEmpty()) dataObj.selectedName.wrapWithLimit(20, ",") else context.getLocalizedName(dataObj.facets?.label ?: "")
}
else -> binding.chip.text = if (dataObj.selectedName.isNotEmpty()) dataObj.selectedName.wrapWithLimit(20, ",") else dataObj.category?.name
}

binding.chip.isChecked = dataObj.isSelected
}

private fun String.wrapWithLimit(limit: Int, delimiter: String): String {
private fun String.wrapWithLimit(limit: Int, delimiter: String? = null, multipleValue: Boolean = false): String {
if (this.length <= limit)
return this

if (this.contains(delimiter)) {
if (delimiter != null && this.contains(delimiter)) {
val splitStringArray = this.split(delimiter)
return context.getString(R.string.name_truncate_in_end, splitStringArray[0].wrapWithLimit(20, ","), splitStringArray.size.minus(1))
return context.getString(R.string.name_truncate_in_end, splitStringArray[0].wrapWithLimit(20, ",", true), splitStringArray.size.minus(1))
}

return context.getString(R.string.name_truncate_in, this.take(5), this.takeLast(5))
return if (multipleValue)
context.getString(R.string.name_truncate_in, this.take(5), this.takeLast(5))
else
context.getString(R.string.name_truncate_end, this.take(20))
}

/**
Expand Down
Loading

0 comments on commit 274f00d

Please sign in to comment.