mirror of
https://github.com/IllusionMan1212/NPS-Browser.git
synced 2026-10-24 02:12:37 +00:00
Add dark and light theme with corresponding settings activity and BaseActivity class
This commit is contained in:
@@ -56,6 +56,9 @@ dependencies {
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'com.github.doyaaaaaken:kotlin-csv-jvm:0.7.3'
|
||||
implementation "androidx.cardview:cardview:1.0.0"
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.0-rc01'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
@@ -20,9 +20,10 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activities.SingleAppActivity" android:screenOrientation="portrait"
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/title_activity_settings"
|
||||
android:parentActivityName=".activities.MainActivity"/>
|
||||
<activity android:name=".activities.AppsListActivity" />
|
||||
<activity
|
||||
android:name=".activities.SingleAppActivity"
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.illusionware.npsbrowser
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
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?) : super(context, attrs)
|
||||
|
||||
constructor(context : Context?) : super(context)
|
||||
|
||||
override fun callChangeListener(newValue : Any?) : Boolean {
|
||||
AppCompatDelegate.setDefaultNightMode(when ((newValue as String).toInt()) {
|
||||
0 -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
1 -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
2 -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
else -> AppCompatDelegate.MODE_NIGHT_UNSPECIFIED
|
||||
})
|
||||
|
||||
return super.callChangeListener(newValue)
|
||||
}
|
||||
|
||||
override fun setValue(value: String?) {
|
||||
super.setValue(value)
|
||||
summary = value
|
||||
}
|
||||
|
||||
override fun setSummary(summary: CharSequence?) {
|
||||
super.setSummary(entry)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.illusionware.npsbrowser.AppData
|
||||
@@ -12,7 +11,7 @@ import com.illusionware.npsbrowser.RecyclerTouchListener
|
||||
import com.illusionware.npsbrowser.adapters.AppAdapter
|
||||
import com.illusionware.npsbrowser.databinding.ActivityAppsListBinding
|
||||
|
||||
class AppsListActivity : AppCompatActivity() {
|
||||
class AppsListActivity : BaseActivity() {
|
||||
companion object {
|
||||
lateinit var apps : ArrayList<AppData>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.illusionware.npsbrowser.activities
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.illusionware.npsbrowser.R
|
||||
|
||||
open class BaseActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var sharedPreferences : SharedPreferences
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
PreferenceManager.setDefaultValues(this, R.xml.root_preferences, false)
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val decor: View = window.decorView
|
||||
|
||||
AppCompatDelegate.setDefaultNightMode(when ((sharedPreferences.getString("app_theme", "2")?.toInt())) {
|
||||
0 -> {
|
||||
decor.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
|
||||
AppCompatDelegate.MODE_NIGHT_NO
|
||||
}
|
||||
1 -> {
|
||||
decor.systemUiVisibility = 0;
|
||||
AppCompatDelegate.MODE_NIGHT_YES
|
||||
}
|
||||
2 -> {
|
||||
decor.systemUiVisibility = if (resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
else -> AppCompatDelegate.MODE_NIGHT_UNSPECIFIED
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import com.illusionware.npsbrowser.databinding.ActivityMainBinding
|
||||
import kotlinx.android.synthetic.main.appbar.*
|
||||
import java.io.InputStream
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
class MainActivity : BaseActivity() {
|
||||
|
||||
private val tsvReader = csvReader {
|
||||
charset = "UTF-8"
|
||||
@@ -52,6 +52,8 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.action_settings -> {
|
||||
val settingsIntent = Intent(this, SettingsActivity::class.java)
|
||||
startActivity(settingsIntent)
|
||||
true
|
||||
}
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
@@ -65,7 +67,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val inputStream: InputStream? = contentResolver.openInputStream(uri)
|
||||
val entries : List<Map<String, String?>> = tsvReader.readAllWithHeader(inputStream!!)
|
||||
val myIntent = Intent(this, AppsListActivity::class.java)
|
||||
var apps = ArrayList<AppData>(entries.size)
|
||||
val apps = ArrayList<AppData>(entries.size)
|
||||
|
||||
entries.forEach { entry ->
|
||||
if (entry["Name"].isNullOrEmpty()) {
|
||||
@@ -81,7 +83,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val fileSize = entry["File Size"]?.toLongOrNull()
|
||||
val sha256 = entry["SHA256"]
|
||||
val minFW = entry["Required FW"]
|
||||
var app = AppData(id, region, name, link ?: "MISSING", license ?: "MISSING",
|
||||
val app = AppData(id, region, name, link ?: "MISSING", license ?: "MISSING",
|
||||
contentID ?: "MISSING", lastDateTime ?: "MISSING",
|
||||
fileSize ?: 0, sha256 ?: "MISSING", minFW)
|
||||
apps.add(app)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.illusionware.npsbrowser.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.illusionware.npsbrowser.R
|
||||
import com.illusionware.npsbrowser.databinding.SettingsActivityBinding
|
||||
import kotlinx.android.synthetic.main.appbar.*
|
||||
|
||||
class SettingsActivity : BaseActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val binding = SettingsActivityBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
supportFragmentManager
|
||||
.beginTransaction()
|
||||
.replace(
|
||||
R.id.settings,
|
||||
SettingsFragment()
|
||||
)
|
||||
.commit()
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
}
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||
PreferenceManager.setDefaultValues(context, R.xml.root_preferences, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.illusionware.npsbrowser.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.illusionware.npsbrowser.AppData
|
||||
import com.illusionware.npsbrowser.databinding.ActivitySingleAppBinding
|
||||
|
||||
class SingleAppActivity: AppCompatActivity() {
|
||||
class SingleAppActivity: BaseActivity() {
|
||||
companion object {
|
||||
lateinit var app : AppData
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:text="gameTitle"
|
||||
android:textAlignment="center"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
@@ -30,7 +29,6 @@
|
||||
android:layout_marginTop="56dp"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:fontFamily="sans-serif-smallcaps"
|
||||
android:text="titleID"
|
||||
android:textAlignment="center"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
@@ -53,7 +51,7 @@
|
||||
android:layout_marginStart="140dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginEnd="141dp"
|
||||
android:contentDescription="Game Icon"
|
||||
android:contentDescription="game Icon"
|
||||
app:srcCompat="@drawable/ic_games_black_24dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
android:paddingEnd="4dp"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="US"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/colorOnSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@@ -54,7 +53,6 @@
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:scrollHorizontally="true"
|
||||
android:singleLine="true"
|
||||
android:text="Placeholder"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:textColor="@color/colorOnPrimary"
|
||||
@@ -67,6 +65,7 @@
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="62dp"
|
||||
android:layout_height="56dp"
|
||||
android:contentDescription="game icon"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
@@ -79,7 +78,6 @@
|
||||
android:layout_marginStart="8dp"
|
||||
android:background="@drawable/rect_red"
|
||||
android:padding="4dp"
|
||||
android:text="3.60"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/colorOnSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
@@ -90,7 +88,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4dp"
|
||||
android:text="2020-5-5"
|
||||
android:textColor="@color/colorOnSecondary"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/appbar" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
@@ -4,7 +4,7 @@
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:title="@string/title_activity_settings"
|
||||
app:iconTint="?attr/colorOnPrimary"
|
||||
android:title="settings"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="app_theme">
|
||||
<item>Light</item>
|
||||
<item>Dark</item>
|
||||
<item>Use System Default</item>
|
||||
</string-array>
|
||||
<string-array name="app_theme_val">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -1,3 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">NPS Browser</string>
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<PreferenceCategory android:title="Customization">
|
||||
|
||||
<com.illusionware.npsbrowser.ThemePreference
|
||||
android:defaultValue="2"
|
||||
android:entries="@array/app_theme"
|
||||
android:entryValues="@array/app_theme_val"
|
||||
android:key="app_theme"
|
||||
android:title="Theme" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user