Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikang
lib_base
Commits
f3db2a9a
Commit
f3db2a9a
authored
Sep 30, 2018
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
eec5c553
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
119 deletions
+32
-119
src/main/java/tech/starwin/base/BaseActivity.java
+7
-1
src/main/java/tech/starwin/base/BaseFragment.java
+11
-1
src/main/java/tech/starwin/base/LibConfig.java
+0
-103
src/main/java/tech/starwin/common/impl/HttpObserver.java
+1
-3
src/main/java/tech/starwin/network/Gateway.java
+3
-5
src/main/java/tech/starwin/utils/FileUtils.java
+1
-2
src/main/java/tech/starwin/utils/LoginManager.java
+1
-1
src/main/java/tech/starwin/utils/PreferencesManager.java
+8
-3
No files found.
src/main/java/tech/starwin/base/BaseActivity.java
View file @
f3db2a9a
...
...
@@ -19,6 +19,7 @@ import com.trello.rxlifecycle2.android.RxLifecycleAndroid;
import
io.reactivex.Observable
;
import
io.reactivex.subjects.BehaviorSubject
;
import
tech.starwin.LibConfig
;
import
tech.starwin.R
;
import
tech.starwin.mvp.IView
;
import
tech.starwin.utils.PresenterHoler
;
...
...
@@ -50,6 +51,8 @@ public abstract class BaseActivity extends AppCompatActivity implements IView {
*/
protected
ProgressHolder
progressHolder
;
private
Object
unBinder
;
private
final
BehaviorSubject
<
ActivityEvent
>
lifecycleSubject
=
BehaviorSubject
.
create
();
@Override
...
...
@@ -91,6 +94,9 @@ public abstract class BaseActivity extends AppCompatActivity implements IView {
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
if
(
unBinder
!=
null
)
{
LibConfig
.
unBindView
(
unBinder
);
}
lifecycleSubject
.
onNext
(
ActivityEvent
.
DESTROY
);
presenterHelper
.
onDestory
();
}
...
...
@@ -150,7 +156,7 @@ public abstract class BaseActivity extends AppCompatActivity implements IView {
//填充Activity -> bindLayout();
if
(
bindLayout
()
!=
0
)
{
LayoutInflater
.
from
(
this
).
inflate
(
bindLayout
(),
rootLayout
,
true
);
LibConfig
.
bindView
(
this
,
rootLayout
);
unBinder
=
LibConfig
.
bindView
(
this
,
rootLayout
);
initView
();
}
else
{
throw
new
RuntimeException
(
"找不到布局文件 bindLayout() -> "
+
bindLayout
());
...
...
src/main/java/tech/starwin/base/BaseFragment.java
View file @
f3db2a9a
...
...
@@ -18,6 +18,7 @@ import com.trello.rxlifecycle2.android.RxLifecycleAndroid;
import
io.reactivex.Observable
;
import
io.reactivex.subjects.BehaviorSubject
;
import
tech.starwin.LibConfig
;
import
tech.starwin.R
;
import
tech.starwin.mvp.IView
;
import
tech.starwin.utils.PresenterHoler
;
...
...
@@ -46,8 +47,14 @@ public abstract class BaseFragment extends Fragment implements IView {
*/
protected
ProgressHolder
progressHolder
;
/**
* LifeCycle
*/
private
final
BehaviorSubject
<
ActivityEvent
>
lifecycleSubject
=
BehaviorSubject
.
create
();
Object
unBinder
;
@Nullable
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
Bundle
savedInstanceState
)
{
...
...
@@ -62,7 +69,7 @@ public abstract class BaseFragment extends Fragment implements IView {
initTopBar
(
mTopBar
);
}
mContentView
=
(
ViewGroup
)
LayoutInflater
.
from
(
getActivity
()).
inflate
(
bindLayout
(),
mContentView
);
LibConfig
.
bindView
(
this
,
mContentView
);
unBinder
=
LibConfig
.
bindView
(
this
,
mContentView
);
initView
();
return
mContentView
;
}
...
...
@@ -137,6 +144,9 @@ public abstract class BaseFragment extends Fragment implements IView {
@Override
public
void
onDestroyView
()
{
super
.
onDestroyView
();
if
(
unBinder
!=
null
)
{
LibConfig
.
unBindView
(
unBinder
);
}
lifecycleSubject
.
onNext
(
ActivityEvent
.
DESTROY
);
presenterHelper
.
onDestory
();
}
...
...
src/main/java/tech/starwin/base/LibConfig.java
deleted
100644 → 0
View file @
eec5c553
package
tech
.
starwin
.
base
;
import
android.app.Application
;
import
android.content.Context
;
import
android.view.View
;
import
com.scwang.smartrefresh.layout.SmartRefreshLayout
;
import
com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator
;
import
com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator
;
import
com.scwang.smartrefresh.layout.api.RefreshFooter
;
import
com.scwang.smartrefresh.layout.api.RefreshHeader
;
import
com.scwang.smartrefresh.layout.api.RefreshLayout
;
import
com.scwang.smartrefresh.layout.footer.ClassicsFooter
;
import
com.scwang.smartrefresh.layout.header.ClassicsHeader
;
import
tech.starwin.R
;
/**
* Created by SiKang on 2018/9/30.
*/
public
class
LibConfig
{
private
static
Context
CONTEXT
;
public
static
boolean
DEBUG
;
public
static
String
APPLICATION_ID
;
public
static
String
BUILD_TYPE
;
public
static
String
FLAVOR
;
public
static
int
VERSION_CODE
;
public
static
String
VERSION_NAME
;
public
static
String
FLAVOR_default
;
public
static
String
FLAVOR_server
;
public
static
String
AGREEMENT_URL
;
public
static
String
APP_URL
;
public
static
String
BUGLY_APP_ID
;
public
static
String
CONTRACT_URL
;
public
static
String
HOTLINE
;
public
static
String
LOAN_AGREEMENT
;
public
static
String
LOGIN_ACTIVITY_ACTION
;
public
static
String
ROOT_DIR
;
public
static
String
ADMIN_HOST
;
public
static
String
API_BASE_URL
;
public
static
String
GATEWAY_HOST_G0
;
public
static
String
GATEWAY_HOST_G1
;
public
static
String
HARVESTER_IP
;
public
static
int
HARVESTER_PORT
;
public
static
ButterKnifeBinder
butterKnifeBinder
;
public
static
Context
getContext
()
{
if
(
CONTEXT
==
null
)
throw
new
RuntimeException
(
"context is null ! you must execute LibConfig.bindApplication(application) in your Appliaction"
);
return
CONTEXT
;
}
/**
* 为Library绑定一个Context
*/
public
static
void
bindApplication
(
Application
application
)
{
CONTEXT
=
application
;
}
/**
* 用于在Base 中 实现Butterknife.bind()的功能
*
* @param binder 实现 ButterKnifeBinder.bindView() 方法,在其中做Butterknife.bind() ,功能
*/
public
static
void
setButterKnifeBinder
(
ButterKnifeBinder
binder
)
{
butterKnifeBinder
=
binder
;
}
public
static
void
bindView
(
Object
obj
,
View
view
)
{
if
(
butterKnifeBinder
!=
null
)
{
butterKnifeBinder
.
bindView
(
obj
,
view
);
}
}
public
interface
ButterKnifeBinder
{
void
bindView
(
Object
obj
,
View
view
);
}
/**
* SmartRefresh 默认风格
* */
static
{
//设置全局的Header构建器
SmartRefreshLayout
.
setDefaultRefreshHeaderCreator
(
new
DefaultRefreshHeaderCreator
()
{
@Override
public
RefreshHeader
createRefreshHeader
(
Context
context
,
RefreshLayout
layout
)
{
layout
.
setPrimaryColorsId
(
R
.
color
.
color_main
,
android
.
R
.
color
.
white
);
//全局设置主题颜色
return
new
ClassicsHeader
(
context
);
//.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header,默认是 贝塞尔雷达Header
}
});
//设置全局的Footer构建器
SmartRefreshLayout
.
setDefaultRefreshFooterCreator
(
new
DefaultRefreshFooterCreator
()
{
@Override
public
RefreshFooter
createRefreshFooter
(
Context
context
,
RefreshLayout
layout
)
{
//指定为经典Footer,默认是 BallPulseFooter
return
new
ClassicsFooter
(
context
).
setDrawableSize
(
20
);
}
});
}
}
src/main/java/tech/starwin/common/impl/HttpObserver.java
View file @
f3db2a9a
package
tech
.
starwin
.
common
.
impl
;
import
java.io.EOFException
;
import
io.reactivex.Observer
;
import
io.reactivex.disposables.Disposable
;
import
retrofit2.HttpException
;
import
tech.starwin.R
;
import
tech.starwin.
base.
LibConfig
;
import
tech.starwin.LibConfig
;
import
tech.starwin.network.Error
;
import
tech.starwin.utils.LoginManager
;
...
...
src/main/java/tech/starwin/network/Gateway.java
View file @
f3db2a9a
...
...
@@ -3,10 +3,8 @@ package tech.starwin.network;
import
java.util.Arrays
;
import
java.util.List
;
import
tech.starwin.BuildConfig
;
import
tech.starwin.base.LibConfig
;
import
tech.starwin.LibConfig
;
import
tech.starwin.mvp.beans.GatewayInfoBean
;
import
tech.starwin.utils.PreferencesManager
;
/**
* Created by SiKang on 2018/9/28.
...
...
@@ -14,8 +12,8 @@ import tech.starwin.utils.PreferencesManager;
public
class
Gateway
{
private
static
GatewayInfoBean
gatewayInfo
;
static
{
gatewayInfo
=
PreferencesManager
.
get
().
getGatewayInfo
()
;
public
static
void
init
(
GatewayInfoBean
info
)
{
gatewayInfo
=
info
;
if
(
gatewayInfo
==
null
)
{
gatewayInfo
=
new
GatewayInfoBean
();
gatewayInfo
.
gateway
=
Arrays
.
asList
(
LibConfig
.
GATEWAY_HOST_G0
,
...
...
src/main/java/tech/starwin/utils/FileUtils.java
View file @
f3db2a9a
...
...
@@ -14,8 +14,7 @@ import java.io.FileInputStream;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
tech.starwin.BuildConfig
;
import
tech.starwin.base.LibConfig
;
import
tech.starwin.LibConfig
;
/**
* Created by SiKang on 2018/9/25.
...
...
src/main/java/tech/starwin/utils/LoginManager.java
View file @
f3db2a9a
...
...
@@ -10,7 +10,7 @@ import com.facebook.accountkit.ui.AccountKitActivity;
import
com.facebook.accountkit.ui.AccountKitConfiguration
;
import
com.facebook.accountkit.ui.LoginType
;
import
tech.starwin.
base.
LibConfig
;
import
tech.starwin.LibConfig
;
import
tech.starwin.mvp.beans.TokenInfoBean
;
import
tech.starwin.utils.activity_utils.EasyActivityResult
;
import
tech.starwin.utils.activity_utils.IntentHolder
;
...
...
src/main/java/tech/starwin/utils/PreferencesManager.java
View file @
f3db2a9a
package
tech
.
starwin
.
utils
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.text.TextUtils
;
import
java.util.Map
;
import
tech.starwin.base.LibConfig
;
import
tech.starwin.mvp.beans.GatewayInfoBean
;
import
tech.starwin.mvp.beans.PersonalInfo
;
import
tech.starwin.mvp.beans.TokenInfoBean
;
...
...
@@ -23,10 +23,15 @@ public class PreferencesManager {
private
SharedPreferences
mSharedPreferences
;
// 获取Editor对象
private
SharedPreferences
.
Editor
mEditor
;
private
Context
context
;
private
PreferencesManager
()
{
mSharedPreferences
=
LibConfig
.
getContext
().
getSharedPreferences
(
PREFERENCES_FILE_NAME
,
Activity
.
MODE_PRIVATE
);
}
public
void
init
(
Context
context
)
{
this
.
context
=
context
;
mSharedPreferences
=
context
.
getSharedPreferences
(
PREFERENCES_FILE_NAME
,
Activity
.
MODE_PRIVATE
);
mEditor
=
mSharedPreferences
.
edit
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment