diff --git a/MeteoriteLibrary/build.gradle b/MeteoriteLibrary/build.gradle
index 2ff5797..6ca6186 100644
--- a/MeteoriteLibrary/build.gradle
+++ b/MeteoriteLibrary/build.gradle
@@ -91,11 +91,8 @@ dependencies {
//https://github.com/pwittchen/ReactiveNetwork
compile "com.github.pwittchen:reactivenetwork-rx2:${versions.reactivenetwork}"
- //https://github.com/permissions-dispatcher/PermissionsDispatcher
- compile("com.github.hotchemi:permissionsdispatcher:${versions.permissionsdispatcher}") {
- // if you don't use android.app.Fragment you can exclude support for them
- exclude module: "support-v13"
- }
+ //https://github.com/tbruyelle/RxPermissions
+ compile "com.github.tbruyelle:rxpermissions:${versions.rxpermissions}"
//https://github.com/crazycodeboy/TakePhoto
compile "com.jph.takephoto:takephoto_library:${versions.takephoto}"
diff --git a/README.md b/README.md
index 8f55b0e..372c5cc 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
- 1、MVP
- 2、网络请求(Novate基于rxjava,okhttp,retrofit封装架构)
- 3、DbFlow(可保存文件入SD卡)
- - 4、6.0权限申请
+ - 4、6.0权限申请(rxpermissions)
- 5、XRecyclerView
- 6、万能Adapter
- 7、异常处理
@@ -19,10 +19,15 @@
- 15、升级更新
- 16、极光推送
- 17、butterknife
+ - 18、APP启动图标多环境区分(easylauncher)
+ - 19、函数输入参数打印(Hugo)
+
+
+
License
diff --git a/app/build.gradle b/app/build.gradle
index e76e64c..5c5f8fd 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
+apply plugin: 'com.akaita.android.easylauncher'
+apply plugin: 'com.jakewharton.hugo'
apply from: '../dependencies.gradle'
def PRODUCT_NAME = "陨石"
@@ -77,17 +79,6 @@ android {
def versionName = defaultConfig.versionName
// 开发环境
buildConfigField "String", "APP_ENV", "\"${flavorName}\""
- // 修改打包环境的url
- def base_url = ''
- if(flavorName.equals("rls")){//生产环境
- base_url = 'http://gank.io/api/'
- }else if(flavorName.equals("dev")){//开发环境(模拟)
- base_url = 'http://dev.gank.io/api/'
- }else if(flavorName.equals("sit")){//测试环境(模拟)
- base_url = 'http://sit.gank.io/api/'
- }
- buildConfigField "String", "BASE_URL", "\"${base_url}\""
-
// yourapkname_release_myapk_ver1.0.0_build20130312.apk 输出格式
def fileName = "${PRODUCT_NAME}_V${versionName}_${buildTypeName}_${flavorName}_${BUILD_TIME_FORMAT}.apk"
@@ -98,11 +89,17 @@ android {
productFlavors {
//生产环境
- rls {}
+ rls {
+ buildConfigField "String", "BASE_URL", "\"http://gank.io/api/\""
+ }
//开发环境
- dev {}
+ dev {
+ buildConfigField "String", "BASE_URL", "\"http://dev.gank.io/api/\""
+ }
//测试环境
- sit {}
+ sit {
+ buildConfigField "String", "BASE_URL", "\"http://sit.gank.io/api/\""
+ }
}
lintOptions {
@@ -133,5 +130,19 @@ dependencies {
exclude group: 'com.google.code.gson', module: 'gson'
}
- annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:${versions.permissionsdispatcher}"
+}
+
+//更改程序图标
+easylauncher {
+ defaultFlavorNaming = true // Use flavor name for default ribbon, instead of the type name
+ variants {
+ devRelease {
+ filters = customColorRibbonFilter("dev", "#6600CC")
+ enable true
+ }
+ sitRelease {
+ filters = customColorRibbonFilter("sit", "#6600CC")
+ enable true
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5d92914..fb04090 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -9,6 +9,7 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/firelotus/meteorite/ui/MainActivity.java b/app/src/main/java/com/firelotus/meteorite/ui/MainActivity.java
index a030879..7288e00 100644
--- a/app/src/main/java/com/firelotus/meteorite/ui/MainActivity.java
+++ b/app/src/main/java/com/firelotus/meteorite/ui/MainActivity.java
@@ -1,5 +1,6 @@
package com.firelotus.meteorite.ui;
+import android.Manifest;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
@@ -19,17 +20,23 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import android.widget.Toast;
import com.firelotus.meteorite.R;
import com.firelotus.meteorite.ui.content.SubFragment;
import com.firelotus.meteoritelibrary.base.BaseActivity;
+import com.firelotus.meteoritelibrary.toast.MToast;
+import com.firelotus.meteoritelibrary.tools.MLog;
import com.orhanobut.logger.Logger;
import com.shizhefei.view.indicator.FixedIndicatorView;
import com.shizhefei.view.indicator.IndicatorViewPager;
import com.shizhefei.view.indicator.transition.OnTransitionTextListener;
+import com.tbruyelle.rxpermissions2.Permission;
+import com.tbruyelle.rxpermissions2.RxPermissions;
import butterknife.BindView;
import de.hdodenhof.circleimageview.CircleImageView;
+import io.reactivex.functions.Consumer;
public class MainActivity extends BaseActivity
implements NavigationView.OnNavigationItemSelectedListener,View.OnClickListener {
@@ -72,7 +79,7 @@ public void onClick(View view) {
navigationView.setNavigationItemSelectedListener(this);
- profile_image = (CircleImageView) navigationView.getHeaderView(0).findViewById(R.id.profile_image);
+ profile_image = navigationView.getHeaderView(0).findViewById(R.id.profile_image);
profile_image.setOnClickListener(this);
float unSelectSize = 16;
@@ -94,12 +101,26 @@ public void onClick(View view) {
@Override
protected void initData() {
-
+ //rxpermissions实现6.0权限申请
+ RxPermissions rxPermissions = new RxPermissions(this);
+ rxPermissions.requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.CAMERA)
+ .subscribe(new Consumer() {
+ @Override
+ public void accept(Permission permission) throws Exception {
+ if(permission.granted){
+ MLog.d("Permission granted !");
+ }else if(permission.shouldShowRequestPermissionRationale){
+ MToast.show(getApplicationContext(),"Denied permission without ask never again !", Toast.LENGTH_LONG);
+ }else{
+ MToast.show(getApplicationContext(),"Permission denied !", Toast.LENGTH_LONG);
+ }
+ }
+ });
}
@Override
public void onBackPressed() {
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
+ DrawerLayout drawer = findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
@@ -137,18 +158,18 @@ public boolean onNavigationItemSelected(MenuItem item) {
if (id == R.id.nav_home) {
} else if (id == R.id.nav_about) {
tv_content.setText("about");
- AboutActivity.start(getApplicationContext());
+ AboutActivity.start(this);
} else if (id == R.id.nav_login) {
- WebActivity.loadUrl(getApplicationContext(), "https://github.com/login", "登录GitHub");
+ WebActivity.loadUrl(this, "https://github.com/login", "登录GitHub");
} else if (id == R.id.nav_set) {
tv_content.setText("set");
} else if (id == R.id.nav_comments) {
- FeedBackActivity.start(getApplicationContext());
+ FeedBackActivity.start(this);
} else if (id == R.id.nav_logout) {
finish();
}
Logger.d(tv_content.getText().toString());
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
+ DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
diff --git a/app/src/main/java/com/firelotus/meteorite/ui/ViewPagerActivity.java b/app/src/main/java/com/firelotus/meteorite/ui/ViewPagerActivity.java
new file mode 100644
index 0000000..b1f6014
--- /dev/null
+++ b/app/src/main/java/com/firelotus/meteorite/ui/ViewPagerActivity.java
@@ -0,0 +1,100 @@
+package com.firelotus.meteorite.ui;
+
+/**
+ * Created by firelotus on 2018/1/1.
+ */
+
+import android.content.Context;
+import android.content.Intent;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+
+import com.bumptech.glide.Glide;
+import com.firelotus.meteorite.R;
+import com.firelotus.meteorite.ui.bean.GankBean;
+import com.firelotus.meteoritelibrary.base.BaseActivity;
+import com.github.chrisbanes.photoview.PhotoView;
+
+import java.util.ArrayList;
+
+public class ViewPagerActivity extends BaseActivity {
+ private int pos;
+ private ArrayList list = new ArrayList<>();
+ private ViewPager viewPager;
+ private ViewPagerAdapter adapter;
+
+ @Override
+ protected int getLayoutId() {
+ return R.layout.activity_viewpager;
+ }
+
+ @Override
+ protected void initView() {
+ viewPager = findViewById(R.id.view_pager);
+ adapter = new ViewPagerAdapter(list);
+ viewPager.setAdapter(adapter);
+ }
+
+ @Override
+ protected void initData() {
+ Intent intent = getIntent();
+ if(intent == null){
+ return;
+ }
+ pos = intent.getIntExtra("pos",0);
+ ArrayList tmpList = (ArrayList) intent.getSerializableExtra("list");
+ if(tmpList != null){
+ list.clear();
+ list.addAll(tmpList);
+ adapter.notifyDataSetChanged();
+ }
+
+ //切换到选中页
+ viewPager.setCurrentItem(pos);
+ }
+
+ static class ViewPagerAdapter extends PagerAdapter {
+ private ArrayList gankBeans = new ArrayList<>();
+
+ public ViewPagerAdapter(ArrayList list){
+ this.gankBeans = list;
+ }
+
+ @Override
+ public int getCount() {
+ return gankBeans.size();
+ }
+
+ @Override
+ public View instantiateItem(ViewGroup container, int position) {
+ PhotoView photoView = new PhotoView(container.getContext());
+ //photoView.setImageURI(Uri.parse(gankBeans.get(position).getUrl()));
+ Glide.with(container.getContext()).load(gankBeans.get(position).getUrl()).into(photoView);
+ // Now just add PhotoView to ViewPager and return it
+ container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
+
+ return photoView;
+ }
+
+ @Override
+ public void destroyItem(ViewGroup container, int position, Object object) {
+ container.removeView((View) object);
+ }
+
+ @Override
+ public boolean isViewFromObject(View view, Object object) {
+ return view == object;
+ }
+
+ }
+
+ public static void start(Context context, int pos, ArrayList gankBeans){
+ Intent intent = new Intent(context,ViewPagerActivity.class);
+ intent.putExtra("pos",pos);
+ intent.putExtra("list",gankBeans);
+ context.startActivity(intent);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/firelotus/meteorite/ui/bean/GankBean.java b/app/src/main/java/com/firelotus/meteorite/ui/bean/GankBean.java
index fbbcbc3..3aad2d9 100644
--- a/app/src/main/java/com/firelotus/meteorite/ui/bean/GankBean.java
+++ b/app/src/main/java/com/firelotus/meteorite/ui/bean/GankBean.java
@@ -2,13 +2,14 @@
import android.support.annotation.Keep;
+import java.io.Serializable;
import java.util.List;
/**
* Created by firelotus on 2017/10/15.
*/
@Keep
-public class GankBean {
+public class GankBean implements Serializable{
/**
* _id : 59e46c6a421aa90fe50c0174
diff --git a/app/src/main/java/com/firelotus/meteorite/ui/content/SubFragment.java b/app/src/main/java/com/firelotus/meteorite/ui/content/SubFragment.java
index 4ff766d..10ea958 100644
--- a/app/src/main/java/com/firelotus/meteorite/ui/content/SubFragment.java
+++ b/app/src/main/java/com/firelotus/meteorite/ui/content/SubFragment.java
@@ -8,7 +8,7 @@
import com.bumptech.glide.Glide;
import com.firelotus.meteorite.R;
-import com.firelotus.meteorite.ui.ImageViewerActivity;
+import com.firelotus.meteorite.ui.ViewPagerActivity;
import com.firelotus.meteorite.ui.WebActivity;
import com.firelotus.meteorite.ui.bean.GankBean;
import com.firelotus.meteoritelibrary.base.BaseFragment;
@@ -22,7 +22,8 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import java.util.Calendar;
+import java.util.Date;
import butterknife.BindView;
@@ -38,7 +39,7 @@ public class SubFragment extends BaseFragment implements ISubContract.View{
@BindView(R.id.banner) Banner banner;
@BindView(R.id.fragment_mainTab_item_textView) TextView textView;
private CommonAdapter adapter;
- private List gankBeans = new ArrayList<>();
+ private ArrayList gankBeans = new ArrayList<>();
private ISubContract.Presenter presenter;
private int pos = 0;
@@ -50,6 +51,9 @@ public class SubFragment extends BaseFragment implements ISubContract.View{
//private TextView textView;
private String[] images;
+ //当前日期
+ private Calendar calendar = Calendar.getInstance();
+
@Override
protected void initView() {
showLoading();
@@ -116,7 +120,7 @@ protected void initView() {
adapter = new CommonAdapter(activity,R.layout.item_sub,gankBeans) {
@Override
- protected void convert(ViewHolder holder, final GankBean gankBean, int position) {
+ protected void convert(ViewHolder holder, final GankBean gankBean, final int position) {
if(type.equals("福利")){
holder.getView(R.id.iv_all_welfare).setVisibility(View.VISIBLE);
holder.getView(R.id.ll_welfare_other).setVisibility(View.GONE);
@@ -125,7 +129,8 @@ protected void convert(ViewHolder holder, final GankBean gankBean, int position)
holder.getConvertView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- ImageViewerActivity.start(activity.getApplicationContext(),gankBean.getUrl());
+ //ImageViewerActivity.start(activity.getApplicationContext(),gankBean.getUrl());
+ ViewPagerActivity.start(activity,position-1,gankBeans);
}
});
} else {
@@ -133,7 +138,7 @@ public void onClick(View v) {
holder.getConvertView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- WebActivity.loadUrl(activity.getApplicationContext(), gankBean.getUrl(),gankBean.getDesc());
+ WebActivity.loadUrl(activity, gankBean.getUrl(),gankBean.getDesc());
}
});
}
@@ -183,10 +188,11 @@ protected int getLayoutId() {
@Override
protected void initData() {
+ calendar.setTime(new Date());
presenter = new SubPresenter(this);
switch (position){
case 0:
- presenter.dealEveryDay("2017","10","20");
+ presenter.dealEveryDay(String.valueOf(calendar.get(Calendar.YEAR)),String.valueOf(calendar.get(Calendar.MONTH)+1),String.valueOf(calendar.get(Calendar.DATE)));
banner.setVisibility(View.VISIBLE);
break;
case 1:
@@ -251,5 +257,11 @@ public void onEveryDaySuccess(ArrayList list) {
this.gankBeans.addAll(list);
adapter.notifyDataSetChanged();
xRecyclerView.setNoMore(true);
+ xRecyclerView.setPullRefreshEnabled(false);
+ //优化逻辑:因为此类数据不是每天都有,所以以当前时间为起始点,进行请求,直到获取到数据为止.
+ if(list.size() == 0){
+ calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)-1);
+ presenter.dealEveryDay(String.valueOf(calendar.get(Calendar.YEAR)),String.valueOf(calendar.get(Calendar.MONTH)+1),String.valueOf(calendar.get(Calendar.DATE)));
+ }
}
}
diff --git a/app/src/main/java/com/firelotus/meteorite/ui/content/SubPresenter.java b/app/src/main/java/com/firelotus/meteorite/ui/content/SubPresenter.java
index 14617f7..e720c0e 100644
--- a/app/src/main/java/com/firelotus/meteorite/ui/content/SubPresenter.java
+++ b/app/src/main/java/com/firelotus/meteorite/ui/content/SubPresenter.java
@@ -5,6 +5,8 @@
import java.util.ArrayList;
+import hugo.weaving.DebugLog;
+
/**
* Created by firelotus on 2017/10/15.
*/
@@ -17,6 +19,8 @@ public SubPresenter(ISubContract.View view) {
this.view = view;
this.modle = new SubModel();
}
+
+ @DebugLog
@Override
public void dealContent(String type, int pageIndex, int pageSize) {
view.showLoading();
@@ -34,6 +38,7 @@ public void onError() {
view.hideLoading();
}
+ @DebugLog
@Override
public void dealEveryDay(String year, String month, String day) {
view.showProgress();
diff --git a/app/src/main/res/layout/activity_viewpager.xml b/app/src/main/res/layout/activity_viewpager.xml
new file mode 100644
index 0000000..a3c7fab
--- /dev/null
+++ b/app/src/main/res/layout/activity_viewpager.xml
@@ -0,0 +1,9 @@
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 8bde05f..b3a0de6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -11,6 +11,10 @@ buildscript {
classpath "com.android.tools.build:gradle:${versions.gradlePlugin}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
+ //环境图标区分
+ classpath 'com.akaita.android:easylauncher:1.2.0'
+ //函数参数输入输出打印
+ classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}
diff --git a/dependencies.gradle b/dependencies.gradle
index ee239de..5e5db65 100644
--- a/dependencies.gradle
+++ b/dependencies.gradle
@@ -1,13 +1,13 @@
//参考material-dialogs
ext.versions = [
minSdk : 15,
- compileSdk : 25,
- targetSdk : 25,
- buildTools : '26.0.2',
+ compileSdk : 27,
+ targetSdk : 27,
+ buildTools : '27.0.0',
gradlePlugin : '3.0.0',
versionCode : 1,
versionName : '1.0.0',
- supportLib : '25.3.1',
+ supportLib : '27.1.1',
constraintLayout : '1.0.2',
dbflow : '4.0.5',
leakcanary : '1.5.4',
@@ -28,7 +28,7 @@ ext.versions = [
glideTransformations : '2.0.1',
agentweb : '2.0.1',
gsonVersion : '2.8.0',
- permissionsdispatcher : '3.0.1',
+ rxpermissions : '0.10.2',
reactivenetwork : '0.12.2',
takephoto : '4.0.3',
PhotoView : '2.1.3'
diff --git a/image/easylauncher.png b/image/easylauncher.png
new file mode 100644
index 0000000..e3b9056
Binary files /dev/null and b/image/easylauncher.png differ
diff --git a/image/hugo.png b/image/hugo.png
new file mode 100644
index 0000000..6f4a09c
Binary files /dev/null and b/image/hugo.png differ
diff --git a/image/permission.gif b/image/permission.gif
new file mode 100644
index 0000000..8d21848
Binary files /dev/null and b/image/permission.gif differ