Skip to content

Commit

Permalink
add default Callback
Browse files Browse the repository at this point in the history
  • Loading branch information
KingJA committed Oct 12, 2017
1 parent 964ae1f commit 9195d66
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 72 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
<activity android:name=".target.AnimateActivity"/>
<activity android:name=".target.KeepTitleFragmentActivity"/>
<activity android:name=".target.BestPracticesActivity"/>
<activity android:name=".target.KeepTitleActivity"/>
<activity
android:name=".target.KeepTitleActivity"
android:theme="@style/NoTitle"/>
</application>

</manifest>
34 changes: 0 additions & 34 deletions app/src/main/java/sample/kingja/loadsir/AActivity.java

This file was deleted.

6 changes: 5 additions & 1 deletion app/src/main/java/sample/kingja/loadsir/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sample.kingja.loadsir.target.AnimateActivity;
import sample.kingja.loadsir.target.BestPracticesActivity;
import sample.kingja.loadsir.target.DefaultCallbackActivity;
import sample.kingja.loadsir.target.KeepTitleActivity;
import sample.kingja.loadsir.target.KeepTitleFragmentActivity;
import sample.kingja.loadsir.target.MultiFragmentActivity;
import sample.kingja.loadsir.target.FragmentSingleActivity;
Expand Down Expand Up @@ -68,12 +69,15 @@ public void animatCallback(View view) {
startActivity(new Intent(this, AnimateActivity.class));
}

public void titleBarActivity(View view) {
public void keepTitleInFragment(View view) {
startActivity(new Intent(this, KeepTitleFragmentActivity.class));
}

public void bestPractices(View view) {
startActivity(new Intent(this, BestPracticesActivity.class));
}

public void keepTitleInActivity(View view) {
startActivity(new Intent(this, KeepTitleActivity.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package sample.kingja.loadsir.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;

import butterknife.ButterKnife;
import sample.kingja.loadsir.R;

/**
* Description:TODO
* Create Time:2017/3/20 14:17
* Author:KingJA
* Email:[email protected]
*/
public abstract class BaseTitleActivity extends AppCompatActivity {
protected View rootView;
protected LoadService mBaseLoadService;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rootView = View.inflate(this, R.layout.activity_title, null);
addContent();
setContentView(rootView);
initView();
initNet();
}


private void addContent() {
FrameLayout flContent = (FrameLayout) rootView.findViewById(R.id.fl_content);
TextView tvTitleTitle = (TextView) rootView.findViewById(R.id.tv_title_title);
LinearLayout llTitleBack = (LinearLayout) rootView.findViewById(R.id.ll_title_back);
tvTitleTitle.setText(getContentTitle() == null ? "" : getContentTitle());
llTitleBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
backClick();
}
});
View content = View.inflate(this, getContentView(), null);
if (content != null) {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
flContent.addView(content, params);
ButterKnife.bind(this, rootView);
mBaseLoadService = LoadSir.getDefault().register(content, new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
onNetReload(v);
}
});
}
}

private void backClick() {
finish();
}

protected abstract String getContentTitle();

protected abstract int getContentView();

protected abstract void initView();

protected abstract void initNet();

protected abstract void onNetReload(View v);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sample.kingja.loadsir.callback;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
Expand All @@ -12,8 +11,6 @@

import sample.kingja.loadsir.R;

import static android.content.ContentValues.TAG;

/**
* Description:TODO
* Create Time:2017/9/3 10:22
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package sample.kingja.loadsir.target;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.View;
import android.widget.TextView;

import butterknife.BindView;
import sample.kingja.loadsir.PostUtil;
import sample.kingja.loadsir.R;
import sample.kingja.loadsir.base.BaseTitleActivity;
import sample.kingja.loadsir.callback.ErrorCallback;
import sample.kingja.loadsir.callback.LoadingCallback;

/**
* Description:
Expand All @@ -13,15 +17,36 @@
* Email:[email protected]
*/

public class KeepTitleActivity extends AppCompatActivity {
public class KeepTitleActivity extends BaseTitleActivity {
@BindView(R.id.tv_title)
TextView mTvTitle;


@Override
protected String getContentTitle() {
return "Title";
}

@Override
protected int getContentView() {
return R.layout.activity_content;
}

@Override
protected void initView() {
TextView tv_msg = (TextView) findViewById(R.id.tv_subTitle);
tv_msg.setText("Keep Title In Activity");
mTvTitle.setText("Yes, Success");
}

@Override
protected void initNet() {
PostUtil.postCallbackDelayed(mBaseLoadService, ErrorCallback.class);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_content);
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
protected void onNetReload(View v) {
mBaseLoadService.showCallback(LoadingCallback.class);
PostUtil.postSuccessDelayed(mBaseLoadService);
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/svg_top_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="@color/red"
android:pathData="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/>
</vector>
21 changes: 0 additions & 21 deletions app/src/main/res/layout/activity_animate.xml

This file was deleted.

2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
android:id="@+id/ll_root_activity">

<TextView
android:id="@+id/tv_title"
android:textSize="30sp"
android:textColor="#358c69"
android:text="Success"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/tv_subTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content in Activity"/>
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="titleBarActivity"
android:onClick="keepTitleInActivity"
android:text="@string/keep_title_bar_in_activity"
android:textAllCaps="false"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="keepTitleInFragment"
android:text="@string/keep_title_bar_in_fragment"
android:textAllCaps="false"/>

Expand Down
41 changes: 41 additions & 0 deletions app/src/main/res/layout/activity_title.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@color/black">

<LinearLayout
android:id="@+id/ll_title_back"
android:layout_width="48dp"
android:layout_height="48dp"
android:gravity="center">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/svg_top_back"
android:tint="@color/white"/>
</LinearLayout>


<TextView
android:id="@+id/tv_title_title"
style="@style/font_f_18"
android:text="标题"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</RelativeLayout>

<FrameLayout
android:id="@+id/fl_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<color name="colorPrimary">#000000</color>
<color name="colorPrimaryDark">#787878</color>
<color name="colorAccent">#FF4081</color>

<color name="black">#000000</color>
<color name="white">#ffffff</color>
<color name="red">#bb2c28</color>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<string name="click_me_to_retry">click me to retry!</string>
<string name="best_practices">best practices</string>
<string name="default_loadsir_callback">default LoadSir Callback</string>
<string name="keep_title_bar_in_activity">keep title bar in Activity</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="NoTitle" parent="Theme.AppCompat.Light.NoActionBar"/>

<style name="Hint_Title">
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textSize">20sp</item>
Expand All @@ -17,4 +19,9 @@
<item name="android:textColor">#666666</item>
</style>

<style name="font_f_18">
<item name="android:singleLine">true</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">@color/white</item>
</style>
</resources>

0 comments on commit 9195d66

Please sign in to comment.