Commit 9471f71c authored by Mohit Mali's avatar Mohit Mali
Browse files

Implemented changes to automatic update microG, Change in ApplicationActivity...

Implemented changes to automatic update microG, Change in ApplicationActivity for adding package name
parent f377726b
Pipeline #98475 passed with stage
in 3 minutes and 9 seconds
......@@ -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);
}
}
......@@ -61,8 +61,8 @@ class ApplicationsFragment(color: Int?) : Fragment() {
categoriesViewModel.getApplicationsCategories().observe(this, Observer {
if (it!!.isNotEmpty()) {
//Add New Category
it.add(Category("system_apps"))
if (!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
......
......@@ -24,6 +24,7 @@ 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.Common
import foundation.e.apps.utils.Constants
class OutdatedApplicationsFinder(private val packageManager: PackageManager,
private val callback: UpdatesWorkerInterface,
......@@ -64,6 +65,10 @@ class OutdatedApplicationsFinder(private val packageManager: PackageManager,
private fun getInstalledApplications(): ArrayList<String> {
val result = ArrayList<String>()
packageManager.getInstalledApplications(0).forEach { app ->
if (Common.isSystemApp(packageManager, app.packageName)) {
if (app.packageName == Constants.MICROG_PACKAGE)
result.add(app.packageName)
}
if (!Common.isSystemApp(packageManager, app.packageName)) {
result.add(app.packageName)
}
......
......@@ -29,12 +29,15 @@ import android.util.Log
import androidx.work.Worker
import androidx.work.WorkerParameters
import foundation.e.apps.R
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.updates.UpdatesNotifier
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 UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context, params),
UpdatesWorkerInterface {
......@@ -44,6 +47,7 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
private var installAutomatically = true
private var wifiOnly = false
val applicationManager = ApplicationManager()
private var error: Error? = null
override fun doWork(): Result {
Log.i(TAG, "Checking for app updates")
......@@ -100,17 +104,25 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
if (wifiOnly) {
if (isConnectedToUnmeteredNetwork) {
applications.forEach {
if (it.state == State.NOT_UPDATED) {
Log.i(TAG, "Updating ${it.packageName}")
it.buttonClicked(applicationContext, null)
if (it.packageName == Constants.MICROG_PACKAGE) {
executeDownloadMicroG()
}else {
if (it.state == State.NOT_UPDATED) {
Log.i(TAG, "Updating ${it.packageName}")
it.buttonClicked(applicationContext, null)
}
}
}
}
} else {
applications.forEach {
if (it.state == State.NOT_UPDATED) {
Log.i(TAG, "Updating ${it.packageName}")
it.buttonClicked(applicationContext, null)
if (it.packageName == Constants.MICROG_PACKAGE) {
executeDownloadMicroG()
}else {
if (it.state == State.NOT_UPDATED) {
Log.i(TAG, "Updating ${it.packageName}")
it.buttonClicked(applicationContext, null)
}
}
}
}
......@@ -132,4 +144,40 @@ class UpdatesWorker(context: Context, params: WorkerParameters) : Worker(context
networkInfo?.isConnected ?: false
} else false
}
private fun executeDownloadMicroG() {
Execute({
var application: Application? = loadMicroGVersion()?.get(0)
if (application!!.state != State.INSTALLED) {
application.download(applicationContext)
}
}, {
if (error != null) {
print(error)
}
})
}
private fun loadMicroGVersion(): ArrayList<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!!, applicationContext)
} else {
null
}
}
}
......@@ -817,6 +817,47 @@
</LinearLayout>
<LinearLayout
android:id="@+id/app_package_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_margin_medium"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_app_licence" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/layout_margin_medium"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/app_package_name"
android:textColor="@android:color/black"
android:textSize="@dimen/text_size_large" />
</LinearLayout>
<TextView
android:id="@+id/app_package_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/layout_margin_medium"
android:ellipsize="end"
android:maxLines="1"
android:textSize="@dimen/text_size_large" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
......
......@@ -56,6 +56,7 @@
<string name="app_updated_on">Updated on</string>
<string name="app_min_android">Requires</string>
<string name="app_licence">Licence</string>
<string name="app_package_name">Package name</string>
<string name="app_screenshots_title">Screenshots</string>
<string name="download_notification_description">Downloading</string>
<string name="no_permissions">No permissions requested</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment