Commit a2540f00 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Rename InstallManager to ApplicationManager

parent 7dfbb76d
......@@ -25,7 +25,7 @@
<activity android:name=".categories.category.CategoryActivity" />
<service
android:name=".application.model.InstallManagerService"
android:name=".applicationmanager.ApplicationManagerService"
android:description="@string/service_description"
android:exported="false" />
......
......@@ -9,8 +9,8 @@ import android.support.design.widget.BottomNavigationView
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.application.model.InstallManagerGetter
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.applicationmanager.ApplicationManagerServiceConnection
import io.eelo.appinstaller.categories.CategoriesFragment
import io.eelo.appinstaller.home.HomeFragment
import io.eelo.appinstaller.search.SearchFragment
......@@ -25,7 +25,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
private val homeFragment = HomeFragment()
private val searchFragment = SearchFragment()
private val updatesFragment = UpdatesFragment()
private val installManagerGetter = InstallManagerGetter()
private val applicationManagerServiceConnection = ApplicationManagerServiceConnection()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
object : AsyncTask<Void, Void, Void>() {
override fun doInBackground(vararg p0: Void?): Void? {
val installManager = installManagerGetter.connectAndGet(this@MainActivity)
val installManager = applicationManagerServiceConnection.connectAndGet(this@MainActivity)
initialiseFragments(installManager)
return null
}
......@@ -57,10 +57,10 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}.executeOnExecutor(Common.EXECUTOR)
}
private fun initialiseFragments(installManager: InstallManager) {
homeFragment.initialise(installManager)
searchFragment.initialise(installManager)
updatesFragment.initialise(installManager)
private fun initialiseFragments(applicationManager: ApplicationManager) {
homeFragment.initialise(applicationManager)
searchFragment.initialise(applicationManager)
updatesFragment.initialise(applicationManager)
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
......@@ -136,6 +136,6 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
homeFragment.decrementApplicationUses()
searchFragment.decrementApplicationUses()
updatesFragment.decrementApplicationUses()
installManagerGetter.disconnect(this)
applicationManagerServiceConnection.disconnect(this)
}
}
......@@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.application.model.data.FullData
import io.eelo.appinstaller.categories.model.Category
import io.eelo.appinstaller.utils.Error
......@@ -47,14 +47,14 @@ class HomeRequest {
constructor(@JsonProperty("success") private val success: Boolean,
@JsonProperty("home") private val home: SubHomeResult) {
fun getBannerApps(installManager: InstallManager, context: Context): ArrayList<Application> {
return ApplicationParser.parseToApps(installManager, context, home.bannerApps)
fun getBannerApps(applicationManager: ApplicationManager, context: Context): ArrayList<Application> {
return ApplicationParser.parseToApps(applicationManager, context, home.bannerApps)
}
fun getApps(installManager: InstallManager, context: Context): HashMap<Category, ArrayList<Application>> {
fun getApps(applicationManager: ApplicationManager, context: Context): HashMap<Category, ArrayList<Application>> {
val apps = HashMap<Category, ArrayList<Application>>()
for (pair in home.apps) {
apps[pair.key] = ApplicationParser.parseToApps(installManager, context, pair.value.toTypedArray())
apps[pair.key] = ApplicationParser.parseToApps(applicationManager, context, pair.value.toTypedArray())
}
return apps
}
......
......@@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.application.model.data.FullData
import io.eelo.appinstaller.utils.Error
import io.eelo.appinstaller.utils.ApplicationParser
......@@ -46,8 +46,8 @@ class ListApplicationsRequest(private val category: String, private val page: In
@JsonProperty("pages") val pages: Int,
@JsonProperty("apps") private val apps: Array<FullData>) {
fun getApplications(installManager: InstallManager, context: Context): ArrayList<Application> {
return ApplicationParser.parseToApps(installManager, context, apps)
fun getApplications(applicationManager: ApplicationManager, context: Context): ArrayList<Application> {
return ApplicationParser.parseToApps(applicationManager, context, apps)
}
}
......
......@@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.application.model.data.BasicData
import io.eelo.appinstaller.utils.Error
import io.eelo.appinstaller.utils.ApplicationParser
......@@ -47,8 +47,8 @@ class SearchRequest(private val keyword: String, private val page: Int, private
@param:JsonProperty("numberOfResults") val resultsNumber: Int,
@param:JsonProperty("apps") val appResults: Array<BasicData>) {
fun getApplications(installManager: InstallManager, context: Context): List<Application> {
return ApplicationParser.parseToApps(installManager, context, appResults)
fun getApplications(applicationManager: ApplicationManager, context: Context): List<Application> {
return ApplicationParser.parseToApps(applicationManager, context, appResults)
}
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import android.view.View
import android.widget.*
import io.eelo.appinstaller.R
import io.eelo.appinstaller.application.model.*
import io.eelo.appinstaller.applicationmanager.ApplicationManagerServiceConnection
import io.eelo.appinstaller.utils.Common
import io.eelo.appinstaller.utils.Common.toMiB
import io.eelo.appinstaller.utils.Constants.APPLICATION_DESCRIPTION_KEY
......@@ -29,7 +30,7 @@ import kotlin.math.roundToInt
class ApplicationActivity : AppCompatActivity(), ApplicationStateListener {
private lateinit var application: Application
private val installManagerGetter = InstallManagerGetter()
private val applicationManagerServiceConnection = ApplicationManagerServiceConnection()
private var imageWidth = 0
private var imageHeight = 0
private var imageMargin = 0
......@@ -358,7 +359,7 @@ class ApplicationActivity : AppCompatActivity(), ApplicationStateListener {
private fun initialise(packageName: String) {
var error: Error? = null
Execute({
val installManager = installManagerGetter.connectAndGet(this)
val installManager = applicationManagerServiceConnection.connectAndGet(this)
application = installManager.findOrCreateApp(packageName)
error = application.assertFullData(this)
}, {
......@@ -448,6 +449,6 @@ class ApplicationActivity : AppCompatActivity(), ApplicationStateListener {
override fun onDestroy() {
super.onDestroy()
application.decrementUses()
installManagerGetter.disconnect(this)
applicationManagerServiceConnection.disconnect(this)
}
}
......@@ -6,14 +6,14 @@ import android.support.v4.view.ViewPager
import android.view.View
import io.eelo.appinstaller.R
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManagerGetter
import io.eelo.appinstaller.applicationmanager.ApplicationManagerServiceConnection
import io.eelo.appinstaller.utils.Constants
import io.eelo.appinstaller.utils.Constants.SELECTED_APPLICATION_SCREENSHOT_KEY
import io.eelo.appinstaller.utils.Execute
import kotlinx.android.synthetic.main.activity_screenshots.*
class ScreenshotsActivity : AppCompatActivity() {
private val installManagerGetter = InstallManagerGetter()
private val applicationManagerServiceConnection = ApplicationManagerServiceConnection()
private lateinit var application: Application
private lateinit var screenshotsCarousel: ViewPager
private var lastSelectedScreenshotIndex = 0
......@@ -41,7 +41,7 @@ class ScreenshotsActivity : AppCompatActivity() {
private fun initialise(packageName: String) {
Execute({
val installManager = installManagerGetter.connectAndGet(this)
val installManager = applicationManagerServiceConnection.connectAndGet(this)
application = installManager.findOrCreateApp(packageName)
}, {
onApplicationInfoLoaded()
......@@ -73,6 +73,6 @@ class ScreenshotsActivity : AppCompatActivity() {
override fun onDestroy() {
super.onDestroy()
application.decrementUses()
installManagerGetter.disconnect(this)
applicationManagerServiceConnection.disconnect(this)
}
}
......@@ -8,10 +8,11 @@ import io.eelo.appinstaller.api.PackageNameSearchRequest
import io.eelo.appinstaller.application.model.State.*
import io.eelo.appinstaller.application.model.data.BasicData
import io.eelo.appinstaller.application.model.data.FullData
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.utils.Error
import java.util.concurrent.atomic.AtomicInteger
class Application(val packageName: String, private val installManager: InstallManager) {
class Application(val packageName: String, private val applicationManager: ApplicationManager) {
private val uses = AtomicInteger(0)
private val info = ApplicationInfo(packageName)
......@@ -38,7 +39,7 @@ class Application(val packageName: String, private val installManager: InstallMa
fun decrementUses() {
uses.decrementAndGet()
installManager.tryRemove(this)
applicationManager.tryRemove(this)
}
fun checkForStateUpdate(context: Context) {
......@@ -56,7 +57,7 @@ class Application(val packageName: String, private val installManager: InstallMa
}
NOT_UPDATED, NOT_DOWNLOADED -> {
stateManager.changeState(DOWNLOADING)
installManager.download(packageName)
applicationManager.download(packageName)
}
DOWNLOADING -> {
// TODO Cancel APK download
......@@ -83,7 +84,7 @@ class Application(val packageName: String, private val installManager: InstallMa
private fun prepareInstall() {
stateManager.changeState(INSTALLING)
installManager.install(packageName)
applicationManager.install(packageName)
}
fun install(context: Context) {
......
package io.eelo.appinstaller.application.model
package io.eelo.appinstaller.applicationmanager
import android.content.Context
import io.eelo.appinstaller.application.model.Application
import java.util.*
import java.util.concurrent.ArrayBlockingQueue
class InstallManager {
class ApplicationManager {
private val apps = HashMap<String, Application>()
private val downloading = ArrayBlockingQueue<String>(100)
......
package io.eelo.appinstaller.application.model
package io.eelo.appinstaller.applicationmanager
import android.app.Service
import android.content.Intent
......@@ -7,9 +7,9 @@ import android.os.IBinder
import android.os.Message
import android.os.Messenger
class InstallManagerService : Service() {
class ApplicationManagerService : Service() {
private val installManager = InstallManager()
private val installManager = ApplicationManager()
private val messenger = Messenger(SimpleHandler(installManager))
......@@ -21,11 +21,11 @@ class InstallManagerService : Service() {
return messenger.binder
}
private class SimpleHandler(private val installManager: InstallManager) : Handler() {
private class SimpleHandler(private val applicationManager: ApplicationManager) : Handler() {
@Suppress("UNCHECKED_CAST")
override fun handleMessage(msg: Message) {
(msg.obj as (InstallManager) -> Unit).invoke(installManager)
(msg.obj as (ApplicationManager) -> Unit).invoke(applicationManager)
}
}
}
package io.eelo.appinstaller.application.model
package io.eelo.appinstaller.applicationmanager
import android.content.ComponentName
import android.content.Context
......@@ -8,14 +8,14 @@ import android.os.IBinder
import android.os.Message
import android.os.Messenger
class InstallManagerGetter : ServiceConnection {
class ApplicationManagerServiceConnection : ServiceConnection {
private lateinit var installManager: InstallManager
private lateinit var applicationManager: ApplicationManager
private val blocker = Object()
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
Messenger(service).send(Message.obtain(null, 0, { result: InstallManager ->
installManager = result
Messenger(service).send(Message.obtain(null, 0, { result: ApplicationManager ->
applicationManager = result
synchronized(blocker) {
blocker.notify()
}
......@@ -25,13 +25,13 @@ class InstallManagerGetter : ServiceConnection {
override fun onServiceDisconnected(name: ComponentName?) {
}
fun connectAndGet(context: Context): InstallManager {
context.startService(Intent(context, InstallManagerService::class.java))
context.bindService(Intent(context, InstallManagerService::class.java), this, Context.BIND_AUTO_CREATE)
fun connectAndGet(context: Context): ApplicationManager {
context.startService(Intent(context, ApplicationManagerService::class.java))
context.bindService(Intent(context, ApplicationManagerService::class.java), this, Context.BIND_AUTO_CREATE)
synchronized(blocker) {
blocker.wait()
}
return installManager
return applicationManager
}
fun disconnect(context: Context) {
......
......@@ -15,7 +15,7 @@ import android.widget.ProgressBar
import android.widget.TextView
import io.eelo.appinstaller.R
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManagerGetter
import io.eelo.appinstaller.applicationmanager.ApplicationManagerServiceConnection
import io.eelo.appinstaller.application.model.State
import io.eelo.appinstaller.categories.category.viewmodel.CategoryViewModel
import io.eelo.appinstaller.categories.model.Category
......@@ -30,7 +30,7 @@ class CategoryActivity : AppCompatActivity() {
private lateinit var recyclerView: RecyclerView
private lateinit var progressBar: ProgressBar
private var applicationList = ArrayList<Application>()
private val installManagerGetter = InstallManagerGetter()
private val applicationManagerServiceConnection = ApplicationManagerServiceConnection()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -88,7 +88,7 @@ class CategoryActivity : AppCompatActivity() {
object : AsyncTask<Void, Void, Void>() {
override fun doInBackground(vararg p0: Void?): Void? {
val installManager = installManagerGetter.connectAndGet(this@CategoryActivity)
val installManager = applicationManagerServiceConnection.connectAndGet(this@CategoryActivity)
categoryViewModel.initialise(installManager, category.id)
return null
}
......@@ -124,6 +124,6 @@ class CategoryActivity : AppCompatActivity() {
applicationList.forEach {
it.decrementUses()
}
installManagerGetter.disconnect(this)
applicationManagerServiceConnection.disconnect(this)
}
}
......@@ -4,12 +4,12 @@ import android.arch.lifecycle.MutableLiveData
import android.content.Context
import io.eelo.appinstaller.api.ListApplicationsRequest
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.utils.*
class CategoryModel : CategoryModelInterface {
lateinit var installManager: InstallManager
lateinit var applicationManager: ApplicationManager
lateinit var category: String
private var page = 1
val categoryApplicationsList = MutableLiveData<ArrayList<Application>>()
......@@ -22,8 +22,8 @@ class CategoryModel : CategoryModelInterface {
}
}
override fun initialise(installManager: InstallManager, category: String) {
this.installManager = installManager
override fun initialise(applicationManager: ApplicationManager, category: String) {
this.applicationManager = applicationManager
this.category = category
}
......@@ -59,7 +59,7 @@ class CategoryModel : CategoryModelInterface {
}
}
if (listApplications != null) {
return listApplications!!.getApplications(installManager, context)
return listApplications!!.getApplications(applicationManager, context)
} else {
return null
}
......
package io.eelo.appinstaller.categories.category.model
import android.content.Context
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
interface CategoryModelInterface {
fun initialise(installManager: InstallManager, category: String)
fun initialise(applicationManager: ApplicationManager, category: String)
fun loadApplications(context: Context)
}
\ No newline at end of file
......@@ -4,15 +4,15 @@ import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel
import android.content.Context
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.categories.category.model.CategoryModel
import io.eelo.appinstaller.utils.Error
class CategoryViewModel : ViewModel(), CategoryViewModelInterface {
private val categoryModel = CategoryModel()
override fun initialise(installManager: InstallManager, category: String) {
categoryModel.initialise(installManager, category)
override fun initialise(applicationManager: ApplicationManager, category: String) {
categoryModel.initialise(applicationManager, category)
}
override fun getApplications(): MutableLiveData<ArrayList<Application>> {
......
......@@ -3,12 +3,12 @@ package io.eelo.appinstaller.categories.category.viewmodel
import android.arch.lifecycle.MutableLiveData
import android.content.Context
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.utils.Error
interface CategoryViewModelInterface {
fun initialise(installManager: InstallManager, category: String)
fun initialise(applicationManager: ApplicationManager, category: String)
fun getApplications(): MutableLiveData<ArrayList<Application>>
......
......@@ -15,7 +15,7 @@ import android.widget.ProgressBar
import android.widget.TextView
import io.eelo.appinstaller.R
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.application.model.State
import io.eelo.appinstaller.categories.model.Category
import io.eelo.appinstaller.common.SmallApplicationListAdapter
......@@ -28,14 +28,14 @@ class HomeFragment : Fragment() {
private lateinit var divider: View
private lateinit var categoryList: LinearLayout
private lateinit var progressBar: ProgressBar
private var installManager: InstallManager? = null
private var applicationManager: ApplicationManager? = null
fun initialise(installManager: InstallManager) {
this.installManager = installManager
fun initialise(applicationManager: ApplicationManager) {
this.applicationManager = applicationManager
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
if (installManager == null) {
if (applicationManager == null) {
return null
}
......@@ -50,7 +50,7 @@ class HomeFragment : Fragment() {
val errorDescription = view.findViewById<TextView>(R.id.error_description)
// Initialise UI elements
homeViewModel.initialise(installManager!!)
homeViewModel.initialise(applicationManager!!)
setCustomScroller()
imageCarousel.visibility = View.INVISIBLE
divider.visibility = View.INVISIBLE
......
......@@ -3,7 +3,7 @@ package io.eelo.appinstaller.home.model
import android.arch.lifecycle.MutableLiveData
import android.content.Context
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.categories.model.Category
import io.eelo.appinstaller.utils.Common
import io.eelo.appinstaller.utils.Error
......@@ -11,7 +11,7 @@ import io.eelo.appinstaller.utils.Error
class HomeModel : HomeModelInterface {
val applications = MutableLiveData<LinkedHashMap<Category, ArrayList<Application>>>()
val bannerApplications = MutableLiveData<ArrayList<BannerApplication>>()
private var installManager: InstallManager? = null
private var applicationManager: ApplicationManager? = null
var screenError = MutableLiveData<Error>()
init {
......@@ -23,12 +23,12 @@ class HomeModel : HomeModelInterface {
}
}
override fun initialise(installManager: InstallManager) {
this.installManager = installManager
override fun initialise(applicationManager: ApplicationManager) {
this.applicationManager = applicationManager
}
override fun getInstallManager(): InstallManager {
return installManager!!
override fun getInstallManager(): ApplicationManager {
return applicationManager!!
}
override fun loadCategories(context: Context) {
......
package io.eelo.appinstaller.home.model
import android.content.Context
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
interface HomeModelInterface {
fun initialise(installManager: InstallManager)
fun initialise(applicationManager: ApplicationManager)
fun getInstallManager(): InstallManager
fun getInstallManager(): ApplicationManager
fun loadCategories(context: Context)
}
......@@ -4,7 +4,7 @@ import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel
import android.content.Context
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.InstallManager
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.categories.model.Category
import io.eelo.appinstaller.home.model.BannerApplication
import io.eelo.appinstaller.home.model.HomeModel
......@@ -13,8 +13,8 @@ import io.eelo.appinstaller.utils.Error
class HomeViewModel : ViewModel(), HomeViewModelInterface {
private val homeModel = HomeModel()
override fun initialise(installManager: InstallManager) {
homeModel.initialise(installManager)
override fun initialise(applicationManager: ApplicationManager) {
homeModel.initialise(applicationManager)
}
override fun getBannerApplications(): MutableLiveData<ArrayList<BannerApplication>> {
......
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