Skip to content

Commit

Permalink
Remove uneeded object creations + method calls in KindnessFragment...
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmold committed Jan 25, 2024
1 parent ad083fd commit 4e7a97d
Showing 1 changed file with 17 additions and 31 deletions.
48 changes: 17 additions & 31 deletions app/src/main/java/org/torproject/android/KindnessFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat
import org.torproject.android.core.putNotSystem
import org.torproject.android.service.OrbotConstants
import org.torproject.android.service.OrbotService
import org.torproject.android.service.util.Prefs

class KindnessFragment : Fragment() {

private lateinit var tvAlltimeTotal: TextView;
private lateinit var tvAllTimeTotal: TextView;
private lateinit var tvWeeklyTotal: TextView;
private lateinit var swVolunteerMode: SwitchCompat;
private lateinit var btnActionActivate: Button;
Expand All @@ -26,15 +27,14 @@ class KindnessFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_kindness, container, false)
tvAlltimeTotal = view.findViewById(R.id.tvAlltimeTotal)
tvAllTimeTotal = view.findViewById(R.id.tvAlltimeTotal)
tvWeeklyTotal = view.findViewById(R.id.tvWeeklyTotal)
swVolunteerMode = view.findViewById(R.id.swVolunteerMode)
btnActionActivate = view.findViewById(R.id.btnActionActivate)
pnlActivate = view.findViewById(R.id.panel_kindness_activate)
pnlStatus = view.findViewById(R.id.panel_kindness_status)
tvAlltimeTotal.text = Prefs.getSnowflakesServed().toString()
tvAllTimeTotal.text = Prefs.getSnowflakesServed().toString()
tvWeeklyTotal.text = (Prefs.getSnowflakesServedWeekly()).toString()

swVolunteerMode.isChecked = Prefs.beSnowflakeProxy()
Expand All @@ -45,55 +45,41 @@ class KindnessFragment : Fragment() {
}

view.findViewById<TextView>(R.id.swVolunteerAdjust).setOnClickListener {
KindessConfigBottomSheet().show(
requireActivity().supportFragmentManager, CustomBridgeBottomSheet.TAG
)
KindessConfigBottomSheet().show(requireActivity().supportFragmentManager, CustomBridgeBottomSheet.TAG)
}

btnActionActivate.setOnClickListener {
swVolunteerMode.isChecked = true
Prefs.setBeSnowflakeProxy(true)
sendIntentToService(OrbotConstants.CMD_ACTIVE)
}

showPanelStatus(Prefs.beSnowflakeProxy())

return view
}

private fun sendIntentToService(intent: Intent) =
ContextCompat.startForegroundService(requireContext(), intent.putNotSystem())

private fun sendIntentToService(action: String) = sendIntentToService(Intent(
requireContext(), org.torproject.android.service.OrbotService::class.java
).apply {
this.action = action
})
private fun sendIntentToService(action: String) {
val intent = Intent(requireContext(), OrbotService::class.java)
.setAction(action)
.putNotSystem()
ContextCompat.startForegroundService(requireContext(), intent)
}

private fun showPanelStatus(isActivated: Boolean) {

val duration = 250L

if (isActivated) {

pnlActivate.animate().alpha(0f).setDuration(duration).withEndAction {
pnlActivate.visibility = View.GONE
}
pnlActivate.visibility = View.GONE
}

pnlStatus.visibility = View.VISIBLE
pnlStatus.animate().alpha(1f).setDuration(duration).withEndAction {

}


pnlStatus.animate().alpha(1f).duration = duration
} else {
pnlActivate.visibility = View.VISIBLE
pnlActivate.animate().alpha(1f).setDuration(duration).withEndAction {}
pnlActivate.animate().alpha(1f).duration = duration

pnlStatus.animate().alpha(0f).setDuration(duration).withEndAction {
pnlStatus.visibility = View.GONE
}

pnlStatus.visibility = View.GONE
}
}
}
}

0 comments on commit 4e7a97d

Please sign in to comment.