Commit d9f73a1a authored by narinder Rana's avatar narinder Rana Committed by Romain Hunault
Browse files

Use system accent color

parent 3ca2170a
......@@ -19,15 +19,24 @@ package foundation.e.apps
//import androidx.fragment.app.ListFragment
import android.annotation.SuppressLint
import android.content.*
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.preference.PreferenceManager
import android.util.TypedValue
import android.view.MenuItem
import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.Fragment
import com.google.android.material.bottomnavigation.BottomNavigationItemView
import com.google.android.material.bottomnavigation.BottomNavigationMenuView
......@@ -60,21 +69,26 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
private val codeRequestPermissions = 9527
var doubleBackToExitPressedOnce = false;
private var isReceiverRegistered = false
var accentColorOS = 0
companion object {
lateinit var mActivity: MainActivity
var sharedPreferences : SharedPreferences?=null
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//ThemeColors(this);
setContentView(R.layout.activity_main)
mActivity = this
disableCategoryIfOpenSource()
bottom_navigation_view.setOnNavigationItemSelectedListener{
if (selectFragment(it.itemId,it)) {
disableCategoryIfOpenSource()
......@@ -101,6 +115,28 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
setupLangReceiver()
applicationManagerServiceConnection.bindService(this)
getAccentColor();
bottom_navigation_view_color()
}
private fun bottom_navigation_view_color() {
val iconsColorStates =
ColorStateList(arrayOf(intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)), intArrayOf(
Color.parseColor("#C4CFD9"),
accentColorOS
))
val textColorStates = ColorStateList(arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)), intArrayOf(
Color.parseColor("#C4CFD9"),
accentColorOS
))
bottom_navigation_view.setItemIconTintList(iconsColorStates)
bottom_navigation_view.setItemTextColor(textColorStates)
}
private fun initialiseUpdatesWorker() {
......@@ -115,9 +151,9 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
private fun initialiseFragments(applicationManager: ApplicationManager) {
homeFragment.initialise(applicationManager)
searchFragment.initialise(applicationManager)
updatesFragment.initialise(applicationManager)
homeFragment.initialise(applicationManager, accentColorOS)
searchFragment.initialise(applicationManager, accentColorOS)
updatesFragment.initialise(applicationManager, accentColorOS)
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
......@@ -143,17 +179,28 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
return "any"
}
fun tintMenuIcon(context: Context, item: MenuItem, @ColorRes color: Int) {
val normalDrawable = item.icon
val wrapDrawable = DrawableCompat.wrap(normalDrawable)
DrawableCompat.setTint(wrapDrawable, ContextCompat.getColor(context, color))//context.resources.getColor(color))
item.icon = wrapDrawable
}
private fun selectFragment(fragmentId: Int, item: MenuItem?): Boolean {
when (fragmentId) {
R.id.menu_home -> {
item?.setIcon(R.drawable.ic_menu_home)
showFragment(homeFragment)
return true
}
R.id.menu_categories -> {
item?.setIcon(R.drawable.ic_menu_categories)
showFragment(CategoriesFragment())
return true
}
R.id.menu_search -> {
......@@ -264,4 +311,20 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
}, 2000)
}
/*
* get Accent color from OS
*
* */
private fun getAccentColor() {
val typedValue = TypedValue()
val contextThemeWrapper = ContextThemeWrapper(this,
android.R.style.Theme_DeviceDefault)
contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent,
typedValue, true)
@ColorInt val color = typedValue.data
accentColorOS=color;
}
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ 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
......@@ -39,8 +40,10 @@ 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
......@@ -90,7 +93,7 @@ class ApplicationActivity :
private var imageMargin = 0
private var defaultElevation = 0f
private val sharedPrefFile = "kotlinsharedpreference"
var accentColorOS = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -113,6 +116,14 @@ class ApplicationActivity :
this.applicationPackageName = applicationPackageName!!
applicationManagerServiceConnection.bindService(this)
}
getAccentColor()
app_install.setTextColor(Color.parseColor("#ffffff"))
app_install.setBackgroundColor(accentColorOS)
app_category.setTextColor(accentColorOS)
app_expand_description.setTextColor(accentColorOS)
}
......@@ -749,4 +760,14 @@ class ApplicationActivity :
applicationManagerServiceConnection.unbindService(this)
}
}
private fun getAccentColor() {
val typedValue = TypedValue()
val contextThemeWrapper = ContextThemeWrapper(this,
android.R.style.Theme_DeviceDefault)
contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent,
typedValue, true)
@ColorInt val color = typedValue.data
accentColorOS=color;
}
}
......@@ -45,17 +45,17 @@ import kotlinx.android.synthetic.main.application_list_item.view.*
import kotlinx.android.synthetic.main.install_button_layout.view.*
class ApplicationViewHolder(private val activity: Activity, private val view: View) :
class ApplicationViewHolder(private val activity: Activity, private val view: View, accentColorOS: Int) :
RecyclerView.ViewHolder(view),
ApplicationStateListener,
Downloader.DownloadProgressCallback,
BasicData.IconLoaderCallback,
PwasBasicData.IconLoaderCallback{
PwasBasicData.IconLoaderCallback {
private val icon: ImageView = view.app_icon
private val title: TextView = view.app_title
private val pwa_icon :TextView =view.pwa_sympol
private val pwa_icon: TextView = view.pwa_sympol
private val author: TextView = view.app_author
private val ratingBar: RatingBar = view.app_rating_bar
private val rating: TextView = view.app_rating
......@@ -64,27 +64,32 @@ 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;
init {
pwa_icon.visibility=View.GONE
pwa_icon.visibility = View.GONE
view.setOnClickListener {
if (application != null) {
applicationViewModel.onApplicationClick(view.context, application!!)
}
}
installButton.setTextColor(Color.parseColor("#ffffff"))
if(0!=this.accentColorOS){
installButton.setBackgroundColor(this.accentColorOS)
}
installButton?.setOnClickListener {
if (application?.fullData != null &&
application!!.fullData!!.getLastVersion() == null) {
Snackbar.make(view, activity.getString(
Error.APK_UNAVAILABLE.description),
Snackbar.LENGTH_LONG).show()
} else if(application?.pwabasicdata!=null){
} else if (application?.pwabasicdata != null) {
application?.pwaInstall(activity)
}else if(application?.searchAppsBasicData!=null &&application?.searchAppsBasicData!!.is_pwa){
} else if (application?.searchAppsBasicData != null && application?.searchAppsBasicData!!.is_pwa) {
application?.pwaInstall(activity)
}
else {
} else {
application?.buttonClicked(activity, activity)
}
}
......@@ -92,46 +97,46 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
fun createApplicationView(app: Application) {
pwa_icon.visibility = View.GONE
this.application = app
pwa_icon.visibility = View.GONE
this.application = app
if (app.basicData != null) {
this.application?.removeListener(this)
this.application = app
icon.setImageDrawable(view.context.resources.getDrawable(R.drawable.ic_app_default))
application!!.loadIcon(this)
application!!.addListener(this)
title.text = application!!.basicData!!.name
author.text = application!!.basicData!!.author
ratingBar.rating = application!!.basicData!!.ratings!!.rating!!
if (application!!.basicData!!.ratings!!.rating != -1f) {
rating.text = application!!.basicData!!.ratings!!.rating.toString()
} else {
rating.text = activity.getString(R.string.not_available)
}
if (application!!.basicData!!.privacyRating != null && application!!.basicData!!.privacyRating != -1f) {
privacyScore.text = application!!.basicData!!.privacyRating.toString()
} else {
privacyScore.text = activity.getString(R.string.not_available)
if (app.basicData != null) {
this.application?.removeListener(this)
this.application = app
icon.setImageDrawable(view.context.resources.getDrawable(R.drawable.ic_app_default))
application!!.loadIcon(this)
application!!.addListener(this)
title.text = application!!.basicData!!.name
author.text = application!!.basicData!!.author
ratingBar.rating = application!!.basicData!!.ratings!!.rating!!
if (application!!.basicData!!.ratings!!.rating != -1f) {
rating.text = application!!.basicData!!.ratings!!.rating.toString()
} else {
rating.text = activity.getString(R.string.not_available)
}
if (application!!.basicData!!.privacyRating != null && application!!.basicData!!.privacyRating != -1f) {
privacyScore.text = application!!.basicData!!.privacyRating.toString()
} else {
privacyScore.text = activity.getString(R.string.not_available)
}
} else {
this.application?.removeListener(this)
this.application = app
icon.setImageDrawable(view.context.resources.getDrawable(R.drawable.ic_app_default))
application!!.addListener(this)
if (application!!.searchAppsBasicData != null) {
if (application!!.searchAppsBasicData!!.is_pwa) {
pwa_icon.visibility = View.VISIBLE
}
}else{
this.application?.removeListener(this)
this.application = app
icon.setImageDrawable(view.context.resources.getDrawable(R.drawable.ic_app_default))
application!!.addListener(this)
if (application!!.searchAppsBasicData != null) {
if (application!!.searchAppsBasicData!!.is_pwa) {
pwa_icon.visibility = View.VISIBLE
}
application!!.SearchAppsloadIcon(this)
title.text = application!!.searchAppsBasicData!!.name
author.text = application!!.searchAppsBasicData!!.author
} else {
application!!.PwaloadIcon(this)
title.text = application!!.pwabasicdata!!.name
application!!.SearchAppsloadIcon(this)
title.text = application!!.searchAppsBasicData!!.name
author.text = application!!.searchAppsBasicData!!.author
} else {
application!!.PwaloadIcon(this)
title.text = application!!.pwabasicdata!!.name
}
}
}
stateChanged(application!!.state)
}
......@@ -143,12 +148,19 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
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 ->{
installButton.setTextColor(Color.parseColor("#0088ED"))
State.NOT_DOWNLOADED -> {
if(0!=this.accentColorOS){
installButton.setTextColor(this.accentColorOS)
}
else{
installButton.setTextColor(Color.parseColor("#0088ED"))
}
installButton.setBackgroundResource(R.drawable.app_install_border_simple)
installButton.isEnabled = true
}
......@@ -156,15 +168,27 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
State.INSTALLED -> {
installButton?.isEnabled =
Common.appHasLaunchActivity(activity, application!!.packageName)
if(0!=this.accentColorOS){
installButton!!.setBackgroundColor(this.accentColorOS)
}
else{
installButton!!.setBackgroundResource(R.drawable.app_install_border)
}
installButton.setTextColor(Color.parseColor("#FAFAFA"))
installButton!!.setBackgroundResource(R.drawable.app_install_border)
}
State.INSTALLING -> {
installButton?.isEnabled = false
}
State.NOT_UPDATED -> {
installButton.setTextColor(Color.parseColor("#FAFAFA"))
installButton!!.setBackgroundResource(R.drawable.app_install_border)
//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 -> {
......@@ -172,6 +196,7 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
installButton?.isEnabled = true
}
}
})
}
......@@ -198,4 +223,5 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
downloader?.removeListener(this)
downloader = null
}
}
......@@ -53,6 +53,7 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
BasicData.IconLoaderCallback,
PwasBasicData.IconLoaderCallback{
private val icon: ImageView = view.app_icon
private val title: TextView = view.app_title
private val installButton: Button = view.app_install
......@@ -67,6 +68,7 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
applicationViewModel.onApplicationClick(view.context, application!!)
}
}
installButton.setOnClickListener {
if (application?.fullData != null &&
application!!.fullData!!.getLastVersion() == null) {
......@@ -82,7 +84,6 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
}
}
}
fun createApplicationView(app: Application) {
if(app.basicData!=null) {
this.application?.removeListener(this)
......@@ -116,11 +117,14 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
installButton.text = activity.getString(state.installButtonTextId)
installButton.clearAnimation()
installButton.clearFocus();
var color = application?.getAccentColor(activity);
when (state) {
State.NOT_DOWNLOADED ->{
installButton.setTextColor(Color.parseColor("#0088ED"))
installButton.setBackgroundResource(R.drawable.app_install_border_simple)
if (color != null) {
installButton.setTextColor(color)
};
installButton.isEnabled = true
}
......@@ -128,7 +132,10 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
installButton.isEnabled =
Common.appHasLaunchActivity(activity, application!!.packageName)
installButton.setTextColor(Color.parseColor("#FAFAFA"))
installButton!!.setBackgroundResource(R.drawable.app_install_border)
if (color != null) {
//installButton!!.setBackgroundResource(R.drawable.app_install_border)
installButton.setBackgroundColor(color)
};
}
State.INSTALLING -> {
installButton.isEnabled = false
......@@ -137,7 +144,11 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
}
State.NOT_UPDATED -> {
installButton.setTextColor(Color.parseColor("#FAFAFA"))
installButton!!.setBackgroundResource(R.drawable.app_install_border)
// installButton!!.setBackgroundResource(R.drawable.app_install_border)
if (color != null) {
//installButton!!.setBackgroundResource(R.drawable.app_install_border)
installButton.setBackgroundColor(color)
};
installButton.isEnabled = true
}
else -> {
......
......@@ -18,11 +18,16 @@
package foundation.e.apps.application.model
import android.Manifest
import android.R
import android.app.Activity
import android.app.DownloadManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.util.Log
import android.util.TypedValue
import androidx.annotation.ColorInt
import androidx.appcompat.view.ContextThemeWrapper
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.pwa.PwaInstaller
import foundation.e.apps.XAPK.XAPKFile
......@@ -39,9 +44,7 @@ import foundation.e.apps.utils.Execute
import java.util.concurrent.atomic.AtomicInteger
class Application(val packageName: String, private val applicationManager: ApplicationManager) :
DownloaderInterface, InstallerInterface{
DownloaderInterface, InstallerInterface {
private val uses = AtomicInteger(0)
......@@ -49,9 +52,9 @@ class Application(val packageName: String, private val applicationManager: Appli
private val stateManager = StateManager(info, this, applicationManager)
var basicData: BasicData? = null
var fullData: FullData? = null
var pwabasicdata : PwasBasicData? = null
var pwabasicdata: PwasBasicData? = null
var pwaFullData: PwaFullData? = null
var searchAppsBasicData : SearchAppsBasicData? =null
var searchAppsBasicData: SearchAppsBasicData? = null
fun addListener(listener: ApplicationStateListener) {
......@@ -80,16 +83,13 @@ class Application(val packageName: String, private val applicationManager: Appli
fun checkForStateUpdate(context: Context) {
if (basicData != null) {
stateManager.find(context, basicData!!)
}
else if(searchAppsBasicData !=null){
if(searchAppsBasicData!!.is_pwa){
} else if (searchAppsBasicData != null) {
if (searchAppsBasicData!!.is_pwa) {
// stateManager.pwaFind()
}
else{
} else {
stateManager.searchAppsFind(context, searchAppsBasicData!!)
}
}
else if(pwabasicdata!=null){
} else if (pwabasicdata != null) {
// stateManager.pwaFind()
}
}
......@@ -98,16 +98,16 @@ class Application(val packageName: String, private val applicationManager: Appli
fun pwaInstall(context: Context) {
var error: Error? = null
Thread(Runnable {
error=assertFullData(context)
Thread(Runnable {
error = assertFullData(context)
mActivity.runOnUiThread(Runnable{
mActivity.runOnUiThread(Runnable {
run {
if (error == null) {
val intent=Intent(context, PwaInstaller::class.java)
intent.putExtra("NAME",pwaFullData!!.name)
intent.putExtra("URL",pwaFullData!!.url)
val intent = Intent(context, PwaInstaller::class.java)
intent.putExtra("NAME", pwaFullData!!.name)
intent.putExtra("URL", pwaFullData!!.url)
context.startActivity(intent)
} else {
stateManager.notifyError(error!!)
......@@ -201,24 +201,22 @@ class Application(val packageName: String, private val applicationManager: Appli
override fun onDownloadComplete(context: Context, status: Int) {
if (status == DownloadManager.STATUS_SUCCESSFUL) {
Execute({
AppDownloadedRequest(basicData!!.id,fullData!!.getLastVersion()?.apkArchitecture).request()
AppDownloadedRequest(basicData!!.id, fullData!!.getLastVersion()?.apkArchitecture).request()
}, {})
if(info.isXapk(fullData!!,basicData)){
isInstalling=true
XAPKFile(info.getxApkFile(context,basicData!!),this)
}
else {
if (info.isXapk(fullData!!, basicData)) {
isInstalling = true
XAPKFile(info.getxApkFile(context, basicData!!), this)
} else {
install(context)
}
} else {
synchronized(blocker) {
blocker.notify()
}
if(basicData!=null) {
if (basicData != null) {
info.getApkFile(context, basicData!!).delete()
applicationManager.stopInstalling(context, this)
}
else{
} else {
applicationManager.stopInstalling(context, this)