Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static class Presenter extends ViewPresenter<FriendView> {
@Override public void onLoad(Bundle savedInstanceState) {
super.onLoad(savedInstanceState);
if (!hasView()) return;
getView().setText(friend.name);
getView().setFriendName(friend.name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,30 @@

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.mortar.R;
import mortar.dagger1support.ObjectGraphService;
import com.example.mortar.screen.FriendScreen;
import javax.inject.Inject;

public class FriendView extends TextView {
public class FriendView extends LinearLayout {
@Inject FriendScreen.Presenter presenter;

private TextView friendNameView;

public FriendView(Context context, AttributeSet attrs) {
super(context, attrs);
ObjectGraphService.inject(context, this);
}

@Override protected void onFinishInflate() {
super.onFinishInflate();
friendNameView = (TextView) findViewById(R.id.friend);
}

@Override protected void onAttachedToWindow() {
super.onAttachedToWindow();
presenter.takeView(this);
Expand All @@ -40,4 +51,8 @@ public FriendView(Context context, AttributeSet attrs) {
super.onDetachedFromWindow();
presenter.dropView(this);
}

public void setFriendName(String name) {
friendNameView.setText(name);
}
}
10 changes: 10 additions & 0 deletions mortar-sample/src/main/res/layout/friend_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView android:id="@+id/friend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textAppearance="?android:textAppearanceMedium"
android:background="?android:attr/selectableItemBackground"
/>

</com.example.mortar.view.FriendView>