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
445e34ac
Commit
445e34ac
authored
Mar 29, 2019
by
fallenstardust
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix loadDeckFromFile
parent
63852a9c
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
240 additions
and
174 deletions
+240
-174
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
+67
-17
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl.java
...cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl.java
+151
-156
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater.java
.../java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater.java
+22
-1
No files found.
mobile/src/main/java/cn/garymb/ygomobile/GameUriManager.java
View file @
445e34ac
...
...
@@ -9,8 +9,7 @@ import android.util.Log;
import
android.widget.Toast
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.util.List
;
import
java.io.FileInputStream
;
import
cn.garymb.ygodata.YGOGameOptions
;
import
cn.garymb.ygomobile.bean.Deck
;
...
...
@@ -68,35 +67,86 @@ public class GameUriManager {
return
activity
;
}
private
String
getDeckName
(
Uri
uri
)
{
String
path
=
uri
.
getPath
();
Log
.
i
(
"kk"
,
"path="
+
path
);
if
(
path
!=
null
)
{
int
index
=
path
.
lastIndexOf
(
"/"
);
if
(
index
>
0
)
{
String
name
=
path
.
substring
(
index
+
1
);
index
=
name
.
lastIndexOf
(
"."
);
if
(
index
>
0
)
{
//1.ydk
name
=
name
.
substring
(
0
,
index
);
}
return
name
;
}
}
return
"tmp_"
+
System
.
currentTimeMillis
();
}
private
File
getDeckFile
(
File
dir
,
String
name
)
{
File
file
=
new
File
(
dir
,
name
+
".ydk"
);
if
(
file
.
exists
())
{
for
(
int
i
=
2
;
i
<
10
;
i
++)
{
file
=
new
File
(
dir
,
name
+
"("
+
i
+
").ydk"
);
if
(!
file
.
exists
())
{
return
file
;
}
}
return
new
File
(
dir
,
"tmp_"
+
System
.
currentTimeMillis
()
+
".ydk"
);
}
else
{
if
(!
dir
.
exists
())
{
dir
.
mkdirs
();
}
}
return
file
;
}
private
boolean
isDeckDir
(
File
file
)
{
if
(!
Constants
.
COPY_YDK_FILE
)
{
return
true
;
}
String
deck
=
new
File
(
AppsSettings
.
get
().
getDeckDir
()).
getAbsolutePath
();
return
TextUtils
.
equals
(
deck
,
file
.
getParentFile
().
getAbsolutePath
());
}
private
void
doUri
(
Uri
uri
)
{
if
(
"file"
.
equals
(
uri
.
getScheme
()))
{
File
file
=
new
File
(
uri
.
getPath
());
Intent
startdeck
=
new
Intent
(
getActivity
(),
DeckManagerActivity
.
getDeckManager
());
if
(
isDeckDir
(
file
))
{
//deck目录
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
file
.
getAbsolutePath
());
}
else
{
//非deck目录
File
ydk
=
getDeckFile
(
new
File
(
AppsSettings
.
get
().
getDeckDir
()),
getDeckName
(
uri
));
FileUtils
.
copyFile
(
file
,
ydk
);
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
ydk
.
getAbsolutePath
());
}
activity
.
startActivity
(
startdeck
);
}
else
if
(
"content"
.
equals
(
uri
.
getScheme
()))
{
}
else
if
(
"content"
.
equals
(
uri
.
getScheme
()))
{
try
{
List
<
String
>
paths
=
uri
.
getPathSegments
();
String
name
=
"tmp_"
+
System
.
currentTimeMillis
()
+
".ydk"
;
if
(
paths
.
size
()
>
0
)
{
String
tmp
=
paths
.
get
(
paths
.
size
()
-
1
);
if
(
tmp
.
endsWith
(
".ydk"
))
{
name
=
tmp
;
}
}
File
file
=
new
File
(
AppsSettings
.
get
().
getDeckDir
(),
name
);
File
dir
=
Constants
.
COPY_YDK_FILE
?
new
File
(
AppsSettings
.
get
().
getDeckDir
()):
new
File
(
getActivity
().
getApplicationInfo
().
dataDir
,
"cache"
);
File
ydk
=
getDeckFile
(
dir
,
getDeckName
(
uri
));
ParcelFileDescriptor
pfd
=
getActivity
().
getContentResolver
().
openFileDescriptor
(
uri
,
"r"
);
if
(
pfd
==
null
)
{
return
;
}
else
{
FileUtils
.
copyFile
(
file
.
getAbsolutePath
(),
new
FileOutputStream
(
pfd
.
getFileDescriptor
()));
try
{
FileUtils
.
copyFile
(
new
FileInputStream
(
pfd
.
getFileDescriptor
()),
ydk
);
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
finally
{
pfd
.
close
();
}
}
Intent
startdeck
=
new
Intent
(
getActivity
(),
DeckManagerActivity
.
getDeckManager
());
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
file
.
getAbsolutePath
());
startdeck
.
putExtra
(
Intent
.
EXTRA_TEXT
,
ydk
.
getAbsolutePath
());
activity
.
startActivity
(
startdeck
);
}
catch
(
Throwable
e
)
{
throw
new
RuntimeException
(
e
);
e
.
printStackTrace
(
);
}
}
else
{
String
host
=
uri
.
getHost
();
...
...
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/DeckManagerActivityImpl.java
View file @
445e34ac
This diff is collapsed.
Click to expand it.
mobile/src/main/java/cn/garymb/ygomobile/ui/cards/deck/DeckAdapater.java
View file @
445e34ac
...
...
@@ -2,6 +2,8 @@ package cn.garymb.ygomobile.ui.cards.deck;
import
android.content.Context
;
import
android.os.SystemClock
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.v7.widget.RecyclerView
;
import
android.text.TextUtils
;
import
android.util.SparseArray
;
...
...
@@ -65,6 +67,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
private
ImageLoader
imageLoader
;
private
boolean
showHead
=
false
;
private
String
mDeckMd5
;
private
DeckInfo
mDeckInfo
;
public
DeckAdapater
(
Context
context
,
RecyclerView
recyclerView
,
ImageLoader
imageLoader
)
{
this
.
context
=
context
;
...
...
@@ -378,7 +381,23 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
return
mSideCount
;
}
public
DeckInfo
getDeckInfo
()
{
return
mDeckInfo
;
}
public
LimitList
getLimitList
()
{
return
mLimitList
;
}
public
File
getYdkFile
(){
if
(
mDeckInfo
!=
null
){
return
mDeckInfo
.
source
;
}
return
null
;
}
public
void
setDeck
(
DeckInfo
deck
)
{
mDeckInfo
=
deck
;
if
(
deck
!=
null
)
{
loadData
(
deck
);
}
...
...
@@ -386,7 +405,9 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
}
public
DeckInfo
read
(
CardLoader
cardLoader
,
File
file
,
LimitList
limitList
)
{
if
(
limitList
!=
null
)
{
setLimitList
(
limitList
);
}
return
DeckLoader
.
readDeck
(
cardLoader
,
file
,
limitList
);
}
...
...
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