Skip to content

Commit

Permalink
Reformat codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Sep 24, 2022
1 parent eb649a0 commit 07b7f07
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 89 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/com/cyb3rko/logviewerforopenhab/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class App: Application() {
override fun onCreate() {
super.onCreate()
val mySPR = getSharedPreferences(SHARED_PREFERENCE, MODE_PRIVATE)
AppCompatDelegate.setDefaultNightMode(mySPR.getString(NIGHTMODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString())!!.toInt())
AppCompatDelegate.setDefaultNightMode(
mySPR.getString(
NIGHTMODE,
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString()
)!!.toInt()
)

setWebViewDataDirectorySuffix()
}
Expand All @@ -37,4 +42,4 @@ class App: Application() {
}
return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ internal data class Connection(
return Connection(parts1[0] == "https", parts2[0], parts2[1].toInt())
}
}
}
}
12 changes: 10 additions & 2 deletions app/src/main/java/com/cyb3rko/logviewerforopenhab/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class MainActivity : AppCompatActivity() {
editor = mySPR.edit()
editor.apply()

requestedOrientation = mySPR.getString(ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED.toString())?.toInt()!!
requestedOrientation = mySPR.getString(
ORIENTATION,
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED.toString()
)?.toInt()!!

setContentView(R.layout.activity_main)
toolbar = findViewById(R.id.toolbar)
Expand All @@ -58,7 +61,12 @@ class MainActivity : AppCompatActivity() {
appBarConfiguration = AppBarConfiguration(setOf(R.id.nav_menu), drawerLayout)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
val drawerToggle = ActionBarDrawerToggle(this, drawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
val drawerToggle = ActionBarDrawerToggle(
this,
drawerLayout,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)
drawerLayout.addDrawerListener(drawerToggle)

if (mySPR.getBoolean(FIRST_START, true) || mySPR.getString(CONSENT_DATE, "") == "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class AppIntro3rdFragment : Fragment(), SlidePolicy {
// This property is only valid between onCreateView and onDestroyView.
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentAppintro3Binding.inflate(inflater, container, false)
return binding.root
}
Expand All @@ -40,4 +44,4 @@ class AppIntro3rdFragment : Fragment(), SlidePolicy {
return AppIntro3rdFragment()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class AppIntro4thFragment : Fragment() {
// This property is only valid between onCreateView and onDestroyView.
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentAppintro4Binding.inflate(inflater, container, false)
return binding.root
}
Expand All @@ -40,4 +44,4 @@ class AppIntro4thFragment : Fragment() {
return AppIntro4thFragment()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class MyAppIntro : AppIntro() {
val mySPR = applicationContext.getSharedPreferences(SHARED_PREFERENCE, 0)
val editor = mySPR.edit()

FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(mySPR.getBoolean(ANALYTICS_COLLECTION, true))
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(mySPR.getBoolean(CRASHLYTICS_COLLECTION, true))
FirebaseAnalytics.getInstance(this)
.setAnalyticsCollectionEnabled(mySPR.getBoolean(ANALYTICS_COLLECTION, true))
FirebaseCrashlytics.getInstance()
.setCrashlyticsCollectionEnabled(mySPR.getBoolean(CRASHLYTICS_COLLECTION, true))

val date = Calendar.getInstance().time
@SuppressLint("SimpleDateFormat") val sDF = SimpleDateFormat("yyyy-MM-dd")
Expand All @@ -64,4 +66,4 @@ class MyAppIntro : AppIntro() {
finish()
startActivity(Intent(applicationContext, MainActivity::class.java))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import mehdi.sakout.aboutpage.Element

class AboutFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val githubIcon = mehdi.sakout.aboutpage.R.drawable.about_icon_github
val emailIcon = mehdi.sakout.aboutpage.R.drawable.about_icon_email
val instagramIcon = mehdi.sakout.aboutpage.R.drawable.about_icon_instagram
Expand All @@ -27,88 +31,81 @@ class AboutFragment : Fragment() {
.setImage(R.mipmap.ic_launcher_foreground)
.setDescription(getString(R.string.about_description))
.addItem(
Element().setTitle(String.format(getString(R.string.about_element_version), BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE))
.setIconDrawable(githubIcon).setOnClickListener(showChangelog())
Element(
String.format(
getString(R.string.about_element_version),
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE
),
githubIcon
).setOnClickListener { openUrl(getString(R.string.about_changelog_link)) }
)
.addGroup(getString(R.string.about_group_legal))
.addItem(
Element().setTitle(getString(R.string.about_element_libraries)).setIconDrawable(R.drawable._ic_libraries)
.setOnClickListener(showLibraries())
Element(
getString(R.string.about_element_libraries),
R.drawable._ic_libraries
).setOnClickListener { showLibraries() }
)
.addItem(
Element().setTitle(getString(R.string.about_element_icons)).setIconDrawable(R.drawable._ic_question).setOnClickListener(showIcons())
Element(
getString(R.string.about_element_icons),
R.drawable._ic_question
).setOnClickListener { findNavController().navigate(R.id.nav_about_icons) }
)
.addItem(
Element().setTitle(getString(R.string.about_element_animations)).setIconDrawable(R.drawable._ic_question)
.setOnClickListener(showAnimations())
Element(
getString(R.string.about_element_animations),
R.drawable._ic_question
).setOnClickListener { findNavController().navigate(R.id.nav_about_animations) }
)
.addGroup(getString(R.string.about_group_connect))
.addItem(
Element().setTitle(getString(R.string.about_element_feedback_text)).setIconDrawable(githubIcon)
.setOnClickListener(openGithubFeedback())
Element(
getString(R.string.about_element_feedback_text),
githubIcon
).setOnClickListener { openUrl("https://github.com/cyb3rko/logviewer-for-openhab-app/") }
)
.addItem(
Element().setTitle(getString(R.string.about_element_email_text)).setIconDrawable(emailIcon)
.setOnClickListener(writeEmail())
Element(
getString(R.string.about_element_email_text),
emailIcon
).setOnClickListener { writeEmail() }
)
.addItem(
Element().setTitle(getString(R.string.about_element_github_text))
.setIconDrawable(githubIcon).setOnClickListener(openGithubProfile())
Element(
getString(R.string.about_element_github_text),
githubIcon
).setOnClickListener { openUrl("https://github.com/cyb3rko/") }
)
.addItem(
Element().setTitle(getString(R.string.about_element_instagram_text)).setIconDrawable(instagramIcon)
.setIconTint(instagramColor).setOnClickListener(openInstaPage())
Element(
getString(R.string.about_element_instagram_text),
instagramIcon
)
.setIconTint(instagramColor)
.setOnClickListener { openUrl("https://instagram.com/_u/cyb3rko") }
)
.create()
}

private fun showChangelog(): View.OnClickListener {
return View.OnClickListener { openUrl(getString(R.string.about_changelog_link)) }
}

private fun showLibraries(): View.OnClickListener {
return View.OnClickListener {
context?.let { validContext ->
LibsBuilder()
.withLicenseShown(true)
.withAboutIconShown(false)
.withAboutVersionShown(false)
.withActivityTitle(getString(R.string.about_element_libraries))
.withSearchEnabled(true)
.start(validContext)
}
private fun showLibraries() {
context?.let { validContext ->
LibsBuilder()
.withLicenseShown(true)
.withAboutIconShown(false)
.withAboutVersionShown(false)
.withActivityTitle(getString(R.string.about_element_libraries))
.withSearchEnabled(true)
.start(validContext)
}
}

private fun showIcons(): View.OnClickListener {
return View.OnClickListener { findNavController().navigate(R.id.nav_about_icons) }
}

private fun showAnimations(): View.OnClickListener {
return View.OnClickListener { findNavController().navigate(R.id.nav_about_animations) }
}

private fun openGithubFeedback(): View.OnClickListener {
return View.OnClickListener { openUrl("https://github.com/cyb3rko/logviewer-for-openhab-app/") }
}

private fun openGithubProfile(): View.OnClickListener {
return View.OnClickListener { openUrl("https://github.com/cyb3rko/") }
}

private fun openInstaPage(): View.OnClickListener {
return View.OnClickListener { openUrl("https://instagram.com/_u/cyb3rko") }
}

private fun writeEmail(): View.OnClickListener {
return View.OnClickListener {
val intent = Intent().apply {
this.action = Intent.ACTION_SENDTO
this.type = "text/plain"
this.data = Uri.parse("mailto:")
this.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
}
startActivity(intent)
private fun writeEmail() {
val intent = Intent(Intent.ACTION_SENDTO).apply {
setDataAndType(Uri.parse("mailto:"), "text/plain")
putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
}
startActivity(intent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import com.cyb3rko.logviewerforopenhab.openUrl

class AnimationCreditsFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val information = listOf(
Triple("error lottie", "koh", "https://lottiefiles.com/17373-error-lottie"),
Triple("Face scanning", "Aneesh Ravi", "https://lottiefiles.com/4432-face-scanning"),
Expand Down Expand Up @@ -49,4 +53,4 @@ class AnimationCreditsFragment : Fragment() {
view.addView(linearLayout)
return view
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import com.cyb3rko.logviewerforopenhab.R

class IconCreditsFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return context?.let { AboutIcons(it, R.drawable::class.java, parentFragmentManager).get() }
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return AboutIcons(
requireContext(),
R.drawable::class.java,
parentFragmentManager
).get()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class MainFragment : Fragment() {
myContext = context
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentMainBinding.inflate(inflater, container, false)
val root = binding.root

Expand Down Expand Up @@ -166,7 +170,11 @@ class MainFragment : Fragment() {
findNavController().navigate(R.id.nav_webview)

if (mySPR.getBoolean(CONNECTION_OVERVIEW_ENABLED, true)) {
storeAndShowConnection((binding.httpToggles[1] as MaterialButton).isChecked, tempHostname, tempPort.toInt())
storeAndShowConnection(
(binding.httpToggles[1] as MaterialButton).isChecked,
tempHostname,
tempPort.toInt()
)
}
}
} else {
Expand All @@ -175,7 +183,11 @@ class MainFragment : Fragment() {
}
}

private fun storeAndShowConnection(httpsActivated: Boolean, hostname: String, port: Int) {
private fun storeAndShowConnection(
httpsActivated: Boolean,
hostname: String,
port: Int
) {
val newConnection = Connection(httpsActivated, hostname, port)
val connections = getListOfConnections(mySPR)
if (!connections.contains(newConnection)) {
Expand Down Expand Up @@ -210,4 +222,4 @@ class MainFragment : Fragment() {
editor.putBoolean(AUTO_START, b).apply()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ class PreferenceFragment : PreferenceFragmentCompat() {
true
}
ANALYTICS_COLLECTION -> {
FirebaseAnalytics.getInstance(requireContext()).setAnalyticsCollectionEnabled(analyticsCollectionSwitch.isChecked)
FirebaseAnalytics.getInstance(requireContext())
.setAnalyticsCollectionEnabled(analyticsCollectionSwitch.isChecked)
true
}
CRASHLYTICS_COLLECTION -> {
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(crashlyticsCollectionSwitch.isChecked)
FirebaseCrashlytics.getInstance()
.setCrashlyticsCollectionEnabled(crashlyticsCollectionSwitch.isChecked)
true
}
DATA_DELETION -> {
Expand All @@ -146,4 +148,4 @@ class PreferenceFragment : PreferenceFragmentCompat() {
else -> false
}
}
}
}
Loading

0 comments on commit 07b7f07

Please sign in to comment.