Some changes (#1)

* Add copy zrif button

* Add zh-CN

* Update zh-CN

* Fix string

* Update zh-CN

* Downloading remove invalid characters

* Update zh-cn and sdk version

* Update dependencies

* Move namespace

* Support Asia game images

* Update README.md

* Restored

* Update README.md
This commit is contained in:
22
2023-02-14 05:17:14 +02:00
committed by GitHub
parent d71ca817ad
commit 764b1c7045
13 changed files with 188 additions and 118 deletions
+3 -3
View File
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.illusionware.npsbrowser">
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
@@ -15,7 +14,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/NPSTheme">
<activity android:name=".activities.SplashActivity" android:theme="@style/NPSTheme.Splash">
<activity android:name=".activities.SplashActivity" android:theme="@style/NPSTheme.Splash"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -41,17 +41,17 @@ data class AppData(
return result
}
override fun <T : Any?> isSameModelAs(model: T): Boolean {
override fun <T : Any> isSameModelAs(model: T): Boolean {
if (model is AppData) {
val other: AppData = model as AppData
val other: AppData = model
return "${other.titleID} ${other.title}" == "$titleID $title"
}
return false
}
override fun <T : Any?> isContentTheSameAs(model: T): Boolean {
override fun <T : Any> isContentTheSameAs(model: T): Boolean {
if (model is AppData) {
val other: AppData = model as AppData
val other: AppData = model
return title?.equals(other.title) ?: (other.title == null)
}
return false
@@ -6,11 +6,11 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.ListPreference
class ThemePreference : ListPreference {
constructor(context : Context?, attrs : AttributeSet?, defStyleAttr : Int) : super(context, attrs, defStyleAttr)
constructor(context : Context?, attrs : AttributeSet?, defStyleAttr : Int) : super(context!!, attrs, defStyleAttr)
constructor(context : Context?, attrs : AttributeSet?) : super(context, attrs)
constructor(context : Context?, attrs : AttributeSet?) : super(context!!, attrs)
constructor(context : Context?) : super(context)
constructor(context : Context?) : super(context!!)
override fun callChangeListener(newValue : Any?) : Boolean {
AppCompatDelegate.setDefaultNightMode(when ((newValue as String).toInt()) {
@@ -12,7 +12,7 @@ class SettingsFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PreferenceManager.setDefaultValues(context, R.xml.root_preferences, false);
PreferenceManager.setDefaultValues(requireContext(), R.xml.root_preferences, false)
activity?.supportFragmentManager
?.beginTransaction()
?.replace(
@@ -35,7 +35,7 @@ class SettingsFragment : Fragment() {
class PrefsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
PreferenceManager.setDefaultValues(context, R.xml.root_preferences, false);
PreferenceManager.setDefaultValues(requireContext(), R.xml.root_preferences, false)
}
}
@@ -42,7 +42,7 @@ class SingleAppFragment : Fragment() {
view?.findViewById<TextView>(R.id.singleAppTitle)?.text = "[${app.titleID}] ${app.title}"
if (app.fileSize != null) {
view?.findViewById<TextView>(R.id.singleAppSize)?.text = prettifySize()
view?.findViewById<TextView>(R.id.singleAppSize)?.text = prettifySize()
} else {
view?.findViewById<TextView>(R.id.singleAppSizeTitle)?.visibility = View.INVISIBLE
}
@@ -53,43 +53,46 @@ class SingleAppFragment : Fragment() {
view?.findViewById<TextView>(R.id.singleAppFwVerTitle)?.visibility = View.INVISIBLE
}
if (app.license == "MISSING") {
view?.findViewById<TextView>(R.id.singleAppError)?.text = "Warning: No license was provided for this app."
view?.findViewById<TextView>(R.id.singleAppError)?.text = getString(R.string.no_license)
view?.findViewById<Button>(R.id.singleAppCopyZRIFButton)?.isEnabled = false
}
if (app.link == "CART ONLY") {
view?.findViewById<TextView>(R.id.singleAppError)?.text = "CART ONLY GAME"
view?.findViewById<TextView>(R.id.singleAppError)?.text = getString(R.string.cart_only)
view?.findViewById<Button>(R.id.singleAppDownloadButton)?.isEnabled = false
view?.findViewById<Button>(R.id.singleAppCopyZRIFButton)?.isEnabled = false
} else if (app.link == "MISSING") {
view?.findViewById<TextView>(R.id.singleAppError)?.text = "Warning: No download link was provided for this app."
view?.findViewById<TextView>(R.id.singleAppError)?.text = getString(R.string.no_download_link)
view?.findViewById<Button>(R.id.singleAppDownloadButton)?.isEnabled = false
view?.findViewById<Button>(R.id.singleAppCopyZRIFButton)?.isEnabled = false
}
view?.findViewById<TextView>(R.id.singleAppContentId)?.setOnLongClickListener {
val clipboardManager = requireActivity().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(
"Content ID",
view?.findViewById<TextView>(R.id.singleAppContentId)?.text
view.findViewById<TextView>(R.id.singleAppContentId)?.text
)
clipboardManager.setPrimaryClip(clipData)
Toast.makeText(requireContext(), "Content ID Copied to Clipboard!", Toast.LENGTH_SHORT).show()
Toast.makeText(requireContext(), getString(R.string.content_id_copied), Toast.LENGTH_SHORT).show()
true
}
// click listener for the download button
view?.findViewById<Button>(R.id.singleAppDownloadButton)?.setOnClickListener {
try {
var request = DownloadManager.Request(Uri.parse(app.link))
val request = DownloadManager.Request(Uri.parse(app.link))
request.setTitle(app.title)
request.setDescription("Downloading...")
request.setDescription(getString(R.string.downloading))
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
app.title + ".pkg"
app.title!!.replace("[\\\\/:*?\"<>|]".toRegex(), " ") + ".pkg"
) // TODO: set up preference for this
downloadManager.enqueue(request)
} catch (e: Exception) {
Toast.makeText(
requireContext(),
"An error occurred while downloading. please try again",
getString(R.string.download_error),
Toast.LENGTH_SHORT
).show()
}
@@ -100,10 +103,18 @@ class SingleAppFragment : Fragment() {
val clipboardManager = requireActivity().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("PKG URL", app.link)
clipboardManager.setPrimaryClip(clipData)
Toast.makeText(requireContext(), "PKG URL Copied to Clipboard", Toast.LENGTH_SHORT).show()
Toast.makeText(requireContext(), getString(R.string.pkg_url_copied), Toast.LENGTH_SHORT).show()
true
}
// click listener for the copyzrifbutton button
view?.findViewById<Button>(R.id.singleAppCopyZRIFButton)?.setOnClickListener {
val clipboardManager = requireActivity().getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("zRIF", app.license)
clipboardManager.setPrimaryClip(clipData)
Toast.makeText(requireContext(),getString(R.string.zrif_copied),Toast.LENGTH_SHORT).show()
}
// set the height for the error text to 0 if there's no error so that the scrollview can take more space
if (view?.findViewById<TextView>(R.id.singleAppError)?.text.isNullOrEmpty()) {
view?.findViewById<TextView>(R.id.singleAppError)?.layoutParams?.height = 0
@@ -116,7 +127,7 @@ class SingleAppFragment : Fragment() {
circularProgressDrawable.centerRadius = 180f
circularProgressDrawable.start()
val image : ImageView? = view?.findViewById<ImageView>(R.id.singleAppIcon)
val image : ImageView? = view?.findViewById(R.id.singleAppIcon)
val iconURL = getImage(app.contentID!!)
if (iconURL != null) {
// TODO: make the options a requestOptions
@@ -137,7 +148,7 @@ class SingleAppFragment : Fragment() {
if (app.fileSize!!.toFloat() / 1024 > 1) {
return "%.1f KB".format(toKB(app.fileSize!!))
}
return "${app.fileSize!!} Bytes";
return "${app.fileSize!!} Bytes"
}
private fun toKB(size: Number): Number {
@@ -167,8 +178,12 @@ class SingleAppFragment : Fragment() {
return "$baseStoreURL/jp/ja/999/${contentID}/image"
}
"KP" -> {
// korean(?) games
// TODO: do this
// korean games
return "$baseStoreURL/kr/ko/999/${contentID}/image"
}
"HP" -> {
// asia games
return "$baseStoreURL/HK/zh/999/${contentID}/image"
}
}
return null
@@ -25,6 +25,8 @@ import com.illusionware.npsbrowser.fragments.SingleAppFragment
import com.illusionware.npsbrowser.adapters.AppAdapter
import com.illusionware.npsbrowser.fragments.SettingsFragment
import java.io.InputStream
import java.util.*
import kotlin.collections.ArrayList
class MainActivityFragment : Fragment() {
@@ -83,7 +85,7 @@ class MainActivityFragment : Fragment() {
recyclerView?.adapter = viewAdapter
val orientation = resources.configuration.orientation
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
val isViewAsList = prefs.getString("layout_type", "0")
if (isViewAsList == "0") {
viewAdapter?.toggleItemViewType(0)
@@ -165,7 +167,7 @@ class MainActivityFragment : Fragment() {
viewAdapter = AppAdapter(requireContext())
viewAdapter?.edit()?.add(apps!!)?.commit()
val orientation = this.resources.configuration.orientation
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
val isViewAsList = prefs.getString("layout_type", "0")
if (isViewAsList == "0") {
@@ -234,7 +236,7 @@ class MainActivityFragment : Fragment() {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
val orientation = newConfig.orientation
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
val isViewAsList = prefs.getString("layout_type", "0")
if (isViewAsList == "0") {
val pos = (recyclerView?.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
@@ -267,11 +269,11 @@ class MainActivityFragment : Fragment() {
}
private fun filter(models: List<AppData>, query: String): List<AppData>? {
val lowerCaseQuery = query.toLowerCase()
val lowerCaseQuery = query.lowercase(Locale.getDefault())
val filteredModelList: MutableList<AppData> = ArrayList()
for (model in models) {
val title: String = model.title?.toLowerCase()!!
val id: String = model.titleID?.toLowerCase()!!
val title: String = model.title?.lowercase(Locale.getDefault())!!
val id: String = model.titleID?.lowercase(Locale.getDefault())!!
if (title.contains(lowerCaseQuery) || id.contains(lowerCaseQuery)) {
filteredModelList.add(model)
}
+61 -47
View File
@@ -57,46 +57,59 @@
app:layout_constraintTop_toTopOf="parent"
tools:text="Game Title" />
<TextView
android:id="@+id/singleAppContentIdTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-black"
android:text="Content ID"
android:textAlignment="center"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppDownloadButton" />
<Button
android:id="@+id/singleAppDownloadButton"
android:layout_width="0dp"
android:layout_height="66dp"
android:layout_marginStart="48dp"
android:layout_marginTop="9dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="Download"
android:text="@string/download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppTitle" />
<Button
android:id="@+id/singleAppCopyZRIFButton"
android:layout_width="0dp"
android:layout_height="66dp"
android:layout_marginStart="48dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="48dp"
android:text="@string/copy_zrif"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppDownloadButton" />
<TextView
android:id="@+id/singleAppContentIdTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-black"
android:text="@string/content_id"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppCopyZRIFButton" />
<TextView
android:id="@+id/singleAppContentId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="11dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-light"
android:textAlignment="center"
android:textSize="24sp"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
@@ -109,62 +122,62 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-black"
android:text="Size"
android:text="@string/size"
android:textAlignment="center"
android:textSize="26sp"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppContentId" />
<TextView
android:id="@+id/singleAppSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-light"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppSizeTitle"
tools:text="Size" />
<TextView
android:id="@+id/singleAppFwVerTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="12dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-black"
android:text="MinFW"
android:text="@string/minfw"
android:textAlignment="center"
android:textSize="26sp"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppSize" />
<TextView
android:id="@+id/singleAppSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-light"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/singleAppSizeTitle"
tools:text="Size" />
<TextView
android:id="@+id/singleAppFwVer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:fontFamily="sans-serif-light"
android:textAlignment="center"
android:textSize="24sp"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
@@ -172,6 +185,7 @@
app:layout_constraintTop_toBottomOf="@+id/singleAppFwVerTitle"
tools:text="MinFW" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
@@ -191,7 +205,7 @@
android:layout_marginStart="100dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="100dp"
android:contentDescription="Single app icon"
android:contentDescription="@string/single_app_icon"
app:srcCompat="@drawable/ic_games_placeholder_24dp" />
</LinearLayout>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">NPS Browser</string>
<string name="title_activity_settings">设置</string>
<string name="search">搜索</string>
<string name="download">下载</string>
<string name="copy_zrif">复制 zRIF</string>
<string name="content_id">内容ID</string>
<string name="size">大小</string>
<string name="minfw">最低固件</string>
<string name="single_app_icon">应用图标</string>
<string name="no_license">注意:这个内容没有提供授权</string>
<string name="cart_only">这个游戏只有实体卡</string>
<string name="no_download_link">注意:这个内容没有提供下载链接</string>
<string name="download_error">下载过程中发生错误,请重试</string>
<string name="pkg_url_copied">PKG 地址已复制到剪贴板</string>
<string name="zrif_copied">zRIF 已复制到剪贴板</string>
<string name="downloading">下载中...</string>
<string name="content_id_copied">内容ID 已复制到剪贴板</string>
</resources>
+14
View File
@@ -2,4 +2,18 @@
<string name="app_name">NPS Browser</string>
<string name="title_activity_settings">Settings</string>
<string name="search">Search</string>
<string name="download">Download</string>
<string name="copy_zrif">Copy zRIF</string>
<string name="content_id">Content ID</string>
<string name="size">Size</string>
<string name="minfw">MinFW</string>
<string name="single_app_icon">Single app icon</string>
<string name="no_license">Warning: No license was provided for this content.</string>
<string name="cart_only">CART ONLY GAME</string>
<string name="no_download_link">Warning: No download link was provided for this content.</string>
<string name="downloading">Downloading...</string>
<string name="download_error">An error occurred while downloading. please try again</string>
<string name="pkg_url_copied">PKG URL Copied to Clipboard</string>
<string name="zrif_copied">zRIF Copied to Clipboard</string>
<string name="content_id_copied">Content ID Copied to Clipboard</string>
</resources>