Skip to content

Commit

Permalink
Merge pull request #21 from Omega-R/develop
Browse files Browse the repository at this point in the history
Make injectviewstate not required
Fix save state for child fragment
add constructors to fragments
  • Loading branch information
anton-knyazev committed Oct 16, 2020
2 parents ae6ec6b + c24a35c commit db441eb
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package example.com.moxy_androidx_sample;

import androidx.annotation.ContentView;
import androidx.annotation.LayoutRes;
import com.omegar.mvp.MvpAppCompatActivity;

public abstract class BaseActivity extends MvpAppCompatActivity implements BaseView {

public BaseActivity() {
super();
}

@ContentView
public BaseActivity(@LayoutRes int contentLayoutId) {
super(contentLayoutId);
}

@Override
public void testFunction() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.omegar.mvp.presenter.InjectPresenter
import example.com.moxy_androidx_sample.contract.Contract
import example.com.moxy_androidx_sample.packagee.Item

class MainActivity : BaseActivity(), Contract.MainView, SecondInterface {
class MainActivity : BaseActivity(R.layout.activity_main), Contract.MainView, SecondInterface {
override fun fourth(item: String?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.omegar.mvp.InjectViewState
import com.omegar.mvp.MvpPresenter
import example.com.moxy_androidx_sample.contract.Contract

@InjectViewState
class MainPresenter : MvpPresenter<Contract.MainView>() {

override fun onFirstViewAttach() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import android.os.Bundle;

import androidx.annotation.ContentView;
import androidx.annotation.LayoutRes;
import androidx.appcompat.app.AppCompatActivity;


/**
* Date: 25-July-18
* Time: 2:51
Expand All @@ -14,6 +17,11 @@
public class MvpAppCompatActivity extends AppCompatActivity {
private MvpDelegate<? extends MvpAppCompatActivity> mMvpDelegate;

public MvpAppCompatActivity() { super(); }

@ContentView
public MvpAppCompatActivity(@LayoutRes int contentLayoutId) { super(contentLayoutId); }

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.omegar.mvp;

import android.os.Bundle;

import androidx.annotation.ContentView;
import androidx.annotation.LayoutRes;
import androidx.fragment.app.Fragment;

/**
Expand All @@ -17,6 +20,11 @@ public class MvpAppCompatFragment extends Fragment {

private MvpDelegate<? extends MvpAppCompatFragment> mMvpDelegate;

public MvpAppCompatFragment() { super(); }

@ContentView
public MvpAppCompatFragment(@LayoutRes int contentLayoutId) { super(contentLayoutId); }

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package androidx.annotation;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.RetentionPolicy.CLASS;

@Retention(CLASS)
@Target({CONSTRUCTOR})
public @interface ContentView {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package androidx.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.CLASS;

@Documented
@Retention(CLASS)
@Target({METHOD, PARAMETER, FIELD, LOCAL_VARIABLE})
public @interface LayoutRes {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import android.os.Bundle;

import androidx.annotation.ContentView;
import androidx.annotation.LayoutRes;
import androidx.fragment.app.FragmentActivity;


/**
* Date: 25-July-18
* Time: 2:51
Expand All @@ -13,6 +16,15 @@

public class AppCompatActivity extends FragmentActivity {

public AppCompatActivity() {
super();
}

@ContentView
public AppCompatActivity(@LayoutRes int contentLayoutId) {
super(contentLayoutId);
}

protected void onCreate(Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.os.Bundle;

import androidx.annotation.LayoutRes;

/**
* Date: 25-July-18
* Time: 4:38
Expand All @@ -10,6 +12,10 @@
*/

public class Fragment {
public Fragment() { super(); }

public Fragment(@LayoutRes int contentLayoutId) { super(); }

public void onCreate(Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package androidx.fragment.app;

import androidx.annotation.LayoutRes;

/**
* Date: 25-July-18
* Time: 4:41
Expand All @@ -8,6 +10,14 @@
*/

public class FragmentActivity {

public FragmentActivity() {
super();
}
public FragmentActivity(@LayoutRes int contentLayoutId) {
super();
}

public boolean isFinishing() {
throw new RuntimeException("Stub!");
}
Expand Down
2 changes: 2 additions & 0 deletions moxy/src/main/java/com/omegar/mvp/InjectViewState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.omegar.mvp;

import java.lang.annotation.Inherited;
import java.lang.annotation.Target;

import com.omegar.mvp.viewstate.MvpViewState;
Expand All @@ -15,6 +16,7 @@
* code, that broke your app.
*/
@Target(value = TYPE)
@Inherited
public @interface InjectViewState {
Class<? extends MvpViewState> value() default DefaultViewState.class;

Expand Down
1 change: 1 addition & 0 deletions moxy/src/main/java/com/omegar/mvp/MvpDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public void onDestroyView() {
childDelegatesClone.addAll(mChildDelegates);

for (MvpDelegate childDelegate : childDelegatesClone) {
childDelegate.onSaveInstanceState();
childDelegate.onDestroyView();
}

Expand Down
1 change: 1 addition & 0 deletions moxy/src/main/java/com/omegar/mvp/MvpPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Alexander Blinov
* @author Konstantin Tckhovrebov
*/
@InjectViewState
public abstract class MvpPresenter<View extends MvpView> {
private boolean mFirstLaunch = true;
private String mTag;
Expand Down

0 comments on commit db441eb

Please sign in to comment.