0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-23 03:35:11 +00:00

attempt to fix 5 times touch detection

This commit is contained in:
X1nto 2020-05-20 00:39:03 +04:00
parent 8e4e64cdf8
commit fce1bdd1fa
4 changed files with 11 additions and 67 deletions

View file

@ -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) {

View file

@ -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;
});
}
}

View file

@ -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)

View file

@ -7,6 +7,7 @@
app:cardCornerRadius="8dp">
<LinearLayout
android:id="@+id/about_header_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rectangle_2"