2019-09-01 11:54:12 +02:00
package com.denizd.substitutionplan.fragments
2019-05-14 22:28:45 +02:00
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
2019-08-27 18:38:49 +02:00
import android.database.Cursor
import android.media.RingtoneManager
2019-05-14 22:28:45 +02:00
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.preference.PreferenceManager
2019-08-27 18:38:49 +02:00
import android.provider.Settings
2019-05-14 22:28:45 +02:00
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
2019-05-21 18:55:29 +02:00
import android.view.Window
2019-05-14 22:28:45 +02:00
import android.widget.*
import androidx.appcompat.app.AlertDialog
2019-05-21 18:55:29 +02:00
import androidx.appcompat.app.AppCompatDelegate
2019-05-14 22:28:45 +02:00
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
2019-07-26 13:31:31 +02:00
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
2019-09-01 11:54:12 +02:00
import com.denizd.substitutionplan.*
import com.denizd.substitutionplan.adapters.ColourAdapter
import com.denizd.substitutionplan.adapters.RingtoneAdapter
2019-09-03 18:18:21 +02:00
import com.denizd.substitutionplan.data.HelperFunctions
2019-09-01 11:54:12 +02:00
import com.denizd.substitutionplan.models.Colour
import com.denizd.substitutionplan.models.Ringtone
2019-05-21 18:55:29 +02:00
import com.google.android.material.bottomnavigation.BottomNavigationView
2019-05-14 22:28:45 +02:00
import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputEditText
2019-08-12 13:10:05 +02:00
import com.google.firebase.messaging.FirebaseMessaging
2019-05-14 22:28:45 +02:00
import com.jaredrummler.android.device.DeviceName
2019-08-02 13:35:54 +02:00
import kotlin.collections.ArrayList
2019-05-14 22:28:45 +02:00
2019-09-01 11:54:12 +02:00
internal class SettingsFragment : Fragment ( R . layout . content_settings ), View . OnClickListener ,
CompoundButton . OnCheckedChangeListener ,
ColourAdapter . OnClickListener ,
RingtoneAdapter . OnClickListener {
2019-05-14 22:28:45 +02:00
2019-08-16 10:31:22 +02:00
private var name = ""
private var model = ""
2019-05-14 22:28:45 +02:00
private lateinit var mContext : Context
private lateinit var prefs : SharedPreferences
private lateinit var edit : SharedPreferences . Editor
private val builder = CustomTabsIntent . Builder ()
private val customTabsIntent = builder . build () as CustomTabsIntent
private var cs : Int = 7
2019-05-24 19:22:23 +02:00
private var window : Window ? = null
2019-07-26 13:31:31 +02:00
private lateinit var colourRecycler : RecyclerView
2019-08-27 18:38:49 +02:00
private lateinit var ringtoneCustomiserDialog : AlertDialog
private lateinit var currentRingtone : TextView
2019-05-14 22:28:45 +02:00
override fun onAttach ( context : Context ) {
super . onAttach ( context )
mContext = context
prefs = PreferenceManager . getDefaultSharedPreferences ( mContext )
edit = prefs . edit ()
2019-05-21 18:55:29 +02:00
2019-05-24 19:22:23 +02:00
window = activity ?. window
2019-05-14 22:28:45 +02:00
}
override fun onViewCreated ( view : View , savedInstanceState : Bundle ?) {
super . onViewCreated ( view , savedInstanceState )
val txtName = view . findViewById < TextInputEditText >( R . id . txtName )
val txtClasses = view . findViewById < TextInputEditText >( R . id . txtClasses )
val txtCourses = view . findViewById < TextInputEditText >( R . id . txtCourses )
val switchDisableGreeting = view . findViewById < Switch >( R . id . switchDisableGreeting )
val switchDark = view . findViewById < Switch >( R . id . switchDark )
val switchNotifications = view . findViewById < Switch >( R . id . switchNotifications )
val switchDefaultPlan = view . findViewById < Switch >( R . id . switchDefaultPlan )
val switchAutoRefresh = view . findViewById < Switch >( R . id . switchAutoRefresh )
val versionNumber = view . findViewById < TextView >( R . id . txtVersionTwo )
val helpCourses = view . findViewById < ImageButton >( R . id . chipHelpCourses )
val helpClasses = view . findViewById < ImageButton >( R . id . chipHelpClasses )
val btnCustomiseColours = view . findViewById < LinearLayout >( R . id . btnCustomiseColours )
val btnVersion = view . findViewById < LinearLayout >( R . id . btnVersion )
2019-08-27 18:38:49 +02:00
currentRingtone = view . findViewById ( R . id . txtCustomiseRingtone2 )
setRingtoneText ()
2019-05-14 22:28:45 +02:00
2019-07-30 16:58:51 +02:00
switchDisableGreeting . setOnCheckedChangeListener ( this )
switchDark . setOnCheckedChangeListener ( this )
switchNotifications . setOnCheckedChangeListener ( this )
switchDefaultPlan . setOnCheckedChangeListener ( this )
switchAutoRefresh . setOnCheckedChangeListener ( this )
2019-05-14 22:28:45 +02:00
helpCourses . setOnClickListener ( this )
helpClasses . setOnClickListener ( this )
btnCustomiseColours . setOnClickListener ( this )
2019-09-03 20:15:08 +02:00
view . findViewById < LinearLayout >( R . id . btnNoNotif ). setOnClickListener ( this )
2019-08-27 18:38:49 +02:00
view . findViewById < LinearLayout >( R . id . btnCustomiseRingtone ). setOnClickListener ( this )
2019-07-26 13:31:31 +02:00
view . findViewById < LinearLayout >( R . id . btnWebsite ). setOnClickListener ( this )
view . findViewById < LinearLayout >( R . id . btnLicences ). setOnClickListener ( this )
view . findViewById < LinearLayout >( R . id . btnTerms ). setOnClickListener ( this )
view . findViewById < LinearLayout >( R . id . btnPrivacyP ). setOnClickListener ( this )
2019-05-14 22:28:45 +02:00
btnVersion . setOnClickListener ( this )
switchDisableGreeting . isChecked = prefs . getBoolean ( "greeting" , true )
switchDark . isChecked = when ( prefs . getInt ( "themeInt" , 0 )) {
1 -> true
else -> false
}
switchNotifications . isChecked = prefs . getBoolean ( "notif" , false )
switchDefaultPlan . isChecked = prefs . getBoolean ( "defaultPersonalised" , false )
switchAutoRefresh . isChecked = prefs . getBoolean ( "autoRefresh" , false )
versionNumber . text = BuildConfig . VERSION_NAME
txtName . setText ( prefs . getString ( "username" , "" ))
txtName . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ) {}
override fun beforeTextChanged ( s : CharSequence , start : Int , count : Int , after : Int ) {}
override fun onTextChanged ( s : CharSequence , start : Int , before : Int , count : Int ) {
2019-09-03 18:18:21 +02:00
edit . putString ( "username" , txtName . text . toString (). trim ()). apply ()
2019-05-14 22:28:45 +02:00
}
})
txtClasses . setText ( prefs . getString ( "classes" , "" ))
txtClasses . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ) {}
override fun beforeTextChanged ( s : CharSequence , start : Int , count : Int , after : Int ) {}
override fun onTextChanged ( s : CharSequence , start : Int , before : Int , count : Int ) {
2019-05-17 11:10:59 +02:00
edit . putString ( "classes" , txtClasses . text . toString ()). apply ()
2019-05-14 22:28:45 +02:00
}
})
txtCourses . setText ( prefs . getString ( "courses" , "" ))
txtCourses . addTextChangedListener ( object : TextWatcher {
override fun afterTextChanged ( s : Editable ) {}
override fun beforeTextChanged ( s : CharSequence , start : Int , count : Int , after : Int ) {}
override fun onTextChanged ( s : CharSequence , start : Int , before : Int , count : Int ) {
2019-05-17 11:10:59 +02:00
edit . putString ( "courses" , txtCourses . text . toString ()). apply ()
2019-05-14 22:28:45 +02:00
}
})
2019-05-23 18:08:04 +02:00
btnVersion . setOnLongClickListener {
2019-09-01 11:54:12 +02:00
makeToast ( getString ( R . string . madeBy ))
2019-05-16 16:14:03 +02:00
debugMenu ()
2019-05-14 22:28:45 +02:00
}
}
override fun onClick ( v : View ?) {
when ( v ?. id ) {
2019-09-01 11:54:12 +02:00
R . id . chipHelpCourses -> createDialog ( getString ( R . string . enterCoursesHelpTitle ), getString (
R . string . enterCoursesHelp
))
R . id . chipHelpClasses -> createDialog ( getString ( R . string . enterGradeHelpTitle ), getString (
R . string . enterGradeHelp
))
2019-05-14 22:28:45 +02:00
R . id . btnCustomiseColours -> createColourDialog ()
2019-09-03 20:15:08 +02:00
R . id . btnNoNotif -> createDialog ( mContext . getString ( R . string . notReceivingNotifications1 ), mContext . getString ( R . string . notReceivingNotificationsHelp ))
2019-08-27 18:38:49 +02:00
R . id . btnCustomiseRingtone -> createRingtoneDialog ()
2019-05-14 22:28:45 +02:00
R . id . btnWebsite -> {
try {
customTabsIntent . launchUrl ( mContext , Uri . parse ( "http://307.joomla.schule.bremen.de" ))
} catch ( e : ActivityNotFoundException ) {
2019-09-01 11:54:12 +02:00
makeToast ( getString ( R . string . chromeCompatibleNotFound ))
2019-05-14 22:28:45 +02:00
}
}
R . id . btnLicences -> {
createDialog ( "Licences" , "Libraries: \n • Android Device Names © 2015 Jared Rummler, licensed under the Apache Licence, Version 2.0" +
" \n • jsoup HTML parser © 2009-2018 Jonathan Hedley, licensed under the open source MIT Licence" +
" \n\n Font: \n • Manrope © 2018-2019 Michael Sharanda, licensed under the SIL Open Font Licence 1.1" +
" \n\n Icons: \n • bqlqn \n • fjstudio \n • Freepik \n • Smashicons \n • © 2013-2019 Freepik Company S.L., licensed under Creative Commons BY 3.0" +
2019-07-22 19:10:25 +02:00
" \n\n Additional help: \n • Leon Becker \n • Alex Lick \n • Batuhan Özcan \n • Erich Kerkesner" )
2019-05-14 22:28:45 +02:00
}
R . id . btnTerms -> {
createDialog ( "Terms & Conditions" , "These terms automatically apply to anyone using this app - therefore, please make sure to read them carefully before using the app. Copying or modifying parts of the app or the entire app, as well as creating derivative versions, is prohibited without permission. This app is intellectual property of the developer. \n " +
" \n The developer reserves the right to make changes to the app at any given time and for any reason. The user will be informed of any changes made accordingly. \n " +
" \n Tampering with the end device, in the form of rooting or otherwise modifying the operating system may result in malfunction of the software. In this case, the developer does not provide support, as the user is responsible for keeping the device free of software that may compromise its security. \n " +
" \n Full functionality of the app relies on a steady internet connection. The developer does not take responsibility for malfunction of these services, nor for any errors caused by the end device. The user is responsible for ensuring that their device is fully updated and fully functioning. \n " +
" \n As the app relies on third-parties, information provided in-app may be delayed or incorrect at times. The developer accepts no liability for any information mistakenly provided in the app. \n " +
" \n The developer may wish to update the app at any point. Should such action arise, then the user is advised to update the app to ensure proper functionality. However, the developer does not promise that the app will be continuously updated, and may stop providing the app at any point. Unless told otherwise, upon any termination, (a) the rights and licenses granted to the user in these terms will end; (b) the user must stop using the app, and (if needed) delete it from their device. \n " +
" \n Changes to these Terms & Conditions \n " +
" \n The developer may update these Terms & Conditions from time to time. Thus, the user is advised to review this page periodically for any changes. Any changes are effective immediately after they are posted on this page. \n " +
" \n Contact Us \n " +
" \n In case of questions or suggestions regarding these Terms & Conditions, the user is advised to contact the developer of this app. Contact information is provided through the Play Store. \n " +
" \n --- \n " +
" \n These Terms & Conditions were modified upon the template provided by App Privacy Policy Generator. This service is in no way affiliated with AvH Plan or the developer." )
}
R . id . btnPrivacyP -> {
createDialog ( "Privacy Policy" , "The app \" Alexander-von-Humboldt-Plan \" , hereby abbreviated to AvH Plan, is provided as a free service by the developer for use as is. \n " +
" \n This page is used to inform visitors and users regarding policies with the collection, use, and disclosure of personal information, if they choose to make use of the service. \n " +
" \n AvH Plan does not collect, store, share, or in any other way use personal information retrieved from its users. Any information asked for within the app is only used to improve the user experience and as such, is stored locally and cannot be accessed by third-parties or be used to identify the user. \n " +
" \n Information Collection and Use \n " +
" \n At this moment, AvH Plan does not require personally identifiable information for its core functionality. Certain features do require entering information that may be personally identifiable, however, this data will be retained on the user's device and is therefore not accessible outside the app \n " +
" \n Log Data \n " +
" \n In the case of an error in the app, device-specific data may be collected and stored on your phone. This data is called Log Data. This Log Data may include information, such as your device's Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilising the service, the time and date when the last usage occured, and other statistics. This data can not be used to personally identify any user. \n " +
" \n Cookies \n " +
" \n Cookies are files with small amounts of data that are commonly used as anonymous unique identifiers on the web. AvH Plan strives to not make use of cookies for its functionality, however, as its functionality requires access to third-party-websites, cookies may be unintentionally collected by the device's web browser. AvH Plan does not make use of these cookies in any way. \n " +
" \n Service Providers \n " +
" \n No third-parties are employed for providing any functionality or services of the AvH Plan-app and as such, all functionality is accessible without directly sharing personal data with third-parties. \n " +
" \n Security \n " +
" \n While absolute security cannot be ensured due to the internet functionality the app employs, no information is shared over any transmission methods. \n " +
" \n Links to Other Sites \n " +
" \n This Service may contain links to other sites, which are not operated by the developer of AvH Plan. The user is advised to review the privacy policy of any webpage they may access through the app. No responsibility for the content of these third-party websites is provided by the app developer. \n " +
" \n Children’ s Privacy \n " +
" \n The service does not address anyone under the age of 13. As the app does not collect any information from its users, no data is collected from users that may be under the age of 13. \n " +
" \n Changes to This Privacy Policy \n " +
" \n This privacy policy may be updated as the AvH Plan app is updated with new features. As such, the user is advised to review this page periodically for any changes. Any changes that may be made are effective immediately upon publishing. \n " +
" \n Contact Us \n " +
" \n In case of questions or suggestions regarding this privacy policy, the user is advised to contact the developer of this app. Contact information is provided through the Play Store. \n " +
" \n --- \n " +
" \n This privacy policy was modified upon the template provided by privacypolicytemplate.net and App Privacy Policy Generator. These services are in no way affiliated with AvH Plan or the developer." )
}
R . id . btnVersion -> {
if ( cs > 0 ) {
cs --
} else {
try {
cs = 7
customTabsIntent . launchUrl ( mContext , Uri . parse ( "http://www.flussufer.de/gerd/person.htm" ))
2019-09-01 11:54:12 +02:00
makeToast ( getString ( R . string . dontTellHim ))
2019-05-14 22:28:45 +02:00
} catch ( e : ActivityNotFoundException ) {
2019-09-01 11:54:12 +02:00
makeToast ( getString ( R . string . chromeCompatibleNotFound ))
2019-05-14 22:28:45 +02:00
}
}
}
}
edit . apply ()
}
2019-07-30 16:58:51 +02:00
override fun onCheckedChanged ( v : CompoundButton ?, isChecked : Boolean ) {
if ( v ?. isPressed == true ) {
when ( v . id ) {
R . id . switchDisableGreeting -> {
edit . putBoolean ( "greeting" , isChecked )
}
R . id . switchDark -> {
val bottomNav = v . rootView . findViewById < BottomNavigationView >( R . id . bottom_nav )
if ( isChecked ) {
edit . putInt ( "themeInt" , 1 )
AppCompatDelegate . setDefaultNightMode ( AppCompatDelegate . MODE_NIGHT_YES )
window ?. decorView ?. systemUiVisibility = View . SYSTEM_UI_FLAG_VISIBLE
2019-07-31 19:48:21 +02:00
window ?. navigationBarColor = ContextCompat . getColor ( mContext , R . color . colorBackground )
2019-07-30 16:58:51 +02:00
} else {
edit . putInt ( "themeInt" , 0 )
AppCompatDelegate . setDefaultNightMode ( AppCompatDelegate . MODE_NIGHT_NO )
if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) {
window ?. decorView ?. systemUiVisibility = View . SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
2019-07-31 19:48:21 +02:00
window ?. navigationBarColor = ContextCompat . getColor ( mContext , R . color . colorBackground )
2019-07-30 16:58:51 +02:00
}
}
if ( prefs . getBoolean ( "defaultPersonalised" , false )) {
bottomNav . selectedItemId = R . id . personal
} else {
bottomNav . selectedItemId = R . id . plan
}
}
R . id . switchNotifications -> {
edit . putBoolean ( "notif" , isChecked )
2019-08-12 13:10:05 +02:00
if ( isChecked ) {
2019-09-03 18:18:21 +02:00
subToTopic ( "android" )
2019-08-12 13:10:05 +02:00
} else {
2019-09-03 18:18:21 +02:00
unsubFromTopic ( "android" )
2019-08-12 13:10:05 +02:00
}
2019-07-30 16:58:51 +02:00
}
R . id . switchDefaultPlan -> {
edit . putBoolean ( "defaultPersonalised" , isChecked )
}
R . id . switchAutoRefresh -> {
edit . putBoolean ( "autoRefresh" , isChecked )
}
}
edit . apply ()
}
}
2019-05-14 22:28:45 +02:00
private fun createDialog ( title : String , text : String ) {
2019-09-01 11:54:12 +02:00
val alertDialog = AlertDialog . Builder ( mContext ,
R . style . AlertDialog
)
2019-05-14 22:28:45 +02:00
val dialogView = LayoutInflater . from ( mContext ). inflate ( R . layout . simple_dialog , null )
2019-07-30 16:58:51 +02:00
dialogView . findViewById < TextView >( R . id . textviewtitle ). text = title
dialogView . findViewById < TextView >( R . id . dialogtext ). text = text
2019-05-14 22:28:45 +02:00
alertDialog . setView ( dialogView ). show ()
}
private fun createColourDialog () {
2019-09-01 11:54:12 +02:00
val colourCustomiserBuilder = AlertDialog . Builder ( mContext ,
R . style . AlertDialog
)
2019-05-14 22:28:45 +02:00
2019-07-26 13:31:31 +02:00
val dialogView = LayoutInflater . from ( mContext ). inflate ( R . layout . recycler_dialog , null )
val titleText = dialogView . findViewById < TextView >( R . id . empty_textviewtitle )
2019-07-31 19:48:21 +02:00
titleText . text = getString ( R . string . customiseColoursTitle )
2019-07-26 13:31:31 +02:00
colourRecycler = dialogView . findViewById ( R . id . recyclerView )
2019-09-03 18:18:21 +02:00
colourRecycler . apply {
hasFixedSize ()
layoutManager = GridLayoutManager ( mContext , 1 )
adapter = ColourAdapter ( getColourList (), this @SettingsFragment )
}
2019-07-26 13:31:31 +02:00
colourCustomiserBuilder . setView ( dialogView )
val colourCustomiserDialog = colourCustomiserBuilder . create ()
colourCustomiserDialog . show ()
}
private fun getColourList (): ArrayList < Colour > {
val colours = ArrayList < Colour >()
2019-09-03 18:18:21 +02:00
val coursesNoLang = HelperFunctions . languageIndependentCourses
2019-09-01 11:54:12 +02:00
val courses = arrayOf ( getString ( R . string . courseDeu ), getString (
R . string . courseEng
), getString ( R . string . courseFra ), getString ( R . string . courseSpa ), getString (
R . string . courseLat
), getString ( R . string . courseTue ), getString ( R . string . courseChi ), getString (
R . string . courseKun
), getString ( R . string . courseMus ), getString ( R . string . courseDar ), getString (
R . string . courseGeg
), getString ( R . string . courseGes ), getString ( R . string . coursePol ), getString (
R . string . coursePhi
), getString ( R . string . courseRel ), getString ( R . string . courseMat ), getString (
R . string . courseBio
), getString ( R . string . courseChe ), getString ( R . string . coursePhy ), getString (
R . string . courseInf
), getString ( R . string . courseSpo ), getString ( R . string . courseGll ), getString (
R . string . courseWat
), getString ( R . string . courseFor ), getString ( R . string . courseWp ))
val coursesIcons = intArrayOf ( R . drawable . ic_german , R . drawable . ic_english , R . drawable . ic_french ,
R . drawable . ic_spanish , R . drawable . ic_latin , R . drawable . ic_turkish , R . drawable . ic_chinese ,
R . drawable . ic_arts , R . drawable . ic_music , R . drawable . ic_drama , R . drawable . ic_geography ,
R . drawable . ic_history , R . drawable . ic_politics , R . drawable . ic_philosophy , R . drawable . ic_religion ,
R . drawable . ic_maths , R . drawable . ic_biology , R . drawable . ic_chemistry , R . drawable . ic_physics ,
R . drawable . ic_compsci , R . drawable . ic_pe , R . drawable . ic_gll , R . drawable . ic_wat ,
R . drawable . ic_help , R . drawable . ic_pencil
)
2019-05-14 22:28:45 +02:00
for ( i in 0 until coursesNoLang . size ) {
2019-09-01 11:54:12 +02:00
colours . add (
Colour (
courses [ i ],
coursesNoLang [ i ],
coursesIcons [ i ],
2019-09-03 18:18:21 +02:00
HelperFunctions . getColourForString ( prefs . getString ( "card ${coursesNoLang[i]} " , "" ) ?: "" )
2019-09-01 11:54:12 +02:00
)
)
2019-05-14 22:28:45 +02:00
}
2019-07-26 13:31:31 +02:00
return colours
}
2019-05-14 22:28:45 +02:00
2019-08-27 18:38:49 +02:00
private fun createRingtoneDialog () {
if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . O ) {
2019-09-03 18:18:21 +02:00
HelperFunctions . getNotificationChannel ( mContext , prefs )
2019-08-27 18:38:49 +02:00
val intent = Intent ( Settings . ACTION_CHANNEL_NOTIFICATION_SETTINGS ). apply {
putExtra ( Settings . EXTRA_APP_PACKAGE , mContext . applicationContext . packageName )
putExtra ( Settings . EXTRA_CHANNEL_ID , "general" )
}
startActivity ( intent )
} else {
val ringtoneCustomiserBuilder = AlertDialog . Builder ( mContext , R . style . AlertDialog )
val dialogView = LayoutInflater . from ( mContext ). inflate ( R . layout . recycler_dialog , null )
val titleText = dialogView . findViewById < TextView >( R . id . empty_textviewtitle )
titleText . text = getString ( R . string . pickRingtone )
val recycler = dialogView . findViewById < RecyclerView >( R . id . recyclerView )
recycler . apply {
hasFixedSize ()
layoutManager = GridLayoutManager ( mContext , 1 )
}
ringtoneCustomiserDialog = ringtoneCustomiserBuilder . setView ( dialogView ). create ()
ringtoneCustomiserDialog . show ()
recycler . postDelayed ({
val ringtones = getRingtones (). toList ()
recycler . adapter = RingtoneAdapter ( ringtones , this )
}, 100 )
}
}
private fun getRingtones (): ArrayList < Ringtone > {
2019-09-01 11:54:12 +02:00
lateinit var ringtoneCursor : Cursor
2019-08-27 18:38:49 +02:00
val ringtoneManager = RingtoneManager ( activity ). apply {
setType ( RingtoneManager . TYPE_NOTIFICATION )
2019-09-01 11:54:12 +02:00
ringtoneCursor = cursor
2019-08-27 18:38:49 +02:00
}
val alarms = ArrayList < Ringtone >()
2019-09-01 11:54:12 +02:00
while (! ringtoneCursor . isAfterLast && ringtoneCursor . moveToNext ()) {
val position = ringtoneCursor . position
alarms . add (
Ringtone (
ringtoneManager . getRingtone ( position ). getTitle ( mContext ),
ringtoneManager . getRingtoneUri ( position ). toString ()
)
)
2019-08-27 18:38:49 +02:00
}
return alarms
}
override fun onRingtoneClick ( position : Int , name : String , uri : String ) {
prefs . edit (). apply {
putString ( "ringtoneName" , name )
putString ( "ringtoneUri" , uri )
}. apply ()
setRingtoneText ()
ringtoneCustomiserDialog . dismiss ()
}
private fun setRingtoneText () {
currentRingtone . text = if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . O ) {
mContext . getString ( R . string . deviceSettingsRedirect )
} else {
val tone = if (( prefs . getString ( "ringtoneName" , "" ) ?: "" ). isNotEmpty ()) {
prefs . getString ( "ringtoneName" , "" )
} else {
mContext . getString ( R . string . defaultRingtone )
}
mContext . getString ( R . string . setRingtone2 , tone )
}
}
2019-07-26 13:31:31 +02:00
override fun onClick ( position : Int , title : String , titleNoLang : String ) {
val colourPickerBuilder = AlertDialog . Builder ( mContext , R . style . AlertDialog )
val pickerDialogView = LayoutInflater . from ( mContext ). inflate ( R . layout . empty_dialog , null )
val pickerTitleText = pickerDialogView . findViewById < TextView >( R . id . empty_textviewtitle )
val pickerLayout = pickerDialogView . findViewById < LinearLayout >( R . id . empty_linearlayout )
pickerTitleText . text = title
2019-05-14 22:28:45 +02:00
2019-07-26 13:31:31 +02:00
val picker = LayoutInflater . from ( mContext ). inflate ( R . layout . bg_colour_picker , null )
pickerLayout . addView ( picker )
colourPickerBuilder . setView ( pickerDialogView )
val colourPickerDialog : AlertDialog = colourPickerBuilder . create ()
2019-09-01 11:54:12 +02:00
val buttons = intArrayOf ( R . id . def , R . id . red , R . id . orange , R . id . yellow , R . id . green ,
R . id . teal , R . id . cyan , R . id . blue , R . id . purple , R . id . pink , R . id . brown , R . id . grey ,
R . id . pureWhite , R . id . salmon , R . id . tangerine , R . id . banana , R . id . flora , R . id . spindrift ,
R . id . sky , R . id . orchid , R . id . lavender , R . id . carnation , R . id . brown2 , R . id . pureBlack )
2019-09-03 18:18:21 +02:00
val colours = HelperFunctions . colourNames
2019-07-26 13:31:31 +02:00
for ( i2 in 0 until buttons . size ) {
2019-09-01 11:54:12 +02:00
picker . findViewById < MaterialButton >( buttons [ i2 ]). setOnClickListener {
2019-08-09 21:18:27 +02:00
// prefs.edit().putInt("bg$titleNoLang", colourIntegers[i2]).apply()
prefs . edit (). putString ( "card $titleNoLang " , colours [ i2 ]). apply ()
2019-07-26 21:43:52 +02:00
val recyclerViewState = colourRecycler . layoutManager ?. onSaveInstanceState ()
2019-07-26 13:31:31 +02:00
colourRecycler . adapter = ColourAdapter ( getColourList (), this )
2019-07-26 21:43:52 +02:00
colourRecycler . layoutManager ?. onRestoreInstanceState ( recyclerViewState )
2019-07-26 13:31:31 +02:00
colourPickerDialog . dismiss ()
2019-05-14 22:28:45 +02:00
}
}
2019-07-26 13:31:31 +02:00
colourPickerDialog . show ()
2019-05-14 22:28:45 +02:00
}
2019-05-16 16:14:03 +02:00
private fun debugMenu (): Boolean {
2019-05-14 22:28:45 +02:00
DeviceName . with ( mContext ). request { deviceInfo , _ ->
name = deviceInfo . marketName
model = deviceInfo . model
}
2019-09-01 11:54:12 +02:00
val alertDialog = AlertDialog . Builder ( mContext ,
R . style . AlertDialog
)
2019-05-14 22:28:45 +02:00
val dialogView = LayoutInflater . from ( mContext ). inflate ( R . layout . edittext_dialog , null )
val dialogEditText = dialogView . findViewById < EditText >( R . id . dialog_edittext )
val dialogButton = dialogView . findViewById < Button >( R . id . dialog_button )
2019-09-01 11:54:12 +02:00
dialogView . findViewById < TextView >( R . id . textviewtitle ). text = getString (
R . string . experimentalMenu
)
dialogView . findViewById < TextView >( R . id . dialogtext ). text = getString (
R . string . menuForTests
)
2019-05-14 22:28:45 +02:00
dialogButton . setOnClickListener {
when ( dialogEditText . text . toString ()) {
2019-07-30 11:18:01 +02:00
"_DIAGNOSTICS" -> {
2019-06-02 17:57:57 +02:00
val alertDialogDev = AlertDialog . Builder ( mContext , R . style . AlertDialog )
2019-05-14 22:28:45 +02:00
val devDialogView = LayoutInflater . from ( mContext ). inflate ( R . layout . diagnostics_dialog , null )
val devDialogText = devDialogView . findViewById < TextView >( R . id . dialogtext )
val resetLaunchBtn = devDialogView . findViewById < Button >( R . id . btnResetLaunch )
2019-09-01 11:54:12 +02:00
val resetNotificationBtn = devDialogView . findViewById < Button >( R . id . btnResetNotif )
2019-05-14 22:28:45 +02:00
2019-09-01 11:54:12 +02:00
devDialogView . findViewById < TextView >( R . id . textviewtitle ). text = getString (
R . string . diagnosticsMenu
)
2019-05-14 22:28:45 +02:00
devDialogText . text = getDiagnosticsText ( prefs )
resetLaunchBtn . setOnClickListener {
edit . putInt ( "launchDev" , 0 ). apply ()
devDialogText . text = getDiagnosticsText ( prefs )
}
2019-09-01 11:54:12 +02:00
resetNotificationBtn . setOnClickListener {
2019-08-21 10:26:54 +02:00
edit . putInt ( "pingFB" , 0 ). apply ()
2019-05-14 22:28:45 +02:00
devDialogText . text = getDiagnosticsText ( prefs )
}
alertDialogDev . setView ( devDialogView )
alertDialogDev . show ()
}
"2018-04-20" -> {
try {
2019-07-06 14:18:59 +02:00
val intent = Intent ( Intent . ACTION_VIEW , Uri . parse ( "https://www.youtube.com/watch?v=Jc2xfYuLWgE" )) // Freak
2019-05-14 22:28:45 +02:00
intent . addFlags ( Intent . FLAG_ACTIVITY_NEW_TASK ). setPackage ( "com.google.android.youtube" )
startActivity ( intent )
} catch ( e : ActivityNotFoundException ) {
2019-09-01 11:54:12 +02:00
makeToast ( getString ( R . string . youtubeNotFound ))
2019-05-14 22:28:45 +02:00
}
}
2019-07-30 11:18:01 +02:00
"_NOTIFICATION" -> {
2019-08-21 10:26:54 +02:00
edit . putString ( "timeNew" , "" ). putString ( "timeFoodNew" , "" ). apply ()
2019-09-01 11:54:12 +02:00
makeToast ( "Notification times cleared" )
2019-05-22 20:33:07 +02:00
} // TODO add option to clear database
2019-07-30 11:18:01 +02:00
"_FIRSTTIME" -> {
2019-05-24 19:22:23 +02:00
edit . putBoolean ( "firstTime" , true ). apply ()
2019-09-01 11:54:12 +02:00
makeToast ( "First time flag cleared" )
2019-05-24 19:22:23 +02:00
}
2019-08-09 09:52:05 +02:00
"_TESTURLS" -> {
val currentTest = ! prefs . getBoolean ( "testUrls" , false )
edit . putBoolean ( "testUrls" , currentTest ). apply ()
2019-09-01 11:54:12 +02:00
makeToast ( "Test URLs set to $currentTest " )
2019-08-09 09:52:05 +02:00
}
2019-08-18 17:53:22 +02:00
"_DEVCHANNEL" -> {
val subbed = if ( prefs . getBoolean ( "subscribedToFBDebugChannel" , false )) {
2019-09-03 18:18:21 +02:00
unsubFromTopic ( "debug" )
2019-08-18 17:53:22 +02:00
"Unsubscribed from"
} else {
2019-09-03 18:18:21 +02:00
subToTopic ( "debug" )
2019-08-18 17:53:22 +02:00
"Subscribed to"
}
edit . putBoolean ( "subscribedToFBDebugChannel" , ! prefs . getBoolean ( "subscribedToFBDebugChannel" , false )). apply ()
2019-09-01 11:54:12 +02:00
makeToast ( " $subbed Firebase development channel" )
2019-08-18 17:53:22 +02:00
}
2019-08-23 13:13:52 +02:00
"_IOSCHANNEL" -> {
val subbed = if ( prefs . getBoolean ( "subscribedToiOSChannel" , false )) {
2019-09-03 18:18:21 +02:00
unsubFromTopic ( "ios" )
2019-08-23 13:13:52 +02:00
"Unsubscribed from"
} else {
2019-09-03 18:18:21 +02:00
subToTopic ( "ios" )
2019-08-23 13:13:52 +02:00
"Subscribed to"
}
edit . putBoolean ( "subscribedToiOSChannel" , ! prefs . getBoolean ( "subscribedToiOSChannel" , false )). apply ()
2019-09-01 11:54:12 +02:00
makeToast ( " $subbed iOS channel" )
2019-08-23 13:13:52 +02:00
}
2019-09-03 18:18:21 +02:00
"_WRITE" -> HelperFunctions . writePrefsToXml ( prefs , mContext , activity !! )
"_READ" -> HelperFunctions . readPrefsFromXml ( prefs , mContext , activity !! )
2019-09-01 11:54:12 +02:00
else -> makeToast ( getString ( R . string . invalidCode ))
2019-05-14 22:28:45 +02:00
}
}
2019-05-17 11:10:59 +02:00
alertDialog . setView ( dialogView )
alertDialog . show ()
2019-05-14 22:28:45 +02:00
return true
}
2019-09-01 11:54:12 +02:00
private fun makeToast ( text : String ) {
Toast . makeText ( mContext , text , Toast . LENGTH_LONG ). show ()
}
2019-05-14 22:28:45 +02:00
private fun getDiagnosticsText ( prefs : SharedPreferences ): String {
2019-08-21 10:26:54 +02:00
return "First Launch: ${prefs.getString("firstTimeDev", "")} " +
" \n\n App launched: ${prefs.getInt("launchDev", 0)} " +
" \n\n Firebase ping service fired: ${prefs.getInt("pingFB", 0)} " +
" \n\n Device Name: $name " +
" \n\n Device Model: $model " +
" \n\n Android Version: ${Build.VERSION.RELEASE} " +
" \n\n Subscribed to notification channel: ${prefs.getBoolean("notif", false)} " +
" \n\n Subscribed to dev channel: ${prefs.getBoolean("subscribedToFBDebugChannel", false)} "
2019-05-14 22:28:45 +02:00
}
2019-09-03 18:18:21 +02:00
private fun subToTopic ( topic : String ) = FirebaseMessaging . getInstance (). subscribeToTopic ( "substitutions- $topic " )
private fun unsubFromTopic ( topic : String ) = FirebaseMessaging . getInstance (). unsubscribeFromTopic ( "substitutions- $topic " )
2019-05-14 22:28:45 +02:00
}