forked from codeestX/GeekNews
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: DataManager & RootView fix: RxBus resubscribe
- Loading branch information
Showing
97 changed files
with
1,638 additions
and
813 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/codeest/geeknews/base/RootActivity.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.codeest.geeknews.base; | ||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.FrameLayout; | ||
import android.widget.LinearLayout; | ||
|
||
import com.codeest.geeknews.R; | ||
import com.codeest.geeknews.widget.ProgressImageView; | ||
|
||
/** | ||
* @author: Est <[email protected]> | ||
* @date: 2017/4/21 | ||
* @desciption: | ||
*/ | ||
|
||
public abstract class RootActivity<T extends BasePresenter> extends BaseActivity<T>{ | ||
|
||
private static final int STATE_MAIN = 0x00; | ||
private static final int STATE_LOADING = 0x01; | ||
private static final int STATE_ERROR = 0x02; | ||
|
||
private ProgressImageView ivLoading; | ||
private LinearLayout viewError; | ||
private FrameLayout viewLoading; | ||
private ViewGroup viewMain; | ||
private int currentState = STATE_MAIN; | ||
|
||
@Override | ||
protected void initEventAndData() { | ||
viewMain = (ViewGroup) findViewById(R.id.view_main); | ||
if (viewMain == null) { | ||
throw new IllegalStateException( | ||
"The subclass of RootActivity must contain a View named view_main."); | ||
} | ||
if (!(viewMain.getParent() instanceof ViewGroup)) { | ||
throw new IllegalStateException( | ||
"view_main's ParentView should be a ViewGroup"); | ||
} | ||
ViewGroup parent = (ViewGroup) viewMain.getParent(); | ||
View.inflate(mContext, R.layout.view_error, parent); | ||
View.inflate(mContext, R.layout.view_progress, parent); | ||
viewError = (LinearLayout) parent.findViewById(R.id.view_error); | ||
viewLoading = (FrameLayout) parent.findViewById(R.id.view_loading); | ||
ivLoading = (ProgressImageView) viewLoading.findViewById(R.id.iv_progress); | ||
viewError.setVisibility(View.GONE); | ||
viewLoading.setVisibility(View.GONE); | ||
viewMain.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void stateError() { | ||
if (currentState == STATE_ERROR) | ||
return; | ||
hideCurrentView(); | ||
currentState = STATE_ERROR; | ||
viewError.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void stateLoading() { | ||
if (currentState == STATE_LOADING) | ||
return; | ||
hideCurrentView(); | ||
currentState = STATE_LOADING; | ||
viewLoading.setVisibility(View.VISIBLE); | ||
ivLoading.start(); | ||
} | ||
|
||
@Override | ||
public void stateMain() { | ||
if (currentState == STATE_MAIN) | ||
return; | ||
hideCurrentView(); | ||
currentState = STATE_MAIN; | ||
viewMain.setVisibility(View.VISIBLE); | ||
} | ||
|
||
private void hideCurrentView() { | ||
switch (currentState) { | ||
case STATE_MAIN: | ||
viewMain.setVisibility(View.GONE); | ||
break; | ||
case STATE_LOADING: | ||
ivLoading.stop(); | ||
viewLoading.setVisibility(View.GONE); | ||
break; | ||
case STATE_ERROR: | ||
viewError.setVisibility(View.GONE); | ||
break; | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
app/src/main/java/com/codeest/geeknews/base/RootFragment.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.codeest.geeknews.base; | ||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.FrameLayout; | ||
import android.widget.LinearLayout; | ||
|
||
import com.codeest.geeknews.R; | ||
import com.codeest.geeknews.widget.ProgressImageView; | ||
|
||
/** | ||
* @author: Est <[email protected]> | ||
* @date: 2017/4/21 | ||
* @desciption: | ||
*/ | ||
|
||
public abstract class RootFragment<T extends BasePresenter> extends BaseFragment<T> { | ||
|
||
private static final int STATE_MAIN = 0x00; | ||
private static final int STATE_LOADING = 0x01; | ||
private static final int STATE_ERROR = 0x02; | ||
|
||
private ProgressImageView ivLoading; | ||
private LinearLayout viewError; | ||
private FrameLayout viewLoading; | ||
private ViewGroup viewMain; | ||
private int currentState = STATE_MAIN; | ||
|
||
@Override | ||
protected void initEventAndData() { | ||
if (getView() == null) | ||
return; | ||
viewMain = (ViewGroup) getView().findViewById(R.id.view_main); | ||
if (viewMain == null) { | ||
throw new IllegalStateException( | ||
"The subclass of RootActivity must contain a View named view_main."); | ||
} | ||
if (!(viewMain.getParent() instanceof ViewGroup)) { | ||
throw new IllegalStateException( | ||
"view_main's ParentView should be a ViewGroup."); | ||
} | ||
ViewGroup parent = (ViewGroup) viewMain.getParent(); | ||
View.inflate(mContext, R.layout.view_error, parent); | ||
View.inflate(mContext, R.layout.view_progress, parent); | ||
viewError = (LinearLayout) parent.findViewById(R.id.view_error); | ||
viewLoading = (FrameLayout) parent.findViewById(R.id.view_loading); | ||
ivLoading = (ProgressImageView) viewLoading.findViewById(R.id.iv_progress); | ||
viewError.setVisibility(View.GONE); | ||
viewLoading.setVisibility(View.GONE); | ||
viewMain.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void stateError() { | ||
if (currentState == STATE_ERROR) | ||
return; | ||
hideCurrentView(); | ||
currentState = STATE_ERROR; | ||
viewError.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void stateLoading() { | ||
if (currentState == STATE_LOADING) | ||
return; | ||
hideCurrentView(); | ||
currentState = STATE_LOADING; | ||
viewLoading.setVisibility(View.VISIBLE); | ||
ivLoading.start(); | ||
} | ||
|
||
@Override | ||
public void stateMain() { | ||
if (currentState == STATE_MAIN) | ||
return; | ||
hideCurrentView(); | ||
currentState = STATE_MAIN; | ||
viewMain.setVisibility(View.VISIBLE); | ||
} | ||
|
||
private void hideCurrentView() { | ||
switch (currentState) { | ||
case STATE_MAIN: | ||
viewMain.setVisibility(View.GONE); | ||
break; | ||
case STATE_LOADING: | ||
ivLoading.stop(); | ||
viewLoading.setVisibility(View.GONE); | ||
break; | ||
case STATE_ERROR: | ||
viewError.setVisibility(View.GONE); | ||
break; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...news/presenter/contract/GirlContract.java → ...news/base/contract/gank/GirlContract.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
...news/presenter/contract/TechContract.java → ...news/base/contract/gank/TechContract.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
...news/presenter/contract/GoldContract.java → ...news/base/contract/gold/GoldContract.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
.../presenter/contract/GoldMainContract.java → .../base/contract/gold/GoldMainContract.java
This file contains 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
This file contains 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
This file contains 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
This file contains 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
2 changes: 1 addition & 1 deletion
2
...s/presenter/contract/WelcomeContract.java → ...s/base/contract/main/WelcomeContract.java
This file contains 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
Oops, something went wrong.