mirror of
https://github.com/IllusionMan1212/NPS-Browser.git
synced 2026-10-24 18:12:38 +00:00
Change singleapp to fragment, put toolbar in activity, add search bar
This commit is contained in:
@@ -2,18 +2,26 @@ package com.illusionware.npsbrowser.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.illusionware.npsbrowser.R
|
||||
import com.illusionware.npsbrowser.fragments.mainactivity.MainActivityFragment
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setTheme(R.style.NPSTheme)
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
supportFragmentManager.addOnBackStackChangedListener(this);
|
||||
|
||||
if (supportFragmentManager.backStackEntryCount > 0) {
|
||||
showUpButton()
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
supportFragmentManager.beginTransaction()
|
||||
.replace(R.id.container, MainActivityFragment.newInstance())
|
||||
.replace(R.id.container, MainActivityFragment())
|
||||
.commitNow()
|
||||
}
|
||||
}
|
||||
@@ -28,12 +36,20 @@ class MainActivity : BaseActivity() {
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
fun showUpButton() {
|
||||
override fun onBackStackChanged() {
|
||||
// enable Up button only if there are entries on the backstack
|
||||
if (supportFragmentManager.backStackEntryCount < 1) {
|
||||
hideUpButton()
|
||||
} else {
|
||||
showUpButton()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showUpButton() {
|
||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
||||
fun hideUpButton() {
|
||||
private fun hideUpButton() {
|
||||
supportActionBar!!.setDisplayHomeAsUpEnabled(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package com.illusionware.npsbrowser.activities
|
||||
|
||||
import android.app.DownloadManager
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import com.illusionware.npsbrowser.AppData
|
||||
import com.illusionware.npsbrowser.databinding.ActivitySingleAppBinding
|
||||
import java.lang.Exception
|
||||
|
||||
class SingleAppActivity: BaseActivity() {
|
||||
companion object {
|
||||
lateinit var app : AppData
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val binding = ActivitySingleAppBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
var downloadManager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
|
||||
|
||||
binding.singleAppTitle.text = "[${app.titleID}] ${app.title}"
|
||||
if (app.fileSize != null) {
|
||||
binding.singleAppSize.text = prettifySize()
|
||||
} else {
|
||||
binding.singleAppSizeTitle.visibility = View.INVISIBLE
|
||||
}
|
||||
binding.singleAppContentId.text = app.contentID
|
||||
binding.singleAppFwVer.text = app.minFW
|
||||
// TODO: get and set app icon
|
||||
if (app.minFW.isNullOrBlank()) {
|
||||
binding.singleAppFwVerTitle.visibility = View.INVISIBLE
|
||||
}
|
||||
if (app.license == "MISSING") {
|
||||
binding.singleAppError.text = "Warning: No license was provided for this app."
|
||||
}
|
||||
if (app.link == "CART ONLY") {
|
||||
binding.singleAppError.text = "CART ONLY GAME"
|
||||
binding.singleAppDownloadButton.isEnabled = false
|
||||
} else if (app.link == "MISSING") {
|
||||
binding.singleAppError.text = "Warning: No download link was provided for this app."
|
||||
binding.singleAppDownloadButton.isEnabled = false
|
||||
}
|
||||
|
||||
binding.singleAppContentId.setOnLongClickListener {
|
||||
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipData = ClipData.newPlainText("Content ID", binding.singleAppContentId.text)
|
||||
clipboardManager.setPrimaryClip(clipData)
|
||||
Toast.makeText(this, "Content ID Copied to Clipboard!", Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
binding.singleAppDownloadButton.setOnClickListener {
|
||||
try {
|
||||
var request = DownloadManager.Request(Uri.parse(app.link))
|
||||
request.setTitle(app.title)
|
||||
request.setDescription("Downloading...")
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, app.title + ".pkg") // TODO: set up preference for this
|
||||
downloadManager.enqueue(request)
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(this, "An error occurred while downloading. please try again", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
binding.singleAppDownloadButton.setOnLongClickListener {
|
||||
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipData = ClipData.newPlainText("PKG URL", app.link)
|
||||
clipboardManager.setPrimaryClip(clipData)
|
||||
Toast.makeText(this, "PKG URL Copied to Clipboard", Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun prettifySize(): String {
|
||||
if (app.fileSize!!.toFloat() / (1024 * 1024 * 1024) > 1) {
|
||||
return "%.1f GB".format(toGB(app.fileSize!!))
|
||||
}
|
||||
if (app.fileSize!!.toFloat() / (1024 * 1024) > 1) {
|
||||
return "%.1f MB".format(toMB(app.fileSize!!))
|
||||
}
|
||||
if (app.fileSize!!.toFloat() / 1024 > 1) {
|
||||
return "%.1f KB".format(toKB(app.fileSize!!))
|
||||
}
|
||||
return "${app.fileSize!!} Bytes";
|
||||
}
|
||||
|
||||
private fun toKB(size: Number): Number {
|
||||
return size.toFloat() / 1024
|
||||
}
|
||||
|
||||
private fun toMB(size: Number): Number {
|
||||
return size.toFloat() / (1024 * 1024)
|
||||
}
|
||||
|
||||
private fun toGB(size: Number): Number {
|
||||
return size.toFloat() / (1024 * 1024 * 1024)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user