Skip to content

Instantly share code, notes, and snippets.

@senneco
Created October 25, 2016 14:06
Show Gist options
  • Save senneco/a91bd53f257c0fddda6e47f7de9a9fb8 to your computer and use it in GitHub Desktop.
Save senneco/a91bd53f257c0fddda6e47f7de9a9fb8 to your computer and use it in GitHub Desktop.
Extra-minimal Moxy sample
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.arello-mobile:moxy:1.1.1'
compile 'com.arello-mobile:moxy-app-compat:1.1.1'
provided 'com.arello-mobile:moxy-compiler:1.1.1'
}
package net.senneco.devfest;
import android.os.Bundle;
import android.support.annotation.StringRes;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.arellomobile.mvp.MvpAppCompatActivity;
import com.arellomobile.mvp.presenter.InjectPresenter;
import net.senneco.devfest.presenter.HelloPresenter;
import net.senneco.devfest.view.HelloView;
public class HelloActivity extends MvpAppCompatActivity implements HelloView {
@InjectPresenter
HelloPresenter mHelloPresenter;
private TextView mMessageTextView;
private ProgressBar mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello);
mMessageTextView = (TextView) findViewById(R.id.text_view_message);
mProgressBar = ((ProgressBar) findViewById(R.id.progress_bar));
}
@Override
public void showMessage(@StringRes int messageResId) {
mMessageTextView.setText(messageResId);
}
@Override
public void toggleMessageLoading(boolean isLoading) {
mProgressBar.setVisibility(isLoading ? View.VISIBLE : View.GONE);
mMessageTextView.setVisibility(isLoading ? View.GONE : View.VISIBLE);
}
}
package net.senneco.devfest.presenter;
import java.util.concurrent.TimeUnit;
import android.os.AsyncTask;
import com.arellomobile.mvp.InjectViewState;
import com.arellomobile.mvp.MvpPresenter;
import net.senneco.devfest.R;
import net.senneco.devfest.view.HelloView;
/**
* Created by senneco on 25.10.2016
*/
@InjectViewState
public class HelloPresenter extends MvpPresenter<HelloView>{
public HelloPresenter() {
getViewState().toggleMessageLoading(true);
new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... voids) {
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
// pass
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
getViewState().toggleMessageLoading(false);
getViewState().showMessage(R.string.hello);
}
}.execute();
}
}
package net.senneco.devfest.view;
import android.support.annotation.StringRes;
import com.arellomobile.mvp.MvpView;
/**
* Created by senneco on 25.10.2016
*/
public interface HelloView extends MvpView {
void toggleMessageLoading(boolean isLoading);
void showMessage(@StringRes int messageResId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment