forked from liuyanggithub/SuperMvp
-
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.
- Loading branch information
0 parents
commit 65e5c79
Showing
90 changed files
with
3,921 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
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 @@ | ||
/build |
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,48 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion '23.0.2' | ||
|
||
defaultConfig { | ||
applicationId "com.ly.testapplicatipn" | ||
minSdkVersion 14 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
testCompile 'junit:junit:4.12' | ||
/*Google library*/ | ||
compile 'com.android.support:appcompat-v7:23.1.1' | ||
compile 'com.android.support:design:23.1.1' | ||
/*squareup library*/ | ||
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' | ||
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' | ||
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' | ||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' | ||
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' | ||
compile 'com.android.support:support-v13:23.1.1' | ||
/*rx library*/ | ||
compile 'io.reactivex:rxandroid:1.1.0' | ||
compile 'io.reactivex:rxjava:1.1.0' | ||
compile 'com.jakewharton.rxbinding:rxbinding:0.3.0' | ||
compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.3.0' | ||
compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.3.0' | ||
compile 'com.jakewharton.rxbinding:rxbinding-recyclerview-v7:0.3.0' | ||
compile 'com.jakewharton.rxbinding:rxbinding-design:0.3.0' | ||
/*other library*/ | ||
compile 'com.github.bumptech.glide:glide:3.6.1' | ||
compile 'com.jakewharton:butterknife:7.0.1' | ||
compile 'com.github.orhanobut:logger:1.12' | ||
compile 'com.github.rey5137:material:1.2.2' | ||
} |
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,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in D:\Android\android-sdk-windows/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/com/ly/supermvp/ApplicationTest.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,13 @@ | ||
package com.ly.supermvp; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
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,24 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.ly.supermvp"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application | ||
android:name="com.ly.supermvp.MyApplication" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name="com.ly.supermvp.ui.activity.MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme.NoActionBar" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
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,47 @@ | ||
package com.ly.supermvp; | ||
|
||
import android.app.Application; | ||
import android.os.StrictMode; | ||
|
||
import com.orhanobut.logger.LogLevel; | ||
import com.orhanobut.logger.Logger; | ||
import com.squareup.leakcanary.LeakCanary; | ||
import com.squareup.leakcanary.RefWatcher; | ||
|
||
import static android.os.Build.VERSION.SDK_INT; | ||
import static android.os.Build.VERSION_CODES.GINGERBREAD; | ||
|
||
/** | ||
* <Pre> | ||
* </Pre> | ||
* | ||
* @author 刘阳 | ||
* @version 1.0 | ||
* <p/> | ||
* Create by 2016/1/27 10:47 | ||
*/ | ||
public class MyApplication extends Application { | ||
private static MyApplication instance; | ||
private RefWatcher refWatcher; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
|
||
Logger.init().logLevel(LogLevel.FULL); | ||
instance = (MyApplication) getApplicationContext(); | ||
|
||
this.enabledStrictMode(); | ||
refWatcher = LeakCanary.install(this); | ||
} | ||
|
||
private void enabledStrictMode() { | ||
if (SDK_INT >= GINGERBREAD) { | ||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() // | ||
.detectAll() // | ||
.penaltyLog() // | ||
.penaltyDeath() // | ||
.build()); | ||
} | ||
} | ||
} |
150 changes: 150 additions & 0 deletions
150
app/src/main/java/com/ly/supermvp/adapter/NewsListAdapter.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,150 @@ | ||
package com.ly.supermvp.adapter; | ||
|
||
import android.app.Activity; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.ly.supermvp.R; | ||
import com.ly.supermvp.model.entity.NewsBody; | ||
import com.ly.supermvp.utils.GlideUtil; | ||
|
||
import java.util.List; | ||
|
||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
|
||
/** | ||
* <Pre> | ||
* 新闻列表适配器 | ||
* </Pre> | ||
* | ||
* @author 刘阳 | ||
* @version 1.0 | ||
* <p/> | ||
* Create by 2016/1/27 16:26 | ||
*/ | ||
public class NewsListAdapter extends RecyclerView.Adapter { | ||
private static final int TYPE_ITEM = 0x00;//内容 | ||
private static final int TYPE_FOOTER = 0x01;//加载更多 | ||
|
||
private Activity context; | ||
private List<NewsBody> newsBodies; | ||
|
||
|
||
/** | ||
* 条目点击监听 | ||
*/ | ||
private OnItemClickListener mOnItemClickListener; | ||
|
||
/** | ||
* 是否显示加载更多视图 | ||
*/ | ||
private boolean mShowFooter = true; | ||
|
||
public NewsListAdapter(Activity context, List<NewsBody> newsBodies) { | ||
this.context = context; | ||
this.newsBodies = newsBodies; | ||
} | ||
|
||
@Override | ||
public int getItemViewType(int position) { | ||
// 最后一个item设置为footerView | ||
if (!mShowFooter) { | ||
return TYPE_ITEM; | ||
} | ||
if (position + 1 == getItemCount()) { | ||
return TYPE_FOOTER; | ||
} else { | ||
return TYPE_ITEM; | ||
} | ||
} | ||
|
||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
if (viewType == TYPE_ITEM) { | ||
View v = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.item_news_list, parent, false); | ||
ItemViewHolder vh = new ItemViewHolder(v); | ||
return vh; | ||
} else { | ||
View view = LayoutInflater.from(parent.getContext()).inflate( | ||
R.layout.list_footer, null); | ||
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.WRAP_CONTENT)); | ||
return new FooterViewHolder(view); | ||
} | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { | ||
if (holder instanceof ItemViewHolder) { | ||
NewsBody item = newsBodies.get(position); | ||
ItemViewHolder holder1 = (ItemViewHolder) holder; | ||
|
||
if (item.imageurls != null && item.imageurls.size() > 0) { | ||
GlideUtil.loadImage(context, item.imageurls.get(0).url, holder1.imageView); | ||
} else { | ||
GlideUtil.loadImage(context, "", holder1.imageView); | ||
} | ||
holder1.title.setText(item.desc); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
int begin = mShowFooter ? 1 : 0; | ||
if (this.newsBodies == null) { | ||
return begin; | ||
} | ||
return this.newsBodies.size() + begin; | ||
} | ||
|
||
public void isShowFooter(boolean showFooter) { | ||
this.mShowFooter = showFooter; | ||
} | ||
|
||
public boolean isShowFooter() { | ||
return this.mShowFooter; | ||
} | ||
|
||
public class FooterViewHolder extends RecyclerView.ViewHolder { | ||
|
||
public FooterViewHolder(View view) { | ||
super(view); | ||
} | ||
|
||
} | ||
|
||
public class ItemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { | ||
@Bind(R.id.text) | ||
TextView title; | ||
@Bind(R.id.imageview) | ||
ImageView imageView; | ||
|
||
public ItemViewHolder(View itemView) { | ||
super(itemView); | ||
ButterKnife.bind(this, itemView); | ||
itemView.setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
mOnItemClickListener.onItemClick(v, this.getPosition()); | ||
} | ||
} | ||
|
||
public void setOnItemClickListener(OnItemClickListener onItemClickListener) { | ||
this.mOnItemClickListener = onItemClickListener; | ||
} | ||
|
||
/** | ||
* 点击条目接口 | ||
*/ | ||
public interface OnItemClickListener { | ||
void onItemClick(View view, int position); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/ly/supermvp/adapter/SectionsPagerAdapter.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,56 @@ | ||
package com.ly.supermvp.adapter; | ||
|
||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentPagerAdapter; | ||
|
||
import com.ly.supermvp.ui.activity.MainActivity; | ||
import com.ly.supermvp.ui.fragment.NewsFragment; | ||
import com.ly.supermvp.ui.fragment.WeatherFragment; | ||
|
||
/** | ||
* <Pre> | ||
* viewpager选项卡适配器 | ||
* </Pre> | ||
* | ||
* @author 刘阳 | ||
* @version 1.0 | ||
* <p/> | ||
* Create by 2016/1/27 16:26 | ||
*/ | ||
public class SectionsPagerAdapter extends FragmentPagerAdapter { | ||
|
||
public SectionsPagerAdapter(FragmentManager fm) { | ||
super(fm); | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
switch (position){ | ||
case 0: | ||
return NewsFragment.newInstance(); | ||
case 1: | ||
return WeatherFragment.newInstance(); | ||
} | ||
return MainActivity.PlaceholderFragment.newInstance(position + 1); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
// Show 3 total pages. | ||
return 3; | ||
} | ||
|
||
@Override | ||
public CharSequence getPageTitle(int position) { | ||
switch (position) { | ||
case 0: | ||
return "最新新闻"; | ||
case 1: | ||
return "天气预报"; | ||
case 2: | ||
return "SECTION 3"; | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.