Skip to content

Commit 5e2be0b

Browse files
committed
更改服务器子域名为app,实现启动Tips和生日祝福
1 parent 2743627 commit 5e2be0b

File tree

16 files changed

+318
-46
lines changed

16 files changed

+318
-46
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ android {
2020
applicationId "com.guang.app"
2121
minSdkVersion 15
2222
targetSdkVersion 23
23-
versionCode 1
24-
versionName "1.0.0"
23+
versionCode 2
24+
versionName "1.1.0"
2525
}
2626
buildTypes {
2727
// proguard测试时可以开注释,可以看到报错

app/src/main/java/com/guang/app/AppConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static class Url {
5050

5151
public static final String feedback = index + "work/feedback";
5252
public static final String updateURL = index + "work/check-app-update";
53+
public static final String appTips = index + "work/get-app-tips";
5354

5455
}
5556

app/src/main/java/com/guang/app/activity/FeedbackActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.guang.app.activity;
22

33
import android.os.Bundle;
4+
import android.text.TextUtils;
45
import android.widget.EditText;
56
import android.widget.Toast;
67

@@ -39,7 +40,10 @@ protected boolean shouldHideLoadingIcon() {
3940
@OnClick(R.id.btn_feedback_submit) void submitFeedback() {
4041
String contact = edFeedbackContact.getText().toString();
4142
String content = edFeedbackContent.getText().toString();
42-
43+
if(TextUtils.isEmpty(content)){
44+
Toast.makeText(this, "内容还没填呢", Toast.LENGTH_SHORT).show();
45+
return;
46+
}
4347
WorkApiFactory factory = WorkApiFactory.getInstance();
4448
factory.submitFeedback(contact, content,new Observer<StrObjectResponse>() {
4549
@Override

app/src/main/java/com/guang/app/activity/MainActivity.java

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package com.guang.app.activity;
22

33
import android.app.Fragment;
4+
import android.content.DialogInterface;
45
import android.content.Intent;
6+
import android.net.Uri;
57
import android.os.Bundle;
8+
import android.support.v7.app.AlertDialog;
69
import android.text.TextUtils;
710
import android.widget.RadioButton;
811

912
import com.guang.app.AppConfig;
1013
import com.guang.app.R;
14+
import com.guang.app.api.WorkApiFactory;
1115
import com.guang.app.fragment.FeatureFragment;
1216
import com.guang.app.fragment.HomeFragment;
1317
import com.guang.app.fragment.MeFragment;
14-
import com.guang.app.model.UserAccount;
18+
import com.guang.app.model.AppTips;
1519
import com.guang.app.util.FileUtils;
1620
import com.guang.app.util.FragmentUtil;
21+
import com.guang.app.util.TimeUtils;
1722

1823
import org.lzh.framework.updatepluginlib.UpdateBuilder;
1924

@@ -22,6 +27,8 @@
2227

2328
import butterknife.Bind;
2429
import butterknife.OnClick;
30+
import io.reactivex.Observer;
31+
import io.reactivex.disposables.Disposable;
2532

2633
public class MainActivity extends BaseActivity {
2734
// @Bind(R.id.main_fragment)
@@ -33,15 +40,12 @@ public class MainActivity extends BaseActivity {
3340
@Bind(R.id.rd_me) RadioButton radioMe;
3441

3542
private FragmentUtil fUtil;
43+
3644
@Override
3745
protected void onCreate(Bundle savedInstanceState) {
3846
super.onCreate(savedInstanceState);
3947
setContentView(R.layout.main);
4048

41-
// TODO 删
42-
FileUtils.setStoredAccount(MainActivity.this, new UserAccount("13251102210", "123456","123456"));
43-
AppConfig.defaultPage = AppConfig.DefaultPage.HOME; //默认首页为课表
44-
4549
//未登录跳转登陆页
4650
if(!FileUtils.getStoredAccountAndSetApp(this) || TextUtils.isEmpty(AppConfig.sno) || TextUtils.isEmpty(AppConfig.idsPwd)){
4751
startActivity(new Intent(this, LoginActivity.class));
@@ -58,8 +62,11 @@ protected void onCreate(Bundle savedInstanceState) {
5862
setTitle(R.string.app_name);
5963
initFragment();
6064
UpdateBuilder.create().check();
65+
66+
checkAppTips();
6167
}
6268

69+
6370
private void initFragment() {
6471
mFragments = new ArrayList<>();
6572
mFragments.add(new HomeFragment());
@@ -71,19 +78,6 @@ private void initFragment() {
7178
fUtil.addAll(R.id.main_fragment,mFragments);
7279
fUtil.show(mFragments.get(0));
7380

74-
// mTabGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
75-
// @Override
76-
// public void onCheckedChanged(RadioGroup radioGroup, int checkID) {
77-
// switch (checkID){
78-
// case R.id.rd_home:
79-
// fUtil.show(mFragments.get(0));break;
80-
// case R.id.rd_features:
81-
// fUtil.show(mFragments.get(1));break;
82-
// case R.id.rd_me:
83-
// fUtil.show(mFragments.get(2));break;
84-
// }
85-
// }
86-
// });
8781
//启动默认首页,注意跟上面监听器的顺序问题
8882
AppConfig.defaultPage = FileUtils.getStoredDefaultPage(this);
8983
switch (AppConfig.defaultPage){
@@ -119,4 +113,72 @@ private void initFragment() {
119113
}
120114
}
121115
}
116+
117+
/**
118+
* 获取每日提醒,如果有就弹窗提示
119+
*/
120+
private void checkAppTips() {
121+
WorkApiFactory workApiFactory = WorkApiFactory.getInstance();
122+
workApiFactory.getAppTips(new Observer<AppTips>() {
123+
@Override
124+
public void onSubscribe(Disposable d) {
125+
}
126+
@Override
127+
public void onNext(AppTips tips) {
128+
long version = FileUtils.getTipsNeverShowAgainVersion(MainActivity.this,tips);
129+
if(tips.getVersion() <= version){ //如果 网络返回的版本 <= 点击 不再提示的版本,则说明同版本或者服务器返回了更老的版本,则不显示tips
130+
return;
131+
}
132+
//没点过 不再提示 则version为-1,也不符合上面的if,一样要显示tips
133+
//如果是开启状态且在时间段内则显示
134+
String cur = TimeUtils.getCurrentDateString();
135+
if( tips.isEnable() && TimeUtils.compareDateString(cur,tips.getStartTime()) >= 0
136+
&& TimeUtils.compareDateString(cur,tips.getEndTime()) <= 0 ){
137+
showTipsDialog(tips);
138+
}
139+
}
140+
@Override
141+
public void onError(Throwable e) {
142+
}
143+
@Override
144+
public void onComplete() {
145+
}
146+
});
147+
}
148+
149+
/**
150+
* 显示每日提醒框,如果有超链接就提供跳转按钮
151+
*/
152+
private void showTipsDialog(final AppTips tips){
153+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
154+
builder.setMessage(tips.getMessage());
155+
builder.setTitle(tips.getTitle());
156+
157+
if(!TextUtils.isEmpty(tips.getOpenUrl())){
158+
String negative = "前往";
159+
final String url = tips.getOpenUrl();
160+
builder.setNegativeButton(negative,new DialogInterface.OnClickListener(){
161+
@Override
162+
public void onClick(DialogInterface dialogInterface, int i) {
163+
Uri uri = Uri.parse(url);
164+
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
165+
startActivity(intent);
166+
}
167+
});
168+
}
169+
170+
builder.setNeutralButton("不再提示",new DialogInterface.OnClickListener(){
171+
@Override
172+
public void onClick(DialogInterface dialogInterface, int which) {
173+
FileUtils.setTipsNeverShowAgain(MainActivity.this,tips);
174+
}
175+
});
176+
builder.setPositiveButton("确定",new DialogInterface.OnClickListener(){
177+
@Override
178+
public void onClick(DialogInterface dialogInterface, int which) {
179+
}
180+
});
181+
AlertDialog alert = builder.create();
182+
alert.show();
183+
}
122184
}

app/src/main/java/com/guang/app/adapter/BookAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.guang.app.R;
66
import com.guang.app.activity.BookActivity;
77
import com.guang.app.model.Book;
8-
import com.guang.app.util.CalcUtils;
8+
import com.guang.app.util.TimeUtils;
99

1010
/**
1111
* 当前借阅、历史借阅
@@ -31,7 +31,7 @@ protected void convert(final BaseViewHolder viewHolder, Book item) {
3131
;
3232
//当前借阅的情况下考虑显示续借按钮和过期书籍的红色字体显示
3333
if(doWhat == BookActivity.doCurrentBook){
34-
if(curTime > CalcUtils.timeString2TimeStamp(item.getReturnTime()) ){ //过期书籍
34+
if(curTime > TimeUtils.timeString2TimeStamp(item.getReturnTime()) ){ //过期书籍
3535
viewHolder.setTextColor(R.id.tv_book_returnTime, mContext.getResources().getColor(R.color.goal_item_failed_color));
3636
}else{
3737
viewHolder.setVisible(R.id.tv_book_renew,item.getRenewTimes() == 0); //当前借阅且是未到期情况下 续借按钮可见

app/src/main/java/com/guang/app/api/WorkApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.guang.app.api;
22

33
import com.guang.app.AppConfig;
4+
import com.guang.app.model.AppTips;
45
import com.guang.app.model.HttpResult;
56
import com.guang.app.model.StrObjectResponse;
67

@@ -22,5 +23,9 @@ public interface WorkApi {
2223
@GET(AppConfig.Avatar_URL)
2324
Observable<ResponseBody> getAvatarIcon(@Query("char") String nickname, @Query("size") int size, @Query("cache") int cache);
2425

26+
//获取每日提醒
27+
@GET(AppConfig.Url.appTips)
28+
Observable<HttpResult<AppTips>> getAppTips();
29+
2530

2631
}

app/src/main/java/com/guang/app/api/WorkApiFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.guang.app.api;
22

33
import com.guang.app.AppConfig;
4+
import com.guang.app.model.AppTips;
45
import com.guang.app.model.StrObjectResponse;
56

67
import io.reactivex.Observer;
@@ -47,4 +48,13 @@ public void getAvatarIcon(String nickname,Observer<ResponseBody> sub ) {
4748
.subscribeOn(Schedulers.io())
4849
.subscribe(sub);
4950
}
51+
52+
public void getAppTips(Observer<AppTips> sub ) {
53+
ApiUtils.getApi(AppConfig.idsPwd).create(WorkApi.class).getAppTips()
54+
.map(new HttpResultFunc<AppTips>())
55+
.observeOn(AndroidSchedulers.mainThread())
56+
.subscribeOn(Schedulers.io())
57+
.subscribe(sub);
58+
}
59+
5060
}

app/src/main/java/com/guang/app/fragment/HomeFragment.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
4747
View view = inflater.inflate(R.layout.fragment_schedule, container, false);
4848
ButterKnife.bind(this, view);
4949
getActivity().setTitle("APP");
50-
// TODO 删
51-
realQuerySchedule("2014-2015-1");
5250

5351
List<Schedule> list = DataSupport.findAll(Schedule.class);
5452
if(list.size() == 0) {

app/src/main/java/com/guang/app/fragment/MeFragment.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.guang.app.model.CardBasic;
3131
import com.guang.app.model.Schedule;
3232
import com.guang.app.util.FileUtils;
33+
import com.guang.app.util.TimeUtils;
3334
import com.guang.app.util.drcom.DrcomFileUtils;
3435
import com.umeng.analytics.MobclickAgent;
3536

@@ -163,6 +164,22 @@ public void onComplete() {
163164
}
164165
});
165166
}
167+
168+
//如果是公历生日那天打开,会弹窗表示生日祝福
169+
if( !TextUtils.isEmpty(value.getBirthday())
170+
&& value.getBirthday().length() == 8
171+
&& value.getBirthday().substring(4, 8) .equals( TimeUtils.getDateStringWithFormat("MMdd"))){
172+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
173+
builder.setMessage( " 生日快乐 (๑•̀ㅂ•́)و✧");
174+
builder.setTitle(value.getName());
175+
builder.setPositiveButton("哈哈",new DialogInterface.OnClickListener(){
176+
@Override
177+
public void onClick(DialogInterface dialogInterface, int which) {
178+
}
179+
});
180+
builder.create().show();;
181+
}
182+
166183
}
167184

168185
@OnClick(R.id.layout_me_cashhistory) void showConsumeToday(){
@@ -239,7 +256,6 @@ public void onClick(DialogInterface dialogInterface, int i) {
239256
}
240257
});
241258
builder.create().show();
242-
243259
}
244260

245261

0 commit comments

Comments
 (0)