Skip to content

gzeinnumer/CheckBeforeIntent

Repository files navigation

Check Before Intent - Check Form Before Leave Activity


Check Form Before Leave Activity


Content List


Download

Add maven jitpack.io and dependencies in build.gradle (Project) :

// build.gradle project
allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

// build.gradle app/module
dependencies {
  ...
  implementation 'com.github.gzeinnumer:CheckBeforeIntent:version'
}

Feature List


Usage

Check Form Before Leave Activity

Use .addView(editText) to add view that you want to check

  • Single View
new CheckBeforeIntent()
    .addView(editText1)
    .isSaveToLeave(...).build();

Example

EditText editText1 = findViewById(R.id.ed1);
EditText editText2 = findViewById(R.id.ed2);
Button btn = findViewById(R.id.btn);

btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        new CheckBeforeIntent()
                .addView(editText1)
                .addView(editText2)
                .isSaveToLeave(new CheckBeforeIntent.CheckBeforeIntentCallBack() {
                    @Override
                    public void isSaveToLeave(boolean isSave) {
                        if (isSave) //true -> free to lease
                            startActivity(new Intent(getApplicationContext(), MainActivity.class));
                        else //false -> not free to leave
                            Toast.makeText(MainActivity.this, "Are you sure leave the activity", Toast.LENGTH_SHORT).show();
                    }
                }).build();

    }
});
  • Multiple View
new CheckBeforeIntent()
    .addView(editText1)
    .addView(editText2)
    .isSaveToLeave(...).build();
List<View> views = new ArrayList<>();
...
new CheckBeforeIntent()
    .addView(views)
    .isSaveToLeave(...).build();
View[] views = new View[size];
...
new CheckBeforeIntent()
    .addView(views)
    .isSaveToLeave(...).build();

FullCode MainActivity


Example Code/app

Sample Code And App


Version

  • 1.0.0
    • First Release

Contribution

You can sent your constibution to branch open-pull.


Copyright 2021 M. Fadli Zein

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages