Browse Source

theme selection & gradle update

* it's now possible to change the app theme (light/dark)
* update gradle to version 6.7.1
* update gradle pugin to version 4.1.1
* update kotlin to  1.4.10
pull/18/head
Jannik 3 months ago
parent
commit
21b6e358e7
Signed by: Seil0 GPG Key ID: E8459F3723C52C24
15 changed files with 230 additions and 60 deletions
  1. +1
    -1
      app/build.gradle
  2. +45
    -14
      app/src/main/java/org/mosad/teapod/MainActivity.kt
  3. +25
    -13
      app/src/main/java/org/mosad/teapod/preferences/Preferences.kt
  4. +37
    -5
      app/src/main/java/org/mosad/teapod/ui/fragments/AccountFragment.kt
  5. +5
    -0
      app/src/main/java/org/mosad/teapod/util/DataTypes.kt
  6. +5
    -0
      app/src/main/res/drawable/ic_baseline_style_24.xml
  7. +44
    -0
      app/src/main/res/layout/fragment_account.xml
  8. +3
    -0
      app/src/main/res/values-de-rDE/strings.xml
  9. +5
    -0
      app/src/main/res/values/strings.xml
  10. +3
    -2
      app/src/main/res/values/styles.xml
  11. +2
    -2
      build.gradle
  12. BIN
      gradle/wrapper/gradle-wrapper.jar
  13. +1
    -2
      gradle/wrapper/gradle-wrapper.properties
  14. +33
    -20
      gradlew
  15. +21
    -1
      gradlew.bat

+ 1
- 1
app/build.gradle View File

@ -11,7 +11,7 @@ android {
minSdkVersion 23
targetSdkVersion 30
versionCode 1000 //00.01.000
versionName "0.2.0-beta1"
versionName "0.2.0-beta2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue "string", "build_time", buildTime()


+ 45
- 14
app/src/main/java/org/mosad/teapod/MainActivity.kt View File

@ -38,6 +38,7 @@ import org.mosad.teapod.preferences.EncryptedPreferences
import org.mosad.teapod.preferences.Preferences
import org.mosad.teapod.ui.components.LoginDialog
import org.mosad.teapod.ui.fragments.*
import org.mosad.teapod.util.DataTypes
import org.mosad.teapod.util.StorageController
import org.mosad.teapod.util.TMDBApiController
import kotlin.system.measureTimeMillis
@ -46,13 +47,22 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
private var activeBaseFragment: Fragment = HomeFragment() // the currently active fragment, home at the start
companion object {
var wasInitialized = false
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (!wasInitialized) {
load()
}
theme.applyStyle(getThemeResource(), true)
setContentView(R.layout.activity_main)
nav_view.setOnNavigationItemSelectedListener(this)
load()
supportFragmentManager.commit {
replace(R.id.nav_host_fragment, activeBaseFragment, activeBaseFragment.javaClass.simpleName)
}
@ -102,6 +112,13 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
return ret
}
private fun getThemeResource(): Int {
return when (Preferences.theme) {
DataTypes.Theme.DARK -> R.style.AppTheme_Dark
else -> R.style.AppTheme_Light
}
}
private fun load() {
// running login and list in parallel does not bring any speed improvements
val time = measureTimeMillis {
@ -118,10 +135,26 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
StorageController.load(this)
AoDParser.initialLoading()
wasInitialized = true
}
Log.i(javaClass.name, "login and list in $time ms")
}
private fun showLoginDialog(firstTry: Boolean) {
LoginDialog(this, firstTry).positiveButton {
EncryptedPreferences.saveCredentials(login, password, context)
if (!AoDParser.login()) {
showLoginDialog(false)
Log.w(javaClass.name, "Login failed, please try again.")
}
}.negativeButton {
Log.i(javaClass.name, "Login canceled, exiting.")
finish()
}.show()
}
/**
* Show the media fragment for the selected media.
* While loading show the loading fragment.
@ -159,17 +192,15 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
startActivity(intent)
}
private fun showLoginDialog(firstTry: Boolean) {
LoginDialog(this, firstTry).positiveButton {
EncryptedPreferences.saveCredentials(login, password, context)
if (!AoDParser.login()) {
showLoginDialog(false)
Log.w(javaClass.name, "Login failed, please try again.")
}
}.negativeButton {
Log.i(javaClass.name, "Login canceled, exiting.")
finish()
}.show()
/**
* use custom restart instead of recreate(), since it has animations
*/
fun restart() {
val restartIntent = intent
restartIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
finish()
startActivity(restartIntent)
}
}

+ 25
- 13
app/src/main/java/org/mosad/teapod/preferences/Preferences.kt View File

@ -1,7 +1,9 @@
package org.mosad.teapod.preferences
import android.content.Context
import android.content.SharedPreferences
import org.mosad.teapod.R
import org.mosad.teapod.util.DataTypes
object Preferences {
@ -9,14 +11,18 @@ object Preferences {
internal set
var autoplay = true
internal set
var theme = DataTypes.Theme.LIGHT
internal set
fun savePreferSecondary(context: Context, preferSecondary: Boolean) {
val sharedPref = context.getSharedPreferences(
private fun getSharedPref(context: Context): SharedPreferences {
return context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
}
with(sharedPref.edit()) {
fun savePreferSecondary(context: Context, preferSecondary: Boolean) {
with(getSharedPref(context).edit()) {
putBoolean(context.getString(R.string.save_key_prefer_secondary), preferSecondary)
apply()
}
@ -25,12 +31,7 @@ object Preferences {
}
fun saveAutoplay(context: Context, autoplay: Boolean) {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
with(sharedPref.edit()) {
with(getSharedPref(context).edit()) {
putBoolean(context.getString(R.string.save_key_autoplay), autoplay)
apply()
}
@ -38,14 +39,20 @@ object Preferences {
this.autoplay = autoplay
}
fun saveTheme(context: Context, theme: DataTypes.Theme) {
with(getSharedPref(context).edit()) {
putString(context.getString(R.string.save_key_theme), theme.toString())
apply()
}
this.theme = theme
}
/**
* initially load the stored values
*/
fun load(context: Context) {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
val sharedPref = getSharedPref(context)
preferSecondary = sharedPref.getBoolean(
context.getString(R.string.save_key_prefer_secondary), false
@ -53,6 +60,11 @@ object Preferences {
autoplay = sharedPref.getBoolean(
context.getString(R.string.save_key_autoplay), true
)
theme = DataTypes.Theme.valueOf(
sharedPref.getString(
context.getString(R.string.save_key_theme), DataTypes.Theme.LIGHT.toString()
) ?: DataTypes.Theme.LIGHT.toString()
)
}

+ 37
- 5
app/src/main/java/org/mosad/teapod/ui/fragments/AccountFragment.kt View File

@ -7,17 +7,21 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import de.psdev.licensesdialog.LicensesDialog
import kotlinx.android.synthetic.main.fragment_account.*
import org.mosad.teapod.BuildConfig
import org.mosad.teapod.MainActivity
import org.mosad.teapod.R
import org.mosad.teapod.parser.AoDParser
import org.mosad.teapod.preferences.EncryptedPreferences
import org.mosad.teapod.preferences.Preferences
import org.mosad.teapod.ui.components.LoginDialog
import org.mosad.teapod.util.DataTypes.Theme
class AccountFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_account, container, false)
}
@ -27,6 +31,11 @@ class AccountFragment : Fragment() {
text_account_login.text = EncryptedPreferences.login
text_info_about_desc.text = getString(R.string.info_about_desc, BuildConfig.VERSION_NAME, getString(R.string.build_time))
text_theme_selected.text = when (Preferences.theme) {
Theme.DARK -> getString(R.string.theme_dark)
else -> getString(R.string.theme_light)
}
switch_secondary.isChecked = Preferences.preferSecondary
switch_autoplay.isChecked = Preferences.autoplay
@ -38,6 +47,10 @@ class AccountFragment : Fragment() {
showLoginDialog(true)
}
linear_theme.setOnClickListener {
showThemeDialog()
}
linear_about.setOnClickListener {
MaterialDialog(requireContext())
.title(R.string.info_about)
@ -46,15 +59,14 @@ class AccountFragment : Fragment() {
}
text_licenses.setOnClickListener {
val selectedTheme = requireContext().applicationInfo.theme
val dialogCss = when (selectedTheme) {
R.style.AppTheme_Dark -> R.string.license_dialog_style_dark
val dialogCss = when (Preferences.theme) {
Theme.DARK -> R.string.license_dialog_style_dark
else -> R.string.license_dialog_style_light
}
val themeId = when (selectedTheme) {
R.style.AppTheme_Dark -> R.style.LicensesDialogTheme_Dark
val themeId = when (Preferences.theme) {
Theme.DARK -> R.style.LicensesDialogTheme_Dark
else -> R.style.AppTheme_Light
}
@ -90,4 +102,24 @@ class AccountFragment : Fragment() {
password = ""
}
}
private fun showThemeDialog() {
val themes = listOf(
resources.getString(R.string.theme_light),
resources.getString(R.string.theme_dark)
)
MaterialDialog(requireContext()).show {
title(R.string.theme)
listItemsSingleChoice(items = themes, initialSelection = Preferences.theme.ordinal) { _, index, _ ->
when(index) {
0 -> Preferences.saveTheme(context, Theme.LIGHT)
1 -> Preferences.saveTheme(context, Theme.DARK)
else -> Preferences.saveTheme(context, Theme.LIGHT)
}
(activity as MainActivity).restart()
}
}
}
}

+ 5
- 0
app/src/main/java/org/mosad/teapod/util/DataTypes.kt View File

@ -6,6 +6,11 @@ class DataTypes {
MOVIE,
TVSHOW
}
enum class Theme(val str: String) {
LIGHT("Light"),
DARK("Dark")
}
}
/**


+ 5
- 0
app/src/main/res/drawable/ic_baseline_style_24.xml View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M2.53,19.65l1.34,0.56v-9.03l-2.43,5.86c-0.41,1.02 0.08,2.19 1.09,2.61zM22.03,15.95L17.07,3.98c-0.31,-0.75 -1.04,-1.21 -1.81,-1.23 -0.26,0 -0.53,0.04 -0.79,0.15L7.1,5.95c-0.75,0.31 -1.21,1.03 -1.23,1.8 -0.01,0.27 0.04,0.54 0.15,0.8l4.96,11.97c0.31,0.76 1.05,1.22 1.83,1.23 0.26,0 0.52,-0.05 0.77,-0.15l7.36,-3.05c1.02,-0.42 1.51,-1.59 1.09,-2.6zM7.88,8.75c-0.55,0 -1,-0.45 -1,-1s0.45,-1 1,-1 1,0.45 1,1 -0.45,1 -1,1zM5.88,19.75c0,1.1 0.9,2 2,2h1.45l-3.45,-8.34v6.34z"/>
</vector>

+ 44
- 0
app/src/main/res/layout/fragment_account.xml View File

@ -222,6 +222,50 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/linear_theme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="7dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageViewTheme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/account"
android:minWidth="48dp"
android:minHeight="48dp"
android:padding="9dp"
android:scaleType="fitXY"
android:src="@drawable/ic_baseline_style_24"
app:tint="?iconNoAction" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text_theme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/theme"
android:textSize="16sp" />
<TextView
android:id="@+id/text_theme_selected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/theme_light"
android:textColor="?textSecondary" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout


+ 3
- 0
app/src/main/res/values-de-rDE/strings.xml View File

@ -31,6 +31,9 @@
<string name="settings_secondary_desc">Untertitle-Stream verwenden, sofern vorhanden</string>
<string name="settings_autoplay">Autoplay</string>
<string name="settings_autoplay_desc">Nächste Episode automatisch abspielen</string>
<string name="theme">Design</string>
<string name="theme_light">Hell</string>
<string name="theme_dark">Dunkel</string>
<!-- player -->
<string name="close_player">Player schließen</string>


+ 5
- 0
app/src/main/res/values/strings.xml View File

@ -40,6 +40,10 @@
<string name="settings_secondary_desc">Use the subtitles stream if present</string>
<string name="settings_autoplay">Autoplay</string>
<string name="settings_autoplay_desc">Play next episode automatically</string>
<string name="theme">Theme</string>
<string name="theme_light">Light</string>
<string name="theme_dark">Dark</string>
<!-- player -->
<string name="close_player">close player</string>
@ -69,6 +73,7 @@
<string name="save_key_user_password" translatable="false">org.mosad.teapod.user_password</string>
<string name="save_key_prefer_secondary" translatable="false">org.mosad.teapod.prefer_secondary</string>
<string name="save_key_autoplay" translatable="false">org.mosad.teapod.autoplay</string>
<string name="save_key_theme" translatable="false">org.mosad.teapod.theme</string>
<!-- intents & states -->
<string name="intent_media_id" translatable="false">intent_media_id</string>


+ 3
- 2
app/src/main/res/values/styles.xml View File

@ -18,7 +18,6 @@
<item name="iconNoAction">@color/iconNoActionLight</item>
<item name="buttonBackground">@color/buttonBackgroundLight</item>
<item name="md_background_color">@color/themeSecondaryLight</item>
<item name="md_color_title">@color/textPrimaryLight</item>
<item name="md_color_content">@color/textSecondaryLight</item>
</style>
@ -34,8 +33,10 @@
<item name="iconNoAction">@color/iconNoActionDark</item>
<item name="buttonBackground">@color/buttonBackgroundDark</item>
<item name="md_background_color">@color/themeSecondaryDark</item>
<item name="md_color_title">@color/textPrimaryDark</item>
<item name="md_color_content">@color/textSecondaryDark</item>
<!-- without this, the unchecked single choice buttons while be black -->
<item name="md_color_widget_unchecked">@color/textSecondaryDark</item>
</style>
<style name="LicensesDialogTheme.Dark" parent="Theme.AppCompat.Dialog">


+ 2
- 2
build.gradle View File

@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.10"
ext.kotlin_version = "1.4.20"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong


BIN
gradle/wrapper/gradle-wrapper.jar View File


+ 1
- 2
gradle/wrapper/gradle-wrapper.properties View File

@ -1,6 +1,5 @@
#Tue Oct 13 12:04:29 CEST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

+ 33
- 20
gradlew View File

@ -1,5 +1,21 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
@ -66,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -109,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
@ -138,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
@ -159,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

+ 21
- 1
gradlew.bat View File

@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@ -65,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%


Loading…
Cancel
Save