Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Fixes sample app.
Browse files Browse the repository at this point in the history
  • Loading branch information
MRezaNasirloo committed Apr 14, 2018
1 parent 8874d9d commit 56d763e
Show file tree
Hide file tree
Showing 29 changed files with 180 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ActivitySimple extends AppCompatActivity implements ViewSimple {

@Override
protected void onCreate(Bundle savedInstanceState) {
PresenterSimple_Slick.bind(this, R.id.textView3, "foo");
PresenterSimple_Slick.bind(this, R.id.textView_simple, "foo");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.mrezanasirloo.slick.sample.activity.dagger;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.mrezanasirloo.slick.Presenter;
import com.mrezanasirloo.slick.sample.App;
Expand All @@ -36,14 +38,18 @@ public class ActivitySimpleDagger extends AppCompatActivity implements ViewSimpl

private static final String TAG = ActivitySimpleDagger.class.getSimpleName();

@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
App.getDaggerComponent(this).inject(this);
PresenterSimpleDagger_Slick.bind(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
TextView textView = findViewById(R.id.textView_simple);
textView.setText("Activity's Presenter has injected with Dagger");
}


@Override
protected void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ControllerSimple extends Controller implements ViewConductor {
@Override
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
PresenterConductor_Slick.bind(this);
return inflater.inflate(R.layout.home_layout, container, false);
return inflater.inflate(R.layout.contoller_home, container, false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ControllerDagger extends Controller implements ViewConductorDagger
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
App.getDaggerComponent(getApplicationContext()).inject(this);
PresenterConductorDagger_Slick.bind(this);
return inflater.inflate(R.layout.home_layout, container, false);
return inflater.inflate(R.layout.contoller_home, container, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_custom_view);
customView1 = findViewById(R.id.custom_view_1);
customView2 = findViewById(R.id.custom_view_2);
customView1.onBind("some_unique_id_1");
customView2.onBind("some_unique_id_2");
view2UniqueId = customView2.getUniqueId();
}

@Override
protected void onDestroy() {
super.onDestroy();
customView1.onBind(customView2.getUniqueId()); //<--- onDestroy notification should be passed to view
ViewPresenter_Slick.onDestroy(view2UniqueId, this);
// If you don't have access to the view anymore, i.e View's hosted in a fragment
// onDestroy callbacks should be passed to the generated class
ViewPresenter_Slick.onDestroy(customView1);
ViewPresenter_Slick.onDestroy(customView2);
// If you don't have access to the view anymore, i.e View's hosted in a fragment and the onDestroyView of the fragment has called
// Retain its uniqueId and send the onDestroy callbacks yourself
// ViewPresenter_Slick.onDestroy(view2UniqueId, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@
package com.mrezanasirloo.slick.sample.cutstomview;

import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;

import com.mrezanasirloo.slick.Presenter;
import com.mrezanasirloo.slick.SlickLifecycleListener;
import com.mrezanasirloo.slick.SlickUniqueId;

import java.util.UUID;

import static com.mrezanasirloo.slick.SlickDelegateActivity.SLICK_UNIQUE_KEY;
import static java.util.Locale.ENGLISH;

/**
Expand All @@ -54,7 +48,7 @@ public CustomView(Context context, AttributeSet attrs) {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
ViewPresenter_Slick.bind(this);
if (isInEditMode()) return;
ViewPresenter_Slick.onAttach(this);

String text = String.format(
Expand All @@ -68,37 +62,20 @@ protected void onAttachedToWindow() {

@Override
protected void onDetachedFromWindow() {
if (isInEditMode()) return;
super.onDetachedFromWindow();
ViewPresenter_Slick.onDetach(this);
}

@Override
public void onBind(@NonNull String instanceId) {
ViewPresenter_Slick.onDestroy(this);
}

@Nullable
@Override
public Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("superState", super.onSaveInstanceState());
bundle.putString(SLICK_UNIQUE_KEY, this.id);
return bundle;
}

@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
this.id = bundle.getString(SLICK_UNIQUE_KEY);
state = bundle.getParcelable("superState");
}
super.onRestoreInstanceState(state);
id = instanceId;
ViewPresenter_Slick.bind(this);
}

@NonNull
@Override
public String getUniqueId() {
return id = (id != null ? id : UUID.randomUUID().toString());
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ public class ActivityCustomViewDagger extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_view_dagger);
customView = (CustomViewDagger) findViewById(R.id.custom_view_dagger);
customView = findViewById(R.id.custom_view_dagger);
customView.onBind("some_string_as_id");
}

@Override
protected void onDestroy() {
super.onDestroy();
customView.onBind("some_string_as_id");
PresenterCustomViewDagger_Slick.onDestroy(customView);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mrezanasirloo.slick.Presenter;
import com.mrezanasirloo.slick.SlickLifecycleListener;
import com.mrezanasirloo.slick.sample.App;
import com.mrezanasirloo.slick.sample.R;

import javax.inject.Inject;
import javax.inject.Provider;
Expand Down Expand Up @@ -59,12 +57,7 @@ public CustomViewDagger(Context context, @Nullable AttributeSet attrs, int defSt
protected void onAttachedToWindow() {
System.out.println("DaggerCustomView.onAttachedToWindow");
super.onAttachedToWindow();
App.getDaggerComponent(getContext()).inject(this);
PresenterCustomViewDagger_Slick.bind(this);
PresenterCustomViewDagger_Slick.onAttach(this);

final TextView textView = (TextView) findViewById(R.id.textView_custom_view);
textView.setText(presenter.getData());
}

@Override
Expand All @@ -76,7 +69,8 @@ protected void onDetachedFromWindow() {

@Override
public void onBind(@NonNull String instanceId) {
System.out.println("DaggerCustomView.onDestroy");
PresenterCustomViewDagger_Slick.onDestroy(this);
System.out.println("DaggerCustomView.onBind");
App.getDaggerComponent(getContext()).inject(this);
PresenterCustomViewDagger_Slick.bind(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class CustomView(context: Context, attrs: AttributeSet) : AppCompatTextView(cont
@Presenter
lateinit var presenter: PresenterCustomView

private lateinit var idStr: String
private lateinit var instanceId: String

@SuppressLint("SetTextI18n")
override fun onBind(instanceId: String) {
idStr = instanceId
this.instanceId = instanceId
PresenterCustomView_Slick.bind(this)
PresenterCustomView_Slick.onAttach(this)
text = "Presenter's code: ${presenter.code}, View's idStr: $uniqueId"
text = "CustomTextView's Presenter code: ${presenter.code}, View's id: $uniqueId"
}

override fun onDetachedFromWindow() {
Expand All @@ -52,6 +52,6 @@ class CustomView(context: Context, attrs: AttributeSet) : AppCompatTextView(cont
}

override fun getUniqueId(): String {
return idStr
return instanceId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static FragmentDagger newInstance() {
@SuppressLint("SetTextI18n")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_example, container, false);
((TextView) view.findViewById(R.id.text_view_fragment)).setText("Dagger Fragment.");
((TextView) view.findViewById(R.id.text_view_fragment)).setText("Fragment's Presenter has Injected via Dagger");
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.mrezanasirloo.slick.sample.fragment.dagger.delegate;


import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -51,11 +52,12 @@ public static FragmentDelegateDagger newInstance() {
return new FragmentDelegateDagger();
}

@SuppressLint("SetTextI18n")
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_example, container, false);
((TextView) view.findViewById(R.id.text_view_fragment)).setText("Delegate Dagger Fragment.");
((TextView) view.findViewById(R.id.text_view_fragment)).setText("This Fragment uses delegation to send callbacks to Presenter");
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
Expand All @@ -40,7 +41,7 @@ public static HostFragment newInstance() {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_support_simple, container, false);

view.findViewById(R.id.button_fragment_support).setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.mrezanasirloo.slick.sample.fragmentsupport.dagger;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
Expand Down Expand Up @@ -50,11 +51,12 @@ public static FragmentSupportDagger newInstance() {
return new FragmentSupportDagger();
}

@SuppressLint("SetTextI18n")
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_example, container, false);
((TextView) view.findViewById(R.id.text_view_fragment)).setText("Dagger Fragment.");
((TextView) view.findViewById(R.id.text_view_fragment)).setText("Support Fragment's Presenter has injected via Dagger");
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_example, container, false);
((TextView) view.findViewById(R.id.text_view_fragment))
.setText("Delegate Fragment without base class");
.setText("Support Fragment");
return view;
}

Expand Down
Binary file added sample-app/src/main/res/font/roboto_light.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion sample-app/src/main/res/layout/activity_conductor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
-->

<RelativeLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
Expand Down
9 changes: 9 additions & 0 deletions sample-app/src/main/res/layout/activity_custom_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context="com.mrezanasirloo.slick.sample.cutstomview.ActivityCustomView"
>
Expand All @@ -29,12 +30,20 @@
android:id="@+id/custom_view_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:textAlignment="center"
android:textSize="24sp"
/>

<com.mrezanasirloo.slick.sample.cutstomview.CustomView
android:id="@+id/custom_view_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:textAlignment="center"
android:textSize="24sp"
/>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@

<com.mrezanasirloo.slick.sample.cutstomview.dagger.CustomViewDagger
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_view_dagger"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>

<TextView
android:id="@+id/textView_custom_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:gravity="center"
android:text="CustomView's Presenter has Injected with Dagger"
android:textSize="30sp"
tools:ignore="HardcodedText"
/>
</com.mrezanasirloo.slick.sample.cutstomview.dagger.CustomViewDagger>
Loading

0 comments on commit 56d763e

Please sign in to comment.