Commit 5c297107 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Apps: Drop non-required non-null and safe assertions completely



- Resolves multiple compile-time warnings
Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
parent 63c2464b
......@@ -320,7 +320,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState?.putInt(CURRENTLY_SELECTED_FRAGMENT_KEY, currentFragmentId)
outState.putInt(CURRENTLY_SELECTED_FRAGMENT_KEY, currentFragmentId)
}
override fun onDestroy() {
......
......@@ -108,7 +108,7 @@ class ApplicationActivity :
initialiseDimensions()
val applicationPackageName: String? = intent.getStringExtra(APPLICATION_PACKAGE_NAME_KEY)
if (!applicationPackageName.isNullOrEmpty()) {
this.applicationPackageName = applicationPackageName!!
this.applicationPackageName = applicationPackageName
applicationManagerServiceConnection.bindService(this)
}
......@@ -236,7 +236,7 @@ class ApplicationActivity :
// Set the app author
if (basicData.author!!.isNotEmpty()) {
if (basicData.author.isNotEmpty()) {
app_author.text = basicData.author
} else {
app_author.visibility = View.GONE
......@@ -272,12 +272,12 @@ class ApplicationActivity :
// Set the app rating
val builder = textColorChange(getText(R.string.not_available).toString())
if (basicData.ratings!!.rating != -1f) {
if (basicData.ratings.rating != -1f) {
app_rating.text = basicData.ratings.rating.toString() + "/5"
} else {
app_rating.text = builder
}
setRatingBorder(basicData.ratings!!.rating)
setRatingBorder(basicData.ratings.rating)
app_rating_container.setOnClickListener {
val text = R.string.ok
......@@ -515,7 +515,7 @@ class ApplicationActivity :
// Set the app title
if (pwasBasicData!!.name.isNotEmpty()) {
app_title.text = pwasBasicData!!.name
app_title.text = pwasBasicData.name
} else {
app_title.visibility = View.GONE
}
......@@ -529,7 +529,7 @@ class ApplicationActivity :
app_description_container.isEnabled = false
}
if (pwaFullData!!.category.getTitle().isNotEmpty()) {
if (pwaFullData.category.getTitle().isNotEmpty()) {
app_category.text = pwaFullData.category.getTitle()
app_category.setOnClickListener {
startActivity(Intent(this, CategoryActivity::class.java).apply {
......
......@@ -82,7 +82,7 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
if (0 != this.accentColorOS) {
installButton.setBackgroundColor(this.accentColorOS)
}
installButton?.setOnClickListener {
installButton.setOnClickListener {
if (application?.fullData != null &&
application!!.fullData!!.getLastVersion() == null) {
Snackbar.make(view, activity.getString(
......@@ -112,9 +112,9 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
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()
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)
}
......@@ -154,7 +154,7 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
Execute({}, {
// installButton.setBackgroundResource(R.drawable.app_install_border_simple)
installButton?.text = activity.getString(state.installButtonTextId)
installButton.text = activity.getString(state.installButtonTextId)
when (state) {
......@@ -171,32 +171,32 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
State.INSTALLED -> {
installButton?.isEnabled =
installButton.isEnabled =
Common.appHasLaunchActivity(activity, application!!.packageName)
if (0 != this.accentColorOS) {
installButton!!.setBackgroundColor(this.accentColorOS)
installButton.setBackgroundColor(this.accentColorOS)
} else {
installButton!!.setBackgroundResource(R.drawable.app_install_border)
installButton.setBackgroundResource(R.drawable.app_install_border)
}
installButton.setTextColor(Color.parseColor("#FAFAFA"))
}
State.INSTALLING -> {
installButton?.isEnabled = false
installButton.isEnabled = false
}
State.NOT_UPDATED -> {
installButton.setTextColor(Color.parseColor("#FAFAFA"))
if (0 != this.accentColorOS) {
installButton!!.setBackgroundColor(this.accentColorOS)
installButton.setBackgroundColor(this.accentColorOS)
} else {
installButton!!.setBackgroundResource(R.drawable.app_install_border)
installButton.setBackgroundResource(R.drawable.app_install_border)
}
installButton?.isEnabled = true
installButton.isEnabled = true
}
else -> {
installButton.setTextColor(Color.parseColor("#0088ED"))
installButton?.isEnabled = true
installButton.isEnabled = true
}
}
......@@ -211,7 +211,7 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
@SuppressLint("SetTextI18n")
override fun notifyDownloadProgress(count: Int, total: Int) {
installButton.setGravity(Gravity.CENTER)
installButton?.text = ((toMiB(count) / toMiB(total)) * 100).toInt().toString() + "%"
installButton.text = ((toMiB(count) / toMiB(total)) * 100).toInt().toString() + "%"
installButton.setTextColor(Color.parseColor("#0088ED"))
installButton.setBackgroundResource(R.drawable.app_installing_border_simple)
}
......
......@@ -55,7 +55,7 @@ class ScreenshotsActivity : AppCompatActivity(), ApplicationManagerServiceConnec
val applicationPackageName: String? =
intent.getStringExtra(Constants.APPLICATION_PACKAGE_NAME_KEY)
if (!applicationPackageName.isNullOrEmpty()) {
this.applicationPackageName = applicationPackageName!!
this.applicationPackageName = applicationPackageName
applicationManagerServiceConnection.bindService(this)
}
}
......@@ -75,7 +75,7 @@ class ScreenshotsActivity : AppCompatActivity(), ApplicationManagerServiceConnec
screenshotsCarousel = screenshots_carousel
screenshotsCarousel.visibility = View.GONE
pwasBasicData!!.loadImagesAsyncly {
pwasBasicData.loadImagesAsyncly {
if (it.isNotEmpty()) {
screenshotsCarousel.adapter = ScreenshotsCarouselAdapter(this, it)
screenshotsCarousel.setCurrentItem(lastSelectedScreenshotIndex, false)
......@@ -100,7 +100,7 @@ class ScreenshotsActivity : AppCompatActivity(), ApplicationManagerServiceConnec
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (::screenshotsCarousel.isInitialized) {
outState?.putInt(last_selected_screenshot_key, screenshotsCarousel.currentItem)
outState.putInt(last_selected_screenshot_key, screenshotsCarousel.currentItem)
}
}
......
......@@ -290,7 +290,7 @@ class Application(val packageName: String, private val applicationManager: Appli
private fun findBasicData(context: Context): Error? {
var error: Error? = null
if (Common.isNetworkAvailable(context)) {
PackageNameSearchRequest(packageName!!).request { applicationError, searchResult ->
PackageNameSearchRequest(packageName).request { applicationError, searchResult ->
when (applicationError) {
null -> {
error = Error.NO_RESULTS
......
......@@ -60,7 +60,7 @@ class Downloader(private val applicationInfo: ApplicationInfo,
}
fun download(context: Context) {
if (fullData?.getLastVersion() != null) {
if (fullData.getLastVersion() != null) {
downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
registerReceivers(context)
initialiseDownloadManagerRequest(context)
......@@ -96,7 +96,7 @@ class Downloader(private val applicationInfo: ApplicationInfo,
request = DownloadManager.Request(
Uri.parse(
Constants.DOWNLOAD_URL + fullData?.getLastVersion()!!.downloadLink))
Constants.DOWNLOAD_URL + fullData.getLastVersion()!!.downloadLink))
.apply {
setTitle(fullData.basicData.name)
setDescription(context.getString(R.string.download_notification_description))
......@@ -158,7 +158,7 @@ class Downloader(private val applicationInfo: ApplicationInfo,
unregisterReceivers(context)
val status = getDownloadStatus()
if (status != null && status == DownloadManager.STATUS_SUCCESSFUL) {
fullData?.let {
fullData.let {
IntegrityVerificationTask(
applicationInfo,
it,
......
......@@ -74,7 +74,7 @@ constructor(
var latestVersion: Version? = null;
val packageName: String
get() = basicData.packageName!!
get() = basicData.packageName
fun getLastVersion(): Version? {
return if (basicData.latestDownloadableUpdate != "-1") {
......
......@@ -52,7 +52,7 @@ class GamesFragment() : Fragment() {
}
view.error_resolve.setTextColor(Color.parseColor("#ffffff"))
if (color != null) {
view.error_resolve.setBackgroundColor(color!!)
view.error_resolve.setBackgroundColor(color)
}
......
......@@ -174,7 +174,7 @@ class HomeFragment : Fragment() {
}
homeViewModel.getBannerApplications().value!!.forEach {
if(it.application!=null)
it.application!!.decrementUses()
it.application.decrementUses()
}
}
}
......
......@@ -48,7 +48,7 @@ class SearchModel : SearchModelInterface {
this.context = context
if (searchQuery.length >= Constants.MIN_SEARCH_TERM_LENGTH) {
if (Common.isNetworkAvailable(context)) {
SearchSuggestionsTask(searchQuery, applicationManager!!, this)
SearchSuggestionsTask(searchQuery, applicationManager, this)
.executeOnExecutor(Common.EXECUTOR, context)
}
} else {
......@@ -76,7 +76,7 @@ class SearchModel : SearchModelInterface {
override fun loadMore(context: Context) {
if (Common.isNetworkAvailable(context)) {
pageNumber++
SearchElement(searchQuery, pageNumber, applicationManager!!, this)
SearchElement(searchQuery, pageNumber, applicationManager, this)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, context)
} else {
screenError.value = Error.NO_INTERNET
......
......@@ -97,7 +97,7 @@ class OutdatedApplicationsFileReader(private val packageManager: PackageManager,
}
}
return if (gitlabData != null) {
gitlabData!!.getApplications(applicationManager!!, context)
gitlabData!!.getApplications(applicationManager, context)
} else {
emptyList()
}
......
......@@ -97,7 +97,7 @@ class OutdatedApplicationsFinder(private val packageManager: PackageManager,
}
}
return if (gitlabData != null) {
gitlabData!!.getApplications(applicationManager!!, context)
gitlabData!!.getApplications(applicationManager, context)
} else {
emptyList()
}
......
......@@ -15,7 +15,7 @@ class PreferenceStorage(val context: Context) {
editor.putString(KEY_NAME, text)
editor!!.commit()
editor.commit()
}
fun save(KEY_NAME: String, value: Int) {
......@@ -30,7 +30,7 @@ class PreferenceStorage(val context: Context) {
val editor: SharedPreferences.Editor = sharedPref.edit()
editor.putBoolean(KEY_NAME, status!!)
editor.putBoolean(KEY_NAME, status)
editor.commit()
}
......
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