├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-xxhdpi │ │ │ │ ├── day1.jpg │ │ │ │ ├── fuli.png │ │ │ │ ├── home.png │ │ │ │ ├── mine.png │ │ │ │ ├── author.png │ │ │ │ ├── night1.jpg │ │ │ │ ├── clean_cache.png │ │ │ │ ├── fuli_selected.png │ │ │ │ ├── home_selected.png │ │ │ │ ├── mine_selected.png │ │ │ │ └── sunny_night_day.png │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-ldpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable │ │ │ │ ├── shape_bq.xml │ │ │ │ ├── list_divider_day.xml │ │ │ │ ├── list_divider_night.xml │ │ │ │ ├── rac.xml │ │ │ │ ├── shape_bg_seclected.xml │ │ │ │ ├── shape_edit.xml │ │ │ │ ├── ic_add_black_24dp.xml │ │ │ │ ├── selector_bq.xml │ │ │ │ ├── ic_arrow_back_black_24dp.xml │ │ │ │ ├── ic_star_black_24dp.xml │ │ │ │ ├── ic_star_black_24dp_red.xml │ │ │ │ ├── ic_collections_black_24dp.xml │ │ │ │ ├── ic_search_black_24dp.xml │ │ │ │ ├── ic_search_brone_24dp.xml │ │ │ │ └── ic_search_white_24dp.xml │ │ │ ├── color │ │ │ │ └── selector_textcolor.xml │ │ │ ├── values │ │ │ │ ├── arrays.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── attr.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── menu │ │ │ │ └── menu.xml │ │ │ ├── transition-v21 │ │ │ │ └── arc_motion.xml │ │ │ └── layout │ │ │ │ ├── topview.xml │ │ │ │ ├── activity_collection.xml │ │ │ │ ├── item_only_icon.xml │ │ │ │ ├── tv_bq.xml │ │ │ │ ├── toolbar.xml │ │ │ │ ├── fragment_text.xml │ │ │ │ ├── item_mz.xml │ │ │ │ ├── activity_order.xml │ │ │ │ ├── activcity_mz_detail.xml │ │ │ │ ├── item_order.xml │ │ │ │ ├── fragment_common.xml │ │ │ │ ├── acticity_image_detail.xml │ │ │ │ ├── fragment_search_two.xml │ │ │ │ ├── fragment_collection.xml │ │ │ │ ├── fragment_mz.xml │ │ │ │ ├── fragment_index.xml │ │ │ │ ├── item_list.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── activity_detail.xml │ │ │ │ ├── fragment_search_first.xml │ │ │ │ ├── fragment_main.xml │ │ │ │ ├── activity_search.xml │ │ │ │ ├── item_index.xml │ │ │ │ └── fragment_setting.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── gank │ │ │ │ ├── ui │ │ │ │ ├── search │ │ │ │ │ ├── OnSelectListener.java │ │ │ │ │ ├── SearchEmptyFragment.java │ │ │ │ │ └── SearchResultFragment.java │ │ │ │ ├── adapter │ │ │ │ │ ├── base │ │ │ │ │ │ ├── ItemViewDelegate.java │ │ │ │ │ │ ├── CommonSimpleAdapter.java │ │ │ │ │ │ ├── ItemViewDelegateManager.java │ │ │ │ │ │ └── MultiItemTypeAdapter.java │ │ │ │ │ ├── MeiziAdapter.java │ │ │ │ │ ├── OrderAdapter.java │ │ │ │ │ ├── MyItenTouchCallback.java │ │ │ │ │ └── CommonAdapter.java │ │ │ │ ├── base │ │ │ │ │ ├── BaseEnum.java │ │ │ │ │ ├── LazyFragment.java │ │ │ │ │ ├── RxBus.java │ │ │ │ │ └── BaseFragment.java │ │ │ │ ├── collection │ │ │ │ │ ├── CollectionActivity.java │ │ │ │ │ └── CollectionFragment.java │ │ │ │ ├── order │ │ │ │ │ └── Order.java │ │ │ │ ├── meizi │ │ │ │ │ └── MeiziDetailActivity.java │ │ │ │ ├── detail │ │ │ │ │ └── ImageDetailActivity.java │ │ │ │ ├── setting │ │ │ │ │ └── SettingFragment.java │ │ │ │ └── MainActivity.java │ │ │ │ ├── business │ │ │ │ ├── request │ │ │ │ │ ├── IMeiziRequest.java │ │ │ │ │ ├── ISettingRequest.java │ │ │ │ │ ├── ISearchRequest.java │ │ │ │ │ └── IGankRequest.java │ │ │ │ ├── GankBus.java │ │ │ │ ├── constant │ │ │ │ │ └── GankResultCode.java │ │ │ │ ├── SettingBusiness.java │ │ │ │ ├── MeiziBusiness.java │ │ │ │ └── SearchBusiness.java │ │ │ │ ├── data │ │ │ │ ├── DataManager.java │ │ │ │ ├── preference │ │ │ │ │ ├── SharePreferenecesHelper.java │ │ │ │ │ └── AppSharePreferences.java │ │ │ │ ├── network │ │ │ │ │ ├── ApiHelper.java │ │ │ │ │ ├── ApiService.java │ │ │ │ │ ├── response │ │ │ │ │ │ ├── Response.java │ │ │ │ │ │ └── ThemeResponse.java │ │ │ │ │ ├── util │ │ │ │ │ │ └── CacheInterceptor.java │ │ │ │ │ └── AppApiHelper.java │ │ │ │ ├── database │ │ │ │ │ ├── DbHelper.java │ │ │ │ │ ├── entity │ │ │ │ │ │ ├── SearchHistory.java │ │ │ │ │ │ └── Image.java │ │ │ │ │ ├── dao │ │ │ │ │ │ ├── ImageDao.java │ │ │ │ │ │ ├── HistoryDao.java │ │ │ │ │ │ └── ResultDao.java │ │ │ │ │ ├── AppDatabase.java │ │ │ │ │ └── AppDbHelper.java │ │ │ │ └── AppDataManager.java │ │ │ │ ├── util │ │ │ │ ├── FileUtils.java │ │ │ │ ├── ListUtil.java │ │ │ │ ├── NetWorkUtils.java │ │ │ │ ├── WrapContentLinearLayoutManager.java │ │ │ │ ├── DensityUtil.java │ │ │ │ ├── RecyclerViewUtil.java │ │ │ │ ├── DataCleanManager.java │ │ │ │ ├── ReavalUtils.java │ │ │ │ ├── TimeUtils.java │ │ │ │ └── ItemDecoration.java │ │ │ │ ├── view │ │ │ │ ├── NoTouchViewPager.java │ │ │ │ └── OnlyIconItemView.java │ │ │ │ ├── Constants.java │ │ │ │ └── GankApp.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── gank │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── gank │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .gitignore ├── README.md ├── README_origin.md ├── gradlew.bat ├── versions.gradle └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/day1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/day1.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/fuli.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/fuli.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/home.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/mine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/mine.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/author.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/author.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/night1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/night1.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/mipmap-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/clean_cache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/clean_cache.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/fuli_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/fuli_selected.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/home_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/home_selected.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/mine_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/mine_selected.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/sunny_night_day.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MyateJx/GankIo-viabus-architecture/HEAD/app/src/main/res/drawable-xxhdpi/sunny_night_day.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_bq.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/list_divider_day.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/list_divider_night.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Mar 27 09:36:59 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/search/OnSelectListener.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.search; 2 | 3 | /** 4 | * Created by Administrator on 2017/4/28 0028. 5 | */ 6 | 7 | public interface OnSelectListener { 8 | void onSelected(String type); 9 | void onSearch(String searchContent); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/color/selector_textcolor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Android 6 | iOS 7 | 前端 8 | 拓展资源 9 | 休息视频 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/rac.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_bg_seclected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/base/ItemViewDelegate.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter.base; 2 | 3 | 4 | public interface ItemViewDelegate { 5 | 6 | int getItemViewLayoutId(); 7 | 8 | boolean isForViewType(T item, int position); 9 | 10 | void convert(ViewHolder holder, T t, int position); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/request/IMeiziRequest.java: -------------------------------------------------------------------------------- 1 | package com.gank.business.request; 2 | 3 | import com.kunminx.architecture.business.bus.IRequest; 4 | 5 | /** 6 | * @author MyateJx 7 | * @date 2018/10/9 8 | */ 9 | public interface IMeiziRequest extends IRequest { 10 | 11 | void queryMeiziList(String path); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/request/ISettingRequest.java: -------------------------------------------------------------------------------- 1 | package com.gank.business.request; 2 | 3 | import com.kunminx.architecture.business.bus.IRequest; 4 | 5 | /** 6 | * @author MyateJx 7 | * @date 2018/10/9 8 | */ 9 | public interface ISettingRequest extends IRequest { 10 | 11 | void queryTheme(); 12 | 13 | void setTheme(boolean hasTheme); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/DataManager.java: -------------------------------------------------------------------------------- 1 | package com.gank.data; 2 | 3 | import com.gank.data.database.DbHelper; 4 | import com.gank.data.network.ApiHelper; 5 | import com.gank.data.preference.SharePreferenecesHelper; 6 | 7 | /** 8 | * Created by Administrator on 2017/3/29 0029. 9 | */ 10 | 11 | public interface DataManager extends ApiHelper, DbHelper, SharePreferenecesHelper { 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/preference/SharePreferenecesHelper.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.preference; 2 | 3 | /** 4 | * Created by Administrator on 2017/4/18 0018. 5 | */ 6 | 7 | public interface SharePreferenecesHelper { 8 | void setOrder(String orderJsonStirng); 9 | 10 | String getOrderString(); 11 | 12 | void setTheme(boolean isNight); 13 | 14 | boolean getTheme(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_add_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_bq.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_back_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_star_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_star_black_24dp_red.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/network/ApiHelper.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.network; 2 | 3 | import com.gank.data.network.response.ThemeResponse; 4 | 5 | import io.reactivex.Observable; 6 | 7 | /** 8 | * Created by Administrator on 2017/3/27 0027. 9 | */ 10 | 11 | public interface ApiHelper { 12 | Observable getThemeDataCall(String path); 13 | 14 | Observable getSearchDataCall(String content,String type,String page); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/base/BaseEnum.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.base; 2 | 3 | /** 4 | * Created by wrh on 16/2/2. 5 | */ 6 | public enum BaseEnum { 7 | all("all"), Android("Android"),iOS("iOS") , qianduan("前端"),expand("拓展资源"),fuli("福利"), video("休息视频"); 8 | 9 | String value; 10 | 11 | private BaseEnum(String value) { 12 | this.value = value; 13 | } 14 | 15 | public String getValue() { 16 | return this.value; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/request/ISearchRequest.java: -------------------------------------------------------------------------------- 1 | package com.gank.business.request; 2 | 3 | import com.kunminx.architecture.business.bus.IRequest; 4 | 5 | /** 6 | * @author MyateJx 7 | * @date 2018/10/9 8 | */ 9 | public interface ISearchRequest extends IRequest { 10 | 11 | void search(String content, String type, String page); 12 | 13 | void insertHistory(String content); 14 | 15 | void querySearchHistory(); 16 | 17 | void deleteAll(); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/test/java/com/gank/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.gank; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_collections_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/transition-v21/arc_motion.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 干果 3 | 4 | 首页 5 | android 6 | ios 7 | 前端 8 | 9 | 福利 10 | 收藏 11 | 12 | 13 | translate_search 14 | 搜索 15 | translate_mz 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_brone_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/topview.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_collection.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_only_icon.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/tv_bq.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * Created by hefuyi on 16/7/30. 10 | */ 11 | public class FileUtils { 12 | 13 | private static final String HTTP_CACHE_DIR = "http"; 14 | 15 | public static final File getHttpCacheDir(Context context) { 16 | if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { 17 | return new File(context.getExternalCacheDir(), HTTP_CACHE_DIR); 18 | } 19 | return new File(context.getCacheDir(), HTTP_CACHE_DIR); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/collection/CollectionActivity.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.collection; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | 6 | import com.gank.R; 7 | import com.gank.ui.base.BaseActivity; 8 | 9 | /** 10 | * Created by Administrator on 2017/6/2 0002. 11 | */ 12 | 13 | public class CollectionActivity extends BaseActivity { 14 | 15 | @Override 16 | protected void onCreate(@Nullable Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_collection); 19 | } 20 | 21 | @Override 22 | protected void refreshUI() { 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/network/ApiService.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.network; 2 | 3 | import com.gank.Constants; 4 | import com.gank.data.network.response.ThemeResponse; 5 | 6 | import io.reactivex.Observable; 7 | import retrofit2.http.GET; 8 | import retrofit2.http.Path; 9 | 10 | /** 11 | * Created by Administrator on 2017/3/30 0030. 12 | */ 13 | 14 | public interface ApiService { 15 | @GET("data/{path}") 16 | Observable getThemeDataCall(@Path("path") String path); 17 | 18 | @GET("search/query/{content}/category/{type}/count/"+ Constants.PAGECOUNT+"/page/{page}") 19 | Observable getSearchDataCall(@Path("content") String content,@Path("type") String type,@Path("page") String page); 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/network/response/Response.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.network.response; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Created by Administrator on 2017/3/30 0030. 8 | */ 9 | 10 | public class Response { 11 | 12 | /** 13 | * error : false 14 | */ 15 | 16 | @SerializedName("error") 17 | private boolean error; 18 | 19 | public static Response objectFromData(String str) { 20 | 21 | return new Gson().fromJson(str, Response.class); 22 | } 23 | 24 | public boolean isError() { 25 | return error; 26 | } 27 | 28 | public void setError(boolean error) { 29 | this.error = error; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/DbHelper.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database; 2 | 3 | import com.gank.data.database.entity.Image; 4 | import com.gank.data.network.response.Result; 5 | 6 | import java.util.List; 7 | 8 | import io.reactivex.Observable; 9 | 10 | 11 | /** 12 | * Created by Administrator on 2017/4/14 0014. 13 | */ 14 | 15 | public interface DbHelper { 16 | Boolean getIsCollnection(String id); 17 | 18 | void addConnection(Result result); 19 | 20 | void addImage(Image img); 21 | 22 | void cancelCollection(String id); 23 | 24 | Observable> queryForList(int offset); 25 | 26 | void addSearchHistory(String content); 27 | 28 | Observable> querySearchHistory(); 29 | 30 | void deleteSearchHistory(); 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/view/NoTouchViewPager.java: -------------------------------------------------------------------------------- 1 | package com.gank.view; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | 8 | /** 9 | * 使ViewPager不能滑动 10 | */ 11 | public class NoTouchViewPager extends ViewPager{ 12 | 13 | public NoTouchViewPager(Context context) { 14 | super(context); 15 | } 16 | 17 | public NoTouchViewPager(Context context, AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | @Override 22 | public boolean onTouchEvent(MotionEvent event) { 23 | return false; 24 | } 25 | 26 | @Override 27 | public boolean onInterceptTouchEvent(MotionEvent event) { 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_mz.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 9 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/network/response/ThemeResponse.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.network.response; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Administrator on 2017/3/29 0029. 10 | */ 11 | 12 | public class ThemeResponse extends Response{ 13 | 14 | 15 | @SerializedName("results") 16 | private List mResults; 17 | 18 | public static ThemeResponse objectFromData(String str) { 19 | 20 | return new Gson().fromJson(str, ThemeResponse.class); 21 | } 22 | 23 | public List getResults() { 24 | return mResults; 25 | } 26 | 27 | public void setResults(List results) { 28 | this.mResults = results; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/request/IGankRequest.java: -------------------------------------------------------------------------------- 1 | package com.gank.business.request; 2 | 3 | import com.gank.data.network.response.Result; 4 | import com.gank.ui.order.Order; 5 | import com.kunminx.architecture.business.bus.IRequest; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author MyateJx 11 | * @date 2018/10/9 12 | */ 13 | public interface IGankRequest extends IRequest { 14 | 15 | void queryIndexList(String path); 16 | 17 | void queryOrderList(); 18 | 19 | void queryOrderString(); 20 | 21 | void setOrderString(List orderList); 22 | 23 | void queryCollectionData(int page); 24 | 25 | void queryIsLike(String id); 26 | 27 | void addCollection(Result result); 28 | 29 | void cancelLike(String id); 30 | 31 | void queryCommonList(String path); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/Constants.java: -------------------------------------------------------------------------------- 1 | package com.gank; 2 | 3 | /** 4 | * Created by hefuyi on 16/7/30. 5 | */ 6 | public class Constants { 7 | 8 | public static class Config { 9 | public static final int HTTP_CACHE_SIZE = 20 * 1024 * 1024; 10 | public static final int HTTP_CONNECT_TIMEOUT = 15 * 1000; 11 | public static final int HTTP_READ_TIMEOUT = 20 * 1000; 12 | } 13 | 14 | public static final String baseUrl = "http://gank.io/api/"; 15 | 16 | public static final int PAGECOUNT=20; 17 | 18 | public static String DB_NAME="gank.db"; 19 | public static String PREFERENCE_NAME="gank"; 20 | 21 | public static final int OPENSTATUS=0; 22 | public static final int CLOSESTATUS=1; 23 | 24 | public static boolean ERROR=false; 25 | 26 | public static boolean isNight; 27 | } 28 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/gank/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.gank; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.gank", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_order.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 10 | 11 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/ListUtil.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.io.ObjectInputStream; 7 | import java.io.ObjectOutputStream; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by Administrator on 2017/4/22 0022. 12 | */ 13 | 14 | public class ListUtil { 15 | public static List deepCopy(List src) throws IOException, ClassNotFoundException { 16 | ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); 17 | ObjectOutputStream out = new ObjectOutputStream(byteOut); 18 | out.writeObject(src); 19 | 20 | ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); 21 | ObjectInputStream in = new ObjectInputStream(byteIn); 22 | @SuppressWarnings("unchecked") 23 | List dest = (List) in.readObject(); 24 | return dest; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/GankBus.java: -------------------------------------------------------------------------------- 1 | package com.gank.business; 2 | 3 | import com.gank.business.request.IGankRequest; 4 | import com.gank.business.request.IMeiziRequest; 5 | import com.gank.business.request.ISearchRequest; 6 | import com.gank.business.request.ISettingRequest; 7 | import com.kunminx.architecture.business.bus.BaseBus; 8 | 9 | /** 10 | * @author MyateJx 11 | * @date 2018/10/9 12 | */ 13 | public class GankBus extends BaseBus { 14 | 15 | public static IGankRequest gank() { 16 | return (IGankRequest) getRequest(IGankRequest.class); 17 | } 18 | 19 | public static IMeiziRequest meizi() { 20 | return (IMeiziRequest) getRequest(IMeiziRequest.class); 21 | } 22 | 23 | public static ISearchRequest search() { 24 | return (ISearchRequest) getRequest(ISearchRequest.class); 25 | } 26 | 27 | public static ISettingRequest setting() { 28 | return (ISettingRequest) getRequest(ISettingRequest.class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/NetWorkUtils.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | /** 8 | * Created by hefuyi on 16/7/30. 9 | */ 10 | public class NetWorkUtils { 11 | public static final boolean isNetWorkAvailable(Context context) { 12 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService 13 | (Context.CONNECTIVITY_SERVICE); 14 | if (connectivityManager != null) { 15 | NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo(); 16 | if (networkInfos != null) { 17 | for (NetworkInfo info : networkInfos) { 18 | if (info.getState() == NetworkInfo.State.CONNECTED) { 19 | return true; 20 | } 21 | } 22 | } 23 | } 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activcity_mz_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 20 | 21 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_order.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 11 | 12 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/constant/GankResultCode.java: -------------------------------------------------------------------------------- 1 | package com.gank.business.constant; 2 | 3 | import com.kunminx.architecture.business.bus.ResultCode; 4 | 5 | /** 6 | * @author MyateJx 7 | * @date 2018/10/9 8 | */ 9 | public class GankResultCode extends ResultCode { 10 | 11 | public static final String INDEX_LIST_QUERYED = "INDEX_LIST_QUERYED"; 12 | public static final String MEIZI_LIST_QUERYED = "MEIZI_LIST_QUERYED"; 13 | public static final String ORDER_LIST_QUERYED = "ORDER_LIST_QUERYED"; 14 | public static final String COLLECT_LIST_QUERYED = "COLLECT_LIST_QUERYED"; 15 | public static final String SEARCH_LIST_QUERYED = "SEARCH_LIST_QUERYED"; 16 | public static final String HISTORY_LIST_QUERYED = "HISTORY_LIST_QUERYED"; 17 | public static final String CHANGE_THEME = "CHANGE_THEME"; 18 | public static final String SHOW_LIKE = "SHOW_LIKE"; 19 | public static final String ORDER_STRING_QUERYED = "ORDER_STRING_QUERYED"; 20 | public static final String COMMON_LIST_QUERYED = "COMMON_LIST_QUERYED"; 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and activity_order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_common.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/entity/SearchHistory.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database.entity; 2 | 3 | import android.arch.persistence.room.Entity; 4 | import android.arch.persistence.room.Ignore; 5 | import android.arch.persistence.room.PrimaryKey; 6 | 7 | 8 | /** 9 | * Created by Administrator on 2017/4/28 0028. 10 | */ 11 | @Entity 12 | public class SearchHistory { 13 | @PrimaryKey(autoGenerate = true) 14 | private Long id; 15 | private String searchContent; 16 | 17 | public SearchHistory(Long id, String searchContent) { 18 | this.id = id; 19 | this.searchContent = searchContent; 20 | } 21 | @Ignore 22 | public SearchHistory() { 23 | } 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getSearchContent() { 34 | return this.searchContent; 35 | } 36 | 37 | public void setSearchContent(String searchContent) { 38 | this.searchContent = searchContent; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/acticity_image_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 15 | 16 | 21 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/MeiziAdapter.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter; 2 | 3 | import android.content.Context; 4 | import android.widget.ImageView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 8 | import com.gank.R; 9 | import com.gank.data.network.response.Result; 10 | import com.gank.ui.adapter.base.CommonSimpleAdapter; 11 | import com.gank.ui.adapter.base.ViewHolder; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by Administrator on 2017/4/24 0024. 17 | */ 18 | 19 | public class MeiziAdapter extends CommonSimpleAdapter{ 20 | 21 | 22 | public MeiziAdapter(Context context, int layoutId, List datas) { 23 | super(context, layoutId, datas); 24 | } 25 | @Override 26 | protected void convert(ViewHolder holder, Result result, int position) { 27 | Glide.with(holder.itemView.getContext()) 28 | .load(result.getUrl()) 29 | .crossFade() 30 | .diskCacheStrategy(DiskCacheStrategy.ALL) 31 | .into((ImageView) holder.getView(R.id.mzimage)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_search_two.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/base/LazyFragment.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.base; 2 | 3 | import android.os.Bundle; 4 | 5 | /** 6 | * Created by Administrator on 2017/3/29 0029. 7 | */ 8 | 9 | public abstract class LazyFragment extends BaseFragment { 10 | 11 | protected boolean isViewInitiated; //控件是否初始化完成 12 | protected boolean isVisibleToUser; //页面是否可见 13 | protected boolean isDataInitiated; //数据是否加载 14 | 15 | 16 | @Override 17 | public void setUserVisibleHint(boolean isVisibleToUser) { 18 | super.setUserVisibleHint(isVisibleToUser); 19 | this.isVisibleToUser = isVisibleToUser; 20 | prepareFetchData(false); 21 | } 22 | 23 | @Override 24 | public void onActivityCreated(Bundle savedInstanceState) { 25 | super.onActivityCreated(savedInstanceState); 26 | isViewInitiated = true; 27 | prepareFetchData(false); 28 | } 29 | 30 | public abstract void loadData(); 31 | 32 | 33 | protected void prepareFetchData(boolean forceUpdate) { 34 | if (isVisibleToUser && isViewInitiated && (!isDataInitiated || forceUpdate)) { 35 | loadData(); 36 | isDataInitiated = true; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | ### Android template 11 | # Built application files 12 | *.apk 13 | *.ap_ 14 | 15 | # Files for the ART/Dalvik VM 16 | *.dex 17 | 18 | # Java class files 19 | *.class 20 | 21 | # Generated files 22 | bin/ 23 | gen/ 24 | out/ 25 | 26 | # Gradle files 27 | .gradle/ 28 | build/ 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Proguard folder generated by Eclipse 34 | proguard/ 35 | 36 | # Log Files 37 | *.log 38 | 39 | # Android Studio Navigation editor temp files 40 | .navigation/ 41 | 42 | # Android Studio captures folder 43 | captures/ 44 | 45 | # Intellij 46 | *.iml 47 | .idea/workspace.xml 48 | .idea/tasks.xml 49 | .idea/gradle.xml 50 | .idea/dictionaries 51 | .idea/libraries 52 | 53 | # Keystore files 54 | *.jks 55 | 56 | # External native build folder generated in Android Studio 2.2 and later 57 | .externalNativeBuild 58 | 59 | # Google Services (e.g. APIs or Firebase) 60 | google-services.json 61 | 62 | # Freeline 63 | freeline.py 64 | freeline/ 65 | freeline_project_description.json 66 | 67 | libs/ 68 | src/main/assets/ 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/dao/ImageDao.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database.dao; 2 | 3 | import android.arch.persistence.room.Dao; 4 | import android.arch.persistence.room.Delete; 5 | import android.arch.persistence.room.Insert; 6 | import android.arch.persistence.room.OnConflictStrategy; 7 | import android.arch.persistence.room.Query; 8 | import android.arch.persistence.room.Update; 9 | 10 | import com.gank.data.database.entity.Image; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author MyateJx 16 | * @date 2018/10/9 17 | */ 18 | @Dao 19 | public interface ImageDao { 20 | 21 | @Query("SELECT * FROM Image") 22 | List getBeans(); 23 | 24 | @Query("SELECT * FROM Image WHERE id=:id") 25 | List getBeans(String id); 26 | 27 | @Insert(onConflict = OnConflictStrategy.REPLACE) 28 | long insert(Image bean); 29 | 30 | @Update 31 | int update(Image bean); 32 | 33 | @Delete 34 | int delete(Image bean); 35 | 36 | @Query("Delete FROM Image where id=:id") 37 | int delete(String id); 38 | 39 | @Insert(onConflict = OnConflictStrategy.REPLACE) 40 | void inserts(List bean); 41 | 42 | @Update 43 | void updates(List bean); 44 | 45 | @Delete 46 | void deletes(List bean); 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/WrapContentLinearLayoutManager.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.AttributeSet; 7 | 8 | /** 9 | * Created by Administrator on 2017/4/29 0029. 10 | * recyclerview异常捕获 防止IndexOutOfBoundsException: Inconsistency detected引起的崩溃 11 | */ 12 | 13 | public class WrapContentLinearLayoutManager extends LinearLayoutManager { 14 | public WrapContentLinearLayoutManager(Context context) { 15 | super(context); 16 | } 17 | 18 | public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { 19 | super(context, orientation, reverseLayout); 20 | } 21 | 22 | public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 23 | super(context, attrs, defStyleAttr, defStyleRes); 24 | } 25 | 26 | @Override 27 | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { 28 | try { 29 | super.onLayoutChildren(recycler, state); 30 | } catch (IndexOutOfBoundsException e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/preference/AppSharePreferences.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.preference; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | /** 7 | * Created by Administrator on 2017/4/18 0018. 8 | */ 9 | 10 | 11 | public class AppSharePreferences implements SharePreferenecesHelper { 12 | 13 | private String PREF_KEY_ORDER = "PREF_KEY_ORDER"; 14 | private String MODE_NIGHT_OR_DAY = "MODE_NIGHT_OR_DAY"; 15 | 16 | private final SharedPreferences mPrefs; 17 | 18 | public AppSharePreferences(Context context, String preferencesname) { 19 | mPrefs = context.getSharedPreferences(preferencesname, Context.MODE_PRIVATE); 20 | } 21 | 22 | @Override 23 | public void setOrder(String orderJsonStirng) { 24 | mPrefs.edit().putString(PREF_KEY_ORDER, orderJsonStirng).commit(); 25 | } 26 | 27 | @Override 28 | public String getOrderString() { 29 | return mPrefs.getString(PREF_KEY_ORDER, ""); 30 | } 31 | 32 | @Override 33 | public void setTheme(boolean isNight) { 34 | mPrefs.edit().putBoolean(MODE_NIGHT_OR_DAY, isNight).commit(); 35 | } 36 | 37 | @Override 38 | public boolean getTheme() { 39 | return mPrefs.getBoolean(MODE_NIGHT_OR_DAY, false); 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_collection.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 15 | 16 | 23 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/network/util/CacheInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.network.util; 2 | 3 | 4 | import com.gank.GankApp; 5 | import com.gank.util.NetWorkUtils; 6 | 7 | import java.io.IOException; 8 | 9 | import okhttp3.CacheControl; 10 | import okhttp3.Interceptor; 11 | import okhttp3.Request; 12 | import okhttp3.Response; 13 | 14 | public class CacheInterceptor implements Interceptor { 15 | 16 | @Override 17 | public Response intercept(Chain chain) throws IOException { 18 | 19 | Request request = chain.request(); 20 | if (!NetWorkUtils.isNetWorkAvailable(GankApp.getAppContext())) { 21 | 22 | request = request.newBuilder() 23 | .cacheControl(CacheControl.FORCE_CACHE) 24 | .build(); 25 | } 26 | Response response = chain.proceed(request); 27 | // 10秒钟之内连续请求多次使用缓存数据 28 | if (NetWorkUtils.isNetWorkAvailable(GankApp.getAppContext())) { 29 | int maxAge = 10; 30 | response.newBuilder() 31 | .header("Cache-Control", "public, max-age=" + maxAge) 32 | // 清除头信息,因为服务器如果不支持,会返回一些干扰信息,不清除下面无法生效 33 | .removeHeader("Pragma") 34 | .build(); 35 | 36 | } 37 | return response; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_mz.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 16 | 17 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/base/CommonSimpleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter.base; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | 6 | import java.util.List; 7 | 8 | 9 | public abstract class CommonSimpleAdapter extends MultiItemTypeAdapter { 10 | protected Context mContext; 11 | protected int mLayoutId; 12 | protected List mDatas; 13 | protected LayoutInflater mInflater; 14 | 15 | public CommonSimpleAdapter(final Context context, final int layoutId, List datas) { 16 | super(context, datas); 17 | mContext = context; 18 | mInflater = LayoutInflater.from(context); 19 | mLayoutId = layoutId; 20 | mDatas = datas; 21 | 22 | addItemViewDelegate(new ItemViewDelegate() { 23 | @Override 24 | public int getItemViewLayoutId() { 25 | return layoutId; 26 | } 27 | 28 | @Override 29 | public boolean isForViewType(T item, int position) { 30 | return true; 31 | } 32 | 33 | @Override 34 | public void convert(ViewHolder holder, T t, int position) { 35 | CommonSimpleAdapter.this.convert(holder, t, position); 36 | } 37 | }); 38 | } 39 | 40 | protected abstract void convert(ViewHolder holder, T t, int position); 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/order/Order.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.order; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Administrator on 2017/4/18 0018. 7 | */ 8 | 9 | public class Order implements Serializable{ 10 | private String theme; 11 | private int status; 12 | 13 | public Order(String theme, int status) { 14 | this.theme = theme; 15 | this.status = status; 16 | } 17 | 18 | public int getStatus() { 19 | return status; 20 | } 21 | 22 | public void setStatus(int status) { 23 | this.status = status; 24 | } 25 | 26 | public String getTheme() { 27 | return theme; 28 | } 29 | 30 | public void setTheme(String theme) { 31 | this.theme = theme; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object o) { 36 | if (this == o) { 37 | return true; 38 | } 39 | if (o == null || getClass() != o.getClass()) { 40 | return false; 41 | } 42 | 43 | Order order = (Order) o; 44 | 45 | if (status != order.status) { 46 | return false; 47 | } 48 | return theme != null ? theme.equals(order.theme) : order.theme == null; 49 | 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | int result = theme != null ? theme.hashCode() : 0; 55 | result = 31 * result + status; 56 | return result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/dao/HistoryDao.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database.dao; 2 | 3 | import android.arch.persistence.room.Dao; 4 | import android.arch.persistence.room.Delete; 5 | import android.arch.persistence.room.Insert; 6 | import android.arch.persistence.room.OnConflictStrategy; 7 | import android.arch.persistence.room.Query; 8 | import android.arch.persistence.room.Update; 9 | 10 | import com.gank.data.database.entity.SearchHistory; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author MyateJx 16 | * @date 2018/10/9 17 | */ 18 | @Dao 19 | public interface HistoryDao { 20 | 21 | @Query("SELECT * FROM SearchHistory") 22 | List getBeans(); 23 | 24 | @Query("SELECT distinct searchContent FROM SearchHistory") 25 | List getContents(); 26 | 27 | @Query("SELECT * FROM SearchHistory WHERE id=:id") 28 | SearchHistory getBean(int id); 29 | 30 | @Insert(onConflict = OnConflictStrategy.REPLACE) 31 | long insert(SearchHistory bean); 32 | 33 | @Update 34 | int update(SearchHistory bean); 35 | 36 | @Delete 37 | int delete(SearchHistory bean); 38 | 39 | @Insert(onConflict = OnConflictStrategy.REPLACE) 40 | void inserts(List bean); 41 | 42 | @Update 43 | void updates(List bean); 44 | 45 | @Delete 46 | void deletes(List bean); 47 | 48 | @Query("Delete FROM SearchHistory") 49 | void deleteAll(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/dao/ResultDao.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database.dao; 2 | 3 | import android.arch.persistence.room.Dao; 4 | import android.arch.persistence.room.Delete; 5 | import android.arch.persistence.room.Insert; 6 | import android.arch.persistence.room.OnConflictStrategy; 7 | import android.arch.persistence.room.Query; 8 | import android.arch.persistence.room.Update; 9 | 10 | import com.gank.data.network.response.Result; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author MyateJx 16 | * @date 2018/10/9 17 | */ 18 | @Dao 19 | public interface ResultDao { 20 | 21 | @Query("SELECT * FROM Result") 22 | List getBeans(); 23 | 24 | @Query("SELECT * FROM Result WHERE id=:id") 25 | Result getBean(String id); 26 | 27 | @Query("SELECT * FROM Result limit :limit offset :offset") 28 | List getBeans(int limit, int offset); 29 | 30 | @Insert(onConflict = OnConflictStrategy.REPLACE) 31 | long insert(Result bean); 32 | 33 | @Update 34 | int update(Result bean); 35 | 36 | @Delete 37 | int delete(Result bean); 38 | 39 | @Query("Delete FROM Result where id=:id") 40 | int delete(String id); 41 | 42 | @Insert(onConflict = OnConflictStrategy.REPLACE) 43 | void inserts(List bean); 44 | 45 | @Update 46 | void updates(List bean); 47 | 48 | @Delete 49 | void deletes(List bean); 50 | 51 | @Query("Delete FROM Result") 52 | void deleteAll(); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/meizi/MeiziDetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.meizi; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 9 | import com.gank.R; 10 | import com.gank.databinding.ActivcityMzDetailBinding; 11 | import com.gank.ui.base.BaseActivity; 12 | 13 | /** 14 | * Created by Administrator on 2017/4/30 0030. 15 | */ 16 | 17 | public class MeiziDetailActivity extends BaseActivity { 18 | 19 | private ActivcityMzDetailBinding mBinding; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | mBinding = DataBindingUtil.setContentView(this, R.layout.activcity_mz_detail); 25 | initToolbar(mBinding.toolbar); 26 | mBinding.toolbar.setBackgroundColor(getResources().getColor(R.color.transparent)); 27 | mBinding.toolbar.setNavigationOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View v) { 30 | MeiziDetailActivity.super.onBackPressed(); 31 | } 32 | }); 33 | Glide.with(this).load(getIntent().getStringExtra("img_url")) 34 | .diskCacheStrategy(DiskCacheStrategy.ALL).crossFade().into(mBinding.photoView); 35 | } 36 | 37 | @Override 38 | protected void refreshUI() { 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/SettingBusiness.java: -------------------------------------------------------------------------------- 1 | package com.gank.business; 2 | 3 | import com.gank.business.constant.GankResultCode; 4 | import com.gank.business.request.ISettingRequest; 5 | import com.gank.data.AppDataManager; 6 | import com.gank.data.DataManager; 7 | import com.gank.util.LogUtils; 8 | import com.kunminx.architecture.business.BaseBusiness; 9 | import com.kunminx.architecture.business.bus.Result; 10 | 11 | import javax.inject.Inject; 12 | 13 | import io.reactivex.disposables.CompositeDisposable; 14 | 15 | /** 16 | * @author MyateJx 17 | * @date 2018/10/9 18 | */ 19 | public class SettingBusiness extends BaseBusiness implements ISettingRequest { 20 | 21 | private DataManager mDataManager; 22 | 23 | private CompositeDisposable mCompositeDisposable; 24 | 25 | public DataManager getDataManager() { 26 | return mDataManager; 27 | } 28 | 29 | public CompositeDisposable getCompositeDisposable() { 30 | return mCompositeDisposable; 31 | } 32 | 33 | public SettingBusiness() { 34 | this.mDataManager = AppDataManager.getInstance(); 35 | this.mCompositeDisposable = AppDataManager.getInstance().getCompositeDisposable(); 36 | } 37 | 38 | @Override 39 | public void queryTheme() { 40 | boolean hasTheme = getDataManager().getTheme(); 41 | GankBus.response(new Result(GankResultCode.CHANGE_THEME, hasTheme)); 42 | } 43 | 44 | @Override 45 | public void setTheme(boolean isNight) { 46 | mDataManager.setTheme(isNight); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 16 | 17 | 22 | 23 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 10 | 11 | 21 | 22 | 30 | 31 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | 18 | 19 | 24 | 25 | 26 | 27 | 32 | 33 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gank.io Viabus 重构版 2 | 3 | **介绍** 4 | --------- 5 | 6 | 一款基于Gank.io重构的客户端。项目采用 Viabus + Retrofit + RxJava 开发。首页布局样式大致参考掘金客户端。 7 | 8 | 项目重构思路请参考:[Android:你还在等那个,手把手带你重构的人出现吗?](https://juejin.im/post/5bcd58b6e51d45404c71d23f) 9 | 10 | 欢迎 Star & Fork ~ 11 | 12 | **应用截图** 13 | ----------- 14 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165508_%E7%BC%96%E8%BE%91.png?raw=true) 15 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165525_%E7%BC%96%E8%BE%91.png?raw=true) 16 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165650_%E7%BC%96%E8%BE%91.png?raw=true) 17 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165608_%E7%BC%96%E8%BE%91.png?raw=true) 18 | 19 | 20 | **Gif** 21 | 22 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/ezgif.com-resize.gif?raw=true) 23 | 24 | **特性** 25 | ----------- 26 | * 基本遵循 Materail Design 风格 27 | * Viabus 架构模式的项目应用 28 | * Retrofit + RxJava配合使用 29 | * Room 数据库实现本地收藏功能 30 | * 日夜模式平滑切换 31 | * Flexbox流式布局的使用 32 | * Viewpager + Fragment栏目动态切换 33 | * 共享元素和扩散效果 34 | 35 | **使用到的开源库** 36 | ----------- 37 | 38 | * 架构:Viabus 39 | * 网络请求:Retrofit2 40 | * 异步操作:Rxjava2 41 | * 数据库:Room 42 | * 图片加载:Glide 43 | * 上拉加载下拉刷新:TwinklingRefreshLayout https://github.com/lcodecorex/TwinklingRefreshLayout 44 | * 流式布局:Flexbox-layout 45 | * 底部导航:PagerBottomTabStrip https://github.com/tyzlmjj/PagerBottomTabStrip 46 | 47 | **更多参考** 48 | ----------- 49 | 50 | * 日夜切换参考了 https://github.com/hefuyicoder/ZhihuDaily 项目以及 http://www.jianshu.com/p/3b55e84742e5 这篇文章。效果非常不错 51 | 52 | * 重构前的项目链接:https://github.com/yanyiqun001/ganguo 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/OrderAdapter.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.SwitchCompat; 5 | import android.widget.CompoundButton; 6 | 7 | import com.gank.R; 8 | import com.gank.ui.adapter.base.CommonSimpleAdapter; 9 | import com.gank.ui.adapter.base.ViewHolder; 10 | import com.gank.ui.order.Order; 11 | 12 | import java.util.List; 13 | 14 | import static com.gank.Constants.OPENSTATUS; 15 | 16 | /** 17 | * Created by Administrator on 2017/5/2 0002. 18 | */ 19 | 20 | public class OrderAdapter extends CommonSimpleAdapter{ 21 | private SwitchChangeCallback switchChangeCallback; 22 | public OrderAdapter(Context context, int layoutId, List datas) { 23 | super(context, layoutId, datas); 24 | } 25 | 26 | @Override 27 | protected void convert(ViewHolder holder, Order order, final int position) { 28 | holder.setText(R.id.title,order.getTheme()); 29 | ((SwitchCompat)holder.getView(R.id.switchCompat)).setChecked(order.getStatus()==OPENSTATUS); 30 | ((SwitchCompat)holder.getView(R.id.switchCompat)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 31 | @Override 32 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 33 | switchChangeCallback.onChange(position,isChecked); 34 | } 35 | }); 36 | } 37 | 38 | public void setOnItemCheckedChanged(SwitchChangeCallback switchChangeCallback){ 39 | this.switchChangeCallback=switchChangeCallback; 40 | } 41 | 42 | public interface SwitchChangeCallback{ 43 | void onChange(int position, boolean isChecked); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README_origin.md: -------------------------------------------------------------------------------- 1 | # ganguo 2 | # 干果——简洁易用的gank客户端 3 | **介绍** 4 | --------- 5 | 一款基于GankIo开发的练手项目。项目采用 MVP+Dagger2+Retrofit + RxJava开发。首页布局样式大致参考掘金客户端。 6 | 7 | **应用截图** 8 | ----------- 9 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165508_%E7%BC%96%E8%BE%91.png?raw=true) 10 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165525_%E7%BC%96%E8%BE%91.png?raw=true) 11 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165650_%E7%BC%96%E8%BE%91.png?raw=true) 12 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/Screenshot_20170605-165608_%E7%BC%96%E8%BE%91.png?raw=true) 13 | 14 | 15 | **Gif** 16 | 17 | ![image](https://github.com/yanyiqun001/ganguo/blob/master/screenshots/ezgif.com-resize.gif?raw=true) 18 | 19 | **特性** 20 | ----------- 21 | * 基本遵循MD风格 22 | * MVP+dagger2架构模式的项目应用 23 | * retrofit+rxjava配合使用 24 | * rxbus组件间通讯 25 | * greendao实现本地收藏功能 26 | * 日夜模式平滑切换 27 | * flexbox流式布局的使用 28 | * viewpager+fragment栏目动态切换 29 | * 共享元素和扩散效果 30 | 31 | **使用到的开源库** 32 | ----------- 33 | 34 | * 网络请求:retrofit2 35 | * rxjava2 36 | * 依赖注入:dagger2 37 | * 数据库:greendao3 38 | * 图片加载:glide 39 | * butterknife 40 | * 上拉加载下拉刷新:TwinklingRefreshLayout https://github.com/lcodecorex/TwinklingRefreshLayout 41 | * 流式布局:flexbox-layout 42 | * 底部导航:PagerBottomTabStrip https://github.com/tyzlmjj/PagerBottomTabStrip 43 | 44 | **参考** 45 | ----------- 46 | * 架构部分参考项目 https://github.com/MindorksOpenSource/android-mvp-architecture 以及文章 47 | https://juejin.im/entry/58a5992961ff4b006c4455e3?utm_source=gold-miner&utm_medium=readme&utm_campaign=github 48 | 如果不了解dagger2,理解起来有些困难。但整体架构思路非常清晰,model层次划分非常细致。 49 | 50 | * 日夜切换参考了https://github.com/hefuyicoder/ZhihuDaily 项目以及 http://www.jianshu.com/p/3b55e84742e5 这篇文章。效果非常不错 -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/detail/ImageDetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.detail; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 9 | import com.bumptech.glide.load.resource.drawable.GlideDrawable; 10 | import com.bumptech.glide.request.animation.GlideAnimation; 11 | import com.bumptech.glide.request.target.GlideDrawableImageViewTarget; 12 | import com.gank.R; 13 | import com.gank.databinding.ActicityImageDetailBinding; 14 | import com.gank.ui.base.BaseActivity; 15 | 16 | /** 17 | * Created by Administrator on 2017/4/17 0017. 18 | */ 19 | 20 | public class ImageDetailActivity extends BaseActivity { 21 | 22 | private ActicityImageDetailBinding mBinding; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | mBinding = DataBindingUtil.setContentView(this, R.layout.acticity_image_detail); 28 | 29 | String url = getIntent().getStringExtra("imgUrl"); 30 | Glide.with(this).load(url).crossFade().diskCacheStrategy(DiskCacheStrategy.SOURCE) 31 | .into(new GlideDrawableImageViewTarget(mBinding.photoView) { 32 | @Override 33 | public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) { 34 | super.onResourceReady(drawable, anim); 35 | mBinding.pb.setVisibility(View.GONE); 36 | } 37 | }); 38 | initToolbar(mBinding.toolbar); 39 | mBinding.toolbar.setBackgroundColor(getResources().getColor(R.color.black)); 40 | 41 | } 42 | 43 | @Override 44 | protected void refreshUI() { 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/view/OnlyIconItemView.java: -------------------------------------------------------------------------------- 1 | package com.gank.view; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.DrawableRes; 5 | import android.util.AttributeSet; 6 | import android.view.LayoutInflater; 7 | import android.widget.ImageView; 8 | 9 | import com.gank.R; 10 | 11 | import me.majiajie.pagerbottomtabstrip.item.BaseTabItem; 12 | 13 | /** 14 | * Created by Administrator on 2017/4/20 0020. 15 | */ 16 | 17 | public class OnlyIconItemView extends BaseTabItem{ 18 | private ImageView mIcon; 19 | 20 | private int mDefaultDrawable; 21 | private int mCheckedDrawable; 22 | 23 | public OnlyIconItemView(Context context) { 24 | this(context,null); 25 | } 26 | 27 | public OnlyIconItemView(Context context, AttributeSet attrs) { 28 | this(context, attrs,0); 29 | } 30 | 31 | public OnlyIconItemView(Context context, AttributeSet attrs, int defStyleAttr) { 32 | super(context, attrs, defStyleAttr); 33 | 34 | LayoutInflater.from(context).inflate(R.layout.item_only_icon, this, true); 35 | 36 | mIcon = (ImageView) findViewById(R.id.icon); 37 | } 38 | 39 | public void initialize(@DrawableRes int drawableRes, @DrawableRes int checkedDrawableRes) 40 | { 41 | mDefaultDrawable = drawableRes; 42 | mCheckedDrawable = checkedDrawableRes; 43 | } 44 | 45 | @Override 46 | public void setChecked(boolean checked) { 47 | mIcon.setImageResource(checked ? mCheckedDrawable : mDefaultDrawable); 48 | } 49 | 50 | @Override 51 | public void setMessageNumber(int number) { 52 | //不需要就不用管 53 | } 54 | 55 | @Override 56 | public void setHasMessage(boolean hasMessage) { 57 | //不需要就不用管 58 | } 59 | 60 | @Override 61 | public String getTitle() { 62 | return "no title"; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/MyItenTouchCallback.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter; 2 | 3 | import android.support.v7.widget.GridLayoutManager; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.support.v7.widget.helper.ItemTouchHelper; 6 | 7 | /** 8 | * Created by Administrator on 2017/4/18 0018. 9 | */ 10 | 11 | public class MyItenTouchCallback extends ItemTouchHelper.Callback { 12 | private OrderAdapter recyclerViewAdapter; 13 | private SwapCallBack swapCallBack; 14 | public MyItenTouchCallback(OrderAdapter recyclerViewAdapter, SwapCallBack swapCallBack) { 15 | this.recyclerViewAdapter=recyclerViewAdapter; 16 | this.swapCallBack=swapCallBack; 17 | } 18 | 19 | @Override 20 | public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { 21 | int dragFlag; 22 | int swipeFlag; 23 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); 24 | if (layoutManager instanceof GridLayoutManager) { 25 | dragFlag = ItemTouchHelper.DOWN | ItemTouchHelper.UP 26 | | ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT; 27 | swipeFlag = 0; 28 | } else { 29 | dragFlag = ItemTouchHelper.DOWN | ItemTouchHelper.UP; 30 | swipeFlag = 0; 31 | } 32 | return makeMovementFlags(dragFlag, swipeFlag); 33 | } 34 | 35 | @Override 36 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { 37 | int fromPosition = viewHolder.getAdapterPosition(); 38 | int toPosition = target.getAdapterPosition(); 39 | swapCallBack.onSwip(fromPosition,toPosition); 40 | return true; 41 | 42 | } 43 | 44 | @Override 45 | public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { 46 | } 47 | 48 | public interface SwapCallBack{ 49 | void onSwip(int fromPosition ,int toPosition); 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/MeiziBusiness.java: -------------------------------------------------------------------------------- 1 | package com.gank.business; 2 | 3 | import com.gank.business.constant.GankResultCode; 4 | import com.gank.business.request.IMeiziRequest; 5 | import com.gank.data.AppDataManager; 6 | import com.gank.data.DataManager; 7 | import com.gank.data.network.response.ThemeResponse; 8 | import com.kunminx.architecture.business.BaseBusiness; 9 | import com.kunminx.architecture.business.bus.Result; 10 | 11 | import io.reactivex.android.schedulers.AndroidSchedulers; 12 | import io.reactivex.disposables.CompositeDisposable; 13 | import io.reactivex.functions.Consumer; 14 | import io.reactivex.schedulers.Schedulers; 15 | 16 | /** 17 | * @author MyateJx 18 | * @date 2018/10/9 19 | */ 20 | public class MeiziBusiness extends BaseBusiness implements IMeiziRequest { 21 | 22 | private DataManager mDataManager; 23 | 24 | private CompositeDisposable mCompositeDisposable; 25 | 26 | public DataManager getDataManager() { 27 | return mDataManager; 28 | } 29 | 30 | public CompositeDisposable getCompositeDisposable() { 31 | return mCompositeDisposable; 32 | } 33 | 34 | public MeiziBusiness() { 35 | this.mDataManager = AppDataManager.getInstance(); 36 | this.mCompositeDisposable = AppDataManager.getInstance().getCompositeDisposable(); 37 | } 38 | 39 | @Override 40 | public void queryMeiziList(String path) { 41 | getCompositeDisposable().add( 42 | getDataManager().getThemeDataCall(path) 43 | .subscribeOn(Schedulers.io()) 44 | .observeOn(AndroidSchedulers.mainThread()) 45 | .subscribe(new Consumer() { 46 | @Override 47 | public void accept(ThemeResponse themeResponse) throws Exception { 48 | GankBus.response(new Result(GankResultCode.MEIZI_LIST_QUERYED, themeResponse.getResults())); 49 | } 50 | })); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/AppDatabase.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database; 2 | 3 | import android.arch.persistence.room.Database; 4 | import android.arch.persistence.room.Room; 5 | import android.arch.persistence.room.RoomDatabase; 6 | import android.content.Context; 7 | import android.support.annotation.NonNull; 8 | 9 | import com.gank.data.database.dao.HistoryDao; 10 | import com.gank.data.database.dao.ImageDao; 11 | import com.gank.data.database.dao.ResultDao; 12 | import com.gank.data.database.entity.Image; 13 | import com.gank.data.database.entity.SearchHistory; 14 | import com.gank.data.network.response.Result; 15 | 16 | /** 17 | * @author MyateJx 18 | * @date 2018/6/30 19 | */ 20 | @Database(entities = {Result.class, Image.class, SearchHistory.class}, version = 1, exportSchema = false) 21 | public abstract class AppDatabase extends RoomDatabase { 22 | 23 | private static String sDbPath = null; 24 | 25 | private static AppDatabase INSTANCE = null; 26 | 27 | private static Context mContext; 28 | 29 | 30 | public static void init(Context context, String dbPath) { 31 | mContext = context; 32 | sDbPath = dbPath; 33 | if (INSTANCE != null) { 34 | INSTANCE.close(); 35 | INSTANCE = null; 36 | } 37 | } 38 | 39 | public synchronized static AppDatabase getInstance() { 40 | if (INSTANCE == null) { 41 | synchronized (AppDatabase.class) { 42 | if (INSTANCE == null) { 43 | INSTANCE = Room.databaseBuilder(mContext.getApplicationContext(), AppDatabase.class, sDbPath) 44 | .allowMainThreadQueries() 45 | .build(); 46 | } 47 | 48 | } 49 | } 50 | return INSTANCE; 51 | } 52 | 53 | public static RoomDatabase getDatabase(@NonNull Context context, String dbPath) { 54 | return Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, dbPath) 55 | .allowMainThreadQueries() 56 | .build(); 57 | } 58 | 59 | public abstract HistoryDao historyDao(); 60 | 61 | public abstract ImageDao imageDao(); 62 | 63 | public abstract ResultDao resultDao(); 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/entity/Image.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database.entity; 2 | 3 | import android.arch.persistence.room.Entity; 4 | import android.arch.persistence.room.Ignore; 5 | import android.arch.persistence.room.PrimaryKey; 6 | import android.os.Parcel; 7 | import android.os.Parcelable; 8 | 9 | 10 | /** 11 | * Created by Administrator on 2017/4/17 0017. 12 | */ 13 | @Entity 14 | public class Image implements Parcelable { 15 | 16 | @PrimaryKey(autoGenerate = true) 17 | private Long id; 18 | private String imageUrl; 19 | private String imageId; 20 | 21 | public Image(Long id, String imageUrl, String imageId) { 22 | this.id = id; 23 | this.imageUrl = imageUrl; 24 | this.imageId = imageId; 25 | } 26 | 27 | @Ignore 28 | public Image(String imageId) { 29 | this.imageId = imageId; 30 | } 31 | @Ignore 32 | public Image() { 33 | } 34 | 35 | public Long getId() { 36 | return this.id; 37 | } 38 | 39 | public void setId(Long id) { 40 | this.id = id; 41 | } 42 | 43 | public String getImageUrl() { 44 | return this.imageUrl; 45 | } 46 | 47 | public void setImageUrl(String imageUrl) { 48 | this.imageUrl = imageUrl; 49 | } 50 | 51 | public String getImageId() { 52 | return this.imageId; 53 | } 54 | 55 | public void setImageId(String imageId) { 56 | this.imageId = imageId; 57 | } 58 | 59 | @Override 60 | public int describeContents() { 61 | return 0; 62 | } 63 | 64 | @Override 65 | public void writeToParcel(Parcel dest, int flags) { 66 | dest.writeValue(this.id); 67 | dest.writeString(this.imageUrl); 68 | dest.writeString(this.imageId); 69 | } 70 | @Ignore 71 | private Image(Parcel in) { 72 | this.id = (Long) in.readValue(Long.class.getClassLoader()); 73 | this.imageUrl = in.readString(); 74 | this.imageId = in.readString(); 75 | } 76 | 77 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 78 | @Override 79 | public Image createFromParcel(Parcel source) { 80 | return new Image(source); 81 | } 82 | 83 | @Override 84 | public Image[] newArray(int size) { 85 | return new Image[size]; 86 | } 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/GankApp.java: -------------------------------------------------------------------------------- 1 | package com.gank; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.facebook.stetho.Stetho; 7 | import com.gank.business.GankBus; 8 | import com.gank.business.GankBusiness; 9 | import com.gank.business.MeiziBusiness; 10 | import com.gank.business.SearchBusiness; 11 | import com.gank.business.SettingBusiness; 12 | import com.gank.data.AppDataManager; 13 | import com.gank.util.LogUtils; 14 | import com.squareup.leakcanary.LeakCanary; 15 | 16 | 17 | /** 18 | * Created by Administrator on 2017/3/27 0027. 19 | */ 20 | 21 | public class GankApp extends Application { 22 | private static Context context; 23 | 24 | @Override 25 | public void onCreate() { 26 | super.onCreate(); 27 | context = getApplicationContext(); 28 | 29 | AppDataManager.getInstance().init(getApplicationContext()); 30 | GankBus.registerRequestHandler(new GankBusiness()); 31 | GankBus.registerRequestHandler(new MeiziBusiness()); 32 | GankBus.registerRequestHandler(new SearchBusiness()); 33 | GankBus.registerRequestHandler(new SettingBusiness()); 34 | 35 | new LogUtils.Builder() 36 | .setLogSwitch(BuildConfig.DEBUG)// 设置log总开关,默认开 37 | .setGlobalTag("CMJ")// 设置log全局标签,默认为空 38 | // 当全局标签不为空时,我们输出的log全部为该tag, 39 | // 为空时,如果传入的tag为空那就显示类名,否则显示tag 40 | .setLog2FileSwitch(false)// 打印log时是否存到文件的开关,默认关 41 | .setBorderSwitch(true)// 输出日志是否带边框开关,默认开 42 | .setLogFilter(LogUtils.V);// log过滤器,和logcat过滤器同理,默认Verbose 43 | 44 | Stetho.initialize( 45 | Stetho.newInitializerBuilder(context) 46 | .enableDumpapp( 47 | Stetho.defaultDumperPluginsProvider(context)) 48 | .enableWebKitInspector( 49 | Stetho.defaultInspectorModulesProvider(context)) 50 | .build()); 51 | 52 | if (LeakCanary.isInAnalyzerProcess(this)) { 53 | // This process is dedicated to LeakCanary for heap analysis. 54 | // You should not init your app in this process. 55 | return; 56 | } 57 | // LeakCanary.install(this); 58 | } 59 | 60 | public static Context getAppContext() { 61 | return context; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/base/RxBus.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.base; 2 | 3 | import android.support.annotation.NonNull; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | 9 | import io.reactivex.Observable; 10 | import io.reactivex.subjects.PublishSubject; 11 | import io.reactivex.subjects.Subject; 12 | 13 | /** 14 | * Created by Administrator on 2017/5/16 0016. 15 | */ 16 | 17 | 18 | public class RxBus { 19 | 20 | private ConcurrentHashMap> subjectMapper = new ConcurrentHashMap<>(); 21 | 22 | private RxBus() { 23 | 24 | } 25 | 26 | private static class Holder { 27 | private static RxBus instance = new RxBus(); 28 | } 29 | 30 | public static RxBus getInstance() { 31 | return Holder.instance; 32 | } 33 | 34 | public Observable register(@NonNull Class clz) { 35 | return register(clz.getName()); 36 | } 37 | 38 | public Observable register(@NonNull Object tag) { 39 | List subjectList = subjectMapper.get(tag); 40 | if (null == subjectList) { 41 | subjectList = new ArrayList<>(); 42 | subjectMapper.put(tag, subjectList); 43 | } 44 | 45 | Subject subject = PublishSubject.create(); 46 | subjectList.add(subject); 47 | 48 | //System.out.println("注册到rxbus"); 49 | return subject; 50 | } 51 | 52 | public void unregister(@NonNull Class clz, @NonNull Observable observable) { 53 | unregister(clz.getName(), observable); 54 | } 55 | 56 | public void unregister(@NonNull Object tag, @NonNull Observable observable) { 57 | List subjects = subjectMapper.get(tag); 58 | if (null != subjects) { 59 | subjects.remove(observable); 60 | if (subjects.isEmpty()) { 61 | subjectMapper.remove(tag); 62 | //System.out.println("从rxbus取消注册"); 63 | } 64 | } 65 | } 66 | 67 | public void post(@NonNull Object content) { 68 | post(content.getClass().getName(), content); 69 | } 70 | 71 | public void post(@NonNull Object tag, @NonNull Object content) { 72 | List subjects = subjectMapper.get(tag); 73 | if (!subjects.isEmpty()) { 74 | for (Subject subject: subjects) { 75 | subject.onNext(content); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/DensityUtil.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.Point; 6 | import android.util.DisplayMetrics; 7 | import android.view.Display; 8 | import android.view.WindowManager; 9 | 10 | import java.lang.reflect.InvocationTargetException; 11 | 12 | /** 13 | * Created by hefuyi on 16/7/30. 14 | */ 15 | public class DensityUtil { 16 | 17 | public static int getScreenHeight(Context context) { 18 | DisplayMetrics displayMetrics = new DisplayMetrics(); 19 | ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 20 | return displayMetrics.heightPixels; 21 | } 22 | 23 | public static int getScreenWidth(Context context) { 24 | DisplayMetrics displayMetrics = new DisplayMetrics(); 25 | ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 26 | return displayMetrics.widthPixels; 27 | } 28 | 29 | public static int getScreenHeightWithDecorations(Context context) { 30 | int heightPixes; 31 | WindowManager windowManager = ((Activity) context).getWindowManager(); 32 | Display display = windowManager.getDefaultDisplay(); 33 | Point realSize = new Point(); 34 | try { 35 | Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize); 36 | } catch (NoSuchMethodException e) { 37 | e.printStackTrace(); 38 | } catch (IllegalAccessException e) { 39 | e.printStackTrace(); 40 | } catch (InvocationTargetException e) { 41 | e.printStackTrace(); 42 | } 43 | heightPixes = realSize.y; 44 | return heightPixes; 45 | } 46 | 47 | public static int dip2px(Context context, float dpVale) { 48 | final float scale = context.getResources().getDisplayMetrics().density; 49 | return (int) (dpVale * scale + 0.5f); 50 | } 51 | 52 | public static int px2dip(Context context, float pxValue) { 53 | final float scale = context.getResources().getDisplayMetrics().density; 54 | return (int) (pxValue / scale + 0.5f); 55 | } 56 | 57 | public static String sizeOfImageforFullWidth(Context context, float pxValue) { 58 | return "?imageView2/0/w/" 59 | + getScreenWidth(context) + "/h/" + DensityUtil.dip2px(context, pxValue); 60 | } 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/database/AppDbHelper.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.database; 2 | 3 | import android.content.Context; 4 | 5 | import com.gank.data.database.entity.Image; 6 | import com.gank.data.database.entity.SearchHistory; 7 | import com.gank.data.network.response.Result; 8 | 9 | import java.util.List; 10 | import java.util.concurrent.Callable; 11 | 12 | import io.reactivex.Observable; 13 | 14 | import static com.gank.Constants.PAGECOUNT; 15 | 16 | /** 17 | * @author MyateJx 18 | * @date 2018/10/9 19 | */ 20 | public class AppDbHelper implements DbHelper { 21 | 22 | public AppDbHelper(Context context, String dbName) { 23 | AppDatabase.init(context, dbName); 24 | } 25 | 26 | @Override 27 | public Boolean getIsCollnection(String id) { 28 | return AppDatabase.getInstance().resultDao().getBean(id) != null; 29 | } 30 | 31 | @Override 32 | public Observable> queryForList(final int offset) { 33 | return Observable.fromCallable(new Callable>() { 34 | @Override 35 | public List call() throws Exception { 36 | return AppDatabase.getInstance().resultDao().getBeans(PAGECOUNT, (offset - 1) * PAGECOUNT); 37 | } 38 | }); 39 | } 40 | 41 | @Override 42 | public void addSearchHistory(String content) { 43 | AppDatabase.getInstance().historyDao().insert(new SearchHistory(null, content)); 44 | } 45 | 46 | @Override 47 | public Observable> querySearchHistory() { 48 | return Observable.fromCallable(new Callable>() { 49 | @Override 50 | public List call() throws Exception { 51 | return AppDatabase.getInstance().historyDao().getContents(); 52 | } 53 | }); 54 | 55 | } 56 | 57 | @Override 58 | public void deleteSearchHistory() { 59 | AppDatabase.getInstance().historyDao().deleteAll(); 60 | } 61 | 62 | @Override 63 | public void addConnection(Result result) { 64 | AppDatabase.getInstance().resultDao().insert(result); 65 | } 66 | 67 | @Override 68 | public void addImage(Image img) { 69 | AppDatabase.getInstance().imageDao().insert(img); 70 | } 71 | 72 | @Override 73 | public void cancelCollection(String id) { 74 | AppDatabase.getInstance().resultDao().delete(id); 75 | AppDatabase.getInstance().imageDao().delete(id); 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/base/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.base; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.widget.Toolbar; 8 | import android.util.TypedValue; 9 | 10 | import com.gank.R; 11 | import com.gank.ui.main.MainFragment; 12 | import com.gank.ui.meizi.MeiziFragment; 13 | import com.gank.ui.setting.SettingFragment; 14 | 15 | import io.reactivex.Observable; 16 | import io.reactivex.functions.Consumer; 17 | 18 | /** 19 | * Created by Administrator on 2017/3/27 0027. 20 | */ 21 | 22 | public abstract class BaseFragment extends Fragment { 23 | protected BaseActivity mActivity; 24 | Observable observable; 25 | 26 | @Override 27 | public void onCreate(@Nullable Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | } 30 | 31 | protected abstract void refreshUI(); 32 | 33 | public static BaseFragment newInstance(int position) { 34 | BaseFragment fragment; 35 | if (position == 0) { 36 | fragment = new MainFragment(); 37 | } else if (position == 1) { 38 | fragment = new MeiziFragment(); 39 | } else { 40 | fragment = new SettingFragment(); 41 | } 42 | return fragment; 43 | } 44 | 45 | @Override 46 | public void onAttach(Context context) { 47 | super.onAttach(context); 48 | if (context instanceof BaseActivity) { 49 | BaseActivity activity = (BaseActivity) context; 50 | mActivity = activity; 51 | observable = RxBus.getInstance().register(Boolean.class); 52 | observable.subscribe(new Consumer() { 53 | @Override 54 | public void accept(Boolean aBoolean) throws Exception { 55 | refreshUI(); 56 | } 57 | }); 58 | } 59 | 60 | } 61 | 62 | protected void refreshToolbar(Toolbar toolbar) { 63 | TypedValue typedValue = new TypedValue(); 64 | getActivity().getTheme().resolveAttribute(R.attr.toolbarcolor, typedValue, true); 65 | toolbar.setBackgroundColor(getResources().getColor(typedValue.resourceId)); 66 | } 67 | 68 | @Override 69 | public void onDetach() { 70 | super.onDetach(); 71 | mActivity = null; 72 | RxBus.getInstance().unregister(Boolean.class, observable); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/network/AppApiHelper.java: -------------------------------------------------------------------------------- 1 | package com.gank.data.network; 2 | 3 | import android.content.Context; 4 | 5 | import com.gank.Constants; 6 | import com.gank.data.network.response.ThemeResponse; 7 | import com.gank.data.network.util.CacheInterceptor; 8 | import com.gank.util.FileUtils; 9 | import com.google.gson.Gson; 10 | import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; 11 | 12 | import java.util.concurrent.TimeUnit; 13 | 14 | import io.reactivex.Observable; 15 | import okhttp3.Cache; 16 | import okhttp3.OkHttpClient; 17 | import okhttp3.logging.HttpLoggingInterceptor; 18 | import retrofit2.Retrofit; 19 | import retrofit2.converter.gson.GsonConverterFactory; 20 | 21 | import static com.gank.Constants.baseUrl; 22 | 23 | /** 24 | * Created by Administrator on 2017/3/27 0027. 25 | */ 26 | public class AppApiHelper implements ApiHelper { 27 | ApiService mApiSerVice; 28 | 29 | public AppApiHelper(Context context) { 30 | this.mApiSerVice = getRetrofit(context).create(ApiService.class); 31 | } 32 | 33 | @Override 34 | public Observable getThemeDataCall(String path) { 35 | return mApiSerVice.getThemeDataCall(path); 36 | } 37 | 38 | @Override 39 | public Observable getSearchDataCall(String content, String type, String page) { 40 | return mApiSerVice.getSearchDataCall(content, type, page); 41 | } 42 | 43 | Retrofit getRetrofit(Context context) { 44 | Gson gson = new Gson(); 45 | GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson); 46 | 47 | HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); 48 | 49 | OkHttpClient client = new OkHttpClient.Builder() 50 | .cache(new Cache(FileUtils.getHttpCacheDir(context), Constants.Config.HTTP_CACHE_SIZE)) 51 | .connectTimeout(Constants.Config.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS) 52 | .readTimeout(Constants.Config.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS) 53 | .addInterceptor(loggingInterceptor) 54 | .addInterceptor(new CacheInterceptor()) 55 | .build(); 56 | 57 | Retrofit retrofit = new Retrofit.Builder() 58 | .baseUrl(baseUrl) 59 | .client(client) 60 | .addConverterFactory(gsonConverterFactory) 61 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) 62 | .build(); 63 | 64 | return retrofit; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/RecyclerViewUtil.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | 6 | import com.gank.Constants; 7 | import com.gank.R; 8 | import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout; 9 | import com.lcodecore.tkrefreshlayout.header.progresslayout.ProgressLayout; 10 | 11 | import java.lang.reflect.Field; 12 | import java.lang.reflect.InvocationTargetException; 13 | import java.lang.reflect.Method; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by Administrator on 2017/4/24 0024. 18 | */ 19 | 20 | public class RecyclerViewUtil { 21 | public static void setHeader(Context context, TwinklingRefreshLayout refreshLayout) { 22 | ProgressLayout header = new ProgressLayout(context); 23 | header.setColorSchemeResources(R.color.Blue, R.color.Orange, R.color.Yellow, R.color.Green); 24 | refreshLayout.setHeaderView(header); 25 | refreshLayout.setFloatRefresh(true); 26 | refreshLayout.setEnableLoadmore(false); 27 | refreshLayout.setAutoLoadMore(false); 28 | } 29 | public static void loadMoreSetting(TwinklingRefreshLayout refreshLayout,List list) { 30 | refreshLayout.finishLoadmore(); 31 | refreshLayout.finishRefreshing(); 32 | if (list.size() >= Constants.PAGECOUNT) { 33 | refreshLayout.setEnableLoadmore(true); 34 | refreshLayout.setAutoLoadMore(true); 35 | } 36 | } 37 | 38 | /** 39 | * 使RecyclerView缓存中在pool中的Item失效 40 | */ 41 | public static void invalidateCacheItem(RecyclerView recyclerView) { 42 | Class recyclerViewClass = RecyclerView.class; 43 | try { 44 | Field declaredField = recyclerViewClass.getDeclaredField("mRecycler"); 45 | declaredField.setAccessible(true); 46 | Method declaredMethod = Class.forName(RecyclerView.Recycler.class.getName()).getDeclaredMethod("clear", (Class[]) new Class[0]); 47 | declaredMethod.setAccessible(true); 48 | declaredMethod.invoke(declaredField.get(recyclerView), new Object[0]); 49 | RecyclerView.RecycledViewPool recycledViewPool = recyclerView.getRecycledViewPool(); 50 | recycledViewPool.clear(); 51 | } catch (NoSuchFieldException e) { 52 | e.printStackTrace(); 53 | } catch (ClassNotFoundException e) { 54 | e.printStackTrace(); 55 | } catch (NoSuchMethodException e) { 56 | e.printStackTrace(); 57 | } catch (InvocationTargetException e) { 58 | e.printStackTrace(); 59 | } catch (IllegalAccessException e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 16 | 17 | 20 | 21 | 26 | 27 | 28 | 33 | 34 | 38 | 39 | 43 | 44 | 47 | 48 | 55 | 56 | 57 | 58 | 59 | 60 | 65 | 66 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | android { 3 | compileSdkVersion build_versions.target_sdk 4 | buildToolsVersion build_versions.build_tools 5 | defaultConfig { 6 | minSdkVersion build_versions.min_sdk 7 | targetSdkVersion build_versions.target_sdk 8 | applicationId "com.myatejx.gankio" 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | defaultConfig { 20 | vectorDrawables.useSupportLibrary = true 21 | } 22 | 23 | 24 | dataBinding { 25 | enabled = true 26 | } 27 | 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(include: ['*.jar'], dir: 'libs') 32 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 33 | exclude group: 'com.android.support', module: 'support-annotations' 34 | }) 35 | implementation 'com.android.support:appcompat-v7:27.1.1' 36 | annotationProcessor 'com.google.dagger:dagger-compiler:2.8' 37 | compileOnly 'org.glassfish:javax.annotation:10.0-b28' 38 | implementation 'com.google.dagger:dagger:2.8' 39 | implementation 'com.android.support:design:27.1.1' 40 | implementation 'io.reactivex.rxjava2:rxjava:2.1.3' 41 | implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' 42 | implementation 'com.squareup.retrofit2:retrofit:2.1.0' 43 | implementation 'com.squareup.okhttp3:okhttp:3.10.0' 44 | implementation 'com.squareup.retrofit2:converter-gson:2.0.2' 45 | implementation 'com.google.code.gson:gson:2.8.1' 46 | implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0' 47 | implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' 48 | implementation 'com.github.bumptech.glide:glide:3.7.0' 49 | implementation 'com.lcodecorex:tkrefreshlayout:1.0.7' 50 | implementation 'com.facebook.stetho:stetho:1.4.1' 51 | implementation 'com.haozhang.libary:android-slanted-textview:1.2' 52 | implementation 'com.github.chrisbanes:PhotoView:2.1.4' 53 | implementation 'com.google.android:flexbox:0.3.2' 54 | implementation 'me.majiajie:pager-bottom-tab-strip:2.1.0' 55 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4' 56 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' 57 | testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' 58 | testImplementation 'junit:junit:4.12' 59 | 60 | implementation 'me.yokeyword:fragmentation:1.3.6' 61 | implementation "com.kunminx.viabus:viabus-architecture:0.3.6" 62 | 63 | implementation deps.room.runtime 64 | annotationProcessor deps.room.compiler 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/business/SearchBusiness.java: -------------------------------------------------------------------------------- 1 | package com.gank.business; 2 | 3 | import com.gank.business.constant.GankResultCode; 4 | import com.gank.business.request.ISearchRequest; 5 | import com.gank.data.AppDataManager; 6 | import com.gank.data.DataManager; 7 | import com.gank.data.network.response.ThemeResponse; 8 | import com.kunminx.architecture.business.BaseBusiness; 9 | import com.kunminx.architecture.business.bus.Result; 10 | 11 | import java.util.List; 12 | 13 | import io.reactivex.android.schedulers.AndroidSchedulers; 14 | import io.reactivex.disposables.CompositeDisposable; 15 | import io.reactivex.functions.Consumer; 16 | import io.reactivex.schedulers.Schedulers; 17 | 18 | /** 19 | * @author MyateJx 20 | * @date 2018/10/9 21 | */ 22 | public class SearchBusiness extends BaseBusiness implements ISearchRequest { 23 | 24 | private DataManager mDataManager; 25 | 26 | private CompositeDisposable mCompositeDisposable; 27 | 28 | public DataManager getDataManager() { 29 | return mDataManager; 30 | } 31 | 32 | public CompositeDisposable getCompositeDisposable() { 33 | return mCompositeDisposable; 34 | } 35 | 36 | public SearchBusiness() { 37 | this.mDataManager = AppDataManager.getInstance(); 38 | this.mCompositeDisposable = AppDataManager.getInstance().getCompositeDisposable(); 39 | } 40 | 41 | 42 | @Override 43 | public void search(String content, String type, String page) { 44 | getCompositeDisposable().add(getDataManager() 45 | .getSearchDataCall(content, type, page) 46 | .subscribeOn(Schedulers.io()) 47 | .observeOn(AndroidSchedulers.mainThread()) 48 | .subscribe(new Consumer() { 49 | @Override 50 | public void accept(ThemeResponse themeResponse) throws Exception { 51 | GankBus.response(new Result(GankResultCode.SEARCH_LIST_QUERYED, themeResponse.getResults())); 52 | } 53 | })); 54 | } 55 | 56 | @Override 57 | public void insertHistory(String content) { 58 | getDataManager().addSearchHistory(content); 59 | } 60 | 61 | @Override 62 | public void querySearchHistory() { 63 | getCompositeDisposable().add(getDataManager() 64 | .querySearchHistory() 65 | .subscribeOn(Schedulers.io()) 66 | .observeOn(AndroidSchedulers.mainThread()) 67 | .subscribe(new Consumer>() { 68 | @Override 69 | public void accept(List searchHistories) throws Exception { 70 | GankBus.response(new Result(GankResultCode.HISTORY_LIST_QUERYED, searchHistories)); 71 | } 72 | }) 73 | ); 74 | } 75 | 76 | @Override 77 | public void deleteAll() { 78 | getDataManager().deleteSearchHistory(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/DataCleanManager.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * Created by Administrator on 2017/6/3 0003. 10 | */ 11 | 12 | public class DataCleanManager { 13 | /** * 清除本应用内部缓存(/data/data/com.xxx.xxx/cache) * * @param context */ 14 | public static void cleanInternalCache(Context context) { 15 | deleteFilesByDirectory(context.getCacheDir()); 16 | } 17 | 18 | /** * 清除本应用所有数据库(/data/data/com.xxx.xxx/databases) * * @param context */ 19 | public static void cleanDatabases(Context context) { 20 | deleteFilesByDirectory(new File("/data/data/" 21 | + context.getPackageName() + "/databases")); 22 | } 23 | 24 | /** 25 | * * 清除本应用SharedPreference(/data/data/com.xxx.xxx/shared_prefs) * * @param 26 | * context 27 | */ 28 | public static void cleanSharedPreference(Context context) { 29 | deleteFilesByDirectory(new File("/data/data/" 30 | + context.getPackageName() + "/shared_prefs")); 31 | } 32 | 33 | /** * 按名字清除本应用数据库 * * @param context * @param dbName */ 34 | public static void cleanDatabaseByName(Context context, String dbName) { 35 | context.deleteDatabase(dbName); 36 | } 37 | 38 | /** * 清除/data/data/com.xxx.xxx/files下的内容 * * @param context */ 39 | public static void cleanFiles(Context context) { 40 | deleteFilesByDirectory(context.getFilesDir()); 41 | } 42 | 43 | /** 44 | * * 清除外部cache下的内容(/mnt/sdcard/android/data/com.xxx.xxx/cache) * * @param 45 | * context 46 | */ 47 | public static void cleanExternalCache(Context context) { 48 | if (Environment.getExternalStorageState().equals( 49 | Environment.MEDIA_MOUNTED)) { 50 | deleteFilesByDirectory(context.getExternalCacheDir()); 51 | } 52 | } 53 | 54 | /** * 清除自定义路径下的文件,使用需小心,请不要误删。而且只支持目录下的文件删除 * * @param filePath */ 55 | public static void cleanCustomCache(String filePath) { 56 | deleteFilesByDirectory(new File(filePath)); 57 | } 58 | 59 | /** * 清除本应用所有的数据 * * @param context * @param filepath */ 60 | public static void cleanApplicationData(Context context, String... filepath) { 61 | cleanInternalCache(context); 62 | cleanExternalCache(context); 63 | // cleanDatabases(context); 64 | cleanSharedPreference(context); 65 | cleanFiles(context); 66 | if(filepath!=null) { 67 | for (String filePath : filepath) { 68 | cleanCustomCache(filePath); 69 | } 70 | } 71 | } 72 | 73 | /** * 删除方法 这里只会删除某个文件夹下的文件,如果传入的directory是个文件,将不做处理 * * @param directory */ 74 | private static void deleteFilesByDirectory(File directory) { 75 | if (directory != null && directory.exists() && directory.isDirectory()) { 76 | for (File item : directory.listFiles()) { 77 | item.delete(); 78 | } 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_search_first.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 16 | 17 | 21 | 22 | 30 | 31 | 32 | 37 | 38 | 39 | 43 | 44 | 52 | 53 | 62 | 63 | 64 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 15 | 16 | 21 | 22 | 31 | 32 | 43 | 44 | 45 | 46 | 47 | 48 | 53 | 54 | 55 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/ReavalUtils.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.annotation.TargetApi; 6 | import android.content.Context; 7 | import android.os.Build; 8 | import android.support.annotation.ColorRes; 9 | import android.support.v4.content.ContextCompat; 10 | import android.view.View; 11 | import android.view.ViewAnimationUtils; 12 | import android.view.animation.AccelerateDecelerateInterpolator; 13 | 14 | /** 15 | * 动画效果 16 | *

17 | * Created by wangchenlong on 16/2/26. 18 | */ 19 | public class ReavalUtils { 20 | public interface OnRevealAnimationListener { 21 | void onRevealHide(); 22 | 23 | void onRevealShow(); 24 | 25 | void onRevealStart(); 26 | } 27 | 28 | // 圆圈爆炸效果显示 29 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 30 | public static void animateRevealShow( 31 | final Context context, final View view, 32 | final int startRadius, @ColorRes final int color, 33 | final OnRevealAnimationListener listener) { 34 | int cx = (view.getLeft() + view.getRight()) / 2; 35 | int cy = (view.getTop() + view.getBottom()) / 2; 36 | 37 | float finalRadius = (float) Math.hypot(view.getWidth(), view.getHeight()); 38 | 39 | // 设置圆形显示动画 40 | Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, startRadius, finalRadius); 41 | anim.setDuration(500); 42 | anim.setInterpolator(new AccelerateDecelerateInterpolator()); 43 | anim.addListener(new AnimatorListenerAdapter() { 44 | @Override public void onAnimationEnd(Animator animation) { 45 | super.onAnimationEnd(animation); 46 | view.setVisibility(View.VISIBLE); 47 | listener.onRevealShow(); 48 | } 49 | 50 | @Override public void onAnimationStart(Animator animation) { 51 | super.onAnimationStart(animation); 52 | view.setBackgroundColor(ContextCompat.getColor(context, color)); 53 | listener.onRevealStart(); 54 | } 55 | 56 | }); 57 | 58 | anim.start(); 59 | } 60 | 61 | // 圆圈凝聚效果 62 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 63 | public static void animateRevealHide( 64 | final Context context, final View view, 65 | final int finalRadius, @ColorRes final int color, 66 | final OnRevealAnimationListener listener 67 | ) { 68 | int cx = (view.getLeft() + view.getRight()) / 2; 69 | int cy = (view.getTop() + view.getBottom()) / 2; 70 | int initialRadius = view.getWidth(); 71 | // 与入场动画的区别就是圆圈起始和终止的半径相反 72 | Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, finalRadius); 73 | anim.setDuration(500); 74 | anim.setInterpolator(new AccelerateDecelerateInterpolator()); 75 | anim.addListener(new AnimatorListenerAdapter() { 76 | @Override public void onAnimationStart(Animator animation) { 77 | super.onAnimationStart(animation); 78 | // view.setBackgroundColor(ContextCompat.getColor(context, color)); 79 | } 80 | 81 | @Override public void onAnimationEnd(Animator animation) { 82 | super.onAnimationEnd(animation); 83 | listener.onRevealHide(); 84 | view.setVisibility(View.INVISIBLE); 85 | } 86 | }); 87 | anim.start(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/base/ItemViewDelegateManager.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter.base; 2 | 3 | import android.support.v4.util.SparseArrayCompat; 4 | 5 | 6 | public class ItemViewDelegateManager { 7 | SparseArrayCompat> delegates = new SparseArrayCompat(); 8 | 9 | public int getItemViewDelegateCount() { 10 | return delegates.size(); 11 | } 12 | 13 | public ItemViewDelegateManager addDelegate(ItemViewDelegate delegate) { 14 | int viewType = delegates.size(); 15 | if (delegate != null) { 16 | delegates.put(viewType, delegate); 17 | viewType++; 18 | } 19 | return this; 20 | } 21 | 22 | public ItemViewDelegateManager addDelegate(int viewType, ItemViewDelegate delegate) { 23 | if (delegates.get(viewType) != null) { 24 | throw new IllegalArgumentException( 25 | "An ItemViewDelegate is already registered for the viewType = " 26 | + viewType 27 | + ". Already registered ItemViewDelegate is " 28 | + delegates.get(viewType)); 29 | } 30 | delegates.put(viewType, delegate); 31 | return this; 32 | } 33 | 34 | public ItemViewDelegateManager removeDelegate(ItemViewDelegate delegate) { 35 | if (delegate == null) { 36 | throw new NullPointerException("ItemViewDelegate is null"); 37 | } 38 | int indexToRemove = delegates.indexOfValue(delegate); 39 | 40 | if (indexToRemove >= 0) { 41 | delegates.removeAt(indexToRemove); 42 | } 43 | return this; 44 | } 45 | 46 | public ItemViewDelegateManager removeDelegate(int itemType) { 47 | int indexToRemove = delegates.indexOfKey(itemType); 48 | 49 | if (indexToRemove >= 0) { 50 | delegates.removeAt(indexToRemove); 51 | } 52 | return this; 53 | } 54 | 55 | public int getItemViewType(T item, int position) { 56 | int delegatesCount = delegates.size(); 57 | for (int i = delegatesCount - 1; i >= 0; i--) { 58 | ItemViewDelegate delegate = delegates.valueAt(i); 59 | if (delegate.isForViewType(item, position)) { 60 | return delegates.keyAt(i); 61 | } 62 | } 63 | throw new IllegalArgumentException( 64 | "No ItemViewDelegate added that matches position=" + position + " in data source"); 65 | } 66 | 67 | public void convert(ViewHolder holder, T item, int position) { 68 | int delegatesCount = delegates.size(); 69 | for (int i = 0; i < delegatesCount; i++) { 70 | ItemViewDelegate delegate = delegates.valueAt(i); 71 | 72 | if (delegate.isForViewType(item, position)) { 73 | delegate.convert(holder, item, position); 74 | return; 75 | } 76 | } 77 | throw new IllegalArgumentException( 78 | "No ItemViewDelegateManager added that matches position=" + position + " in data source"); 79 | } 80 | 81 | 82 | public ItemViewDelegate getItemViewDelegate(int viewType) { 83 | return delegates.get(viewType); 84 | } 85 | 86 | public int getItemViewLayoutId(int viewType) { 87 | return getItemViewDelegate(viewType).getItemViewLayoutId(); 88 | } 89 | 90 | public int getItemViewType(ItemViewDelegate itemViewDelegate) { 91 | return delegates.indexOfValue(itemViewDelegate); 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_search.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 21 | 22 | 27 | 28 | 37 | 38 | 43 | 44 | 51 | 52 | 62 | 63 | 64 | 74 | 75 | 76 | 77 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/data/AppDataManager.java: -------------------------------------------------------------------------------- 1 | package com.gank.data; 2 | 3 | import android.content.Context; 4 | 5 | import com.gank.Constants; 6 | import com.gank.data.database.AppDbHelper; 7 | import com.gank.data.database.DbHelper; 8 | import com.gank.data.database.entity.Image; 9 | import com.gank.data.network.ApiHelper; 10 | import com.gank.data.network.AppApiHelper; 11 | import com.gank.data.network.response.Result; 12 | import com.gank.data.network.response.ThemeResponse; 13 | import com.gank.data.preference.AppSharePreferences; 14 | import com.gank.data.preference.SharePreferenecesHelper; 15 | 16 | import java.util.List; 17 | 18 | import io.reactivex.Observable; 19 | import io.reactivex.disposables.CompositeDisposable; 20 | 21 | /** 22 | * Created by Administrator on 2017/3/29 0029. 23 | */ 24 | public class AppDataManager implements DataManager { 25 | 26 | private ApiHelper apiHelper; 27 | private DbHelper dbHelper; 28 | private SharePreferenecesHelper sharePreferenecesHelper; 29 | private CompositeDisposable mCompositeDisposable; 30 | 31 | private static AppDataManager sAppDataManager; 32 | 33 | public static AppDataManager getInstance() { 34 | if (sAppDataManager == null) { 35 | sAppDataManager = new AppDataManager(); 36 | } 37 | return sAppDataManager; 38 | } 39 | 40 | private AppDataManager() { 41 | 42 | } 43 | 44 | public void init(Context context) { 45 | dbHelper = new AppDbHelper(context, Constants.DB_NAME); 46 | apiHelper = new AppApiHelper(context); 47 | sharePreferenecesHelper = new AppSharePreferences(context, Constants.PREFERENCE_NAME); 48 | } 49 | 50 | @Override 51 | public Observable getThemeDataCall(String path) { 52 | return apiHelper.getThemeDataCall(path); 53 | } 54 | 55 | @Override 56 | public Observable getSearchDataCall(String content, String type, String page) { 57 | return apiHelper.getSearchDataCall(content, type, page); 58 | } 59 | 60 | 61 | @Override 62 | public Boolean getIsCollnection(String id) { 63 | return dbHelper.getIsCollnection(id); 64 | } 65 | 66 | @Override 67 | public void addConnection(Result result) { 68 | dbHelper.addConnection(result); 69 | } 70 | 71 | @Override 72 | public void addImage(Image img) { 73 | dbHelper.addImage(img); 74 | } 75 | 76 | @Override 77 | public void cancelCollection(String id) { 78 | dbHelper.cancelCollection(id); 79 | } 80 | 81 | 82 | @Override 83 | public Observable> queryForList(int offset) { 84 | return dbHelper.queryForList(offset); 85 | } 86 | 87 | @Override 88 | public void addSearchHistory(String content) { 89 | dbHelper.addSearchHistory(content); 90 | } 91 | 92 | @Override 93 | public Observable> querySearchHistory() { 94 | return dbHelper.querySearchHistory(); 95 | } 96 | 97 | @Override 98 | public void deleteSearchHistory() { 99 | dbHelper.deleteSearchHistory(); 100 | } 101 | 102 | @Override 103 | public void setOrder(String orderJsonStirng) { 104 | sharePreferenecesHelper.setOrder(orderJsonStirng); 105 | } 106 | 107 | @Override 108 | public String getOrderString() { 109 | return sharePreferenecesHelper.getOrderString(); 110 | } 111 | 112 | @Override 113 | public void setTheme(boolean isNight) { 114 | sharePreferenecesHelper.setTheme(isNight); 115 | } 116 | 117 | @Override 118 | public boolean getTheme() { 119 | return sharePreferenecesHelper.getTheme(); 120 | } 121 | 122 | public CompositeDisposable getCompositeDisposable() { 123 | if (mCompositeDisposable == null) { 124 | mCompositeDisposable = new CompositeDisposable(); 125 | } 126 | return mCompositeDisposable; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/TimeUtils.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | 8 | /** 9 | * Created by Administrator on 2017/4/20 0020. 10 | */ 11 | 12 | public class TimeUtils { 13 | public static String convert(String sdate) { 14 | String day=sdate.split("T")[0]; 15 | String time=sdate.split("T")[1].split("Z")[0]; 16 | return day+" "+time; 17 | }; 18 | private static ThreadLocal dateFormater2 = new ThreadLocal() { 19 | @Override 20 | protected SimpleDateFormat initialValue() { 21 | return new SimpleDateFormat("yyyy-MM-dd"); 22 | } 23 | }; 24 | public static String friendlyTimeFormat(String date) { 25 | String sdate=convert(date); 26 | Date time = toDate(sdate); 27 | if (time == null) { 28 | return ""; 29 | } 30 | String ftime = ""; 31 | Calendar cal = Calendar.getInstance(); 32 | 33 | //判断是否是同一天 34 | String curDate = dateFormater2.get().format(cal.getTime()); 35 | String paramDate = dateFormater2.get().format(time); 36 | if (curDate.equals(paramDate)) { 37 | int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000); 38 | if (hour == 0) 39 | ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / 60000, 1) + "分钟前"; 40 | else 41 | ftime = hour + "小时前"; 42 | return ftime; 43 | } 44 | 45 | 46 | long lt = time.getTime() / 86400000; 47 | long ct = cal.getTimeInMillis() / 86400000; 48 | int days = (int) (ct - lt); 49 | if (days == 0) { 50 | int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000); 51 | if (hour == 0) 52 | ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / 60000, 1) + "分钟前"; 53 | else 54 | ftime = hour + "小时前"; 55 | } else if (days == 1) { 56 | ftime = "昨天"; 57 | } else if (days == 2) { 58 | ftime = "前天"; 59 | } 60 | 61 | else if (days > 2 && days <= 30) { 62 | ftime = days + "天前"; 63 | } else if (days > 30 && days <= 60) { 64 | ftime = "1个月前"; 65 | } else if (days > 60 && days <= 90) { 66 | ftime = "2个月前"; 67 | } else if (days > 90 && days <= 120) { 68 | ftime = "3个月前"; 69 | } else if (days > 120 && days <= 150) { 70 | ftime = "4个月前"; 71 | } else if (days > 150 && days <= 180) { 72 | ftime = "5个月前"; 73 | } else if (days > 180 && days <= 210) { 74 | ftime = "6个月前"; 75 | } else if (days > 210 && days <= 240) { 76 | ftime = "7个月前"; 77 | } else if (days > 240 && days <= 270) { 78 | ftime = "8个月前"; 79 | } else if (days > 270 && days <= 300) { 80 | ftime = "9个月前"; 81 | } else if (days > 300 && days <= 330) { 82 | ftime = "10个月前"; 83 | } else if (days > 330 && days <= 360) { 84 | ftime = "11个月前"; 85 | } else if (days > 360 && days <= 720) { 86 | ftime = "一年前"; 87 | } else if (days > 720 && days <= 1080) { 88 | ftime = "两年前"; 89 | } else if (days > 1080) { 90 | ftime = dateFormater2.get().format(time); 91 | } 92 | return ftime; 93 | } 94 | 95 | 96 | /** 97 | * 将字符串转位日期类型 98 | * 99 | * @param sdate 100 | * @return 101 | */ 102 | public static Date toDate(String sdate) { 103 | try { 104 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 105 | return sdf.parse(sdate); 106 | } catch (ParseException e) { 107 | return null; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/util/ItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.gank.util; 2 | 3 | /** 4 | * Created by Administrator on 2017/4/19 0019. 5 | */ 6 | 7 | import android.content.Context; 8 | import android.content.res.TypedArray; 9 | import android.graphics.Canvas; 10 | import android.graphics.Rect; 11 | import android.graphics.drawable.Drawable; 12 | import android.support.v7.widget.LinearLayoutManager; 13 | import android.support.v7.widget.RecyclerView; 14 | import android.view.View; 15 | 16 | public class ItemDecoration extends RecyclerView.ItemDecoration { 17 | 18 | private Context mContext; 19 | private Drawable mDivider; 20 | private int mOrientation; 21 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 22 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 23 | 24 | //我们通过获取系统属性中的listDivider来添加,在系统中的AppTheme中设置 25 | public static final int[] ATRRS = new int[]{ 26 | android.R.attr.listDivider 27 | }; 28 | 29 | public ItemDecoration(Context context, int orientation) { 30 | this.mContext = context; 31 | final TypedArray ta = context.obtainStyledAttributes(ATRRS); 32 | this.mDivider = ta.getDrawable(0); 33 | ta.recycle(); 34 | setOrientation(orientation); 35 | } 36 | 37 | //设置屏幕的方向 38 | public void setOrientation(int orientation) { 39 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { 40 | throw new IllegalArgumentException("invalid orientation"); 41 | } 42 | mOrientation = orientation; 43 | } 44 | 45 | @Override 46 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 47 | if (mOrientation == HORIZONTAL_LIST) { 48 | drawVerticalLine(c, parent, state); 49 | } else { 50 | drawHorizontalLine(c, parent, state); 51 | } 52 | } 53 | 54 | //画横线, 这里的parent其实是显示在屏幕显示的这部分 55 | public void drawHorizontalLine(Canvas c, RecyclerView parent, RecyclerView.State state) { 56 | int left = parent.getPaddingLeft(); 57 | int right = parent.getWidth() - parent.getPaddingRight(); 58 | final int childCount = parent.getChildCount(); 59 | for (int i = 0; i < childCount; i++) { 60 | final View child = parent.getChildAt(i); 61 | 62 | //获得child的布局信息 63 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 64 | final int top = child.getBottom() + params.bottomMargin; 65 | final int bottom = top + mDivider.getIntrinsicHeight(); 66 | mDivider.setBounds(left, top, right, bottom); 67 | mDivider.draw(c); 68 | //Log.d("wnw", left + " " + top + " "+right+" "+bottom+" "+i); 69 | } 70 | } 71 | 72 | //画竖线 73 | public void drawVerticalLine(Canvas c, RecyclerView parent, RecyclerView.State state) { 74 | int top = parent.getPaddingTop(); 75 | int bottom = parent.getHeight() - parent.getPaddingBottom(); 76 | final int childCount = parent.getChildCount(); 77 | for (int i = 0; i < childCount; i++) { 78 | final View child = parent.getChildAt(i); 79 | 80 | //获得child的布局信息 81 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 82 | final int left = child.getRight() + params.rightMargin; 83 | final int right = left + mDivider.getIntrinsicWidth(); 84 | mDivider.setBounds(left, top, right, bottom); 85 | mDivider.draw(c); 86 | } 87 | } 88 | 89 | //由于Divider也有长宽高,每一个Item需要向下或者向右偏移 90 | @Override 91 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 92 | if (mOrientation == HORIZONTAL_LIST) { 93 | //画横线,就是往下偏移一个分割线的高度 94 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 95 | } else { 96 | //画竖线,就是往右偏移一个分割线的宽度 97 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/setting/SettingFragment.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.setting; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.design.widget.Snackbar; 7 | import android.util.TypedValue; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.CompoundButton; 12 | 13 | import com.bumptech.glide.Glide; 14 | import com.gank.R; 15 | import com.gank.business.GankBus; 16 | import com.gank.databinding.FragmentSettingBinding; 17 | import com.gank.ui.base.LazyFragment; 18 | import com.gank.ui.base.RxBus; 19 | import com.gank.ui.collection.CollectionActivity; 20 | import com.gank.util.DataCleanManager; 21 | 22 | import static com.gank.Constants.isNight; 23 | 24 | /** 25 | * Created by Administrator on 2017/5/12 0012. 26 | */ 27 | 28 | public class SettingFragment extends LazyFragment { 29 | 30 | private FragmentSettingBinding mBinding; 31 | 32 | @Nullable 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 35 | View view = inflater.inflate(R.layout.fragment_setting, container, false); 36 | mBinding = FragmentSettingBinding.bind(view); 37 | return view; 38 | 39 | } 40 | 41 | @Override 42 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 43 | super.onViewCreated(view, savedInstanceState); 44 | mBinding.toolbar.setTitle("我的"); 45 | mBinding.llCollection.setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View v) { 48 | startActivity(new Intent(getActivity(), CollectionActivity.class)); 49 | } 50 | }); 51 | //清除缓存 52 | mBinding.llClean.setOnClickListener(new View.OnClickListener() { 53 | @Override 54 | public void onClick(View v) { 55 | DataCleanManager.cleanApplicationData(getActivity(), new String[0]); 56 | Snackbar.make(mBinding.llClean, "清除缓存成功", Snackbar.LENGTH_SHORT).show(); 57 | } 58 | }); 59 | } 60 | 61 | @Override 62 | public void loadData() { 63 | 64 | if (isNight) { 65 | Glide.with(getActivity()).load(R.drawable.night1).crossFade().into(mBinding.ivBg); 66 | mBinding.switchCompat.setChecked(true); 67 | } else { 68 | Glide.with(getActivity()).load(R.drawable.day1).crossFade().into(mBinding.ivBg); 69 | mBinding.switchCompat.setChecked(false); 70 | } 71 | mBinding.switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 72 | @Override 73 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 74 | if (isChecked) { 75 | isNight = true; 76 | getActivity().setTheme(R.style.NightTheme); 77 | Glide.with(getActivity()).load(R.drawable.night1).crossFade().into(mBinding.ivBg); 78 | 79 | } else { 80 | isNight = false; 81 | getActivity().setTheme(R.style.DayTheme); 82 | Glide.with(getActivity()).load(R.drawable.day1).crossFade().into(mBinding.ivBg); 83 | } 84 | GankBus.setting().setTheme(isNight); 85 | RxBus.getInstance().post(isNight); 86 | 87 | } 88 | }); 89 | 90 | } 91 | 92 | 93 | @Override 94 | public void onDestroyView() { 95 | super.onDestroyView(); 96 | } 97 | 98 | @Override 99 | protected void refreshUI() { 100 | refreshToolbar(mBinding.toolbar); 101 | TypedValue bottomline = new TypedValue(); 102 | getActivity().getTheme().resolveAttribute(R.attr.bottomline, bottomline, true); 103 | mBinding.line1.setBackgroundResource(bottomline.resourceId); 104 | mBinding.line2.setBackgroundResource(bottomline.resourceId); 105 | mBinding.line3.setBackgroundResource(bottomline.resourceId); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /versions.gradle: -------------------------------------------------------------------------------- 1 | ext.deps = [:] 2 | def versions = [:] 3 | versions.arcgis = "10.2.9" 4 | 5 | //versions.wcdb = "1.0.6" 6 | versions.leakcanary = "1.5.4" 7 | versions.arouter_api = "1.3.1" 8 | versions.arouter_compiler = "1.1.4" 9 | 10 | versions.room = "1.1.1" 11 | versions.lifecycle = "1.1.0" 12 | 13 | versions.constraint_layout = "1.0.2" 14 | 15 | versions.appcompat_v7 = "27.1.1" 16 | versions.support_v4 = "27.1.1" 17 | versions.recyclerview_v7 = "27.1.1" 18 | versions.cardview = "27.1.1" 19 | versions.design = "27.1.1" 20 | 21 | versions.android_gradle_plugin = "3.1.0" 22 | versions.multidex = "1.0.3" 23 | versions.rxjava = "2.0.1" 24 | versions.eventbus = "3.0.0" 25 | 26 | versions.imageLoaderVersion = "1.9.5" 27 | versions.photoviewVersion = "1.2.4" 28 | versions.recyclerview_swipe = "1.1.4" 29 | versions.tablayout = "2.1.2" 30 | versions.PhotoPicker = "0.9.5@aar" 31 | versions.Vlayout = "1.1.0@aar" 32 | 33 | versions.glide = "3.7.0" 34 | versions.fastjson = "1.1.68.android" 35 | versions.okgo = "3.0.4" 36 | versions.okhttp = "3.10.0" 37 | 38 | def deps = [:] 39 | 40 | def leakcanary = [:] 41 | leakcanary.debug = "com.squareup.leakcanary:leakcanary-android:$versions.leakcanary" 42 | leakcanary.release = "com.squareup.leakcanary:leakcanary-android-no-op:$versions.leakcanary" 43 | deps.leakcanary = leakcanary 44 | 45 | 46 | deps.arcgis = "com.esri.arcgis.android:arcgis-android:$versions.arcgis" 47 | deps.wcdb = "com.tencent.wcdb:wcdb-android:$versions.wcdb" 48 | deps.constraint_layout = "com.android.support.constraint:constraint-layout:$versions.constraint_layout" 49 | deps.appcompat_v7 = "com.android.support:appcompat-v7:$versions.appcompat_v7" 50 | deps.support_v4 = "com.android.support:support-v4:$versions.support_v4" 51 | deps.recyclerview_v7 = "com.android.support:recyclerview-v7:$versions.recyclerview_v7" 52 | deps.cardview = "com.android.support:cardview-v7:$versions.cardview" 53 | deps.design = "com.android.support:design:$versions.design" 54 | deps.android_gradle_plugin = "com.android.tools.build:gradle:$versions.android_gradle_plugin" 55 | deps.multidex = "com.android.support:multidex:$versions.multidex" 56 | deps.rxjava = "io.reactivex.rxjava2:rxandroid:$versions.rxjava" 57 | deps.eventbus = "org.greenrobot:eventbus:$versions.eventbus" 58 | deps.imageLoaderVersion = "com.nostra13.universalimageloader:universal-image-loader:$versions.imageLoaderVersion" 59 | deps.photoviewVersion = "com.github.chrisbanes.photoview:library:$versions.photoviewVersion" 60 | deps.recyclerview_swipe = "com.yanzhenjie:recyclerview-swipe:$versions.recyclerview_swipe" 61 | deps.tablayout = "com.flyco.tablayout:FlycoTabLayout_Lib:$versions.tablayout" 62 | deps.fastjson = "com.alibaba:fastjson:$versions.fastjson" 63 | deps.PhotoPicker = "me.iwf.photopicker:PhotoPicker:$versions.PhotoPicker" 64 | deps.Vlayout = "com.alibaba.android:vlayout:$versions.Vlayout" /*{ 65 | transitive = true 66 | }*/ 67 | deps.glide = "com.github.bumptech.glide:glide:$versions.glide" 68 | deps.okgo = "com.lzy.net:okgo:$versions.okgo" 69 | deps.okhttp = "com.squareup.okhttp3:okhttp:$versions.okhttp" 70 | 71 | def arouter = [:] 72 | arouter.compiler = "com.alibaba:arouter-compiler:$versions.arouter_compiler" 73 | arouter.api = "com.alibaba:arouter-api:$versions.arouter_api" 74 | deps.arouter = arouter 75 | 76 | def room = [:] 77 | room.runtime = "android.arch.persistence.room:runtime:$versions.room" 78 | room.compiler = "android.arch.persistence.room:compiler:$versions.room" 79 | room.rxjava = "android.arch.persistence.room:rxjava2:$versions.room" 80 | deps.room = room 81 | 82 | def lifecycle = [:] 83 | lifecycle.runtime = "android.arch.lifecycle:runtime:$versions.lifecycle" 84 | lifecycle.extensions = "android.arch.lifecycle:extensions:$versions.lifecycle" 85 | lifecycle.livedata = "android.arch.lifecycle:livedata:$versions.lifecycle" 86 | lifecycle.java8 = "android.arch.lifecycle:common-java8:$versions.lifecycle" 87 | lifecycle.compiler = "android.arch.lifecycle:compiler:$versions.lifecycle" 88 | deps.lifecycle = lifecycle 89 | 90 | 91 | deps.ffmpeg = '3.2.1-1.3' 92 | 93 | ext.deps = deps 94 | 95 | 96 | 97 | def build_versions = [:] 98 | build_versions.min_sdk = 21 99 | build_versions.target_sdk = 27 100 | build_versions.build_tools = "27.0.3" 101 | ext.build_versions = build_versions 102 | 103 | 104 | ext.addRepos = this.&addRepos -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/CommonAdapter.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ImageView; 8 | import android.widget.TextView; 9 | 10 | import com.bumptech.glide.Glide; 11 | import com.gank.R; 12 | import com.gank.data.network.response.Result; 13 | import com.gank.util.TimeUtils; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Created by Administrator on 2017/4/3 0003. 19 | */ 20 | 21 | public class CommonAdapter extends RecyclerView.Adapter { 22 | private boolean fromCollection; 23 | private boolean fromSearch; 24 | private List list; 25 | private OnItemClickListener OnItemClickListener; 26 | 27 | public CommonAdapter() { 28 | } 29 | 30 | public void setData(List list) { 31 | this.list = list; 32 | } 33 | 34 | public void setData(List list, boolean fromCollection) { 35 | this.fromCollection = fromCollection; 36 | this.list = list; 37 | } 38 | 39 | public void setSearchData(List list, boolean fromSearch) { 40 | this.fromSearch = fromSearch; 41 | this.list = list; 42 | } 43 | 44 | public void notifyData(int startPosition, int count) { 45 | notifyItemRangeChanged(startPosition, count); 46 | } 47 | 48 | @Override 49 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 50 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, parent, false); 51 | ViewHolder viewHolder = new ViewHolder(view); 52 | return viewHolder; 53 | } 54 | 55 | @Override 56 | public void onBindViewHolder(ViewHolder holder, final int position) { 57 | Result result = list.get(position); 58 | holder.image.setVisibility(View.GONE); 59 | if (fromSearch) { 60 | holder.image.setVisibility(View.GONE); 61 | } else if (fromCollection) { 62 | if (result.getImg() != null && result.getImg().size() > 0) { 63 | holder.image.setVisibility(View.VISIBLE); 64 | Glide.with(holder.itemView.getContext()).load(result.getImg().get(0).getImageUrl()) 65 | .asBitmap().centerCrop().into(holder.image); 66 | } 67 | } else { 68 | if (result.getImages() != null && result.getImages().size() > 0) { 69 | holder.image.setVisibility(View.VISIBLE); 70 | Glide.with(holder.itemView.getContext()).load(result.getImages().get(0)) 71 | .asBitmap().centerCrop().into(holder.image); 72 | } 73 | } 74 | 75 | holder.text.setText(result.getDesc()); 76 | if (fromSearch) { 77 | holder.author.setText(result.getType() + " · " + result.getWho() + " · " + TimeUtils.friendlyTimeFormat(result.getPublishedAt())); 78 | } else { 79 | holder.author.setText(result.getWho() + " · " + TimeUtils.friendlyTimeFormat(result.getPublishedAt())); 80 | } 81 | holder.itemView.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | onItemClickListener.OnItemClick(v, position); 85 | } 86 | }); 87 | 88 | } 89 | 90 | 91 | @Override 92 | public int getItemCount() { 93 | return list == null ? 0 : list.size(); 94 | } 95 | 96 | 97 | class ViewHolder extends RecyclerView.ViewHolder { 98 | TextView text; 99 | ImageView image; 100 | TextView author; 101 | 102 | public ViewHolder(View itemView) { 103 | super(itemView); 104 | text = (TextView) itemView.findViewById(R.id.text); 105 | image = (ImageView) itemView.findViewById(R.id.image); 106 | author = (TextView) itemView.findViewById(R.id.author); 107 | } 108 | } 109 | 110 | private OnItemClickListener onItemClickListener; 111 | 112 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) { 113 | this.onItemClickListener = onItemClickListener; 114 | } 115 | 116 | 117 | public interface OnItemClickListener { 118 | void OnItemClick(View v, int position); 119 | } 120 | 121 | 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui; 2 | 3 | 4 | import android.content.res.Resources; 5 | import android.databinding.DataBindingUtil; 6 | import android.os.Bundle; 7 | import android.support.annotation.ColorInt; 8 | import android.support.annotation.ColorRes; 9 | import android.support.v4.app.Fragment; 10 | import android.support.v4.app.FragmentPagerAdapter; 11 | import android.support.v4.content.ContextCompat; 12 | import android.support.v4.view.PagerAdapter; 13 | import android.util.TypedValue; 14 | import android.view.KeyEvent; 15 | import android.widget.Toast; 16 | 17 | import com.gank.R; 18 | import com.gank.business.GankBus; 19 | import com.gank.business.GankBusiness; 20 | import com.gank.business.MeiziBusiness; 21 | import com.gank.business.SearchBusiness; 22 | import com.gank.business.SettingBusiness; 23 | import com.gank.data.AppDataManager; 24 | import com.gank.databinding.ActivityMainBinding; 25 | import com.gank.ui.base.BaseActivity; 26 | import com.gank.ui.base.BaseFragment; 27 | import com.gank.view.OnlyIconItemView; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | import me.majiajie.pagerbottomtabstrip.NavigationController; 33 | import me.majiajie.pagerbottomtabstrip.item.BaseTabItem; 34 | 35 | public class MainActivity extends BaseActivity { 36 | 37 | private ActivityMainBinding mBinding; 38 | 39 | private List fragmentList = new ArrayList<>(); 40 | 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); 46 | setSupportActionBar(mBinding.toolbar); 47 | getSupportActionBar().setDisplayShowTitleEnabled(true); 48 | 49 | 50 | NavigationController navigationController = mBinding.tab.custom() 51 | .addItem(newItem(R.drawable.home, R.drawable.home_selected)) 52 | .addItem(newItem(R.drawable.fuli, R.drawable.fuli_selected)) 53 | .addItem(newItem(R.drawable.mine, R.drawable.mine_selected)) 54 | .build(); 55 | fragmentList.add(BaseFragment.newInstance(0)); 56 | fragmentList.add(BaseFragment.newInstance(1)); 57 | fragmentList.add(BaseFragment.newInstance(2)); 58 | mBinding.viewpager.setOffscreenPageLimit(3); 59 | PagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { 60 | @Override 61 | public Fragment getItem(int position) { 62 | return fragmentList.get(position); 63 | } 64 | 65 | @Override 66 | public int getCount() { 67 | return fragmentList.size(); 68 | } 69 | }; 70 | mBinding.viewpager.setAdapter(pagerAdapter); 71 | 72 | navigationController.setupWithViewPager(mBinding.viewpager); 73 | 74 | } 75 | 76 | @Override 77 | protected void refreshUI() { 78 | TypedValue bottomColor = new TypedValue(); 79 | Resources.Theme theme = getTheme(); 80 | theme.resolveAttribute(R.attr.bottomcolor, bottomColor, true); 81 | Resources resources = getResources(); 82 | if (mBinding.tab != null) { 83 | mBinding.tab.setBackgroundColor(resources.getColor(bottomColor.resourceId)); 84 | } 85 | 86 | } 87 | 88 | 89 | //创建一个Item 90 | private BaseTabItem newItem(int drawable, int checkedDrawable) { 91 | OnlyIconItemView onlyIconItemView = new OnlyIconItemView(this); 92 | onlyIconItemView.initialize(drawable, checkedDrawable); 93 | return onlyIconItemView; 94 | } 95 | 96 | @ColorInt 97 | private int color(@ColorRes int res) { 98 | return ContextCompat.getColor(this, res); 99 | } 100 | 101 | private long exitTime = 0; 102 | 103 | @Override 104 | public boolean onKeyDown(int keyCode, KeyEvent event) { 105 | if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { 106 | if ((System.currentTimeMillis() - exitTime) > 2000) { 107 | Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show(); 108 | exitTime = System.currentTimeMillis(); 109 | } else { 110 | finish(); 111 | // System.exit(0); 112 | } 113 | return true; 114 | } 115 | return super.onKeyDown(keyCode, event); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #4e372f 4 | #4e372f 5 | #4e372f 6 | 7 | #F2F3F3 8 | #e75946 9 | #f4d227 10 | #4674e7 11 | #0ba62c 12 | #E6E6E6 13 | #DADCDC 14 | #FFAF8F84 15 | #FFCCB9B3 16 | #00000000 17 | #dcdbdb 18 | #e1e4e6 19 | #222222 20 | #252525 21 | 22 | #404040 23 | #262626 24 | #ACACAC 25 | #262626 26 | #8A8A8A 27 | #8A8A8A 28 | 29 | #FFFFFF 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | #FF6347 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | #D2B48C 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | #B8860B 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | #8B0000 120 | 121 | 122 | 123 | #808080 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | #000000 175 | 176 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_index.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 39 | 40 | 43 | 44 | 45 | 46 | 52 | 53 | 62 | 63 | 76 | 77 | 82 | 88 | 98 | 99 | 100 | 101 | 102 | 107 | 108 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 20 | 21 | 42 | 43 | 61 | 62 | 63 | 67 | 68 | 75 | 76 | 79 | 80 | 83 | 84 | 87 | 88 | 92 | 93 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/adapter/base/MultiItemTypeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.adapter.base; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import java.util.List; 9 | 10 | 11 | public class MultiItemTypeAdapter extends RecyclerView.Adapter { 12 | protected Context mContext; 13 | protected List mDatas; 14 | 15 | protected ItemViewDelegateManager mItemViewDelegateManager; 16 | protected OnItemClickListener mOnItemClickListener; 17 | 18 | 19 | public MultiItemTypeAdapter(Context context, List datas) { 20 | mContext = context; 21 | mDatas = datas; 22 | mItemViewDelegateManager = new ItemViewDelegateManager(); 23 | } 24 | 25 | @Override 26 | public int getItemViewType(int position) { 27 | if (!useItemViewDelegateManager()) return super.getItemViewType(position); 28 | return mItemViewDelegateManager.getItemViewType(mDatas.get(position), position); 29 | } 30 | 31 | 32 | @Override 33 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 34 | ItemViewDelegate itemViewDelegate = mItemViewDelegateManager.getItemViewDelegate(viewType); 35 | int layoutId = itemViewDelegate.getItemViewLayoutId(); 36 | ViewHolder holder = ViewHolder.createViewHolder(mContext, parent, layoutId); 37 | onViewHolderCreated(holder, holder.getConvertView()); 38 | setListener(parent, holder, viewType); 39 | return holder; 40 | } 41 | 42 | public void onViewHolderCreated(ViewHolder holder, View itemView) { 43 | 44 | } 45 | 46 | public void convert(ViewHolder holder, T t) { 47 | mItemViewDelegateManager.convert(holder, t, holder.getAdapterPosition()); 48 | } 49 | 50 | protected boolean isEnabled(int viewType) { 51 | return true; 52 | } 53 | 54 | 55 | protected void setListener(final ViewGroup parent, final ViewHolder viewHolder, int viewType) { 56 | if (!isEnabled(viewType)) return; 57 | viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View v) { 60 | if (mOnItemClickListener != null) { 61 | int position = viewHolder.getAdapterPosition(); 62 | mOnItemClickListener.onItemClick(v, viewHolder, position); 63 | } 64 | } 65 | }); 66 | 67 | viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() { 68 | @Override 69 | public boolean onLongClick(View v) { 70 | if (mOnItemClickListener != null) { 71 | int position = viewHolder.getAdapterPosition(); 72 | return mOnItemClickListener.onItemLongClick(v, viewHolder, position); 73 | } 74 | return false; 75 | } 76 | }); 77 | } 78 | 79 | @Override 80 | public void onBindViewHolder(ViewHolder holder, int position) { 81 | convert(holder, mDatas.get(position)); 82 | } 83 | 84 | @Override 85 | public int getItemCount() { 86 | int itemCount = mDatas.size(); 87 | return itemCount; 88 | } 89 | 90 | 91 | public List getDatas() { 92 | return mDatas; 93 | } 94 | 95 | public MultiItemTypeAdapter addItemViewDelegate(ItemViewDelegate itemViewDelegate) { 96 | mItemViewDelegateManager.addDelegate(itemViewDelegate); 97 | return this; 98 | } 99 | 100 | public MultiItemTypeAdapter addItemViewDelegate(int viewType, ItemViewDelegate itemViewDelegate) { 101 | mItemViewDelegateManager.addDelegate(viewType, itemViewDelegate); 102 | return this; 103 | } 104 | 105 | protected boolean useItemViewDelegateManager() { 106 | return mItemViewDelegateManager.getItemViewDelegateCount() > 0; 107 | } 108 | 109 | public interface OnItemClickListener { 110 | void onItemClick(View view, RecyclerView.ViewHolder holder, int position); 111 | 112 | boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position); 113 | } 114 | 115 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) { 116 | this.mOnItemClickListener = onItemClickListener; 117 | } 118 | 119 | 120 | public void clearData() { 121 | int itemCount = mDatas.size(); 122 | mDatas.clear(); 123 | this.notifyItemRangeRemoved(0, itemCount); 124 | } 125 | 126 | 127 | public void addData(int position, List datas) { 128 | if (datas != null && datas.size() > 0) { 129 | this.mDatas.addAll(datas); 130 | this.notifyItemRangeChanged(position, datas.size()); 131 | } 132 | } 133 | 134 | public void addData(List datas) { 135 | if (datas != null && datas.size() > 0) { 136 | int startPosition = mDatas.size(); 137 | this.mDatas.addAll(datas); 138 | this.notifyItemRangeChanged(startPosition, datas.size()); 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 12 | 17 | 18 | 21 | 22 | 27 | 28 | 29 | 30 | 37 | 38 | 43 | 44 | 52 | 53 | 54 | 60 | 61 | 68 | 69 | 74 | 75 | 83 | 84 | 85 | 91 | 92 | 98 | 99 | 104 | 105 | 113 | 114 | 120 | 121 | 122 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/search/SearchEmptyFragment.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.search; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.gank.R; 12 | import com.gank.business.GankBus; 13 | import com.gank.business.constant.GankResultCode; 14 | import com.gank.databinding.FragmentSearchFirstBinding; 15 | import com.gank.ui.base.BaseEnum; 16 | import com.gank.ui.base.BaseFragment; 17 | import com.gank.util.DensityUtil; 18 | import com.google.android.flexbox.FlexWrap; 19 | import com.google.android.flexbox.FlexboxLayout; 20 | import com.kunminx.architecture.business.bus.IResponse; 21 | import com.kunminx.architecture.business.bus.Result; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Created by Administrator on 2017/4/27 0027. 27 | */ 28 | 29 | public class SearchEmptyFragment extends BaseFragment implements IResponse { 30 | 31 | 32 | OnSelectListener listener; 33 | 34 | public static SearchEmptyFragment newInstance() { 35 | Bundle args = new Bundle(); 36 | SearchEmptyFragment fragment = new SearchEmptyFragment(); 37 | fragment.setArguments(args); 38 | return fragment; 39 | } 40 | 41 | @Override 42 | protected void refreshUI() { 43 | 44 | } 45 | 46 | @Override 47 | public void onAttach(Context context) { 48 | super.onAttach(context); 49 | if (context instanceof SearchActivity) { 50 | listener = (OnSelectListener) context; 51 | } 52 | } 53 | 54 | private FragmentSearchFirstBinding mBinding; 55 | 56 | @Nullable 57 | @Override 58 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 59 | View view = inflater.inflate(R.layout.fragment_search_first, container, false); 60 | mBinding = FragmentSearchFirstBinding.bind(view); 61 | GankBus.registerResponseObserver(this); 62 | return view; 63 | } 64 | 65 | @Override 66 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 67 | super.onViewCreated(view, savedInstanceState); 68 | initFlexbox(); 69 | } 70 | 71 | private void initFlexbox() { 72 | mBinding.fblType.setFlexWrap(FlexWrap.WRAP); 73 | for (BaseEnum nameEnum : BaseEnum.values()) { 74 | final TextView tv_bq = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.tv_bq, mBinding.fblType, false); 75 | mBinding.fblType.addView(tv_bq); 76 | FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) tv_bq.getLayoutParams(); 77 | layoutParams.setMargins(DensityUtil.dip2px(getActivity(), 10), 78 | DensityUtil.dip2px(getActivity(), 5), 0, DensityUtil.dip2px(getActivity(), 5)); 79 | tv_bq.setText(nameEnum.getValue()); 80 | mBinding.fblType.getChildAt(0).setSelected(true); 81 | tv_bq.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | for (int i = 0; i < mBinding.fblType.getChildCount(); i++) { 85 | mBinding.fblType.getChildAt(i).setSelected(false); 86 | } 87 | tv_bq.setSelected(true); 88 | listener.onSelected(tv_bq.getText().toString()); 89 | } 90 | }); 91 | } 92 | mBinding.clear.setOnClickListener(new View.OnClickListener() { 93 | @Override 94 | public void onClick(View v) { 95 | GankBus.search().deleteAll(); 96 | GankBus.search().querySearchHistory(); 97 | } 98 | }); 99 | } 100 | 101 | @Override 102 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 103 | super.onActivityCreated(savedInstanceState); 104 | GankBus.search().querySearchHistory(); 105 | } 106 | 107 | @Override 108 | public void onDestroy() { 109 | super.onDestroy(); 110 | GankBus.unregisterResponseObserver(this); 111 | } 112 | 113 | @Override 114 | public void onResult(Result testResult) { 115 | String resultCode = (String) testResult.getResultCode(); 116 | switch (resultCode) { 117 | case GankResultCode.HISTORY_LIST_QUERYED: 118 | List results = (List) testResult.getResultObject(); 119 | mBinding.fblHistory.setFlexWrap(FlexWrap.WRAP); 120 | mBinding.fblHistory.removeAllViews(); 121 | for (String content : results) { 122 | final TextView tv_his = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.tv_bq, mBinding.fblHistory, false); 123 | mBinding.fblHistory.addView(tv_his); 124 | tv_his.setText(content); 125 | FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) tv_his.getLayoutParams(); 126 | layoutParams.setMargins(DensityUtil.dip2px(getActivity(), 10), 127 | DensityUtil.dip2px(getActivity(), 5), 0, DensityUtil.dip2px(getActivity(), 5)); 128 | tv_his.setOnClickListener(new View.OnClickListener() { 129 | @Override 130 | public void onClick(View v) { 131 | listener.onSearch(tv_his.getText().toString()); 132 | } 133 | }); 134 | } 135 | break; 136 | case GankResultCode.FAILURE: 137 | 138 | break; 139 | default: 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/collection/CollectionFragment.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.collection; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import com.gank.R; 13 | import com.gank.business.GankBus; 14 | import com.gank.business.constant.GankResultCode; 15 | import com.gank.data.database.entity.Image; 16 | import com.gank.data.network.response.Result; 17 | import com.gank.databinding.FragmentCollectionBinding; 18 | import com.gank.ui.adapter.CommonAdapter; 19 | import com.gank.ui.base.BaseFragment; 20 | import com.gank.ui.detail.DetailActivity; 21 | import com.gank.util.ItemDecoration; 22 | import com.gank.util.LogUtils; 23 | import com.gank.util.RecyclerViewUtil; 24 | import com.kunminx.architecture.business.bus.IResponse; 25 | import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter; 26 | import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | /** 32 | * Created by Administrator on 2017/4/20 0020. 33 | */ 34 | 35 | public class CollectionFragment extends BaseFragment implements IResponse { 36 | 37 | private int page = 1; 38 | private List list = new ArrayList<>(); 39 | private CommonAdapter mCommonAdapter = new CommonAdapter(); 40 | 41 | private FragmentCollectionBinding mBinding; 42 | 43 | @Nullable 44 | @Override 45 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 46 | View view = inflater.inflate(R.layout.fragment_collection, container, false); 47 | mBinding = FragmentCollectionBinding.bind(view); 48 | GankBus.registerResponseObserver(this); 49 | 50 | return view; 51 | } 52 | 53 | @Override 54 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 55 | super.onViewCreated(view, savedInstanceState); 56 | mActivity.initToolbar(mBinding.toolbar); 57 | mBinding.toolbar.setTitle(R.string.main3); 58 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); 59 | mBinding.recyclerView.addItemDecoration(new ItemDecoration(getActivity(), ItemDecoration.VERTICAL_LIST)); 60 | linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); 61 | mBinding.recyclerView.setLayoutManager(linearLayoutManager); 62 | mBinding.recyclerView.setAdapter(mCommonAdapter); 63 | RecyclerViewUtil.setHeader(getActivity(), mBinding.refreshLayout); 64 | mBinding.refreshLayout.setOnRefreshListener(new RefreshListenerAdapter() { 65 | @Override 66 | public void onRefresh(final TwinklingRefreshLayout refreshLayout) { 67 | new Handler().postDelayed(new Runnable() { 68 | @Override 69 | public void run() { 70 | page = 1; 71 | list.clear(); 72 | GankBus.gank().queryCollectionData(page); 73 | } 74 | }, 0); 75 | } 76 | 77 | @Override 78 | public void onLoadMore(final TwinklingRefreshLayout refreshLayout) { 79 | LogUtils.v("onLoadmore"); 80 | new Handler().postDelayed(new Runnable() { 81 | @Override 82 | public void run() { 83 | GankBus.gank().queryCollectionData(page); 84 | } 85 | }, 500); 86 | } 87 | 88 | @Override 89 | public void onFinishLoadMore() { 90 | page++; 91 | LogUtils.v("onFinishLoadMore"); 92 | super.onFinishLoadMore(); 93 | } 94 | 95 | }); 96 | 97 | mCommonAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() { 98 | @Override 99 | public void OnItemClick(View v, int position) { 100 | Intent intent = new Intent(getActivity(), DetailActivity.class); 101 | Result resultbean = list.get(position); 102 | if (resultbean.getImg() != null && resultbean.getImg().size() > 0) { 103 | List imgList = new ArrayList(); 104 | for (Image image : resultbean.getImg()) { 105 | imgList.add(image.getImageUrl()); 106 | resultbean.setImages(imgList); 107 | } 108 | } 109 | intent.putExtra("bean", resultbean); 110 | startActivity(intent); 111 | } 112 | }); 113 | 114 | } 115 | 116 | @Override 117 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 118 | super.onActivityCreated(savedInstanceState); 119 | mBinding.refreshLayout.startRefresh(); 120 | } 121 | 122 | @Override 123 | protected void refreshUI() { 124 | refreshToolbar(mBinding.toolbar); 125 | } 126 | 127 | @Override 128 | public void onDestroy() { 129 | super.onDestroy(); 130 | GankBus.unregisterResponseObserver(this); 131 | 132 | } 133 | 134 | @Override 135 | public void onResult(com.kunminx.architecture.business.bus.Result testResult) { 136 | String resultCode = (String) testResult.getResultCode(); 137 | switch (resultCode) { 138 | case GankResultCode.INDEX_LIST_QUERYED: 139 | List collections = (List) testResult.getResultObject(); 140 | if (collections != null) { 141 | list.addAll(collections); 142 | RecyclerViewUtil.loadMoreSetting(mBinding.refreshLayout, list); 143 | mCommonAdapter.setData(list, true); 144 | mCommonAdapter.notifyDataSetChanged(); 145 | } 146 | break; 147 | case GankResultCode.FAILURE: 148 | 149 | break; 150 | default: 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /app/src/main/java/com/gank/ui/search/SearchResultFragment.java: -------------------------------------------------------------------------------- 1 | package com.gank.ui.search; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import com.gank.Constants; 13 | import com.gank.R; 14 | import com.gank.business.GankBus; 15 | import com.gank.business.constant.GankResultCode; 16 | import com.gank.data.network.response.Result; 17 | import com.gank.databinding.FragmentSearchTwoBinding; 18 | import com.gank.ui.adapter.CommonAdapter; 19 | import com.gank.ui.base.BaseFragment; 20 | import com.gank.ui.detail.DetailActivity; 21 | import com.gank.util.ItemDecoration; 22 | import com.gank.util.RecyclerViewUtil; 23 | import com.gank.util.WrapContentLinearLayoutManager; 24 | import com.kunminx.architecture.business.bus.IResponse; 25 | import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter; 26 | import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | /** 32 | * Created by Administrator on 2017/4/27 0027. 33 | */ 34 | 35 | public class SearchResultFragment extends BaseFragment implements IResponse { 36 | 37 | private CommonAdapter commonAdapter = new CommonAdapter(); 38 | private int page; 39 | private boolean isRefresh = true; 40 | private String content; 41 | private String type; 42 | private List list = new ArrayList<>(); 43 | 44 | public static SearchResultFragment newInstance(Bundle bundle) { 45 | SearchResultFragment fragment = new SearchResultFragment(); 46 | fragment.setArguments(bundle); 47 | return fragment; 48 | } 49 | 50 | private FragmentSearchTwoBinding mBinding; 51 | 52 | @Nullable 53 | @Override 54 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 55 | View view = inflater.inflate(R.layout.fragment_search_two, container, false); 56 | mBinding = FragmentSearchTwoBinding.bind(view); 57 | GankBus.registerResponseObserver(this); 58 | 59 | return view; 60 | } 61 | 62 | @Override 63 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 64 | super.onViewCreated(view, savedInstanceState); 65 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); 66 | linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); 67 | mBinding.recyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); 68 | mBinding.recyclerView.addItemDecoration(new ItemDecoration(getActivity(), ItemDecoration.VERTICAL_LIST)); 69 | RecyclerViewUtil.setHeader(getActivity(), mBinding.refreshLayout); 70 | mBinding.refreshLayout.setOnRefreshListener(new RefreshListenerAdapter() { 71 | @Override 72 | public void onRefresh(final TwinklingRefreshLayout refreshLayout) { 73 | new Handler().postDelayed(new Runnable() { 74 | @Override 75 | public void run() { 76 | page = 1; 77 | isRefresh = true; 78 | GankBus.search().search(content, type, page + ""); 79 | } 80 | }, 0); 81 | } 82 | 83 | @Override 84 | public void onLoadMore(final TwinklingRefreshLayout refreshLayout) { 85 | new Handler().postDelayed(new Runnable() { 86 | @Override 87 | public void run() { 88 | GankBus.search().search(content, type, page + ""); 89 | } 90 | }, 500); 91 | } 92 | 93 | @Override 94 | public void onFinishLoadMore() { 95 | if (Constants.ERROR) { 96 | Constants.ERROR = false; 97 | } else { 98 | page++; 99 | } 100 | super.onFinishLoadMore(); 101 | } 102 | 103 | }); 104 | 105 | commonAdapter.setOnItemClickListener(new CommonAdapter.OnItemClickListener() { 106 | @Override 107 | public void OnItemClick(View v, int position) { 108 | Intent intent = new Intent(getActivity(), DetailActivity.class); 109 | Result resultbean = list.get(position); 110 | intent.putExtra("bean", resultbean); 111 | startActivity(intent); 112 | } 113 | }); 114 | } 115 | 116 | @Override 117 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 118 | super.onActivityCreated(savedInstanceState); 119 | mBinding.recyclerView.setAdapter(commonAdapter); 120 | loadData(getArguments().getString("content"), getArguments().getString("type")); 121 | } 122 | 123 | public void loadData(String content, String type) { 124 | this.content = content; 125 | this.type = type; 126 | mBinding.refreshLayout.startRefresh(); 127 | } 128 | 129 | @Override 130 | protected void refreshUI() { 131 | 132 | } 133 | 134 | @Override 135 | public void onDestroy() { 136 | super.onDestroy(); 137 | GankBus.unregisterResponseObserver(this); 138 | } 139 | 140 | @Override 141 | public void onResult(com.kunminx.architecture.business.bus.Result testResult) { 142 | String resultCode = (String) testResult.getResultCode(); 143 | switch (resultCode) { 144 | case GankResultCode.SEARCH_LIST_QUERYED: 145 | List results = (List) testResult.getResultObject(); 146 | if (isRefresh) { 147 | list.clear(); 148 | isRefresh = false; 149 | } 150 | int start = list.size(); 151 | list.addAll(results); 152 | RecyclerViewUtil.loadMoreSetting(mBinding.refreshLayout, list); 153 | commonAdapter.setSearchData(list, true); 154 | commonAdapter.notifyData(start, results.size()); 155 | break; 156 | case GankResultCode.FAILURE: 157 | Constants.ERROR = true; 158 | mBinding.refreshLayout.onFinishLoadMore(); 159 | break; 160 | default: 161 | } 162 | } 163 | } 164 | --------------------------------------------------------------------------------