content: /*
   * Copyright 2020 Andrey Novikov
   *
   * This program is free software: you can redistribute it and/or modify it under the
   * terms of the GNU Lesser General Public License as published by the Free Software
   * Foundation, either version 3 of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful, but WITHOUT ANY
   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License along with
   * this program. If not, see <http://www.gnu.org/licenses/>.
   *
   */
  
  package mobi.maptrek.ui;
  
  import android.view.View;
  
  public abstract class DoubleClickListener implements View.OnClickListener {
  
      private static final long DOUBLE_CLICK_TIME_DELTA = 300;
  
      private long lastClickTime = 0;
      private boolean isSingleClick = true;
  
      @Override
      public void onClick(View v) {
          long clickTime = System.currentTimeMillis();
          if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA) {
              onDoubleClick(v);
              isSingleClick = false;
          } else {
              isSingleClick = true;
          }
  
          v.postDelayed(() -> {
              if(isSingleClick)
                  onSingleClick(v);
          }, DOUBLE_CLICK_TIME_DELTA);
  
          lastClickTime = clickTime;
      }
  
      public abstract void onSingleClick(View v);
      public abstract void onDoubleClick(View v);
  }