Created
January 17, 2018 11:51
-
-
Save nikialeksey/169c433bba22f4e213f5810db4263eee to your computer and use it in GitHub Desktop.
Moxy Bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 27 | |
defaultConfig { | |
applicationId "com.nikialeksey.moxybug" | |
minSdkVersion 20 | |
targetSdkVersion 27 | |
} | |
buildTypes { | |
release { | |
minifyEnabled false | |
} | |
} | |
} | |
dependencies { | |
implementation 'com.arello-mobile:moxy:1.5.3' | |
implementation 'com.arello-mobile:moxy-android:1.5.3' | |
annotationProcessor 'com.arello-mobile:moxy-compiler:1.5.3' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.nikialeksey.moxybug"> | |
<application | |
android:allowBackup="true" | |
android:label="@string/app_name" | |
android:supportsRtl="true"> | |
<activity android:name=".MainActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.LAUNCHER"/> | |
</intent-filter> | |
</activity> | |
<activity android:name=".BugActivity"/> | |
</application> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nikialeksey.moxybug; | |
import android.app.Activity; | |
import android.os.Bundle; | |
public class BugActivity extends Activity { | |
@Override | |
protected void onCreate(final Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
final BugFragment bugFragment = new BugFragment(); | |
final Bundle arguments = new Bundle(); | |
arguments.putBoolean("bug", getIntent().getBooleanExtra("bug", false)); | |
bugFragment.setArguments(arguments); | |
getFragmentManager() | |
.beginTransaction() | |
.replace(android.R.id.content, bugFragment) | |
.commit(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nikialeksey.moxybug; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.TextView; | |
import com.arellomobile.mvp.MvpFragment; | |
import com.arellomobile.mvp.presenter.InjectPresenter; | |
import com.arellomobile.mvp.presenter.PresenterType; | |
import com.arellomobile.mvp.presenter.ProvidePresenter; | |
public class BugFragment extends MvpFragment implements BugView { | |
@InjectPresenter(type = PresenterType.WEAK, tag = "Bug") | |
BugPresenter bugPresenter; | |
@ProvidePresenter(type = PresenterType.WEAK, tag = "Bug") | |
BugPresenter providePresenter() { | |
return new BugPresenter(getArguments().getBoolean("bug")); | |
} | |
@Override | |
public View onCreateView( | |
final LayoutInflater inflater, | |
final ViewGroup container, | |
final Bundle savedInstanceState | |
) { | |
return inflater.inflate(R.layout.fragment_bug, container, false); | |
} | |
@Override | |
public void show1() { | |
final TextView bugText = getView().findViewById(R.id.bugText); | |
bugText.setText("1"); | |
} | |
@Override | |
public void show2() { | |
final TextView bugText = getView().findViewById(R.id.bugText); | |
bugText.setText("2"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nikialeksey.moxybug; | |
import com.arellomobile.mvp.InjectViewState; | |
import com.arellomobile.mvp.MvpPresenter; | |
@InjectViewState | |
public class BugPresenter extends MvpPresenter<BugView> { | |
private final boolean flag; | |
public BugPresenter(final boolean flag) { | |
this.flag = flag; | |
} | |
@Override | |
protected void onFirstViewAttach() { | |
super.onFirstViewAttach(); | |
if (flag) { | |
getViewState().show1(); | |
} else { | |
getViewState().show2(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nikialeksey.moxybug; | |
import com.arellomobile.mvp.MvpView; | |
public interface BugView extends MvpView { | |
void show1(); | |
void show2(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nikialeksey.moxybug; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(final View v) { | |
final Intent intent = new Intent(MainActivity.this, BugActivity.class); | |
intent.putExtra("bug", true); | |
startActivity(intent); | |
} | |
}); | |
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(final View v) { | |
final Intent intent = new Intent(MainActivity.this, BugActivity.class); | |
intent.putExtra("bug", false); | |
startActivity(intent); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context="com.nikialeksey.moxybug.MainActivity"> | |
<Button | |
android:id="@+id/button1" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:layout_weight="1" | |
android:text="1"/> | |
<Button | |
android:id="@+id/button2" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:layout_weight="1" | |
android:text="2"/> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/bugText" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:textAppearance="@android:style/TextAppearance.Large"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<string name="app_name">Moxy bug</string> | |
</resources> |
Author
nikialeksey
commented
Jan 17, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment