Skip to content

Commit

Permalink
Optimize code and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Jun 15, 2021
1 parent 344f4d0 commit 74d307f
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 267 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ android {
packagingOptions {
pickFirst 'META-INF/library_release.kotlin_module'
}
buildFeatures {
viewBinding true
}
}

dependencies {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

<application
android:allowBackup="true"
Expand Down
123 changes: 62 additions & 61 deletions app/src/main/java/com/cyb3rko/logviewerforopenhab/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.cyb3rko.logviewerforopenhab
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.ActivityInfo
import android.net.Uri
import android.os.Bundle
import android.text.SpannableString
import android.text.Spanned
Expand Down Expand Up @@ -45,7 +44,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

Toasty.Config.getInstance().allowQueue(false).apply()
mySPR = getSharedPreferences(SHARED_PREFERENCE, 0)
mySPR = getSharedPreferences(SHARED_PREFERENCE, MODE_PRIVATE)
editor = mySPR.edit()
editor.apply()
AppCompatDelegate.setDefaultNightMode(mySPR.getString(NIGHTMODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString())!!.toInt())
Expand Down Expand Up @@ -85,63 +84,7 @@ class MainActivity : AppCompatActivity() {
R.id.nav_settings -> navController.navigate(R.id.nav_settings)
R.id.drawer_about -> navController.navigate(R.id.nav_about)
R.id.drawer_end_user_consent -> {
var dialogMessage = getString(R.string.end_user_consent_2_message_1)
dialogMessage += mySPR.getString(CONSENT_DATE, getString(R.string.end_user_consent_2_date_not_found)) +
getString(R.string.end_user_consent_2_message_2) +
mySPR.getString(CONSENT_TIME, getString(R.string.end_user_consent_2_time_not_found))
val spannableString = SpannableString(dialogMessage)
val drawerMenu = navView.menu
val clickableSpan1 = object : ClickableSpan() {
override fun onClick(view: View) {
showLicenseDialog(this@MainActivity, PRIVACY_POLICY)
}
}
val clickableSpan2 = object : ClickableSpan() {
override fun onClick(view: View) {
showLicenseDialog(this@MainActivity, TERMS_OF_USE)
}
}
var currentText = getString(R.string.end_user_consent_2_privacy_policy)
var index = dialogMessage.indexOf(currentText)
spannableString.setSpan(
clickableSpan1, index, index + currentText.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
currentText = getString(R.string.end_user_consent_2_terms_of_use)
index = dialogMessage.indexOf(currentText)
spannableString.setSpan(
clickableSpan2, index, index + currentText.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
currentText = getString(R.string.end_user_consent_2_date)
index = dialogMessage.indexOf(currentText)
for (i in 0..1) {
spannableString.setSpan(UnderlineSpan(), index, index + currentText.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
currentText = getString(R.string.end_user_consent_2_date)
index = dialogMessage.indexOf(currentText)
}

MaterialDialog(this).show {
title(R.string.end_user_consent_2_title)
message(0, spannableString) {
messageTextView.movementMethod = LinkMovementMethod.getInstance()
}
positiveButton(android.R.string.ok) {
drawerMenu.findItem(R.id.drawer_end_user_consent).isChecked = false
}
negativeButton(R.string.end_user_consent_2_button_2) {
val analytics = FirebaseAnalytics.getInstance(applicationContext)
analytics.resetAnalyticsData()
analytics.setAnalyticsCollectionEnabled(false)
val crashlytics = FirebaseCrashlytics.getInstance()
crashlytics.deleteUnsentReports()
crashlytics.setCrashlyticsCollectionEnabled(false)
editor.clear().commit()
finish()
startActivity(Intent(applicationContext, this@MainActivity::class.java))
}
onCancel {
drawerMenu.findItem(R.id.drawer_end_user_consent).isChecked = false
}
}
showEndUserConsent()
}
}
it.isChecked = true
Expand All @@ -153,8 +96,66 @@ class MainActivity : AppCompatActivity() {
requestReview()
}

private fun restoreConnections() {
showConnections(mySPR, getListOfConnections(mySPR), this)
private fun restoreConnections() = showConnections(mySPR, getListOfConnections(mySPR), this)

private fun showEndUserConsent() {
var dialogMessage = getString(R.string.end_user_consent_2_message_1)
dialogMessage += mySPR.getString(CONSENT_DATE, getString(R.string.end_user_consent_2_date_not_found)) +
getString(R.string.end_user_consent_2_message_2) +
mySPR.getString(CONSENT_TIME, getString(R.string.end_user_consent_2_time_not_found))
val spannableString = SpannableString(dialogMessage)
val drawerMenu = navView.menu
val clickableSpan1 = object : ClickableSpan() {
override fun onClick(view: View) {
showLicenseDialog(this@MainActivity, PRIVACY_POLICY)
}
}
val clickableSpan2 = object : ClickableSpan() {
override fun onClick(view: View) {
showLicenseDialog(this@MainActivity, TERMS_OF_USE)
}
}
var currentText = getString(R.string.end_user_consent_2_privacy_policy)
var index = dialogMessage.indexOf(currentText)
spannableString.setSpan(
clickableSpan1, index, index + currentText.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
currentText = getString(R.string.end_user_consent_2_terms_of_use)
index = dialogMessage.indexOf(currentText)
spannableString.setSpan(
clickableSpan2, index, index + currentText.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
currentText = getString(R.string.end_user_consent_2_date)
index = dialogMessage.indexOf(currentText)
repeat(2) {
spannableString.setSpan(UnderlineSpan(), index, index + currentText.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
currentText = getString(R.string.end_user_consent_2_time)
index = dialogMessage.indexOf(currentText)
}

MaterialDialog(this).show {
title(R.string.end_user_consent_2_title)
message(text = spannableString) {
messageTextView.movementMethod = LinkMovementMethod.getInstance()
}
positiveButton(android.R.string.ok) {
drawerMenu.findItem(R.id.drawer_end_user_consent).isChecked = false
}
negativeButton(R.string.end_user_consent_2_button_2) {
val analytics = FirebaseAnalytics.getInstance(applicationContext)
analytics.resetAnalyticsData()
analytics.setAnalyticsCollectionEnabled(false)
val crashlytics = FirebaseCrashlytics.getInstance()
crashlytics.deleteUnsentReports()
crashlytics.setCrashlyticsCollectionEnabled(false)
editor.clear().commit()
finish()
startActivity(Intent(applicationContext, this@MainActivity::class.java))
}
onCancel {
drawerMenu.findItem(R.id.drawer_end_user_consent).isChecked = false
}
}
}

private fun requestReview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,33 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CheckBox
import androidx.fragment.app.Fragment
import com.cyb3rko.logviewerforopenhab.PRIVACY_POLICY
import com.cyb3rko.logviewerforopenhab.R
import com.cyb3rko.logviewerforopenhab.TERMS_OF_USE
import com.cyb3rko.logviewerforopenhab.databinding.FragmentAppintro3Binding
import com.cyb3rko.logviewerforopenhab.showLicenseDialog
import com.github.appintro.SlidePolicy
import es.dmoral.toasty.Toasty

class AppIntro3rdFragment : Fragment(), SlidePolicy {
private var _binding: FragmentAppintro3Binding? = null
// This property is only valid between onCreateView and onDestroyView.
private val binding get() = _binding!!

private lateinit var button1: Button
private lateinit var button2: Button
private lateinit var checkBox1: CheckBox
private lateinit var checkBox2: CheckBox

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?)
: View = inflater.inflate(R.layout.fragment_appintro3, container, false)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentAppintro3Binding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
button1 = view.findViewById(R.id.terms_of_use_button)
button2 = view.findViewById(R.id.privacy_policy_button)
checkBox1 = view.findViewById(R.id.terms_of_use_check)
checkBox2 = view.findViewById(R.id.privacy_policy_check)

button1.setOnClickListener { showLicenseDialog(context, TERMS_OF_USE) }
button2.setOnClickListener { showLicenseDialog(context, PRIVACY_POLICY) }
binding.termsOfUseButton.setOnClickListener { showLicenseDialog(context, TERMS_OF_USE) }
binding.privacyPolicyButton.setOnClickListener { showLicenseDialog(context, PRIVACY_POLICY) }
}

override val isPolicyRespected: Boolean
get() = (checkBox1.isChecked && checkBox2.isChecked)
get() = (binding.termsOfUseCheck.isChecked && binding.privacyPolicyCheck.isChecked)

override fun onUserIllegallyRequestedNextPage() {
Toasty.error(requireContext(), getString(R.string.intro_fragment3_toast), Toasty.LENGTH_SHORT).show()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
package com.cyb3rko.logviewerforopenhab.appintro

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import androidx.fragment.app.Fragment
import com.cyb3rko.logviewerforopenhab.ANALYTICS_COLLECTION
import com.cyb3rko.logviewerforopenhab.CRASHLYTICS_COLLECTION
import com.cyb3rko.logviewerforopenhab.R
import com.cyb3rko.logviewerforopenhab.SHARED_PREFERENCE
import com.cyb3rko.logviewerforopenhab.databinding.FragmentAppintro4Binding

class AppIntro4thFragment : Fragment() {
private var _binding: FragmentAppintro4Binding? = null
// This property is only valid between onCreateView and onDestroyView.
private val binding get() = _binding!!

private lateinit var checkBox1: CheckBox
private lateinit var checkBox2: CheckBox

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?)
: View = inflater.inflate(R.layout.fragment_appintro4, container, false)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = FragmentAppintro4Binding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
checkBox1 = view.findViewById(R.id.analytics_check)
checkBox2 = view.findViewById(R.id.crashlytics_check)

val mySPR = requireContext().getSharedPreferences(SHARED_PREFERENCE, 0)
val mySPR = requireContext().getSharedPreferences(SHARED_PREFERENCE, Context.MODE_PRIVATE)
val editor = mySPR.edit()

checkBox1.setOnCheckedChangeListener { _, b ->
binding.analyticsCheck.setOnCheckedChangeListener { _, b ->
editor.putBoolean(ANALYTICS_COLLECTION, b).apply()
}

checkBox2.setOnCheckedChangeListener { _, b ->
binding.crashlyticsCheck.setOnCheckedChangeListener { _, b ->
editor.putBoolean(CRASHLYTICS_COLLECTION, b).apply()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import android.os.Bundle
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment
import com.cyb3rko.logviewerforopenhab.*
import com.cyb3rko.logviewerforopenhab.CONSENT_TIME
import com.cyb3rko.logviewerforopenhab.FIRST_START
import com.cyb3rko.logviewerforopenhab.SHARED_PREFERENCE
import com.github.appintro.AppIntro
import com.github.appintro.AppIntroFragment
import com.github.appintro.AppIntroPageTransformerType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.cyb3rko.logviewerforopenhab.R

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
Loading

0 comments on commit 74d307f

Please sign in to comment.