Skip to content

App Factory for Android (Android MVP, Function Programming)

Notifications You must be signed in to change notification settings

skaengus2012/Ndroid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

Ndroid

Ndroid is util library, which is supported Android MVP, Lambda combination in alpha version.

First, I suggest android MVP because we can separate data model, control and view.
But we need to share activity instance in presenter and I think that will be induce memory leak in specific situation.
So we need to weak reference has-a relation.

So I made NxPresenter, which is auto weak-ref between activity and presenter. And I support NxActivity & NxModeler, which are abstract class for comfortable develop.

blog url : http://doohyun.tistory.com/38
example : https://github.com/skaengus2012/Ndroid#android-mvp

Secondly, I made Lambda combination util for Android. Android support default method in JAVA8 at API >= 24.
So we can use lambda, but we can not combination default and static method.
And I tried to find that in Rx, but I could not find.

So I published LambdaUtil for combination. We can build lambda.

blog url : http://doohyun.tistory.com/45
example : https://github.com/skaengus2012/N-java#lambda-combination

And I will make new function for this library. Please check support Function.
Index : https://github.com/skaengus2012/Ndroid#support-function

Thank you!!

Getting started

STEP1 : Add it in your root build.gradle at the end of repositories:

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

STEP2 : Add the dependency:

dependencies {
    compile 'com.github.skaengus2012:Ndroid:v0.5.2-beta'
}

Support Function

N-java

1. Lambda combination : https://github.com/skaengus2012/N-java/wiki/N-java-v0.2-wiki#lambda-combination
2. MaybeUtil : https://github.com/skaengus2012/N-java/wiki/N-java-v0.2-wiki#maybeutil
3. TimeUtil & TimeBuilder : https://github.com/skaengus2012/N-java/wiki/N-java-v0.2-wiki#timeutil--timebuilder
4. CheckUtil : https://github.com/skaengus2012/N-java/wiki/N-java-v0.2-wiki#checkutil

Ndroid

1. Android MVP : https://github.com/skaengus2012/Ndroid#android-mvp

Android MVP

Ndroid support android mvp with considering memory leak.

First, You can find NxActivity, NxPresenter, NxComponent

NxActivity series

I defined required abstract method in NxActivity series.

This is sample Activity. We need to separte basic function, and I suggest that.

public class LoginActivity extends NxActivity {

    private EditText editId, editPwd;

    // This is presenter for LoginActivity
    private LoginPresenter loginPresenter;

     /**
      * Define, your activity layout resource id;
      *
      * @return
      */
      @Override
      public int getLayoutResourceId() {
         return R.layout.activity_login;
      }

     /**
      * layout xml binding.
      */
      @Override
      public void initView() {
          editId = (EditText) findViewById(R.id.editId);
          editPwd = (EditText) findViewById(R.id.editPwd);
      }

      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          loginPresenter = new LoginPresenter(this);
      }
}

NxPresenter

This presenter manage activity using WeakReference.
If you use that, you do not need to consider memory leak.
This is simple presenter.

And attention observer in presenter. Implement observer in presenter, not activity.
public class LoginPresenter extends NxActivityPresenter<T> implements ILoginServiceObserver {

     public LoginPresenter(LoginActivity loginActivity) {
        super(loginActivity);
     }
	
    /**
     * Presenter method example.
     *
     * @param view
     */
     public void clickLoginButton(View view) {
     	// simple activity action.
	run(LoginActivity::setClickDisableLoginButton);	// run(loginActivity -> loginActivity.setClickDisableLoginButton());
		
	// runOnUiThread activity action.
	runOnUiThread(LoginActivity::setClickDisableLoginButton);
     }
}

NxComponent

I think that model likes Service, Component in Spring Framework required while devloping app.
So I made modeler for busines logic.
public class DummyModeler extends NxComponent {

    private DummyModeler() {
    }

    private static final class ManagerHolder {
        private static DummyModeler dummyModeler = new DummyModeler();
    }

    public static DummyModeler GetInstance() {
        return ManagerHolder.dummyModeler;
    }

    public void introduceModelerMethod() {
        // Check example.
        {
            Integer a = 10;
            Check(a != 5);       // throws RuntimeException.
        }

        // NullCheck example.
        {
            Integer a = null;
            NullCheck(a);       // throws RuntimeException.
        }

        // String empty check example.
        {
            String a = "";
            EmptyToStringCheck(a);       // throws RuntimeException.
        }

        // Container empty check example.
        {
            EmptyContainerCheck(new LinkedList<String>());                      // throws RuntimeException.
            EmptyContainerCheck(new Integer[2]);                                // throws RuntimeException.
            EmptyContainerCheck(new HashMap<String, String>());                 // throws RuntimeException.
        }

        {
            Map<String, Object> param = new HashMap<>();
            PutDefualtValueInMap(param, "Doohyun", () -> 2);

            // Not operate put action, because param have key "doohyun"
            PutDefualtValueInMap(param, "Doohyun", () -> 3);
        }
    }
}

About

App Factory for Android (Android MVP, Function Programming)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages