From fce1bdd1facf4ac4f38e8533254f95bbb9e224f7 Mon Sep 17 00:00:00 2001 From: X1nto Date: Wed, 20 May 2020 00:39:03 +0400 Subject: [PATCH] attempt to fix 5 times touch detection --- .../vanced/manager/core/fragments/About.kt | 5 +- .../manager/core/fragments/about_7tap.java | 59 ------------------- .../com/vanced/manager/ui/MainActivity.kt | 13 ++-- .../main/res/layout/include_about_header.xml | 1 + 4 files changed, 11 insertions(+), 67 deletions(-) delete mode 100644 app/src/main/java/com/vanced/manager/core/fragments/about_7tap.java diff --git a/app/src/main/java/com/vanced/manager/core/fragments/About.kt b/app/src/main/java/com/vanced/manager/core/fragments/About.kt index 7857ad8d..b3585c08 100644 --- a/app/src/main/java/com/vanced/manager/core/fragments/About.kt +++ b/app/src/main/java/com/vanced/manager/core/fragments/About.kt @@ -6,6 +6,7 @@ import android.os.Bundle import android.view.MotionEvent import android.view.View import android.widget.Button +import android.widget.LinearLayout import android.widget.Toast import androidx.preference.PreferenceManager import com.google.android.material.card.MaterialCardView @@ -21,8 +22,8 @@ open class About : BaseFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val aboutHeader: MaterialCardView = view.findViewById(R.id.about_header_wrapper) - aboutHeader.setOnTouchListener { _: View?, event: MotionEvent -> + val aboutHeader: LinearLayout = view.findViewById(R.id.about_header_layout) + aboutHeader.setOnTouchListener { _, event: MotionEvent -> val eventAction = event.action if (eventAction == MotionEvent.ACTION_UP) { diff --git a/app/src/main/java/com/vanced/manager/core/fragments/about_7tap.java b/app/src/main/java/com/vanced/manager/core/fragments/about_7tap.java deleted file mode 100644 index 05725b15..00000000 --- a/app/src/main/java/com/vanced/manager/core/fragments/about_7tap.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.vanced.manager.core.fragments; - -import android.annotation.SuppressLint; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.MotionEvent; -import android.view.View; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.preference.PreferenceManager; - -import com.google.android.material.card.MaterialCardView; -import com.vanced.manager.R; -import com.vanced.manager.core.base.BaseFragment; - -//This java code is stinky -public class about_7tap extends BaseFragment { - - private int count = 0; - private long startMillSec = 0; - - @SuppressLint("ClickableViewAccessibility") - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - MaterialCardView aboutHeader = requireView().findViewById(R.id.about_header_wrapper); - aboutHeader.setOnTouchListener((v, event) -> { - - int eventAction = event.getAction(); - if (eventAction == MotionEvent.ACTION_UP) { - long time = System.currentTimeMillis(); - if (startMillSec == 0 || (time - startMillSec > 3000)) { - - startMillSec = time; - count = 1; - - } else { - count++; - } - - if (count == 5) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireContext()); - prefs.edit().putBoolean("devSettings", true).apply(); - - } - - return true; - } - - return false; - }); - - } - - - -} diff --git a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt index e4956aa2..8e5dc978 100644 --- a/app/src/main/java/com/vanced/manager/ui/MainActivity.kt +++ b/app/src/main/java/com/vanced/manager/ui/MainActivity.kt @@ -29,8 +29,8 @@ class MainActivity : Main() { val appBarConfiguration = AppBarConfiguration(navHost.graph) toolbar.setupWithNavController(navHost, appBarConfiguration) - navHost.addOnDestinationChangedListener{_, currfrag: NavDestination, _ -> - isParent = when (currfrag.id) { + navHost.addOnDestinationChangedListener{_, currFrag: NavDestination, _ -> + isParent = when (currFrag.id) { R.id.home_fragment -> true else -> false } @@ -44,7 +44,7 @@ class MainActivity : Main() { override fun onOptionsItemSelected(item: MenuItem): Boolean { val navHost = findNavController(R.id.bottom_nav_host) val prefs = PreferenceManager.getDefaultSharedPreferences(this) - val devSettings = prefs.getBoolean("devSettings", true) + val devSettings = prefs.getBoolean("devSettings", false) when (item.itemId) { android.R.id.home -> { onBackPressed() @@ -63,10 +63,11 @@ class MainActivity : Main() { return true } R.id.dev_settings -> { - if (devSettings) { + return if (devSettings) { navHost.navigate(R.id.toDevSettingsFragment) - return true - } else super.onOptionsItemSelected(item) + true + } else + false } else -> super.onOptionsItemSelected(item) diff --git a/app/src/main/res/layout/include_about_header.xml b/app/src/main/res/layout/include_about_header.xml index e7887ce6..4e22d073 100644 --- a/app/src/main/res/layout/include_about_header.xml +++ b/app/src/main/res/layout/include_about_header.xml @@ -7,6 +7,7 @@ app:cardCornerRadius="8dp">