Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RvApp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lify
RvApp
Commits
84d52d68
Commit
84d52d68
authored
Oct 29, 2019
by
linfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
租车时间按24小时计算
parent
a82c93e8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
43 deletions
+136
-43
DateUtils.java
...utils/src/main/java/com/rv/component/utils/DateUtils.java
+57
-14
HomeFragment.java
...java/com/rv/home/rv/module/ui/main/home/HomeFragment.java
+59
-10
CalendarActivity.java
...rc/main/java/com/rv/plugin/calendar/CalendarActivity.java
+17
-16
activity_calendar2.xml
plugin_calendar/src/main/res/layout/activity_calendar2.xml
+3
-3
No files found.
component_utils/src/main/java/com/rv/component/utils/DateUtils.java
View file @
84d52d68
...
@@ -228,9 +228,9 @@ public class DateUtils {
...
@@ -228,9 +228,9 @@ public class DateUtils {
* @return 失败返回-1 ,所以尽量是datetime1大于datetime2
* @return 失败返回-1 ,所以尽量是datetime1大于datetime2
*/
*/
public
static
long
compareDateSecond2
(
String
datetime1
,
String
datetime2
)
{
public
static
long
compareDateSecond2
(
String
datetime1
,
String
datetime2
)
{
String
date1
=
formatDate7
(
datetime1
);
String
date1
=
formatDate7
(
datetime1
);
String
date2
=
formatDate7
(
datetime2
);
String
date2
=
formatDate7
(
datetime2
);
return
compareDateSecond
(
date1
,
date2
);
return
compareDateSecond
(
date1
,
date2
);
}
}
/**
/**
...
@@ -251,6 +251,24 @@ public class DateUtils {
...
@@ -251,6 +251,24 @@ public class DateUtils {
}
}
}
}
/**
* 比较两个时间相差多少秒 datetime1-datetime2
*
* @param datetime1 yyyy-MM-dd HH:mm
* @param datetime2 yyyy-MM-dd HH:mm
* @return 失败返回-1 ,所以尽量是datetime1大于datetime2
*/
public
static
long
compareDateSecond3
(
String
datetime1
,
String
datetime2
)
{
try
{
Date
date1
=
sdf7
.
parse
(
datetime1
);
Date
date2
=
sdf7
.
parse
(
datetime2
);
return
compareDateSecond
(
date1
.
getTime
(),
date2
.
getTime
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
-
1
;
}
}
/**
/**
* 比较两个时间相差多少秒 datetime1-datetime2
* 比较两个时间相差多少秒 datetime1-datetime2
*
*
...
@@ -417,6 +435,7 @@ public class DateUtils {
...
@@ -417,6 +435,7 @@ public class DateUtils {
/**
/**
* yyyy-MM 转化成 yyyy年MM月
* yyyy-MM 转化成 yyyy年MM月
*
* @param dateStr yyyy-MM
* @param dateStr yyyy-MM
* @return yyyy年MM月
* @return yyyy年MM月
*/
*/
...
@@ -554,6 +573,31 @@ public class DateUtils {
...
@@ -554,6 +573,31 @@ public class DateUtils {
return
day
;
return
day
;
}
}
/**
* 给时间加上几个小时
*
* @param dateStr 当前时间 格式:yyyy-MM-dd HH:mm
* @param hour 需要加的时间
* @return
*/
public
static
String
formatDate28
(
String
dateStr
,
int
hour
)
{
Date
date
=
null
;
try
{
date
=
sdf7
.
parse
(
dateStr
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
if
(
date
==
null
)
return
""
;
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
cal
.
add
(
Calendar
.
HOUR
,
hour
);
// 24小时制
date
=
cal
.
getTime
();
cal
=
null
;
return
sdf7
.
format
(
date
);
}
/**
/**
* 将yyyy-MM-dd HH:mm格式成yy-MM-dd HH:mm
* 将yyyy-MM-dd HH:mm格式成yy-MM-dd HH:mm
...
@@ -580,7 +624,7 @@ public class DateUtils {
...
@@ -580,7 +624,7 @@ public class DateUtils {
String
day
=
""
;
String
day
=
""
;
try
{
try
{
long
time
=
sdf12
.
parse
(
dateStr
).
getTime
();
long
time
=
sdf12
.
parse
(
dateStr
).
getTime
();
time
+=
30
*
60
*
1000
;
time
+=
30
*
60
*
1000
;
Date
da
=
new
Date
(
time
);
Date
da
=
new
Date
(
time
);
day
=
sdf12
.
format
(
da
);
day
=
sdf12
.
format
(
da
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -596,7 +640,7 @@ public class DateUtils {
...
@@ -596,7 +640,7 @@ public class DateUtils {
String
day
=
""
;
String
day
=
""
;
try
{
try
{
long
time
=
sdf12
.
parse
(
dateStr
).
getTime
();
long
time
=
sdf12
.
parse
(
dateStr
).
getTime
();
time
-=
30
*
60
*
1000
;
time
-=
30
*
60
*
1000
;
Date
da
=
new
Date
(
time
);
Date
da
=
new
Date
(
time
);
day
=
sdf12
.
format
(
da
);
day
=
sdf12
.
format
(
da
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -606,12 +650,11 @@ public class DateUtils {
...
@@ -606,12 +650,11 @@ public class DateUtils {
}
}
/**
/**
* 把时分转成毫秒
* 把时分转成毫秒
*/
*/
public
static
long
formatDate20
(
String
dateStr
)
{
public
static
long
formatDate20
(
String
dateStr
)
{
long
time
=
0
;
long
time
=
0
;
try
{
try
{
time
=
sdf12
.
parse
(
dateStr
).
getTime
();
time
=
sdf12
.
parse
(
dateStr
).
getTime
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -793,7 +836,6 @@ public class DateUtils {
...
@@ -793,7 +836,6 @@ public class DateUtils {
}
}
/**
/**
* 获取网络时间
* 获取网络时间
*
*
...
@@ -821,13 +863,14 @@ public class DateUtils {
...
@@ -821,13 +863,14 @@ public class DateUtils {
/**
/**
* 获取手机当前时间yyMMddHHmmss
* 获取手机当前时间yyMMddHHmmss
*
* @return
* @return
*/
*/
public
static
String
getPhoneCurTime
(){
public
static
String
getPhoneCurTime
()
{
String
timeStr
=
""
;
String
timeStr
=
""
;
try
{
try
{
Date
date
=
new
Date
(
System
.
currentTimeMillis
());
Date
date
=
new
Date
(
System
.
currentTimeMillis
());
timeStr
=
sdf3
.
format
(
date
);
timeStr
=
sdf3
.
format
(
date
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
module_home/src/main/java/com/rv/home/rv/module/ui/main/home/HomeFragment.java
View file @
84d52d68
...
@@ -45,6 +45,7 @@ import com.ruiwenliu.wrapper.util.UtilsManager;
...
@@ -45,6 +45,7 @@ import com.ruiwenliu.wrapper.util.UtilsManager;
import
com.ruiwenliu.wrapper.util.glide.GlideManager
;
import
com.ruiwenliu.wrapper.util.glide.GlideManager
;
import
com.ruiwenliu.wrapper.util.listener.SwitchFragment
;
import
com.ruiwenliu.wrapper.util.listener.SwitchFragment
;
import
com.ruiwenliu.wrapper.util.permission.RxPermission
;
import
com.ruiwenliu.wrapper.util.permission.RxPermission
;
import
com.ruiwenliu.wrapper.weight.refresh.IFooterWrapper
;
import
com.ruiwenliu.wrapper.weight.refresh.SimpleRefreshLayout
;
import
com.ruiwenliu.wrapper.weight.refresh.SimpleRefreshLayout
;
import
com.ruiwenliu.wrapper.weight.refresh.SimpleRefreshView
;
import
com.ruiwenliu.wrapper.weight.refresh.SimpleRefreshView
;
import
com.rv.component.utils.DateUtils
;
import
com.rv.component.utils.DateUtils
;
...
@@ -255,19 +256,12 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
...
@@ -255,19 +256,12 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
mSimpleRefreshLayout
.
setOnSimpleRefreshListener
(
this
);
mSimpleRefreshLayout
.
setOnSimpleRefreshListener
(
this
);
permissionProcess
();
permissionProcess
();
setBanner
();
setBanner
();
tvDay
.
setText
(
String
.
format
(
"%1$s%2$s"
,
copyDay
,
getContext
().
getString
(
R
.
string
.
rv_days
)));
Drawable
drawable
=
getResources
().
getDrawable
(
R
.
drawable
.
icon_day_times
);
Drawable
drawable
=
getResources
().
getDrawable
(
R
.
drawable
.
icon_day_times
);
drawable
.
setBounds
(
0
,
0
,
DisplayUtil
.
dip2px
(
getContext
(),
25
),
DisplayUtil
.
dip2px
(
getContext
(),
5
));
drawable
.
setBounds
(
0
,
0
,
DisplayUtil
.
dip2px
(
getContext
(),
25
),
DisplayUtil
.
dip2px
(
getContext
(),
5
));
tvDay
.
setCompoundDrawables
(
null
,
null
,
null
,
drawable
);
tvDay
.
setCompoundDrawables
(
null
,
null
,
null
,
drawable
);
begDate
=
MyUtils
.
getFetureDate
(
1
)
+
" 09:00"
;
tvGetTime
.
setText
(
DateUtils
.
formatDate66
(
begDate
));
tvGetWeek
.
setText
(
"周"
+
MyUtils
.
getWeek
(
DateUtils
.
getCurDate
()));
endDate
=
MyUtils
.
getFetureDate
(
2
)
+
" 18:00"
;
tvOutTime
.
setText
(
DateUtils
.
formatDate66
(
endDate
));
tvOutWeek
.
setText
(
"周"
+
MyUtils
.
getWeek
(
MyUtils
.
getFetureDate
(
2
)));
copyDay
=
DateUtils
.
compareDateDay
(
MyUtils
.
getFetureDate
(
1
),
DateUtils
.
getCurDate
())
+
1
;
setDefaultTime
();
llItemHotRvtour
.
setSelected
(
true
);
llItemHotRvtour
.
setSelected
(
true
);
tvItemRvTour
.
setSelected
(
true
);
tvItemRvTour
.
setSelected
(
true
);
hotType
=
"2"
;
hotType
=
"2"
;
...
@@ -436,6 +430,38 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
...
@@ -436,6 +430,38 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
});
});
}
}
/**
* 设置默认时间
*/
private
void
setDefaultTime
()
{
String
time
=
DateUtils
.
formatDate28
(
DateUtils
.
timestampToString1
(
DateUtils
.
getCurTimeMillis
()),
2
);
String
hh
=
DateUtils
.
formatDate21
(
time
);
String
mm
=
DateUtils
.
formatDate22
(
time
);
String
begTime
=
""
;
if
(
Double
.
valueOf
(
mm
)
>
30
)
{
//判断当前分钟是否已经超过30,如果超过了取整加30分钟
begTime
=
DateUtils
.
formatDate19
(
hh
+
":30"
);
}
else
{
begTime
=
hh
+
":30"
;
}
if
(
DateUtils
.
formatDate20
(
begTime
)
>
DateUtils
.
formatDate20
(
"19:30"
))
{
//如果当前时间大于 19:30,日期往后加一,时间改成早上8:00
begDate
=
MyUtils
.
getFetureDate
(
1
)
+
" "
+
"08:00"
;
endDate
=
MyUtils
.
getFetureDate
(
3
)
+
" "
+
"08:00"
;
}
else
{
begDate
=
MyUtils
.
getFetureDate
(
0
)
+
" "
+
begTime
;
endDate
=
MyUtils
.
getFetureDate
(
2
)
+
" "
+
begTime
;
}
tvGetTime
.
setText
(
DateUtils
.
formatDate66
(
begDate
));
tvGetWeek
.
setText
(
"周"
+
MyUtils
.
getWeek
(
DateUtils
.
formatDate16
(
begDate
)));
tvOutTime
.
setText
(
DateUtils
.
formatDate66
(
endDate
));
tvOutWeek
.
setText
(
"周"
+
MyUtils
.
getWeek
(
DateUtils
.
formatDate16
(
endDate
)));
copyDay
=
getCountDay
(
begDate
,
endDate
);
tvDay
.
setText
(
String
.
format
(
"%1$s%2$s"
,
copyDay
,
getContext
().
getString
(
R
.
string
.
rv_days
)));
}
@Override
@Override
public
void
onRefresh
()
{
public
void
onRefresh
()
{
...
@@ -961,7 +987,10 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
...
@@ -961,7 +987,10 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
}
else
if
(
resultCode
==
200
&&
requestCode
==
108
)
{
}
else
if
(
resultCode
==
200
&&
requestCode
==
108
)
{
begDate
=
data
.
getStringExtra
(
"begDate"
);
begDate
=
data
.
getStringExtra
(
"begDate"
);
endDate
=
data
.
getStringExtra
(
"endDate"
);
endDate
=
data
.
getStringExtra
(
"endDate"
);
copyDay
=
DateUtils
.
compareDateDay
(
endDate
,
begDate
)
+
1
;
copyDay
=
getCountDay
(
begDate
,
endDate
);
//天数
// copyDay = DateUtils.compareDateDay(endDate, begDate) + 1;
if
(
tvGetTime
!=
null
)
{
if
(
tvGetTime
!=
null
)
{
tvGetTime
.
setText
(
DateUtils
.
formatDate66
(
begDate
));
tvGetTime
.
setText
(
DateUtils
.
formatDate66
(
begDate
));
}
}
...
@@ -980,6 +1009,26 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
...
@@ -980,6 +1009,26 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements Observa
}
}
}
}
/**
* 计算天数
*
* @param endDate2
* @param begDate2
* @return
*/
private
long
getCountDay
(
String
begDate2
,
String
endDate2
)
{
long
second
=
DateUtils
.
compareDateSecond3
(
endDate2
,
begDate2
);
//两个时间相差的秒数
long
day
=
(
long
)
second
/
86400
;
//天数
long
remainder
=
(
long
)
second
%
86400
;
//余数 秒
if
(
day
==
0
)
{
//不够24小时也算一天
day
=
day
+
1
;
}
else
if
(
remainder
>
14400
)
{
//4小时内天数不增加,否则加一
day
=
day
+
1
;
}
return
day
;
}
/**
/**
* 设置返回结果参数
* 设置返回结果参数
...
...
plugin_calendar/src/main/java/com/rv/plugin/calendar/CalendarActivity.java
View file @
84d52d68
...
@@ -140,10 +140,16 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
...
@@ -140,10 +140,16 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
wheelViewLeft
.
setOnWheelViewListener
(
new
WheelView
.
OnWheelViewListener
()
{
wheelViewLeft
.
setOnWheelViewListener
(
new
WheelView
.
OnWheelViewListener
()
{
@Override
@Override
public
void
onSelected
(
int
selectedIndex
,
String
item
)
{
public
void
onSelected
(
int
selectedIndex
,
String
item
)
{
String
s
=
DateUtils
.
formatDate17
(
DateUtils
.
formatDate8
(
DateUtils
.
getCurDateTime
()));
if
(
s_begDate
.
equals
(
DateUtils
.
getCurDate
())
&&
DateUtils
.
formatDate20
(
item
)
<
DateUtils
.
formatDate20
(
s
))
{
wheelViewLeft
.
setSeletion
(
begSelected
);
tvGetTime
.
setText
(
s_begTime
);
}
else
{
begSelected
=
selectedIndex
;
begSelected
=
selectedIndex
;
s_begTime
=
item
;
s_begTime
=
item
;
tvGetTime
.
setText
(
item
);
tvGetTime
.
setText
(
item
);
}
}
}
});
});
wheelViewRight
.
setOffset
(
1
);
// 对话框中当前项上面和下面的项数
wheelViewRight
.
setOffset
(
1
);
// 对话框中当前项上面和下面的项数
...
@@ -171,20 +177,12 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
...
@@ -171,20 +177,12 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
begSelected
=
i
;
begSelected
=
i
;
wheelViewLeft
.
setSeletion
(
i
);
wheelViewLeft
.
setSeletion
(
i
);
s_begTime
=
begTime
;
s_begTime
=
begTime
;
}
else
if
(
timeList
.
get
(
i
).
equals
(
"08:00"
))
{
begSelected
=
i
;
wheelViewLeft
.
setSeletion
(
i
);
s_begTime
=
"08:00"
;
}
}
if
(
timeList
.
get
(
i
).
equals
(
endTime
))
{
if
(
timeList
.
get
(
i
).
equals
(
endTime
))
{
endSelected
=
i
;
endSelected
=
i
;
wheelViewRight
.
setSeletion
(
i
);
wheelViewRight
.
setSeletion
(
i
);
s_endTime
=
endTime
;
s_endTime
=
endTime
;
}
else
if
(
timeList
.
get
(
i
).
equals
(
"18:00"
))
{
endSelected
=
i
;
wheelViewRight
.
setSeletion
(
i
);
s_endTime
=
"18:00"
;
}
}
}
}
}
}
...
@@ -211,6 +209,11 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
...
@@ -211,6 +209,11 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
showToast
(
"还车时刻要大于取车时刻!"
);
showToast
(
"还车时刻要大于取车时刻!"
);
return
;
return
;
}
}
String
s
=
DateUtils
.
formatDate17
(
DateUtils
.
formatDate8
(
DateUtils
.
getCurDateTime
()));
if
(
s_begDate
.
equals
(
DateUtils
.
getCurDate
())
&&
DateUtils
.
formatDate20
(
s_begTime
)
<
DateUtils
.
formatDate20
(
s
))
{
showToast
(
"取车时刻要大于现在时刻!"
);
return
;
}
Intent
intent
=
new
Intent
();
Intent
intent
=
new
Intent
();
intent
.
putExtra
(
"begDate"
,
s_begDate
+
" "
+
s_begTime
);
intent
.
putExtra
(
"begDate"
,
s_begDate
+
" "
+
s_begTime
);
...
@@ -308,7 +311,7 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
...
@@ -308,7 +311,7 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
day
.
setCurDay
(
true
);
day
.
setCurDay
(
true
);
day
.
setDefTextColor
(
context
.
getResources
().
getColor
(
R
.
color
.
gray_FFB74B
));
day
.
setDefTextColor
(
context
.
getResources
().
getColor
(
R
.
color
.
gray_FFB74B
));
day
.
setDefNongTextColor
(
context
.
getResources
().
getColor
(
R
.
color
.
gray_FFB74B
));
day
.
setDefNongTextColor
(
context
.
getResources
().
getColor
(
R
.
color
.
gray_FFB74B
));
day
.
setCanBeChoose
(
fals
e
);
day
.
setCanBeChoose
(
tru
e
);
}
else
if
(
CalendarDateUtil
.
compareDateDay
(
CalendarDateUtil
.
getCurDate
(),
curDay
)
>
0
||
spanIndex
>=
MAX_SPAN
)
{
}
else
if
(
CalendarDateUtil
.
compareDateDay
(
CalendarDateUtil
.
getCurDate
(),
curDay
)
>
0
||
spanIndex
>=
MAX_SPAN
)
{
//如果是今天以前
//如果是今天以前
day
.
setDefTextColor
(
context
.
getResources
().
getColor
(
R
.
color
.
ri_lhui
));
day
.
setDefTextColor
(
context
.
getResources
().
getColor
(
R
.
color
.
ri_lhui
));
...
@@ -367,11 +370,9 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
...
@@ -367,11 +370,9 @@ public class CalendarActivity extends BaseStatusActivity<CalendarPresenter> {
* 初始化时间数据
* 初始化时间数据
*/
*/
private
void
initTime
()
{
private
void
initTime
()
{
for
(
int
i
=
9
;
i
<
22
;
i
++)
{
for
(
int
i
=
8
;
i
<
20
;
i
++)
{
timeList
.
add
(
String
.
format
(
"%02d"
,
i
)
+
":00"
);
timeList
.
add
(
String
.
format
(
"%02d"
,
i
)
+
":00"
);
if
(
i
<
21
)
{
timeList
.
add
(
String
.
format
(
"%02d"
,
i
)
+
":30"
);
timeList
.
add
(
String
.
format
(
"%02d"
,
i
)
+
":30"
);
}
}
}
}
}
}
}
plugin_calendar/src/main/res/layout/activity_calendar2.xml
View file @
84d52d68
...
@@ -107,9 +107,9 @@
...
@@ -107,9 +107,9 @@
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:
paddingBottom=
"@dimen/size_5
"
android:
orientation=
"horizontal
"
android:paddingTop=
"@dimen/size_5"
android:paddingTop=
"@dimen/size_5"
android:
orientation=
"horizontal"
>
android:
paddingBottom=
"@dimen/size_5"
>
<TextView
<TextView
android:layout_width=
"0dip"
android:layout_width=
"0dip"
...
@@ -201,7 +201,7 @@
...
@@ -201,7 +201,7 @@
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/size_2
2
0"
android:layout_height=
"@dimen/size_2
0
0"
android:background=
"@color/colorWrite"
android:background=
"@color/colorWrite"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
...
...
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