Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YGOMobile
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fallenstardust
YGOMobile
Commits
9584fd46
Commit
9584fd46
authored
Sep 26, 2023
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
判断字符串包含才进行substring操作
parent
d2975e48
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
75 deletions
+94
-75
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
...c/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
+56
-54
mobile/src/main/java/cn/garymb/ygomobile/ui/settings/SettingFragment.java
...java/cn/garymb/ygomobile/ui/settings/SettingFragment.java
+24
-21
mobile/src/main/java/cn/garymb/ygomobile/utils/OkhttpUtil.java
...e/src/main/java/cn/garymb/ygomobile/utils/OkhttpUtil.java
+14
-0
No files found.
mobile/src/main/java/cn/garymb/ygomobile/ui/home/HomeActivity.java
View file @
9584fd46
...
...
@@ -2,7 +2,6 @@ package cn.garymb.ygomobile.ui.home;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_HOME_VERSION
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_HOME_VERSION_ALT
;
import
static
cn
.
garymb
.
ygomobile
.
Constants
.
URL_YGO233_FILE_ALT
;
import
android.annotation.SuppressLint
;
import
android.content.Intent
;
...
...
@@ -60,16 +59,20 @@ import okhttp3.Response;
public
abstract
class
HomeActivity
extends
BaseActivity
implements
BottomNavigationBar
.
OnTabSelectedListener
{
long
exitLasttime
=
0
;
private
static
final
int
TYPE_GET_VERSION_OK
=
0
;
private
static
final
int
TYPE_GET_VERSION_FAILED
=
1
;
public
static
String
Version
;
public
static
String
Cache_link
;
public
static
String
Cache_pre_release_code
;
public
static
List
<
Integer
>
pre_code_list
=
new
ArrayList
<>();
public
static
List
<
Integer
>
released_code_list
=
new
ArrayList
<>();
private
static
final
int
TYPE_GET_VERSION_OK
=
0
;
private
static
final
int
TYPE_GET_VERSION_FAILED
=
1
;
public
HomeFragment
fragment_home
;
public
CardSearchFragment
fragment_search
;
public
DeckManagerFragment
fragment_deck_cards
;
public
MycardFragment
fragment_mycard
;
public
SettingFragment
fragment_settings
;
public
MycardChatFragment
fragment_mycard_chatting_room
;
long
exitLasttime
=
0
;
private
CardLoader
cardLoader
;
private
ImageLoader
imageLoader
;
private
BottomNavigationBar
bottomNavigationBar
;
...
...
@@ -77,55 +80,9 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
private
TextBadgeItem
mTextBadgeItem
;
private
FrameLayout
frameLayout
;
private
Fragment
mFragment
;
public
HomeFragment
fragment_home
;
public
CardSearchFragment
fragment_search
;
public
DeckManagerFragment
fragment_deck_cards
;
public
MycardFragment
fragment_mycard
;
public
SettingFragment
fragment_settings
;
public
MycardChatFragment
fragment_mycard_chatting_room
;
private
Bundle
mBundle
;
private
int
FailedCount
;
@SuppressLint
(
"HandlerLeak"
)
Handler
handlerHome
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
super
.
handleMessage
(
msg
);
switch
(
msg
.
what
)
{
case
TYPE_GET_VERSION_OK:
Version
=
msg
.
obj
.
toString
().
substring
(
0
,
msg
.
obj
.
toString
().
indexOf
(
"|"
));
//截取版本号
Cache_link
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"|"
)
+
1
,
msg
.
obj
.
toString
().
indexOf
(
"\n"
));
//截取下载地址
Cache_pre_release_code
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"\n"
)
+
1
);
//截取先行-正式对照文本
if
(!
TextUtils
.
isEmpty
(
Cache_pre_release_code
))
{
arrangeCodeList
(
Cache_pre_release_code
);
//转换成两个数组
}
if
(!
Version
.
equals
(
BuildConfig
.
VERSION_NAME
)
&&
!
Version
.
isEmpty
()
&&
!
Cache_link
.
isEmpty
())
{
DialogPlus
dialog
=
new
DialogPlus
(
getActivity
());
dialog
.
setMessage
(
R
.
string
.
Found_Update
);
dialog
.
setLeftButtonText
(
R
.
string
.
download_home
);
dialog
.
setLeftButtonListener
((
dlg
,
s
)
->
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
intent
.
setData
(
Uri
.
parse
(
Cache_link
));
startActivity
(
intent
);
dialog
.
dismiss
();
});
dialog
.
show
();
}
break
;
case
TYPE_GET_VERSION_FAILED:
++
FailedCount
;
if
(
FailedCount
<=
2
)
{
Toast
.
makeText
(
getActivity
(),
R
.
string
.
Ask_to_Change_Other_Way
,
Toast
.
LENGTH_SHORT
).
show
();
checkUpgrade
(
URL_HOME_VERSION_ALT
);
}
String
error
=
msg
.
obj
.
toString
();
break
;
}
}
};
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
if
(
savedInstanceState
!=
null
)
{
...
...
@@ -203,7 +160,49 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
mFragment
=
fragment_home
;
getSupportFragmentManager
().
beginTransaction
().
add
(
R
.
id
.
fragment_content
,
fragment_home
).
commit
();
getSupportActionBar
().
hide
();
}
}
@SuppressLint
(
"HandlerLeak"
)
Handler
handlerHome
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
super
.
handleMessage
(
msg
);
switch
(
msg
.
what
)
{
case
TYPE_GET_VERSION_OK:
if
(
msg
.
obj
.
toString
().
contains
(
"|"
)
&&
msg
.
obj
.
toString
().
contains
(
"\n"
))
{
Version
=
msg
.
obj
.
toString
().
substring
(
0
,
msg
.
obj
.
toString
().
indexOf
(
"|"
));
//截取版本号
Cache_link
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"|"
)
+
1
,
msg
.
obj
.
toString
().
indexOf
(
"\n"
));
//截取下载地址
Cache_pre_release_code
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"\n"
)
+
1
);
//截取先行-正式对照文本
if
(!
TextUtils
.
isEmpty
(
Cache_pre_release_code
))
{
arrangeCodeList
(
Cache_pre_release_code
);
//转换成两个数组
}
if
(!
Version
.
equals
(
BuildConfig
.
VERSION_NAME
)
&&
!
TextUtils
.
isEmpty
(
Version
)
&&
!
TextUtils
.
isEmpty
(
Cache_link
))
{
DialogPlus
dialog
=
new
DialogPlus
(
getActivity
());
dialog
.
setMessage
(
R
.
string
.
Found_Update
);
dialog
.
setLeftButtonText
(
R
.
string
.
download_home
);
dialog
.
setLeftButtonListener
((
dlg
,
s
)
->
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
intent
.
setData
(
Uri
.
parse
(
Cache_link
));
startActivity
(
intent
);
dialog
.
dismiss
();
});
dialog
.
show
();
}
}
else
{
Toast
.
makeText
(
getContext
(),
getString
(
R
.
string
.
Checking_Update_Failed
)
+
msg
.
obj
.
toString
(),
Toast
.
LENGTH_SHORT
).
show
();
}
break
;
case
TYPE_GET_VERSION_FAILED:
++
FailedCount
;
if
(
FailedCount
<=
2
)
{
Toast
.
makeText
(
getActivity
(),
R
.
string
.
Ask_to_Change_Other_Way
,
Toast
.
LENGTH_SHORT
).
show
();
checkUpgrade
(
URL_HOME_VERSION_ALT
);
}
else
{
Toast
.
makeText
(
getContext
(),
getString
(
R
.
string
.
Checking_Update_Failed
)
+
msg
.
obj
.
toString
(),
Toast
.
LENGTH_SHORT
).
show
();
}
break
;
}
}
};
private
void
showNewsCounts
()
{
mTextBadgeItem
=
new
TextBadgeItem
()
...
...
@@ -316,7 +315,6 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
}
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
...
...
@@ -439,4 +437,8 @@ public abstract class HomeActivity extends BaseActivity implements BottomNavigat
}
}
}
mobile/src/main/java/cn/garymb/ygomobile/ui/settings/SettingFragment.java
View file @
9584fd46
...
...
@@ -89,6 +89,7 @@ import cn.garymb.ygomobile.ui.plus.DialogPlus;
import
cn.garymb.ygomobile.ui.plus.VUiKit
;
import
cn.garymb.ygomobile.utils.FileUtils
;
import
cn.garymb.ygomobile.utils.IOUtils
;
import
cn.garymb.ygomobile.utils.LogUtil
;
import
cn.garymb.ygomobile.utils.OkhttpUtil
;
import
cn.garymb.ygomobile.utils.ServerUtil
;
import
cn.garymb.ygomobile.utils.SharedPreferenceUtil
;
...
...
@@ -167,36 +168,38 @@ public class SettingFragment extends PreferenceFragmentPlus {
super
.
handleMessage
(
msg
);
switch
(
msg
.
what
)
{
case
TYPE_SETTING_GET_VERSION_OK:
Version
=
msg
.
obj
.
toString
().
substring
(
0
,
msg
.
obj
.
toString
().
indexOf
(
"|"
));
//截取版本号
Cache_link
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"|"
)
+
1
);
Cache_link
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"|"
)
+
1
,
msg
.
obj
.
toString
().
indexOf
(
"\n"
));
//截取下载地址
Cache_pre_release_code
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"\n"
)
+
1
);
//截取先行-正式对照文本
if
(!
Cache_pre_release_code
.
isEmpty
())
{
arrangeCodeList
(
Cache_pre_release_code
);
//转换成两个数组
}
if
(!
Version
.
equals
(
BuildConfig
.
VERSION_NAME
)
&&
!
Version
.
isEmpty
()
&&
!
Cache_link
.
isEmpty
())
{
DialogPlus
dialog
=
new
DialogPlus
(
getActivity
());
dialog
.
setMessage
(
R
.
string
.
Found_Update
);
dialog
.
setLeftButtonText
(
R
.
string
.
download_home
);
dialog
.
setLeftButtonListener
((
dlg
,
s
)
->
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
intent
.
setData
(
Uri
.
parse
(
Cache_link
));
startActivity
(
intent
);
dialog
.
dismiss
();
});
dialog
.
show
();
if
(
msg
.
obj
.
toString
().
contains
(
"|"
)
&&
msg
.
obj
.
toString
().
contains
(
"\n"
))
{
Version
=
msg
.
obj
.
toString
().
substring
(
0
,
msg
.
obj
.
toString
().
indexOf
(
"|"
));
//截取版本号
Cache_link
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"|"
)
+
1
,
msg
.
obj
.
toString
().
indexOf
(
"\n"
));
//截取下载地址
Cache_pre_release_code
=
msg
.
obj
.
toString
().
substring
(
msg
.
obj
.
toString
().
indexOf
(
"\n"
)
+
1
);
//截取先行-正式对照文本
if
(!
TextUtils
.
isEmpty
(
Cache_pre_release_code
))
{
arrangeCodeList
(
Cache_pre_release_code
);
//转换成两个数组
}
if
(!
Version
.
equals
(
BuildConfig
.
VERSION_NAME
)
&&
!
TextUtils
.
isEmpty
(
Version
)
&&
!
TextUtils
.
isEmpty
(
Cache_link
))
{
DialogPlus
dialog
=
new
DialogPlus
(
getActivity
());
dialog
.
setMessage
(
R
.
string
.
Found_Update
);
dialog
.
setLeftButtonText
(
R
.
string
.
download_home
);
dialog
.
setLeftButtonListener
((
dlg
,
s
)
->
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
);
intent
.
setData
(
Uri
.
parse
(
Cache_link
));
startActivity
(
intent
);
dialog
.
dismiss
();
});
dialog
.
show
();
}
else
{
Toast
.
makeText
(
getContext
(),
R
.
string
.
Already_Lastest
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
else
{
Toast
.
makeText
(
getContext
(),
R
.
string
.
Already_Lastest
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getContext
(),
getString
(
R
.
string
.
Checking_Update_Failed
)
+
msg
.
obj
.
toString
()
,
Toast
.
LENGTH_SHORT
).
show
();
}
break
;
case
TYPE_SETTING_GET_VERSION_FAILED:
String
error
=
msg
.
obj
.
toString
();
++
FailedCount
;
if
(
FailedCount
<=
2
)
{
Toast
.
makeText
(
getActivity
(),
R
.
string
.
Ask_to_Change_Other_Way
,
Toast
.
LENGTH_SHORT
).
show
();
checkUpgrade
(
URL_YGO233_FILE_ALT
);
}
else
{
Toast
.
makeText
(
getContext
(),
getString
(
R
.
string
.
Checking_Update_Failed
)
+
error
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getContext
(),
getString
(
R
.
string
.
Checking_Update_Failed
)
+
msg
.
obj
.
toString
()
,
Toast
.
LENGTH_SHORT
).
show
();
}
break
;
}
...
...
mobile/src/main/java/cn/garymb/ygomobile/utils/OkhttpUtil.java
View file @
9584fd46
...
...
@@ -296,5 +296,19 @@ public class OkhttpUtil {
okHttpClient
.
newCall
(
request
.
build
()).
enqueue
(
callback
);
}
public
static
String
parseByte2HexStr
(
byte
[]
buf
)
{
if
(
null
==
buf
)
{
return
null
;
}
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
buf
.
length
;
i
++)
{
String
hex
=
Integer
.
toHexString
(
buf
[
i
]
&
0xFF
);
if
(
hex
.
length
()
==
1
)
{
hex
=
'0'
+
hex
;
}
sb
.
append
(
hex
.
toUpperCase
());
}
return
sb
.
toString
();
}
}
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