-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lucky
committed
Aug 29, 2022
1 parent
6fc8fa3
commit 957bec3
Showing
20 changed files
with
295 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/src/main/java/me/lucky/wasted/fragment/RecastFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package me.lucky.wasted.fragment | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.core.widget.doAfterTextChanged | ||
import androidx.fragment.app.Fragment | ||
|
||
import me.lucky.wasted.Preferences | ||
import me.lucky.wasted.databinding.FragmentRecastBinding | ||
|
||
class RecastFragment : Fragment() { | ||
private lateinit var binding: FragmentRecastBinding | ||
private lateinit var ctx: Context | ||
private lateinit var prefs: Preferences | ||
private lateinit var prefsdb: Preferences | ||
|
||
private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> | ||
prefs.copyTo(prefsdb, key) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
binding = FragmentRecastBinding.inflate(inflater, container, false) | ||
init() | ||
setup() | ||
return binding.root | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
prefs.registerListener(prefsListener) | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
prefs.unregisterListener(prefsListener) | ||
} | ||
|
||
private fun init() { | ||
ctx = requireContext() | ||
prefs = Preferences(ctx) | ||
prefsdb = Preferences(ctx, encrypted = false) | ||
binding.apply { | ||
enabled.isChecked = prefs.isRecastEnabled | ||
action.editText?.setText(prefs.recastAction) | ||
receiver.editText?.setText(prefs.recastReceiver) | ||
extraKey.editText?.setText(prefs.recastExtraKey) | ||
extraValue.editText?.setText(prefs.recastExtraValue) | ||
} | ||
} | ||
|
||
private fun setup() = binding.apply { | ||
enabled.setOnCheckedChangeListener { _, isChecked -> | ||
prefs.isRecastEnabled = isChecked | ||
} | ||
action.editText?.doAfterTextChanged { | ||
prefs.recastAction = it?.toString()?.trim() ?: return@doAfterTextChanged | ||
} | ||
receiver.editText?.doAfterTextChanged { | ||
prefs.recastReceiver = it?.toString()?.trim() ?: return@doAfterTextChanged | ||
} | ||
extraKey.editText?.doAfterTextChanged { | ||
prefs.recastExtraKey = it?.toString()?.trim() ?: return@doAfterTextChanged | ||
} | ||
extraValue.editText?.doAfterTextChanged { | ||
prefs.recastExtraValue = it?.toString()?.trim() ?: return@doAfterTextChanged | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.