Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
App Lounge
Commits
3e5c1342
Commit
3e5c1342
authored
Feb 19, 2021
by
Romain Hunault
Browse files
Merge branch 'update_menu_fix' into 'master'
Update microG fix See merge request e/apps/apps!49
parents
4a667413
3b6bc270
Pipeline
#102784
passed with stage
in 3 minutes and 8 seconds
Changes
20
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
3e5c1342
...
...
@@ -68,6 +68,13 @@
android:launchMode=
"singleInstance"
android:theme=
"@style/AppTheme1"
android:windowSoftInputMode=
"adjustResize"
/>
<receiver
android:name=
".MicrogUninstallListener"
android:enabled=
"true"
android:exported=
"true"
>
<intent-filter>
<action
android:name=
"foundation.e.apps"
/>
</intent-filter>
</receiver>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/foundation/e/apps/MicrogUninstallListener.kt
0 → 100644
View file @
3e5c1342
package
foundation.e.apps
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.util.Log
import
foundation.e.apps.utils.PreferenceStorage
class
MicrogUninstallListener
:
BroadcastReceiver
()
{
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
PreferenceStorage
(
context
).
save
(
context
.
getString
(
R
.
string
.
prefs_microg_vrsn_installed
),
false
)
}
}
\ No newline at end of file
app/src/main/java/foundation/e/apps/application/ApplicationActivity.kt
View file @
3e5c1342
...
...
@@ -32,7 +32,6 @@ import android.text.SpannableStringBuilder
import
android.text.method.LinkMovementMethod
import
android.text.style.ForegroundColorSpan
import
android.util.DisplayMetrics
import
android.util.Log
import
android.util.TypedValue
import
android.view.Menu
import
android.view.MenuItem
...
...
@@ -40,14 +39,11 @@ import android.view.View
import
android.widget.ImageView
import
android.widget.LinearLayout
import
android.widget.TextView
import
androidx.annotation.ColorInt
import
androidx.appcompat.app.AlertDialog
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.view.ContextThemeWrapper
import
androidx.appcompat.widget.Toolbar
import
com.google.android.material.snackbar.Snackbar
import
foundation.e.apps.MainActivity.Companion.sharedPreferences
import
foundation.e.apps.pwa.PwaInstaller
import
foundation.e.apps.R
import
foundation.e.apps.application.model.Application
import
foundation.e.apps.application.model.ApplicationStateListener
...
...
@@ -61,6 +57,7 @@ import foundation.e.apps.applicationmanager.ApplicationManager
import
foundation.e.apps.applicationmanager.ApplicationManagerServiceConnection
import
foundation.e.apps.applicationmanager.ApplicationManagerServiceConnectionCallback
import
foundation.e.apps.categories.category.CategoryActivity
import
foundation.e.apps.pwa.PwaInstaller
import
foundation.e.apps.utils.Common
import
foundation.e.apps.utils.Common.toMiB
import
foundation.e.apps.utils.Constants
...
...
@@ -79,9 +76,7 @@ class ApplicationActivity :
ApplicationManagerServiceConnectionCallback
,
Downloader
.
DownloadProgressCallback
,
BasicData
.
IconLoaderCallback
,
PwasBasicData
.
IconLoaderCallback
{
PwasBasicData
.
IconLoaderCallback
{
private
lateinit
var
applicationPackageName
:
String
...
...
@@ -98,15 +93,15 @@ class ApplicationActivity :
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_application
)
good_border
.
visibility
=
View
.
GONE
neutral_border
.
visibility
=
View
.
GONE
good_border
.
visibility
=
View
.
GONE
neutral_border
.
visibility
=
View
.
GONE
val
toolbar
=
findViewById
<
Toolbar
>(
R
.
id
.
toolbar
)
setSupportActionBar
(
toolbar
)
supportActionBar
?.
setDisplayHomeAsUpEnabled
(
true
)
supportActionBar
?.
setDisplayShowTitleEnabled
(
false
)
sharedPreferences
=
this
.
getSharedPreferences
(
sharedPrefFile
,
Context
.
MODE_PRIVATE
)
sharedPreferences
=
this
.
getSharedPreferences
(
sharedPrefFile
,
Context
.
MODE_PRIVATE
)
pwa_sympol
.
visibility
=
View
.
GONE
...
...
@@ -213,9 +208,9 @@ class ApplicationActivity :
@SuppressLint
(
"ResourceAsColor"
)
private
fun
textColorChange
(
text
:
String
):
SpannableStringBuilder
{
val
builder
=
SpannableStringBuilder
();
val
redSpannable
=
SpannableString
(
text
);
redSpannable
.
setSpan
(
ForegroundColorSpan
(
R
.
color
.
colorDarkGray
),
0
,
text
.
length
,
0
);
val
builder
=
SpannableStringBuilder
();
val
redSpannable
=
SpannableString
(
text
);
redSpannable
.
setSpan
(
ForegroundColorSpan
(
R
.
color
.
colorDarkGray
),
0
,
text
.
length
,
0
);
builder
.
append
(
redSpannable
);
return
builder
}
...
...
@@ -276,7 +271,7 @@ class ApplicationActivity :
}
// Set the app rating
val
builder
=
textColorChange
(
getText
(
R
.
string
.
not_available
).
toString
())
val
builder
=
textColorChange
(
getText
(
R
.
string
.
not_available
).
toString
())
if
(
basicData
.
ratings
!!
.
rating
!=
-
1f
)
{
app_rating
.
text
=
basicData
.
ratings
.
rating
.
toString
()
+
"/5"
}
else
{
...
...
@@ -321,7 +316,7 @@ class ApplicationActivity :
}
// Set the app privacy rating
val
builder
=
textColorChange
(
getText
(
R
.
string
.
not_available
).
toString
())
val
builder
=
textColorChange
(
getText
(
R
.
string
.
not_available
).
toString
())
if
(
fullData
.
getLastVersion
()
!!
.
privacyRating
!=
null
&&
fullData
.
getLastVersion
()
!!
.
privacyRating
!=
-
1
)
{
...
...
@@ -360,6 +355,12 @@ class ApplicationActivity :
}
else
{
app_version
.
text
=
getString
(
R
.
string
.
not_available
)
}
// Set app package name.
if
(
fullData
.
packageName
.
isNotEmpty
())
{
app_package_name
.
text
=
fullData
.
packageName
}
else
{
app_package_name
.
text
=
getString
(
R
.
string
.
not_available
)
}
// Set app update timestamp
if
(
fullData
.
getLastVersion
()
!!
.
createdOn
.
isNotEmpty
())
{
...
...
@@ -380,7 +381,7 @@ class ApplicationActivity :
app_size
.
visibility
=
View
.
GONE
// Set app privacy rating
val
builder
=
textColorChange
(
getText
(
R
.
string
.
not_available
).
toString
())
val
builder
=
textColorChange
(
getText
(
R
.
string
.
not_available
).
toString
())
app_privacy_score
.
text
=
builder
setPrivacyRatingBorder
(-
1
)
app_privacy_container
.
setOnClickListener
{
...
...
@@ -505,7 +506,7 @@ class ApplicationActivity :
application
.
PwaloadIcon
(
this
)
pwa_sympol
.
visibility
=
View
.
VISIBLE
Ratings
.
visibility
=
View
.
GONE
Ratings
.
visibility
=
View
.
GONE
val
pwasBasicData
=
application
.
pwabasicdata
...
...
@@ -553,14 +554,15 @@ class ApplicationActivity :
// Handle clicks on app permissions
exodus_info_container
.
visibility
=
View
.
GONE
exodus_info_container
.
visibility
=
View
.
GONE
//app_information details
app_information_title
.
visibility
=
View
.
GONE
app_version_layout
.
visibility
=
View
.
GONE
app_updated_on_layout
.
visibility
=
View
.
GONE
app_requires
.
visibility
=
View
.
GONE
app_licence_layout
.
visibility
=
View
.
GONE
app_information_title
.
visibility
=
View
.
GONE
app_version_layout
.
visibility
=
View
.
GONE
app_updated_on_layout
.
visibility
=
View
.
GONE
app_requires
.
visibility
=
View
.
GONE
app_licence_layout
.
visibility
=
View
.
GONE
app_package_name_layout
.
visibility
=
View
.
GONE
application
.
addListener
(
this
)
...
...
@@ -610,9 +612,9 @@ class ApplicationActivity :
fun
onPwaInstallButtonClick
(
fullData
:
PwaFullData
)
{
val
intent
=
Intent
(
this
,
PwaInstaller
::
class
.
java
)
intent
.
putExtra
(
"NAME"
,
fullData
.
name
)
intent
.
putExtra
(
"URL"
,
fullData
.
url
)
val
intent
=
Intent
(
this
,
PwaInstaller
::
class
.
java
)
intent
.
putExtra
(
"NAME"
,
fullData
.
name
)
intent
.
putExtra
(
"URL"
,
fullData
.
url
)
this
.
startActivity
(
intent
)
}
...
...
@@ -670,13 +672,13 @@ class ApplicationActivity :
private
fun
setRatingBorder
(
rating
:
Float
?)
{
when
{
rating
!!
>=
7f
->
{
app_rating
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_cat_green_ellipse
,
0
)
app_rating
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_cat_green_ellipse
,
0
)
}
rating
>=
4f
->
{
app_rating
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_yellow_ellipse
,
0
)
app_rating
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_yellow_ellipse
,
0
)
}
else
->
{
app_rating
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_red_ellipse
,
0
)
app_rating
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_red_ellipse
,
0
)
}
}
}
...
...
@@ -684,13 +686,13 @@ class ApplicationActivity :
private
fun
setPrivacyRatingBorder
(
rating
:
Int
)
{
when
{
rating
>=
7
->
{
app_privacy_score
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_cat_green_ellipse
,
0
)
app_privacy_score
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_cat_green_ellipse
,
0
)
}
rating
>=
4
->
{
app_privacy_score
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_yellow_ellipse
,
0
)
app_privacy_score
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_yellow_ellipse
,
0
)
}
else
->
{
app_privacy_score
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_red_ellipse
,
0
)
app_privacy_score
.
setCompoundDrawablesWithIntrinsicBounds
(
0
,
0
,
R
.
drawable
.
ic_red_ellipse
,
0
)
}
}
}
...
...
@@ -762,6 +764,6 @@ class ApplicationActivity :
}
private
fun
getAccentColor
()
{
accentColorOS
=
this
.
resources
.
getColor
(
R
.
color
.
colorAccent
);
accentColorOS
=
this
.
resources
.
getColor
(
R
.
color
.
colorAccent
);
}
}
app/src/main/java/foundation/e/apps/application/ApplicationViewHolder.kt
View file @
3e5c1342
...
...
@@ -67,7 +67,7 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
private
var
application
:
Application
?
=
null
private
val
applicationViewModel
=
ApplicationViewModel
()
private
var
downloader
:
Downloader
?
=
null
var
accentColorOS
=
accentColorOS
;
var
accentColorOS
=
accentColorOS
;
init
{
pwa_icon
.
visibility
=
View
.
GONE
view
.
setOnClickListener
{
...
...
@@ -79,7 +79,7 @@ var accentColorOS=accentColorOS;
installButton
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
if
(
0
!=
this
.
accentColorOS
){
if
(
0
!=
this
.
accentColorOS
)
{
installButton
.
setBackgroundColor
(
this
.
accentColorOS
)
}
installButton
?.
setOnClickListener
{
...
...
@@ -153,16 +153,15 @@ var accentColorOS=accentColorOS;
override
fun
stateChanged
(
state
:
State
)
{
Execute
({},
{
// installButton.setBackgroundResource(R.drawable.app_install_border_simple)
// installButton.setBackgroundResource(R.drawable.app_install_border_simple)
installButton
?.
text
=
activity
.
getString
(
state
.
installButtonTextId
)
when
(
state
)
{
State
.
NOT_DOWNLOADED
->
{
if
(
0
!=
this
.
accentColorOS
){
if
(
0
!=
this
.
accentColorOS
)
{
installButton
.
setTextColor
(
this
.
accentColorOS
)
}
else
{
}
else
{
installButton
.
setTextColor
(
Color
.
parseColor
(
"#0088ED"
))
}
...
...
@@ -174,10 +173,9 @@ var accentColorOS=accentColorOS;
installButton
?.
isEnabled
=
Common
.
appHasLaunchActivity
(
activity
,
application
!!
.
packageName
)
if
(
0
!=
this
.
accentColorOS
){
if
(
0
!=
this
.
accentColorOS
)
{
installButton
!!
.
setBackgroundColor
(
this
.
accentColorOS
)
}
else
{
}
else
{
installButton
!!
.
setBackgroundResource
(
R
.
drawable
.
app_install_border
)
}
installButton
.
setTextColor
(
Color
.
parseColor
(
"#FAFAFA"
))
...
...
@@ -187,14 +185,20 @@ var accentColorOS=accentColorOS;
installButton
?.
isEnabled
=
false
}
State
.
NOT_UPDATED
->
{
installButton
.
setTextColor
(
Color
.
parseColor
(
"#FAFAFA"
))
//installButton!!.setBackgroundResource(R.drawable.app_install_border)
if
(
0
!=
this
.
accentColorOS
){
installButton
!!
.
setBackgroundColor
(
this
.
accentColorOS
)
}
else
{
installButton
!!
.
setBackgroundResource
(
R
.
drawable
.
app_install_border
)
if
(
application
?.
packageName
==
Constants
.
MICROG_PACKAGE
)
{
installButton
.
setBackgroundResource
(
R
.
drawable
.
app_install_border_simple
)
installButton
.
text
=
"Install"
installButton
.
setTextColor
(
this
.
accentColorOS
)
}
else
{
installButton
.
setTextColor
(
Color
.
parseColor
(
"#FAFAFA"
))
//installButton!!.setBackgroundResource(R.drawable.app_install_border)
if
(
0
!=
this
.
accentColorOS
)
{
installButton
!!
.
setBackgroundColor
(
this
.
accentColorOS
)
}
else
{
installButton
!!
.
setBackgroundResource
(
R
.
drawable
.
app_install_border
)
}
}
installButton
?.
isEnabled
=
true
}
else
->
{
...
...
app/src/main/java/foundation/e/apps/application/model/Installer.kt
View file @
3e5c1342
...
...
@@ -134,24 +134,22 @@ class Installer(private val packageName: String,
addAction
(
Intent
.
ACTION_PACKAGE_ADDED
)
addDataScheme
(
"package"
)
})
Log
.
i
(
TAG
,
"Registered new broadcast receiver"
)
}
private
var
receiver
=
object
:
BroadcastReceiver
()
{
override
fun
onReceive
(
p0
:
Context
,
p1
:
Intent
)
{
if
(
p1
.
action
==
Intent
.
ACTION_PACKAGE_ADDED
&&
(
p1
.
data
.
encodedSchemeSpecificPart
==
packageName
))
{
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
if
(
intent
.
action
==
Intent
.
ACTION_PACKAGE_ADDED
&&
(
intent
.
data
.
encodedSchemeSpecificPart
==
packageName
))
{
Log
.
i
(
TAG
,
"Broadcast received"
)
var
path
=
apk
.
absolutePath
.
split
(
"Download"
)
//delete all APK file after install
deleteFileOrDir
(
path
[
0
]
+
"Download"
);
callback
.
onInstallationComplete
(
p0
)
callback
.
onInstallationComplete
(
context
)
if
(
packageName
==
Constants
.
MICROG_PACKAGE
)
{
PreferenceStorage
(
p0
).
save
(
p0
.
getString
(
R
.
string
.
prefs_microg_vrsn_installed
),
true
)
PreferenceStorage
(
context
).
save
(
context
.
getString
(
R
.
string
.
prefs_microg_vrsn_installed
),
true
)
}
}
}
}
...
...
app/src/main/java/foundation/e/apps/categories/ApplicationsFragment.kt
View file @
3e5c1342
...
...
@@ -33,17 +33,17 @@ import foundation.e.apps.categories.viewmodel.CategoriesViewModel
import
kotlinx.android.synthetic.main.error_layout.view.*
import
kotlinx.android.synthetic.main.fragment_application_categories.view.*
class
ApplicationsFragment
(
color
:
Int
?
)
:
Fragment
()
{
class
ApplicationsFragment
()
:
Fragment
()
{
private
lateinit
var
categoriesViewModel
:
CategoriesViewModel
va
l
color
=
color
;
va
r
color
:
Int
=
0
;
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
categoriesViewModel
=
ViewModelProviders
.
of
(
activity
!!
).
get
(
CategoriesViewModel
::
class
.
java
)
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_application_categories
,
container
,
false
)
view
.
categories_list
.
layoutManager
=
LinearLayoutManager
(
context
)
color
=
arguments
!!
.
getInt
(
"color"
,
0
)
view
.
categories_list
.
visibility
=
View
.
GONE
view
.
progress_bar
.
visibility
=
View
.
VISIBLE
view
.
error_container
.
visibility
=
View
.
GONE
...
...
@@ -61,8 +61,8 @@ class ApplicationsFragment(color: Int?) : Fragment() {
categoriesViewModel
.
getApplicationsCategories
().
observe
(
this
,
Observer
{
if
(
it
!!
.
isNotEmpty
())
{
//Add New Category
i
t
.
add
(
Category
(
"system_apps"
)
)
i
f
(!
it
.
any
{
Category
->
Category
.
id
==
"system_apps"
}
)
it
.
add
(
Category
(
"system_apps"
))
view
.
categories_list
.
adapter
=
CategoriesListAdapter
(
it
,
color
)
view
.
categories_list
.
visibility
=
View
.
VISIBLE
view
.
progress_bar
.
visibility
=
View
.
GONE
...
...
@@ -85,4 +85,13 @@ class ApplicationsFragment(color: Int?) : Fragment() {
}
return
view
}
companion
object
{
fun
newInstance
(
color
:
Int
?)
:
ApplicationsFragment
{
val
applicationsFragment
=
ApplicationsFragment
()
val
bundle
=
Bundle
()
bundle
.
putInt
(
"color"
,
color
!!
)
applicationsFragment
.
arguments
=
bundle
return
applicationsFragment
}
}
}
app/src/main/java/foundation/e/apps/categories/CategoriesViewPagerAdapter.kt
View file @
3e5c1342
...
...
@@ -24,8 +24,8 @@ import androidx.fragment.app.FragmentStatePagerAdapter
class
CategoriesViewPagerAdapter
(
fragmentManager
:
FragmentManager
,
private
val
numberOfTabs
:
Int
,
color
:
Int
?)
:
FragmentStatePagerAdapter
(
fragmentManager
)
{
private
val
applicationsFragment
=
ApplicationsFragment
(
color
)
private
val
gamesFragment
=
GamesFragment
(
color
)
private
val
applicationsFragment
=
ApplicationsFragment
.
newInstance
(
color
)
private
val
gamesFragment
=
GamesFragment
.
newInstance
(
color
)
private
val
pwasFragment
=
PwasFragment
()
...
...
app/src/main/java/foundation/e/apps/categories/GamesFragment.kt
View file @
3e5c1342
...
...
@@ -32,17 +32,17 @@ import foundation.e.apps.categories.viewmodel.CategoriesViewModel
import
kotlinx.android.synthetic.main.error_layout.view.*
import
kotlinx.android.synthetic.main.fragment_games_categories.view.*
class
GamesFragment
(
color
:
Int
?
)
:
Fragment
()
{
class
GamesFragment
()
:
Fragment
()
{
private
lateinit
var
categoriesViewModel
:
CategoriesViewModel
var
color
=
color
;
var
color
:
Int
=
0
;
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?):
View
?
{
categoriesViewModel
=
ViewModelProviders
.
of
(
activity
!!
).
get
(
CategoriesViewModel
::
class
.
java
)
val
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_games_categories
,
container
,
false
)
view
.
categories_list
.
layoutManager
=
LinearLayoutManager
(
context
)
color
=
arguments
!!
.
getInt
(
"color"
,
0
)
view
.
categories_list
.
visibility
=
View
.
GONE
view
.
progress_bar
.
visibility
=
View
.
VISIBLE
view
.
error_container
.
visibility
=
View
.
GONE
...
...
@@ -81,4 +81,14 @@ class GamesFragment(color: Int?) : Fragment() {
}
return
view
}
companion
object
{
fun
newInstance
(
color
:
Int
?)
:
GamesFragment
{
val
gamesFragment
=
GamesFragment
()
val
bundle
=
Bundle
()
bundle
.
putInt
(
"color"
,
color
!!
)
gamesFragment
.
arguments
=
bundle
return
gamesFragment
}
}
}
app/src/main/java/foundation/e/apps/categories/category/CategoryActivity.kt
View file @
3e5c1342
...
...
@@ -66,6 +66,7 @@ class CategoryActivity : AppCompatActivity(), ApplicationManagerServiceConnectio
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_category
)
getAccentColor
()
val
toolbar
=
findViewById
<
Toolbar
>(
R
.
id
.
toolbar
)
setSupportActionBar
(
toolbar
)
...
...
@@ -115,7 +116,7 @@ class CategoryActivity : AppCompatActivity(), ApplicationManagerServiceConnectio
// Initialise recycler view
recyclerView
.
setHasFixedSize
(
true
)
recyclerView
.
layoutManager
=
LinearLayoutManager
(
this
)
recyclerView
.
adapter
=
ApplicationListAdapter
(
this
,
applicationList
,
0
)
recyclerView
.
adapter
=
ApplicationListAdapter
(
this
,
applicationList
,
accentColorOS
)
// Bind to the list of applications in this activity's category
categoryViewModel
.
getApplications
().
observe
(
this
,
Observer
{
...
...
app/src/main/java/foundation/e/apps/search/model/SearchElement.kt
View file @
3e5c1342
...
...
@@ -19,11 +19,15 @@ package foundation.e.apps.search.model
import
android.content.Context
import
android.os.AsyncTask
import
foundation.e.apps.R
import
foundation.e.apps.api.AllAppsSearchRequest
import
foundation.e.apps.api.GitlabDataRequest
import
foundation.e.apps.application.model.Application
import
foundation.e.apps.application.model.State
import
foundation.e.apps.applicationmanager.ApplicationManager
import
foundation.e.apps.utils.Constants
import
foundation.e.apps.utils.Error
import
foundation.e.apps.utils.PreferenceStorage
class
SearchElement
(
private
val
query
:
String
,
private
val
pageNumber
:
Int
,
private
val
applicationManager
:
ApplicationManager
,
...
...
@@ -33,8 +37,9 @@ class SearchElement(private val query: String, private val pageNumber: Int,
override
fun
doInBackground
(
vararg
params
:
Context
):
ArrayList
<
Application
>
{
val
apps
=
ArrayList
<
Application
>()
if
(
"microG Exposure Notification version"
.
contains
(
query
,
true
))
{
apps
.
addAll
(
loadMicroGVersion
(
params
[
0
]))
}
AllAppsSearchRequest
(
query
,
pageNumber
,
Constants
.
RESULTS_PER_PAGE
)
.
request
{
applicationError
,
searchResult
->
...
...
@@ -54,4 +59,26 @@ class SearchElement(private val query: String, private val pageNumber: Int,
override
fun
onPostExecute
(
result
:
ArrayList
<
Application
>)
{
callback
.
onSearchComplete
(
error
,
result
)
}
/*gets microG application from gitlab*/
private
fun
loadMicroGVersion
(
context
:
Context
):
List
<
Application
>
{
var
gitlabData
:
GitlabDataRequest
.
GitlabDataResult
?
=
null
GitlabDataRequest
()
.
requestGmsCoreRelease
{
applicationError
,
listGitlabData
->
when
(
applicationError
)
{
null
->
{
gitlabData
=
listGitlabData
!!
}
else
->
{
error
=
applicationError
}
}
}
return
if
(
gitlabData
!=
null
)
{
gitlabData
!!
.
getApplications
(
applicationManager
,
context
)
}
else
{
emptyList
()
}
}
}
app/src/main/java/foundation/e/apps/search/model/SearchModel.kt
View file @
3e5c1342
...
...
@@ -18,26 +18,26 @@
package
foundation.e.apps.search.model
import
android.content.Context
import
android.content.Intent
import
android.os.AsyncTask
import
androidx.lifecycle.MutableLiveData
import
foundation.e.apps.api.GitlabDataRequest
import
foundation.e.apps.application.model.Application
import
foundation.e.apps.applicationmanager.ApplicationManager
import
foundation.e.apps.categories.category.CategoryActivity
import
foundation.e.apps.categories.model.Category
import
foundation.e.apps.utils.Common
import
foundation.e.apps.utils.Constants
import
foundation.e.apps.utils.Error
import
foundation.e.apps.utils.Execute
class
SearchModel
:
SearchModelInterface
{
val
suggestionList
=
MutableLiveData
<
ArrayList
<
String
>>()
val
applicationList
=
MutableLiveData
<
ArrayList
<
Application
>>()
var
screenError
=
MutableLiveData
<
Error
>()
private
var
applicationManager
:
ApplicationManager
?
=
null
lateinit
var
applicationManager
:
ApplicationManager
private
var
pageNumber
=
0
private
lateinit
var
searchQuery
:
String
private
lateinit
var
context
:
Context
private
var
error
:
Error
?
=
null
override
fun
initialise
(
applicationManager
:
ApplicationManager
)
{
this
.
applicationManager
=
applicationManager
...
...
@@ -45,7 +45,7 @@ class SearchModel : SearchModelInterface {
override
fun
searchSuggestions
(
context
:
Context
,
searchQuery
:
String
)
{
this
.
searchQuery
=
searchQuery
this
.
context
=
context
this
.
context
=
context
if
(
searchQuery
.
length
>=
Constants
.
MIN_SEARCH_TERM_LENGTH
)
{
if
(
Common
.
isNetworkAvailable
(
context
))
{
SearchSuggestionsTask
(
searchQuery
,
applicationManager
!!
,
this
)
...
...
@@ -86,22 +86,16 @@ class SearchModel : SearchModelInterface {
override
fun
onSearchComplete
(
error
:
Error
?,
applicationList
:
ArrayList
<
Application
>)
{
if
(
error
==
null
)
{
if
(
searchQuery
.
equals
(
"microg"
,
true
))
{
val
categoryIntent
=
Intent
(
context
,
CategoryActivity
::
class
.
java
)
categoryIntent
.
putExtra
(
Constants
.
CATEGORY_KEY
,
Category
(
"system_apps"
))
context
.
startActivity
(
categoryIntent
)
}
else
{
if
(
applicationList
.
isNotEmpty
())
{
if
(
pageNumber
>
1
&&
this
.
applicationList
.
value
!=
null
)
{
val
combinedAppList
=
this
.
applicationList
.
value
!!
combinedAppList
.
addAll
(
applicationList
)
this
.
applicationList
.
value
=
combinedAppList
}
else
{
this
.
applicationList
.
value
=
applicationList
}
if
(
applicationList
.
isNotEmpty
())
{
if
(
pageNumber
>
1
&&
this
.
applicationList
.
value
!=
null
)
{
val
combinedAppList
=
this
.
applicationList
.
value
!!
combinedAppList
.
addAll
(
applicationList
)
this
.
applicationList
.
value
=
combinedAppList
}
else
{
screenError
.
value
=
Error
.
NO_RESULTS
this
.
applicationList
.
value
=
applicationList
}
}
else
{
screenError
.
value
=
Error
.
NO_RESULTS
}
}
else
{
screenError
.
value
=
error
...
...
app/src/main/java/foundation/e/apps/search/model/SearchSuggestionsTask.kt
View file @
3e5c1342
...
...
@@ -19,6 +19,7 @@ package foundation.e.apps.search.model
import
android.content.Context
import
android.os.AsyncTask
import
android.util.Log
import
foundation.e.apps.api.AllAppsSearchRequest
import
foundation.e.apps.applicationmanager.ApplicationManager