Merge remote-tracking branch 'ns/adrian/single-click-kotlin' into dev
This commit is contained in:
commit
370c54a20b
|
@ -273,12 +273,13 @@ class ActionsFragment : DaggerFragment() {
|
|||
private fun checkPumpCustomActions() {
|
||||
val activePump = activePlugin.activePump
|
||||
val customActions = activePump.customActions ?: return
|
||||
val currentContext = context ?: return
|
||||
removePumpCustomActions()
|
||||
|
||||
for (customAction in customActions) {
|
||||
if (!customAction.isEnabled) continue
|
||||
|
||||
val btn = SingleClickButton(context, null, android.R.attr.buttonStyle)
|
||||
val btn = SingleClickButton(currentContext, null, android.R.attr.buttonStyle)
|
||||
btn.text = resourceHelper.gs(customAction.name)
|
||||
|
||||
val layoutParams = LinearLayout.LayoutParams(
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
package info.nightscout.androidaps.utils.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.SystemClock;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||
|
||||
/**
|
||||
* Created by mike on 22.12.2017.
|
||||
*/
|
||||
|
||||
public class SingleClickButton extends androidx.appcompat.widget.AppCompatButton implements View.OnClickListener {
|
||||
private static final Logger log = StacktraceLoggerWrapper.getLogger(SingleClickButton.class);
|
||||
|
||||
Context context;
|
||||
OnClickListener listener = null;
|
||||
|
||||
public SingleClickButton(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
super.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public SingleClickButton(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.context = context;
|
||||
super.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public SingleClickButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
this.context = context;
|
||||
super.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnClickListener(@Nullable OnClickListener l) {
|
||||
listener = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
setEnabled(false);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SystemClock.sleep(3000);
|
||||
Activity activity = (Activity) context;
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setEnabled(true);
|
||||
log.debug("Button enabled");
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
if (listener != null)
|
||||
listener.onClick(v);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package info.nightscout.androidaps.utils.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.R
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper.Companion.getLogger
|
||||
import org.slf4j.Logger
|
||||
|
||||
class SingleClickButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.buttonStyle) : AppCompatButton(context, attrs, defStyleAttr) {
|
||||
|
||||
override fun performClick(): Boolean = guardClick { super.performClick() }
|
||||
override fun callOnClick(): Boolean = guardClick { super.callOnClick() }
|
||||
|
||||
private fun guardClick(block: () -> Boolean): Boolean {
|
||||
isEnabled = false
|
||||
postDelayed({ isEnabled = true; log.debug("Button enabled") }, BUTTON_REFRACTION_PERIOD)
|
||||
return block()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val BUTTON_REFRACTION_PERIOD = 3000L
|
||||
private val log: Logger = getLogger(SingleClickButton::class.java)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue