diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0c0c338..16c2bbc 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -2,6 +2,9 @@ + + + diff --git a/app/build.gradle b/app/build.gradle index 8b9928d..2972e05 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "de.msdevs.einschlafhilfe" minSdkVersion 26 targetSdkVersion 33 - versionCode 46 - versionName "4.2" + versionCode 48 + versionName "4.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/build/generated/source/buildConfig/debug/de/msdevs/einschlafhilfe/BuildConfig.java b/app/build/generated/source/buildConfig/debug/de/msdevs/einschlafhilfe/BuildConfig.java index ee0cd00..32dac81 100644 --- a/app/build/generated/source/buildConfig/debug/de/msdevs/einschlafhilfe/BuildConfig.java +++ b/app/build/generated/source/buildConfig/debug/de/msdevs/einschlafhilfe/BuildConfig.java @@ -7,6 +7,6 @@ public final class BuildConfig { public static final boolean DEBUG = Boolean.parseBoolean("true"); public static final String APPLICATION_ID = "de.msdevs.einschlafhilfe"; public static final String BUILD_TYPE = "debug"; - public static final int VERSION_CODE = 46; - public static final String VERSION_NAME = "4.2"; + public static final int VERSION_CODE = 48; + public static final String VERSION_NAME = "4.3"; } diff --git a/app/release/app-release.aab b/app/release/app-release.aab index 199d0fa..3217aa9 100644 Binary files a/app/release/app-release.aab and b/app/release/app-release.aab differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9bbc2d7..5d5a584 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -42,7 +42,6 @@ android:label="@string/about" /> - diff --git a/app/src/main/java/de/msdevs/einschlafhilfe/AboutActivity.kt b/app/src/main/java/de/msdevs/einschlafhilfe/AboutActivity.kt index bdd7d61..0b91b15 100644 --- a/app/src/main/java/de/msdevs/einschlafhilfe/AboutActivity.kt +++ b/app/src/main/java/de/msdevs/einschlafhilfe/AboutActivity.kt @@ -4,12 +4,11 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.widget.Button -import androidx.appcompat.app.AppCompatActivity import de.msdevs.einschlafhilfe.databinding.ActivityAboutBinding import net.cachapa.expandablelayout.ExpandableLayout -class AboutActivity : AppCompatActivity() { +class AboutActivity : BaseActivity() { private lateinit var binding : ActivityAboutBinding private lateinit var btnPrivacy : Button @@ -75,7 +74,7 @@ class AboutActivity : AppCompatActivity() { btnAppIntro.setOnClickListener{ opennUrl("https://github.com/AppIntro/AppIntro") } - btnGlide.setOnClickListener { + btnContact.setOnClickListener { val intent = Intent(Intent.ACTION_SENDTO) intent.setData(Uri.parse("mailto:")) intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("stelter.developer@gmail.com")) diff --git a/app/src/main/java/de/msdevs/einschlafhilfe/BaseActivity.kt b/app/src/main/java/de/msdevs/einschlafhilfe/BaseActivity.kt new file mode 100644 index 0000000..199f6af --- /dev/null +++ b/app/src/main/java/de/msdevs/einschlafhilfe/BaseActivity.kt @@ -0,0 +1,39 @@ +package de.msdevs.einschlafhilfe + + +import android.os.Bundle +import android.view.WindowManager +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import de.msdevs.einschlafhilfe.utils.Utility.getTheme + + +open class BaseActivity : AppCompatActivity() { + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + updateTheme() + } + + fun updateTheme() { + if (getTheme(applicationContext) <= THEME_RED) { + setTheme(R.style.AppTheme) + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + window.statusBarColor = resources.getColor(R.color.colorPrimary) + } else if (getTheme(applicationContext) == THEME_BLUE) { + setTheme(R.style.AppThemeBlue) + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + window.statusBarColor = resources.getColor(R.color.colorPrimaryBlue) + } else if (getTheme(applicationContext) == THEME_WHITE) { + setTheme(R.style.AppThemeWhite) + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) + window.statusBarColor = resources.getColor(R.color.white) + + } + } + + companion object { + private const val THEME_WHITE = 4 + private const val THEME_RED = 2 + private const val THEME_BLUE = 3 + } +} \ No newline at end of file diff --git a/app/src/main/java/de/msdevs/einschlafhilfe/MainActivity.kt b/app/src/main/java/de/msdevs/einschlafhilfe/MainActivity.kt index 3167b80..c2b116f 100644 --- a/app/src/main/java/de/msdevs/einschlafhilfe/MainActivity.kt +++ b/app/src/main/java/de/msdevs/einschlafhilfe/MainActivity.kt @@ -1,10 +1,12 @@ package de.msdevs.einschlafhilfe -import android.annotation.SuppressLint + + import android.content.DialogInterface import android.content.Intent import android.content.SharedPreferences import android.content.pm.PackageManager +import android.graphics.PorterDuff import android.net.ConnectivityManager import android.net.Uri import android.os.Bundle @@ -12,14 +14,13 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.Toast -import androidx.appcompat.app.AlertDialog -import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import de.msdevs.einschlafhilfe.databinding.ActivityMainBinding +import de.msdevs.einschlafhilfe.utils.Utility import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -31,7 +32,7 @@ import java.io.BufferedReader import java.io.IOException -class MainActivity : AppCompatActivity() { +class MainActivity : BaseActivity() { //Extends Base Activity private lateinit var binding: ActivityMainBinding private var urlExtraParameter = "folgen.json" @@ -40,7 +41,9 @@ class MainActivity : AppCompatActivity() { private lateinit var sharedPreferences: SharedPreferences private lateinit var sharedPreferencesEditor: SharedPreferences.Editor private lateinit var folgenListe : String + private var selectedTheme : Int = 0 var random : Int = 0 + /* Copyright 2017 - 2023 by Marvin Stelter */ @@ -52,6 +55,8 @@ class MainActivity : AppCompatActivity() { sharedPreferences = getSharedPreferences(packageName,0) sharedPreferencesEditor = sharedPreferences.edit() + + if(sharedPreferences.getInt("first",0) == 0){ sharedPreferencesEditor.putBoolean("update_list", true) sharedPreferencesEditor.putBoolean("spotify", false) @@ -120,7 +125,12 @@ class MainActivity : AppCompatActivity() { refresh() } binding.fabDescription.setOnClickListener { - val alert = MaterialAlertDialogBuilder(this, R.style.DialogTheme) + var alert : MaterialAlertDialogBuilder + if(Utility.getTheme(this) == 4){ + alert = MaterialAlertDialogBuilder(this, R.style.DialogThemeWhite) + }else{ + alert = MaterialAlertDialogBuilder(this, R.style.DialogTheme) + } alert.setTitle(getString(R.string.output, (episodeNumber + 1).toString(), episodeList[episodeNumber].name) ) @@ -155,7 +165,15 @@ class MainActivity : AppCompatActivity() { } - val builder = MaterialAlertDialogBuilder(this, R.style.DialogTheme) + + + var builder : MaterialAlertDialogBuilder + if(Utility.getTheme(this) == 4){ + builder = MaterialAlertDialogBuilder(this, R.style.DialogThemeWhite) + }else{ + builder = MaterialAlertDialogBuilder(this, R.style.DialogTheme) + } + builder.setTitle("Links:") builder.setItems(liste) { _: DialogInterface?, which: Int -> var i = Intent(Intent.ACTION_VIEW) @@ -284,7 +302,7 @@ class MainActivity : AppCompatActivity() { } when (binding.bottomBarViewFlipper.displayedChild) { 4 -> - loadEpisodeCover(getString(R.string.cover_citroncode_dd_url) + (episodeNumber + 1) + ".jpg") + loadEpisodeCover(getString(R.string.cover_citroncode_dd_url) + (episodeNumber + 1) + ".png") else -> if(binding.bottomBarViewFlipper.displayedChild == 6) { loadEpisodeCover(getString(R.string.cover_citroncode_url) + "k" + (episodeNumber + 1) + ".png") @@ -300,7 +318,7 @@ class MainActivity : AppCompatActivity() { binding.fabLinks.hide() } if(random == 3){ - loadEpisodeCover(getString(R.string.cover_citroncode_dd_url) + (episodeNumber + 1) + ".jpg") + loadEpisodeCover(getString(R.string.cover_citroncode_dd_url) + (episodeNumber + 1) + ".png") binding.fabLinks.show() } if(random == 4){ @@ -402,5 +420,27 @@ class MainActivity : AppCompatActivity() { } } + override fun onResume() { + super.onResume() + + sharedPreferences = getSharedPreferences(packageName,0) + sharedPreferencesEditor = sharedPreferences.edit() + + if (sharedPreferences.getInt("theme_changed",0) == 1) { + val intent = intent + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) + finish() + overridePendingTransition(0, 0) + startActivity(intent) + overridePendingTransition(0, 0) + + sharedPreferencesEditor.putInt("theme_changed",0) + sharedPreferencesEditor.apply() + } + } + + fun changeViewThemes(){ + + } } diff --git a/app/src/main/java/de/msdevs/einschlafhilfe/SettingsActivity.kt b/app/src/main/java/de/msdevs/einschlafhilfe/SettingsActivity.kt index f3ffd4b..88d6b58 100644 --- a/app/src/main/java/de/msdevs/einschlafhilfe/SettingsActivity.kt +++ b/app/src/main/java/de/msdevs/einschlafhilfe/SettingsActivity.kt @@ -1,19 +1,29 @@ package de.msdevs.einschlafhilfe +import android.R +import android.content.Intent import android.content.SharedPreferences +import android.content.res.ColorStateList +import android.content.res.Resources +import android.graphics.Color import android.os.Bundle +import android.view.View +import android.widget.ImageView +import android.widget.RelativeLayout import android.widget.TextView -import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.widget.SwitchCompat +import androidx.appcompat.content.res.AppCompatResources +import com.google.android.material.materialswitch.MaterialSwitch import com.google.android.material.slider.RangeSlider import de.msdevs.einschlafhilfe.databinding.ActivitySettingsBinding +import de.msdevs.einschlafhilfe.utils.Utility -class SettingsActivity : AppCompatActivity() { + +class SettingsActivity : BaseActivity() { lateinit var binding : ActivitySettingsBinding - lateinit var switchSpotify : SwitchCompat - lateinit var switchUpdatelist : SwitchCompat + lateinit var switchSpotify : MaterialSwitch + lateinit var switchUpdatelist : MaterialSwitch lateinit var sharedPreferences: SharedPreferences lateinit var sharedPreferencesEditor: SharedPreferences.Editor lateinit var rangeSlider : RangeSlider @@ -22,6 +32,13 @@ class SettingsActivity : AppCompatActivity() { lateinit var tvStartK : TextView lateinit var tvEnd: TextView lateinit var tvEndK : TextView + lateinit var selectedTheme : String + lateinit var ivCheckJustus : ImageView + lateinit var ivCheckBob : ImageView + lateinit var ivCheckPeter : ImageView + lateinit var rlJustus : RelativeLayout + lateinit var rlBob : RelativeLayout + lateinit var rlPeter: RelativeLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -30,18 +47,7 @@ class SettingsActivity : AppCompatActivity() { setContentView(view) supportActionBar?.setDisplayHomeAsUpEnabled(true) - sharedPreferences = getSharedPreferences(packageName,0) - sharedPreferencesEditor = sharedPreferences.edit() - - switchSpotify = binding.swUseSpotify - switchUpdatelist = binding.swUpdateList - - rangeSlider = binding.rangeSlider - rangeSliderKids = binding.rangeSliderKids - tvStart = binding.tvStart - tvStartK = binding.tvStartKids - tvEnd = binding.tvEnd - tvEndK = binding.tvEndKids + iniViews() switchSpotify.isChecked = sharedPreferences.getBoolean("spotify",false) switchUpdatelist.isChecked = sharedPreferences.getBoolean("update_list",false) @@ -118,6 +124,77 @@ class SettingsActivity : AppCompatActivity() { sharedPreferencesEditor.apply() } }) + + + rlJustus.setOnClickListener{ + selectedTheme = "justus" + loadThemeSettings() + + Utility.setTheme(applicationContext, 4); + recreateActivity(); + } + rlBob.setOnClickListener{ + selectedTheme = "bob" + loadThemeSettings() + + Utility.setTheme(applicationContext, 2); + recreateActivity(); + } + rlPeter.setOnClickListener{ + selectedTheme = "peter" + loadThemeSettings() + + Utility.setTheme(applicationContext, 3); + recreateActivity(); + } + } + fun iniViews(){ + sharedPreferences = getSharedPreferences(packageName,0) + sharedPreferencesEditor = sharedPreferences.edit() + selectedTheme = sharedPreferences.getString("selected_theme","").toString() + + switchSpotify = binding.swUseSpotify + switchUpdatelist = binding.swUpdateList + + rangeSlider = binding.rangeSlider + rangeSliderKids = binding.rangeSliderKids + tvStart = binding.tvStart + tvStartK = binding.tvStartKids + tvEnd = binding.tvEnd + tvEndK = binding.tvEndKids + ivCheckJustus = binding.ivCheckJustus + ivCheckPeter = binding.ivCheckPeter + ivCheckBob = binding.ivCheckBob + + rlJustus = binding.rlJustus + rlBob = binding.rlBob + rlPeter = binding.rlPeter + + loadThemeSettings() + + changeViewThemes() + } + fun loadThemeSettings(){ + sharedPreferencesEditor.putString("selected_theme",selectedTheme) + sharedPreferencesEditor.putInt("theme_changed",1) + sharedPreferencesEditor.apply() + + if(selectedTheme.length == 0 || selectedTheme == "bob"){ + ivCheckBob.visibility = View.VISIBLE + + ivCheckPeter.visibility = View.GONE + ivCheckJustus.visibility = View.GONE + }else if(selectedTheme == "justus"){ + ivCheckJustus.visibility = View.VISIBLE + + ivCheckPeter.visibility = View.GONE + ivCheckBob.visibility = View.GONE + }else if(selectedTheme == "peter"){ + ivCheckPeter.visibility = View.VISIBLE + + ivCheckBob.visibility = View.GONE + ivCheckJustus.visibility = View.GONE + } } fun String.floatToInt(): Int { return this.toFloat().toInt() @@ -126,5 +203,69 @@ class SettingsActivity : AppCompatActivity() { onBackPressed() return true } + fun recreateActivity() { + val intent = intent + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) + finish() + overridePendingTransition(0, 0) + startActivity(intent) + overridePendingTransition(0, 0) + + + } + + fun changeViewThemes(){ + if(Utility.getTheme(this) == 4){ + // switchUpdatelist.thumbDrawable = getDrawable(R.drawable.thumb_style_white) + + val thumbTintSelector = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), + intArrayOf(-android.R.attr.state_checked) + ), + intArrayOf( + // Color when the switch is checked + Color.parseColor("#000000"), + // Color when the switch is unchecked + Color.parseColor("#938F99") + ) + ) + switchUpdatelist.thumbTintList = thumbTintSelector + switchSpotify.thumbTintList = thumbTintSelector + + }else if(Utility.getTheme(this) == 2){ + + val thumbTintSelector = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), + intArrayOf(-android.R.attr.state_checked) + ), + intArrayOf( + // Color when the switch is checked + Color.parseColor("#d50000"), + // Color when the switch is unchecked + Color.parseColor("#938F99") + ) + ) + switchUpdatelist.thumbTintList = thumbTintSelector + switchSpotify.thumbTintList = thumbTintSelector + }else if(Utility.getTheme(this) == 3){ + val thumbTintSelector = ColorStateList( + arrayOf( + intArrayOf(android.R.attr.state_checked), + intArrayOf(-android.R.attr.state_checked) + ), + intArrayOf( + // Color when the switch is checked + Color.parseColor("#0048FF"), + // Color when the switch is unchecked + Color.parseColor("#938F99") + ) + ) + switchUpdatelist.thumbTintList = thumbTintSelector + switchSpotify.thumbTintList = thumbTintSelector + } + + } } diff --git a/app/src/main/java/de/msdevs/einschlafhilfe/utils/Utility.kt b/app/src/main/java/de/msdevs/einschlafhilfe/utils/Utility.kt new file mode 100644 index 0000000..fa73bcf --- /dev/null +++ b/app/src/main/java/de/msdevs/einschlafhilfe/utils/Utility.kt @@ -0,0 +1,17 @@ +package de.msdevs.einschlafhilfe.utils + +import android.content.Context +import android.preference.PreferenceManager +import de.msdevs.einschlafhilfe.R + +object Utility { + fun setTheme(context: Context, theme: Int) { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + prefs.edit().putInt(context.getString(R.string.prefs_theme_key), theme).apply() + } + + fun getTheme(context: Context): Int { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + return prefs.getInt(context.getString(R.string.prefs_theme_key), -1) + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_check_theme.xml b/app/src/main/res/drawable/ic_check_theme.xml new file mode 100644 index 0000000..0413cd3 --- /dev/null +++ b/app/src/main/res/drawable/ic_check_theme.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_check_theme_out.xml b/app/src/main/res/drawable/ic_check_theme_out.xml new file mode 100644 index 0000000..04ea9bc --- /dev/null +++ b/app/src/main/res/drawable/ic_check_theme_out.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_circle.xml b/app/src/main/res/drawable/ic_circle.xml new file mode 100644 index 0000000..1b58825 --- /dev/null +++ b/app/src/main/res/drawable/ic_circle.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6687daf..42ae7ea 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,8 +13,8 @@ android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_alignParentEnd="true" - app:backgroundTint="@color/colorPrimary" - app:tint="#FFFFFF" + app:backgroundTint="?attr/colorOnPrimary" + app:tint="?attr/colorOnSurface" android:layout_marginEnd="10dp" android:layout_above="@id/fab_description" android:layout_marginTop="10dp" @@ -27,10 +27,10 @@ android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="60dp" - app:backgroundTint="@color/colorPrimary" - app:tint="#FFFFFF" + app:backgroundTint="?attr/colorOnPrimary" + app:tint="?attr/colorOnSurface" android:layout_alignParentEnd="true" - android:layout_marginRight="10dp" + android:layout_marginEnd="10dp" android:layout_marginTop="10dp" android:clickable="true" app:srcCompat="@drawable/ic_refresh" /> @@ -39,10 +39,10 @@ android:id="@+id/fab_description" android:layout_width="wrap_content" android:layout_above="@id/fab_refresh" - android:layout_marginRight="10dp" - app:backgroundTint="@color/colorPrimary" - app:tint="#FFFFFF" - android:layout_alignParentRight="true" + android:layout_marginEnd="10dp" + app:backgroundTint="?attr/colorOnPrimary" + app:tint="?attr/colorOnSurface" + android:layout_alignParentEnd="true" android:layout_height="wrap_content" android:clickable="true" app:srcCompat="@drawable/ic_text" /> @@ -81,15 +81,15 @@ android:layout_marginBottom="10dp" android:layout_marginTop="10dp" android:textStyle="bold" - android:textColor="@color/colorPrimary" /> + android:textColor="?attr/colorOnPrimary" />