Personal analysis of the Daily project on GitHub
20498 단어 project
Let's start analyzing:
Application–>
I usually start analyzing the code from the Application, so let's take a look at how other people's Applications do it. In the manifest file:
".App"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/BaseAppTheme">
</application>
Detailed explanation of Android application and activity tags: http://blog.csdn.net/self_study/article/details/54020909In the Application, it is also the App, that is, various initializations.
setupDatabase
SplashActivity–>
In the manifest file:
<activity
android:name=".mvp.ui.activities.SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/AppTheme.FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
intent-filter>
activity>
The first started Activity configuration Details about Intent: http://blog.csdn.net/u012637501/article/details/41080891SplashActivity–>
Take a look at this SplashActivity again:
Property Animation
ButterKnife
RxAndroid RxJava
BaseActivity–>
Abstract, generic:
public abstract class BaseActivity<T extends BasePresenter> extends AppCompatActivity {
protected T mPresenter;
public abstract int getLayoutId();
public abstract void initInjector();
public abstract void initViews();
}
ActivityComponent
DrawerLayout
Toolbar
onNewIntent:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
RefWatcher
NewsActivity–>
DrawerLayout
NavigationView
CoordinatorLayout
AppBarLayout
Toolbar
TabLayout
ViewPager
FloatingActionButton
Snackbar
MVP
Rx
butterknife
dagger
So many things combined to play together. It feels like a must-play for the mainstream now.
BaseFragment–>
Similar to Activity, it is also associated with Presenter through generics
NewsListFragment
RecyclerView
SwipeRefreshLayout
Rx
butterknife
dagger
MVP
BaseRecyclerViewAdapter–>
Generics
Commonly used additions, deletions and revisions
Footer load more
setItemAppearAnimation
protected void setItemAppearAnimation(RecyclerView.ViewHolder holder, int position, @AnimRes int type) {
if (position > mLastPosition/* && !isFooterPosition(position)*/) {
Animation animation = AnimationUtils.loadAnimation(holder.itemView.getContext(), type);
holder.itemView.startAnimation(animation);
mLastPosition = position;
}
}
NewsListAdapter–>
onCreateViewHolder
Wonderful usage:
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
View view;
switch (viewType) {
case TYPE_FOOTER:
view = getView(parent, R.layout.item_news_footer);
return new FooterViewHolder(view);
case TYPE_ITEM:
view = getView(parent, R.layout.item_news);
final ItemViewHolder itemViewHolder = new ItemViewHolder(view);
setItemOnClickEvent(itemViewHolder, false);
return itemViewHolder;
case TYPE_PHOTO_ITEM:
view = getView(parent, R.layout.item_news_photo);
final PhotoViewHolder photoItemViewHolder = new PhotoViewHolder(view);
setItemOnClickEvent(photoItemViewHolder, true);
return photoItemViewHolder;
default:
throw new RuntimeException("there is no type that matches the type " +
viewType + " + make sure your using types correctly");
}
}
Glide
Google's recommended image loading library Glide
A variety of flexible use of ViewHolder
butterknife
NewsActivity in MVP–>
NewsActivity–>NewsView–>NewsPresenterImpl–>NewsPresenter–>NewsInteractorImpl–>NewsInteractor–>NewsChannelTable–>NewsChannelTableManager
The Subscription of Rx is used in NewsInteractor
public interface NewsInteractor {
Subscription lodeNewsChannels(RequestCallBack callBack);
}
Rx's Observable is used in NewsInteractorImpl
@Inject using dagger
public class NewsInteractorImpl implements NewsInteractor> {
@Inject
public NewsInteractorImpl() {
}
@Override
public Subscription lodeNewsChannels(final RequestCallBack> callBack) {
return Observable
.create(new Observable.OnSubscribe>() {
@Override
public void call(Subscriber super List> subscriber) {
NewsChannelTableManager.initDB();
subscriber.onNext(NewsChannelTableManager.loadNewsChannelsMine());
subscriber.onCompleted();
}
})
.compose(TransformUtils.>defaultSchedulers())
.subscribe(new Subscriber>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
callBack.onError(App.getAppContext().getString(R.string.db_error));
}
@Override
public void onNext(List newsChannelTables) {
callBack.success(newsChannelTables);
}
}
);
}
}
greendao is used in NewsChannelTable
NewsChannelTableManager
Repository (warehouse) is divided into (db) and (network) NewsChannelTableManager belongs to obtaining data from db repository
NewsListFragment in MVP–>
NewsListFragment–>NewsListView–>NewsListPresenterImpl–>NewsListPresenter–>NewsListInteractorImpl–>NewsListInteractor–>NewsSummary–>RetrofitManager–>NetUtil
Rx's Observable is used in NewsListInteractor
public interface NewsListInteractor {
Subscription loadNews(RequestCallBack listener, String type, String id, int startPage);
}
NewsListInteractorImpl (I don't understand it yet.)
public class NewsListInteractorImpl implements NewsListInteractor> {
// private boolean mIsNetError;
@Inject
public NewsListInteractorImpl() {
}
@Override
public Subscription loadNews(final RequestCallBack> listener, String type,
final String id, int startPage) {
// mIsNetError = false;
// API observeOn(MainThread) , , onComplete ,
// unsubscribe , call.cancel NetworkOnMainThreadException
// unsubscribeOn(io)
return RetrofitManager.getInstance(HostType.NETEASE_NEWS_VIDEO).getNewsListObservable(type, id, startPage)
.flatMap(new Func1
greendao layer
DaoMaster
DaoSession
NewsChannelTableDao
common layer
ApiConstants
Constants
HostType
LoadNewsType
PhotoRequestType
utils layer
widget layer
Daily This is a framework template made by others, and there are many knowledge points in it. It is quite unfamiliar to me, and I have to work hard to learn one by one. MVP + Rx + Retrofit + OkHttp3 + Dagger is a good demo for getting started. If + modularized and componentized, those things will be even more powerful.
Attached:
https://GitHub.com/green robot/green DAO
HTTPS://GitHub.com/square/OK HTTP
https://GitHub.com/square/retrofit
https://GitHub.com/Re ActiveX/Rx Java
https://GitHub.com/Re ActiveX/Rx Android
https://GitHub.com/square/dagger
https://GitHub.com/Google samples/Android-architecture
https://GitHub.com/Jake Wharton/Butter knife
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Personal analysis of the Daily project on GitHubAnalysis of other people's projects on github. Learn from him well. https://github.com/spring2613/Daily The project has ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.