乐乐音乐紫林版V7.0 初始备份。
This commit is contained in:
commit
54419f5a5e
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
*.iml
|
||||||
|
.gradle
|
||||||
|
/local.properties
|
||||||
|
/.idea/workspace.xml
|
||||||
|
/.idea/libraries
|
||||||
|
.DS_Store
|
||||||
|
/build
|
||||||
|
/captures
|
||||||
|
.externalNativeBuild
|
||||||
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
162
.idea/assetWizardSettings.xml
Normal file
162
.idea/assetWizardSettings.xml
Normal file
|
|
@ -0,0 +1,162 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="WizardSettings">
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="imageWizard">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="imageAssetPanel">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="actionbar">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="image">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="trimmed" value="true" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="assetType" value="IMAGE" />
|
||||||
|
<entry key="imageAsset" value="C:\Users\zhangliangming\Desktop\乐.png" />
|
||||||
|
<entry key="theme" value="CUSTOM" />
|
||||||
|
<entry key="themeColor" value="ffffff" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry key="launcher">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="foregroundClipArt">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="trimmed" value="true" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry key="foregroundImage">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="scalingPercent" value="55" />
|
||||||
|
<entry key="trimmed" value="true" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="backgroundAssetType" value="COLOR" />
|
||||||
|
<entry key="backgroundColor" value="0288d1" />
|
||||||
|
<entry key="foregroundImage" value="C:\Users\zhangliangming\Desktop\乐.png" />
|
||||||
|
<entry key="legacyIconShape" value="CIRCLE" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry key="launcherLegacy">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="image">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="paddingPercent" value="40" />
|
||||||
|
<entry key="trimmed" value="true" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="assetType" value="IMAGE" />
|
||||||
|
<entry key="backgroundColor" value="0288d1" />
|
||||||
|
<entry key="cropped" value="true" />
|
||||||
|
<entry key="imageAsset" value="C:\Users\zhangliangming\Desktop\乐.png" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry key="notification">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="image">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="paddingPercent" value="30" />
|
||||||
|
<entry key="trimmed" value="true" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="assetType" value="IMAGE" />
|
||||||
|
<entry key="imageAsset" value="C:\Users\zhangliangming\Desktop\乐.png" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="outputIconType" value="ACTIONBAR" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
BIN
.idea/caches/build_file_checksums.ser
Normal file
BIN
.idea/caches/build_file_checksums.ser
Normal file
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
Normal file
BIN
.idea/caches/gradle_models.ser
Normal file
Binary file not shown.
113
.idea/codeStyles/Project.xml
Normal file
113
.idea/codeStyles/Project.xml
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<codeStyleSettings language="XML">
|
||||||
|
<arrangement>
|
||||||
|
<rules>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:android</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:id</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:name</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>name</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>style</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
</rules>
|
||||||
|
</arrangement>
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
||||||
6
.idea/compiler.xml
Normal file
6
.idea/compiler.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="11" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/encodings.xml
Normal file
7
.idea/encodings.xml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="UTF-8">
|
||||||
|
<file url="file://$PROJECT_DIR$/app/src/main/java/com/zlm/hp/fragment/BaseFragment.java" charset="UTF-8" />
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
21
.idea/gradle.xml
Normal file
21
.idea/gradle.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
|
<component name="GradleSettings">
|
||||||
|
<option name="linkedExternalProjectsSettings">
|
||||||
|
<GradleProjectSettings>
|
||||||
|
<option name="testRunner" value="PLATFORM" />
|
||||||
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
<option name="resolveModulePerSourceSet" value="false" />
|
||||||
|
<option name="useQualifiedModuleNames" value="true" />
|
||||||
|
</GradleProjectSettings>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
50
.idea/jarRepositories.xml
Normal file
50
.idea/jarRepositories.xml
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="BintrayJCenter" />
|
||||||
|
<option name="name" value="BintrayJCenter" />
|
||||||
|
<option name="url" value="https://jcenter.bintray.com/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven" />
|
||||||
|
<option name="name" value="maven" />
|
||||||
|
<option name="url" value="https://jitpack.io" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="Google" />
|
||||||
|
<option name="name" value="Google" />
|
||||||
|
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="4b7e7c13-cc9f-450d-9a8c-367aa521d628" />
|
||||||
|
<option name="name" value="4b7e7c13-cc9f-450d-9a8c-367aa521d628" />
|
||||||
|
<option name="url" value="https://maven.aliyun.com/repository/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="MavenLocal" />
|
||||||
|
<option name="name" value="MavenLocal" />
|
||||||
|
<option name="url" value="file:/$USER_HOME$/.m2/repository" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="MavenRepo" />
|
||||||
|
<option name="name" value="MavenRepo" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="maven" />
|
||||||
|
<option name="name" value="maven" />
|
||||||
|
<option name="url" value="http://maven.aliyun.com/nexus/content/repositories/jcenter" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
83
.idea/markdown-navigator.xml
Normal file
83
.idea/markdown-navigator.xml
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MarkdownProjectSettings" wasCopied="false">
|
||||||
|
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.25" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="NONE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="false" showSelectionInPreview="true" openRemoteLinks="true" replaceUnicodeEmoji="false" lastLayoutSetsDefault="false">
|
||||||
|
<PanelProvider>
|
||||||
|
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
|
||||||
|
</PanelProvider>
|
||||||
|
</PreviewSettings>
|
||||||
|
<ParserSettings gitHubSyntaxChange="false" emojiShortcuts="1" emojiImages="0">
|
||||||
|
<PegdownExtensions>
|
||||||
|
<option name="ABBREVIATIONS" value="false" />
|
||||||
|
<option name="ANCHORLINKS" value="true" />
|
||||||
|
<option name="ASIDE" value="false" />
|
||||||
|
<option name="ATXHEADERSPACE" value="true" />
|
||||||
|
<option name="AUTOLINKS" value="true" />
|
||||||
|
<option name="DEFINITIONS" value="false" />
|
||||||
|
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
|
||||||
|
<option name="FENCED_CODE_BLOCKS" value="true" />
|
||||||
|
<option name="FOOTNOTES" value="false" />
|
||||||
|
<option name="HARDWRAPS" value="false" />
|
||||||
|
<option name="HTML_DEEP_PARSER" value="false" />
|
||||||
|
<option name="INSERTED" value="false" />
|
||||||
|
<option name="QUOTES" value="false" />
|
||||||
|
<option name="RELAXEDHRULES" value="true" />
|
||||||
|
<option name="SMARTS" value="false" />
|
||||||
|
<option name="STRIKETHROUGH" value="true" />
|
||||||
|
<option name="SUBSCRIPT" value="false" />
|
||||||
|
<option name="SUPERSCRIPT" value="false" />
|
||||||
|
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
|
||||||
|
<option name="SUPPRESS_INLINE_HTML" value="false" />
|
||||||
|
<option name="TABLES" value="true" />
|
||||||
|
<option name="TASKLISTITEMS" value="true" />
|
||||||
|
<option name="TOC" value="false" />
|
||||||
|
<option name="WIKILINKS" value="false" />
|
||||||
|
</PegdownExtensions>
|
||||||
|
<ParserOptions>
|
||||||
|
<option name="ADMONITION_EXT" value="false" />
|
||||||
|
<option name="ATTRIBUTES_EXT" value="false" />
|
||||||
|
<option name="COMMONMARK_LISTS" value="true" />
|
||||||
|
<option name="DUMMY" value="false" />
|
||||||
|
<option name="EMOJI_SHORTCUTS" value="true" />
|
||||||
|
<option name="ENUMERATED_REFERENCES_EXT" value="false" />
|
||||||
|
<option name="FLEXMARK_FRONT_MATTER" value="false" />
|
||||||
|
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
|
||||||
|
<option name="GFM_TABLE_RENDERING" value="true" />
|
||||||
|
<option name="GITBOOK_URL_ENCODING" value="false" />
|
||||||
|
<option name="GITHUB_LISTS" value="false" />
|
||||||
|
<option name="GITHUB_WIKI_LINKS" value="false" />
|
||||||
|
<option name="GITLAB_EXT" value="false" />
|
||||||
|
<option name="GITLAB_MATH_EXT" value="false" />
|
||||||
|
<option name="GITLAB_MERMAID_EXT" value="false" />
|
||||||
|
<option name="HEADER_ID_NON_ASCII_TO_LOWERCASE" value="false" />
|
||||||
|
<option name="HEADER_ID_NO_DUPED_DASHES" value="false" />
|
||||||
|
<option name="JEKYLL_FRONT_MATTER" value="false" />
|
||||||
|
<option name="MACROS_EXT" value="false" />
|
||||||
|
<option name="NO_TEXT_ATTRIBUTES" value="false" />
|
||||||
|
<option name="PARSE_HTML_ANCHOR_ID" value="false" />
|
||||||
|
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
|
||||||
|
</ParserOptions>
|
||||||
|
</ParserSettings>
|
||||||
|
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true" embedImages="false" embedHttpImages="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false">
|
||||||
|
<GeneratorProvider>
|
||||||
|
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.generator" providerName="Default Swing HTML Generator" />
|
||||||
|
</GeneratorProvider>
|
||||||
|
<headerTop />
|
||||||
|
<headerBottom />
|
||||||
|
<bodyTop />
|
||||||
|
<bodyBottom />
|
||||||
|
</HtmlSettings>
|
||||||
|
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
|
||||||
|
<StylesheetProvider>
|
||||||
|
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.css" providerName="Default Swing Stylesheet" />
|
||||||
|
</StylesheetProvider>
|
||||||
|
<ScriptProviders />
|
||||||
|
<cssText />
|
||||||
|
<cssUriHistory />
|
||||||
|
</CssSettings>
|
||||||
|
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="" scriptDir="" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
|
||||||
|
<LinkMapSettings>
|
||||||
|
<textMaps />
|
||||||
|
</LinkMapSettings>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
3
.idea/markdown-navigator/profiles_settings.xml
Normal file
3
.idea/markdown-navigator/profiles_settings.xml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<component name="MarkdownNavigator.ProfileManager">
|
||||||
|
<settings default="" pdf-export="" />
|
||||||
|
</component>
|
||||||
48
.idea/misc.xml
Normal file
48
.idea/misc.xml
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="NullableNotNullManager">
|
||||||
|
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||||
|
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||||
|
<option name="myNullables">
|
||||||
|
<value>
|
||||||
|
<list size="12">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||||
|
<item index="4" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||||
|
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||||
|
<item index="6" class="java.lang.String" itemvalue="android.annotation.Nullable" />
|
||||||
|
<item index="7" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||||
|
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
|
||||||
|
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
|
||||||
|
<item index="10" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
|
||||||
|
<item index="11" class="java.lang.String" itemvalue="com.android.annotations.Nullable" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="myNotNulls">
|
||||||
|
<value>
|
||||||
|
<list size="11">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||||
|
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||||
|
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||||
|
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||||
|
<item index="5" class="java.lang.String" itemvalue="android.annotation.NonNull" />
|
||||||
|
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||||
|
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
|
||||||
|
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
|
||||||
|
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
|
||||||
|
<item index="10" class="java.lang.String" itemvalue="com.android.annotations.NonNull" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="Android" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
9
.idea/modules.xml
Normal file
9
.idea/modules.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/HappyPlayer5-happy_player6.iml" filepath="$PROJECT_DIR$/HappyPlayer5-happy_player6.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/HappyPlayer5-happy_player6.app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/HappyPlayer5-happy_player6.app.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
.idea/runConfigurations.xml
Normal file
12
.idea/runConfigurations.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RunConfigurationProducerService">
|
||||||
|
<option name="ignoredProducers">
|
||||||
|
<set>
|
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
2
CHANGELOG.md
Normal file
2
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
2020-11-28 V7.0
|
||||||
|
暂无。
|
||||||
201
LICENSE
Normal file
201
LICENSE
Normal file
|
|
@ -0,0 +1,201 @@
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
1
app/.gitignore
vendored
Normal file
1
app/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/build
|
||||||
131
app/build.gradle
Normal file
131
app/build.gradle
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'org.greenrobot.greendao'
|
||||||
|
|
||||||
|
android {
|
||||||
|
buildToolsVersion '28.0.3'
|
||||||
|
compileSdkVersion 29
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "com.zlm.hp"
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 29
|
||||||
|
versionCode 7
|
||||||
|
versionName "V7.0"
|
||||||
|
/**添加多 dex分包支持*/
|
||||||
|
multiDexEnabled true
|
||||||
|
useLibrary 'org.apache.http.legacy'
|
||||||
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
ndk {
|
||||||
|
// 设置支持的SO库架构
|
||||||
|
abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
debuggable false
|
||||||
|
jniDebuggable false
|
||||||
|
shrinkResources true
|
||||||
|
zipAlignEnabled true
|
||||||
|
minifyEnabled true
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 保证其他的lib没有被preDex
|
||||||
|
dexOptions {
|
||||||
|
preDexLibraries = false
|
||||||
|
}
|
||||||
|
|
||||||
|
productFlavors {
|
||||||
|
}
|
||||||
|
//greendao设置相关参数
|
||||||
|
greendao {
|
||||||
|
schemaVersion 2
|
||||||
|
daoPackage 'com.zlm.hp.db.dao'
|
||||||
|
targetGenDir 'src/main/java'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
|
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||||
|
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||||
|
exclude group: 'com.android.support', module: 'support-annotations'
|
||||||
|
})
|
||||||
|
implementation 'com.android.support:appcompat-v7:28+'
|
||||||
|
implementation 'com.android.support:support-v4:28.0.0'
|
||||||
|
implementation 'com.android.support:recyclerview-v7:28.0.0'
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
implementation 'com.android.support:multidex:1.0.1'
|
||||||
|
//第三方bugly
|
||||||
|
implementation 'com.tencent.bugly:crashreport:latest.release'
|
||||||
|
//其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.1.9
|
||||||
|
implementation 'com.tencent.bugly:nativecrashreport:latest.release'
|
||||||
|
//其中latest.release指代最新Bugly NDK版本号,也可以指定明确的版本号,例如3.0
|
||||||
|
//第三方内存泄露 LeakCanary
|
||||||
|
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
|
||||||
|
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
|
||||||
|
// Optional, if you use support library fragments:
|
||||||
|
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1'
|
||||||
|
/**
|
||||||
|
* 右滑动关闭
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:SwipeBackLayout:v3.1'
|
||||||
|
/**
|
||||||
|
* 旋转界面
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:RotateLayout:v3.2'
|
||||||
|
/**
|
||||||
|
* 进度条
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:SeekBar:v3.7'
|
||||||
|
/**
|
||||||
|
* 歌词
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:HPLyrics:v1.63'
|
||||||
|
/**
|
||||||
|
* 音频
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:HPAudio:v2.4'
|
||||||
|
/**
|
||||||
|
* 注册码
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:Register:v1.2'
|
||||||
|
/**
|
||||||
|
* ijkplayer
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:Player:v1.1'
|
||||||
|
/**
|
||||||
|
* SlidingMenuLayout
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:SlidingMenuLayout:v1.14'
|
||||||
|
/**
|
||||||
|
* 第三方switch-button
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zcweng:switch-button:0.0.3@aar'
|
||||||
|
/**
|
||||||
|
* 第三方greendao
|
||||||
|
*/
|
||||||
|
implementation 'org.greenrobot:greendao:3.3.0'
|
||||||
|
/**
|
||||||
|
* greendao 加密
|
||||||
|
*/
|
||||||
|
implementation 'net.zetetic:android-database-sqlcipher:3.5.7'
|
||||||
|
/**
|
||||||
|
* 第三方pinyin4j
|
||||||
|
*/
|
||||||
|
implementation 'com.belerweb:pinyin4j:2.5.1'
|
||||||
|
/**
|
||||||
|
* 第三方弹出窗口:jjdxm_dialogui
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:Dialog:v1.0'
|
||||||
|
/**
|
||||||
|
* 第三方上拉加载更多,下拉刷新
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:LRecyclerView:v1.0'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字幕
|
||||||
|
*/
|
||||||
|
implementation 'com.github.zhangliangming:Subtitle:v1.2'
|
||||||
|
|
||||||
|
}
|
||||||
57592
app/mapping.txt
Normal file
57592
app/mapping.txt
Normal file
File diff suppressed because it is too large
Load Diff
181
app/proguard-rules.pro
vendored
Normal file
181
app/proguard-rules.pro
vendored
Normal file
|
|
@ -0,0 +1,181 @@
|
||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
|
#1.基本指令区
|
||||||
|
-optimizationpasses 5
|
||||||
|
-dontusemixedcaseclassnames
|
||||||
|
-dontskipnonpubliclibraryclasses
|
||||||
|
-dontskipnonpubliclibraryclassmembers
|
||||||
|
-dontpreverify
|
||||||
|
-verbose
|
||||||
|
#-ignorewarning
|
||||||
|
# 混淆前后的映射
|
||||||
|
-printmapping mapping.txt
|
||||||
|
# apk 包内所有 class 的内部结构
|
||||||
|
-dump class_files.txt
|
||||||
|
# 未混淆的类和成员
|
||||||
|
-printseeds seeds.txt
|
||||||
|
# 列出从 apk 中删除的代码
|
||||||
|
-printusage unused.txt
|
||||||
|
-optimizations !code/simplification/cast,!field/*,!class/merging/*
|
||||||
|
-keepattributes *Annotation*,InnerClasses
|
||||||
|
-keepattributes Signature
|
||||||
|
-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
#2.默认保留区
|
||||||
|
-keep public class * extends android.app.Activity
|
||||||
|
-keep public class * extends android.app.Application
|
||||||
|
-keep public class * extends android.app.Service
|
||||||
|
-keep public class * extends android.content.BroadcastReceiver
|
||||||
|
-keep public class * extends android.content.ContentProvider
|
||||||
|
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||||
|
-keep public class * extends android.preference.Preference
|
||||||
|
-keep public class * extends android.view.View
|
||||||
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
-keep class android.support.** {*;}
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
native <methods>;
|
||||||
|
}
|
||||||
|
-keepclassmembers class * extends android.app.Activity{
|
||||||
|
public void *(android.view.View);
|
||||||
|
}
|
||||||
|
-keepclassmembers enum * {
|
||||||
|
public static **[] values();
|
||||||
|
public static ** valueOf(java.lang.String);
|
||||||
|
}
|
||||||
|
-keep public class * extends android.view.View{
|
||||||
|
*** get*();
|
||||||
|
void set*(***);
|
||||||
|
public <init>(android.content.Context);
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||||
|
}
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||||
|
}
|
||||||
|
-keep class * implements android.os.Parcelable {
|
||||||
|
public static final android.os.Parcelable$Creator *;
|
||||||
|
}
|
||||||
|
-keepclassmembers class * implements java.io.Serializable {
|
||||||
|
static final long serialVersionUID;
|
||||||
|
private static final java.io.ObjectStreamField[] serialPersistentFields;
|
||||||
|
private void writeObject(java.io.ObjectOutputStream);
|
||||||
|
private void readObject(java.io.ObjectInputStream);
|
||||||
|
java.lang.Object writeReplace();
|
||||||
|
java.lang.Object readResolve();
|
||||||
|
}
|
||||||
|
-keep class **.R$* {
|
||||||
|
*;
|
||||||
|
}
|
||||||
|
-keepclassmembers class * {
|
||||||
|
void *(**On*Event);
|
||||||
|
}
|
||||||
|
|
||||||
|
#3.webview
|
||||||
|
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
public *;
|
||||||
|
}
|
||||||
|
-keepclassmembers class * extends android.webkit.webViewClient {
|
||||||
|
public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
|
||||||
|
public boolean *(android.webkit.WebView, java.lang.String);
|
||||||
|
}
|
||||||
|
-keepclassmembers class * extends android.webkit.webViewClient {
|
||||||
|
public void *(android.webkit.webView, jav.lang.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
#5complie包
|
||||||
|
|
||||||
|
#SwitchButton
|
||||||
|
-keep class com.suke.widget.**
|
||||||
|
-keepclassmembers class com.suke.widget.** {
|
||||||
|
public *;
|
||||||
|
}
|
||||||
|
|
||||||
|
#bugly
|
||||||
|
-dontwarn com.tencent.bugly.**
|
||||||
|
-keep public class com.tencent.bugly.**{*;}
|
||||||
|
|
||||||
|
#leakcanary 内存泄露
|
||||||
|
-keep public class com.squareup.leakcanary.**{*;}
|
||||||
|
|
||||||
|
#greendao
|
||||||
|
-keep class org.greenrobot.greendao.**{*;}
|
||||||
|
-keep public interface org.greenrobot.greendao.**
|
||||||
|
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
|
||||||
|
public static java.lang.String TABLENAME;
|
||||||
|
}
|
||||||
|
-keep class **$Properties
|
||||||
|
-keep class net.sqlcipher.** {*;}
|
||||||
|
-keep class net.sqlcipher.database.** {*;}
|
||||||
|
-dontwarn net.sqlcipher.database.**
|
||||||
|
-dontwarn org.greenrobot.greendao.**
|
||||||
|
|
||||||
|
|
||||||
|
#pinyin
|
||||||
|
-keep public class com.hp.hpl.sparta.**{*;}
|
||||||
|
-keep public class net.sourceforge.pinyin4j.**{*;}
|
||||||
|
|
||||||
|
|
||||||
|
#ijkplayer
|
||||||
|
-keep class com.zlm.player.**
|
||||||
|
-keepclassmembers class com.zlm.player.** {
|
||||||
|
public *;
|
||||||
|
}
|
||||||
|
-keep class tv.danmaku.ijk.media.player.** { *; }
|
||||||
|
|
||||||
|
|
||||||
|
#com.github.zhangliangming:SwipeBackLayout、com.github.zhangliangming:RotateLayout
|
||||||
|
#com.github.zhangliangming:SeekBar、com.github.zhangliangming:SeekBar
|
||||||
|
-keep class com.zlm.libs.widget.** { *; }
|
||||||
|
|
||||||
|
#com.github.zhangliangming:HPLyrics
|
||||||
|
-keep class com.zlm.hp.lyrics.** { *; }
|
||||||
|
|
||||||
|
#com.github.zhangliangming:HPAudio
|
||||||
|
-dontwarn javax.**
|
||||||
|
-dontwarn java.awt.**
|
||||||
|
-keep class org.jaudiotagger.** { *; }
|
||||||
|
-keep class davaguine.jmac.** { *; }
|
||||||
|
-keep class com.wavpack.** { *; }
|
||||||
|
-keep class com.zlm.hp.audio.** { *; }
|
||||||
|
|
||||||
|
#com.github.zhangliangming:Register:v1.0
|
||||||
|
-keep class com.zlm.libs.register.** { *; }
|
||||||
|
|
||||||
|
#第三方弹出窗口:
|
||||||
|
-keep class com.dou361.dialogui.** { *; }
|
||||||
|
|
||||||
|
#第三方上拉加载更多,下拉刷新:
|
||||||
|
-dontwarn com.github.jdsjlzx.**
|
||||||
|
-keep class com.github.jdsjlzx.progressindicator.indicators.** { *; }
|
||||||
|
|
||||||
|
#implementation 'com.github.zhangliangming:Subtitle:v1.0'
|
||||||
|
-keep class com.zlm.subtitlelibrary.** { *; }
|
||||||
|
|
||||||
|
#6混淆项目代码
|
||||||
|
-keep class com.zlm.**
|
||||||
|
-keepclassmembers class com.zlm.** {
|
||||||
|
public *;
|
||||||
|
}
|
||||||
|
-ignorewarnings
|
||||||
62697
app/seeds.txt
Normal file
62697
app/seeds.txt
Normal file
File diff suppressed because it is too large
Load Diff
141
app/src/androidTest/java/com/zlm/hp/DownloadTaskTest.java
Normal file
141
app/src/androidTest/java/com/zlm/hp/DownloadTaskTest.java
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
package com.zlm.hp;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.down.interfaces.IDownloadTaskEvent;
|
||||||
|
import com.zlm.down.manager.DownloadTaskManager;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 测试下载类
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-05 10:50
|
||||||
|
**/
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class DownloadTaskTest {
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 下载任务
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-05 10:50
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void DownloadTask() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
DownloadTaskManager downloadTaskManager = new DownloadTaskManager(appContext,"downloadTask", new IDownloadTaskEvent() {
|
||||||
|
@Override
|
||||||
|
public void taskWaiting(DownloadTask task) {
|
||||||
|
//更新当前任务的状态
|
||||||
|
Log.d("Test", "taskWaiting->" + task.getTaskName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskDownloading(DownloadTask task, int downloadedSize) {
|
||||||
|
//更新当前任务的进度
|
||||||
|
Log.d("Test", "taskDownloading->" + task.getTaskName() + " " + ((float) downloadedSize / task.getTaskFileSize()) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskPause(DownloadTask task, int downloadedSize) {
|
||||||
|
//更新当前任务的状态
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskCancel(DownloadTask task) {
|
||||||
|
//更新当前任务的状态
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskFinish(DownloadTask task, int downloadedSize) {
|
||||||
|
//更新当前任务的状态
|
||||||
|
Log.d("Test", "taskFinish->" + task.getTaskName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskError(DownloadTask task, String msg) {
|
||||||
|
//更新当前任务的状态
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAskWifi() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTaskThreadDownloadedSize(DownloadTask task, int threadId) {
|
||||||
|
//获取之前线程任务已下载完成的进度
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadDownloading(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
//更新每个线程任务的下载进度
|
||||||
|
//Log.d("Test", "taskDownloading->" + threadId + ":" + ((float) downloadedSize / task.getFileSize()) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadPause(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
//更新每个线程任务的状态
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadFinish(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
//更新每个线程任务的状态
|
||||||
|
// Log.d("Test", "taskThreadFinish->" + threadId + ":" + ((float) downloadedSize / task.getFileSize()) * 100);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadError(DownloadTask task, int threadId, String msg) {
|
||||||
|
//更新每个线程任务的状态
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
DownloadTask downloadTask2 = new DownloadTask();
|
||||||
|
downloadTask2.setTaskName("张学友 - 等你等到我心痛2");
|
||||||
|
downloadTask2.setTaskExt("mkv");
|
||||||
|
downloadTask2.setTaskId("5F8393A55D5762A63F1A5E92B46E575E");
|
||||||
|
|
||||||
|
String fileName2 = downloadTask2.getTaskName();
|
||||||
|
String taskPath2 = ResourceUtil.getFilePath(appContext, ResourceConstants.PATH_VIDEO, fileName2 + "." + downloadTask2.getTaskExt());
|
||||||
|
String taskTempPath2 = ResourceUtil.getFilePath(appContext, ResourceConstants.PATH_VIDEO_TEMP, fileName2 + ".temp");
|
||||||
|
|
||||||
|
downloadTask2.setTaskPath(taskPath2);
|
||||||
|
downloadTask2.setTaskTempPath(taskTempPath2);
|
||||||
|
downloadTask2.setTaskUrl("http://fs.mv.web.kugou.com/201808050215/a842a9d7b8b048433ac1d90a3cf188a1/G030/M06/14/0B/Xg0DAFXeLMiAMle_ATon28lO__I941.mkv");
|
||||||
|
downloadTask2.setThreadNum(3);
|
||||||
|
downloadTask2.setCreateTime(new Date());
|
||||||
|
|
||||||
|
|
||||||
|
DownloadTask downloadTask = new DownloadTask();
|
||||||
|
downloadTask.setTaskName("张学友 - 等你等到我心痛");
|
||||||
|
downloadTask.setTaskExt("mkv");
|
||||||
|
downloadTask.setTaskId("5F8393A55D5762A63F1A5E92B46E575E");
|
||||||
|
|
||||||
|
String fileName = downloadTask.getTaskName();
|
||||||
|
String taskPath = ResourceUtil.getFilePath(appContext, ResourceConstants.PATH_VIDEO, fileName + "." + downloadTask.getTaskExt());
|
||||||
|
String taskTempPath = ResourceUtil.getFilePath(appContext, ResourceConstants.PATH_VIDEO_TEMP, fileName + ".temp");
|
||||||
|
|
||||||
|
downloadTask.setTaskPath(taskPath);
|
||||||
|
downloadTask.setTaskTempPath(taskTempPath);
|
||||||
|
downloadTask.setTaskUrl("http://fs.mv.web.kugou.com/201808050215/a842a9d7b8b048433ac1d90a3cf188a1/G030/M06/14/0B/Xg0DAFXeLMiAMle_ATon28lO__I941.mkv");
|
||||||
|
downloadTask.setThreadNum(3);
|
||||||
|
downloadTask.setCreateTime(new Date());
|
||||||
|
|
||||||
|
downloadTaskManager.addDownloadTask(downloadTask);
|
||||||
|
downloadTaskManager.addDownloadTask(downloadTask2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
312
app/src/androidTest/java/com/zlm/hp/KuGouApiTest.java
Normal file
312
app/src/androidTest/java/com/zlm/hp/KuGouApiTest.java
Normal file
|
|
@ -0,0 +1,312 @@
|
||||||
|
package com.zlm.hp;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.test.InstrumentationRegistry;
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.zlm.hp.http.APIHttpClient;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class KuGouApiTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 搜索-歌曲
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSearchSong() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.searchSongList(appContext, "爱就一个字", 1, 2, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 搜索-歌单
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSearchSpecial() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.searchSpecialList(appContext, "爱就一个字", 1, 2, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 搜索-专辑
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSearchAlbum() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.searchAlbumList(appContext, "爱就一个字", 1, 2, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 音乐新歌榜
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiLastSongList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.lastSongList(appContext, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 排行榜
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiRankList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.rankList(appContext, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 排行榜/歌曲列表
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiRankSongList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.rankSongList(appContext, "6666", "1", 1,10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 音乐.歌单
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSpecialList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.specialList(appContext, 1, 10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音乐.歌单/歌曲列表
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSpecialSongList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.specialSongList(appContext, "125032", 1, 10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手分类
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSingerClass() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.singerClassList(appContext, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手分类/歌手列表
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSingeList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.singeList(appContext, "88", 1, 10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 歌手分类/歌手列表/歌曲列表
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSingeSongList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.singeSongList(appContext, "3060", 1, 10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 热门搜索
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSearchHotList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.searchHotList(appContext, 1, 10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 搜索-mv
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 18:43
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSearchMV() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.searchMVList(appContext, "爱就一个字", 1, 10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 获取歌曲下载地址
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 22:44
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiGetSongInfo() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.getSongInfo(appContext, "CB7EE97F4CC11C4EA7A1FA4B516A5D97", null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 获取mv歌曲下载地址
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 22:44
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiGetMVInfo() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.getMVInfo(appContext, "5F8393A55D5762A63F1A5E92B46E575E", null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 获取歌手头像
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 22:44
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiGetSingerIcon() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.getSingerIcon(appContext, "周杰伦", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 获取歌手写真
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 22:44
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiGetSingerPicList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.getSingerPicList(appContext, "周杰伦", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 搜索-歌词
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-01 0:44
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiSearchLyricsList() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.searchLyricsList(appContext, "王力宏 - 就是现在", "270000", "", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 获取歌词信息
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-01 0:48
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiGetLyricsInfo() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.getLyricsInfo(appContext, "16835663", "32BA8996EA9E72C30069713CCD58236D", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 获取歌词信息
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-01 0:48
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void KuGouApiGetLyricsInfo2() {
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
apiHttpClient.getLyricsInfo(appContext, "张杰 - 微笑着胜利【庆祝建军91周年网宣主题曲】", "271000", "37F4B77A2BAD8471BF1C70E4F7667400", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
103
app/src/main/AndroidManifest.xml
Normal file
103
app/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.zlm.hp.ui">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<!-- 存储权限 -->
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
|
<!-- 显示悬浮窗口权限 -->
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
|
|
||||||
|
<!-- ssid -->
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
|
|
||||||
|
<!-- 动态广播自定义权限 -->
|
||||||
|
<uses-permission android:name="com.zlm.hp.permissions.RECEIVER" />
|
||||||
|
<permission
|
||||||
|
android:name="com.zlm.hp.permissions.RECEIVER"
|
||||||
|
android:protectionLevel="signature" />
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:name="com.zlm.hp.application.HPApplication"
|
||||||
|
android:allowBackup="false"
|
||||||
|
android:hardwareAccelerated="false"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:usesCleartextTraffic="true"
|
||||||
|
android:theme="@style/AppTheme">
|
||||||
|
<!-- 兼容9.0 不存在Apache HTTP库-->
|
||||||
|
<uses-library android:name="org.apache.http.legacy" android:required="false" />
|
||||||
|
<!-- 支持全面屏 -->
|
||||||
|
<meta-data
|
||||||
|
android:name="android.max_aspect"
|
||||||
|
android:value="2.1" />
|
||||||
|
|
||||||
|
<activity android:name=".SplashActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".MainActivity"
|
||||||
|
android:configChanges="screenSize|keyboardHidden|orientation" />
|
||||||
|
<activity android:name=".SettingActivity" />
|
||||||
|
<activity android:name=".AboutActivity" />
|
||||||
|
<activity android:name=".HelpActivity" />
|
||||||
|
|
||||||
|
<service android:name="com.zlm.hp.service.AudioPlayerService" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".LrcActivity"
|
||||||
|
android:configChanges="screenSize|keyboardHidden|orientation" />
|
||||||
|
<activity android:name=".SearchSingerActivity" />
|
||||||
|
<activity android:name=".SearchLrcActivity" />
|
||||||
|
<activity android:name=".TimerPowerOffActivity" />
|
||||||
|
|
||||||
|
<service android:name="com.zlm.hp.service.FloatService" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".LockActivity"
|
||||||
|
android:configChanges="screenSize|keyboardHidden|orientation"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:launchMode="singleInstance"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
|
android:taskAffinity="com.zlm.lockscreen"
|
||||||
|
android:theme="@style/LockScreenTheme" />
|
||||||
|
<activity android:name=".ToolActivity" />
|
||||||
|
<activity android:name=".tool.LrcConverterActivity" />
|
||||||
|
<activity android:name=".tool.FileManagerActivity" />
|
||||||
|
<activity android:name=".MakeLrcSettingActivity" />
|
||||||
|
<activity
|
||||||
|
android:name=".tool.MakeLrcActivity"
|
||||||
|
android:theme="@style/MakeLrcTheme" />
|
||||||
|
<activity
|
||||||
|
android:name=".tool.MakeTranslateLrcActivity"
|
||||||
|
android:theme="@style/MakeLrcTheme" />
|
||||||
|
<activity
|
||||||
|
android:name=".tool.MakeTransliterationLrcActivity"
|
||||||
|
android:theme="@style/MakeLrcTheme" />
|
||||||
|
<activity android:name=".tool.LrcMakerActivity" />
|
||||||
|
<activity
|
||||||
|
android:name=".SearchMVActivity"
|
||||||
|
android:configChanges="screenSize|keyboardHidden|orientation" />
|
||||||
|
<activity
|
||||||
|
android:name=".VideoActivity"
|
||||||
|
android:screenOrientation="landscape"></activity>
|
||||||
|
<activity
|
||||||
|
android:name=".LocalVideoActivity"
|
||||||
|
android:screenOrientation="landscape"></activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
BIN
app/src/main/assets/audio/hellolele.mp3
Normal file
BIN
app/src/main/assets/audio/hellolele.mp3
Normal file
Binary file not shown.
BIN
app/src/main/assets/fonts/iconfont.ttf
Normal file
BIN
app/src/main/assets/fonts/iconfont.ttf
Normal file
Binary file not shown.
BIN
app/src/main/assets/fonts/pingguolihei.ttf
Normal file
BIN
app/src/main/assets/fonts/pingguolihei.ttf
Normal file
Binary file not shown.
BIN
app/src/main/assets/fonts/weiruanyahei14M.ttf
Normal file
BIN
app/src/main/assets/fonts/weiruanyahei14M.ttf
Normal file
Binary file not shown.
BIN
app/src/main/ic_launcher-web.png
Normal file
BIN
app/src/main/ic_launcher-web.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
254
app/src/main/java/com/zlm/down/entity/DownloadTask.java
Normal file
254
app/src/main/java/com/zlm/down/entity/DownloadTask.java
Normal file
|
|
@ -0,0 +1,254 @@
|
||||||
|
package com.zlm.down.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.zlm.down.thread.DownloadTaskThreadManager;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.annotation.Entity;
|
||||||
|
import org.greenrobot.greendao.annotation.Transient;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import org.greenrobot.greendao.annotation.Generated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载任务
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-04 23:01
|
||||||
|
**/
|
||||||
|
@Entity(
|
||||||
|
generateConstructors = false,
|
||||||
|
generateGettersSetters = false
|
||||||
|
)
|
||||||
|
public class DownloadTask implements Parcelable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
public static final int STATUS_INT = 0;
|
||||||
|
/**
|
||||||
|
* 等待下载
|
||||||
|
*/
|
||||||
|
public static final int STATUS_WAIT = 1;
|
||||||
|
/**
|
||||||
|
* 下载中
|
||||||
|
*/
|
||||||
|
public static final int STATUS_DOWNLOADING = 2;
|
||||||
|
/**
|
||||||
|
* 暂停
|
||||||
|
*/
|
||||||
|
public static final int STATUS_PAUSE = 3;
|
||||||
|
/**
|
||||||
|
* 取消
|
||||||
|
*/
|
||||||
|
public static final int STATUS_CANCEL = 4;
|
||||||
|
/**
|
||||||
|
* 错误
|
||||||
|
*/
|
||||||
|
public static final int STATUS_ERROR = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完成
|
||||||
|
*/
|
||||||
|
public static final int STATUS_FINISH = 6;
|
||||||
|
/**
|
||||||
|
* 任务id
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String taskId;
|
||||||
|
/**
|
||||||
|
* 任务名称
|
||||||
|
*/
|
||||||
|
private String taskName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务文件后缀名
|
||||||
|
*/
|
||||||
|
private String taskExt;
|
||||||
|
/**
|
||||||
|
* 任务保存路径
|
||||||
|
*/
|
||||||
|
private String taskPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务临时保存路径
|
||||||
|
*/
|
||||||
|
private String taskTempPath;
|
||||||
|
/**
|
||||||
|
* 根目录
|
||||||
|
*/
|
||||||
|
private String rootPath;
|
||||||
|
/**
|
||||||
|
* 任务下载路径
|
||||||
|
*/
|
||||||
|
private String taskUrl;
|
||||||
|
/**
|
||||||
|
* 添加时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
/**
|
||||||
|
* 任务状态
|
||||||
|
*/
|
||||||
|
private int status = STATUS_INT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程总数
|
||||||
|
*/
|
||||||
|
|
||||||
|
private int threadNum;
|
||||||
|
/**
|
||||||
|
* 任务文件大小
|
||||||
|
*/
|
||||||
|
private long taskFileSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载任务线程
|
||||||
|
*/
|
||||||
|
@Transient
|
||||||
|
private DownloadTaskThreadManager downloadTaskThreadManager;
|
||||||
|
|
||||||
|
public DownloadTask() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DownloadTask(Parcel in) {
|
||||||
|
taskId = in.readString();
|
||||||
|
taskName = in.readString();
|
||||||
|
taskExt = in.readString();
|
||||||
|
taskPath = in.readString();
|
||||||
|
taskTempPath = in.readString();
|
||||||
|
rootPath = in.readString();
|
||||||
|
taskUrl = in.readString();
|
||||||
|
status = in.readInt();
|
||||||
|
threadNum = in.readInt();
|
||||||
|
taskFileSize = in.readLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<DownloadTask> CREATOR = new Creator<DownloadTask>() {
|
||||||
|
@Override
|
||||||
|
public DownloadTask createFromParcel(Parcel in) {
|
||||||
|
return new DownloadTask(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadTask[] newArray(int size) {
|
||||||
|
return new DownloadTask[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getTaskId() {
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskId(String taskId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskName() {
|
||||||
|
return taskName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskName(String taskName) {
|
||||||
|
this.taskName = taskName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskExt() {
|
||||||
|
return taskExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskExt(String taskExt) {
|
||||||
|
this.taskExt = taskExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskPath() {
|
||||||
|
return taskPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskPath(String taskPath) {
|
||||||
|
this.taskPath = taskPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskTempPath() {
|
||||||
|
return taskTempPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskTempPath(String taskTempPath) {
|
||||||
|
this.taskTempPath = taskTempPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTaskUrl() {
|
||||||
|
return taskUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskUrl(String taskUrl) {
|
||||||
|
this.taskUrl = taskUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getThreadNum() {
|
||||||
|
return threadNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThreadNum(int threadNum) {
|
||||||
|
this.threadNum = threadNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTaskFileSize() {
|
||||||
|
return taskFileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskFileSize(long taskFileSize) {
|
||||||
|
this.taskFileSize = taskFileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadTaskThreadManager getDownloadTaskThreadManager() {
|
||||||
|
return downloadTaskThreadManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadTaskThreadManager(DownloadTaskThreadManager downloadTaskThreadManager) {
|
||||||
|
this.downloadTaskThreadManager = downloadTaskThreadManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRootPath() {
|
||||||
|
return rootPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRootPath(String rootPath) {
|
||||||
|
this.rootPath = rootPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(taskId);
|
||||||
|
dest.writeString(taskName);
|
||||||
|
dest.writeString(taskExt);
|
||||||
|
dest.writeString(taskPath);
|
||||||
|
dest.writeString(taskTempPath);
|
||||||
|
dest.writeString(rootPath);
|
||||||
|
dest.writeString(taskUrl);
|
||||||
|
dest.writeInt(status);
|
||||||
|
dest.writeInt(threadNum);
|
||||||
|
dest.writeLong(taskFileSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.zlm.down.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.annotation.Entity;
|
||||||
|
import org.greenrobot.greendao.annotation.Generated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载线程任务
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-10-07 20:19
|
||||||
|
**/
|
||||||
|
@Entity(
|
||||||
|
generateConstructors = false,
|
||||||
|
generateGettersSetters = false
|
||||||
|
)
|
||||||
|
public class DownloadThreadInfo implements Parcelable {
|
||||||
|
|
||||||
|
private String taskId;
|
||||||
|
|
||||||
|
private int threadNum;
|
||||||
|
|
||||||
|
private int threadId;
|
||||||
|
private int downloadedSize;
|
||||||
|
|
||||||
|
public DownloadThreadInfo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DownloadThreadInfo(Parcel in) {
|
||||||
|
taskId = in.readString();
|
||||||
|
threadNum = in.readInt();
|
||||||
|
threadId = in.readInt();
|
||||||
|
downloadedSize = in.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(taskId);
|
||||||
|
dest.writeInt(threadNum);
|
||||||
|
dest.writeInt(threadId);
|
||||||
|
dest.writeInt(downloadedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<DownloadThreadInfo> CREATOR = new Creator<DownloadThreadInfo>() {
|
||||||
|
@Override
|
||||||
|
public DownloadThreadInfo createFromParcel(Parcel in) {
|
||||||
|
return new DownloadThreadInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadThreadInfo[] newArray(int size) {
|
||||||
|
return new DownloadThreadInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getTaskId() {
|
||||||
|
return taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskId(String taskId) {
|
||||||
|
this.taskId = taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getThreadNum() {
|
||||||
|
return threadNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThreadNum(int threadNum) {
|
||||||
|
this.threadNum = threadNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getThreadId() {
|
||||||
|
return threadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThreadId(int threadId) {
|
||||||
|
this.threadId = threadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDownloadedSize() {
|
||||||
|
return downloadedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadedSize(int downloadedSize) {
|
||||||
|
this.downloadedSize = downloadedSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.zlm.down.interfaces;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载事件接口
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-04 23:09
|
||||||
|
**/
|
||||||
|
public interface IDownloadTaskEvent extends IDownloadThreadEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务等待
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskWaiting(DownloadTask task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务下载中
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
* @param downloadedSize 下载大小
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskDownloading(DownloadTask task, int downloadedSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务暂停
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
* @param downloadedSize 下载进度
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskPause(DownloadTask task, int downloadedSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消任务
|
||||||
|
*
|
||||||
|
* @param task
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月9日
|
||||||
|
*/
|
||||||
|
void taskCancel(DownloadTask task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务完成
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
* @param downloadedSize 下载进度
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskFinish(DownloadTask task, int downloadedSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务错误
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
* @param msg 错误信息
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskError(DownloadTask task, String msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是wifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean getAskWifi();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.zlm.down.interfaces;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载任务线程事件
|
||||||
|
*
|
||||||
|
* @author zhangliangming
|
||||||
|
*/
|
||||||
|
public interface IDownloadThreadEvent {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取已下载的进度
|
||||||
|
*
|
||||||
|
* @param task
|
||||||
|
* @param threadId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getTaskThreadDownloadedSize(DownloadTask task, int threadId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务线程下载中
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
* @param threadId 线程任务id
|
||||||
|
* @param downloadedSize 线程下载进度
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskThreadDownloading(DownloadTask task, int threadId,
|
||||||
|
int downloadedSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务线程暂停
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
* @param threadId 线程任务id
|
||||||
|
* @param downloadedSize 线程下载进度
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskThreadPause(DownloadTask task, int threadId, int downloadedSize);
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* 任务线程完成
|
||||||
|
*
|
||||||
|
* @param task
|
||||||
|
* 任务
|
||||||
|
* @param threadId
|
||||||
|
* 线程任务id
|
||||||
|
* @param downloadedSize
|
||||||
|
* 线程下载进度
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskThreadFinish(DownloadTask task, int threadId, int downloadedSize);
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* 任务线程错误
|
||||||
|
*
|
||||||
|
* @param task
|
||||||
|
* 任务
|
||||||
|
* @param msg
|
||||||
|
* 错误信息
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
void taskThreadError(DownloadTask task, int threadId, String msg);
|
||||||
|
|
||||||
|
}
|
||||||
280
app/src/main/java/com/zlm/down/manager/DownloadTaskManager.java
Normal file
280
app/src/main/java/com/zlm/down/manager/DownloadTaskManager.java
Normal file
|
|
@ -0,0 +1,280 @@
|
||||||
|
package com.zlm.down.manager;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
|
import android.os.Process;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.down.interfaces.IDownloadTaskEvent;
|
||||||
|
import com.zlm.down.thread.DownloadTaskThreadManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 任务下载管理类
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-04 23:07
|
||||||
|
**/
|
||||||
|
public class DownloadTaskManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子线程用于执行耗时任务
|
||||||
|
*/
|
||||||
|
public Handler mWorkerHandler;
|
||||||
|
//创建异步HandlerThread
|
||||||
|
private HandlerThread mHandlerThread;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
/**
|
||||||
|
* 任务队列
|
||||||
|
*/
|
||||||
|
private List<DownloadTask> mDownloadTasks = new ArrayList<DownloadTask>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对外下载回调
|
||||||
|
*/
|
||||||
|
private IDownloadTaskEvent mIDownloadTaskEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对内下载回调
|
||||||
|
*/
|
||||||
|
private IDownloadTaskEvent mInnerIDownloadTaskEvent = new IDownloadTaskEvent() {
|
||||||
|
@Override
|
||||||
|
public void taskWaiting(DownloadTask task) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
task.setStatus(DownloadTask.STATUS_WAIT);
|
||||||
|
mIDownloadTaskEvent.taskWaiting(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskDownloading(DownloadTask task, int downloadedSize) {
|
||||||
|
if (task.getTaskFileSize() <= downloadedSize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
task.setStatus(DownloadTask.STATUS_DOWNLOADING);
|
||||||
|
mIDownloadTaskEvent.taskDownloading(task, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskPause(DownloadTask task, int downloadedSize) {
|
||||||
|
|
||||||
|
removeTask(task);
|
||||||
|
|
||||||
|
if (task.getTaskFileSize() <= downloadedSize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
task.setStatus(DownloadTask.STATUS_PAUSE);
|
||||||
|
mIDownloadTaskEvent
|
||||||
|
.taskPause(task, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskCancel(DownloadTask task) {
|
||||||
|
removeTask(task);
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
task.setStatus(DownloadTask.STATUS_CANCEL);
|
||||||
|
mIDownloadTaskEvent
|
||||||
|
.taskCancel(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskFinish(DownloadTask task, int downloadedSize) {
|
||||||
|
|
||||||
|
removeTask(task);
|
||||||
|
|
||||||
|
if (task.getTaskFileSize() > downloadedSize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
task.setStatus(DownloadTask.STATUS_FINISH);
|
||||||
|
mIDownloadTaskEvent
|
||||||
|
.taskFinish(task, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskError(DownloadTask task, String msg) {
|
||||||
|
removeTask(task);
|
||||||
|
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
task.setStatus(DownloadTask.STATUS_ERROR);
|
||||||
|
mIDownloadTaskEvent
|
||||||
|
.taskError(task, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAskWifi() {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
return mIDownloadTaskEvent.getAskWifi();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTaskThreadDownloadedSize(DownloadTask task, int threadId) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
return mIDownloadTaskEvent.getTaskThreadDownloadedSize(task, threadId);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadDownloading(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadDownloading(task, threadId, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadPause(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadPause(task, threadId, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadFinish(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadFinish(task, threadId, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadError(DownloadTask task, int threadId, String msg) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadError(task, threadId, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public DownloadTaskManager(Context context, String threadName, IDownloadTaskEvent downloadTaskEvent) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mIDownloadTaskEvent = downloadTaskEvent;
|
||||||
|
|
||||||
|
//创建异步HandlerThread
|
||||||
|
mHandlerThread = new HandlerThread(threadName, Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
|
//必须先开启线程
|
||||||
|
mHandlerThread.start();
|
||||||
|
//子线程Handler
|
||||||
|
mWorkerHandler = new Handler(mHandlerThread.getLooper());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放
|
||||||
|
*/
|
||||||
|
public void release() {
|
||||||
|
//移除队列任务
|
||||||
|
if (mWorkerHandler != null) {
|
||||||
|
mWorkerHandler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭线程
|
||||||
|
if (mHandlerThread != null)
|
||||||
|
mHandlerThread.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加下载任务
|
||||||
|
*
|
||||||
|
* @param downloadTask
|
||||||
|
*/
|
||||||
|
public void addDownloadTask(DownloadTask downloadTask) {
|
||||||
|
DownloadTaskThreadManager downloadTaskThreadManager = new DownloadTaskThreadManager(mContext, mWorkerHandler, downloadTask, mInnerIDownloadTaskEvent);
|
||||||
|
downloadTask.setDownloadTaskThreadManager(downloadTaskThreadManager);
|
||||||
|
if (mDownloadTasks.size() == 0 || mDownloadTasks.size() > 0) {
|
||||||
|
downloadTask.setStatus(DownloadTask.STATUS_WAIT);
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskWaiting(downloadTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mDownloadTasks.add(downloadTask);
|
||||||
|
mWorkerHandler.post(downloadTask.getDownloadTaskThreadManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停任务
|
||||||
|
*
|
||||||
|
* @param downloadTaskId
|
||||||
|
*/
|
||||||
|
public void pauseDownloadTask(String downloadTaskId) {
|
||||||
|
for (int i = 0; i < mDownloadTasks.size(); i++) {
|
||||||
|
DownloadTask task = mDownloadTasks.get(i);
|
||||||
|
if (task.getTaskId().equals(downloadTaskId)) {
|
||||||
|
if (i == 0) {
|
||||||
|
|
||||||
|
DownloadTaskThreadManager downloadTaskThreadManager = task.getDownloadTaskThreadManager();
|
||||||
|
downloadTaskThreadManager.pauseTaskThread();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskPause(task, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mDownloadTasks.size() > 0) {
|
||||||
|
mDownloadTasks.remove(i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消下载任务
|
||||||
|
*
|
||||||
|
* @param downloadTaskId
|
||||||
|
*/
|
||||||
|
public void cancelDownloadTask(String downloadTaskId) {
|
||||||
|
for (int i = 0; i < mDownloadTasks.size(); i++) {
|
||||||
|
DownloadTask task = mDownloadTasks.get(i);
|
||||||
|
if (task.getTaskId().equals(downloadTaskId)) {
|
||||||
|
if (i == 0) {
|
||||||
|
|
||||||
|
DownloadTaskThreadManager downloadTaskThreadManager = task.getDownloadTaskThreadManager();
|
||||||
|
downloadTaskThreadManager.cancelTaskThread();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskCancel(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除任务
|
||||||
|
*
|
||||||
|
* @param task
|
||||||
|
*/
|
||||||
|
private void removeTask(DownloadTask task) {
|
||||||
|
for (int i = 0; i < mDownloadTasks.size(); i++) {
|
||||||
|
DownloadTask temp = mDownloadTasks.get(i);
|
||||||
|
if (temp.getTaskId().equals(task.getTaskId())) {
|
||||||
|
if (mDownloadTasks.size() > 0) {
|
||||||
|
mDownloadTasks.remove(i);
|
||||||
|
mWorkerHandler.removeCallbacks(temp.getDownloadTaskThreadManager());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DownloadTask> getDownloadTasks() {
|
||||||
|
return mDownloadTasks;
|
||||||
|
}
|
||||||
|
}
|
||||||
318
app/src/main/java/com/zlm/down/thread/DownloadTaskThread.java
Normal file
318
app/src/main/java/com/zlm/down/thread/DownloadTaskThread.java
Normal file
|
|
@ -0,0 +1,318 @@
|
||||||
|
package com.zlm.down.thread;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.down.interfaces.IDownloadThreadEvent;
|
||||||
|
import com.zlm.hp.http.HttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
import com.zlm.hp.util.NetUtil;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLSession;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载任务线程
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-04 23:14
|
||||||
|
**/
|
||||||
|
public class DownloadTaskThread extends Thread {
|
||||||
|
/**
|
||||||
|
* 连接超时时间
|
||||||
|
*/
|
||||||
|
private final int CONNECTTIME = 30 * 1000;
|
||||||
|
/**
|
||||||
|
* 读取数据超时时间
|
||||||
|
*/
|
||||||
|
private final int READTIME = 30 * 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private final int BUFF_LENGTH = 1024 * 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是wifi条件
|
||||||
|
*/
|
||||||
|
private boolean isAskWifi;
|
||||||
|
/**
|
||||||
|
* 是否完成任务
|
||||||
|
*/
|
||||||
|
private boolean isFinish = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务
|
||||||
|
*/
|
||||||
|
private DownloadTask mDownloadTask;
|
||||||
|
/**
|
||||||
|
* 线程id
|
||||||
|
*/
|
||||||
|
private int mThreadId = -1;
|
||||||
|
/**
|
||||||
|
* 旧的开始位置
|
||||||
|
*/
|
||||||
|
private int mStartPos = 0;
|
||||||
|
/**
|
||||||
|
* 新的开始位置
|
||||||
|
*/
|
||||||
|
private int mNewStartPos = 0;
|
||||||
|
/**
|
||||||
|
* 结束位置
|
||||||
|
*/
|
||||||
|
private int mEndPos = 0;
|
||||||
|
/**
|
||||||
|
* 下载大小
|
||||||
|
*/
|
||||||
|
private int mDownloadedSize = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否能继续下载
|
||||||
|
*/
|
||||||
|
private volatile boolean isCanDownload = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临时文件
|
||||||
|
*/
|
||||||
|
private RandomAccessFile mItemFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程下载任务回调
|
||||||
|
*/
|
||||||
|
private IDownloadThreadEvent mIDownloadThreadEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
public DownloadTaskThread(Context context, int threadId, int startPos, int endPos,
|
||||||
|
DownloadTask downloadTask, IDownloadThreadEvent downloadThreadEvent, boolean askWifi) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mThreadId = threadId;
|
||||||
|
this.mStartPos = startPos;
|
||||||
|
this.mEndPos = endPos;
|
||||||
|
this.mDownloadTask = downloadTask;
|
||||||
|
this.mIDownloadThreadEvent = downloadThreadEvent;
|
||||||
|
this.isAskWifi = askWifi;
|
||||||
|
mDownloadedSize = mIDownloadThreadEvent.getTaskThreadDownloadedSize(mDownloadTask, mThreadId);
|
||||||
|
// 设置新的开始位置
|
||||||
|
mNewStartPos = mStartPos + mDownloadedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新下载进程
|
||||||
|
*/
|
||||||
|
private Thread mUpdateDownloadThread = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (isCanDownload && !isFinish) {
|
||||||
|
synchronized (this) {
|
||||||
|
int taskThreadDownloadedSize = getDownloadedSize();
|
||||||
|
//更新任务线程
|
||||||
|
if (mIDownloadThreadEvent != null && !isFinish) {
|
||||||
|
mIDownloadThreadEvent.taskThreadDownloading(mDownloadTask, mThreadId, taskThreadDownloadedSize);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mUpdateDownloadThread.start();
|
||||||
|
if (mEndPos > mNewStartPos) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
URL url = new URL(mDownloadTask.getTaskUrl());
|
||||||
|
// 获取文件输入流,读取文件内容
|
||||||
|
InputStream is = getUrlInputStream(mDownloadTask.getTaskUrl(), url);
|
||||||
|
|
||||||
|
//
|
||||||
|
mItemFile = new RandomAccessFile(mDownloadTask.getTaskTempPath(), "rw");
|
||||||
|
mItemFile.seek(mNewStartPos);
|
||||||
|
|
||||||
|
byte[] buff = new byte[BUFF_LENGTH];
|
||||||
|
int length = -1;
|
||||||
|
while ((length = is.read(buff)) > 0
|
||||||
|
&& (mStartPos + mDownloadedSize) < mEndPos && isCanDownload) {
|
||||||
|
|
||||||
|
if (!NetUtil.isNetworkAvailable(mContext)) {
|
||||||
|
|
||||||
|
|
||||||
|
if (mIDownloadThreadEvent != null) {
|
||||||
|
//无网络
|
||||||
|
mIDownloadThreadEvent.taskThreadError(mDownloadTask, mThreadId,
|
||||||
|
HttpReturnResult.ERROR_MSG_NONET);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAskWifi && !NetUtil.isWifiConnected(mContext)) {
|
||||||
|
// 不是wifi
|
||||||
|
if (mIDownloadThreadEvent != null) {
|
||||||
|
mIDownloadThreadEvent.taskThreadError(mDownloadTask, mThreadId,
|
||||||
|
HttpReturnResult.ERROR_MSG_NOWIFI);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mItemFile.write(buff, 0, length);
|
||||||
|
mDownloadedSize += length;
|
||||||
|
}
|
||||||
|
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
if (mIDownloadThreadEvent != null) {
|
||||||
|
mIDownloadThreadEvent.taskThreadError(mDownloadTask, mThreadId,
|
||||||
|
HttpReturnResult.ERROR_MSG_NET);
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (mItemFile != null)
|
||||||
|
try {
|
||||||
|
mItemFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//在允许下载的状态下,说明下载完成
|
||||||
|
if (isCanDownload) {
|
||||||
|
isFinish = true;
|
||||||
|
mUpdateDownloadThread.interrupt();
|
||||||
|
mDownloadedSize = mEndPos - mStartPos;
|
||||||
|
if (mIDownloadThreadEvent != null)
|
||||||
|
mIDownloadThreadEvent.taskThreadFinish(mDownloadTask, mThreadId,
|
||||||
|
getDownloadedSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param taskUrl
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private InputStream getUrlInputStream(String taskUrl, URL url) throws Exception {
|
||||||
|
if (taskUrl.startsWith("https://")) {
|
||||||
|
HttpsURLConnection conn = getHttpsConnection(url);
|
||||||
|
// 设置连接超时时间
|
||||||
|
conn.setConnectTimeout(CONNECTTIME);
|
||||||
|
// 设置读取数据超时时间
|
||||||
|
conn.setReadTimeout(READTIME);
|
||||||
|
HttpUtil.seURLConnectiontHeader(conn);
|
||||||
|
conn.setRequestProperty("Range", "bytes=" + mNewStartPos + "-"
|
||||||
|
+ mEndPos);
|
||||||
|
return conn.getInputStream();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
HttpURLConnection conn = getHttpConnection(url);
|
||||||
|
// 设置连接超时时间
|
||||||
|
conn.setConnectTimeout(CONNECTTIME);
|
||||||
|
// 设置读取数据超时时间
|
||||||
|
conn.setReadTimeout(READTIME);
|
||||||
|
HttpUtil.seURLConnectiontHeader(conn);
|
||||||
|
conn.setRequestProperty("Range", "bytes=" + mNewStartPos + "-"
|
||||||
|
+ mEndPos);
|
||||||
|
return conn.getInputStream();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private HttpsURLConnection getHttpsConnection(URL url) throws Exception {
|
||||||
|
|
||||||
|
// 创建SSLContext
|
||||||
|
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||||
|
TrustManager[] tm = {new HttpClient.IgnoreSSLTrustManager()};
|
||||||
|
// 初始化
|
||||||
|
sslContext.init(null, tm, new SecureRandom());
|
||||||
|
// 获取SSLSocketFactory对象
|
||||||
|
SSLSocketFactory ssf = sslContext.getSocketFactory();
|
||||||
|
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
|
||||||
|
HttpUtil.seURLConnectiontHeader(conn);
|
||||||
|
// https忽略证书
|
||||||
|
conn.setHostnameVerifier(new HostnameVerifier() {
|
||||||
|
@Override
|
||||||
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
|
// 强行返回true 即验证成功
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
conn.setSSLSocketFactory(ssf);
|
||||||
|
|
||||||
|
return conn;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param url
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private HttpURLConnection getHttpConnection(URL url) throws Exception {
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* 获取总下载进度
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
public int getDownloadedSize() {
|
||||||
|
int tempDownloadedSize = Math.min(mDownloadedSize,
|
||||||
|
(mEndPos - mStartPos));
|
||||||
|
return tempDownloadedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停
|
||||||
|
*/
|
||||||
|
public void pause() {
|
||||||
|
isCanDownload = false;
|
||||||
|
mUpdateDownloadThread.interrupt();
|
||||||
|
//更新任务线程
|
||||||
|
if (mIDownloadThreadEvent != null) {
|
||||||
|
int taskThreadDownloadedSize = getDownloadedSize();
|
||||||
|
if (taskThreadDownloadedSize != 0)
|
||||||
|
mIDownloadThreadEvent.taskThreadPause(mDownloadTask, mThreadId, taskThreadDownloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消
|
||||||
|
*/
|
||||||
|
public void cancel() {
|
||||||
|
isCanDownload = false;
|
||||||
|
mUpdateDownloadThread.interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,441 @@
|
||||||
|
package com.zlm.down.thread;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.down.interfaces.IDownloadTaskEvent;
|
||||||
|
import com.zlm.down.interfaces.IDownloadThreadEvent;
|
||||||
|
import com.zlm.hp.http.HttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.util.FileUtil;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLSession;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载任务线程管理
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-05 0:19
|
||||||
|
**/
|
||||||
|
|
||||||
|
public class DownloadTaskThreadManager implements Runnable {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
/**
|
||||||
|
* 任务线程
|
||||||
|
*/
|
||||||
|
private List<DownloadTaskThread> mDownloadTaskThreads = new ArrayList<DownloadTaskThread>();
|
||||||
|
/**
|
||||||
|
* 任务
|
||||||
|
*/
|
||||||
|
private DownloadTask mDownloadTask;
|
||||||
|
|
||||||
|
private Handler mWorkerHandler;
|
||||||
|
/**
|
||||||
|
* 是否能下载任务
|
||||||
|
*/
|
||||||
|
private volatile boolean isCanDownload = false;
|
||||||
|
/**
|
||||||
|
* 下载任务回调
|
||||||
|
*/
|
||||||
|
private IDownloadTaskEvent mIDownloadTaskEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载线程任务回调
|
||||||
|
*/
|
||||||
|
private IDownloadThreadEvent mIDownloadThreadEvent = new IDownloadThreadEvent() {
|
||||||
|
@Override
|
||||||
|
public int getTaskThreadDownloadedSize(DownloadTask task, int threadId) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
return mIDownloadTaskEvent.getTaskThreadDownloadedSize(task, threadId);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadDownloading(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadDownloading(task, threadId, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadPause(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadPause(task, threadId, downloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadFinish(DownloadTask task, int threadId, int downloadedSize) {
|
||||||
|
synchronized (this) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadFinish(task, threadId, downloadedSize);
|
||||||
|
}
|
||||||
|
int taskDownloadedSize = getTaskDownloadedSize();
|
||||||
|
if (taskDownloadedSize >= mDownloadTask.getTaskFileSize() && !isCanDownload) {
|
||||||
|
isCanDownload = true;
|
||||||
|
mUpdateDownloadThread.interrupt();
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskFinish(task, taskDownloadedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task.getTaskPath() != null) {
|
||||||
|
// 临时文件复制到真正的路径
|
||||||
|
copyFile(task.getTaskTempPath(), task.getTaskPath());
|
||||||
|
}
|
||||||
|
synchronized (mWorkerHandler) {
|
||||||
|
mWorkerHandler.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void taskThreadError(DownloadTask task, int threadId, String msg) {
|
||||||
|
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskThreadError(task, threadId, msg);
|
||||||
|
mIDownloadTaskEvent.taskError(task, msg);
|
||||||
|
}
|
||||||
|
synchronized (mWorkerHandler) {
|
||||||
|
mWorkerHandler.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public DownloadTaskThreadManager(Context context, Handler workerHandler, DownloadTask downloadTask, IDownloadTaskEvent downloadTaskEvent) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
this.mDownloadTask = downloadTask;
|
||||||
|
this.mIDownloadTaskEvent = downloadTaskEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
boolean askWifi = false;
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
askWifi = mIDownloadTaskEvent.getAskWifi();
|
||||||
|
}
|
||||||
|
boolean resultFlag = startDownloadTask(mContext, askWifi);
|
||||||
|
if (!resultFlag) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mUpdateDownloadThread.start();
|
||||||
|
try {
|
||||||
|
synchronized (mWorkerHandler) {
|
||||||
|
mWorkerHandler.wait();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载任务
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
private boolean startDownloadTask(Context context, boolean askWifi) {
|
||||||
|
// 1.获取文件的长度
|
||||||
|
// 2.对文件进行多线程下载
|
||||||
|
try {
|
||||||
|
String taskUrl = mDownloadTask.getTaskUrl();
|
||||||
|
if (TextUtils.isEmpty(taskUrl)) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskError(mDownloadTask, HttpReturnResult.ERROR_MSG_NULLURL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1获取文件的长度
|
||||||
|
int fileLength = (int) mDownloadTask.getTaskFileSize();
|
||||||
|
if (fileLength == 0)
|
||||||
|
fileLength = getFileLength(taskUrl);
|
||||||
|
if (fileLength <= 0) {
|
||||||
|
// 获取文件的长度失败
|
||||||
|
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskError(mDownloadTask, HttpReturnResult.ERROR_FILE_ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果根目录不为空,则判断空间大小是否能继续下载
|
||||||
|
String rootPath = mDownloadTask.getRootPath();
|
||||||
|
if (!TextUtils.isEmpty(rootPath)) {
|
||||||
|
long memorySize = FileUtil.getMemorySize(rootPath);
|
||||||
|
if (2 * fileLength > memorySize) {
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskError(mDownloadTask, HttpReturnResult.ERROR_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mDownloadTask.setTaskFileSize(fileLength);
|
||||||
|
//
|
||||||
|
File destFile = new File(mDownloadTask.getTaskTempPath());
|
||||||
|
if (!destFile.getParentFile().exists()) {
|
||||||
|
destFile.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
//目标文件不存在
|
||||||
|
if (!destFile.exists()) {
|
||||||
|
|
||||||
|
// 临时文件
|
||||||
|
RandomAccessFile tempFile = new RandomAccessFile(
|
||||||
|
mDownloadTask.getTaskTempPath(), "rw");
|
||||||
|
tempFile.setLength(fileLength);
|
||||||
|
tempFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 2对文件进行多线程下载
|
||||||
|
int threadNum = mDownloadTask.getThreadNum();
|
||||||
|
int avg = fileLength / threadNum;
|
||||||
|
for (int i = 0; i < threadNum; i++) {
|
||||||
|
int threadId = (i + 1);
|
||||||
|
int startPos = i * avg;
|
||||||
|
int endPos = 0;
|
||||||
|
if (i == (threadNum - 1)) {
|
||||||
|
endPos = fileLength;
|
||||||
|
} else {
|
||||||
|
endPos = startPos + avg;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
DownloadTaskThread taskThread = new DownloadTaskThread(context, threadId, startPos,
|
||||||
|
endPos, mDownloadTask, mIDownloadThreadEvent, askWifi);
|
||||||
|
mDownloadTaskThreads.add(taskThread);
|
||||||
|
taskThread.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// 下载出错
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskError(mDownloadTask, HttpReturnResult.ERROR_MSG_NET);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新下载进程
|
||||||
|
*/
|
||||||
|
private Thread mUpdateDownloadThread = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (!isCanDownload) {
|
||||||
|
synchronized (this) {
|
||||||
|
int taskDownloadedSize = 0;
|
||||||
|
try {
|
||||||
|
taskDownloadedSize = getTaskDownloadedSize();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
//更新任务线程
|
||||||
|
if (mIDownloadTaskEvent != null && !isCanDownload) {
|
||||||
|
if (taskDownloadedSize != 0)
|
||||||
|
mIDownloadTaskEvent.taskDownloading(mDownloadTask, taskDownloadedSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下载文件的长度
|
||||||
|
*
|
||||||
|
* @param downloadUrl
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
private int getFileLength(String downloadUrl) {
|
||||||
|
if (downloadUrl.startsWith("https://")) {
|
||||||
|
return getHttpsFileLength(downloadUrl);
|
||||||
|
}
|
||||||
|
return getHttpFileLength(downloadUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取https文件长度
|
||||||
|
*
|
||||||
|
* @param downloadUrl
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getHttpsFileLength(String downloadUrl) {
|
||||||
|
int length = 0;
|
||||||
|
try {
|
||||||
|
URL url = new URL(downloadUrl);
|
||||||
|
// 创建SSLContext
|
||||||
|
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||||
|
TrustManager[] tm = {new HttpClient.IgnoreSSLTrustManager()};
|
||||||
|
// 初始化
|
||||||
|
sslContext.init(null, tm, new SecureRandom());
|
||||||
|
// 获取SSLSocketFactory对象
|
||||||
|
SSLSocketFactory ssf = sslContext.getSocketFactory();
|
||||||
|
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
|
||||||
|
HttpUtil.seURLConnectiontHeader(conn);
|
||||||
|
// https忽略证书
|
||||||
|
conn.setHostnameVerifier(new HostnameVerifier() {
|
||||||
|
@Override
|
||||||
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
|
// 强行返回true 即验证成功
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
conn.setSSLSocketFactory(ssf);
|
||||||
|
|
||||||
|
length = conn.getContentLength();
|
||||||
|
conn.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取http文件长度
|
||||||
|
*
|
||||||
|
* @param downloadUrl
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getHttpFileLength(String downloadUrl) {
|
||||||
|
int length = 0;
|
||||||
|
try {
|
||||||
|
URL url = new URL(downloadUrl);
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
HttpUtil.seURLConnectiontHeader(conn);
|
||||||
|
length = conn.getContentLength();
|
||||||
|
conn.disconnect();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停任务
|
||||||
|
*/
|
||||||
|
public void pauseTaskThread() {
|
||||||
|
isCanDownload = true;
|
||||||
|
mUpdateDownloadThread.interrupt();
|
||||||
|
|
||||||
|
for (int i = 0; i < mDownloadTaskThreads.size(); i++) {
|
||||||
|
DownloadTaskThread taskThread = mDownloadTaskThreads.get(i);
|
||||||
|
taskThread.pause();
|
||||||
|
}
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskPause(mDownloadTask, getTaskDownloadedSize());
|
||||||
|
}
|
||||||
|
synchronized (mWorkerHandler) {
|
||||||
|
mWorkerHandler.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取任务的总下载进度
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
public int getTaskDownloadedSize() {
|
||||||
|
int downloadedSize = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < mDownloadTaskThreads.size(); i++) {
|
||||||
|
DownloadTaskThread taskThread = mDownloadTaskThreads.get(i);
|
||||||
|
downloadedSize += taskThread.getDownloadedSize();
|
||||||
|
}
|
||||||
|
return downloadedSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消任务
|
||||||
|
*/
|
||||||
|
public void cancelTaskThread() {
|
||||||
|
isCanDownload = true;
|
||||||
|
mUpdateDownloadThread.interrupt();
|
||||||
|
|
||||||
|
for (int i = 0; i < mDownloadTaskThreads.size(); i++) {
|
||||||
|
DownloadTaskThread taskThread = mDownloadTaskThreads.get(i);
|
||||||
|
taskThread.cancel();
|
||||||
|
}
|
||||||
|
if (mIDownloadTaskEvent != null) {
|
||||||
|
mIDownloadTaskEvent.taskCancel(mDownloadTask);
|
||||||
|
}
|
||||||
|
synchronized (mWorkerHandler) {
|
||||||
|
mWorkerHandler.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制文件
|
||||||
|
*
|
||||||
|
* @param oldPath 旧文件路径
|
||||||
|
* @param newPath 新文件路径
|
||||||
|
* @author zhangliangming
|
||||||
|
* @date 2017年7月8日
|
||||||
|
*/
|
||||||
|
private void copyFile(String oldPath, String newPath) {
|
||||||
|
File oldfile = null;
|
||||||
|
try {
|
||||||
|
int bytesum = 0;
|
||||||
|
int byteread = 0;
|
||||||
|
oldfile = new File(oldPath);
|
||||||
|
if (oldfile.exists()) { // 文件存在时
|
||||||
|
InputStream inStream = new FileInputStream(oldPath); // 读入原文件
|
||||||
|
FileOutputStream fs = new FileOutputStream(newPath);
|
||||||
|
byte[] buffer = new byte[1444];
|
||||||
|
while ((byteread = inStream.read(buffer)) != -1) {
|
||||||
|
bytesum += byteread; // 字节数 文件大小
|
||||||
|
fs.write(buffer, 0, byteread);
|
||||||
|
}
|
||||||
|
inStream.close();
|
||||||
|
fs.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (oldfile != null) {
|
||||||
|
System.gc();
|
||||||
|
oldfile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.zlm.hp.PageTransformer;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.support.v4.view.ViewPager;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* viewpage动画
|
||||||
|
*/
|
||||||
|
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
|
||||||
|
private static final float MIN_SCALE = 0.85f;
|
||||||
|
private static final float MIN_ALPHA = 0.5f;
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
public void transformPage(View view, float position) {
|
||||||
|
int pageWidth = view.getWidth();
|
||||||
|
int pageHeight = view.getHeight();
|
||||||
|
|
||||||
|
Log.e("TAG", view + " , " + position + "");
|
||||||
|
|
||||||
|
if (position < -1) { // [-Infinity,-1)
|
||||||
|
// This page is way off-screen to the left.
|
||||||
|
view.setAlpha(0);
|
||||||
|
|
||||||
|
} else if (position <= 1) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0
|
||||||
|
{ // [-1,1]
|
||||||
|
// Modify the default slide transition to shrink the page as well
|
||||||
|
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
|
||||||
|
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
|
||||||
|
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
|
||||||
|
if (position < 0) {
|
||||||
|
view.setTranslationX(horzMargin - vertMargin / 2);
|
||||||
|
} else {
|
||||||
|
view.setTranslationX(-horzMargin + vertMargin / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale the page down (between MIN_SCALE and 1)
|
||||||
|
view.setScaleX(scaleFactor);
|
||||||
|
view.setScaleY(scaleFactor);
|
||||||
|
|
||||||
|
// Fade the page relative to its size.
|
||||||
|
view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE)
|
||||||
|
/ (1 - MIN_SCALE) * (1 - MIN_ALPHA));
|
||||||
|
|
||||||
|
} else { // (1,+Infinity]
|
||||||
|
// This page is way off-screen to the right.
|
||||||
|
view.setAlpha(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
667
app/src/main/java/com/zlm/hp/adapter/AudioAdapter.java
Normal file
667
app/src/main/java/com/zlm/hp/adapter/AudioAdapter.java
Normal file
|
|
@ -0,0 +1,667 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewStub;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
import android.view.animation.Animation;
|
||||||
|
import android.view.animation.TranslateAnimation;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.db.util.AudioInfoDB;
|
||||||
|
import com.zlm.hp.db.util.DownloadThreadInfoDB;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.fragment.SongFragment;
|
||||||
|
import com.zlm.hp.manager.AudioPlayerManager;
|
||||||
|
import com.zlm.hp.manager.DownloadAudioManager;
|
||||||
|
import com.zlm.hp.manager.OnLineAudioManager;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.FileUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.widget.IconfontImageButtonTextView;
|
||||||
|
import com.zlm.hp.widget.ListItemRelativeLayout;
|
||||||
|
import com.zlm.hp.widget.PlayListBGRelativeLayout;
|
||||||
|
import com.zlm.libs.widget.RotateLayout;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌曲适配器
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-09-24 1:16
|
||||||
|
**/
|
||||||
|
public class AudioAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ArrayList<AudioInfo> mDatas;
|
||||||
|
private int mSongType;
|
||||||
|
private String mOldPlayHash = "";
|
||||||
|
private ConfigInfo mConfigInfo;
|
||||||
|
/**
|
||||||
|
* 歌曲详情
|
||||||
|
*/
|
||||||
|
private boolean mIsSongInfoPopShowing = false;
|
||||||
|
private ViewStub mViewStubSongInfo;
|
||||||
|
private RelativeLayout mSongInfoPopLayout;
|
||||||
|
private PlayListBGRelativeLayout mSongInfoPopRL;
|
||||||
|
/**
|
||||||
|
* 菜单打开索引
|
||||||
|
*/
|
||||||
|
private int mMenuOpenIndex = -1;
|
||||||
|
|
||||||
|
public AudioAdapter(Context context, ArrayList<AudioInfo> datas, int songType) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
this.mSongType = songType;
|
||||||
|
mConfigInfo = ConfigInfo.obtain();
|
||||||
|
mOldPlayHash = mConfigInfo.getPlayHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_song, null, false);
|
||||||
|
AudioViewHolder holder = new AudioViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof AudioViewHolder && position < mDatas.size()) {
|
||||||
|
AudioInfo audioInfo = mDatas.get(position);
|
||||||
|
reshViewHolder(position, (AudioViewHolder) viewHolder, audioInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void resetMenuOpenIndex() {
|
||||||
|
mMenuOpenIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新ui
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(final int position, final AudioViewHolder viewHolder, final AudioInfo audioInfo) {
|
||||||
|
//1更多按钮点击事件
|
||||||
|
viewHolder.getItemMoreImg().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (position != mMenuOpenIndex) {
|
||||||
|
if (mMenuOpenIndex != -1) {
|
||||||
|
notifyItemChanged(mMenuOpenIndex);
|
||||||
|
}
|
||||||
|
mMenuOpenIndex = position;
|
||||||
|
notifyItemChanged(mMenuOpenIndex);
|
||||||
|
} else {
|
||||||
|
if (mMenuOpenIndex != -1) {
|
||||||
|
notifyItemChanged(mMenuOpenIndex);
|
||||||
|
mMenuOpenIndex = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//2展开或者隐藏菜单
|
||||||
|
if (position == mMenuOpenIndex) {
|
||||||
|
if (mSongType == SongFragment.SONG_TYPE_LOCAL) {
|
||||||
|
//本地歌曲
|
||||||
|
//喜欢/不喜欢
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.GONE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
//下载/未下载
|
||||||
|
viewHolder.getDownloadImg().setVisibility(View.GONE);
|
||||||
|
viewHolder.getDownloadedImg().setVisibility(View.GONE);
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
if (mSongType == SongFragment.SONG_TYPE_LIKE) {
|
||||||
|
//喜欢
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.GONE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.GONE);
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
if (mSongType == SongFragment.SONG_TYPE_RECENT) {
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteImgBtn().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
//喜欢/不喜欢
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.GONE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//下载完成
|
||||||
|
if (audioInfo.getType() == AudioInfo.TYPE_LOCAL || AudioInfoDB.isDownloadedAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
viewHolder.getDownloadImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getDownloadedImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getDownloadImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getDownloadedImg().setVisibility(View.INVISIBLE);
|
||||||
|
int downloadedSize = DownloadThreadInfoDB.getDownloadedSize(mContext, audioInfo.getHash(), OnLineAudioManager.mThreadNum);
|
||||||
|
if (downloadedSize >= audioInfo.getFileSize()) {
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewHolder.getMenuLinearLayout().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getMenuLinearLayout().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (audioInfo.getHash().equals(mConfigInfo.getPlayHash())) {
|
||||||
|
viewHolder.getStatusView().setVisibility(View.VISIBLE);
|
||||||
|
mOldPlayHash = audioInfo.getHash();
|
||||||
|
} else {
|
||||||
|
viewHolder.getStatusView().setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
viewHolder.getSongIndexTv().setText(((position + 1) < 10 ? "0" + (position + 1) : (position + 1) + ""));
|
||||||
|
viewHolder.getSongIndexTv().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getSongNameTv().setText(audioInfo.getSongName());
|
||||||
|
viewHolder.getSingerNameTv().setText(audioInfo.getSingerName());
|
||||||
|
if(audioInfo.getMvPath()!=null && audioInfo.getMvPath().length()>0) {
|
||||||
|
if(audioInfo.IsOnlyMV()) {
|
||||||
|
viewHolder.getIsMVTv().setText("[仅MV]");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
viewHolder.getIsMVTv().setText("[MV]");
|
||||||
|
}
|
||||||
|
viewHolder.getIsMVTv().setVisibility(View.VISIBLE);
|
||||||
|
try {
|
||||||
|
File mvFile = new File(audioInfo.getMvPath());
|
||||||
|
String MVFileName = FileUtil.getFileNameWithoutExt(mvFile);
|
||||||
|
if (MVFileName.contains("(高清)")) {
|
||||||
|
viewHolder.getMVQSDTv().setText("[高清]");
|
||||||
|
viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
} else if (MVFileName.contains("(超清)")) {
|
||||||
|
viewHolder.getMVQSDTv().setText("[超清]");
|
||||||
|
viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
} else if (MVFileName.contains("(蓝光)")) {
|
||||||
|
viewHolder.getMVQSDTv().setText("[蓝光]");
|
||||||
|
viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
} else if (MVFileName.contains("(标清)")) {
|
||||||
|
viewHolder.getMVQSDTv().setText("[标清]");
|
||||||
|
viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getMVQSDTv().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
viewHolder.getIsMVTv().setVisibility(View.GONE);
|
||||||
|
viewHolder.getMVQSDTv().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
//下载完成
|
||||||
|
if (audioInfo.getType() == AudioInfo.TYPE_LOCAL || AudioInfoDB.isDownloadedAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
int downloadedSize = DownloadThreadInfoDB.getDownloadedSize(mContext, audioInfo.getHash(), OnLineAudioManager.mThreadNum);
|
||||||
|
if (downloadedSize >= audioInfo.getFileSize()) {
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
//列表点击后,还原更多菜单
|
||||||
|
if (mMenuOpenIndex != -1) {
|
||||||
|
notifyItemChanged(mMenuOpenIndex);
|
||||||
|
mMenuOpenIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int oldIndex = getAudioIndex(mConfigInfo.getPlayHash());
|
||||||
|
if (oldIndex == position) {
|
||||||
|
AudioPlayerManager.newInstance(mContext).playOrPause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mOldPlayHash = audioInfo.getHash();
|
||||||
|
if (mSongType == SongFragment.SONG_TYPE_LOCAL) {
|
||||||
|
//如果是本地歌曲列表,点击列表时,需要替换当前的播放列表为本地歌曲列表
|
||||||
|
AudioPlayerManager.newInstance(mContext).playSong(AudioInfoDB.getLocalAudios(mContext), audioInfo);
|
||||||
|
} else {
|
||||||
|
AudioPlayerManager.newInstance(mContext).playSongAndAdd(audioInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldIndex != -1) {
|
||||||
|
notifyItemChanged(oldIndex);
|
||||||
|
}
|
||||||
|
int newIndex = getAudioIndex(audioInfo.getHash());
|
||||||
|
if (newIndex != -1) {
|
||||||
|
notifyItemChanged(newIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//喜欢/不喜欢
|
||||||
|
viewHolder.getUnLikeImgBtn().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (!AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.addLikeAudio(mContext, audioInfo, true);
|
||||||
|
if (result) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.GONE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.like_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
viewHolder.getLikedImgBtn().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.deleteLikeAudio(mContext, audioInfo.getHash(), true);
|
||||||
|
if (result) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.GONE);
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.unlike_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteImgBtn().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//隐藏更多菜单
|
||||||
|
mMenuOpenIndex = -1;
|
||||||
|
viewHolder.getMenuLinearLayout().setVisibility(View.GONE);
|
||||||
|
|
||||||
|
if (mSongType == SongFragment.SONG_TYPE_LIKE) {
|
||||||
|
//移除喜欢
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.deleteLikeAudio(mContext, audioInfo.getHash(), true);
|
||||||
|
if (result) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.GONE);
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.unlike_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (mSongType == SongFragment.SONG_TYPE_RECENT) {
|
||||||
|
//最近移除
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (AudioInfoDB.isRecentAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.deleteRecentAudio(mContext, audioInfo.getHash(), true);
|
||||||
|
if (result) {
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.remove_success_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//本地歌曲删除
|
||||||
|
//1.先判断是否是当前正在播放的歌曲
|
||||||
|
//2.移除歌曲
|
||||||
|
//3.发通知
|
||||||
|
|
||||||
|
String curHash = audioInfo.getHash();
|
||||||
|
//是否是正在播放歌曲
|
||||||
|
boolean flag = mConfigInfo.getPlayHash().equals(audioInfo.getHash());
|
||||||
|
//获取下一首歌曲
|
||||||
|
List<AudioInfo> audioInfos = mConfigInfo.getAudioInfos();
|
||||||
|
AudioInfo nextAudioInfo = null;
|
||||||
|
boolean hasNext = false;
|
||||||
|
int curHashIndex = -1;
|
||||||
|
for (int i = 0; i < audioInfos.size(); i++) {
|
||||||
|
AudioInfo temp = audioInfos.get(i);
|
||||||
|
if (hasNext) {
|
||||||
|
nextAudioInfo = temp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (temp.getHash().equals(curHash)) {
|
||||||
|
curHashIndex = i;
|
||||||
|
if (!flag) break;
|
||||||
|
hasNext = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//播放器如果正在播放
|
||||||
|
if (flag)
|
||||||
|
AudioPlayerManager.newInstance(mContext).stop();
|
||||||
|
//移除数据
|
||||||
|
if (curHashIndex != -1) {
|
||||||
|
audioInfos.remove(curHashIndex);
|
||||||
|
mConfigInfo.setAudioInfos(audioInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除歌曲
|
||||||
|
boolean deleteFlag = AudioInfoDB.deleteAudio(mContext, audioInfo.getHash(), true);
|
||||||
|
if (deleteFlag) {
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.remove_success_tip_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果是正在播放歌曲,发播放下一首通知
|
||||||
|
if (!flag) return;
|
||||||
|
if (nextAudioInfo != null) {
|
||||||
|
mConfigInfo.setPlayHash(nextAudioInfo.getHash());
|
||||||
|
nextAudioInfo.setPlayProgress(0);
|
||||||
|
AudioBroadcastReceiver.sendPlayInitReceiver(mContext, nextAudioInfo);
|
||||||
|
} else {
|
||||||
|
mConfigInfo.setPlayHash("");
|
||||||
|
AudioBroadcastReceiver.sendNullReceiver(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
mConfigInfo.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//未下载
|
||||||
|
viewHolder.getDownloadImg().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean flag = DownloadAudioManager.newInstance(mContext).isDownloadAudioExists(audioInfo.getHash());
|
||||||
|
if (flag) {
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.undownload_tip_text));
|
||||||
|
} else {
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.download_tip_text));
|
||||||
|
DownloadAudioManager.newInstance(mContext).addTask(audioInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
/***
|
||||||
|
* 刷新
|
||||||
|
*/
|
||||||
|
public void reshViewHolder(String playHash) {
|
||||||
|
int oldIndex = getAudioIndex(mOldPlayHash);
|
||||||
|
if (oldIndex != -1) {
|
||||||
|
mOldPlayHash = "";
|
||||||
|
notifyItemChanged(oldIndex);
|
||||||
|
}
|
||||||
|
int newIndex = getAudioIndex(playHash);
|
||||||
|
if (newIndex != -1) {
|
||||||
|
notifyItemChanged(newIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌曲索引
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getAudioIndex(String playHash) {
|
||||||
|
if (TextUtils.isEmpty(playHash)) return -1;
|
||||||
|
if (mDatas != null && mDatas.size() > 0) {
|
||||||
|
for (int i = 0; i < mDatas.size(); i++) {
|
||||||
|
AudioInfo temp = mDatas.get(i);
|
||||||
|
if (temp.getHash().equals(playHash)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
class AudioViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更多按钮
|
||||||
|
*/
|
||||||
|
private ImageView moreImg;
|
||||||
|
/**
|
||||||
|
* 状态标记view
|
||||||
|
*/
|
||||||
|
private View statusView;
|
||||||
|
/**
|
||||||
|
* 歌曲索引
|
||||||
|
*/
|
||||||
|
private TextView songIndexTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲名称
|
||||||
|
*/
|
||||||
|
private TextView songNameTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手名称
|
||||||
|
*/
|
||||||
|
private TextView singerNameTv;
|
||||||
|
/**
|
||||||
|
* 是否有MV
|
||||||
|
*/
|
||||||
|
private TextView IsMVTv;
|
||||||
|
/**
|
||||||
|
* MV清晰度
|
||||||
|
*/
|
||||||
|
private TextView MVQSDTv;
|
||||||
|
/**
|
||||||
|
* 是否存在本地
|
||||||
|
*/
|
||||||
|
private ImageView islocalImg;
|
||||||
|
|
||||||
|
//、、、、、、、、、、、、、、、、、、、、更多菜单、、、、、、、、、、、、、、、、、、、、、、、、
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更多按钮
|
||||||
|
*/
|
||||||
|
private ImageView itemMoreImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单
|
||||||
|
*/
|
||||||
|
private LinearLayout menuLinearLayout;
|
||||||
|
/**
|
||||||
|
* 不喜欢按钮
|
||||||
|
*/
|
||||||
|
private IconfontImageButtonTextView unLikeImgBtn;
|
||||||
|
/**
|
||||||
|
* 不喜欢按钮
|
||||||
|
*/
|
||||||
|
private IconfontImageButtonTextView likedImgBtn;
|
||||||
|
/**
|
||||||
|
* 下载布局
|
||||||
|
*/
|
||||||
|
private RelativeLayout downloadParentRl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载完成按钮
|
||||||
|
*/
|
||||||
|
private ImageView downloadedImg;
|
||||||
|
/**
|
||||||
|
* 下载按钮
|
||||||
|
*/
|
||||||
|
private ImageView downloadImg;
|
||||||
|
/**
|
||||||
|
* 信息按钮
|
||||||
|
*/
|
||||||
|
private IconfontImageButtonTextView detailImgBtn;
|
||||||
|
/**
|
||||||
|
* 删除按钮
|
||||||
|
*/
|
||||||
|
private IconfontImageButtonTextView deleteImgBtn;
|
||||||
|
|
||||||
|
public AudioViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getMoreImg() {
|
||||||
|
if (moreImg == null) {
|
||||||
|
moreImg = view.findViewById(R.id.item_more);
|
||||||
|
}
|
||||||
|
return moreImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getStatusView() {
|
||||||
|
if (statusView == null) {
|
||||||
|
statusView = view.findViewById(R.id.status);
|
||||||
|
}
|
||||||
|
return statusView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSongNameTv() {
|
||||||
|
if (songNameTv == null) {
|
||||||
|
songNameTv = view.findViewById(R.id.songName);
|
||||||
|
}
|
||||||
|
return songNameTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSingerNameTv() {
|
||||||
|
if (singerNameTv == null) {
|
||||||
|
singerNameTv = view.findViewById(R.id.singerName);
|
||||||
|
}
|
||||||
|
return singerNameTv;
|
||||||
|
}
|
||||||
|
public TextView getIsMVTv() {
|
||||||
|
if (IsMVTv == null) {
|
||||||
|
IsMVTv = view.findViewById(R.id.isMV);
|
||||||
|
}
|
||||||
|
return IsMVTv;
|
||||||
|
}
|
||||||
|
public TextView getMVQSDTv() {
|
||||||
|
if (MVQSDTv == null) {
|
||||||
|
MVQSDTv = view.findViewById(R.id.MVQSD);
|
||||||
|
}
|
||||||
|
return MVQSDTv;
|
||||||
|
}
|
||||||
|
public ImageView getIslocalImg() {
|
||||||
|
if (islocalImg == null) {
|
||||||
|
islocalImg = view.findViewById(R.id.islocal);
|
||||||
|
}
|
||||||
|
return islocalImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSongIndexTv() {
|
||||||
|
|
||||||
|
if (songIndexTv == null) {
|
||||||
|
songIndexTv = view.findViewById(R.id.songIndex);
|
||||||
|
}
|
||||||
|
return songIndexTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getItemMoreImg() {
|
||||||
|
if (itemMoreImg == null) {
|
||||||
|
itemMoreImg = view.findViewById(R.id.item_more);
|
||||||
|
}
|
||||||
|
return itemMoreImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinearLayout getMenuLinearLayout() {
|
||||||
|
if (menuLinearLayout == null) {
|
||||||
|
menuLinearLayout = view.findViewById(R.id.menu);
|
||||||
|
}
|
||||||
|
return menuLinearLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontImageButtonTextView getLikedImgBtn() {
|
||||||
|
if (likedImgBtn == null) {
|
||||||
|
likedImgBtn = view.findViewById(R.id.liked_menu);
|
||||||
|
}
|
||||||
|
likedImgBtn.setConvert(true);
|
||||||
|
return likedImgBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontImageButtonTextView getUnLikeImgBtn() {
|
||||||
|
if (unLikeImgBtn == null) {
|
||||||
|
unLikeImgBtn = view.findViewById(R.id.unlike_menu);
|
||||||
|
}
|
||||||
|
unLikeImgBtn.setConvert(true);
|
||||||
|
return unLikeImgBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeLayout getDownloadParentRl() {
|
||||||
|
if (downloadParentRl == null) {
|
||||||
|
downloadParentRl = view.findViewById(R.id.downloadParent);
|
||||||
|
}
|
||||||
|
return downloadParentRl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getDownloadedImg() {
|
||||||
|
if (downloadedImg == null) {
|
||||||
|
downloadedImg = view.findViewById(R.id.downloaded_menu);
|
||||||
|
}
|
||||||
|
return downloadedImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getDownloadImg() {
|
||||||
|
if (downloadImg == null) {
|
||||||
|
downloadImg = view.findViewById(R.id.download_menu);
|
||||||
|
}
|
||||||
|
return downloadImg;
|
||||||
|
}
|
||||||
|
public IconfontImageButtonTextView getDeleteImgBtn() {
|
||||||
|
if (deleteImgBtn == null) {
|
||||||
|
deleteImgBtn = view.findViewById(R.id.delete_menu);
|
||||||
|
}
|
||||||
|
deleteImgBtn.setConvert(true);
|
||||||
|
return deleteImgBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
790
app/src/main/java/com/zlm/hp/adapter/DownloadMusicAdapter.java
Normal file
790
app/src/main/java/com/zlm/hp/adapter/DownloadMusicAdapter.java
Normal file
|
|
@ -0,0 +1,790 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.db.util.AudioInfoDB;
|
||||||
|
import com.zlm.hp.db.util.DownloadTaskDB;
|
||||||
|
import com.zlm.hp.db.util.DownloadThreadInfoDB;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.Category;
|
||||||
|
import com.zlm.hp.manager.AudioPlayerManager;
|
||||||
|
import com.zlm.hp.manager.DownloadAudioManager;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.FileUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.widget.IconfontImageButtonTextView;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
import com.zlm.hp.widget.ListItemRelativeLayout;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载音乐
|
||||||
|
* Created by zhangliangming on 2017/9/9.
|
||||||
|
*/
|
||||||
|
public class DownloadMusicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
public final static int CATEGORYTITLE = 0;
|
||||||
|
/**
|
||||||
|
* item正在下载
|
||||||
|
*/
|
||||||
|
public final static int ITEMDownloading = 1;
|
||||||
|
/**
|
||||||
|
* item已经下载
|
||||||
|
*/
|
||||||
|
public final static int ITEMDownloaded = 2;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ArrayList<Category> mDatas;
|
||||||
|
|
||||||
|
private ConfigInfo mConfigInfo;
|
||||||
|
private String mOldPlayHash = "";
|
||||||
|
/**
|
||||||
|
* 菜单打开索引
|
||||||
|
*/
|
||||||
|
private int mMenuOpenIndex = -1;
|
||||||
|
|
||||||
|
|
||||||
|
public DownloadMusicAdapter(Context context, ArrayList<Category> datas) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
mConfigInfo = ConfigInfo.obtain();
|
||||||
|
mOldPlayHash = mConfigInfo.getPlayHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
View view = null;
|
||||||
|
if (viewType == CATEGORYTITLE) {
|
||||||
|
view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_title, null, false);
|
||||||
|
CategoryTitleViewHolder holder = new CategoryTitleViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
} else if (viewType == ITEMDownloading) {
|
||||||
|
view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_downloading, null, false);
|
||||||
|
return new DownloadingMusicViewHolder(view);
|
||||||
|
|
||||||
|
} else if (viewType == ITEMDownloaded) {
|
||||||
|
view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_song, null, false);
|
||||||
|
|
||||||
|
return new DownloadedMusicViewHolder(view);
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
|
||||||
|
if (viewHolder instanceof CategoryTitleViewHolder) {
|
||||||
|
CategoryTitleViewHolder categoryViewHolder = (CategoryTitleViewHolder) viewHolder;
|
||||||
|
String mCategoryName = (String) getItem(position);
|
||||||
|
|
||||||
|
categoryViewHolder.getCategoryTextTextView().setText(
|
||||||
|
mCategoryName + "("
|
||||||
|
+ getItemSizeByCategoryName(mCategoryName) + ")");
|
||||||
|
} else if (viewHolder instanceof DownloadingMusicViewHolder) {
|
||||||
|
AudioInfo audioInfo = (AudioInfo) getItem(position);
|
||||||
|
reshViewHolder(position, (DownloadingMusicViewHolder) viewHolder, audioInfo);
|
||||||
|
} else if (viewHolder instanceof DownloadedMusicViewHolder) {
|
||||||
|
AudioInfo audioInfo = (AudioInfo) getItem(position);
|
||||||
|
reshViewHolder(position, (DownloadedMusicViewHolder) viewHolder, audioInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过种类名称来获取该分类下的歌曲数目
|
||||||
|
*
|
||||||
|
* @param mCategoryName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getItemSizeByCategoryName(String mCategoryName) {
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (null != mDatas) {
|
||||||
|
// 所有分类中item的总和是ListVIew Item的总个数
|
||||||
|
for (Category category : mDatas) {
|
||||||
|
if (category.getCategoryName().equals(mCategoryName)) {
|
||||||
|
count = category.getItemCount();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载中刷新ui
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(final int position, final DownloadingMusicViewHolder viewHolder, final AudioInfo audioInfo) {
|
||||||
|
viewHolder.getTitleTv().setText(audioInfo.getTitle());
|
||||||
|
String fileSizeText = FileUtil.getFileSize(audioInfo.getFileSize());
|
||||||
|
int downloadedSize = DownloadThreadInfoDB.getDownloadedSize(mContext, audioInfo.getHash(), DownloadAudioManager.mThreadNum);
|
||||||
|
String downloadSizeText = FileUtil.getFileSize(downloadedSize);
|
||||||
|
viewHolder.getDlTipTv().setText(downloadSizeText + "/" + fileSizeText);
|
||||||
|
|
||||||
|
//获取下载任务
|
||||||
|
DownloadTask downloadTask = DownloadAudioManager.newInstance(mContext).getDownloadTask(audioInfo.getHash());
|
||||||
|
if (downloadTask == null) {
|
||||||
|
//点击下载
|
||||||
|
viewHolder.getDownloadingImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getDownloadPauseImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getOpTipTv().setText(mContext.getString(R.string.download_goon_text));
|
||||||
|
} else {
|
||||||
|
if (downloadTask.getStatus() == DownloadTask.STATUS_WAIT) {
|
||||||
|
//等待下载
|
||||||
|
viewHolder.getDownloadingImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getDownloadPauseImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getOpTipTv().setText(mContext.getString(R.string.download_wait_text));
|
||||||
|
} else if (downloadTask.getStatus() == DownloadTask.STATUS_DOWNLOADING) {
|
||||||
|
|
||||||
|
//点击暂停
|
||||||
|
viewHolder.getDownloadingImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getDownloadPauseImg().setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
viewHolder.getOpTipTv().setText(mContext.getString(R.string.download_pause_text));
|
||||||
|
} else {
|
||||||
|
//点击下载
|
||||||
|
viewHolder.getDownloadingImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getDownloadPauseImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getOpTipTv().setText(mContext.getString(R.string.download_goon_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//列表点击事件
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//获取下载任务
|
||||||
|
DownloadTask downloadTask = DownloadAudioManager.newInstance(mContext).getDownloadTask(audioInfo.getHash());
|
||||||
|
if (downloadTask == null) {
|
||||||
|
//点击下载
|
||||||
|
DownloadAudioManager.newInstance(mContext).addTask(audioInfo);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (downloadTask.getStatus() == DownloadTask.STATUS_WAIT) {
|
||||||
|
//等待下载
|
||||||
|
DownloadAudioManager.newInstance(mContext).cancelTask(downloadTask.getTaskId());
|
||||||
|
|
||||||
|
} else if (downloadTask.getStatus() == DownloadTask.STATUS_DOWNLOADING) {
|
||||||
|
//点击暂停
|
||||||
|
DownloadAudioManager.newInstance(mContext).pauseTask(downloadTask.getTaskId());
|
||||||
|
} else {
|
||||||
|
//点击下载
|
||||||
|
DownloadAudioManager.newInstance(mContext).addTask(audioInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteTv().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//获取下载任务
|
||||||
|
DownloadTask downloadTask = DownloadAudioManager.newInstance(mContext).getDownloadTask(audioInfo.getHash());
|
||||||
|
if (downloadTask == null) {
|
||||||
|
//删除
|
||||||
|
DownloadTaskDB.delete(mContext, audioInfo.getHash(), DownloadAudioManager.mThreadNum);
|
||||||
|
} else {
|
||||||
|
//取消任务(任务正在下载)
|
||||||
|
DownloadAudioManager.newInstance(mContext).cancelTask(downloadTask.getTaskId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void resetMenuOpenIndex() {
|
||||||
|
mMenuOpenIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载完成刷新ui
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(final int position, final DownloadedMusicViewHolder viewHolder, final AudioInfo audioInfo) {
|
||||||
|
|
||||||
|
//1更多按钮点击事件
|
||||||
|
viewHolder.getItemMoreImg().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (position != mMenuOpenIndex) {
|
||||||
|
if (mMenuOpenIndex != -1) {
|
||||||
|
notifyItemChanged(mMenuOpenIndex);
|
||||||
|
}
|
||||||
|
mMenuOpenIndex = position;
|
||||||
|
notifyItemChanged(mMenuOpenIndex);
|
||||||
|
} else {
|
||||||
|
if (mMenuOpenIndex != -1) {
|
||||||
|
notifyItemChanged(mMenuOpenIndex);
|
||||||
|
mMenuOpenIndex = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//2展开或者隐藏菜单
|
||||||
|
if (position == mMenuOpenIndex) {
|
||||||
|
|
||||||
|
//下载/未下载
|
||||||
|
viewHolder.getDownloadImg().setVisibility(View.GONE);
|
||||||
|
viewHolder.getDownloadedImg().setVisibility(View.GONE);
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
//喜欢/不喜欢
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.GONE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
viewHolder.getMenuLinearLayout().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getMenuLinearLayout().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//喜欢/不喜欢
|
||||||
|
viewHolder.getUnLikeImgBtn().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (!AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.addLikeAudio(mContext, audioInfo, true);
|
||||||
|
if (result) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.GONE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.like_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
viewHolder.getLikedImgBtn().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.deleteLikeAudio(mContext, audioInfo.getHash(), true);
|
||||||
|
if (result) {
|
||||||
|
viewHolder.getUnLikeImgBtn().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImgBtn().setVisibility(View.GONE);
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.unlike_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//删除
|
||||||
|
viewHolder.getDeleteImgBtn().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//隐藏更多菜单
|
||||||
|
mMenuOpenIndex = -1;
|
||||||
|
viewHolder.getMenuLinearLayout().setVisibility(View.GONE);
|
||||||
|
DownloadTaskDB.delete(mContext, audioInfo.getHash(), DownloadAudioManager.mThreadNum);
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.remove_success_tip_text));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
viewHolder.getSingerNameTv().setText(audioInfo.getSingerName());
|
||||||
|
viewHolder.getSongNameTv().setText(audioInfo.getSongName());
|
||||||
|
|
||||||
|
if (audioInfo.getHash().equals(mConfigInfo.getPlayHash())) {
|
||||||
|
viewHolder.getStatusView().setVisibility(View.VISIBLE);
|
||||||
|
mOldPlayHash = audioInfo.getHash();
|
||||||
|
} else {
|
||||||
|
viewHolder.getStatusView().setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int oldIndex = getPlayIndexPosition(mConfigInfo.getPlayHash());
|
||||||
|
if (oldIndex == position) {
|
||||||
|
AudioPlayerManager.newInstance(mContext).playOrPause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mOldPlayHash = audioInfo.getHash();
|
||||||
|
//如果是本地歌曲列表,点击列表时,需要替换当前的播放列表为本地歌曲列表
|
||||||
|
AudioPlayerManager.newInstance(mContext).playSong(AudioInfoDB.getDownloadedAudios(mContext), audioInfo);
|
||||||
|
|
||||||
|
if (oldIndex != -1) {
|
||||||
|
notifyItemChanged(oldIndex);
|
||||||
|
}
|
||||||
|
int newIndex = getPlayIndexPosition(audioInfo.getHash());
|
||||||
|
if (newIndex != -1) {
|
||||||
|
notifyItemChanged(newIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新view
|
||||||
|
*
|
||||||
|
* @param hash
|
||||||
|
*/
|
||||||
|
public void reshViewHolder(String hash) {
|
||||||
|
if (hash == null || hash.equals("")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int oldIndex = getPlayIndexPosition(mOldPlayHash);
|
||||||
|
if (oldIndex != -1) {
|
||||||
|
mOldPlayHash = "";
|
||||||
|
notifyItemChanged(oldIndex);
|
||||||
|
}
|
||||||
|
int index = getPlayIndexPosition(hash);
|
||||||
|
if (index != -1) {
|
||||||
|
notifyItemChanged(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过sid获取当前的播放索引
|
||||||
|
*
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getPlayIndexPosition(String hash) {
|
||||||
|
int index = -1;
|
||||||
|
// 异常情况处理
|
||||||
|
if (null == mDatas) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(hash)) return -1;
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < mDatas.size(); i++) {
|
||||||
|
Category category = mDatas.get(i);
|
||||||
|
List<AudioInfo> downloadInfoList = category.getCategoryItem();
|
||||||
|
int j = 0;
|
||||||
|
for (; j < downloadInfoList.size(); j++) {
|
||||||
|
AudioInfo audioInfo = (AudioInfo) downloadInfoList.get(j);
|
||||||
|
|
||||||
|
if (audioInfo.getHash().equals(hash)) {
|
||||||
|
|
||||||
|
index = count + j + 1;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count += category.getCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据索引获取内容
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Object getItem(int position) {
|
||||||
|
|
||||||
|
// 异常情况处理
|
||||||
|
if (null == mDatas || position < 0 || position > getItemCount()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 同一分类内,第一个元素的索引值
|
||||||
|
int categroyFirstIndex = 0;
|
||||||
|
|
||||||
|
for (Category category : mDatas) {
|
||||||
|
int size = category.getCount();
|
||||||
|
// 在当前分类中的索引值
|
||||||
|
int categoryIndex = position - categroyFirstIndex;
|
||||||
|
// item在当前分类内
|
||||||
|
if (categoryIndex < size) {
|
||||||
|
return category.getItem(categoryIndex);
|
||||||
|
}
|
||||||
|
// 索引移动到当前分类结尾,即下一个分类第一个元素索引
|
||||||
|
categroyFirstIndex += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (null != mDatas) {
|
||||||
|
// 所有分类中item的总和是ListVIew Item的总个数
|
||||||
|
for (Category category : mDatas) {
|
||||||
|
count += category.getCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
// 异常情况处理
|
||||||
|
if (null == mDatas || position < 0 || position > getItemCount()) {
|
||||||
|
return CATEGORYTITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int categroyFirstIndex = 0;
|
||||||
|
|
||||||
|
for (Category category : mDatas) {
|
||||||
|
int size = category.getCount();
|
||||||
|
// 在当前分类中的索引值
|
||||||
|
int categoryIndex = position - categroyFirstIndex;
|
||||||
|
if (categoryIndex == 0) {
|
||||||
|
return CATEGORYTITLE;
|
||||||
|
} else if (categoryIndex < size) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
categroyFirstIndex += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getItem(position) instanceof String) {
|
||||||
|
return CATEGORYTITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioInfo audioInfo = (AudioInfo) getItem(position);
|
||||||
|
if (audioInfo.getStatus() == AudioInfo.STATUS_FINISH) {
|
||||||
|
return ITEMDownloaded;
|
||||||
|
}
|
||||||
|
return ITEMDownloading;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CategoryTitleViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View itemView;
|
||||||
|
private TextView categoryTextTextView;
|
||||||
|
private View lineView;
|
||||||
|
|
||||||
|
public CategoryTitleViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.itemView = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getCategoryTextTextView() {
|
||||||
|
if (categoryTextTextView == null) {
|
||||||
|
categoryTextTextView = itemView
|
||||||
|
.findViewById(R.id.category_text);
|
||||||
|
}
|
||||||
|
return categoryTextTextView;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载中
|
||||||
|
*/
|
||||||
|
class DownloadingMusicViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
/**
|
||||||
|
* 下载中
|
||||||
|
*/
|
||||||
|
private IconfontTextView downloadingImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载暂停
|
||||||
|
*/
|
||||||
|
private IconfontTextView downloadPauseImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
private TextView titleTv;
|
||||||
|
/**
|
||||||
|
* 状态提示
|
||||||
|
*/
|
||||||
|
private TextView opTipTv;
|
||||||
|
/**
|
||||||
|
* 下载提示
|
||||||
|
*/
|
||||||
|
private TextView dlTipTv;
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
private IconfontTextView deleteTv;
|
||||||
|
|
||||||
|
public DownloadingMusicViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public IconfontTextView getDownloadingImg() {
|
||||||
|
if (downloadingImg == null) {
|
||||||
|
downloadingImg = view.findViewById(R.id.download_img);
|
||||||
|
}
|
||||||
|
return downloadingImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontTextView getDownloadPauseImg() {
|
||||||
|
if (downloadPauseImg == null) {
|
||||||
|
downloadPauseImg = view.findViewById(R.id.pause_img);
|
||||||
|
}
|
||||||
|
return downloadPauseImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getTitleTv() {
|
||||||
|
if (titleTv == null) {
|
||||||
|
titleTv = view.findViewById(R.id.titleName);
|
||||||
|
}
|
||||||
|
return titleTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getOpTipTv() {
|
||||||
|
if (opTipTv == null) {
|
||||||
|
opTipTv = view.findViewById(R.id.download_tip);
|
||||||
|
}
|
||||||
|
return opTipTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getDlTipTv() {
|
||||||
|
if (dlTipTv == null) {
|
||||||
|
dlTipTv = view.findViewById(R.id.downloadSizeText);
|
||||||
|
}
|
||||||
|
return dlTipTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontTextView getDeleteTv() {
|
||||||
|
if (deleteTv == null) {
|
||||||
|
deleteTv = view.findViewById(R.id.delete);
|
||||||
|
}
|
||||||
|
return deleteTv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载完成
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadedMusicViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更多按钮
|
||||||
|
*/
|
||||||
|
private ImageView moreImg;
|
||||||
|
/**
|
||||||
|
* 状态标记view
|
||||||
|
*/
|
||||||
|
private View statusView;
|
||||||
|
/**
|
||||||
|
* 歌曲索引
|
||||||
|
*/
|
||||||
|
private TextView songIndexTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲名称
|
||||||
|
*/
|
||||||
|
private TextView songNameTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手名称
|
||||||
|
*/
|
||||||
|
private TextView singerNameTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存在本地
|
||||||
|
*/
|
||||||
|
private ImageView islocalImg;
|
||||||
|
|
||||||
|
//、、、、、、、、、、、、、、、、、、、、更多菜单、、、、、、、、、、、、、、、、、、、、、、、、
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更多按钮
|
||||||
|
*/
|
||||||
|
private ImageView itemMoreImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单
|
||||||
|
*/
|
||||||
|
private LinearLayout menuLinearLayout;
|
||||||
|
/**
|
||||||
|
* 不喜欢按钮
|
||||||
|
*/
|
||||||
|
private IconfontImageButtonTextView unLikeImgBtn;
|
||||||
|
/**
|
||||||
|
* 不喜欢按钮
|
||||||
|
*/
|
||||||
|
private IconfontImageButtonTextView likedImgBtn;
|
||||||
|
/**
|
||||||
|
* 下载布局
|
||||||
|
*/
|
||||||
|
private RelativeLayout downloadParentRl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载完成按钮
|
||||||
|
*/
|
||||||
|
private ImageView downloadedImg;
|
||||||
|
/**
|
||||||
|
* 下载按钮
|
||||||
|
*/
|
||||||
|
private ImageView downloadImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除按钮
|
||||||
|
*/
|
||||||
|
private IconfontImageButtonTextView deleteImgBtn;
|
||||||
|
|
||||||
|
public DownloadedMusicViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getMoreImg() {
|
||||||
|
if (moreImg == null) {
|
||||||
|
moreImg = view.findViewById(R.id.item_more);
|
||||||
|
}
|
||||||
|
return moreImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getStatusView() {
|
||||||
|
if (statusView == null) {
|
||||||
|
statusView = view.findViewById(R.id.status);
|
||||||
|
}
|
||||||
|
return statusView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSongNameTv() {
|
||||||
|
if (songNameTv == null) {
|
||||||
|
songNameTv = view.findViewById(R.id.songName);
|
||||||
|
}
|
||||||
|
return songNameTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSingerNameTv() {
|
||||||
|
if (singerNameTv == null) {
|
||||||
|
singerNameTv = view.findViewById(R.id.singerName);
|
||||||
|
}
|
||||||
|
return singerNameTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getIslocalImg() {
|
||||||
|
if (islocalImg == null) {
|
||||||
|
islocalImg = view.findViewById(R.id.islocal);
|
||||||
|
}
|
||||||
|
return islocalImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSongIndexTv() {
|
||||||
|
|
||||||
|
if (songIndexTv == null) {
|
||||||
|
songIndexTv = view.findViewById(R.id.songIndex);
|
||||||
|
}
|
||||||
|
return songIndexTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getItemMoreImg() {
|
||||||
|
if (itemMoreImg == null) {
|
||||||
|
itemMoreImg = view.findViewById(R.id.item_more);
|
||||||
|
}
|
||||||
|
return itemMoreImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinearLayout getMenuLinearLayout() {
|
||||||
|
if (menuLinearLayout == null) {
|
||||||
|
menuLinearLayout = view.findViewById(R.id.menu);
|
||||||
|
}
|
||||||
|
return menuLinearLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontImageButtonTextView getLikedImgBtn() {
|
||||||
|
if (likedImgBtn == null) {
|
||||||
|
likedImgBtn = view.findViewById(R.id.liked_menu);
|
||||||
|
}
|
||||||
|
likedImgBtn.setConvert(true);
|
||||||
|
return likedImgBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontImageButtonTextView getUnLikeImgBtn() {
|
||||||
|
if (unLikeImgBtn == null) {
|
||||||
|
unLikeImgBtn = view.findViewById(R.id.unlike_menu);
|
||||||
|
}
|
||||||
|
unLikeImgBtn.setConvert(true);
|
||||||
|
return unLikeImgBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeLayout getDownloadParentRl() {
|
||||||
|
if (downloadParentRl == null) {
|
||||||
|
downloadParentRl = view.findViewById(R.id.downloadParent);
|
||||||
|
}
|
||||||
|
return downloadParentRl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getDownloadedImg() {
|
||||||
|
if (downloadedImg == null) {
|
||||||
|
downloadedImg = view.findViewById(R.id.downloaded_menu);
|
||||||
|
}
|
||||||
|
return downloadedImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getDownloadImg() {
|
||||||
|
if (downloadImg == null) {
|
||||||
|
downloadImg = view.findViewById(R.id.download_menu);
|
||||||
|
}
|
||||||
|
return downloadImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontImageButtonTextView getDeleteImgBtn() {
|
||||||
|
if (deleteImgBtn == null) {
|
||||||
|
deleteImgBtn = view.findViewById(R.id.delete_menu);
|
||||||
|
}
|
||||||
|
deleteImgBtn.setConvert(true);
|
||||||
|
return deleteImgBtn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
236
app/src/main/java/com/zlm/hp/adapter/FileManagerAdapter.java
Normal file
236
app/src/main/java/com/zlm/hp/adapter/FileManagerAdapter.java
Normal file
|
|
@ -0,0 +1,236 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.FileInfo;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.widget.ListItemRelativeLayout;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 文件管理器适配器
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-05-22 22:29
|
||||||
|
**/
|
||||||
|
public class FileManagerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ArrayList<FileInfo> mDatas;
|
||||||
|
private ItemEvent mItemEvent;
|
||||||
|
|
||||||
|
private final int FILETYPE = 0;
|
||||||
|
private final int FILEDIRECTORYTYPE = 1;
|
||||||
|
|
||||||
|
private String mSelectFilePath;
|
||||||
|
|
||||||
|
public FileManagerAdapter(Context context, ArrayList<FileInfo> datas) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
|
||||||
|
mSelectFilePath = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
FileInfo fileInfo = mDatas.get(position);
|
||||||
|
if (fileInfo.isFile()) {
|
||||||
|
return FILETYPE;
|
||||||
|
} else {
|
||||||
|
return FILEDIRECTORYTYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View view = null;
|
||||||
|
if (viewType == FILETYPE) {
|
||||||
|
view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_file, null, false);
|
||||||
|
FileViewHolder holder = new FileViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
} else{
|
||||||
|
view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_file_directory, null, false);
|
||||||
|
FileDirectoryViewHolder holder = new FileDirectoryViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof FileViewHolder && position < mDatas.size()) {
|
||||||
|
reshFileViewHolder((FileViewHolder) viewHolder, position);
|
||||||
|
} else if (viewHolder instanceof FileDirectoryViewHolder && position < mDatas.size()) {
|
||||||
|
reshFileDirectoryViewHolder((FileDirectoryViewHolder) viewHolder, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件夹
|
||||||
|
*
|
||||||
|
* @param viewHolder
|
||||||
|
* @param position
|
||||||
|
*/
|
||||||
|
private void reshFileDirectoryViewHolder(FileDirectoryViewHolder viewHolder, int position) {
|
||||||
|
final FileInfo fileInfo = mDatas.get(position);
|
||||||
|
viewHolder.getFileDirectoryNameTextView().setText(fileInfo.getFileName());
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mItemEvent != null) {
|
||||||
|
mItemEvent.fileDirectoryClick(fileInfo.getFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件
|
||||||
|
*
|
||||||
|
* @param viewHolder
|
||||||
|
* @param position
|
||||||
|
*/
|
||||||
|
private void reshFileViewHolder(final FileViewHolder viewHolder, int position) {
|
||||||
|
final FileInfo fileInfo = mDatas.get(position);
|
||||||
|
viewHolder.getFimeNamTextView().setText(fileInfo.getFileName());
|
||||||
|
if (mSelectFilePath.equals(fileInfo.getFilePath())) {
|
||||||
|
viewHolder.getFileRadioButton().setChecked(true);
|
||||||
|
} else {
|
||||||
|
viewHolder.getFileRadioButton().setChecked(false);
|
||||||
|
}
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean flag = viewHolder.getFileRadioButton().isChecked();
|
||||||
|
if (flag) {
|
||||||
|
viewHolder.getFileRadioButton().setChecked(false);
|
||||||
|
} else {
|
||||||
|
viewHolder.getFileRadioButton().setChecked(true);
|
||||||
|
for (int i = 0; i < mDatas.size(); i++) {
|
||||||
|
FileInfo temp = mDatas.get(i);
|
||||||
|
if (temp.getFilePath().equals(mSelectFilePath)) {
|
||||||
|
notifyItemChanged(i,0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mSelectFilePath = fileInfo.getFilePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 文件
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-05-22 22:34
|
||||||
|
**/
|
||||||
|
class FileViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
private TextView fimeNamTextView;
|
||||||
|
/**
|
||||||
|
* 文件选择按钮
|
||||||
|
*/
|
||||||
|
private RadioButton fileRadioButton;
|
||||||
|
|
||||||
|
public FileViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getFimeNamTextView() {
|
||||||
|
if (fimeNamTextView == null) {
|
||||||
|
fimeNamTextView = view.findViewById(R.id.filename);
|
||||||
|
}
|
||||||
|
return fimeNamTextView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RadioButton getFileRadioButton() {
|
||||||
|
if (fileRadioButton == null) {
|
||||||
|
fileRadioButton = view.findViewById(R.id.fileRadioButton);
|
||||||
|
}
|
||||||
|
return fileRadioButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 文件夹
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-05-22 22:34
|
||||||
|
**/
|
||||||
|
class FileDirectoryViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件夹名
|
||||||
|
*/
|
||||||
|
private TextView fileDirectoryNameTextView;
|
||||||
|
|
||||||
|
|
||||||
|
public FileDirectoryViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getFileDirectoryNameTextView() {
|
||||||
|
if (fileDirectoryNameTextView == null) {
|
||||||
|
fileDirectoryNameTextView = view.findViewById(R.id.filedirectoryname);
|
||||||
|
}
|
||||||
|
return fileDirectoryNameTextView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectFilePath() {
|
||||||
|
return mSelectFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectFilePath(String mSelectFilePath) {
|
||||||
|
this.mSelectFilePath = mSelectFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemEvent(ItemEvent mItemEvent) {
|
||||||
|
this.mItemEvent = mItemEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ItemEvent {
|
||||||
|
public void fileDirectoryClick(String filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
136
app/src/main/java/com/zlm/hp/adapter/LrcPopSingerAdapter.java
Normal file
136
app/src/main/java/com/zlm/hp/adapter/LrcPopSingerAdapter.java
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.async.AsyncHandlerTask;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
import com.zlm.hp.ui.LrcActivity;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.ImageUtil;
|
||||||
|
import com.zlm.hp.widget.PopListItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手列表
|
||||||
|
*/
|
||||||
|
public class LrcPopSingerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private String[] mDatas;
|
||||||
|
private WeakRefHandler mUIHandler;
|
||||||
|
private WeakRefHandler mWorkerHandler;
|
||||||
|
private LrcActivity.PopSingerListener mPopSingerListener;
|
||||||
|
|
||||||
|
public LrcPopSingerAdapter(Context context, String[] datas, WeakRefHandler uiHandler, WeakRefHandler workerHandler, LrcActivity.PopSingerListener popSingerListener) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
this.mUIHandler = uiHandler;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
this.mPopSingerListener = popSingerListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_lrc_singer, null, false);
|
||||||
|
LrcPopSingerListViewHolder holder = new LrcPopSingerListViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof LrcPopSingerListViewHolder && position < mDatas.length) {
|
||||||
|
String singerName = mDatas[position];
|
||||||
|
reshViewHolder(position, (LrcPopSingerListViewHolder) viewHolder, singerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param singerName
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(final int position, final LrcPopSingerListViewHolder viewHolder, final String singerName) {
|
||||||
|
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
ImageUtil.loadSingerImage(mContext, viewHolder.getSingPicImg(), singerName, configInfo.isWifi(), 400, 400, new AsyncHandlerTask(mUIHandler, mWorkerHandler), null);
|
||||||
|
|
||||||
|
viewHolder.getSingerNameTv().setText(singerName);
|
||||||
|
//item点击事件
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mPopSingerListener != null) {
|
||||||
|
mPopSingerListener.search(singerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class LrcPopSingerListViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private PopListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手头像按钮
|
||||||
|
*/
|
||||||
|
private ImageView singPicImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手名称
|
||||||
|
*/
|
||||||
|
private TextView singerNameTv;
|
||||||
|
|
||||||
|
|
||||||
|
public LrcPopSingerListViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PopListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSingerNameTv() {
|
||||||
|
if (singerNameTv == null) {
|
||||||
|
singerNameTv = view.findViewById(R.id.singerName);
|
||||||
|
}
|
||||||
|
return singerNameTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ImageView getSingPicImg() {
|
||||||
|
if (singPicImg == null) {
|
||||||
|
singPicImg = view.findViewById(R.id.singPic);
|
||||||
|
}
|
||||||
|
return singPicImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
154
app/src/main/java/com/zlm/hp/adapter/MVAdapter.java
Normal file
154
app/src/main/java/com/zlm/hp/adapter/MVAdapter.java
Normal file
|
|
@ -0,0 +1,154 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.async.AsyncHandlerTask;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.entity.VideoInfo;
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.ImageUtil;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
import com.zlm.hp.widget.ListItemRelativeLayout;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: mv列表
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2019-01-05 20:07
|
||||||
|
**/
|
||||||
|
public class MVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private WeakRefHandler mUIHandler;
|
||||||
|
private WeakRefHandler mWorkerHandler;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ArrayList<VideoInfo> mDatas;
|
||||||
|
|
||||||
|
private OnClickListener mOnClickListener;
|
||||||
|
|
||||||
|
public MVAdapter(WeakRefHandler uiHandler, WeakRefHandler workerHandler, Context context, ArrayList<VideoInfo> datas) {
|
||||||
|
this.mUIHandler = uiHandler;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_mv, null, false);
|
||||||
|
MvViewHolder holder = new MvViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof MvViewHolder && position < mDatas.size()) {
|
||||||
|
VideoInfo videoInfo = mDatas.get(position);
|
||||||
|
reshViewHolder(position, (MvViewHolder) viewHolder, videoInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新ui
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param videoInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(int position, final MvViewHolder viewHolder, final VideoInfo videoInfo) {
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
String filePath = ResourceUtil.getFilePath(mContext, ResourceConstants.PATH_CACHE_IMAGE, videoInfo.getImageUrl().hashCode() + ".png");
|
||||||
|
ImageUtil.loadImage(mContext, filePath, videoInfo.getImageUrl(), configInfo.isWifi(), viewHolder.getItemImg(), 400, 400, new AsyncHandlerTask(mUIHandler, mWorkerHandler), null);
|
||||||
|
viewHolder.getTitleTv().setText(videoInfo.getMvName());
|
||||||
|
viewHolder.getSingerNameTv().setText(videoInfo.getSingerName());
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mOnClickListener != null) {
|
||||||
|
mOnClickListener.openVideoView(videoInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnClickListener(OnClickListener onClickListener) {
|
||||||
|
this.mOnClickListener = onClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface OnClickListener {
|
||||||
|
void openVideoView(VideoInfo videoInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
class MvViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* item图片
|
||||||
|
*/
|
||||||
|
private ImageView itemImg;
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
private TextView titleTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手
|
||||||
|
*/
|
||||||
|
private TextView singerNameTv;
|
||||||
|
|
||||||
|
public MvViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getItemImg() {
|
||||||
|
if (itemImg == null) {
|
||||||
|
itemImg = view.findViewById(R.id.item_icon);
|
||||||
|
}
|
||||||
|
return itemImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getTitleTv() {
|
||||||
|
if (titleTv == null) {
|
||||||
|
titleTv = view.findViewById(R.id.songName);
|
||||||
|
}
|
||||||
|
return titleTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSingerNameTv() {
|
||||||
|
if (singerNameTv == null) {
|
||||||
|
singerNameTv = view.findViewById(R.id.singerName);
|
||||||
|
}
|
||||||
|
return singerNameTv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
492
app/src/main/java/com/zlm/hp/adapter/PopPlayListAdapter.java
Normal file
492
app/src/main/java/com/zlm/hp/adapter/PopPlayListAdapter.java
Normal file
|
|
@ -0,0 +1,492 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.async.AsyncHandlerTask;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.db.util.AudioInfoDB;
|
||||||
|
import com.zlm.hp.db.util.DownloadThreadInfoDB;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
import com.zlm.hp.manager.AudioPlayerManager;
|
||||||
|
import com.zlm.hp.manager.DownloadAudioManager;
|
||||||
|
import com.zlm.hp.manager.OnLineAudioManager;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.FileUtil;
|
||||||
|
import com.zlm.hp.util.ImageUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌曲列表弹出窗口
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-11-28 21:08
|
||||||
|
**/
|
||||||
|
public class PopPlayListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private Context mContext;
|
||||||
|
private List<AudioInfo> mDatas;
|
||||||
|
private WeakRefHandler mUIHandler;
|
||||||
|
private WeakRefHandler mWorkerHandler;
|
||||||
|
private String mOldPlayHash = "";
|
||||||
|
private ConfigInfo mConfigInfo;
|
||||||
|
|
||||||
|
|
||||||
|
public PopPlayListAdapter(Context context, List<AudioInfo> datas, WeakRefHandler uiHandler, WeakRefHandler workerHandler) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
this.mUIHandler = uiHandler;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
mConfigInfo = ConfigInfo.obtain();
|
||||||
|
mOldPlayHash = mConfigInfo.getPlayHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_popsong, null, false);
|
||||||
|
PopListViewHolder holder = new PopListViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof PopListViewHolder && position < mDatas.size()) {
|
||||||
|
AudioInfo audioInfo = mDatas.get(position);
|
||||||
|
reshViewHolder(position, (PopListViewHolder) viewHolder, audioInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(final int position, final PopListViewHolder viewHolder, final AudioInfo audioInfo) {
|
||||||
|
|
||||||
|
if (audioInfo.getHash().equals(mConfigInfo.getPlayHash())) {
|
||||||
|
mOldPlayHash = audioInfo.getHash();
|
||||||
|
|
||||||
|
viewHolder.getSingPicImg().setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
//加载歌手头像
|
||||||
|
ImageUtil.loadSingerImage(mContext, viewHolder.getSingPicImg(), audioInfo.getSingerName(), mConfigInfo.isWifi(), 400, 400, new AsyncHandlerTask(mUIHandler, mWorkerHandler), new ImageUtil.ImageLoadCallBack() {
|
||||||
|
@Override
|
||||||
|
public void callback(Bitmap bitmap) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
viewHolder.getSongIndexTv().setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getSongIndexTv().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getSingPicImg().setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//下载完成
|
||||||
|
if (audioInfo.getType() == AudioInfo.TYPE_LOCAL || AudioInfoDB.isDownloadedAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
viewHolder.getDownloadImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getDownloadedImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getDownloadImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getDownloadedImg().setVisibility(View.INVISIBLE);
|
||||||
|
int downloadedSize = DownloadThreadInfoDB.getDownloadedSize(mContext, audioInfo.getHash(), OnLineAudioManager.mThreadNum);
|
||||||
|
if (downloadedSize >= audioInfo.getFileSize()) {
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getIslocalImg().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//未下载
|
||||||
|
viewHolder.getDownloadImg().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean flag = DownloadAudioManager.newInstance(mContext).isDownloadAudioExists(audioInfo.getHash());
|
||||||
|
if (flag) {
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.undownload_tip_text));
|
||||||
|
} else {
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.download_tip_text));
|
||||||
|
DownloadAudioManager.newInstance(mContext).addTask(audioInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//喜欢/不喜欢
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
viewHolder.getUnLikeTv().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getLikedImg().setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getUnLikeTv().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImg().setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
//不喜欢
|
||||||
|
viewHolder.getUnLikeTv().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (!AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.addLikeAudio(mContext, audioInfo, true);
|
||||||
|
if (result) {
|
||||||
|
viewHolder.getUnLikeTv().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getLikedImg().setVisibility(View.VISIBLE);
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.like_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//喜欢
|
||||||
|
viewHolder.getLikedImg().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (audioInfo != null) {
|
||||||
|
if (AudioInfoDB.isLikeAudioExists(mContext, audioInfo.getHash())) {
|
||||||
|
boolean result = AudioInfoDB.deleteLikeAudio(mContext, audioInfo.getHash(), true);
|
||||||
|
if (result) {
|
||||||
|
viewHolder.getUnLikeTv().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getLikedImg().setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.unlike_tip_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//从播放列表中移除
|
||||||
|
viewHolder.getDeleteTv().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//1.先判断是否是当前正在播放的歌曲
|
||||||
|
//2.移除歌曲
|
||||||
|
//3.发通知
|
||||||
|
|
||||||
|
String curHash = audioInfo.getHash();
|
||||||
|
//是否是正在播放歌曲
|
||||||
|
boolean flag = mConfigInfo.getPlayHash().equals(audioInfo.getHash());
|
||||||
|
|
||||||
|
//获取下一首歌曲
|
||||||
|
List<AudioInfo> audioInfos = mConfigInfo.getAudioInfos();
|
||||||
|
AudioInfo nextAudioInfo = null;
|
||||||
|
boolean hasNext = false;
|
||||||
|
int curHashIndex = -1;
|
||||||
|
for (int i = 0; i < audioInfos.size(); i++) {
|
||||||
|
AudioInfo temp = audioInfos.get(i);
|
||||||
|
if (hasNext) {
|
||||||
|
nextAudioInfo = temp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (temp.getHash().equals(curHash)) {
|
||||||
|
curHashIndex = i;
|
||||||
|
if (!flag) break;
|
||||||
|
hasNext = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//播放器如果正在播放
|
||||||
|
if (flag)
|
||||||
|
AudioPlayerManager.newInstance(mContext).stop();
|
||||||
|
|
||||||
|
//移除数据
|
||||||
|
if (curHashIndex != -1) {
|
||||||
|
audioInfos.remove(curHashIndex);
|
||||||
|
|
||||||
|
mConfigInfo.setAudioInfos(audioInfos);
|
||||||
|
//发更新通知
|
||||||
|
AudioBroadcastReceiver.sendReceiver(mContext, AudioBroadcastReceiver.ACTION_CODE_UPDATE_PLAYLIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, mContext.getResources().getString(R.string.remove_success_tip_text));
|
||||||
|
|
||||||
|
//如果是正在播放歌曲,发播放下一首通知
|
||||||
|
if (!flag) return;
|
||||||
|
if (nextAudioInfo != null) {
|
||||||
|
mConfigInfo.setPlayHash(nextAudioInfo.getHash());
|
||||||
|
nextAudioInfo.setPlayProgress(0);
|
||||||
|
AudioBroadcastReceiver.sendPlayInitReceiver(mContext, nextAudioInfo);
|
||||||
|
} else {
|
||||||
|
mConfigInfo.setPlayHash("");
|
||||||
|
AudioBroadcastReceiver.sendNullReceiver(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
mConfigInfo.save();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//显示歌曲索引
|
||||||
|
viewHolder.getSongIndexTv().setText(((position + 1) < 10 ? "0" + (position + 1) : (position + 1) + ""));
|
||||||
|
String singerName = audioInfo.getSingerName();
|
||||||
|
String songName = audioInfo.getSongName();
|
||||||
|
viewHolder.getSongNameTv().setText(songName);
|
||||||
|
if(audioInfo.getMvPath()!=null && audioInfo.getMvPath().length()>0) {
|
||||||
|
if(audioInfo.IsOnlyMV()) {
|
||||||
|
viewHolder.getIsMVTv().setText("[仅MV]");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
viewHolder.getIsMVTv().setText("[MV]");
|
||||||
|
}
|
||||||
|
viewHolder.getIsMVTv().setVisibility(View.VISIBLE);
|
||||||
|
File mvFile=new File(audioInfo.getMvPath());
|
||||||
|
String MVFileName= FileUtil.getFileNameWithoutExt(mvFile);
|
||||||
|
if(MVFileName.contains("(高清)"))
|
||||||
|
{
|
||||||
|
viewHolder.getMVQSDTv().setText("[高清]"); viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else if(MVFileName.contains("(超清)"))
|
||||||
|
{
|
||||||
|
viewHolder.getMVQSDTv().setText("[超清]"); viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else if(MVFileName.contains("(蓝光)"))
|
||||||
|
{
|
||||||
|
viewHolder.getMVQSDTv().setText("[蓝光]"); viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else if(MVFileName.contains("(标清)"))
|
||||||
|
{
|
||||||
|
viewHolder.getMVQSDTv().setText("[标清]"); viewHolder.getMVQSDTv().setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
viewHolder.getMVQSDTv().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
viewHolder.getIsMVTv().setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
viewHolder.getSingerNameTv().setText(singerName);
|
||||||
|
//item点击事件
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
int oldIndex = getAudioIndex(mConfigInfo.getPlayHash());
|
||||||
|
if (oldIndex == position) {
|
||||||
|
AudioPlayerManager.newInstance(mContext).playOrPause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioPlayerManager.newInstance(mContext).playSong(audioInfo);
|
||||||
|
|
||||||
|
if (oldIndex != -1) {
|
||||||
|
notifyItemChanged(oldIndex);
|
||||||
|
}
|
||||||
|
int newIndex = getAudioIndex(audioInfo.getHash());
|
||||||
|
if (newIndex != -1) {
|
||||||
|
notifyItemChanged(newIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 刷新
|
||||||
|
*/
|
||||||
|
public void reshViewHolder(String playHash) {
|
||||||
|
int oldIndex = getAudioIndex(mOldPlayHash);
|
||||||
|
if (oldIndex != -1) {
|
||||||
|
notifyItemChanged(oldIndex);
|
||||||
|
}
|
||||||
|
int newIndex = getAudioIndex(playHash);
|
||||||
|
if (newIndex != -1) {
|
||||||
|
notifyItemChanged(newIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌曲索引
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private int getAudioIndex(String playHash) {
|
||||||
|
if (TextUtils.isEmpty(playHash)) return -1;
|
||||||
|
if (mDatas != null && mDatas.size() > 0) {
|
||||||
|
for (int i = 0; i < mDatas.size(); i++) {
|
||||||
|
AudioInfo temp = mDatas.get(i);
|
||||||
|
if (temp.getHash().equals(playHash)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class PopListViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private RelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手头像按钮
|
||||||
|
*/
|
||||||
|
private ImageView singPicImg;
|
||||||
|
/**
|
||||||
|
* 歌曲索引
|
||||||
|
*/
|
||||||
|
private TextView songIndexTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲名称
|
||||||
|
*/
|
||||||
|
private TextView songNameTv;
|
||||||
|
/**
|
||||||
|
* 是否有MV
|
||||||
|
*/
|
||||||
|
private TextView IsMVTv;
|
||||||
|
/**
|
||||||
|
* MV清晰度
|
||||||
|
*/
|
||||||
|
private TextView MVQSDTv;
|
||||||
|
/**
|
||||||
|
* 歌手名称
|
||||||
|
*/
|
||||||
|
private TextView singerNameTv;
|
||||||
|
/**
|
||||||
|
* 是否存在本地
|
||||||
|
*/
|
||||||
|
private ImageView islocalImg;
|
||||||
|
/**
|
||||||
|
* 下载未完成按钮
|
||||||
|
*/
|
||||||
|
private ImageView downloadImg;
|
||||||
|
/**
|
||||||
|
* 添加喜欢按钮
|
||||||
|
*/
|
||||||
|
private IconfontTextView unlikeTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载完成按钮
|
||||||
|
*/
|
||||||
|
private ImageView downloadedImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 喜欢按钮
|
||||||
|
*/
|
||||||
|
private ImageView likeImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
private IconfontTextView deleteTv;
|
||||||
|
|
||||||
|
|
||||||
|
public PopListViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSongNameTv() {
|
||||||
|
if (songNameTv == null) {
|
||||||
|
songNameTv = view.findViewById(R.id.songName);
|
||||||
|
}
|
||||||
|
return songNameTv;
|
||||||
|
}
|
||||||
|
public TextView getIsMVTv() {
|
||||||
|
if (IsMVTv == null) {
|
||||||
|
IsMVTv = view.findViewById(R.id.isMV);
|
||||||
|
}
|
||||||
|
return IsMVTv;
|
||||||
|
}
|
||||||
|
public TextView getMVQSDTv() {
|
||||||
|
if (MVQSDTv == null) {
|
||||||
|
MVQSDTv = view.findViewById(R.id.MVQSD);
|
||||||
|
}
|
||||||
|
return MVQSDTv;
|
||||||
|
}
|
||||||
|
public TextView getSingerNameTv() {
|
||||||
|
if (singerNameTv == null) {
|
||||||
|
singerNameTv = view.findViewById(R.id.singerName);
|
||||||
|
}
|
||||||
|
return singerNameTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getIslocalImg() {
|
||||||
|
if (islocalImg == null) {
|
||||||
|
islocalImg = view.findViewById(R.id.islocal);
|
||||||
|
}
|
||||||
|
return islocalImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getSingPicImg() {
|
||||||
|
if (singPicImg == null) {
|
||||||
|
singPicImg = view.findViewById(R.id.singPic);
|
||||||
|
}
|
||||||
|
return singPicImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getSongIndexTv() {
|
||||||
|
if (songIndexTv == null) {
|
||||||
|
songIndexTv = view.findViewById(R.id.songIndex);
|
||||||
|
}
|
||||||
|
return songIndexTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getDownloadImg() {
|
||||||
|
if (downloadImg == null) {
|
||||||
|
downloadImg = view.findViewById(R.id.download);
|
||||||
|
}
|
||||||
|
return downloadImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontTextView getUnLikeTv() {
|
||||||
|
if (unlikeTv == null) {
|
||||||
|
unlikeTv = view.findViewById(R.id.unlike);
|
||||||
|
}
|
||||||
|
return unlikeTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getDownloadedImg() {
|
||||||
|
if (downloadedImg == null) {
|
||||||
|
downloadedImg = view.findViewById(R.id.downloaded);
|
||||||
|
}
|
||||||
|
return downloadedImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getLikedImg() {
|
||||||
|
if (likeImg == null) {
|
||||||
|
likeImg = view.findViewById(R.id.liked);
|
||||||
|
}
|
||||||
|
return likeImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IconfontTextView getDeleteTv() {
|
||||||
|
if (deleteTv == null) {
|
||||||
|
deleteTv = view.findViewById(R.id.delete);
|
||||||
|
}
|
||||||
|
return deleteTv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
129
app/src/main/java/com/zlm/hp/adapter/RecommendAdapter.java
Normal file
129
app/src/main/java/com/zlm/hp/adapter/RecommendAdapter.java
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.async.AsyncHandlerTask;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.entity.RankInfo;
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
import com.zlm.hp.receiver.FragmentReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.ImageUtil;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
import com.zlm.hp.widget.ListItemRelativeLayout;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排行
|
||||||
|
* Created by zhangliangming on 2017/7/29.
|
||||||
|
*/
|
||||||
|
public class RecommendAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private WeakRefHandler mUIHandler;
|
||||||
|
private WeakRefHandler mWorkerHandler;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ArrayList<RankInfo> mDatas;
|
||||||
|
|
||||||
|
public RecommendAdapter(WeakRefHandler uiHandler, WeakRefHandler workerHandler, Context context, ArrayList<RankInfo> datas) {
|
||||||
|
this.mUIHandler = uiHandler;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_one_category, null, false);
|
||||||
|
RecommendViewHolder holder = new RecommendViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof RecommendViewHolder && position < mDatas.size()) {
|
||||||
|
RankInfo rankInfo = mDatas.get(position);
|
||||||
|
reshViewHolder(position, (RecommendViewHolder) viewHolder, rankInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新ui
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param rankInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(int position, final RecommendViewHolder viewHolder, final RankInfo rankInfo) {
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
String filePath = ResourceUtil.getFilePath(mContext, ResourceConstants.PATH_CACHE_IMAGE, rankInfo.getImageUrl().hashCode() + ".png");
|
||||||
|
ImageUtil.loadImage(mContext, filePath, rankInfo.getImageUrl(), configInfo.isWifi(), viewHolder.getItemImg(), 400, 400, new AsyncHandlerTask(mUIHandler, mWorkerHandler), null);
|
||||||
|
viewHolder.getRankTitleTv().setText(rankInfo.getRankName());
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//打开排行页面
|
||||||
|
FragmentReceiver.sendRecommendFragmentReceiver(mContext, rankInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
class RecommendViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* item图片
|
||||||
|
*/
|
||||||
|
private ImageView itemImg;
|
||||||
|
/**
|
||||||
|
* 排行标题
|
||||||
|
*/
|
||||||
|
private TextView rankTitleTv;
|
||||||
|
|
||||||
|
public RecommendViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getItemImg() {
|
||||||
|
if (itemImg == null) {
|
||||||
|
itemImg = view.findViewById(R.id.item_icon);
|
||||||
|
}
|
||||||
|
return itemImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getRankTitleTv() {
|
||||||
|
if (rankTitleTv == null) {
|
||||||
|
rankTitleTv = view.findViewById(R.id.title);
|
||||||
|
}
|
||||||
|
return rankTitleTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.LrcInfo;
|
||||||
|
import com.zlm.hp.fragment.LrcFragment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: tab适配器
|
||||||
|
* @Param:
|
||||||
|
* @Return:
|
||||||
|
* @Author: zhangliangming
|
||||||
|
* @Date: 2017/7/16 20:33
|
||||||
|
* @Throws: https://blog.csdn.net/shanshan_1117/article/details/79756399
|
||||||
|
*/
|
||||||
|
public class SearchLrcFragmentAdapter extends FragmentStatePagerAdapter {
|
||||||
|
//存储所有的fragment
|
||||||
|
private List<LrcInfo> mDatas;
|
||||||
|
private AudioInfo mAudioInfo;
|
||||||
|
private Fragment mCurrentFragment;
|
||||||
|
|
||||||
|
public SearchLrcFragmentAdapter(FragmentManager fm, AudioInfo audioInfo, List<LrcInfo> datas) {
|
||||||
|
super(fm);
|
||||||
|
this.mDatas = datas;
|
||||||
|
this.mAudioInfo = audioInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||||
|
mCurrentFragment = (Fragment) object;
|
||||||
|
super.setPrimaryItem(container, position, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int index) {
|
||||||
|
try {
|
||||||
|
LrcInfo lrcInfo = mDatas.get(index);
|
||||||
|
|
||||||
|
Class clazz = LrcFragment.class;
|
||||||
|
LrcFragment fragment = (LrcFragment) clazz.newInstance();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(LrcFragment.AUDIO_DATA_KEY, mAudioInfo);
|
||||||
|
bundle.putParcelable(LrcFragment.LRC_DATA_KEY, lrcInfo);
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
|
||||||
|
return fragment;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Fragment getCurrentFragment() {
|
||||||
|
return mCurrentFragment;
|
||||||
|
}
|
||||||
|
}
|
||||||
199
app/src/main/java/com/zlm/hp/adapter/SearchSingerAdapter.java
Normal file
199
app/src/main/java/com/zlm/hp/adapter/SearchSingerAdapter.java
Normal file
|
|
@ -0,0 +1,199 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
|
import com.zlm.hp.async.AsyncHandlerTask;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.entity.SingerInfo;
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.ImageUtil;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索歌手写真
|
||||||
|
*/
|
||||||
|
public class SearchSingerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private List<SingerInfo> mDatas;
|
||||||
|
private WeakRefHandler mUIHandler;
|
||||||
|
private WeakRefHandler mWorkerHandler;
|
||||||
|
private List<SingerInfo> mSelectDatas;
|
||||||
|
|
||||||
|
|
||||||
|
public SearchSingerAdapter(Context context, List<SingerInfo> datas, List<SingerInfo> selectDatas, WeakRefHandler uiHandler, WeakRefHandler workerHandler) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
this.mUIHandler = uiHandler;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
this.mSelectDatas = selectDatas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_search_singer, null, false);
|
||||||
|
SearchSingerViewHolder holder = new SearchSingerViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof SearchSingerViewHolder && position < mDatas.size()) {
|
||||||
|
SingerInfo singerInfo = mDatas.get(position);
|
||||||
|
reshViewHolder(position, (SearchSingerViewHolder) viewHolder, singerInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param singerInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(final int position, final SearchSingerViewHolder viewHolder, final SingerInfo singerInfo) {
|
||||||
|
String filePath = ResourceUtil.getFilePath(mContext, ResourceConstants.PATH_SINGER, (singerInfo.getSingerName() + File.separator + singerInfo.getImageUrl().hashCode() + ".jpg"));
|
||||||
|
ImageUtil.loadSingerPic(mContext, filePath, singerInfo.getImageUrl(), true, viewHolder.getSingPicImg(), 720, 1080, new AsyncHandlerTask(mUIHandler, mWorkerHandler), null);
|
||||||
|
if (contains(singerInfo)) {
|
||||||
|
viewHolder.getSelectedImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getUnSelectImg().setVisibility(View.INVISIBLE);
|
||||||
|
} else {
|
||||||
|
viewHolder.getSelectedImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getUnSelectImg().setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (viewHolder.getSelectedImg().getVisibility() == View.VISIBLE) {
|
||||||
|
viewHolder.getSelectedImg().setVisibility(View.INVISIBLE);
|
||||||
|
viewHolder.getUnSelectImg().setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
delete(singerInfo);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
viewHolder.getSelectedImg().setVisibility(View.VISIBLE);
|
||||||
|
viewHolder.getUnSelectImg().setVisibility(View.INVISIBLE);
|
||||||
|
if (!contains(singerInfo)) {
|
||||||
|
mSelectDatas.add(singerInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param singerInfo
|
||||||
|
*/
|
||||||
|
private void delete(SingerInfo singerInfo) {
|
||||||
|
if (mSelectDatas != null && mSelectDatas.size() > 0) {
|
||||||
|
for (int i = 0; i < mSelectDatas.size(); i++) {
|
||||||
|
SingerInfo temp = mSelectDatas.get(i);
|
||||||
|
if (temp.getImageUrl().equals(singerInfo.getImageUrl())) {
|
||||||
|
mSelectDatas.remove(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param singerInfo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean contains(SingerInfo singerInfo) {
|
||||||
|
if (mSelectDatas != null && mSelectDatas.size() > 0) {
|
||||||
|
for (int i = 0; i < mSelectDatas.size(); i++) {
|
||||||
|
SingerInfo temp = mSelectDatas.get(i);
|
||||||
|
if (temp.getImageUrl().equals(singerInfo.getImageUrl())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<SingerInfo> getSelectDatas() {
|
||||||
|
return mSelectDatas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
return super.getItemViewType(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class SearchSingerViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
private ImageView singPicImg;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private RelativeLayout listItemRelativeLayout;
|
||||||
|
/**
|
||||||
|
* 未选择
|
||||||
|
*/
|
||||||
|
private ImageView unSelectImg;
|
||||||
|
/**
|
||||||
|
* 选择
|
||||||
|
*/
|
||||||
|
private ImageView selectedImg;
|
||||||
|
|
||||||
|
public SearchSingerViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getSingPicImg() {
|
||||||
|
if (singPicImg == null) {
|
||||||
|
singPicImg = view.findViewById(R.id.singPic);
|
||||||
|
}
|
||||||
|
return singPicImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getUnSelectImg() {
|
||||||
|
|
||||||
|
if (unSelectImg == null) {
|
||||||
|
unSelectImg = view.findViewById(R.id.unselect);
|
||||||
|
}
|
||||||
|
return unSelectImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getSelectedImg() {
|
||||||
|
if (selectedImg == null) {
|
||||||
|
selectedImg = view.findViewById(R.id.selected);
|
||||||
|
}
|
||||||
|
return selectedImg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
130
app/src/main/java/com/zlm/hp/adapter/SpecialAdapter.java
Normal file
130
app/src/main/java/com/zlm/hp/adapter/SpecialAdapter.java
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.async.AsyncHandlerTask;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.entity.SpecialInfo;
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
import com.zlm.hp.receiver.FragmentReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.ImageUtil;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
import com.zlm.hp.widget.ListItemRelativeLayout;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌单
|
||||||
|
* Created by zhangliangming on 2017/7/29.
|
||||||
|
*/
|
||||||
|
public class SpecialAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
private WeakRefHandler mUIHandler;
|
||||||
|
private WeakRefHandler mWorkerHandler;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private ArrayList<SpecialInfo> mDatas;
|
||||||
|
|
||||||
|
public SpecialAdapter(WeakRefHandler uiHandler, WeakRefHandler workerHandler, Context context, ArrayList<SpecialInfo> datas) {
|
||||||
|
this.mUIHandler = uiHandler;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_one_category, null, false);
|
||||||
|
SpecialViewHolder holder = new SpecialViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof SpecialViewHolder && position < mDatas.size()) {
|
||||||
|
SpecialInfo specialInfo = mDatas.get(position);
|
||||||
|
reshViewHolder(position, (SpecialViewHolder) viewHolder, specialInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新ui
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param specialInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(int position, final SpecialViewHolder viewHolder, final SpecialInfo specialInfo) {
|
||||||
|
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
String filePath = ResourceUtil.getFilePath(mContext, ResourceConstants.PATH_CACHE_IMAGE, specialInfo.getImageUrl().hashCode() + ".png");
|
||||||
|
ImageUtil.loadImage(mContext, filePath, specialInfo.getImageUrl(), configInfo.isWifi(), viewHolder.getItemImg(), 400, 400, new AsyncHandlerTask(mUIHandler, mWorkerHandler), null);
|
||||||
|
|
||||||
|
viewHolder.getSpecialTitleTv().setText(specialInfo.getSpecialName());
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
FragmentReceiver.sendSpecialFragmentReceiver(mContext, specialInfo);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpecialViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private ListItemRelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* item图片
|
||||||
|
*/
|
||||||
|
private ImageView itemImg;
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
private TextView specialTitleTv;
|
||||||
|
|
||||||
|
public SpecialViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getItemImg() {
|
||||||
|
if (itemImg == null) {
|
||||||
|
itemImg = view.findViewById(R.id.item_icon);
|
||||||
|
}
|
||||||
|
return itemImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public TextView getSpecialTitleTv() {
|
||||||
|
if (specialTitleTv == null) {
|
||||||
|
specialTitleTv = view.findViewById(R.id.title);
|
||||||
|
}
|
||||||
|
return specialTitleTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
45
app/src/main/java/com/zlm/hp/adapter/TabFragmentAdapter.java
Normal file
45
app/src/main/java/com/zlm/hp/adapter/TabFragmentAdapter.java
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: tab适配器
|
||||||
|
* @Param:
|
||||||
|
* @Return:
|
||||||
|
* @Author: zhangliangming
|
||||||
|
* @Date: 2017/7/16 20:33
|
||||||
|
* @Throws: https://blog.csdn.net/shanshan_1117/article/details/79756399
|
||||||
|
*/
|
||||||
|
public class TabFragmentAdapter extends FragmentPagerAdapter {
|
||||||
|
//存储所有的fragment
|
||||||
|
private List<Class> mDatas;
|
||||||
|
|
||||||
|
public TabFragmentAdapter(FragmentManager fm, ArrayList<Class> datas) {
|
||||||
|
super(fm);
|
||||||
|
this.mDatas = datas;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int index) {
|
||||||
|
try {
|
||||||
|
Class clazz = mDatas.get(index);
|
||||||
|
Fragment fragment = (Fragment) clazz.newInstance();
|
||||||
|
return fragment;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
123
app/src/main/java/com/zlm/hp/adapter/ToolAdapter.java
Normal file
123
app/src/main/java/com/zlm/hp/adapter/ToolAdapter.java
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.ToolInfo;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 工具适配器
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-30 16:59
|
||||||
|
**/
|
||||||
|
public class ToolAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private Context mContext;
|
||||||
|
/**
|
||||||
|
* 工具数据
|
||||||
|
*/
|
||||||
|
private List<ToolInfo> mDatas;
|
||||||
|
|
||||||
|
private OnClickListener mClickListener;
|
||||||
|
|
||||||
|
public ToolAdapter(Context context, List<ToolInfo> datas) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mDatas = datas;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_tool, null, false);
|
||||||
|
ToolViewHolder holder = new ToolViewHolder(view);
|
||||||
|
return holder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
if (viewHolder instanceof ToolViewHolder && position < mDatas.size()) {
|
||||||
|
ToolInfo toolInfo = mDatas.get(position);
|
||||||
|
reshViewHolder(position, (ToolViewHolder) viewHolder, toolInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新
|
||||||
|
*
|
||||||
|
* @param position
|
||||||
|
* @param viewHolder
|
||||||
|
* @param toolInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(int position, ToolViewHolder viewHolder, final ToolInfo toolInfo) {
|
||||||
|
viewHolder.getToolNameTv().setText(toolInfo.getTitle());
|
||||||
|
viewHolder.getListItemRelativeLayout().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
if(mClickListener != null){
|
||||||
|
mClickListener.runTool(toolInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mDatas.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClickListener(OnClickListener clickListener) {
|
||||||
|
this.mClickListener = clickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface OnClickListener{
|
||||||
|
void runTool(ToolInfo toolInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ToolViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* item底部布局
|
||||||
|
*/
|
||||||
|
private RelativeLayout listItemRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工具名称
|
||||||
|
*/
|
||||||
|
private TextView toolNameTv;
|
||||||
|
|
||||||
|
public ToolViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeLayout getListItemRelativeLayout() {
|
||||||
|
if (listItemRelativeLayout == null) {
|
||||||
|
listItemRelativeLayout = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return listItemRelativeLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getToolNameTv() {
|
||||||
|
if (toolNameTv == null) {
|
||||||
|
toolNameTv = view.findViewById(R.id.tool_name);
|
||||||
|
}
|
||||||
|
return toolNameTv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.zlm.hp.adapter;
|
||||||
|
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: tab适配器
|
||||||
|
* @Param:
|
||||||
|
* @Return:
|
||||||
|
* @Author: zhangliangming
|
||||||
|
* @Date: 2017/7/16 20:33
|
||||||
|
* @Throws:
|
||||||
|
*/
|
||||||
|
public class ViewPageFragmentAdapter extends FragmentPagerAdapter {
|
||||||
|
//存储所有的fragment
|
||||||
|
private List<Fragment> list;
|
||||||
|
|
||||||
|
public ViewPageFragmentAdapter(FragmentManager fm, ArrayList<Fragment> list) {
|
||||||
|
super(fm);
|
||||||
|
this.list = list;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int index) {
|
||||||
|
|
||||||
|
return list.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
|
||||||
|
return list.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,208 @@
|
||||||
|
package com.zlm.hp.adapter.tool;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.lyrics.model.make.MakeExtraLrcLineInfo;
|
||||||
|
import com.zlm.hp.lyrics.utils.StringUtils;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.widget.ListItemRelativeLayout;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作额外歌词适配器
|
||||||
|
* Created by zhangliangming on 2018-03-28.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MakeExtraLrcAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词数据集合
|
||||||
|
*/
|
||||||
|
private ArrayList<MakeExtraLrcLineInfo> mMakeLrcs;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选中索引
|
||||||
|
*/
|
||||||
|
private int mSelectedIndex = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private ItemEvent mItemEvent;
|
||||||
|
|
||||||
|
public MakeExtraLrcAdapter(Context context, ArrayList<MakeExtraLrcLineInfo> makeLrcs) {
|
||||||
|
this.mContext = context;
|
||||||
|
this.mMakeLrcs = makeLrcs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View view = LayoutInflater.from(mContext).inflate(R.layout.layout_lvitem_make_extralrc, null, false);
|
||||||
|
MakeExtraLrcViewHolder makeExtraLrcViewHolder = new MakeExtraLrcViewHolder(view);
|
||||||
|
return makeExtraLrcViewHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||||
|
if (holder instanceof MakeExtraLrcViewHolder && position < mMakeLrcs.size()) {
|
||||||
|
MakeExtraLrcLineInfo makeExtraLrcLineInfo = mMakeLrcs.get(position);
|
||||||
|
reshViewHolder((MakeExtraLrcViewHolder) holder, position, makeExtraLrcLineInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param viewHolder
|
||||||
|
* @param position
|
||||||
|
* @param makeLrcLineInfo
|
||||||
|
*/
|
||||||
|
private void reshViewHolder(final MakeExtraLrcViewHolder viewHolder, final int position, final MakeExtraLrcLineInfo makeLrcLineInfo) {
|
||||||
|
viewHolder.getIndexTv().setText(String.format("%0" + (mMakeLrcs.size() + "").length() + "d", (position + 1)));
|
||||||
|
|
||||||
|
//设置内容
|
||||||
|
viewHolder.getLineLyricsYv().setText(makeLrcLineInfo.getLyricsLineInfo().getLineLyrics());
|
||||||
|
if (makeLrcLineInfo.getExtraLineLyrics() != null) {
|
||||||
|
viewHolder.getExtraLineLyricsYv().setText(makeLrcLineInfo.getExtraLineLyrics());
|
||||||
|
} else {
|
||||||
|
viewHolder.getExtraLineLyricsYv().setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
String extraLineLyrics = makeLrcLineInfo.getExtraLineLyrics();
|
||||||
|
|
||||||
|
//该行歌词已经录制完成
|
||||||
|
if (StringUtils.isNotBlank(extraLineLyrics)) {
|
||||||
|
viewHolder.getIndexTv().setTextColor(Color.BLUE);
|
||||||
|
viewHolder.getLineLyricsYv().setTextColor(Color.BLUE);
|
||||||
|
viewHolder.getExtraLineLyricsYv().setTextColor(Color.BLUE);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
viewHolder.getIndexTv().setTextColor(Color.BLACK);
|
||||||
|
viewHolder.getLineLyricsYv().setTextColor(Color.BLACK);
|
||||||
|
viewHolder.getExtraLineLyricsYv().setTextColor(Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
//item点击
|
||||||
|
viewHolder.getItemBG().setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
mSelectedIndex = position;
|
||||||
|
if (mItemEvent != null) {
|
||||||
|
mItemEvent.itemClick(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mMakeLrcs.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemEvent(ItemEvent mItemEvent) {
|
||||||
|
this.mItemEvent = mItemEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 获取上一行歌词
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getPreIndex() {
|
||||||
|
mSelectedIndex--;
|
||||||
|
if (mSelectedIndex < 0) {
|
||||||
|
mSelectedIndex = 0;
|
||||||
|
}
|
||||||
|
return mSelectedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下一行歌词
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getNextIndex() {
|
||||||
|
mSelectedIndex++;
|
||||||
|
if (mSelectedIndex >= mMakeLrcs.size()) {
|
||||||
|
mSelectedIndex = mMakeLrcs.size() - 1;
|
||||||
|
}
|
||||||
|
return mSelectedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*/
|
||||||
|
public void saveAndUpdate() {
|
||||||
|
notifyItemChanged(mSelectedIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset(){
|
||||||
|
mSelectedIndex = -1;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
class MakeExtraLrcViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
private View view;
|
||||||
|
/**
|
||||||
|
* 索引
|
||||||
|
*/
|
||||||
|
private TextView indexTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原歌词
|
||||||
|
*/
|
||||||
|
private TextView lineLyricsYv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外歌词
|
||||||
|
*/
|
||||||
|
private TextView extraLineLyricsYv;
|
||||||
|
|
||||||
|
private ListItemRelativeLayout itemBG;
|
||||||
|
|
||||||
|
|
||||||
|
public MakeExtraLrcViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
this.view = itemView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListItemRelativeLayout getItemBG() {
|
||||||
|
if (itemBG == null) {
|
||||||
|
itemBG = view.findViewById(R.id.itemBG);
|
||||||
|
}
|
||||||
|
return itemBG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getIndexTv() {
|
||||||
|
if (indexTv == null) {
|
||||||
|
indexTv = view.findViewById(R.id.index);
|
||||||
|
}
|
||||||
|
return indexTv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getLineLyricsYv() {
|
||||||
|
if (lineLyricsYv == null) {
|
||||||
|
lineLyricsYv = view.findViewById(R.id.lineLyrics);
|
||||||
|
}
|
||||||
|
return lineLyricsYv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getExtraLineLyricsYv() {
|
||||||
|
if (extraLineLyricsYv == null) {
|
||||||
|
extraLineLyricsYv = view.findViewById(R.id.extraLineLyrics);
|
||||||
|
}
|
||||||
|
return extraLineLyricsYv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ItemEvent {
|
||||||
|
void itemClick(int index);
|
||||||
|
}
|
||||||
|
}
|
||||||
286
app/src/main/java/com/zlm/hp/application/HPApplication.java
Normal file
286
app/src/main/java/com/zlm/hp/application/HPApplication.java
Normal file
|
|
@ -0,0 +1,286 @@
|
||||||
|
package com.zlm.hp.application;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.support.multidex.MultiDexApplication;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.dou361.dialogui.DialogUIUtils;
|
||||||
|
import com.squareup.leakcanary.LeakCanary;
|
||||||
|
import com.squareup.leakcanary.RefWatcher;
|
||||||
|
import com.tencent.bugly.crashreport.CrashReport;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.constants.Constants;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.db.DBHelper;
|
||||||
|
import com.zlm.hp.manager.ActivityManager;
|
||||||
|
import com.zlm.hp.service.FloatService;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.ApkUtil;
|
||||||
|
import com.zlm.hp.util.CodeLineUtil;
|
||||||
|
import com.zlm.hp.util.ContextUtil;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.util.ZLog;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by zhangliangming on 2018-07-29.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class HPApplication extends MultiDexApplication {
|
||||||
|
|
||||||
|
private Handler mHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用来后续监控可能发生泄漏的对象
|
||||||
|
*/
|
||||||
|
private static RefWatcher sRefWatcher;
|
||||||
|
/**
|
||||||
|
* 用于记录ativity的个数
|
||||||
|
*/
|
||||||
|
private int mActivityCounter = 0;
|
||||||
|
/**
|
||||||
|
* 全局收集错误信息
|
||||||
|
*/
|
||||||
|
private Thread.UncaughtExceptionHandler mErrorHandler = new Thread.UncaughtExceptionHandler() {
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
//修改保存路径
|
||||||
|
initLog(ResourceConstants.PATH_CRASH);
|
||||||
|
//输出配置信息
|
||||||
|
String codeLineInfo = new CodeLineUtil().getCodeLineInfo();
|
||||||
|
ZLog.logBuildInfo(getApplicationContext(), codeLineInfo);
|
||||||
|
ZLog.e(codeLineInfo, "UncaughtException: ", e.getMessage());
|
||||||
|
|
||||||
|
mHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(getApplicationContext(), getString(R.string.exit_tip));
|
||||||
|
//关闭app
|
||||||
|
ActivityManager.getInstance().exit();
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
|
||||||
|
mHandler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
|
//全局收集
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(mErrorHandler);
|
||||||
|
|
||||||
|
//初始化日志
|
||||||
|
initLog(ResourceConstants.PATH_LOGCAT);
|
||||||
|
|
||||||
|
//初始化bugly
|
||||||
|
initBugly();
|
||||||
|
|
||||||
|
//初始化LeakCanary
|
||||||
|
initLeakCanary();
|
||||||
|
|
||||||
|
// 获取当前进程名
|
||||||
|
String processName = getProcessName(android.os.Process.myPid());
|
||||||
|
if (getApplicationContext().getPackageName().equals(processName)) {
|
||||||
|
//主进程
|
||||||
|
//输出配置信息
|
||||||
|
ZLog.logBuildInfo(getApplicationContext(), new CodeLineUtil().getCodeLineInfo());
|
||||||
|
//初始化数据库
|
||||||
|
initDB();
|
||||||
|
registerActivityLifecycleCallbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
//封装全局context
|
||||||
|
ContextUtil.init(getApplicationContext());
|
||||||
|
//封装弹出窗口context
|
||||||
|
DialogUIUtils.init(getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册activity
|
||||||
|
*/
|
||||||
|
private void registerActivityLifecycleCallbacks() {
|
||||||
|
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStarted(Activity activity) {
|
||||||
|
mActivityCounter++;
|
||||||
|
stopFloatService();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResumed(Activity activity) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityPaused(Activity activity) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStopped(Activity activity) {
|
||||||
|
mActivityCounter--;
|
||||||
|
startFloatService();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityDestroyed(Activity activity) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void startFloatService() {
|
||||||
|
if (mActivityCounter <= 0) {
|
||||||
|
ZLog.i(new CodeLineUtil().getCodeLineInfo(), "app background");
|
||||||
|
|
||||||
|
if (!isServiceRunning(FloatService.class.getName())) {
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
if (configInfo.isShowDesktopLrc()) {
|
||||||
|
//启动悬浮窗口服务
|
||||||
|
Intent floatServiceIntent = new Intent(getApplicationContext(), FloatService.class);
|
||||||
|
startService(floatServiceIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopFloatService() {
|
||||||
|
if (isServiceRunning(FloatService.class.getName())) {
|
||||||
|
//关闭悬浮窗口服务
|
||||||
|
Intent floatServiceIntent = new Intent(getApplicationContext(), FloatService.class);
|
||||||
|
stopService(floatServiceIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断服务是否正在运行
|
||||||
|
*
|
||||||
|
* @param serviceName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isServiceRunning(String serviceName) {
|
||||||
|
android.app.ActivityManager manager = (android.app.ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
for (android.app.ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||||
|
if (serviceName.equals(service.service.getClassName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化数据库
|
||||||
|
*/
|
||||||
|
private void initDB() {
|
||||||
|
DBHelper.getInstance(getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 初始化LeakCanary
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-05 15:24
|
||||||
|
*/
|
||||||
|
private void initLeakCanary() {
|
||||||
|
//初始化LeakCanary
|
||||||
|
if (LeakCanary.isInAnalyzerProcess(this)) {
|
||||||
|
// This process is dedicated to LeakCanary for heap analysis.
|
||||||
|
// You should not init your app in this process.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sRefWatcher = LeakCanary.install(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用来后续监控可能发生泄漏的对象
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static RefWatcher getRefWatcher() {
|
||||||
|
return sRefWatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 初始化日志
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 11:01
|
||||||
|
*/
|
||||||
|
private void initLog(String path) {
|
||||||
|
ZLog.init(getApplicationContext(), ResourceUtil.getFilePath(getApplicationContext(), path), Constants.APPNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 初始化bugly
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 10:06
|
||||||
|
*/
|
||||||
|
private void initBugly() {
|
||||||
|
CrashReport.initCrashReport(getApplicationContext(), "969a9196a8", false);
|
||||||
|
CrashReport.putUserData(getApplicationContext(), "DeviceID", ApkUtil.getUniquePsuedoID(getApplicationContext()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取进程号对应的进程名
|
||||||
|
*
|
||||||
|
* @param pid 进程号
|
||||||
|
* @return 进程名
|
||||||
|
*/
|
||||||
|
private static String getProcessName(int pid) {
|
||||||
|
BufferedReader reader = null;
|
||||||
|
try {
|
||||||
|
reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline"));
|
||||||
|
String processName = reader.readLine();
|
||||||
|
if (!TextUtils.isEmpty(processName)) {
|
||||||
|
processName = processName.trim();
|
||||||
|
}
|
||||||
|
return processName;
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
} catch (IOException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
86
app/src/main/java/com/zlm/hp/async/AsyncHandlerTask.java
Normal file
86
app/src/main/java/com/zlm/hp/async/AsyncHandlerTask.java
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.zlm.hp.async;
|
||||||
|
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异步handler任务
|
||||||
|
* Created by zhangliangming on 2018-08-12.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AsyncHandlerTask {
|
||||||
|
|
||||||
|
private WeakRefHandler mUIHandler;
|
||||||
|
private WeakRefHandler mWorkerHandler;
|
||||||
|
|
||||||
|
public AsyncHandlerTask(WeakRefHandler uiHandler, WeakRefHandler workerHandler) {
|
||||||
|
this.mUIHandler = uiHandler;
|
||||||
|
this.mWorkerHandler = workerHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行后台任务
|
||||||
|
*
|
||||||
|
* @param task 任务
|
||||||
|
*/
|
||||||
|
public void execute(Task task) {
|
||||||
|
execute(mUIHandler, mWorkerHandler, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行后台任务,子线程返回或者主线程返回
|
||||||
|
*
|
||||||
|
* @param uiHandler
|
||||||
|
* @param workerHandler
|
||||||
|
* @param task
|
||||||
|
*/
|
||||||
|
private void execute(final WeakRefHandler uiHandler, final WeakRefHandler workerHandler, final Task task) {
|
||||||
|
if (workerHandler != null) {
|
||||||
|
workerHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Object result = null;
|
||||||
|
if (workerHandler.isAlive()) {
|
||||||
|
if (task != null) {
|
||||||
|
result = task.doInBackground();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (uiHandler != null) {
|
||||||
|
final Object finalResult = result;
|
||||||
|
uiHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (uiHandler.isAlive()) {
|
||||||
|
if (task != null) {
|
||||||
|
task.onPostExecute(finalResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作任务
|
||||||
|
*/
|
||||||
|
public static abstract class Task<T> {
|
||||||
|
/**
|
||||||
|
* 后台执行
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract T doInBackground();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主线程回调
|
||||||
|
*
|
||||||
|
* @param result
|
||||||
|
*/
|
||||||
|
protected void onPostExecute(T result) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
553
app/src/main/java/com/zlm/hp/constants/ConfigInfo.java
Normal file
553
app/src/main/java/com/zlm/hp/constants/ConfigInfo.java
Normal file
|
|
@ -0,0 +1,553 @@
|
||||||
|
package com.zlm.hp.constants;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.TimerInfo;
|
||||||
|
import com.zlm.hp.util.CodeLineUtil;
|
||||||
|
import com.zlm.hp.util.ColorUtil;
|
||||||
|
import com.zlm.hp.util.ContextUtil;
|
||||||
|
import com.zlm.hp.util.FileUtil;
|
||||||
|
import com.zlm.hp.util.RandomUtil;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
import com.zlm.hp.util.ZLog;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 配置数据
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-04 21:38
|
||||||
|
**/
|
||||||
|
public class ConfigInfo implements Parcelable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static byte[] lock = new byte[0];
|
||||||
|
|
||||||
|
//开关
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是在wifi环境下使用
|
||||||
|
*/
|
||||||
|
private boolean isWifi;
|
||||||
|
/**
|
||||||
|
* 是否启动hello语音
|
||||||
|
*/
|
||||||
|
private boolean isSayHello;
|
||||||
|
/**
|
||||||
|
* 是否启动线控
|
||||||
|
*/
|
||||||
|
private boolean isWire;
|
||||||
|
/**
|
||||||
|
* 是否显示状态栏
|
||||||
|
*/
|
||||||
|
private boolean isStatusBarShow;
|
||||||
|
/**
|
||||||
|
* 是否显示桌面歌词
|
||||||
|
*/
|
||||||
|
private boolean isShowDesktopLrc;
|
||||||
|
/**
|
||||||
|
* 是否是显示锁屏歌词
|
||||||
|
*/
|
||||||
|
private boolean isShowLockScreenLrc;
|
||||||
|
/**
|
||||||
|
* MV播放模式,0表示不播放MV,1表示有MV就只播放MV,2表示有MV就随机选择播放MV和歌曲文件
|
||||||
|
*/
|
||||||
|
private int MVPlayMode;
|
||||||
|
/**
|
||||||
|
* 歌手和歌名是否居中显示
|
||||||
|
*/
|
||||||
|
private boolean isCenterSingerSongName;
|
||||||
|
/**
|
||||||
|
* 最小字体大小
|
||||||
|
*/
|
||||||
|
public static final int MIN_LRC_FONT_SIZE = 30;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大字体大小
|
||||||
|
*/
|
||||||
|
public static final int MAX_LRC_FONT_SIZE = 100;
|
||||||
|
|
||||||
|
//歌词相关
|
||||||
|
/**
|
||||||
|
* 歌词字体大小
|
||||||
|
*/
|
||||||
|
private int lrcFontSize = MIN_LRC_FONT_SIZE;
|
||||||
|
/**
|
||||||
|
* 歌词颜色索引
|
||||||
|
*/
|
||||||
|
private int lrcColorIndex;
|
||||||
|
|
||||||
|
|
||||||
|
//桌面
|
||||||
|
/**
|
||||||
|
* 桌面歌词显示可移动
|
||||||
|
*/
|
||||||
|
private boolean isDesktopLrcCanMove = true;
|
||||||
|
/**
|
||||||
|
* 桌面歌词颜色索引
|
||||||
|
*/
|
||||||
|
private int desktopLrcColorIndex;
|
||||||
|
/**
|
||||||
|
* 桌面歌词字体大小
|
||||||
|
*/
|
||||||
|
private int desktopLrcFontSize;
|
||||||
|
/**
|
||||||
|
* 桌面歌词y轴位置
|
||||||
|
*/
|
||||||
|
private int desktopLrcY;
|
||||||
|
|
||||||
|
//歌曲相关数据
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前播放歌曲的hash
|
||||||
|
*/
|
||||||
|
private String playHash = "";
|
||||||
|
/**
|
||||||
|
* 当前播放模式
|
||||||
|
*/
|
||||||
|
private int playModel = 0; // 0是 顺序播放 1是随机播放 2是循环播放 3是单曲播放
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前播放歌曲列表
|
||||||
|
*/
|
||||||
|
private List<AudioInfo> audioInfos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示翻译歌词
|
||||||
|
*/
|
||||||
|
public static final int EXTRALRCSTATUS_SHOWTRANSLATELRC = 0;
|
||||||
|
/**
|
||||||
|
* 显示音译歌词
|
||||||
|
*/
|
||||||
|
public static final int EXTRALRCSTATUS_SHOWTRANSLITERATIONLRC = 1;
|
||||||
|
/**
|
||||||
|
* 只显示默认歌词
|
||||||
|
*/
|
||||||
|
public static final int EXTRALRCSTATUS_NOSHOWEXTRALRC = 2;
|
||||||
|
/**
|
||||||
|
* 默认只显示默认歌词
|
||||||
|
*/
|
||||||
|
private int extraLrcStatus = EXTRALRCSTATUS_NOSHOWEXTRALRC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 桌面歌词未读颜色
|
||||||
|
*/
|
||||||
|
public static int DESKTOP_LRC_NOREAD_COLORS[][] = {{
|
||||||
|
ColorUtil.parserColor("#00348a"),
|
||||||
|
ColorUtil.parserColor("#0080c0"),
|
||||||
|
ColorUtil.parserColor("#03cafc")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#ffffff"),
|
||||||
|
ColorUtil.parserColor("#ffffff"),
|
||||||
|
ColorUtil.parserColor("#ffffff")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#ffffff"),
|
||||||
|
ColorUtil.parserColor("#ffffff"),
|
||||||
|
ColorUtil.parserColor("#ffffff")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#ffac00"),
|
||||||
|
ColorUtil.parserColor("#ff0000"),
|
||||||
|
ColorUtil.parserColor("#aa0000")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#93ff26"),
|
||||||
|
ColorUtil.parserColor("#46b000"),
|
||||||
|
ColorUtil.parserColor("#005500")
|
||||||
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 桌面歌词已读颜色
|
||||||
|
*/
|
||||||
|
public static int DESKTOP_LRC_READED_COLORS[][] = {{
|
||||||
|
ColorUtil.parserColor("#82f7fd"),
|
||||||
|
ColorUtil.parserColor("#ffffff"),
|
||||||
|
ColorUtil.parserColor("#03e9fc")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#ffff00"),
|
||||||
|
ColorUtil.parserColor("#ffff00"),
|
||||||
|
ColorUtil.parserColor("#ffff00")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#e17db3"),
|
||||||
|
ColorUtil.parserColor("#e17db3"),
|
||||||
|
ColorUtil.parserColor("#e17db3")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#ffffa4"),
|
||||||
|
ColorUtil.parserColor("#ffff00"),
|
||||||
|
ColorUtil.parserColor("#ff641a")
|
||||||
|
}, {
|
||||||
|
ColorUtil.parserColor("#ffffff"),
|
||||||
|
ColorUtil.parserColor("#9aff11"),
|
||||||
|
ColorUtil.parserColor("#ffff00")
|
||||||
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词颜色集合
|
||||||
|
*/
|
||||||
|
public static String[] LRC_COLORS_STRING = {"#fada83", "#fe8db6", "#feb88e",
|
||||||
|
"#adfe8e", "#8dc7ff", "#e69bff"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时器
|
||||||
|
*/
|
||||||
|
private TimerInfo timerInfo;
|
||||||
|
|
||||||
|
|
||||||
|
protected ConfigInfo(Parcel in) {
|
||||||
|
if (in != null) {
|
||||||
|
isWifi = in.readByte() != 0;
|
||||||
|
isSayHello = in.readByte() != 0;
|
||||||
|
isWire = in.readByte() != 0;
|
||||||
|
isShowDesktopLrc = in.readByte() != 0;
|
||||||
|
isShowLockScreenLrc = in.readByte() != 0;
|
||||||
|
lrcFontSize = in.readInt();
|
||||||
|
lrcColorIndex = in.readInt();
|
||||||
|
isDesktopLrcCanMove = in.readByte() != 0;
|
||||||
|
desktopLrcColorIndex = in.readInt();
|
||||||
|
desktopLrcFontSize = in.readInt();
|
||||||
|
desktopLrcY = in.readInt();
|
||||||
|
playHash = in.readString();
|
||||||
|
playModel = in.readInt();
|
||||||
|
isStatusBarShow= in.readByte() != 0;
|
||||||
|
MVPlayMode=in.readInt();
|
||||||
|
isCenterSingerSongName= in.readByte() != 0;
|
||||||
|
// audioInfos = in.createTypedArrayList(AudioInfo.CREATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeByte((byte) (isWifi ? 1 : 0));
|
||||||
|
dest.writeByte((byte) (isSayHello ? 1 : 0));
|
||||||
|
dest.writeByte((byte) (isWire ? 1 : 0));
|
||||||
|
dest.writeByte((byte) (isShowDesktopLrc ? 1 : 0));
|
||||||
|
dest.writeByte((byte) (isShowLockScreenLrc ? 1 : 0));
|
||||||
|
dest.writeInt(lrcFontSize);
|
||||||
|
dest.writeInt(lrcColorIndex);
|
||||||
|
dest.writeByte((byte) (isDesktopLrcCanMove ? 1 : 0));
|
||||||
|
dest.writeInt(desktopLrcColorIndex);
|
||||||
|
dest.writeInt(desktopLrcFontSize);
|
||||||
|
dest.writeInt(desktopLrcY);
|
||||||
|
dest.writeString(playHash);
|
||||||
|
dest.writeInt(playModel);
|
||||||
|
dest.writeByte((byte) (isStatusBarShow ? 1 : 0));
|
||||||
|
dest.writeInt(MVPlayMode);
|
||||||
|
dest.writeByte((byte) (isCenterSingerSongName ? 1 : 0));
|
||||||
|
// dest.writeTypedList(audioInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<ConfigInfo> CREATOR = new Creator<ConfigInfo>() {
|
||||||
|
@Override
|
||||||
|
public ConfigInfo createFromParcel(Parcel in) {
|
||||||
|
return new ConfigInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigInfo[] newArray(int size) {
|
||||||
|
return new ConfigInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ConfigInfo load() {
|
||||||
|
Parcel parcel = null;
|
||||||
|
synchronized (lock) {
|
||||||
|
String filePath = ResourceUtil.getContextFilePath(ContextUtil.getContext(), ResourceConstants.PATH_CONFIG, Constants.CONFIG);
|
||||||
|
try {
|
||||||
|
byte[] data = FileUtil.readFile(filePath);
|
||||||
|
if (data == null) {
|
||||||
|
parcel = null;
|
||||||
|
ZLog.i(new CodeLineUtil().getCodeLineInfo(), "ConfigInfo.load readFile => null");
|
||||||
|
} else {
|
||||||
|
parcel = Parcel.obtain();
|
||||||
|
parcel.unmarshall(data, 0, data.length);
|
||||||
|
parcel.setDataPosition(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
ZLog.e(new CodeLineUtil().getCodeLineInfo(), "ConfigInfo.load Exception: ", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
_ConfigInfo = CREATOR.createFromParcel(parcel);
|
||||||
|
return _ConfigInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static ConfigInfo _ConfigInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ConfigInfo obtain() {
|
||||||
|
if (_ConfigInfo == null) {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
return _ConfigInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ConfigInfo save() {
|
||||||
|
Parcel parcel = Parcel.obtain();
|
||||||
|
writeToParcel(parcel, PARCELABLE_WRITE_RETURN_VALUE);
|
||||||
|
synchronized (lock) {
|
||||||
|
try {
|
||||||
|
String filePath = ResourceUtil.getContextFilePath(ContextUtil.getContext(), ResourceConstants.PATH_CONFIG, Constants.CONFIG);
|
||||||
|
FileUtil.writeFile(filePath, parcel.marshall());
|
||||||
|
} catch (Exception e) {
|
||||||
|
ZLog.e(new CodeLineUtil().getCodeLineInfo(), "ConfigInfo.save Exception: ", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
_ConfigInfo = this;
|
||||||
|
return _ConfigInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWifi() {
|
||||||
|
return isWifi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setWifi(boolean wifi) {
|
||||||
|
isWifi = wifi;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSayHello() {
|
||||||
|
return isSayHello;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setSayHello(boolean sayHello) {
|
||||||
|
isSayHello = sayHello;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWire() {
|
||||||
|
return isWire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setWire(boolean wire) {
|
||||||
|
isWire = wire;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public boolean isStatusBarShow() {
|
||||||
|
return isStatusBarShow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setStatusBarShow(boolean statusbar_show) {
|
||||||
|
isStatusBarShow = statusbar_show;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public boolean isCenterSingerSongName() {
|
||||||
|
return isCenterSingerSongName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setIsCenterSingerSongName(boolean is_CenterSingerSongName) {
|
||||||
|
isCenterSingerSongName = is_CenterSingerSongName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public boolean isShowDesktopLrc() {
|
||||||
|
return isShowDesktopLrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setShowDesktopLrc(boolean showDesktopLrc) {
|
||||||
|
isShowDesktopLrc = showDesktopLrc;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShowLockScreenLrc() {
|
||||||
|
return isShowLockScreenLrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setShowLockScreenLrc(boolean showLockScreenLrc) {
|
||||||
|
isShowLockScreenLrc = showLockScreenLrc;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLrcFontSize() {
|
||||||
|
return lrcFontSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setLrcFontSize(int lrcFontSize) {
|
||||||
|
this.lrcFontSize = lrcFontSize;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLrcColorIndex() {
|
||||||
|
return lrcColorIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setLrcColorIndex(int lrcColorIndex) {
|
||||||
|
this.lrcColorIndex = lrcColorIndex;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDesktopLrcCanMove() {
|
||||||
|
return isDesktopLrcCanMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setDesktopLrcCanMove(boolean desktopLrcCanMove) {
|
||||||
|
isDesktopLrcCanMove = desktopLrcCanMove;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDesktopLrcColorIndex() {
|
||||||
|
return desktopLrcColorIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setDesktopLrcColorIndex(int desktopLrcColorIndex) {
|
||||||
|
this.desktopLrcColorIndex = desktopLrcColorIndex;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDesktopLrcFontSize() {
|
||||||
|
return desktopLrcFontSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setDesktopLrcFontSize(int desktopLrcFontSize) {
|
||||||
|
this.desktopLrcFontSize = desktopLrcFontSize;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDesktopLrcY() {
|
||||||
|
return desktopLrcY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setDesktopLrcY(int desktopLrcY) {
|
||||||
|
this.desktopLrcY = desktopLrcY;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayHash() {
|
||||||
|
return playHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setPlayHash(String playHash) {
|
||||||
|
this.playHash = playHash;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimerInfo getTimerInfo() {
|
||||||
|
return timerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimerInfo(TimerInfo timerInfo) {
|
||||||
|
this.timerInfo = timerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPlayModel() {
|
||||||
|
return playModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setPlayModel(int playModel) {
|
||||||
|
this.playModel = playModel;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getExtraLrcStatus() {
|
||||||
|
return extraLrcStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setExtraLrcStatus(int extraLrcStatus) {
|
||||||
|
this.extraLrcStatus = extraLrcStatus;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AudioInfo> getAudioInfos() {
|
||||||
|
if (audioInfos == null) {
|
||||||
|
loadPlayListData();
|
||||||
|
}
|
||||||
|
return audioInfos;
|
||||||
|
}
|
||||||
|
public int getMVPlayMode() {
|
||||||
|
return MVPlayMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setMVPlayMode(int MVPlayMode) {
|
||||||
|
this.MVPlayMode = MVPlayMode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigInfo setAudioInfos(List<AudioInfo> audioInfos) {
|
||||||
|
//添加随机数
|
||||||
|
RandomUtil.setNums(audioInfos.size());
|
||||||
|
this.audioInfos = audioInfos;
|
||||||
|
savePlayListData(audioInfos);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 加载播放列表
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-10-06 23:21
|
||||||
|
*/
|
||||||
|
private void loadPlayListData() {
|
||||||
|
Parcel parcel = null;
|
||||||
|
synchronized (lock) {
|
||||||
|
String filePath = ResourceUtil.getContextFilePath(ContextUtil.getContext(), ResourceConstants.PATH_CONFIG, Constants.PLAYLIST);
|
||||||
|
try {
|
||||||
|
byte[] data = FileUtil.readFile(filePath);
|
||||||
|
if (data == null) {
|
||||||
|
parcel = null;
|
||||||
|
ZLog.i(new CodeLineUtil().getCodeLineInfo(), "ConfigInfo.loadPlayListData readFile => null");
|
||||||
|
} else {
|
||||||
|
parcel = Parcel.obtain();
|
||||||
|
parcel.unmarshall(data, 0, data.length);
|
||||||
|
parcel.setDataPosition(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
ZLog.e(new CodeLineUtil().getCodeLineInfo(), "ConfigInfo.loadPlayListData Exception: ", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parcel == null) {
|
||||||
|
audioInfos = new ArrayList<AudioInfo>();
|
||||||
|
} else {
|
||||||
|
audioInfos = parcel.createTypedArrayList(AudioInfo.CREATOR);
|
||||||
|
}
|
||||||
|
//添加随机数
|
||||||
|
RandomUtil.setNums(audioInfos.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 保存播放列表数据
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-10-06 23:26
|
||||||
|
*/
|
||||||
|
private void savePlayListData(List<AudioInfo> audioInfos) {
|
||||||
|
Parcel parcel = Parcel.obtain();
|
||||||
|
parcel.writeTypedList(audioInfos);
|
||||||
|
synchronized (lock) {
|
||||||
|
try {
|
||||||
|
String filePath = ResourceUtil.getContextFilePath(ContextUtil.getContext(), ResourceConstants.PATH_CONFIG, Constants.PLAYLIST);
|
||||||
|
FileUtil.writeFile(filePath, parcel.marshall());
|
||||||
|
} catch (Exception e) {
|
||||||
|
ZLog.e(new CodeLineUtil().getCodeLineInfo(), "ConfigInfo.savePlayListData Exception: ", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
app/src/main/java/com/zlm/hp/constants/Constants.java
Normal file
46
app/src/main/java/com/zlm/hp/constants/Constants.java
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.zlm.hp.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 基础信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-08-05 15:16
|
||||||
|
**/
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是第一次使用,return true/false
|
||||||
|
*/
|
||||||
|
public static final String IS_FRIST_KEY = "isFristKey";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app应用名
|
||||||
|
*/
|
||||||
|
public final static String APPNAME = "HappyPlayer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置文件名称
|
||||||
|
*/
|
||||||
|
public final static String CONFIG = "happy-player-config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲播放列表
|
||||||
|
*/
|
||||||
|
public final static String PLAYLIST = "happy-player-list";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备id
|
||||||
|
*/
|
||||||
|
public final static String DEVICE_ID = "DeviceID";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 锁屏权限
|
||||||
|
*/
|
||||||
|
public final static String ASK_LOCK_PERMISSION = "AskLockPermission";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态广播自定义权限
|
||||||
|
*/
|
||||||
|
public final static String RECEIVER_PERMISSION = "com.zlm.hp.permissions.RECEIVER";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.zlm.hp.constants;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 资源文件常量
|
||||||
|
* @Author: zhangliangming
|
||||||
|
* @Date: 2017/7/16 13:40
|
||||||
|
* @Version:
|
||||||
|
*/
|
||||||
|
public class ResourceConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临时目录
|
||||||
|
*/
|
||||||
|
public final static String PATH_TEMP = "haplayer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logcat日志目录
|
||||||
|
*/
|
||||||
|
public final static String PATH_LOGCAT = PATH_TEMP + File.separator
|
||||||
|
+ "logcat";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基本数据
|
||||||
|
*/
|
||||||
|
public final static String PATH_CONFIG = PATH_TEMP + File.separator
|
||||||
|
+ "config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局异常日志目录
|
||||||
|
*/
|
||||||
|
public final static String PATH_CRASH = PATH_TEMP + File.separator
|
||||||
|
+ "crash";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词目录
|
||||||
|
*/
|
||||||
|
public final static String PATH_LYRICS = PATH_TEMP + File.separator + "lyrics";
|
||||||
|
/**
|
||||||
|
* 歌曲目录
|
||||||
|
*/
|
||||||
|
public final static String PATH_AUDIO = PATH_TEMP + File.separator + "audio";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲临时保存路径
|
||||||
|
*/
|
||||||
|
public final static String PATH_AUDIO_TEMP = PATH_AUDIO + File.separator + "temp";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频目录
|
||||||
|
*/
|
||||||
|
public final static String PATH_VIDEO = PATH_TEMP + File.separator + "video";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频临时保存路径
|
||||||
|
*/
|
||||||
|
public final static String PATH_VIDEO_TEMP = PATH_VIDEO + File.separator + "temp";
|
||||||
|
/**
|
||||||
|
* 歌手写真目录
|
||||||
|
*/
|
||||||
|
public final static String PATH_SINGER = PATH_TEMP + File.separator
|
||||||
|
+ "singer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存
|
||||||
|
*/
|
||||||
|
public final static String PATH_CACHE = PATH_TEMP + File.separator
|
||||||
|
+ "cache";
|
||||||
|
/**
|
||||||
|
* 图片缓存
|
||||||
|
*/
|
||||||
|
public final static String PATH_CACHE_IMAGE = PATH_TEMP + File.separator
|
||||||
|
+ "cache" + File.separator + "image";
|
||||||
|
/**
|
||||||
|
* 歌曲缓存
|
||||||
|
*/
|
||||||
|
public final static String PATH_CACHE_AUDIO = PATH_TEMP + File.separator
|
||||||
|
+ "cache" + File.separator + "audio";
|
||||||
|
|
||||||
|
}
|
||||||
87
app/src/main/java/com/zlm/hp/db/DBHelper.java
Normal file
87
app/src/main/java/com/zlm/hp/db/DBHelper.java
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.zlm.hp.db;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.dao.DaoMaster;
|
||||||
|
import com.zlm.hp.db.dao.DaoSession;
|
||||||
|
import com.zlm.hp.util.ApkUtil;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库辅助类
|
||||||
|
* Created by zhangliangming on 2018-08-18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DBHelper {
|
||||||
|
private final String DB_NAME = "happyplayer.db";
|
||||||
|
private static DBHelper _DBHelper;
|
||||||
|
private static UpdateOpenHelper mDevOpenHelper;
|
||||||
|
private static DaoMaster mDaoMaster;
|
||||||
|
private static DaoSession mDaoSession;
|
||||||
|
private static String mPassword;
|
||||||
|
|
||||||
|
private DBHelper(Context context) {
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context) {
|
||||||
|
mPassword = ApkUtil.getUniquePsuedoID(context);
|
||||||
|
// 初始化数据库信息
|
||||||
|
mDevOpenHelper = new UpdateOpenHelper(context, DB_NAME, null);
|
||||||
|
getDaoMaster();
|
||||||
|
getDaoSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DBHelper getInstance(Context context) {
|
||||||
|
if (null == _DBHelper) {
|
||||||
|
synchronized (DBHelper.class) {
|
||||||
|
if (null == _DBHelper) {
|
||||||
|
_DBHelper = new DBHelper(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _DBHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取可写数据库
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Database getWritableDatabase() {
|
||||||
|
return mDevOpenHelper.getEncryptedWritableDb(mPassword);
|
||||||
|
// return mDevOpenHelper.getWritableDb();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取DaoMaster
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private DaoMaster getDaoMaster() {
|
||||||
|
if (null == mDaoMaster) {
|
||||||
|
synchronized (DBHelper.class) {
|
||||||
|
if (null == mDaoMaster) {
|
||||||
|
mDaoMaster = new DaoMaster(getWritableDatabase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mDaoMaster;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取DaoSession
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public DaoSession getDaoSession() {
|
||||||
|
if (null == mDaoSession) {
|
||||||
|
synchronized (DBHelper.class) {
|
||||||
|
mDaoSession = getDaoMaster().newSession();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mDaoSession;
|
||||||
|
}
|
||||||
|
}
|
||||||
168
app/src/main/java/com/zlm/hp/db/MigrationHelper.java
Normal file
168
app/src/main/java/com/zlm/hp/db/MigrationHelper.java
Normal file
|
|
@ -0,0 +1,168 @@
|
||||||
|
package com.zlm.hp.db;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.dao.DaoMaster;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDao;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.internal.DaoConfig;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 升级数据库辅助类
|
||||||
|
*/
|
||||||
|
public class MigrationHelper {
|
||||||
|
|
||||||
|
private static final String CONVERSION_CLASS_NOT_FOUND_EXCEPTION = "MIGRATION HELPER - CLASS DOESN'T MATCH WITH THE CURRENT PARAMETERS";
|
||||||
|
private static MigrationHelper instance;
|
||||||
|
|
||||||
|
public static MigrationHelper getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new MigrationHelper();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void migrate(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
|
||||||
|
|
||||||
|
generateTempTables(db, daoClasses);
|
||||||
|
DaoMaster.dropAllTables(db, true);
|
||||||
|
DaoMaster.createAllTables(db, false);
|
||||||
|
restoreData(db, daoClasses);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成临时列表
|
||||||
|
*
|
||||||
|
* @param db
|
||||||
|
* @param daoClasses
|
||||||
|
*/
|
||||||
|
private void generateTempTables(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
|
||||||
|
for (int i = 0; i < daoClasses.length; i++) {
|
||||||
|
DaoConfig daoConfig = new DaoConfig(db, daoClasses[i]);
|
||||||
|
|
||||||
|
String divider = "";
|
||||||
|
String tableName = daoConfig.tablename;
|
||||||
|
String tempTableName = daoConfig.tablename.concat("_TEMP");
|
||||||
|
ArrayList<String> properties = new ArrayList<>();
|
||||||
|
|
||||||
|
StringBuilder createTableStringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
createTableStringBuilder.append("CREATE TABLE ").append(tempTableName).append(" (");
|
||||||
|
|
||||||
|
for (int j = 0; j < daoConfig.properties.length; j++) {
|
||||||
|
String columnName = daoConfig.properties[j].columnName;
|
||||||
|
|
||||||
|
if (getColumns(db, tableName).contains(columnName)) {
|
||||||
|
properties.add(columnName);
|
||||||
|
|
||||||
|
String type = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
type = getTypeByClass(daoConfig.properties[j].type);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
createTableStringBuilder.append(divider).append(columnName).append(" ").append(type);
|
||||||
|
|
||||||
|
if (daoConfig.properties[j].primaryKey) {
|
||||||
|
createTableStringBuilder.append(" PRIMARY KEY");
|
||||||
|
}
|
||||||
|
|
||||||
|
divider = ",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
createTableStringBuilder.append(");");
|
||||||
|
|
||||||
|
db.execSQL(createTableStringBuilder.toString());
|
||||||
|
|
||||||
|
StringBuilder insertTableStringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
insertTableStringBuilder.append("INSERT INTO ").append(tempTableName).append(" (");
|
||||||
|
insertTableStringBuilder.append(TextUtils.join(",", properties));
|
||||||
|
insertTableStringBuilder.append(") SELECT ");
|
||||||
|
insertTableStringBuilder.append(TextUtils.join(",", properties));
|
||||||
|
insertTableStringBuilder.append(" FROM ").append(tableName).append(";");
|
||||||
|
|
||||||
|
db.execSQL(insertTableStringBuilder.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储新的数据库表 以及数据
|
||||||
|
*
|
||||||
|
* @param db
|
||||||
|
* @param daoClasses
|
||||||
|
*/
|
||||||
|
private void restoreData(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
|
||||||
|
for (int i = 0; i < daoClasses.length; i++) {
|
||||||
|
DaoConfig daoConfig = new DaoConfig(db, daoClasses[i]);
|
||||||
|
String tableName = daoConfig.tablename;
|
||||||
|
String tempTableName = daoConfig.tablename.concat("_TEMP");
|
||||||
|
ArrayList<String> properties = new ArrayList();
|
||||||
|
|
||||||
|
for (int j = 0; j < daoConfig.properties.length; j++) {
|
||||||
|
String columnName = daoConfig.properties[j].columnName;
|
||||||
|
|
||||||
|
if (getColumns(db, tempTableName).contains(columnName)) {
|
||||||
|
properties.add(columnName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder insertTableStringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
insertTableStringBuilder.append("INSERT INTO ").append(tableName).append(" (");
|
||||||
|
insertTableStringBuilder.append(TextUtils.join(",", properties));
|
||||||
|
insertTableStringBuilder.append(") SELECT ");
|
||||||
|
insertTableStringBuilder.append(TextUtils.join(",", properties));
|
||||||
|
insertTableStringBuilder.append(" FROM ").append(tempTableName).append(";");
|
||||||
|
|
||||||
|
StringBuilder dropTableStringBuilder = new StringBuilder();
|
||||||
|
dropTableStringBuilder.append("DROP TABLE ").append(tempTableName);
|
||||||
|
db.execSQL(insertTableStringBuilder.toString());
|
||||||
|
db.execSQL(dropTableStringBuilder.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTypeByClass(Class<?> type) throws Exception {
|
||||||
|
if (type.equals(String.class)) {
|
||||||
|
return "TEXT";
|
||||||
|
}
|
||||||
|
if (type.equals(Long.class) || type.equals(Integer.class) || type.equals(long.class)) {
|
||||||
|
return "INTEGER";
|
||||||
|
}
|
||||||
|
if (type.equals(Boolean.class)) {
|
||||||
|
return "BOOLEAN";
|
||||||
|
}
|
||||||
|
|
||||||
|
Exception exception = new Exception(CONVERSION_CLASS_NOT_FOUND_EXCEPTION.concat(" - Class: ").concat(type.toString()));
|
||||||
|
exception.printStackTrace();
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getColumns(Database db, String tableName) {
|
||||||
|
List<String> columns = new ArrayList<>();
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
|
||||||
|
if (cursor != null) {
|
||||||
|
columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.v(tableName, e.getMessage(), e);
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null)
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
app/src/main/java/com/zlm/hp/db/UpdateOpenHelper.java
Normal file
33
app/src/main/java/com/zlm/hp/db/UpdateOpenHelper.java
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.zlm.hp.db;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.dao.DaoMaster;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*/
|
||||||
|
public class UpdateOpenHelper extends DaoMaster.OpenHelper {
|
||||||
|
|
||||||
|
public UpdateOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
|
||||||
|
super(context, name, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据库升级
|
||||||
|
*
|
||||||
|
* @param db
|
||||||
|
* @param oldVersion
|
||||||
|
* @param newVersion
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(Database db, int oldVersion, int newVersion) {
|
||||||
|
if (oldVersion < newVersion) {
|
||||||
|
//操作数据库的更新 有几个表升级都可以传入到下面
|
||||||
|
//MigrationHelper.getInstance().migrate(db, AudioInfoDao.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
352
app/src/main/java/com/zlm/hp/db/dao/AudioInfoDao.java
Normal file
352
app/src/main/java/com/zlm/hp/db/dao/AudioInfoDao.java
Normal file
|
|
@ -0,0 +1,352 @@
|
||||||
|
package com.zlm.hp.db.dao;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteStatement;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDao;
|
||||||
|
import org.greenrobot.greendao.Property;
|
||||||
|
import org.greenrobot.greendao.internal.DaoConfig;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.database.DatabaseStatement;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
|
||||||
|
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||||
|
/**
|
||||||
|
* DAO for table "AUDIO_INFO".
|
||||||
|
*/
|
||||||
|
public class AudioInfoDao extends AbstractDao<AudioInfo, Void> {
|
||||||
|
|
||||||
|
public static final String TABLENAME = "AUDIO_INFO";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties of entity AudioInfo.<br/>
|
||||||
|
* Can be used for QueryBuilder and for referencing column names.
|
||||||
|
*/
|
||||||
|
public static class Properties {
|
||||||
|
public final static Property Status = new Property(0, int.class, "status", false, "STATUS");
|
||||||
|
public final static Property Type = new Property(1, int.class, "type", false, "TYPE");
|
||||||
|
public final static Property Keyword = new Property(2, String.class, "keyword", false, "KEYWORD");
|
||||||
|
public final static Property ImageUrl = new Property(3, String.class, "imageUrl", false, "IMAGE_URL");
|
||||||
|
public final static Property SpecialId = new Property(4, String.class, "specialId", false, "SPECIAL_ID");
|
||||||
|
public final static Property SingerId = new Property(5, String.class, "singerId", false, "SINGER_ID");
|
||||||
|
public final static Property AlbumId = new Property(6, String.class, "albumId", false, "ALBUM_ID");
|
||||||
|
public final static Property SongName = new Property(7, String.class, "songName", false, "SONG_NAME");
|
||||||
|
public final static Property SingerName = new Property(8, String.class, "singerName", false, "SINGER_NAME");
|
||||||
|
public final static Property Hash = new Property(9, String.class, "hash", false, "HASH");
|
||||||
|
public final static Property MvHash = new Property(10, String.class, "mvHash", false, "MV_HASH");
|
||||||
|
public final static Property FileExt = new Property(11, String.class, "fileExt", false, "FILE_EXT");
|
||||||
|
public final static Property FileSize = new Property(12, long.class, "fileSize", false, "FILE_SIZE");
|
||||||
|
public final static Property FileSizeText = new Property(13, String.class, "fileSizeText", false, "FILE_SIZE_TEXT");
|
||||||
|
public final static Property FilePath = new Property(14, String.class, "filePath", false, "FILE_PATH");
|
||||||
|
public final static Property Duration = new Property(15, long.class, "duration", false, "DURATION");
|
||||||
|
public final static Property DurationText = new Property(16, String.class, "durationText", false, "DURATION_TEXT");
|
||||||
|
public final static Property CreateTime = new Property(17, String.class, "createTime", false, "CREATE_TIME");
|
||||||
|
public final static Property Category = new Property(18, String.class, "category", false, "CATEGORY");
|
||||||
|
public final static Property ChildCategory = new Property(19, String.class, "childCategory", false, "CHILD_CATEGORY");
|
||||||
|
public final static Property DownloadUrl = new Property(20, String.class, "downloadUrl", false, "DOWNLOAD_URL");
|
||||||
|
public final static Property MvPath = new Property(21, String.class, "mvPath", false, "MV_PATH");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AudioInfoDao(DaoConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AudioInfoDao(DaoConfig config, DaoSession daoSession) {
|
||||||
|
super(config, daoSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates the underlying database table. */
|
||||||
|
public static void createTable(Database db, boolean ifNotExists) {
|
||||||
|
String constraint = ifNotExists? "IF NOT EXISTS ": "";
|
||||||
|
db.execSQL("CREATE TABLE " + constraint + "\"AUDIO_INFO\" (" + //
|
||||||
|
"\"STATUS\" INTEGER NOT NULL ," + // 0: status
|
||||||
|
"\"TYPE\" INTEGER NOT NULL ," + // 1: type
|
||||||
|
"\"KEYWORD\" TEXT," + // 2: keyword
|
||||||
|
"\"IMAGE_URL\" TEXT," + // 3: imageUrl
|
||||||
|
"\"SPECIAL_ID\" TEXT," + // 4: specialId
|
||||||
|
"\"SINGER_ID\" TEXT," + // 5: singerId
|
||||||
|
"\"ALBUM_ID\" TEXT," + // 6: albumId
|
||||||
|
"\"SONG_NAME\" TEXT," + // 7: songName
|
||||||
|
"\"SINGER_NAME\" TEXT," + // 8: singerName
|
||||||
|
"\"HASH\" TEXT," + // 9: hash
|
||||||
|
"\"MV_HASH\" TEXT," + // 10: mvHash
|
||||||
|
"\"FILE_EXT\" TEXT," + // 11: fileExt
|
||||||
|
"\"FILE_SIZE\" INTEGER NOT NULL ," + // 12: fileSize
|
||||||
|
"\"FILE_SIZE_TEXT\" TEXT," + // 13: fileSizeText
|
||||||
|
"\"FILE_PATH\" TEXT," + // 14: filePath
|
||||||
|
"\"DURATION\" INTEGER NOT NULL ," + // 15: duration
|
||||||
|
"\"DURATION_TEXT\" TEXT," + // 16: durationText
|
||||||
|
"\"CREATE_TIME\" TEXT," + // 17: createTime
|
||||||
|
"\"CATEGORY\" TEXT," + // 18: category
|
||||||
|
"\"CHILD_CATEGORY\" TEXT," + // 19: childCategory
|
||||||
|
"\"DOWNLOAD_URL\" TEXT," + // 20: downloadUrl
|
||||||
|
"\"MV_PATH\" TEXT);"); // 21: mvPath
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drops the underlying database table. */
|
||||||
|
public static void dropTable(Database db, boolean ifExists) {
|
||||||
|
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"AUDIO_INFO\"";
|
||||||
|
db.execSQL(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(DatabaseStatement stmt, AudioInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
stmt.bindLong(1, entity.getStatus());
|
||||||
|
stmt.bindLong(2, entity.getType());
|
||||||
|
|
||||||
|
String keyword = entity.getKeyword();
|
||||||
|
if (keyword != null) {
|
||||||
|
stmt.bindString(3, keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = entity.getImageUrl();
|
||||||
|
if (imageUrl != null) {
|
||||||
|
stmt.bindString(4, imageUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String specialId = entity.getSpecialId();
|
||||||
|
if (specialId != null) {
|
||||||
|
stmt.bindString(5, specialId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerId = entity.getSingerId();
|
||||||
|
if (singerId != null) {
|
||||||
|
stmt.bindString(6, singerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String albumId = entity.getAlbumId();
|
||||||
|
if (albumId != null) {
|
||||||
|
stmt.bindString(7, albumId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String songName = entity.getSongName();
|
||||||
|
if (songName != null) {
|
||||||
|
stmt.bindString(8, songName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerName = entity.getSingerName();
|
||||||
|
if (singerName != null) {
|
||||||
|
stmt.bindString(9, singerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String hash = entity.getHash();
|
||||||
|
if (hash != null) {
|
||||||
|
stmt.bindString(10, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mvHash = entity.getMvHash();
|
||||||
|
if (mvHash != null) {
|
||||||
|
stmt.bindString(11, mvHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileExt = entity.getFileExt();
|
||||||
|
if (fileExt != null) {
|
||||||
|
stmt.bindString(12, fileExt);
|
||||||
|
}
|
||||||
|
stmt.bindLong(13, entity.getFileSize());
|
||||||
|
|
||||||
|
String fileSizeText = entity.getFileSizeText();
|
||||||
|
if (fileSizeText != null) {
|
||||||
|
stmt.bindString(14, fileSizeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String filePath = entity.getFilePath();
|
||||||
|
if (filePath != null) {
|
||||||
|
stmt.bindString(15, filePath);
|
||||||
|
}
|
||||||
|
stmt.bindLong(16, entity.getDuration());
|
||||||
|
|
||||||
|
String durationText = entity.getDurationText();
|
||||||
|
if (durationText != null) {
|
||||||
|
stmt.bindString(17, durationText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String createTime = entity.getCreateTime();
|
||||||
|
if (createTime != null) {
|
||||||
|
stmt.bindString(18, createTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
String category = entity.getCategory();
|
||||||
|
if (category != null) {
|
||||||
|
stmt.bindString(19, category);
|
||||||
|
}
|
||||||
|
|
||||||
|
String childCategory = entity.getChildCategory();
|
||||||
|
if (childCategory != null) {
|
||||||
|
stmt.bindString(20, childCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
String downloadUrl = entity.getDownloadUrl();
|
||||||
|
if (downloadUrl != null) {
|
||||||
|
stmt.bindString(21, downloadUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mvPath = entity.getMvPath();
|
||||||
|
if (mvPath != null) {
|
||||||
|
stmt.bindString(22, mvPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(SQLiteStatement stmt, AudioInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
stmt.bindLong(1, entity.getStatus());
|
||||||
|
stmt.bindLong(2, entity.getType());
|
||||||
|
|
||||||
|
String keyword = entity.getKeyword();
|
||||||
|
if (keyword != null) {
|
||||||
|
stmt.bindString(3, keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = entity.getImageUrl();
|
||||||
|
if (imageUrl != null) {
|
||||||
|
stmt.bindString(4, imageUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String specialId = entity.getSpecialId();
|
||||||
|
if (specialId != null) {
|
||||||
|
stmt.bindString(5, specialId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerId = entity.getSingerId();
|
||||||
|
if (singerId != null) {
|
||||||
|
stmt.bindString(6, singerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String albumId = entity.getAlbumId();
|
||||||
|
if (albumId != null) {
|
||||||
|
stmt.bindString(7, albumId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String songName = entity.getSongName();
|
||||||
|
if (songName != null) {
|
||||||
|
stmt.bindString(8, songName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerName = entity.getSingerName();
|
||||||
|
if (singerName != null) {
|
||||||
|
stmt.bindString(9, singerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String hash = entity.getHash();
|
||||||
|
if (hash != null) {
|
||||||
|
stmt.bindString(10, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mvHash = entity.getMvHash();
|
||||||
|
if (mvHash != null) {
|
||||||
|
stmt.bindString(11, mvHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileExt = entity.getFileExt();
|
||||||
|
if (fileExt != null) {
|
||||||
|
stmt.bindString(12, fileExt);
|
||||||
|
}
|
||||||
|
stmt.bindLong(13, entity.getFileSize());
|
||||||
|
|
||||||
|
String fileSizeText = entity.getFileSizeText();
|
||||||
|
if (fileSizeText != null) {
|
||||||
|
stmt.bindString(14, fileSizeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String filePath = entity.getFilePath();
|
||||||
|
if (filePath != null) {
|
||||||
|
stmt.bindString(15, filePath);
|
||||||
|
}
|
||||||
|
stmt.bindLong(16, entity.getDuration());
|
||||||
|
|
||||||
|
String durationText = entity.getDurationText();
|
||||||
|
if (durationText != null) {
|
||||||
|
stmt.bindString(17, durationText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String createTime = entity.getCreateTime();
|
||||||
|
if (createTime != null) {
|
||||||
|
stmt.bindString(18, createTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
String category = entity.getCategory();
|
||||||
|
if (category != null) {
|
||||||
|
stmt.bindString(19, category);
|
||||||
|
}
|
||||||
|
|
||||||
|
String childCategory = entity.getChildCategory();
|
||||||
|
if (childCategory != null) {
|
||||||
|
stmt.bindString(20, childCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
String downloadUrl = entity.getDownloadUrl();
|
||||||
|
if (downloadUrl != null) {
|
||||||
|
stmt.bindString(21, downloadUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mvPath = entity.getMvPath();
|
||||||
|
if (mvPath != null) {
|
||||||
|
stmt.bindString(22, mvPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void readKey(Cursor cursor, int offset) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AudioInfo readEntity(Cursor cursor, int offset) {
|
||||||
|
AudioInfo entity = new AudioInfo();
|
||||||
|
readEntity(cursor, entity, offset);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readEntity(Cursor cursor, AudioInfo entity, int offset) {
|
||||||
|
entity.setStatus(cursor.getInt(offset + 0));
|
||||||
|
entity.setType(cursor.getInt(offset + 1));
|
||||||
|
entity.setKeyword(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
|
||||||
|
entity.setImageUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
|
||||||
|
entity.setSpecialId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
|
||||||
|
entity.setSingerId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
|
||||||
|
entity.setAlbumId(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
|
||||||
|
entity.setSongName(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
|
||||||
|
entity.setSingerName(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
|
||||||
|
entity.setHash(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
|
||||||
|
entity.setMvHash(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
|
||||||
|
entity.setFileExt(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
|
||||||
|
entity.setFileSize(cursor.getLong(offset + 12));
|
||||||
|
entity.setFileSizeText(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
|
||||||
|
entity.setFilePath(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
|
||||||
|
entity.setDuration(cursor.getLong(offset + 15));
|
||||||
|
entity.setDurationText(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
|
||||||
|
entity.setCreateTime(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17));
|
||||||
|
entity.setCategory(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
|
||||||
|
entity.setChildCategory(cursor.isNull(offset + 19) ? null : cursor.getString(offset + 19));
|
||||||
|
entity.setDownloadUrl(cursor.isNull(offset + 20) ? null : cursor.getString(offset + 20));
|
||||||
|
entity.setMvPath(cursor.isNull(offset + 21) ? null : cursor.getString(offset + 21));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final Void updateKeyAfterInsert(AudioInfo entity, long rowId) {
|
||||||
|
// Unsupported or missing PK type
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void getKey(AudioInfo entity) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasKey(AudioInfo entity) {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final boolean isEntityUpdateable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
108
app/src/main/java/com/zlm/hp/db/dao/DaoMaster.java
Normal file
108
app/src/main/java/com/zlm/hp/db/dao/DaoMaster.java
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.zlm.hp.db.dao;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDaoMaster;
|
||||||
|
import org.greenrobot.greendao.database.StandardDatabase;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.database.DatabaseOpenHelper;
|
||||||
|
import org.greenrobot.greendao.identityscope.IdentityScopeType;
|
||||||
|
|
||||||
|
|
||||||
|
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||||
|
/**
|
||||||
|
* Master of DAO (schema version 2): knows all DAOs.
|
||||||
|
*/
|
||||||
|
public class DaoMaster extends AbstractDaoMaster {
|
||||||
|
public static final int SCHEMA_VERSION = 2;
|
||||||
|
|
||||||
|
/** Creates underlying database table using DAOs. */
|
||||||
|
public static void createAllTables(Database db, boolean ifNotExists) {
|
||||||
|
DownloadTaskDao.createTable(db, ifNotExists);
|
||||||
|
DownloadThreadInfoDao.createTable(db, ifNotExists);
|
||||||
|
AudioInfoDao.createTable(db, ifNotExists);
|
||||||
|
SingerInfoDao.createTable(db, ifNotExists);
|
||||||
|
VideoInfoDao.createTable(db, ifNotExists);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drops underlying database table using DAOs. */
|
||||||
|
public static void dropAllTables(Database db, boolean ifExists) {
|
||||||
|
DownloadTaskDao.dropTable(db, ifExists);
|
||||||
|
DownloadThreadInfoDao.dropTable(db, ifExists);
|
||||||
|
AudioInfoDao.dropTable(db, ifExists);
|
||||||
|
SingerInfoDao.dropTable(db, ifExists);
|
||||||
|
VideoInfoDao.dropTable(db, ifExists);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WARNING: Drops all table on Upgrade! Use only during development.
|
||||||
|
* Convenience method using a {@link DevOpenHelper}.
|
||||||
|
*/
|
||||||
|
public static DaoSession newDevSession(Context context, String name) {
|
||||||
|
Database db = new DevOpenHelper(context, name).getWritableDb();
|
||||||
|
DaoMaster daoMaster = new DaoMaster(db);
|
||||||
|
return daoMaster.newSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DaoMaster(SQLiteDatabase db) {
|
||||||
|
this(new StandardDatabase(db));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DaoMaster(Database db) {
|
||||||
|
super(db, SCHEMA_VERSION);
|
||||||
|
registerDaoClass(DownloadTaskDao.class);
|
||||||
|
registerDaoClass(DownloadThreadInfoDao.class);
|
||||||
|
registerDaoClass(AudioInfoDao.class);
|
||||||
|
registerDaoClass(SingerInfoDao.class);
|
||||||
|
registerDaoClass(VideoInfoDao.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DaoSession newSession() {
|
||||||
|
return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DaoSession newSession(IdentityScopeType type) {
|
||||||
|
return new DaoSession(db, type, daoConfigMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
|
||||||
|
*/
|
||||||
|
public static abstract class OpenHelper extends DatabaseOpenHelper {
|
||||||
|
public OpenHelper(Context context, String name) {
|
||||||
|
super(context, name, SCHEMA_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenHelper(Context context, String name, CursorFactory factory) {
|
||||||
|
super(context, name, factory, SCHEMA_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Database db) {
|
||||||
|
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
|
||||||
|
createAllTables(db, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** WARNING: Drops all table on Upgrade! Use only during development. */
|
||||||
|
public static class DevOpenHelper extends OpenHelper {
|
||||||
|
public DevOpenHelper(Context context, String name) {
|
||||||
|
super(context, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DevOpenHelper(Context context, String name, CursorFactory factory) {
|
||||||
|
super(context, name, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(Database db, int oldVersion, int newVersion) {
|
||||||
|
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
|
||||||
|
dropAllTables(db, true);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
104
app/src/main/java/com/zlm/hp/db/dao/DaoSession.java
Normal file
104
app/src/main/java/com/zlm/hp/db/dao/DaoSession.java
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.zlm.hp.db.dao;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDao;
|
||||||
|
import org.greenrobot.greendao.AbstractDaoSession;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.identityscope.IdentityScopeType;
|
||||||
|
import org.greenrobot.greendao.internal.DaoConfig;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.down.entity.DownloadThreadInfo;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.SingerInfo;
|
||||||
|
import com.zlm.hp.entity.VideoInfo;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.dao.DownloadTaskDao;
|
||||||
|
import com.zlm.hp.db.dao.DownloadThreadInfoDao;
|
||||||
|
import com.zlm.hp.db.dao.AudioInfoDao;
|
||||||
|
import com.zlm.hp.db.dao.SingerInfoDao;
|
||||||
|
import com.zlm.hp.db.dao.VideoInfoDao;
|
||||||
|
|
||||||
|
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @see org.greenrobot.greendao.AbstractDaoSession
|
||||||
|
*/
|
||||||
|
public class DaoSession extends AbstractDaoSession {
|
||||||
|
|
||||||
|
private final DaoConfig downloadTaskDaoConfig;
|
||||||
|
private final DaoConfig downloadThreadInfoDaoConfig;
|
||||||
|
private final DaoConfig audioInfoDaoConfig;
|
||||||
|
private final DaoConfig singerInfoDaoConfig;
|
||||||
|
private final DaoConfig videoInfoDaoConfig;
|
||||||
|
|
||||||
|
private final DownloadTaskDao downloadTaskDao;
|
||||||
|
private final DownloadThreadInfoDao downloadThreadInfoDao;
|
||||||
|
private final AudioInfoDao audioInfoDao;
|
||||||
|
private final SingerInfoDao singerInfoDao;
|
||||||
|
private final VideoInfoDao videoInfoDao;
|
||||||
|
|
||||||
|
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
|
||||||
|
daoConfigMap) {
|
||||||
|
super(db);
|
||||||
|
|
||||||
|
downloadTaskDaoConfig = daoConfigMap.get(DownloadTaskDao.class).clone();
|
||||||
|
downloadTaskDaoConfig.initIdentityScope(type);
|
||||||
|
|
||||||
|
downloadThreadInfoDaoConfig = daoConfigMap.get(DownloadThreadInfoDao.class).clone();
|
||||||
|
downloadThreadInfoDaoConfig.initIdentityScope(type);
|
||||||
|
|
||||||
|
audioInfoDaoConfig = daoConfigMap.get(AudioInfoDao.class).clone();
|
||||||
|
audioInfoDaoConfig.initIdentityScope(type);
|
||||||
|
|
||||||
|
singerInfoDaoConfig = daoConfigMap.get(SingerInfoDao.class).clone();
|
||||||
|
singerInfoDaoConfig.initIdentityScope(type);
|
||||||
|
|
||||||
|
videoInfoDaoConfig = daoConfigMap.get(VideoInfoDao.class).clone();
|
||||||
|
videoInfoDaoConfig.initIdentityScope(type);
|
||||||
|
|
||||||
|
downloadTaskDao = new DownloadTaskDao(downloadTaskDaoConfig, this);
|
||||||
|
downloadThreadInfoDao = new DownloadThreadInfoDao(downloadThreadInfoDaoConfig, this);
|
||||||
|
audioInfoDao = new AudioInfoDao(audioInfoDaoConfig, this);
|
||||||
|
singerInfoDao = new SingerInfoDao(singerInfoDaoConfig, this);
|
||||||
|
videoInfoDao = new VideoInfoDao(videoInfoDaoConfig, this);
|
||||||
|
|
||||||
|
registerDao(DownloadTask.class, downloadTaskDao);
|
||||||
|
registerDao(DownloadThreadInfo.class, downloadThreadInfoDao);
|
||||||
|
registerDao(AudioInfo.class, audioInfoDao);
|
||||||
|
registerDao(SingerInfo.class, singerInfoDao);
|
||||||
|
registerDao(VideoInfo.class, videoInfoDao);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
downloadTaskDaoConfig.clearIdentityScope();
|
||||||
|
downloadThreadInfoDaoConfig.clearIdentityScope();
|
||||||
|
audioInfoDaoConfig.clearIdentityScope();
|
||||||
|
singerInfoDaoConfig.clearIdentityScope();
|
||||||
|
videoInfoDaoConfig.clearIdentityScope();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadTaskDao getDownloadTaskDao() {
|
||||||
|
return downloadTaskDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadThreadInfoDao getDownloadThreadInfoDao() {
|
||||||
|
return downloadThreadInfoDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AudioInfoDao getAudioInfoDao() {
|
||||||
|
return audioInfoDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingerInfoDao getSingerInfoDao() {
|
||||||
|
return singerInfoDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VideoInfoDao getVideoInfoDao() {
|
||||||
|
return videoInfoDao;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
217
app/src/main/java/com/zlm/hp/db/dao/DownloadTaskDao.java
Normal file
217
app/src/main/java/com/zlm/hp/db/dao/DownloadTaskDao.java
Normal file
|
|
@ -0,0 +1,217 @@
|
||||||
|
package com.zlm.hp.db.dao;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteStatement;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDao;
|
||||||
|
import org.greenrobot.greendao.Property;
|
||||||
|
import org.greenrobot.greendao.internal.DaoConfig;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.database.DatabaseStatement;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
|
||||||
|
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||||
|
/**
|
||||||
|
* DAO for table "DOWNLOAD_TASK".
|
||||||
|
*/
|
||||||
|
public class DownloadTaskDao extends AbstractDao<DownloadTask, Void> {
|
||||||
|
|
||||||
|
public static final String TABLENAME = "DOWNLOAD_TASK";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties of entity DownloadTask.<br/>
|
||||||
|
* Can be used for QueryBuilder and for referencing column names.
|
||||||
|
*/
|
||||||
|
public static class Properties {
|
||||||
|
public final static Property TaskId = new Property(0, String.class, "taskId", false, "TASK_ID");
|
||||||
|
public final static Property TaskName = new Property(1, String.class, "taskName", false, "TASK_NAME");
|
||||||
|
public final static Property TaskExt = new Property(2, String.class, "taskExt", false, "TASK_EXT");
|
||||||
|
public final static Property TaskPath = new Property(3, String.class, "taskPath", false, "TASK_PATH");
|
||||||
|
public final static Property TaskTempPath = new Property(4, String.class, "taskTempPath", false, "TASK_TEMP_PATH");
|
||||||
|
public final static Property RootPath = new Property(5, String.class, "rootPath", false, "ROOT_PATH");
|
||||||
|
public final static Property TaskUrl = new Property(6, String.class, "taskUrl", false, "TASK_URL");
|
||||||
|
public final static Property CreateTime = new Property(7, java.util.Date.class, "createTime", false, "CREATE_TIME");
|
||||||
|
public final static Property Status = new Property(8, int.class, "status", false, "STATUS");
|
||||||
|
public final static Property ThreadNum = new Property(9, int.class, "threadNum", false, "THREAD_NUM");
|
||||||
|
public final static Property TaskFileSize = new Property(10, long.class, "taskFileSize", false, "TASK_FILE_SIZE");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DownloadTaskDao(DaoConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadTaskDao(DaoConfig config, DaoSession daoSession) {
|
||||||
|
super(config, daoSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates the underlying database table. */
|
||||||
|
public static void createTable(Database db, boolean ifNotExists) {
|
||||||
|
String constraint = ifNotExists? "IF NOT EXISTS ": "";
|
||||||
|
db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOAD_TASK\" (" + //
|
||||||
|
"\"TASK_ID\" TEXT," + // 0: taskId
|
||||||
|
"\"TASK_NAME\" TEXT," + // 1: taskName
|
||||||
|
"\"TASK_EXT\" TEXT," + // 2: taskExt
|
||||||
|
"\"TASK_PATH\" TEXT," + // 3: taskPath
|
||||||
|
"\"TASK_TEMP_PATH\" TEXT," + // 4: taskTempPath
|
||||||
|
"\"ROOT_PATH\" TEXT," + // 5: rootPath
|
||||||
|
"\"TASK_URL\" TEXT," + // 6: taskUrl
|
||||||
|
"\"CREATE_TIME\" INTEGER," + // 7: createTime
|
||||||
|
"\"STATUS\" INTEGER NOT NULL ," + // 8: status
|
||||||
|
"\"THREAD_NUM\" INTEGER NOT NULL ," + // 9: threadNum
|
||||||
|
"\"TASK_FILE_SIZE\" INTEGER NOT NULL );"); // 10: taskFileSize
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drops the underlying database table. */
|
||||||
|
public static void dropTable(Database db, boolean ifExists) {
|
||||||
|
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DOWNLOAD_TASK\"";
|
||||||
|
db.execSQL(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(DatabaseStatement stmt, DownloadTask entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String taskId = entity.getTaskId();
|
||||||
|
if (taskId != null) {
|
||||||
|
stmt.bindString(1, taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskName = entity.getTaskName();
|
||||||
|
if (taskName != null) {
|
||||||
|
stmt.bindString(2, taskName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskExt = entity.getTaskExt();
|
||||||
|
if (taskExt != null) {
|
||||||
|
stmt.bindString(3, taskExt);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskPath = entity.getTaskPath();
|
||||||
|
if (taskPath != null) {
|
||||||
|
stmt.bindString(4, taskPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskTempPath = entity.getTaskTempPath();
|
||||||
|
if (taskTempPath != null) {
|
||||||
|
stmt.bindString(5, taskTempPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String rootPath = entity.getRootPath();
|
||||||
|
if (rootPath != null) {
|
||||||
|
stmt.bindString(6, rootPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskUrl = entity.getTaskUrl();
|
||||||
|
if (taskUrl != null) {
|
||||||
|
stmt.bindString(7, taskUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
java.util.Date createTime = entity.getCreateTime();
|
||||||
|
if (createTime != null) {
|
||||||
|
stmt.bindLong(8, createTime.getTime());
|
||||||
|
}
|
||||||
|
stmt.bindLong(9, entity.getStatus());
|
||||||
|
stmt.bindLong(10, entity.getThreadNum());
|
||||||
|
stmt.bindLong(11, entity.getTaskFileSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(SQLiteStatement stmt, DownloadTask entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String taskId = entity.getTaskId();
|
||||||
|
if (taskId != null) {
|
||||||
|
stmt.bindString(1, taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskName = entity.getTaskName();
|
||||||
|
if (taskName != null) {
|
||||||
|
stmt.bindString(2, taskName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskExt = entity.getTaskExt();
|
||||||
|
if (taskExt != null) {
|
||||||
|
stmt.bindString(3, taskExt);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskPath = entity.getTaskPath();
|
||||||
|
if (taskPath != null) {
|
||||||
|
stmt.bindString(4, taskPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskTempPath = entity.getTaskTempPath();
|
||||||
|
if (taskTempPath != null) {
|
||||||
|
stmt.bindString(5, taskTempPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String rootPath = entity.getRootPath();
|
||||||
|
if (rootPath != null) {
|
||||||
|
stmt.bindString(6, rootPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskUrl = entity.getTaskUrl();
|
||||||
|
if (taskUrl != null) {
|
||||||
|
stmt.bindString(7, taskUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
java.util.Date createTime = entity.getCreateTime();
|
||||||
|
if (createTime != null) {
|
||||||
|
stmt.bindLong(8, createTime.getTime());
|
||||||
|
}
|
||||||
|
stmt.bindLong(9, entity.getStatus());
|
||||||
|
stmt.bindLong(10, entity.getThreadNum());
|
||||||
|
stmt.bindLong(11, entity.getTaskFileSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void readKey(Cursor cursor, int offset) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadTask readEntity(Cursor cursor, int offset) {
|
||||||
|
DownloadTask entity = new DownloadTask();
|
||||||
|
readEntity(cursor, entity, offset);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readEntity(Cursor cursor, DownloadTask entity, int offset) {
|
||||||
|
entity.setTaskId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
|
||||||
|
entity.setTaskName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
|
||||||
|
entity.setTaskExt(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
|
||||||
|
entity.setTaskPath(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
|
||||||
|
entity.setTaskTempPath(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
|
||||||
|
entity.setRootPath(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
|
||||||
|
entity.setTaskUrl(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
|
||||||
|
entity.setCreateTime(cursor.isNull(offset + 7) ? null : new java.util.Date(cursor.getLong(offset + 7)));
|
||||||
|
entity.setStatus(cursor.getInt(offset + 8));
|
||||||
|
entity.setThreadNum(cursor.getInt(offset + 9));
|
||||||
|
entity.setTaskFileSize(cursor.getLong(offset + 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final Void updateKeyAfterInsert(DownloadTask entity, long rowId) {
|
||||||
|
// Unsupported or missing PK type
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void getKey(DownloadTask entity) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasKey(DownloadTask entity) {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final boolean isEntityUpdateable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
126
app/src/main/java/com/zlm/hp/db/dao/DownloadThreadInfoDao.java
Normal file
126
app/src/main/java/com/zlm/hp/db/dao/DownloadThreadInfoDao.java
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
package com.zlm.hp.db.dao;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteStatement;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDao;
|
||||||
|
import org.greenrobot.greendao.Property;
|
||||||
|
import org.greenrobot.greendao.internal.DaoConfig;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.database.DatabaseStatement;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadThreadInfo;
|
||||||
|
|
||||||
|
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||||
|
/**
|
||||||
|
* DAO for table "DOWNLOAD_THREAD_INFO".
|
||||||
|
*/
|
||||||
|
public class DownloadThreadInfoDao extends AbstractDao<DownloadThreadInfo, Void> {
|
||||||
|
|
||||||
|
public static final String TABLENAME = "DOWNLOAD_THREAD_INFO";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties of entity DownloadThreadInfo.<br/>
|
||||||
|
* Can be used for QueryBuilder and for referencing column names.
|
||||||
|
*/
|
||||||
|
public static class Properties {
|
||||||
|
public final static Property TaskId = new Property(0, String.class, "taskId", false, "TASK_ID");
|
||||||
|
public final static Property ThreadNum = new Property(1, int.class, "threadNum", false, "THREAD_NUM");
|
||||||
|
public final static Property ThreadId = new Property(2, int.class, "threadId", false, "THREAD_ID");
|
||||||
|
public final static Property DownloadedSize = new Property(3, int.class, "downloadedSize", false, "DOWNLOADED_SIZE");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DownloadThreadInfoDao(DaoConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadThreadInfoDao(DaoConfig config, DaoSession daoSession) {
|
||||||
|
super(config, daoSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates the underlying database table. */
|
||||||
|
public static void createTable(Database db, boolean ifNotExists) {
|
||||||
|
String constraint = ifNotExists? "IF NOT EXISTS ": "";
|
||||||
|
db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOAD_THREAD_INFO\" (" + //
|
||||||
|
"\"TASK_ID\" TEXT," + // 0: taskId
|
||||||
|
"\"THREAD_NUM\" INTEGER NOT NULL ," + // 1: threadNum
|
||||||
|
"\"THREAD_ID\" INTEGER NOT NULL ," + // 2: threadId
|
||||||
|
"\"DOWNLOADED_SIZE\" INTEGER NOT NULL );"); // 3: downloadedSize
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drops the underlying database table. */
|
||||||
|
public static void dropTable(Database db, boolean ifExists) {
|
||||||
|
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DOWNLOAD_THREAD_INFO\"";
|
||||||
|
db.execSQL(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(DatabaseStatement stmt, DownloadThreadInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String taskId = entity.getTaskId();
|
||||||
|
if (taskId != null) {
|
||||||
|
stmt.bindString(1, taskId);
|
||||||
|
}
|
||||||
|
stmt.bindLong(2, entity.getThreadNum());
|
||||||
|
stmt.bindLong(3, entity.getThreadId());
|
||||||
|
stmt.bindLong(4, entity.getDownloadedSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(SQLiteStatement stmt, DownloadThreadInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String taskId = entity.getTaskId();
|
||||||
|
if (taskId != null) {
|
||||||
|
stmt.bindString(1, taskId);
|
||||||
|
}
|
||||||
|
stmt.bindLong(2, entity.getThreadNum());
|
||||||
|
stmt.bindLong(3, entity.getThreadId());
|
||||||
|
stmt.bindLong(4, entity.getDownloadedSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void readKey(Cursor cursor, int offset) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DownloadThreadInfo readEntity(Cursor cursor, int offset) {
|
||||||
|
DownloadThreadInfo entity = new DownloadThreadInfo();
|
||||||
|
readEntity(cursor, entity, offset);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readEntity(Cursor cursor, DownloadThreadInfo entity, int offset) {
|
||||||
|
entity.setTaskId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
|
||||||
|
entity.setThreadNum(cursor.getInt(offset + 1));
|
||||||
|
entity.setThreadId(cursor.getInt(offset + 2));
|
||||||
|
entity.setDownloadedSize(cursor.getInt(offset + 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final Void updateKeyAfterInsert(DownloadThreadInfo entity, long rowId) {
|
||||||
|
// Unsupported or missing PK type
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void getKey(DownloadThreadInfo entity) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasKey(DownloadThreadInfo entity) {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final boolean isEntityUpdateable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
150
app/src/main/java/com/zlm/hp/db/dao/SingerInfoDao.java
Normal file
150
app/src/main/java/com/zlm/hp/db/dao/SingerInfoDao.java
Normal file
|
|
@ -0,0 +1,150 @@
|
||||||
|
package com.zlm.hp.db.dao;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteStatement;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDao;
|
||||||
|
import org.greenrobot.greendao.Property;
|
||||||
|
import org.greenrobot.greendao.internal.DaoConfig;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.database.DatabaseStatement;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.SingerInfo;
|
||||||
|
|
||||||
|
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||||
|
/**
|
||||||
|
* DAO for table "SINGER_INFO".
|
||||||
|
*/
|
||||||
|
public class SingerInfoDao extends AbstractDao<SingerInfo, Void> {
|
||||||
|
|
||||||
|
public static final String TABLENAME = "SINGER_INFO";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties of entity SingerInfo.<br/>
|
||||||
|
* Can be used for QueryBuilder and for referencing column names.
|
||||||
|
*/
|
||||||
|
public static class Properties {
|
||||||
|
public final static Property SingerId = new Property(0, String.class, "singerId", false, "SINGER_ID");
|
||||||
|
public final static Property SingerName = new Property(1, String.class, "singerName", false, "SINGER_NAME");
|
||||||
|
public final static Property ImageUrl = new Property(2, String.class, "imageUrl", false, "IMAGE_URL");
|
||||||
|
public final static Property CreateTime = new Property(3, String.class, "createTime", false, "CREATE_TIME");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SingerInfoDao(DaoConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingerInfoDao(DaoConfig config, DaoSession daoSession) {
|
||||||
|
super(config, daoSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates the underlying database table. */
|
||||||
|
public static void createTable(Database db, boolean ifNotExists) {
|
||||||
|
String constraint = ifNotExists? "IF NOT EXISTS ": "";
|
||||||
|
db.execSQL("CREATE TABLE " + constraint + "\"SINGER_INFO\" (" + //
|
||||||
|
"\"SINGER_ID\" TEXT," + // 0: singerId
|
||||||
|
"\"SINGER_NAME\" TEXT," + // 1: singerName
|
||||||
|
"\"IMAGE_URL\" TEXT," + // 2: imageUrl
|
||||||
|
"\"CREATE_TIME\" TEXT);"); // 3: createTime
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drops the underlying database table. */
|
||||||
|
public static void dropTable(Database db, boolean ifExists) {
|
||||||
|
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SINGER_INFO\"";
|
||||||
|
db.execSQL(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(DatabaseStatement stmt, SingerInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String singerId = entity.getSingerId();
|
||||||
|
if (singerId != null) {
|
||||||
|
stmt.bindString(1, singerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerName = entity.getSingerName();
|
||||||
|
if (singerName != null) {
|
||||||
|
stmt.bindString(2, singerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = entity.getImageUrl();
|
||||||
|
if (imageUrl != null) {
|
||||||
|
stmt.bindString(3, imageUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String createTime = entity.getCreateTime();
|
||||||
|
if (createTime != null) {
|
||||||
|
stmt.bindString(4, createTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(SQLiteStatement stmt, SingerInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String singerId = entity.getSingerId();
|
||||||
|
if (singerId != null) {
|
||||||
|
stmt.bindString(1, singerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerName = entity.getSingerName();
|
||||||
|
if (singerName != null) {
|
||||||
|
stmt.bindString(2, singerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = entity.getImageUrl();
|
||||||
|
if (imageUrl != null) {
|
||||||
|
stmt.bindString(3, imageUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String createTime = entity.getCreateTime();
|
||||||
|
if (createTime != null) {
|
||||||
|
stmt.bindString(4, createTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void readKey(Cursor cursor, int offset) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingerInfo readEntity(Cursor cursor, int offset) {
|
||||||
|
SingerInfo entity = new SingerInfo();
|
||||||
|
readEntity(cursor, entity, offset);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readEntity(Cursor cursor, SingerInfo entity, int offset) {
|
||||||
|
entity.setSingerId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
|
||||||
|
entity.setSingerName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
|
||||||
|
entity.setImageUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
|
||||||
|
entity.setCreateTime(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final Void updateKeyAfterInsert(SingerInfo entity, long rowId) {
|
||||||
|
// Unsupported or missing PK type
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void getKey(SingerInfo entity) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasKey(SingerInfo entity) {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final boolean isEntityUpdateable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
230
app/src/main/java/com/zlm/hp/db/dao/VideoInfoDao.java
Normal file
230
app/src/main/java/com/zlm/hp/db/dao/VideoInfoDao.java
Normal file
|
|
@ -0,0 +1,230 @@
|
||||||
|
package com.zlm.hp.db.dao;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteStatement;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.AbstractDao;
|
||||||
|
import org.greenrobot.greendao.Property;
|
||||||
|
import org.greenrobot.greendao.internal.DaoConfig;
|
||||||
|
import org.greenrobot.greendao.database.Database;
|
||||||
|
import org.greenrobot.greendao.database.DatabaseStatement;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.VideoInfo;
|
||||||
|
|
||||||
|
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
|
||||||
|
/**
|
||||||
|
* DAO for table "VIDEO_INFO".
|
||||||
|
*/
|
||||||
|
public class VideoInfoDao extends AbstractDao<VideoInfo, Void> {
|
||||||
|
|
||||||
|
public static final String TABLENAME = "VIDEO_INFO";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Properties of entity VideoInfo.<br/>
|
||||||
|
* Can be used for QueryBuilder and for referencing column names.
|
||||||
|
*/
|
||||||
|
public static class Properties {
|
||||||
|
public final static Property Hash = new Property(0, String.class, "hash", false, "HASH");
|
||||||
|
public final static Property FileExt = new Property(1, String.class, "fileExt", false, "FILE_EXT");
|
||||||
|
public final static Property FileSize = new Property(2, long.class, "fileSize", false, "FILE_SIZE");
|
||||||
|
public final static Property FileSizeText = new Property(3, String.class, "fileSizeText", false, "FILE_SIZE_TEXT");
|
||||||
|
public final static Property FilePath = new Property(4, String.class, "filePath", false, "FILE_PATH");
|
||||||
|
public final static Property Duration = new Property(5, long.class, "duration", false, "DURATION");
|
||||||
|
public final static Property DurationText = new Property(6, String.class, "durationText", false, "DURATION_TEXT");
|
||||||
|
public final static Property MvName = new Property(7, String.class, "mvName", false, "MV_NAME");
|
||||||
|
public final static Property SingerName = new Property(8, String.class, "singerName", false, "SINGER_NAME");
|
||||||
|
public final static Property ImageUrl = new Property(9, String.class, "imageUrl", false, "IMAGE_URL");
|
||||||
|
public final static Property DownloadUrl = new Property(10, String.class, "downloadUrl", false, "DOWNLOAD_URL");
|
||||||
|
public final static Property Status = new Property(11, int.class, "status", false, "STATUS");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public VideoInfoDao(DaoConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VideoInfoDao(DaoConfig config, DaoSession daoSession) {
|
||||||
|
super(config, daoSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates the underlying database table. */
|
||||||
|
public static void createTable(Database db, boolean ifNotExists) {
|
||||||
|
String constraint = ifNotExists? "IF NOT EXISTS ": "";
|
||||||
|
db.execSQL("CREATE TABLE " + constraint + "\"VIDEO_INFO\" (" + //
|
||||||
|
"\"HASH\" TEXT," + // 0: hash
|
||||||
|
"\"FILE_EXT\" TEXT," + // 1: fileExt
|
||||||
|
"\"FILE_SIZE\" INTEGER NOT NULL ," + // 2: fileSize
|
||||||
|
"\"FILE_SIZE_TEXT\" TEXT," + // 3: fileSizeText
|
||||||
|
"\"FILE_PATH\" TEXT," + // 4: filePath
|
||||||
|
"\"DURATION\" INTEGER NOT NULL ," + // 5: duration
|
||||||
|
"\"DURATION_TEXT\" TEXT," + // 6: durationText
|
||||||
|
"\"MV_NAME\" TEXT," + // 7: mvName
|
||||||
|
"\"SINGER_NAME\" TEXT," + // 8: singerName
|
||||||
|
"\"IMAGE_URL\" TEXT," + // 9: imageUrl
|
||||||
|
"\"DOWNLOAD_URL\" TEXT," + // 10: downloadUrl
|
||||||
|
"\"STATUS\" INTEGER NOT NULL );"); // 11: status
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drops the underlying database table. */
|
||||||
|
public static void dropTable(Database db, boolean ifExists) {
|
||||||
|
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"VIDEO_INFO\"";
|
||||||
|
db.execSQL(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(DatabaseStatement stmt, VideoInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String hash = entity.getHash();
|
||||||
|
if (hash != null) {
|
||||||
|
stmt.bindString(1, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileExt = entity.getFileExt();
|
||||||
|
if (fileExt != null) {
|
||||||
|
stmt.bindString(2, fileExt);
|
||||||
|
}
|
||||||
|
stmt.bindLong(3, entity.getFileSize());
|
||||||
|
|
||||||
|
String fileSizeText = entity.getFileSizeText();
|
||||||
|
if (fileSizeText != null) {
|
||||||
|
stmt.bindString(4, fileSizeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String filePath = entity.getFilePath();
|
||||||
|
if (filePath != null) {
|
||||||
|
stmt.bindString(5, filePath);
|
||||||
|
}
|
||||||
|
stmt.bindLong(6, entity.getDuration());
|
||||||
|
|
||||||
|
String durationText = entity.getDurationText();
|
||||||
|
if (durationText != null) {
|
||||||
|
stmt.bindString(7, durationText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mvName = entity.getMvName();
|
||||||
|
if (mvName != null) {
|
||||||
|
stmt.bindString(8, mvName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerName = entity.getSingerName();
|
||||||
|
if (singerName != null) {
|
||||||
|
stmt.bindString(9, singerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = entity.getImageUrl();
|
||||||
|
if (imageUrl != null) {
|
||||||
|
stmt.bindString(10, imageUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String downloadUrl = entity.getDownloadUrl();
|
||||||
|
if (downloadUrl != null) {
|
||||||
|
stmt.bindString(11, downloadUrl);
|
||||||
|
}
|
||||||
|
stmt.bindLong(12, entity.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void bindValues(SQLiteStatement stmt, VideoInfo entity) {
|
||||||
|
stmt.clearBindings();
|
||||||
|
|
||||||
|
String hash = entity.getHash();
|
||||||
|
if (hash != null) {
|
||||||
|
stmt.bindString(1, hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileExt = entity.getFileExt();
|
||||||
|
if (fileExt != null) {
|
||||||
|
stmt.bindString(2, fileExt);
|
||||||
|
}
|
||||||
|
stmt.bindLong(3, entity.getFileSize());
|
||||||
|
|
||||||
|
String fileSizeText = entity.getFileSizeText();
|
||||||
|
if (fileSizeText != null) {
|
||||||
|
stmt.bindString(4, fileSizeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String filePath = entity.getFilePath();
|
||||||
|
if (filePath != null) {
|
||||||
|
stmt.bindString(5, filePath);
|
||||||
|
}
|
||||||
|
stmt.bindLong(6, entity.getDuration());
|
||||||
|
|
||||||
|
String durationText = entity.getDurationText();
|
||||||
|
if (durationText != null) {
|
||||||
|
stmt.bindString(7, durationText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String mvName = entity.getMvName();
|
||||||
|
if (mvName != null) {
|
||||||
|
stmt.bindString(8, mvName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String singerName = entity.getSingerName();
|
||||||
|
if (singerName != null) {
|
||||||
|
stmt.bindString(9, singerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String imageUrl = entity.getImageUrl();
|
||||||
|
if (imageUrl != null) {
|
||||||
|
stmt.bindString(10, imageUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
String downloadUrl = entity.getDownloadUrl();
|
||||||
|
if (downloadUrl != null) {
|
||||||
|
stmt.bindString(11, downloadUrl);
|
||||||
|
}
|
||||||
|
stmt.bindLong(12, entity.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void readKey(Cursor cursor, int offset) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VideoInfo readEntity(Cursor cursor, int offset) {
|
||||||
|
VideoInfo entity = new VideoInfo();
|
||||||
|
readEntity(cursor, entity, offset);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readEntity(Cursor cursor, VideoInfo entity, int offset) {
|
||||||
|
entity.setHash(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
|
||||||
|
entity.setFileExt(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
|
||||||
|
entity.setFileSize(cursor.getLong(offset + 2));
|
||||||
|
entity.setFileSizeText(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
|
||||||
|
entity.setFilePath(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
|
||||||
|
entity.setDuration(cursor.getLong(offset + 5));
|
||||||
|
entity.setDurationText(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
|
||||||
|
entity.setMvName(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
|
||||||
|
entity.setSingerName(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
|
||||||
|
entity.setImageUrl(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
|
||||||
|
entity.setDownloadUrl(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
|
||||||
|
entity.setStatus(cursor.getInt(offset + 11));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final Void updateKeyAfterInsert(VideoInfo entity, long rowId) {
|
||||||
|
// Unsupported or missing PK type
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void getKey(VideoInfo entity) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasKey(VideoInfo entity) {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final boolean isEntityUpdateable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
805
app/src/main/java/com/zlm/hp/db/util/AudioInfoDB.java
Normal file
805
app/src/main/java/com/zlm/hp/db/util/AudioInfoDB.java
Normal file
|
|
@ -0,0 +1,805 @@
|
||||||
|
package com.zlm.hp.db.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.DBHelper;
|
||||||
|
import com.zlm.hp.db.dao.AudioInfoDao;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.manager.DownloadAudioManager;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.util.DateUtil;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.query.WhereCondition;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频数据库表处理
|
||||||
|
* Created by zhangliangming on 2018-08-18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AudioInfoDB {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加歌曲数据
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param audioInfo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean addAudioInfo(Context context, AudioInfo audioInfo, boolean notifyData) {
|
||||||
|
try {
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().insert(audioInfo);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendReceiver(context, AudioBroadcastReceiver.ACTION_CODE_UPDATE_LOCAL);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量添加歌曲数据
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param audioInfos
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean addAudioInfos(Context context, List<AudioInfo> audioInfos) {
|
||||||
|
try {
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().insertInTx(audioInfos);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 批量添加歌曲数据
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param audioInfos
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean addAudioInfos2(Context context, List<AudioInfo> audioInfos) {
|
||||||
|
// try {
|
||||||
|
// DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().insertInTx(audioInfos);
|
||||||
|
// return true;
|
||||||
|
//} catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
//return false;
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < audioInfos.size(); i++) {
|
||||||
|
AudioInfo temp = audioInfos.get(i);
|
||||||
|
if(isAudioExists(context,temp.getSingerName(),temp.getSongName())) //如果MV已经存在,则直接将歌曲写入
|
||||||
|
{
|
||||||
|
updateAudio(context,temp);
|
||||||
|
}
|
||||||
|
else //如果MV不存在,则创建一条数据
|
||||||
|
{
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().insert(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 针对已有MV信息,但是没有歌曲信息的
|
||||||
|
*/
|
||||||
|
public static boolean updateAudio(Context context, AudioInfo info) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "UPDATE ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " SET " + AudioInfoDao.Properties.Duration.columnName + " ="+info.getDuration()+","+
|
||||||
|
AudioInfoDao.Properties.FileSize.columnName+"="+info.getFileSize()+","+
|
||||||
|
AudioInfoDao.Properties.Type.columnName+"="+info.getType()+","+
|
||||||
|
AudioInfoDao.Properties.Status.columnName+"="+info.getStatus()+","+
|
||||||
|
AudioInfoDao.Properties.CreateTime.columnName+"=?,"+
|
||||||
|
AudioInfoDao.Properties.FileExt.columnName+"=?,"+
|
||||||
|
AudioInfoDao.Properties.FilePath.columnName+"=?,"+
|
||||||
|
AudioInfoDao.Properties.Hash.columnName+"=?,"+
|
||||||
|
AudioInfoDao.Properties.DurationText.columnName+"=?,"+
|
||||||
|
AudioInfoDao.Properties.FileSizeText.columnName+"=?,"
|
||||||
|
;
|
||||||
|
sql += " where " + AudioInfoDao.Properties.SingerName.columnName + "=? and " + AudioInfoDao.Properties.SongName.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {info.getCreateTime(),info.getFileExt(), info.getFilePath(), info.getHash(), info.getDurationText(),info.getFileSizeText()};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 批量添加MV数据
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param videoInfos
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean addVideoInfos(Context context, List<AudioInfo> videoInfos) {
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < videoInfos.size(); i++) {
|
||||||
|
AudioInfo temp = videoInfos.get(i);
|
||||||
|
if(isAudioExists(context,temp.getSingerName(),temp.getSongName())) //如果歌曲已经存在,则直接将MV写入
|
||||||
|
{
|
||||||
|
updateVideo(context,temp);
|
||||||
|
}
|
||||||
|
else //如果歌曲不存在,则创建一条数据
|
||||||
|
{
|
||||||
|
InsertVideo(context,temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 更新MV信息
|
||||||
|
*/
|
||||||
|
public static boolean updateVideo(Context context, AudioInfo info) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "UPDATE ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " SET " + AudioInfoDao.Properties.MvPath.columnName + " =?,"+
|
||||||
|
AudioInfoDao.Properties.MvHash.columnName+"=?";
|
||||||
|
sql += " where " + AudioInfoDao.Properties.SingerName.columnName + "=? and " + AudioInfoDao.Properties.SongName.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {info.getMvPath(),info.getMvHash(), info.getSingerName(), info.getSongName()};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 插入MV信息
|
||||||
|
*/
|
||||||
|
public static boolean InsertVideo(Context context, AudioInfo info) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "insert into ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " (" + AudioInfoDao.Properties.SingerName.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.SongName.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.CreateTime.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.Status.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.Type.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.FileSize.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.Duration.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.Hash.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.MvHash.columnName + ",";
|
||||||
|
sql += AudioInfoDao.Properties.MvPath.columnName + ")";
|
||||||
|
sql += " values (?,?,?,"+info.getStatus()+","+info.getType()+","+info.getFileSize()+",9000,?,?,?)";
|
||||||
|
String args[] = {info.getSingerName(), info.getSongName(),info.getCreateTime(),info.getHash(),info.getMvHash(),info.getMvPath()};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取本地歌曲个数
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getLocalAudioCount(Context context) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
int count = 0;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_LOCAL + "", AudioInfo.TYPE_NET + "", AudioInfo.STATUS_FINISH + ""};
|
||||||
|
String sql = "select count(*) from " + AudioInfoDao.TABLENAME + " WHERE " + AudioInfoDao.Properties.Type.columnName + "=? or ( " + AudioInfoDao.Properties.Type.columnName + "=? and " + AudioInfoDao.Properties.Status.columnName +
|
||||||
|
"=? )";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
count = cursor.getInt(0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 判断歌曲是否存在
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean DbExistAudio(Context context,String Hash) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
int count = 0;
|
||||||
|
try {
|
||||||
|
String args[] = {Hash,Hash};
|
||||||
|
String sql = "select count(*) from " + AudioInfoDao.TABLENAME + " WHERE " + AudioInfoDao.Properties.Hash.columnName + "=? or "+AudioInfoDao.Properties.MvHash.columnName+"=?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
count = cursor.getInt(0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count!=0;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取本地音频列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<AudioInfo> getLocalAudios(Context context) {
|
||||||
|
try {
|
||||||
|
List<AudioInfo> audioInfos = DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().queryBuilder().where(new WhereCondition.StringCondition(AudioInfoDao.Properties.Type.columnName + "=? or ( " + AudioInfoDao.Properties.Type.columnName + "=? and " + AudioInfoDao.Properties.Status.columnName +
|
||||||
|
"=? )", AudioInfo.TYPE_LOCAL + "", AudioInfo.TYPE_NET + "", AudioInfo.STATUS_FINISH + "")).orderAsc(AudioInfoDao.Properties.Category, AudioInfoDao.Properties.ChildCategory).list();
|
||||||
|
return audioInfos;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new ArrayList<AudioInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加喜欢歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
public static boolean addLikeAudio(Context context, AudioInfo audioInfo, boolean notifyData) {
|
||||||
|
int type = audioInfo.getType();
|
||||||
|
try {
|
||||||
|
if (type == AudioInfo.TYPE_LOCAL) {
|
||||||
|
audioInfo.setType(AudioInfo.TYPE_LIKE_LOCAL);
|
||||||
|
} else {
|
||||||
|
audioInfo.setType(AudioInfo.TYPE_LIKE_NET);
|
||||||
|
}
|
||||||
|
audioInfo.setCreateTime(DateUtil.parseDateToString(new Date()));
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().insert(audioInfo);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendLikeReceiver(context, audioInfo.getHash());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
audioInfo.setType(type);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取喜欢歌曲个数
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getLikeAudioCount(Context context) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
int count = 0;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_LIKE_LOCAL + "", AudioInfo.TYPE_LIKE_NET + ""};
|
||||||
|
String sql = "select count(*) from " + AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName + "=?";
|
||||||
|
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
count = cursor.getInt(0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
public static boolean deleteAudio(Context context, String hash, boolean notifyData) {
|
||||||
|
|
||||||
|
//删除喜欢
|
||||||
|
//删除下载
|
||||||
|
//删除最近
|
||||||
|
//删除下载任务
|
||||||
|
|
||||||
|
deleteLikeAudio(context, hash, notifyData);
|
||||||
|
DownloadTaskDB.delete(context, hash, DownloadAudioManager.mThreadNum);
|
||||||
|
deleteRecentAudio(context, hash, notifyData);
|
||||||
|
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Hash.columnName + "=?";
|
||||||
|
String args[] = {hash};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendReceiver(context, AudioBroadcastReceiver.ACTION_CODE_UPDATE_LOCAL);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除喜欢歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
public static boolean deleteLikeAudio(Context context, String hash, boolean notifyData) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where (" + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName + "=? ) and " + AudioInfoDao.Properties.Hash.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {AudioInfo.TYPE_LIKE_LOCAL + "", AudioInfo.TYPE_LIKE_NET + "", hash};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendLikeReceiver(context, hash);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前歌曲是否是喜欢歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isLikeAudioExists(Context context, String hash) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_LIKE_LOCAL + "", AudioInfo.TYPE_LIKE_NET + "", hash};
|
||||||
|
String sql = "select * from " + AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where (" + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName + "=? ) and " + AudioInfoDao.Properties.Hash.columnName + "=?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 判断当前歌曲是否存在
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param singer
|
||||||
|
* @param songName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isAudioExists(Context context, String singer,String songName) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {singer,songName};
|
||||||
|
String sql = "select * from " + AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where (" + AudioInfoDao.Properties.SingerName.columnName + "=? and " + AudioInfoDao.Properties.SongName.columnName + "=? )";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取喜欢音频列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<AudioInfo> getLikeAudios(Context context) {
|
||||||
|
try {
|
||||||
|
List<AudioInfo> audioInfos = DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().queryBuilder().where(new WhereCondition.StringCondition("( " + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName +
|
||||||
|
"=? )", AudioInfo.TYPE_LIKE_LOCAL + "", AudioInfo.TYPE_LIKE_NET + "")).orderDesc(AudioInfoDao.Properties.CreateTime).list();
|
||||||
|
if (audioInfos != null && audioInfos.size() > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < audioInfos.size(); i++) {
|
||||||
|
AudioInfo temp = audioInfos.get(i);
|
||||||
|
int type = temp.getType();
|
||||||
|
//添加时修改了类型,从数据库中获取后,需要修改为原来的状态
|
||||||
|
if (type == AudioInfo.TYPE_LIKE_LOCAL) {
|
||||||
|
temp.setType(AudioInfo.TYPE_LOCAL);
|
||||||
|
} else {
|
||||||
|
temp.setType(AudioInfo.TYPE_NET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return audioInfos;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new ArrayList<AudioInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加最近歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
public static boolean addRecentAudio(Context context, AudioInfo audioInfo, boolean notifyData) {
|
||||||
|
int type = audioInfo.getType();
|
||||||
|
try {
|
||||||
|
if (type == AudioInfo.TYPE_LOCAL) {
|
||||||
|
audioInfo.setType(AudioInfo.TYPE_RECENT_LOCAL);
|
||||||
|
} else {
|
||||||
|
audioInfo.setType(AudioInfo.TYPE_RECENT_NET);
|
||||||
|
}
|
||||||
|
audioInfo.setCreateTime(DateUtil.parseDateToString(new Date()));
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().insert(audioInfo);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendReceiver(context, AudioBroadcastReceiver.ACTION_CODE_UPDATE_RECENT);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
audioInfo.setType(type);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最近歌曲个数
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getRecentAudioCount(Context context) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
int count = 0;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_RECENT_LOCAL + "", AudioInfo.TYPE_RECENT_NET + ""};
|
||||||
|
String sql = "select count(*) from " + AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName + "=?";
|
||||||
|
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
count = cursor.getInt(0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除最近歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
public static boolean deleteRecentAudio(Context context, String hash, boolean notifyData) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where (" + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName + "=? ) and " + AudioInfoDao.Properties.Hash.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {AudioInfo.TYPE_RECENT_LOCAL + "", AudioInfo.TYPE_RECENT_NET + "", hash};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendReceiver(context, AudioBroadcastReceiver.ACTION_CODE_UPDATE_RECENT);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前歌曲是否是最近歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isRecentAudioExists(Context context, String hash) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_RECENT_LOCAL + "", AudioInfo.TYPE_RECENT_NET + "", hash};
|
||||||
|
String sql = "select * from " + AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where (" + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName + "=? ) and " + AudioInfoDao.Properties.Hash.columnName + "=?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最近音频列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<AudioInfo> getRecentAudios(Context context) {
|
||||||
|
try {
|
||||||
|
List<AudioInfo> audioInfos = DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().queryBuilder().where(new WhereCondition.StringCondition("( " + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName +
|
||||||
|
"=? )", AudioInfo.TYPE_RECENT_LOCAL + "", AudioInfo.TYPE_RECENT_NET + "")).orderDesc(AudioInfoDao.Properties.CreateTime).list();
|
||||||
|
if (audioInfos != null && audioInfos.size() > 0) {
|
||||||
|
|
||||||
|
for (int i = 0; i < audioInfos.size(); i++) {
|
||||||
|
AudioInfo temp = audioInfos.get(i);
|
||||||
|
int type = temp.getType();
|
||||||
|
//添加时修改了类型,从数据库中获取后,需要修改为原来的状态
|
||||||
|
if (type == AudioInfo.TYPE_RECENT_LOCAL) {
|
||||||
|
temp.setType(AudioInfo.TYPE_LOCAL);
|
||||||
|
} else {
|
||||||
|
temp.setType(AudioInfo.TYPE_NET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return audioInfos;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new ArrayList<AudioInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新最近歌曲时间
|
||||||
|
*/
|
||||||
|
public static boolean updateRecentAudio(Context context, String hash, String createTime) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "UPDATE ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " SET " + AudioInfoDao.Properties.CreateTime.columnName + " =?";
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Hash.columnName + "=? and (" + AudioInfoDao.Properties.Type.columnName + "=? or " + AudioInfoDao.Properties.Type.columnName + "=?)";
|
||||||
|
|
||||||
|
String args[] = {createTime, hash, AudioInfo.TYPE_RECENT_LOCAL + "", AudioInfo.TYPE_RECENT_NET + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下载歌曲个数
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getDownloadAudioCount(Context context) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
int count = 0;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_NET + "", AudioInfo.STATUS_DOWNLOADING + "", AudioInfo.STATUS_FINISH + ""};
|
||||||
|
String sql = "select count(*) from " + AudioInfoDao.TABLENAME + " WHERE " + AudioInfoDao.Properties.Type.columnName + "=? and (" + AudioInfoDao.Properties.Status.columnName +
|
||||||
|
"=? or " + AudioInfoDao.Properties.Status.columnName + " =?)";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
count = cursor.getInt(0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加下载歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
public static boolean addDownloadAudio(Context context, AudioInfo audioInfo, boolean notifyData) {
|
||||||
|
try {
|
||||||
|
audioInfo.setStatus(AudioInfo.STATUS_DOWNLOADING);
|
||||||
|
audioInfo.setCreateTime(DateUtil.parseDateToString(new Date()));
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().insert(audioInfo);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendReceiver(context, AudioBroadcastReceiver.ACTION_CODE_UPDATE_DOWNLOAD);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新下载歌曲时间
|
||||||
|
*/
|
||||||
|
public static boolean addDownloadedAudio(Context context, String hash, boolean notifyData) {
|
||||||
|
boolean flag = updateDownloadAudio(context, hash, DateUtil.parseDateToString(new Date()), AudioInfo.STATUS_FINISH);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendReceiver(context, AudioBroadcastReceiver.ACTION_CODE_UPDATE_LOCAL);
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新下载歌曲时间
|
||||||
|
*/
|
||||||
|
public static boolean updateDownloadAudio(Context context, String hash, String createTime, int status) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "UPDATE ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " SET " + AudioInfoDao.Properties.CreateTime.columnName + " =?," + AudioInfoDao.Properties.Status.columnName + " =?";
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Hash.columnName + "=? and " + AudioInfoDao.Properties.Type.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {createTime, status + "", hash, AudioInfo.TYPE_NET + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除下载歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
|
public static boolean deleteDownloadAudio(Context context, String hash, boolean notifyData) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Type.columnName + "=? and " + AudioInfoDao.Properties.Hash.columnName + "=? and (" + AudioInfoDao.Properties.Status.columnName + " =? or " + AudioInfoDao.Properties.Status.columnName + " =?)";
|
||||||
|
|
||||||
|
String args[] = {AudioInfo.TYPE_NET + "", hash, AudioInfo.STATUS_DOWNLOADING + "", AudioInfo.STATUS_FINISH + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
if (notifyData) {
|
||||||
|
AudioBroadcastReceiver.sendReceiver(context, AudioBroadcastReceiver.ACTION_CODE_UPDATE_DOWNLOAD);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前歌曲是否是下载歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isDownloadAudioExists(Context context, String hash) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_NET + "", hash, AudioInfo.STATUS_DOWNLOADING + "", AudioInfo.STATUS_FINISH + ""};
|
||||||
|
String sql = "select * from " + AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Type.columnName + "=? and " + AudioInfoDao.Properties.Hash.columnName + "=? and (" + AudioInfoDao.Properties.Status.columnName + " =? or " + AudioInfoDao.Properties.Status.columnName + " =?)";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前歌曲是否是下载完成歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isDownloadedAudioExists(Context context, String hash) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {AudioInfo.TYPE_NET + "", hash, AudioInfo.STATUS_FINISH + ""};
|
||||||
|
String sql = "select * from " + AudioInfoDao.TABLENAME;
|
||||||
|
sql += " where " + AudioInfoDao.Properties.Type.columnName + "=? and " + AudioInfoDao.Properties.Hash.columnName + "=? and " + AudioInfoDao.Properties.Status.columnName + " =?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下载中音频列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<AudioInfo> getDownloadingAudios(Context context) {
|
||||||
|
try {
|
||||||
|
List<AudioInfo> audioInfos = DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().queryBuilder().where(new WhereCondition.StringCondition(AudioInfoDao.Properties.Type.columnName + "=? and " + AudioInfoDao.Properties.Status.columnName +
|
||||||
|
"=?", AudioInfo.TYPE_NET + "", AudioInfo.STATUS_DOWNLOADING + "")).orderDesc(AudioInfoDao.Properties.CreateTime).list();
|
||||||
|
return audioInfos;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new ArrayList<AudioInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下载完成音频列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<AudioInfo> getDownloadedAudios(Context context) {
|
||||||
|
try {
|
||||||
|
List<AudioInfo> audioInfos = DBHelper.getInstance(context).getDaoSession().getAudioInfoDao().queryBuilder().where(new WhereCondition.StringCondition(AudioInfoDao.Properties.Type.columnName + "=? and " + AudioInfoDao.Properties.Status.columnName +
|
||||||
|
"=?", AudioInfo.TYPE_NET + "", AudioInfo.STATUS_FINISH + "")).orderDesc(AudioInfoDao.Properties.CreateTime).list();
|
||||||
|
return audioInfos;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return new ArrayList<AudioInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
131
app/src/main/java/com/zlm/hp/db/util/DownloadTaskDB.java
Normal file
131
app/src/main/java/com/zlm/hp/db/util/DownloadTaskDB.java
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
package com.zlm.hp.db.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.SQLException;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.db.DBHelper;
|
||||||
|
import com.zlm.hp.db.dao.DownloadTaskDao;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载任务db管理
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-10-07 19:42
|
||||||
|
**/
|
||||||
|
public class DownloadTaskDB {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加下载任务
|
||||||
|
*
|
||||||
|
* @param downloadTask
|
||||||
|
*/
|
||||||
|
public static boolean add(Context context, DownloadTask downloadTask) {
|
||||||
|
try {
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getDownloadTaskDao().insert(downloadTask);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务是否存在
|
||||||
|
*
|
||||||
|
* @param tid
|
||||||
|
* @param threadNum
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isExists(Context context, String tid, int threadNum) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {tid, threadNum + ""};
|
||||||
|
String sql = "select * from " + DownloadTaskDao.TABLENAME + " WHERE " + DownloadTaskDao.Properties.TaskId.columnName + "=? and " + DownloadTaskDao.Properties.ThreadNum.columnName + "=?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新下载任务
|
||||||
|
*/
|
||||||
|
public static boolean update(Context context, String tid, int threadNum,int status) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "UPDATE ";
|
||||||
|
sql += DownloadTaskDao.TABLENAME;
|
||||||
|
sql += " SET " + DownloadTaskDao.Properties.Status.columnName + " =?";
|
||||||
|
sql += " where " + DownloadTaskDao.Properties.TaskId.columnName + "=? and " + DownloadTaskDao.Properties.ThreadNum.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {status + "",tid, threadNum + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除hash对应的数据
|
||||||
|
*/
|
||||||
|
public static void delete(Context context,String taskid,int threadNum) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
if(AudioInfoDB.isDownloadAudioExists(context,taskid)){
|
||||||
|
//删除下载歌曲
|
||||||
|
AudioInfoDB.deleteDownloadAudio(context,taskid,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isExists(context,taskid,threadNum)){
|
||||||
|
//删除任务
|
||||||
|
deleteTask(context,taskid, threadNum);
|
||||||
|
|
||||||
|
//删除任务线程
|
||||||
|
DownloadThreadInfoDB.delete(context,taskid, threadNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除本地缓存文件
|
||||||
|
String tempFilePath = ResourceUtil.getFilePath(context, ResourceConstants.PATH_AUDIO_TEMP, taskid + ".temp");
|
||||||
|
File tempFile = new File(tempFilePath);
|
||||||
|
if (tempFile.exists()) {
|
||||||
|
tempFile.delete();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除下载任务
|
||||||
|
*/
|
||||||
|
private static boolean deleteTask(Context context, String tid,int threadNum) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += DownloadTaskDao.TABLENAME;
|
||||||
|
sql += " where " + DownloadTaskDao.Properties.TaskId.columnName + "=? and " + DownloadTaskDao.Properties.ThreadNum.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {tid, threadNum + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
169
app/src/main/java/com/zlm/hp/db/util/DownloadThreadInfoDB.java
Normal file
169
app/src/main/java/com/zlm/hp/db/util/DownloadThreadInfoDB.java
Normal file
|
|
@ -0,0 +1,169 @@
|
||||||
|
package com.zlm.hp.db.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadThreadInfo;
|
||||||
|
import com.zlm.hp.db.DBHelper;
|
||||||
|
import com.zlm.hp.db.dao.DownloadThreadInfoDao;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.query.WhereCondition;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载线程db处理
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-10-07 20:24
|
||||||
|
**/
|
||||||
|
public class DownloadThreadInfoDB {
|
||||||
|
/**
|
||||||
|
* 添加下载线程任务
|
||||||
|
*
|
||||||
|
* @param downloadThreadInfo
|
||||||
|
*/
|
||||||
|
public static boolean add(Context context, DownloadThreadInfo downloadThreadInfo) {
|
||||||
|
try {
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getDownloadThreadInfoDao().insert(downloadThreadInfo);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws
|
||||||
|
* @Description: 获取线程任务
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-10-07 20:32
|
||||||
|
*/
|
||||||
|
public static DownloadThreadInfo getDownloadThreadInfo(Context context, String tid, int threadNum, int threadId) {
|
||||||
|
try {
|
||||||
|
List<DownloadThreadInfo> downloadThreadInfos = DBHelper.getInstance(context).getDaoSession().getDownloadThreadInfoDao().queryBuilder().where(new WhereCondition.StringCondition(DownloadThreadInfoDao.Properties.TaskId.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadNum.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadId.columnName +
|
||||||
|
"=?", tid + "", threadNum + "", threadId + "")).list();
|
||||||
|
if (downloadThreadInfos != null && downloadThreadInfos.size() > 0) {
|
||||||
|
return downloadThreadInfos.get(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程任务是否存在
|
||||||
|
*
|
||||||
|
* @param tid
|
||||||
|
* @param threadNum
|
||||||
|
* @param threadID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isExists(Context context, String tid, int threadNum, int threadID) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {tid, threadNum + "", threadID + ""};
|
||||||
|
String sql = "select * from " + DownloadThreadInfoDao.TABLENAME + " WHERE " + DownloadThreadInfoDao.Properties.TaskId.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadNum.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadId.columnName +
|
||||||
|
"=?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下载进度
|
||||||
|
*
|
||||||
|
* @param tid
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int getDownloadedSize(Context context, String tid, int threadNum) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {tid, threadNum + ""};
|
||||||
|
String name = DownloadThreadInfoDao.Properties.DownloadedSize.columnName;
|
||||||
|
String sql = "SELECT sum(" + name + ") as " + name + " from " + DownloadThreadInfoDao.TABLENAME
|
||||||
|
+ " WHERE " + DownloadThreadInfoDao.Properties.TaskId.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadNum.columnName + "=?";
|
||||||
|
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return cursor.getInt(cursor.getColumnIndex(name));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新下载线程任务
|
||||||
|
*/
|
||||||
|
public static boolean update(Context context, String tid, int threadNum, int threadID,
|
||||||
|
int downloadedSize) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "UPDATE ";
|
||||||
|
sql += DownloadThreadInfoDao.TABLENAME;
|
||||||
|
sql += " SET " + DownloadThreadInfoDao.Properties.DownloadedSize.columnName + " =?";
|
||||||
|
sql += " where " + DownloadThreadInfoDao.Properties.TaskId.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadNum.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadId.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {downloadedSize + "", tid, threadNum + "", threadID + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除下载线程任务
|
||||||
|
*/
|
||||||
|
public static boolean delete(Context context, String tid, int threadNum) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += DownloadThreadInfoDao.TABLENAME;
|
||||||
|
sql += " where " + DownloadThreadInfoDao.Properties.TaskId.columnName + "=? and " + DownloadThreadInfoDao.Properties.ThreadNum.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {tid, threadNum + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除所有下载线程任务
|
||||||
|
*/
|
||||||
|
public static boolean deleteAll(Context context, int threadNum) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += DownloadThreadInfoDao.TABLENAME;
|
||||||
|
sql += " where " + DownloadThreadInfoDao.Properties.ThreadNum.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {threadNum + ""};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
114
app/src/main/java/com/zlm/hp/db/util/SingerInfoDB.java
Normal file
114
app/src/main/java/com/zlm/hp/db/util/SingerInfoDB.java
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
package com.zlm.hp.db.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.DBHelper;
|
||||||
|
import com.zlm.hp.db.dao.SingerInfoDao;
|
||||||
|
import com.zlm.hp.entity.SingerInfo;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.query.WhereCondition;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌手写真
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-11-18 12:48
|
||||||
|
**/
|
||||||
|
public class SingerInfoDB {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param singerInfo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean add(Context context, SingerInfo singerInfo) {
|
||||||
|
try {
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getSingerInfoDao().insert(singerInfo);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌手写真图片
|
||||||
|
*
|
||||||
|
* @param singerName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<SingerInfo> getAllSingerImage(Context context, String singerName) {
|
||||||
|
try {
|
||||||
|
List<SingerInfo> singerInfos = DBHelper.getInstance(context).getDaoSession().getSingerInfoDao().queryBuilder().where(new WhereCondition.StringCondition(SingerInfoDao.Properties.SingerName.columnName + "=?", singerName)).orderDesc(SingerInfoDao.Properties.CreateTime).list();
|
||||||
|
return singerInfos;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param context
|
||||||
|
* @param imageUrl
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isExists(Context context, String imageUrl) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {imageUrl};
|
||||||
|
String sql = "select * from " + SingerInfoDao.TABLENAME + " WHERE " + SingerInfoDao.Properties.ImageUrl.columnName + "=?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public static boolean deleteBySingerName(Context context, String singerName) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += SingerInfoDao.TABLENAME;
|
||||||
|
sql += " where " + SingerInfoDao.Properties.SingerName.columnName + "=?";
|
||||||
|
String args[] = {singerName};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public static boolean delete(Context context, String imageUrl) {
|
||||||
|
try {
|
||||||
|
String sql = "DELETE FROM ";
|
||||||
|
sql += SingerInfoDao.TABLENAME;
|
||||||
|
sql += " where " + SingerInfoDao.Properties.ImageUrl.columnName + "=?";
|
||||||
|
String args[] = {imageUrl};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
84
app/src/main/java/com/zlm/hp/db/util/VideoInfoDB.java
Normal file
84
app/src/main/java/com/zlm/hp/db/util/VideoInfoDB.java
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.zlm.hp.db.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.DBHelper;
|
||||||
|
import com.zlm.hp.db.dao.VideoInfoDao;
|
||||||
|
import com.zlm.hp.entity.VideoInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: Video数据库处理
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2019-01-06 1:06
|
||||||
|
**/
|
||||||
|
public class VideoInfoDB {
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param videoInfo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean addVideoInfo(Context context, VideoInfo videoInfo) {
|
||||||
|
try {
|
||||||
|
DBHelper.getInstance(context).getDaoSession().getVideoInfoDao().save(videoInfo);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存在
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isVideoExists(Context context, String hash) {
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
String args[] = {hash};
|
||||||
|
String sql = "select * from " + VideoInfoDao.TABLENAME;
|
||||||
|
sql += " where " + VideoInfoDao.Properties.Hash.columnName + "=?";
|
||||||
|
cursor = DBHelper.getInstance(context).getWritableDatabase().rawQuery(sql, args);
|
||||||
|
if (cursor.moveToNext()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (cursor != null) {
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param hash
|
||||||
|
* @param status
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean updateVideo(Context context, String hash, int status) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String sql = "UPDATE ";
|
||||||
|
sql += VideoInfoDao.TABLENAME;
|
||||||
|
sql += " SET " + VideoInfoDao.Properties.Status.columnName + " =?";
|
||||||
|
sql += " where " + VideoInfoDao.Properties.Hash.columnName + "=?";
|
||||||
|
|
||||||
|
String args[] = {status + "", hash};
|
||||||
|
DBHelper.getInstance(context).getWritableDatabase().execSQL(sql, args);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
48
app/src/main/java/com/zlm/hp/entity/AlbumInfo.java
Normal file
48
app/src/main/java/com/zlm/hp/entity/AlbumInfo.java
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 专辑信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 23:21
|
||||||
|
**/
|
||||||
|
|
||||||
|
public class AlbumInfo {
|
||||||
|
/**
|
||||||
|
* 专辑id
|
||||||
|
*/
|
||||||
|
private String albumId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专辑名称
|
||||||
|
*/
|
||||||
|
private String albumName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
public String getAlbumId() {
|
||||||
|
return albumId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumId(String albumId) {
|
||||||
|
this.albumId = albumId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAlbumName() {
|
||||||
|
return albumName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumName(String albumName) {
|
||||||
|
this.albumName = albumName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
415
app/src/main/java/com/zlm/hp/entity/AudioInfo.java
Normal file
415
app/src/main/java/com/zlm/hp/entity/AudioInfo.java
Normal file
|
|
@ -0,0 +1,415 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.annotation.Entity;
|
||||||
|
import org.greenrobot.greendao.annotation.Transient;
|
||||||
|
import org.greenrobot.greendao.annotation.Generated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌曲信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 17:50
|
||||||
|
**/
|
||||||
|
@Entity(
|
||||||
|
generateConstructors = false,
|
||||||
|
generateGettersSetters = false
|
||||||
|
)
|
||||||
|
public class AudioInfo implements Parcelable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
public static final int STATUS_FINISH = 0;
|
||||||
|
public static final int STATUS_DOWNLOADING = 1;
|
||||||
|
public static final int STATUS_INIT = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private int status = STATUS_INIT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
public static final int TYPE_LOCAL = 0;
|
||||||
|
public static final int TYPE_NET = 1;
|
||||||
|
//最近-本地
|
||||||
|
public static final int TYPE_RECENT_LOCAL = 2;
|
||||||
|
//最近-网络
|
||||||
|
public static final int TYPE_RECENT_NET = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 喜欢(网络-本地)
|
||||||
|
*/
|
||||||
|
public static final int TYPE_LIKE_LOCAL = 4;
|
||||||
|
public static final int TYPE_LIKE_NET = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private int type = TYPE_LOCAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关键字
|
||||||
|
*/
|
||||||
|
private String keyword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌单id
|
||||||
|
*/
|
||||||
|
private String specialId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手id
|
||||||
|
*/
|
||||||
|
private String singerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专辑id
|
||||||
|
*/
|
||||||
|
private String albumId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲名称
|
||||||
|
*/
|
||||||
|
private String songName;
|
||||||
|
/**
|
||||||
|
* 歌手名称
|
||||||
|
*/
|
||||||
|
private String singerName;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String hash;
|
||||||
|
/**
|
||||||
|
* mv hash
|
||||||
|
*/
|
||||||
|
private String mvHash;
|
||||||
|
/**
|
||||||
|
* 歌曲后缀名
|
||||||
|
*/
|
||||||
|
private String fileExt;
|
||||||
|
/**
|
||||||
|
* 文件大小
|
||||||
|
*/
|
||||||
|
private long fileSize;
|
||||||
|
private String fileSizeText;
|
||||||
|
/**
|
||||||
|
* 文件路径
|
||||||
|
*/
|
||||||
|
private String filePath;
|
||||||
|
/**
|
||||||
|
* 时长
|
||||||
|
*/
|
||||||
|
private long duration;
|
||||||
|
private String durationText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加时间
|
||||||
|
*/
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类索引
|
||||||
|
*/
|
||||||
|
private String category;
|
||||||
|
private String childCategory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件下载路径
|
||||||
|
*/
|
||||||
|
private String downloadUrl;
|
||||||
|
/**
|
||||||
|
* MV路径
|
||||||
|
*/
|
||||||
|
private String mvPath;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Transient
|
||||||
|
private int playProgress;
|
||||||
|
public AudioInfo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AudioInfo(Parcel in) {
|
||||||
|
if (in != null) {
|
||||||
|
status = in.readInt();
|
||||||
|
type = in.readInt();
|
||||||
|
keyword = in.readString();
|
||||||
|
imageUrl = in.readString();
|
||||||
|
specialId = in.readString();
|
||||||
|
singerId = in.readString();
|
||||||
|
albumId = in.readString();
|
||||||
|
songName = in.readString();
|
||||||
|
singerName = in.readString();
|
||||||
|
hash = in.readString();
|
||||||
|
mvHash = in.readString();
|
||||||
|
fileExt = in.readString();
|
||||||
|
fileSize = in.readLong();
|
||||||
|
fileSizeText = in.readString();
|
||||||
|
filePath = in.readString();
|
||||||
|
duration = in.readLong();
|
||||||
|
durationText = in.readString();
|
||||||
|
createTime = in.readString();
|
||||||
|
category = in.readString();
|
||||||
|
childCategory = in.readString();
|
||||||
|
downloadUrl = in.readString();
|
||||||
|
playProgress = in.readInt();
|
||||||
|
mvPath = in.readString();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
if (getSingerName().equals("未知")) {
|
||||||
|
return getSongName();
|
||||||
|
}
|
||||||
|
return getSingerName() + " - " + getSongName();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 判断是否单纯是MV
|
||||||
|
*/
|
||||||
|
public boolean IsOnlyMV() {
|
||||||
|
if(filePath==null){return true;}
|
||||||
|
if(mvPath==null){return false;}
|
||||||
|
if (filePath.isEmpty() && !mvPath.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static final Creator<AudioInfo> CREATOR = new Creator<AudioInfo>() {
|
||||||
|
@Override
|
||||||
|
public AudioInfo createFromParcel(Parcel in) {
|
||||||
|
return new AudioInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AudioInfo[] newArray(int size) {
|
||||||
|
return new AudioInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getKeyword() {
|
||||||
|
return keyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyword(String keyword) {
|
||||||
|
this.keyword = keyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSpecialId() {
|
||||||
|
return specialId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpecialId(String specialId) {
|
||||||
|
this.specialId = specialId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSongName() {
|
||||||
|
return songName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSongName(String songName) {
|
||||||
|
this.songName = songName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingerName() {
|
||||||
|
return singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingerName(String singerName) {
|
||||||
|
this.singerName = singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHash() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHash(String hash) {
|
||||||
|
this.hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileExt() {
|
||||||
|
return fileExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileExt(String fileExt) {
|
||||||
|
this.fileExt = fileExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFileSize() {
|
||||||
|
return fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSize(long fileSize) {
|
||||||
|
this.fileSize = fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileSizeText() {
|
||||||
|
return fileSizeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSizeText(String fileSizeText) {
|
||||||
|
this.fileSizeText = fileSizeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilePath() {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilePath(String filePath) {
|
||||||
|
this.filePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuration(long duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDurationText() {
|
||||||
|
return durationText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDurationText(String durationText) {
|
||||||
|
this.durationText = durationText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(String createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChildCategory() {
|
||||||
|
return childCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChildCategory(String childCategory) {
|
||||||
|
this.childCategory = childCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMvHash() {
|
||||||
|
return mvHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMvHash(String mvHash) {
|
||||||
|
this.mvHash = mvHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingerId() {
|
||||||
|
return singerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingerId(String singerId) {
|
||||||
|
this.singerId = singerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAlbumId() {
|
||||||
|
return albumId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbumId(String albumId) {
|
||||||
|
this.albumId = albumId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDownloadUrl() {
|
||||||
|
return downloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadUrl(String downloadUrl) {
|
||||||
|
this.downloadUrl = downloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMvPath() {
|
||||||
|
return mvPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMvPath(String mvPath) {
|
||||||
|
this.mvPath = mvPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPlayProgress() {
|
||||||
|
return playProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayProgress(int playProgress) {
|
||||||
|
this.playProgress = playProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(status);
|
||||||
|
dest.writeInt(type);
|
||||||
|
dest.writeString(keyword);
|
||||||
|
dest.writeString(imageUrl);
|
||||||
|
dest.writeString(specialId);
|
||||||
|
dest.writeString(singerId);
|
||||||
|
dest.writeString(albumId);
|
||||||
|
dest.writeString(songName);
|
||||||
|
dest.writeString(singerName);
|
||||||
|
dest.writeString(hash);
|
||||||
|
dest.writeString(mvHash);
|
||||||
|
dest.writeString(fileExt);
|
||||||
|
dest.writeLong(fileSize);
|
||||||
|
dest.writeString(fileSizeText);
|
||||||
|
dest.writeString(filePath);
|
||||||
|
dest.writeLong(duration);
|
||||||
|
dest.writeString(durationText);
|
||||||
|
dest.writeString(createTime);
|
||||||
|
dest.writeString(category);
|
||||||
|
dest.writeString(childCategory);
|
||||||
|
dest.writeString(downloadUrl);
|
||||||
|
dest.writeInt(playProgress);
|
||||||
|
dest.writeString(mvPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
74
app/src/main/java/com/zlm/hp/entity/Category.java
Normal file
74
app/src/main/java/com/zlm/hp/entity/Category.java
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类
|
||||||
|
* Created by zhangliangming on 2017/8/5.
|
||||||
|
*/
|
||||||
|
public class Category {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类名
|
||||||
|
*/
|
||||||
|
private String categoryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类的内容
|
||||||
|
*/
|
||||||
|
private List<AudioInfo> categoryItem = new ArrayList<AudioInfo>();
|
||||||
|
|
||||||
|
public String getCategoryName() {
|
||||||
|
return categoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryName(String categoryName) {
|
||||||
|
this.categoryName = categoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AudioInfo> getCategoryItem() {
|
||||||
|
return categoryItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryItem(List<AudioInfo> categoryItem) {
|
||||||
|
this.categoryItem = categoryItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取总个数
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getCount() {
|
||||||
|
return categoryItem.size() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取子个数
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getItemCount() {
|
||||||
|
return categoryItem.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据索引获取子内容
|
||||||
|
*
|
||||||
|
* @param pPosition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Object getItem(int pPosition) {
|
||||||
|
if (pPosition < 0)
|
||||||
|
return null;
|
||||||
|
if (pPosition == 0) {
|
||||||
|
return categoryName;
|
||||||
|
} else {
|
||||||
|
if (categoryItem.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return categoryItem.get(pPosition - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
app/src/main/java/com/zlm/hp/entity/FileInfo.java
Normal file
46
app/src/main/java/com/zlm/hp/entity/FileInfo.java
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 文件信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-05-22 22:26
|
||||||
|
**/
|
||||||
|
public class FileInfo {
|
||||||
|
/**
|
||||||
|
* 是否是文件
|
||||||
|
*/
|
||||||
|
private boolean isFile;
|
||||||
|
/**
|
||||||
|
* 路径
|
||||||
|
*/
|
||||||
|
private String filePath;
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
public boolean isFile() {
|
||||||
|
return isFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFile(boolean file) {
|
||||||
|
isFile = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilePath() {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilePath(String filePath) {
|
||||||
|
this.filePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileName(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
156
app/src/main/java/com/zlm/hp/entity/LrcInfo.java
Normal file
156
app/src/main/java/com/zlm/hp/entity/LrcInfo.java
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌词信息类
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-31 23:59
|
||||||
|
**/
|
||||||
|
|
||||||
|
public class LrcInfo implements Parcelable{
|
||||||
|
/**
|
||||||
|
* 歌词id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String accesskey;
|
||||||
|
/**
|
||||||
|
* 时长
|
||||||
|
*/
|
||||||
|
private String duration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手
|
||||||
|
*/
|
||||||
|
private String singerName;
|
||||||
|
/**
|
||||||
|
* 歌曲名称
|
||||||
|
*/
|
||||||
|
private String songName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词编码
|
||||||
|
*/
|
||||||
|
private String charset;
|
||||||
|
/**
|
||||||
|
* 歌词内容(base64)
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 歌词格式
|
||||||
|
*/
|
||||||
|
private String fmt;
|
||||||
|
|
||||||
|
public LrcInfo(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected LrcInfo(Parcel in) {
|
||||||
|
id = in.readString();
|
||||||
|
accesskey = in.readString();
|
||||||
|
duration = in.readString();
|
||||||
|
singerName = in.readString();
|
||||||
|
songName = in.readString();
|
||||||
|
charset = in.readString();
|
||||||
|
content = in.readString();
|
||||||
|
fmt = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(id);
|
||||||
|
dest.writeString(accesskey);
|
||||||
|
dest.writeString(duration);
|
||||||
|
dest.writeString(singerName);
|
||||||
|
dest.writeString(songName);
|
||||||
|
dest.writeString(charset);
|
||||||
|
dest.writeString(content);
|
||||||
|
dest.writeString(fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<LrcInfo> CREATOR = new Creator<LrcInfo>() {
|
||||||
|
@Override
|
||||||
|
public LrcInfo createFromParcel(Parcel in) {
|
||||||
|
return new LrcInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LrcInfo[] newArray(int size) {
|
||||||
|
return new LrcInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccesskey() {
|
||||||
|
return accesskey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccesskey(String accesskey) {
|
||||||
|
this.accesskey = accesskey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuration(String duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingerName() {
|
||||||
|
return singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingerName(String singerName) {
|
||||||
|
this.singerName = singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSongName() {
|
||||||
|
return songName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSongName(String songName) {
|
||||||
|
this.songName = songName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCharset() {
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCharset(String charset) {
|
||||||
|
this.charset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFmt() {
|
||||||
|
return fmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFmt(String fmt) {
|
||||||
|
this.fmt = fmt;
|
||||||
|
}
|
||||||
|
}
|
||||||
108
app/src/main/java/com/zlm/hp/entity/RankInfo.java
Normal file
108
app/src/main/java/com/zlm/hp/entity/RankInfo.java
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 排行榜信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 23:25
|
||||||
|
**/
|
||||||
|
|
||||||
|
public class RankInfo implements Parcelable{
|
||||||
|
/**
|
||||||
|
* 排行榜id
|
||||||
|
*/
|
||||||
|
private String rankId;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String rankType = "";
|
||||||
|
/**
|
||||||
|
* 排行榜名称
|
||||||
|
*/
|
||||||
|
private String rankName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
public RankInfo(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public RankInfo(String rankId, String rankName,String rankType) {
|
||||||
|
this.rankId = rankId;
|
||||||
|
this.rankName = rankName;
|
||||||
|
this.rankType = rankType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RankInfo newDefRankInfo(){
|
||||||
|
return new RankInfo("6666","2","酷狗飙升榜");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RankInfo(Parcel in) {
|
||||||
|
rankId = in.readString();
|
||||||
|
rankName = in.readString();
|
||||||
|
imageUrl = in.readString();
|
||||||
|
rankType = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(rankId);
|
||||||
|
dest.writeString(rankName);
|
||||||
|
dest.writeString(imageUrl);
|
||||||
|
dest.writeString(rankType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<RankInfo> CREATOR = new Creator<RankInfo>() {
|
||||||
|
@Override
|
||||||
|
public RankInfo createFromParcel(Parcel in) {
|
||||||
|
return new RankInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RankInfo[] newArray(int size) {
|
||||||
|
return new RankInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getRankId() {
|
||||||
|
return rankId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRankId(String rankId) {
|
||||||
|
this.rankId = rankId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRankName() {
|
||||||
|
return rankName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRankName(String rankName) {
|
||||||
|
this.rankName = rankName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRankType() {
|
||||||
|
return rankType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRankType(String rankType) {
|
||||||
|
this.rankType = rankType;
|
||||||
|
}
|
||||||
|
}
|
||||||
137
app/src/main/java/com/zlm/hp/entity/SingerInfo.java
Normal file
137
app/src/main/java/com/zlm/hp/entity/SingerInfo.java
Normal file
|
|
@ -0,0 +1,137 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.annotation.Entity;
|
||||||
|
import org.greenrobot.greendao.annotation.Transient;
|
||||||
|
import org.greenrobot.greendao.annotation.Generated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌手信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 23:09
|
||||||
|
**/
|
||||||
|
@Entity(
|
||||||
|
generateConstructors = false,
|
||||||
|
generateGettersSetters = false
|
||||||
|
)
|
||||||
|
public class SingerInfo implements Parcelable {
|
||||||
|
/**
|
||||||
|
* 歌手分类id
|
||||||
|
*/
|
||||||
|
@Transient
|
||||||
|
private String classId;
|
||||||
|
/**
|
||||||
|
* 歌手分类名称
|
||||||
|
*/
|
||||||
|
@Transient
|
||||||
|
private String className;
|
||||||
|
/**
|
||||||
|
* 歌手id
|
||||||
|
*/
|
||||||
|
private String singerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手名称
|
||||||
|
*/
|
||||||
|
private String singerName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
public SingerInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected SingerInfo(Parcel in) {
|
||||||
|
classId = in.readString();
|
||||||
|
className = in.readString();
|
||||||
|
singerId = in.readString();
|
||||||
|
singerName = in.readString();
|
||||||
|
imageUrl = in.readString();
|
||||||
|
createTime = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(classId);
|
||||||
|
dest.writeString(className);
|
||||||
|
dest.writeString(singerId);
|
||||||
|
dest.writeString(singerName);
|
||||||
|
dest.writeString(imageUrl);
|
||||||
|
dest.writeString(createTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<SingerInfo> CREATOR = new Creator<SingerInfo>() {
|
||||||
|
@Override
|
||||||
|
public SingerInfo createFromParcel(Parcel in) {
|
||||||
|
return new SingerInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingerInfo[] newArray(int size) {
|
||||||
|
return new SingerInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getClassId() {
|
||||||
|
return classId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassId(String classId) {
|
||||||
|
this.classId = classId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassName() {
|
||||||
|
return className;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClassName(String className) {
|
||||||
|
this.className = className;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingerId() {
|
||||||
|
return singerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingerId(String singerId) {
|
||||||
|
this.singerId = singerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingerName() {
|
||||||
|
return singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingerName(String singerName) {
|
||||||
|
this.singerName = singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreateTime(String createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
84
app/src/main/java/com/zlm/hp/entity/SpecialInfo.java
Normal file
84
app/src/main/java/com/zlm/hp/entity/SpecialInfo.java
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌单
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 23:28
|
||||||
|
**/
|
||||||
|
|
||||||
|
public class SpecialInfo implements Parcelable{
|
||||||
|
/**
|
||||||
|
* 歌单id
|
||||||
|
*/
|
||||||
|
private String specialId;
|
||||||
|
/**
|
||||||
|
* 歌单名称
|
||||||
|
*/
|
||||||
|
private String specialName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
public SpecialInfo(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SpecialInfo(Parcel in) {
|
||||||
|
specialId = in.readString();
|
||||||
|
specialName = in.readString();
|
||||||
|
imageUrl = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(specialId);
|
||||||
|
dest.writeString(specialName);
|
||||||
|
dest.writeString(imageUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<SpecialInfo> CREATOR = new Creator<SpecialInfo>() {
|
||||||
|
@Override
|
||||||
|
public SpecialInfo createFromParcel(Parcel in) {
|
||||||
|
return new SpecialInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpecialInfo[] newArray(int size) {
|
||||||
|
return new SpecialInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getSpecialId() {
|
||||||
|
return specialId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpecialId(String specialId) {
|
||||||
|
this.specialId = specialId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSpecialName() {
|
||||||
|
return specialName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpecialName(String specialName) {
|
||||||
|
this.specialName = specialName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
55
app/src/main/java/com/zlm/hp/entity/StorageInfo.java
Normal file
55
app/src/main/java/com/zlm/hp/entity/StorageInfo.java
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 储存卡
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-29 11:59
|
||||||
|
**/
|
||||||
|
public class StorageInfo {
|
||||||
|
/**
|
||||||
|
* 路径
|
||||||
|
*/
|
||||||
|
private String path;
|
||||||
|
/**
|
||||||
|
* 挂载状态
|
||||||
|
*/
|
||||||
|
private String state;
|
||||||
|
/**
|
||||||
|
* 是否移除
|
||||||
|
*/
|
||||||
|
private boolean isRemoveable;
|
||||||
|
|
||||||
|
public StorageInfo(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isMounted() {
|
||||||
|
return "mounted".equals(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(String state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRemoveable() {
|
||||||
|
return isRemoveable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoveable(boolean removeable) {
|
||||||
|
isRemoveable = removeable;
|
||||||
|
}
|
||||||
|
}
|
||||||
77
app/src/main/java/com/zlm/hp/entity/TimerInfo.java
Normal file
77
app/src/main/java/com/zlm/hp/entity/TimerInfo.java
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 定时器信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-11-25 13:45
|
||||||
|
**/
|
||||||
|
public class TimerInfo implements Parcelable{
|
||||||
|
public static final int TYPE_SYS = 0;
|
||||||
|
public static final int TYPE_DEF = 1;
|
||||||
|
|
||||||
|
private int sumTime;
|
||||||
|
private int curTime;
|
||||||
|
private int type = TYPE_SYS;
|
||||||
|
|
||||||
|
public TimerInfo(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected TimerInfo(Parcel in) {
|
||||||
|
sumTime = in.readInt();
|
||||||
|
curTime = in.readInt();
|
||||||
|
type = in.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(sumTime);
|
||||||
|
dest.writeInt(curTime);
|
||||||
|
dest.writeInt(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<TimerInfo> CREATOR = new Creator<TimerInfo>() {
|
||||||
|
@Override
|
||||||
|
public TimerInfo createFromParcel(Parcel in) {
|
||||||
|
return new TimerInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimerInfo[] newArray(int size) {
|
||||||
|
return new TimerInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public int getSumTime() {
|
||||||
|
return sumTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSumTime(int sumTime) {
|
||||||
|
this.sumTime = sumTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurTime() {
|
||||||
|
return curTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurTime(int curTime) {
|
||||||
|
this.curTime = curTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
64
app/src/main/java/com/zlm/hp/entity/ToolInfo.java
Normal file
64
app/src/main/java/com/zlm/hp/entity/ToolInfo.java
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 工具信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-30 16:46
|
||||||
|
**/
|
||||||
|
public class ToolInfo implements Parcelable{
|
||||||
|
public static final String DATA_KEY = "Data_Key";
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String packageName;
|
||||||
|
|
||||||
|
public ToolInfo(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ToolInfo(Parcel in) {
|
||||||
|
title = in.readString();
|
||||||
|
packageName = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(title);
|
||||||
|
dest.writeString(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<ToolInfo> CREATOR = new Creator<ToolInfo>() {
|
||||||
|
@Override
|
||||||
|
public ToolInfo createFromParcel(Parcel in) {
|
||||||
|
return new ToolInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ToolInfo[] newArray(int size) {
|
||||||
|
return new ToolInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageName(String packageName) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
}
|
||||||
|
}
|
||||||
236
app/src/main/java/com/zlm/hp/entity/VideoInfo.java
Normal file
236
app/src/main/java/com/zlm/hp/entity/VideoInfo.java
Normal file
|
|
@ -0,0 +1,236 @@
|
||||||
|
package com.zlm.hp.entity;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import org.greenrobot.greendao.annotation.Entity;
|
||||||
|
import org.greenrobot.greendao.annotation.Generated;
|
||||||
|
import org.greenrobot.greendao.annotation.Transient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 视频信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-07-30 1:55
|
||||||
|
**/
|
||||||
|
@Entity(
|
||||||
|
generateConstructors = false,
|
||||||
|
generateGettersSetters = false
|
||||||
|
)
|
||||||
|
public class VideoInfo implements Parcelable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final String DATA_KEY = "Data_Key";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
public static final int STATUS_FINISH = 0;
|
||||||
|
public static final int STATUS_INIT = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String hash;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲后缀名
|
||||||
|
*/
|
||||||
|
private String fileExt;
|
||||||
|
/**
|
||||||
|
* 文件大小
|
||||||
|
*/
|
||||||
|
private long fileSize;
|
||||||
|
private String fileSizeText;
|
||||||
|
/**
|
||||||
|
* 文件路径
|
||||||
|
*/
|
||||||
|
private String filePath;
|
||||||
|
/**
|
||||||
|
* 时长
|
||||||
|
*/
|
||||||
|
private long duration;
|
||||||
|
private String durationText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mv名称
|
||||||
|
*/
|
||||||
|
private String mvName;
|
||||||
|
/**
|
||||||
|
* 歌手名称
|
||||||
|
*/
|
||||||
|
private String singerName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
*/
|
||||||
|
private String imageUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件下载路径
|
||||||
|
*/
|
||||||
|
private String downloadUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private int status = STATUS_INIT;
|
||||||
|
|
||||||
|
public VideoInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected VideoInfo(Parcel in) {
|
||||||
|
hash = in.readString();
|
||||||
|
fileExt = in.readString();
|
||||||
|
fileSize = in.readLong();
|
||||||
|
fileSizeText = in.readString();
|
||||||
|
filePath = in.readString();
|
||||||
|
duration = in.readLong();
|
||||||
|
durationText = in.readString();
|
||||||
|
mvName = in.readString();
|
||||||
|
singerName = in.readString();
|
||||||
|
imageUrl = in.readString();
|
||||||
|
downloadUrl = in.readString();
|
||||||
|
status = in.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(hash);
|
||||||
|
dest.writeString(fileExt);
|
||||||
|
dest.writeLong(fileSize);
|
||||||
|
dest.writeString(fileSizeText);
|
||||||
|
dest.writeString(filePath);
|
||||||
|
dest.writeLong(duration);
|
||||||
|
dest.writeString(durationText);
|
||||||
|
dest.writeString(mvName);
|
||||||
|
dest.writeString(singerName);
|
||||||
|
dest.writeString(imageUrl);
|
||||||
|
dest.writeString(downloadUrl);
|
||||||
|
dest.writeInt(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<VideoInfo> CREATOR = new Creator<VideoInfo>() {
|
||||||
|
@Override
|
||||||
|
public VideoInfo createFromParcel(Parcel in) {
|
||||||
|
return new VideoInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VideoInfo[] newArray(int size) {
|
||||||
|
return new VideoInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHash() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHash(String hash) {
|
||||||
|
this.hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileExt() {
|
||||||
|
return fileExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileExt(String fileExt) {
|
||||||
|
this.fileExt = fileExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFileSize() {
|
||||||
|
return fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSize(long fileSize) {
|
||||||
|
this.fileSize = fileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileSizeText() {
|
||||||
|
return fileSizeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSizeText(String fileSizeText) {
|
||||||
|
this.fileSizeText = fileSizeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilePath() {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilePath(String filePath) {
|
||||||
|
this.filePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getDuration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuration(long duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDurationText() {
|
||||||
|
return durationText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDurationText(String durationText) {
|
||||||
|
this.durationText = durationText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMvName() {
|
||||||
|
return mvName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMvName(String mvName) {
|
||||||
|
this.mvName = mvName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSingerName() {
|
||||||
|
return singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingerName(String singerName) {
|
||||||
|
this.singerName = singerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDownloadUrl() {
|
||||||
|
return downloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadUrl(String downloadUrl) {
|
||||||
|
this.downloadUrl = downloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
if (getSingerName().equals("未知")) {
|
||||||
|
return getMvName();
|
||||||
|
}
|
||||||
|
return getSingerName() + " - " + getMvName();
|
||||||
|
}
|
||||||
|
}
|
||||||
87
app/src/main/java/com/zlm/hp/entity/tool/MakeInfo.java
Normal file
87
app/src/main/java/com/zlm/hp/entity/tool/MakeInfo.java
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.zlm.hp.entity.tool;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 制作歌词信息
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-30 22:34
|
||||||
|
**/
|
||||||
|
public class MakeInfo implements Parcelable{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static final String DATA_KEY = "Data_Key";
|
||||||
|
private AudioInfo audioInfo;
|
||||||
|
/**
|
||||||
|
* 默认歌词读取路径
|
||||||
|
*/
|
||||||
|
private String lrcFilePath;
|
||||||
|
/**
|
||||||
|
* 保存歌词路径
|
||||||
|
*/
|
||||||
|
private String saveLrcFilePath;
|
||||||
|
|
||||||
|
|
||||||
|
public MakeInfo(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MakeInfo(Parcel in) {
|
||||||
|
audioInfo = in.readParcelable(AudioInfo.class.getClassLoader());
|
||||||
|
lrcFilePath = in.readString();
|
||||||
|
saveLrcFilePath = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeParcelable(audioInfo, flags);
|
||||||
|
dest.writeString(lrcFilePath);
|
||||||
|
dest.writeString(saveLrcFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<MakeInfo> CREATOR = new Creator<MakeInfo>() {
|
||||||
|
@Override
|
||||||
|
public MakeInfo createFromParcel(Parcel in) {
|
||||||
|
return new MakeInfo(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MakeInfo[] newArray(int size) {
|
||||||
|
return new MakeInfo[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getSaveLrcFilePath() {
|
||||||
|
return saveLrcFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSaveLrcFilePath(String saveLrcFilePath) {
|
||||||
|
this.saveLrcFilePath = saveLrcFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLrcFilePath() {
|
||||||
|
return lrcFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLrcFilePath(String lrcFilePath) {
|
||||||
|
this.lrcFilePath = lrcFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AudioInfo getAudioInfo() {
|
||||||
|
return audioInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAudioInfo(AudioInfo audioInfo) {
|
||||||
|
this.audioInfo = audioInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
427
app/src/main/java/com/zlm/hp/fragment/BaseFragment.java
Normal file
427
app/src/main/java/com/zlm/hp/fragment/BaseFragment.java
Normal file
|
|
@ -0,0 +1,427 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Process;
|
||||||
|
import android.support.constraint.ConstraintLayout;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewParent;
|
||||||
|
import android.view.ViewStub;
|
||||||
|
import android.view.animation.Animation;
|
||||||
|
import android.view.animation.AnimationUtils;
|
||||||
|
import android.view.animation.LinearInterpolator;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
|
import com.zlm.hp.handler.WeakRefHandler;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.AppBarUtil;
|
||||||
|
import com.zlm.hp.util.ColorUtil;
|
||||||
|
import com.zlm.hp.util.ContextUtil;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by zhangliangming on 2018-08-11.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public abstract class BaseFragment extends Fragment {
|
||||||
|
/**
|
||||||
|
* 是否是第一次可视
|
||||||
|
*/
|
||||||
|
private boolean mIsFristVisibleToUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Context mContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子线程用于执行耗时任务
|
||||||
|
*/
|
||||||
|
public WeakRefHandler mWorkerHandler;
|
||||||
|
//创建异步HandlerThread
|
||||||
|
private HandlerThread mHandlerThread;
|
||||||
|
/**
|
||||||
|
* 处理ui任务
|
||||||
|
*/
|
||||||
|
public WeakRefHandler mUIHandler;
|
||||||
|
/**
|
||||||
|
* 状态栏背景颜色
|
||||||
|
*/
|
||||||
|
private int mStatusBarViewBG = -1;
|
||||||
|
|
||||||
|
private final int SHOWLOADINGVIEW = 1000;
|
||||||
|
private final int SHOWCONTENTVIEW = 1001;
|
||||||
|
private final int SHOWNONETVIEW = 1002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否添加
|
||||||
|
*/
|
||||||
|
private boolean isAddStatusBarView = true;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容布局
|
||||||
|
*/
|
||||||
|
private ViewStub mContentContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载中布局
|
||||||
|
*/
|
||||||
|
private ViewStub mLoadingContainer;
|
||||||
|
/**
|
||||||
|
* 加载图标
|
||||||
|
*/
|
||||||
|
private IconfontTextView mLoadImgView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 旋转动画
|
||||||
|
*/
|
||||||
|
private Animation rotateAnimation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无网络
|
||||||
|
*/
|
||||||
|
private ViewStub mNetContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private ConstraintLayout mNetBGLayout;
|
||||||
|
|
||||||
|
private RefreshListener mRefreshListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题视图
|
||||||
|
*/
|
||||||
|
private int mTitleViewId = R.layout.layout_title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
private void init() {
|
||||||
|
this.mIsFristVisibleToUser = false;
|
||||||
|
this.mContext = ContextUtil.getContext();
|
||||||
|
//创建ui handler
|
||||||
|
mUIHandler = new WeakRefHandler(Looper.getMainLooper(), this, new Handler.Callback() {
|
||||||
|
@Override
|
||||||
|
public boolean handleMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case SHOWCONTENTVIEW:
|
||||||
|
showContentViewHandler();
|
||||||
|
break;
|
||||||
|
case SHOWLOADINGVIEW:
|
||||||
|
showLoadingViewHandler();
|
||||||
|
break;
|
||||||
|
case SHOWNONETVIEW:
|
||||||
|
showNoNetViewHandler();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
handleUIMessage(msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//创建异步HandlerThread
|
||||||
|
mHandlerThread = new HandlerThread("loadFragmentData", Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
|
//必须先开启线程
|
||||||
|
mHandlerThread.start();
|
||||||
|
//子线程Handler
|
||||||
|
mWorkerHandler = new WeakRefHandler(mHandlerThread.getLooper(), this, new Handler.Callback() {
|
||||||
|
@Override
|
||||||
|
public boolean handleMessage(Message msg) {
|
||||||
|
handleWorkerMessage(msg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
init();
|
||||||
|
mStatusBarViewBG = ColorUtil.parserColor(ContextCompat.getColor(mContext, R.color.defColor));
|
||||||
|
preInitStatusBar();
|
||||||
|
View mainView = inflater.inflate(R.layout.fragment_base, container, false);
|
||||||
|
|
||||||
|
//添加主布局
|
||||||
|
mContentContainer = mainView.findViewById(R.id.viewstub_content_container);
|
||||||
|
mContentContainer.setLayoutResource(setContentLayoutResID());
|
||||||
|
mContentContainer.inflate();
|
||||||
|
mContentContainer.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
//添加titleview
|
||||||
|
View titleView = inflater.inflate(mTitleViewId, container, false);
|
||||||
|
LinearLayout titleViewLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(-1, -1);
|
||||||
|
titleViewLL.addView(titleView,llp);
|
||||||
|
|
||||||
|
if (isAddStatusBarView) {
|
||||||
|
initStatusBar(mainView);
|
||||||
|
}
|
||||||
|
initLoadingView(mainView);
|
||||||
|
initNoNetView(mainView);
|
||||||
|
|
||||||
|
//初始化view相关数据
|
||||||
|
initViews(mainView, savedInstanceState);
|
||||||
|
|
||||||
|
//初始化是否可视
|
||||||
|
if (!mIsFristVisibleToUser && getUserVisibleHint()) {
|
||||||
|
mIsFristVisibleToUser = true;
|
||||||
|
isFristVisibleToUser();
|
||||||
|
}
|
||||||
|
return mainView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
|
||||||
|
//移除队列任务
|
||||||
|
if (mUIHandler != null) {
|
||||||
|
mUIHandler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//移除队列任务
|
||||||
|
if (mWorkerHandler != null) {
|
||||||
|
mWorkerHandler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭线程
|
||||||
|
if (mHandlerThread != null)
|
||||||
|
mHandlerThread.quit();
|
||||||
|
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化状态栏
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
*/
|
||||||
|
private void initStatusBar(View mainView) {
|
||||||
|
boolean isAddStatusBar = AppBarUtil.isAddStatusBar();
|
||||||
|
//添加状态栏
|
||||||
|
addStatusBar(mainView, isAddStatusBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加状态栏
|
||||||
|
*
|
||||||
|
* @param isAddStatusBar
|
||||||
|
*/
|
||||||
|
private void addStatusBar(View mainView, boolean isAddStatusBar) {
|
||||||
|
View statusBarView = mainView.findViewById(R.id.status_bar_view);
|
||||||
|
if (statusBarView == null) return;
|
||||||
|
if (!isAddStatusBar) {
|
||||||
|
statusBarView.setVisibility(View.GONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ViewParent parentView = statusBarView.getParent();
|
||||||
|
int statusBarViewHeight = AppBarUtil.getStatusBarHeight(mContext);
|
||||||
|
|
||||||
|
if (parentView instanceof ConstraintLayout) {
|
||||||
|
ConstraintLayout.LayoutParams clp = new ConstraintLayout.LayoutParams(-1, statusBarViewHeight);
|
||||||
|
statusBarView.setLayoutParams(clp);
|
||||||
|
} else if (parentView instanceof LinearLayout) {
|
||||||
|
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(-1, statusBarViewHeight);
|
||||||
|
statusBarView.setLayoutParams(llp);
|
||||||
|
} else if (parentView instanceof RelativeLayout) {
|
||||||
|
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(-1, statusBarViewHeight);
|
||||||
|
statusBarView.setLayoutParams(rlp);
|
||||||
|
} else if (parentView instanceof FrameLayout) {
|
||||||
|
FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(-1, statusBarViewHeight);
|
||||||
|
statusBarView.setLayoutParams(flp);
|
||||||
|
} else if (parentView instanceof ViewGroup) {
|
||||||
|
ViewGroup.LayoutParams vplp = new ViewGroup.LayoutParams(-1, statusBarViewHeight);
|
||||||
|
statusBarView.setLayoutParams(vplp);
|
||||||
|
}
|
||||||
|
|
||||||
|
statusBarView.setVisibility(View.VISIBLE);
|
||||||
|
statusBarView.setBackgroundColor(mStatusBarViewBG);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化view之前
|
||||||
|
*/
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化加载界面
|
||||||
|
*/
|
||||||
|
private void initLoadingView(View mainView) {
|
||||||
|
mLoadingContainer = mainView.findViewById(R.id.viewstub_loading_container);
|
||||||
|
mLoadingContainer.inflate();
|
||||||
|
mLoadImgView = mainView.findViewById(R.id.load_img);
|
||||||
|
rotateAnimation = AnimationUtils.loadAnimation(getContext(),
|
||||||
|
R.anim.anim_rotate);
|
||||||
|
rotateAnimation.setInterpolator(new LinearInterpolator());// 匀速
|
||||||
|
mLoadImgView.startAnimation(rotateAnimation);
|
||||||
|
//mLoadingContainer.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示加载窗口
|
||||||
|
*/
|
||||||
|
public void showLoadingView() {
|
||||||
|
mUIHandler.sendEmptyMessage(SHOWLOADINGVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示加载窗口
|
||||||
|
*/
|
||||||
|
private void showLoadingViewHandler() {
|
||||||
|
if (mNetContainer != null)
|
||||||
|
mNetContainer.setVisibility(View.GONE);
|
||||||
|
mContentContainer.setVisibility(View.GONE);
|
||||||
|
if (mLoadingContainer != null) {
|
||||||
|
mLoadingContainer.setVisibility(View.VISIBLE);
|
||||||
|
mLoadImgView.clearAnimation();
|
||||||
|
mLoadImgView.startAnimation(rotateAnimation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化没网络界面
|
||||||
|
*/
|
||||||
|
private void initNoNetView(View mainView) {
|
||||||
|
//
|
||||||
|
mNetContainer = mainView.findViewById(R.id.viewstub_net_container);
|
||||||
|
mNetContainer.inflate();
|
||||||
|
mNetBGLayout = mainView.findViewById(R.id.net_layout);
|
||||||
|
mNetBGLayout.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mRefreshListener != null) {
|
||||||
|
mRefreshListener.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mNetContainer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示无网络界面
|
||||||
|
*/
|
||||||
|
public void showNoNetView() {
|
||||||
|
mUIHandler.sendEmptyMessage(SHOWNONETVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示无网络界面
|
||||||
|
*/
|
||||||
|
private void showNoNetViewHandler() {
|
||||||
|
mContentContainer.setVisibility(View.GONE);
|
||||||
|
if (mLoadingContainer != null) {
|
||||||
|
mLoadingContainer.setVisibility(View.GONE);
|
||||||
|
mLoadImgView.clearAnimation();
|
||||||
|
}
|
||||||
|
if (mNetContainer != null)
|
||||||
|
mNetContainer.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示主界面
|
||||||
|
*/
|
||||||
|
public void showContentView() {
|
||||||
|
mUIHandler.sendEmptyMessage(SHOWCONTENTVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示主界面
|
||||||
|
*/
|
||||||
|
private void showContentViewHandler() {
|
||||||
|
mContentContainer.setVisibility(View.VISIBLE);
|
||||||
|
if (mLoadingContainer != null) {
|
||||||
|
mLoadingContainer.setVisibility(View.GONE);
|
||||||
|
mLoadImgView.clearAnimation();
|
||||||
|
}
|
||||||
|
if (mNetContainer != null)
|
||||||
|
mNetContainer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddStatusBarView(boolean addStatusBarView) {
|
||||||
|
isAddStatusBarView = addStatusBarView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置状态栏背景颜色
|
||||||
|
*
|
||||||
|
* @param statusBarViewBG
|
||||||
|
*/
|
||||||
|
public void setStatusBarViewBG(int statusBarViewBG) {
|
||||||
|
this.mStatusBarViewBG = statusBarViewBG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitleViewId(int mTitleViewId) {
|
||||||
|
this.mTitleViewId = mTitleViewId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||||
|
super.setUserVisibleHint(isVisibleToUser);
|
||||||
|
if (!mIsFristVisibleToUser && getUserVisibleHint() && getView() != null) {
|
||||||
|
mIsFristVisibleToUser = true;
|
||||||
|
isFristVisibleToUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视图可见,只执行一次
|
||||||
|
*/
|
||||||
|
protected abstract void isFristVisibleToUser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置主界面内容视图
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected abstract int setContentLayoutResID();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化view视图
|
||||||
|
*
|
||||||
|
* @param savedInstanceState
|
||||||
|
*/
|
||||||
|
protected abstract void initViews(View mainView, Bundle savedInstanceState);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理UI
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
protected abstract void handleUIMessage(Message msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理子线程worker
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
protected abstract void handleWorkerMessage(Message msg);
|
||||||
|
|
||||||
|
|
||||||
|
public interface RefreshListener {
|
||||||
|
void refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefreshListener(RefreshListener mRefreshListener) {
|
||||||
|
this.mRefreshListener = mRefreshListener;
|
||||||
|
}
|
||||||
|
}
|
||||||
213
app/src/main/java/com/zlm/hp/fragment/DownloadMusicFragment.java
Normal file
213
app/src/main/java/com/zlm/hp/fragment/DownloadMusicFragment.java
Normal file
|
|
@ -0,0 +1,213 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.hp.adapter.DownloadMusicAdapter;
|
||||||
|
import com.zlm.hp.db.util.AudioInfoDB;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.Category;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.receiver.FragmentReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 下载音乐
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-17 21:17
|
||||||
|
**/
|
||||||
|
public class DownloadMusicFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载数据
|
||||||
|
*/
|
||||||
|
private final int MESSAGE_WHAT_LOADDATA = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表视图
|
||||||
|
*/
|
||||||
|
private RecyclerView mRecyclerView;
|
||||||
|
private DownloadMusicAdapter mAdapter;
|
||||||
|
/**
|
||||||
|
* 分类数据
|
||||||
|
*/
|
||||||
|
private ArrayList<Category> mDatas;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频广播
|
||||||
|
*/
|
||||||
|
private AudioBroadcastReceiver mAudioBroadcastReceiver;
|
||||||
|
|
||||||
|
public DownloadMusicFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
mWorkerHandler.sendEmptyMessageDelayed(MESSAGE_WHAT_LOADDATA, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static DownloadMusicFragment newInstance() {
|
||||||
|
DownloadMusicFragment fragment = new DownloadMusicFragment();
|
||||||
|
return fragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_download;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
initView(mainView);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView(View mainView) {
|
||||||
|
//显示标题视图
|
||||||
|
LinearLayout titleLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
titleLL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
TextView titleView = mainView.findViewById(R.id.title);
|
||||||
|
titleView.setText(getString(R.string.tab_download));
|
||||||
|
//返回
|
||||||
|
ImageView backImg = mainView.findViewById(R.id.backImg);
|
||||||
|
backImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
FragmentReceiver.sendReceiver(mContext, FragmentReceiver.ACTION_CODE_CLOSE_FRAGMENT, null, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//
|
||||||
|
mRecyclerView = mainView.findViewById(R.id.recyclerView);
|
||||||
|
//初始化内容视图
|
||||||
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
|
||||||
|
|
||||||
|
//广播
|
||||||
|
mAudioBroadcastReceiver = new AudioBroadcastReceiver();
|
||||||
|
mAudioBroadcastReceiver.setReceiverListener(new AudioBroadcastReceiver.AudioReceiverListener() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, final Intent intent, final int code) {
|
||||||
|
mUIHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleAudioBroadcastReceiver(intent, code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAudioBroadcastReceiver(Intent intent, int code) {
|
||||||
|
switch (code) {
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_NULL:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_INIT:
|
||||||
|
|
||||||
|
if (mAdapter != null) {
|
||||||
|
Bundle initBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
if (initBundle == null) {
|
||||||
|
mAdapter.reshViewHolder(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AudioInfo initAudioInfo = initBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
mAdapter.reshViewHolder(initAudioInfo.getHash());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_DOWNLOAD:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_CANCEL:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_FINISH:
|
||||||
|
//重新加载数据
|
||||||
|
mWorkerHandler.sendEmptyMessageDelayed(MESSAGE_WHAT_LOADDATA, 500);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_SONG:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_WAIT:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_ERROR:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_PAUSE:
|
||||||
|
//网络歌曲下载
|
||||||
|
Bundle downloadBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
DownloadTask downloadTask = downloadBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
String downloadHash = downloadTask.getTaskId();
|
||||||
|
if (downloadTask != null && !TextUtils.isEmpty(downloadHash)) {
|
||||||
|
if (mAdapter != null)
|
||||||
|
mAdapter.reshViewHolder(downloadHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mAudioBroadcastReceiver.registerReceiver(mContext);
|
||||||
|
//
|
||||||
|
mDatas = new ArrayList<Category>();
|
||||||
|
mAdapter = new DownloadMusicAdapter(mContext, mDatas);
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case MESSAGE_WHAT_LOADDATA:
|
||||||
|
|
||||||
|
if (mDatas != null) {
|
||||||
|
mAdapter.resetMenuOpenIndex();
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
showContentView();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case MESSAGE_WHAT_LOADDATA:
|
||||||
|
if (mDatas != null) {
|
||||||
|
mDatas.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//下载中
|
||||||
|
Category category = new Category();
|
||||||
|
category.setCategoryName(getString(R.string.downloading_text));
|
||||||
|
List<AudioInfo> downloadInfos = AudioInfoDB.getDownloadingAudios(mContext);
|
||||||
|
category.setCategoryItem(downloadInfos);
|
||||||
|
mDatas.add(category);
|
||||||
|
|
||||||
|
//下载完成
|
||||||
|
category = new Category();
|
||||||
|
category.setCategoryName(getString(R.string.downloaded_text));
|
||||||
|
downloadInfos = AudioInfoDB.getDownloadedAudios(mContext);
|
||||||
|
category.setCategoryItem(downloadInfos);
|
||||||
|
mDatas.add(category);
|
||||||
|
//
|
||||||
|
mUIHandler.sendEmptyMessage(MESSAGE_WHAT_LOADDATA);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
if (mAudioBroadcastReceiver != null) {
|
||||||
|
mAudioBroadcastReceiver.unregisterReceiver(mContext);
|
||||||
|
}
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
}
|
||||||
278
app/src/main/java/com/zlm/hp/fragment/LastSongFragment.java
Normal file
278
app/src/main/java/com/zlm/hp/fragment/LastSongFragment.java
Normal file
|
|
@ -0,0 +1,278 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.github.jdsjlzx.interfaces.OnRefreshListener;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerView;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.hp.adapter.AudioAdapter;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.http.APIHttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新歌
|
||||||
|
* Created by zhangliangming on 2018-08-11.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class LastSongFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private LRecyclerView mRecyclerView;
|
||||||
|
|
||||||
|
private LRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频广播
|
||||||
|
*/
|
||||||
|
private AudioBroadcastReceiver mAudioBroadcastReceiver;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private ArrayList<AudioInfo> mDatas;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private final int LOADREFRESHDATA = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载更多数据
|
||||||
|
*/
|
||||||
|
private final int LOADMOREDATA = 1;
|
||||||
|
|
||||||
|
private int mPage = 1;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private int mPageSize = 20;
|
||||||
|
|
||||||
|
|
||||||
|
public LastSongFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static LastSongFragment newInstance() {
|
||||||
|
LastSongFragment fragment = new LastSongFragment();
|
||||||
|
return fragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setAddStatusBarView(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_last_song;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
initView(mainView);
|
||||||
|
showLoadingView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mainView
|
||||||
|
*/
|
||||||
|
private void initView(View mainView) {
|
||||||
|
mRecyclerView = mainView.findViewById(R.id.recyclerView);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||||
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||||
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
//
|
||||||
|
mDatas = new ArrayList<AudioInfo>();
|
||||||
|
mAdapter = new LRecyclerViewAdapter(new AudioAdapter(mContext, mDatas, SongFragment.SONG_TYPE_LAST));
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
mRecyclerView.setLoadMoreEnabled(false);
|
||||||
|
|
||||||
|
mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
//refresh data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
setRefreshListener(new RefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
showLoadingView();
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//音频广播
|
||||||
|
mAudioBroadcastReceiver = new AudioBroadcastReceiver();
|
||||||
|
mAudioBroadcastReceiver.setReceiverListener(new AudioBroadcastReceiver.AudioReceiverListener() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, final Intent intent, final int code) {
|
||||||
|
mUIHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleAudioBroadcastReceiver(intent, code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAudioBroadcastReceiver(Intent intent, int code) {
|
||||||
|
switch (code) {
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_NULL:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_INIT:
|
||||||
|
|
||||||
|
if (mAdapter != null) {
|
||||||
|
Bundle initBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
if (initBundle == null) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AudioInfo initAudioInfo = initBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(initAudioInfo.getHash());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_LIKE:
|
||||||
|
|
||||||
|
//喜欢/不喜欢
|
||||||
|
Bundle likeBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
String likeHash = likeBundle.getString(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
if (!TextUtils.isEmpty(likeHash)) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(likeHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_FINISH:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOADONEDLINESONG:
|
||||||
|
if (mAdapter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//网络歌曲下载完成
|
||||||
|
Bundle downloadedBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
DownloadTask downloadedTask = downloadedBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
String downloadedHash = downloadedTask.getTaskId();
|
||||||
|
if (downloadedTask != null && !TextUtils.isEmpty(downloadedHash)) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(downloadedHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mAudioBroadcastReceiver.registerReceiver(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
handleLoadData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadData(HttpReturnResult httpReturnResult) {
|
||||||
|
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.refreshComplete(0);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
} else {
|
||||||
|
mDatas.clear();
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<AudioInfo> lists = (List<AudioInfo>) returnResult.get("rows");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).resetMenuOpenIndex();
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
mRecyclerView.setLoadMoreEnabled(false);
|
||||||
|
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
loadRefreshData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private void loadRefreshData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
HttpReturnResult httpReturnResult = apiHttpClient.lastSongList(mContext, configInfo.isWifi());
|
||||||
|
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADREFRESHDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
if (mAudioBroadcastReceiver != null)
|
||||||
|
mAudioBroadcastReceiver.unregisterReceiver(mContext);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
495
app/src/main/java/com/zlm/hp/fragment/LrcFragment.java
Normal file
495
app/src/main/java/com/zlm/hp/fragment/LrcFragment.java
Normal file
|
|
@ -0,0 +1,495 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.constants.ResourceConstants;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.LrcInfo;
|
||||||
|
import com.zlm.hp.http.APIHttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.lyrics.LyricsReader;
|
||||||
|
import com.zlm.hp.lyrics.widget.AbstractLrcView;
|
||||||
|
import com.zlm.hp.lyrics.widget.ManyLyricsView;
|
||||||
|
import com.zlm.hp.manager.AudioPlayerManager;
|
||||||
|
import com.zlm.hp.manager.LyricsManager;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.ColorUtil;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
import com.zlm.hp.util.ImageUtil;
|
||||||
|
import com.zlm.hp.util.ResourceUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.widget.ButtonRelativeLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌词
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-11-24 22:45
|
||||||
|
**/
|
||||||
|
public class LrcFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String LRC_DATA_KEY = "lrcDataKey";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final String AUDIO_DATA_KEY = "audioDataKey";
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private boolean isFristINVisibleToUser = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private AudioInfo mAudioInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词数据
|
||||||
|
*/
|
||||||
|
private LrcInfo mLrcInfo;
|
||||||
|
|
||||||
|
private ConfigInfo mConfigInfo;
|
||||||
|
|
||||||
|
//多行歌词
|
||||||
|
private ManyLyricsView mManyLineLyricsView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用歌词按钮
|
||||||
|
*/
|
||||||
|
private ButtonRelativeLayout mUseBtn;
|
||||||
|
|
||||||
|
private final int MESSAGE_WHAT_LOADDATA = 0;
|
||||||
|
|
||||||
|
//、、、、、、、、、、、、、、、、、、、、、、、、、翻译和音译歌词、、、、、、、、、、、、、、、、、、、、、、、、、、、
|
||||||
|
//翻译歌词
|
||||||
|
private ImageView hideTranslateImg;
|
||||||
|
private ImageView showTranslateImg;
|
||||||
|
//音译歌词
|
||||||
|
private ImageView hideTransliterationImg;
|
||||||
|
private ImageView showTransliterationImg;
|
||||||
|
|
||||||
|
//翻译歌词/音译歌词
|
||||||
|
private ImageView showTTToTranslateImg;
|
||||||
|
private ImageView showTTToTransliterationImg;
|
||||||
|
private ImageView hideTTImg;
|
||||||
|
|
||||||
|
private final int HASTRANSLATELRC = 0;
|
||||||
|
private final int HASTRANSLITERATIONLRC = 1;
|
||||||
|
private final int HASTRANSLATEANDTRANSLITERATIONLRC = 2;
|
||||||
|
private final int NOEXTRALRC = 3;
|
||||||
|
|
||||||
|
private Handler mExtraLrcTypeHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
switch (msg.what) {
|
||||||
|
case NOEXTRALRC:
|
||||||
|
|
||||||
|
//翻译歌词
|
||||||
|
hideTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
//音译歌词
|
||||||
|
hideTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
//翻译歌词/音译歌词
|
||||||
|
showTTToTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTTToTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
hideTTImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
case HASTRANSLATEANDTRANSLITERATIONLRC:
|
||||||
|
|
||||||
|
|
||||||
|
//翻译歌词
|
||||||
|
hideTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
//音译歌词
|
||||||
|
hideTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
//翻译歌词/音译歌词
|
||||||
|
showTTToTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTTToTransliterationImg.setVisibility(View.VISIBLE);
|
||||||
|
hideTTImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLATELRC);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case HASTRANSLITERATIONLRC:
|
||||||
|
|
||||||
|
//翻译歌词
|
||||||
|
hideTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
//音译歌词
|
||||||
|
hideTransliterationImg.setVisibility(View.VISIBLE);
|
||||||
|
showTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
//翻译歌词/音译歌词
|
||||||
|
showTTToTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTTToTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
hideTTImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLITERATIONLRC);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case HASTRANSLATELRC:
|
||||||
|
|
||||||
|
//翻译歌词
|
||||||
|
hideTranslateImg.setVisibility(View.VISIBLE);
|
||||||
|
showTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
//音译歌词
|
||||||
|
hideTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
//翻译歌词/音译歌词
|
||||||
|
showTTToTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTTToTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
hideTTImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLATELRC);
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public LrcFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LrcFragment newInstance(AudioInfo audioInfo, LrcInfo lrcInfo) {
|
||||||
|
LrcFragment fragment = new LrcFragment();
|
||||||
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(AUDIO_DATA_KEY, audioInfo);
|
||||||
|
bundle.putParcelable(LRC_DATA_KEY, lrcInfo);
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
//添加状态栏
|
||||||
|
setAddStatusBarView(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||||
|
super.setUserVisibleHint(isVisibleToUser);
|
||||||
|
if (mUIHandler != null && !getUserVisibleHint() && !isFristINVisibleToUser) {
|
||||||
|
isFristINVisibleToUser = true;
|
||||||
|
mUIHandler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mAudioInfo != null) {
|
||||||
|
AudioInfo audioInfo = AudioPlayerManager.newInstance(mContext).getCurSong(mConfigInfo.getPlayHash());
|
||||||
|
if (audioInfo == null) {
|
||||||
|
refreshView((int) mAudioInfo.getDuration());
|
||||||
|
} else if (mAudioInfo.getHash().equals(audioInfo.getHash())) {
|
||||||
|
refreshView((int) audioInfo.getPlayProgress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
} else if (getUserVisibleHint()) {
|
||||||
|
isFristINVisibleToUser = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
initData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initData() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(MESSAGE_WHAT_LOADDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_lrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
if (getArguments() != null) {
|
||||||
|
mAudioInfo = getArguments().getParcelable(AUDIO_DATA_KEY);
|
||||||
|
mLrcInfo = getArguments().getParcelable(LRC_DATA_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
isFristINVisibleToUser = false;
|
||||||
|
mConfigInfo = ConfigInfo.obtain();
|
||||||
|
|
||||||
|
//歌词视图
|
||||||
|
mManyLineLyricsView = mainView.findViewById(R.id.lrcview);
|
||||||
|
mManyLineLyricsView.setSize(mConfigInfo.getLrcFontSize(), mConfigInfo.getLrcFontSize(), false);
|
||||||
|
mManyLineLyricsView.setPaintColor(new int[]{ColorUtil.parserColor("#888888"), ColorUtil.parserColor("#888888")}, false);
|
||||||
|
mManyLineLyricsView.setPaintHLColor(new int[]{ColorUtil.parserColor("#0288d1"), ColorUtil.parserColor("#0288d1")}, false);
|
||||||
|
mManyLineLyricsView.setIsDrawIndicator(false);
|
||||||
|
|
||||||
|
//翻译歌词
|
||||||
|
hideTranslateImg = mainView.findViewById(R.id.hideTranslateImg);
|
||||||
|
ImageUtil.getTranslateColorImg(mContext, hideTranslateImg, R.mipmap.bql, ColorUtil.parserColor("#0288d1"));
|
||||||
|
|
||||||
|
hideTranslateImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
hideTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTranslateImg.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_NOSHOWEXTRALRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showTranslateImg = mainView.findViewById(R.id.showTranslateImg);
|
||||||
|
ImageUtil.getTranslateColorImg(mContext, showTranslateImg, R.mipmap.bqm, ColorUtil.parserColor("#0288d1"));
|
||||||
|
|
||||||
|
|
||||||
|
showTranslateImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
hideTranslateImg.setVisibility(View.VISIBLE);
|
||||||
|
showTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLATELRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//音译歌词
|
||||||
|
hideTransliterationImg = mainView.findViewById(R.id.hideTransliterationImg);
|
||||||
|
ImageUtil.getTranslateColorImg(mContext, hideTransliterationImg, R.mipmap.bqn, ColorUtil.parserColor("#0288d1"));
|
||||||
|
|
||||||
|
|
||||||
|
hideTransliterationImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
hideTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTransliterationImg.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_NOSHOWEXTRALRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showTransliterationImg = mainView.findViewById(R.id.showTransliterationImg);
|
||||||
|
ImageUtil.getTranslateColorImg(mContext, showTransliterationImg, R.mipmap.bqo, ColorUtil.parserColor("#0288d1"));
|
||||||
|
|
||||||
|
|
||||||
|
showTransliterationImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
hideTransliterationImg.setVisibility(View.VISIBLE);
|
||||||
|
showTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLITERATIONLRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//翻译歌词/音译歌词
|
||||||
|
showTTToTranslateImg = mainView.findViewById(R.id.showTTToTranslateImg);
|
||||||
|
ImageUtil.getTranslateColorImg(mContext, showTTToTranslateImg, R.mipmap.bqi, ColorUtil.parserColor("#0288d1"));
|
||||||
|
|
||||||
|
|
||||||
|
showTTToTranslateImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
showTTToTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTTToTransliterationImg.setVisibility(View.VISIBLE);
|
||||||
|
hideTTImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLATELRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showTTToTransliterationImg = mainView.findViewById(R.id.showTTToTransliterationImg);
|
||||||
|
ImageUtil.getTranslateColorImg(mContext, showTTToTransliterationImg, R.mipmap.bqj, ColorUtil.parserColor("#0288d1"));
|
||||||
|
|
||||||
|
|
||||||
|
showTTToTransliterationImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
showTTToTranslateImg.setVisibility(View.INVISIBLE);
|
||||||
|
showTTToTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
hideTTImg.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLITERATIONLRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
hideTTImg = mainView.findViewById(R.id.hideTTImg);
|
||||||
|
ImageUtil.getTranslateColorImg(mContext, hideTTImg, R.mipmap.bqk, ColorUtil.parserColor("#0288d1"));
|
||||||
|
|
||||||
|
hideTTImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
showTTToTranslateImg.setVisibility(View.VISIBLE);
|
||||||
|
showTTToTransliterationImg.setVisibility(View.INVISIBLE);
|
||||||
|
hideTTImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLineLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_NOSHOWEXTRALRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
mManyLineLyricsView.setExtraLyricsListener(new AbstractLrcView.ExtraLyricsListener() {
|
||||||
|
@Override
|
||||||
|
public void extraLrcCallback() {
|
||||||
|
int extraLrcType = mManyLineLyricsView.getExtraLrcType();
|
||||||
|
if (extraLrcType == AbstractLrcView.EXTRALRCTYPE_NOLRC) {
|
||||||
|
mExtraLrcTypeHandler.sendEmptyMessage(NOEXTRALRC);
|
||||||
|
} else if (extraLrcType == AbstractLrcView.EXTRALRCTYPE_TRANSLATELRC) {
|
||||||
|
mExtraLrcTypeHandler.sendEmptyMessage(HASTRANSLATELRC);
|
||||||
|
} else if (extraLrcType == AbstractLrcView.EXTRALRCTYPE_TRANSLITERATIONLRC) {
|
||||||
|
mExtraLrcTypeHandler.sendEmptyMessage(HASTRANSLITERATIONLRC);
|
||||||
|
} else if (extraLrcType == AbstractLrcView.EXTRALRCTYPE_BOTH) {
|
||||||
|
mExtraLrcTypeHandler.sendEmptyMessage(HASTRANSLATEANDTRANSLITERATIONLRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//使用歌词按钮
|
||||||
|
mUseBtn = mainView.findViewById(R.id.uselrcbtn);
|
||||||
|
mUseBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mAudioInfo != null && mManyLineLyricsView != null && mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
|
||||||
|
String hash = mAudioInfo.getHash();
|
||||||
|
|
||||||
|
//使用歌词加载中
|
||||||
|
AudioBroadcastReceiver.sendLrcReLoadingReceiver(mContext, hash);
|
||||||
|
|
||||||
|
//歌词文件名
|
||||||
|
String fileName = mAudioInfo.getTitle();
|
||||||
|
String lrcFilePath = ResourceUtil.getFilePath(mContext, ResourceConstants.PATH_LYRICS, fileName + ".krc");
|
||||||
|
mManyLineLyricsView.getLyricsReader().setLrcFilePath(lrcFilePath);
|
||||||
|
LyricsManager.newInstance(mContext).setLyricsReader(hash, mManyLineLyricsView.getLyricsReader());
|
||||||
|
|
||||||
|
//发送使用歌词广播
|
||||||
|
AudioBroadcastReceiver.sendLrcReLoadedReceiver(mContext, hash);
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.setting_song_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
showLoadingView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新view
|
||||||
|
*
|
||||||
|
* @param playProgress
|
||||||
|
*/
|
||||||
|
public void refreshView(int playProgress) {
|
||||||
|
boolean isPlay = getUserVisibleHint();
|
||||||
|
if (mManyLineLyricsView != null) {
|
||||||
|
if (mManyLineLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
if (isPlay) {
|
||||||
|
if (mManyLineLyricsView.getLrcPlayerStatus() != AbstractLrcView.LRCPLAYERSTATUS_PLAY) {
|
||||||
|
mManyLineLyricsView.play(playProgress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mManyLineLyricsView.getLrcPlayerStatus() == AbstractLrcView.LRCPLAYERSTATUS_PLAY) {
|
||||||
|
mManyLineLyricsView.pause();
|
||||||
|
}
|
||||||
|
if (mManyLineLyricsView.getLrcPlayerStatus() != AbstractLrcView.LRCPLAYERSTATUS_SEEKTO) {
|
||||||
|
mManyLineLyricsView.seekto(playProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case MESSAGE_WHAT_LOADDATA:
|
||||||
|
if (msg.obj != null && msg.obj instanceof LrcInfo) {
|
||||||
|
LrcInfo lrcInfo = (LrcInfo) msg.obj;
|
||||||
|
if (mAudioInfo != null && mManyLineLyricsView.getLyricsReader() == null) {
|
||||||
|
String hash = mAudioInfo.getHash();
|
||||||
|
//歌词文件名
|
||||||
|
String fileName = mAudioInfo.getTitle();
|
||||||
|
String lrcFilePath = ResourceUtil.getFilePath(mContext, ResourceConstants.PATH_LYRICS, fileName + ".krc");
|
||||||
|
//
|
||||||
|
LyricsReader lyricsReader = new LyricsReader();
|
||||||
|
lyricsReader.setHash(hash);
|
||||||
|
lyricsReader.loadLrc(lrcInfo.getContent(), null, lrcFilePath);
|
||||||
|
mManyLineLyricsView.setLyricsReader(lyricsReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showContentView();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case MESSAGE_WHAT_LOADDATA:
|
||||||
|
|
||||||
|
Message nMsg = Message.obtain();
|
||||||
|
nMsg.what = MESSAGE_WHAT_LOADDATA;
|
||||||
|
|
||||||
|
|
||||||
|
if (mAudioInfo != null && mManyLineLyricsView.getLyricsReader() == null) {
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
HttpReturnResult httpReturnResult = apiHttpClient.getLyricsInfo(mContext, mLrcInfo.getId(), mLrcInfo.getAccesskey(), mConfigInfo.isWifi());
|
||||||
|
if (httpReturnResult.isSuccessful()) {
|
||||||
|
LrcInfo lrcInfo = (LrcInfo) httpReturnResult.getResult();
|
||||||
|
nMsg.obj = lrcInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mUIHandler.sendMessage(nMsg);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
if (mManyLineLyricsView != null) {
|
||||||
|
mManyLineLyricsView.release();
|
||||||
|
}
|
||||||
|
System.gc();
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
288
app/src/main/java/com/zlm/hp/fragment/MeFragment.java
Normal file
288
app/src/main/java/com/zlm/hp/fragment/MeFragment.java
Normal file
|
|
@ -0,0 +1,288 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.zlm.hp.db.util.AudioInfoDB;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.receiver.FragmentReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by zhangliangming on 2018-08-11.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MeFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地音乐
|
||||||
|
*/
|
||||||
|
private LinearLayout mLocalMusicLL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地音乐个数
|
||||||
|
*/
|
||||||
|
private TextView mLocalCountTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载本地歌曲的个数
|
||||||
|
*/
|
||||||
|
private final int LOAD_LOCAL_AUDIO_COUNT = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 喜欢音乐
|
||||||
|
*/
|
||||||
|
private LinearLayout mLikeMusicLL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 喜欢音乐个数
|
||||||
|
*/
|
||||||
|
private TextView mLikeCountTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载喜欢歌曲的个数
|
||||||
|
*/
|
||||||
|
private final int LOAD_LIKE_AUDIO_COUNT = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近音乐
|
||||||
|
*/
|
||||||
|
private LinearLayout mRecentMusicLL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近音乐个数
|
||||||
|
*/
|
||||||
|
private TextView mRecentCountTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载最近歌曲的个数
|
||||||
|
*/
|
||||||
|
private final int LOAD_RECENT_AUDIO_COUNT = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
*/
|
||||||
|
private LinearLayout mDownloadMusicLL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载音乐个数
|
||||||
|
*/
|
||||||
|
private TextView mDownloadCountTv;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载下载歌曲的个数
|
||||||
|
*/
|
||||||
|
private final int LOAD_DOWNLOAD_AUDIO_COUNT = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频广播
|
||||||
|
*/
|
||||||
|
private AudioBroadcastReceiver mAudioBroadcastReceiver;
|
||||||
|
|
||||||
|
public MeFragment() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static MeFragment newInstance() {
|
||||||
|
MeFragment fragment = new MeFragment();
|
||||||
|
return fragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadData() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_LOCAL_AUDIO_COUNT);
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_LIKE_AUDIO_COUNT);
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_RECENT_AUDIO_COUNT);
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_DOWNLOAD_AUDIO_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setAddStatusBarView(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_me;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
initViews(mainView);
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initViews(View mainView) {
|
||||||
|
|
||||||
|
//本地音乐
|
||||||
|
mLocalMusicLL = mainView.findViewById(R.id.tab_local_music);
|
||||||
|
mLocalMusicLL.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
FragmentReceiver.sendLocalFragmentReceiver(mContext, getString(R.string.tab_localmusic));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mLocalCountTv = mainView.findViewById(R.id.local_music_count);
|
||||||
|
|
||||||
|
//喜欢音乐
|
||||||
|
mLikeMusicLL = mainView.findViewById(R.id.tab_like_music);
|
||||||
|
mLikeMusicLL.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
FragmentReceiver.sendLikeFragmentReceiver(mContext, getString(R.string.tab_like));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mLikeCountTv = mainView.findViewById(R.id.like_music_count);
|
||||||
|
|
||||||
|
//最近音乐
|
||||||
|
mRecentMusicLL = mainView.findViewById(R.id.tab_recent_music);
|
||||||
|
mRecentMusicLL.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
FragmentReceiver.sendRecentFragmentReceiver(mContext, getString(R.string.tab_recent));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mRecentCountTv = mainView.findViewById(R.id.recent_music_count);
|
||||||
|
|
||||||
|
//下载音乐
|
||||||
|
mDownloadMusicLL = mainView.findViewById(R.id.tab_download_music);
|
||||||
|
mDownloadMusicLL.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
FragmentReceiver.sendDownloadFragmentReceiver(mContext);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mDownloadCountTv = mainView.findViewById(R.id.download_music_count);
|
||||||
|
|
||||||
|
//广播
|
||||||
|
mAudioBroadcastReceiver = new AudioBroadcastReceiver();
|
||||||
|
mAudioBroadcastReceiver.setReceiverListener(new AudioBroadcastReceiver.AudioReceiverListener() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, final Intent intent, final int code) {
|
||||||
|
mUIHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleAudioBroadcastReceiver(intent, code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAudioBroadcastReceiver(Intent intent, int code) {
|
||||||
|
switch (code) {
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_RECENT:
|
||||||
|
//最近歌曲更新
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_RECENT_AUDIO_COUNT);
|
||||||
|
break;
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_LOCAL:
|
||||||
|
//本地歌曲更新
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_LOCAL_AUDIO_COUNT);
|
||||||
|
break;
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_LIKE:
|
||||||
|
//喜欢歌曲更新
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_LIKE_AUDIO_COUNT);
|
||||||
|
break;
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_DOWNLOAD:
|
||||||
|
|
||||||
|
//下载歌曲更新
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOAD_DOWNLOAD_AUDIO_COUNT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mAudioBroadcastReceiver.registerReceiver(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOAD_LOCAL_AUDIO_COUNT:
|
||||||
|
|
||||||
|
int localCount = (int) msg.obj;
|
||||||
|
mLocalCountTv.setText(localCount + "");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOAD_LIKE_AUDIO_COUNT:
|
||||||
|
|
||||||
|
int likeCount = (int) msg.obj;
|
||||||
|
mLikeCountTv.setText(likeCount + "");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOAD_RECENT_AUDIO_COUNT:
|
||||||
|
|
||||||
|
int recentCount = (int) msg.obj;
|
||||||
|
mRecentCountTv.setText(recentCount + "");
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOAD_DOWNLOAD_AUDIO_COUNT:
|
||||||
|
|
||||||
|
int downloadCount = (int) msg.obj;
|
||||||
|
mDownloadCountTv.setText(downloadCount + "");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOAD_LOCAL_AUDIO_COUNT:
|
||||||
|
|
||||||
|
int localCount = AudioInfoDB.getLocalAudioCount(mContext);
|
||||||
|
Message localMsg = Message.obtain();
|
||||||
|
localMsg.what = LOAD_LOCAL_AUDIO_COUNT;
|
||||||
|
localMsg.obj = localCount;
|
||||||
|
|
||||||
|
mUIHandler.sendMessage(localMsg);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOAD_LIKE_AUDIO_COUNT:
|
||||||
|
int likeCount = AudioInfoDB.getLikeAudioCount(mContext);
|
||||||
|
Message likeMsg = Message.obtain();
|
||||||
|
likeMsg.what = LOAD_LIKE_AUDIO_COUNT;
|
||||||
|
likeMsg.obj = likeCount;
|
||||||
|
|
||||||
|
mUIHandler.sendMessage(likeMsg);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOAD_RECENT_AUDIO_COUNT:
|
||||||
|
int recentCount = AudioInfoDB.getRecentAudioCount(mContext);
|
||||||
|
Message recentMsg = Message.obtain();
|
||||||
|
recentMsg.what = LOAD_RECENT_AUDIO_COUNT;
|
||||||
|
recentMsg.obj = recentCount;
|
||||||
|
|
||||||
|
mUIHandler.sendMessage(recentMsg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOAD_DOWNLOAD_AUDIO_COUNT:
|
||||||
|
int downloadCount = AudioInfoDB.getDownloadAudioCount(mContext);
|
||||||
|
Message downloadMsg = Message.obtain();
|
||||||
|
downloadMsg.what = LOAD_DOWNLOAD_AUDIO_COUNT;
|
||||||
|
downloadMsg.obj = downloadCount;
|
||||||
|
|
||||||
|
mUIHandler.sendMessage(downloadMsg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
if (mAudioBroadcastReceiver != null) {
|
||||||
|
mAudioBroadcastReceiver.unregisterReceiver(mContext);
|
||||||
|
}
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
}
|
||||||
186
app/src/main/java/com/zlm/hp/fragment/RecommendFragment.java
Normal file
186
app/src/main/java/com/zlm/hp/fragment/RecommendFragment.java
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.github.jdsjlzx.interfaces.OnRefreshListener;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerView;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
|
||||||
|
import com.zlm.hp.adapter.RecommendAdapter;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.entity.RankInfo;
|
||||||
|
import com.zlm.hp.http.APIHttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排行
|
||||||
|
* Created by zhangliangming on 2018-08-11.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RecommendFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private LRecyclerView mRecyclerView;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private LRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private ArrayList<RankInfo> mDatas;
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private final int LOADREFRESHDATA = 0;
|
||||||
|
|
||||||
|
public RecommendFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static RecommendFragment newInstance() {
|
||||||
|
RecommendFragment fragment = new RecommendFragment();
|
||||||
|
return fragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_recommend;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setAddStatusBarView(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
initView(mainView);
|
||||||
|
//showLoadingView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mainView
|
||||||
|
*/
|
||||||
|
private void initView(View mainView) {
|
||||||
|
mRecyclerView = mainView.findViewById(R.id.recyclerView);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||||
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||||
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
//
|
||||||
|
mDatas = new ArrayList<RankInfo>();
|
||||||
|
mAdapter = new LRecyclerViewAdapter(new RecommendAdapter(mUIHandler, mWorkerHandler, mContext, mDatas));
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
mRecyclerView.setLoadMoreEnabled(false);
|
||||||
|
|
||||||
|
mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
//refresh data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
setRefreshListener(new RefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
showLoadingView();
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
handleLoadData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadData(HttpReturnResult httpReturnResult) {
|
||||||
|
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.refreshComplete(0);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
} else {
|
||||||
|
mDatas.clear();
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<RankInfo> lists = (List<RankInfo>) returnResult.get("rows");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
mRecyclerView.setLoadMoreEnabled(false);
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
loadRefreshData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private void loadRefreshData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
HttpReturnResult httpReturnResult = apiHttpClient.rankList(mContext, configInfo.isWifi());
|
||||||
|
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADREFRESHDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
493
app/src/main/java/com/zlm/hp/fragment/SearchFragment.java
Normal file
493
app/src/main/java/com/zlm/hp/fragment/SearchFragment.java
Normal file
|
|
@ -0,0 +1,493 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
|
||||||
|
import com.github.jdsjlzx.interfaces.OnNetWorkErrorListener;
|
||||||
|
import com.github.jdsjlzx.interfaces.OnRefreshListener;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerView;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.hp.adapter.AudioAdapter;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.http.APIHttpClient;
|
||||||
|
import com.zlm.hp.http.HttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.receiver.FragmentReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
import com.zlm.hp.widget.SearchEditText;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 搜索
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-22 22:09
|
||||||
|
**/
|
||||||
|
public class SearchFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private LRecyclerView mRecyclerView;
|
||||||
|
|
||||||
|
private LRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索框
|
||||||
|
*/
|
||||||
|
private SearchEditText mSearchEditText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private ArrayList<AudioInfo> mDatas;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private final int LOADREFRESHDATA = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载更多数据
|
||||||
|
*/
|
||||||
|
private final int LOADMOREDATA = 1;
|
||||||
|
|
||||||
|
private int mPage = 1;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private int mPageSize = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频广播
|
||||||
|
*/
|
||||||
|
private AudioBroadcastReceiver mAudioBroadcastReceiver;
|
||||||
|
|
||||||
|
public SearchFragment() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static SearchFragment newInstance() {
|
||||||
|
SearchFragment fragment = new SearchFragment();
|
||||||
|
return fragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_search;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
//显示标题视图
|
||||||
|
LinearLayout titleLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
titleLL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
//返回
|
||||||
|
ImageView backImg = mainView.findViewById(R.id.backImg);
|
||||||
|
backImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
|
||||||
|
//关闭输入法
|
||||||
|
hideInput(mContext, mSearchEditText);
|
||||||
|
|
||||||
|
FragmentReceiver.sendReceiver(mContext, FragmentReceiver.ACTION_CODE_CLOSE_FRAGMENT, null, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//清除输入内容
|
||||||
|
final IconfontTextView clearBtn = mainView.findViewById(R.id.clean_img);
|
||||||
|
clearBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
mSearchEditText.setText("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//搜索按钮
|
||||||
|
TextView searchBtn = mainView.findViewById(R.id.right_flag);
|
||||||
|
searchBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
String searchKey = mSearchEditText.getText().toString();
|
||||||
|
if (searchKey == null || searchKey.equals("")) {
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.input_key));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
doSearch();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//搜索框
|
||||||
|
mSearchEditText = mainView.findViewById(R.id.search);
|
||||||
|
mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||||
|
String searchKey = mSearchEditText.getText().toString();
|
||||||
|
if (searchKey == null || searchKey.equals("")) {
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.input_key));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
doSearch();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mSearchEditText.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable editable) {
|
||||||
|
String searchKey = mSearchEditText.getText().toString();
|
||||||
|
if (searchKey == null || searchKey.equals("")) {
|
||||||
|
if (clearBtn.getVisibility() != View.INVISIBLE) {
|
||||||
|
clearBtn.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (clearBtn.getVisibility() != View.VISIBLE) {
|
||||||
|
clearBtn.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
mRecyclerView = mainView.findViewById(R.id.recyclerView);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||||
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||||
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
//
|
||||||
|
mDatas = new ArrayList<AudioInfo>();
|
||||||
|
mAdapter = new LRecyclerViewAdapter(new AudioAdapter(mContext, mDatas, SongFragment.SONG_TYPE_SEARCH));
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
|
||||||
|
mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
//refresh data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
|
||||||
|
@Override
|
||||||
|
public void onLoadMore() {
|
||||||
|
// load more data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADMOREDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//音频广播
|
||||||
|
mAudioBroadcastReceiver = new AudioBroadcastReceiver();
|
||||||
|
mAudioBroadcastReceiver.setReceiverListener(new AudioBroadcastReceiver.AudioReceiverListener() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, final Intent intent, final int code) {
|
||||||
|
mUIHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleAudioBroadcastReceiver(intent, code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAudioBroadcastReceiver(Intent intent, int code) {
|
||||||
|
switch (code) {
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_NULL:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_INIT:
|
||||||
|
|
||||||
|
if (mAdapter != null) {
|
||||||
|
Bundle initBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
if (initBundle == null) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AudioInfo initAudioInfo = initBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(initAudioInfo.getHash());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_LIKE:
|
||||||
|
|
||||||
|
//喜欢/不喜欢
|
||||||
|
Bundle likeBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
String likeHash = likeBundle.getString(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
if (!TextUtils.isEmpty(likeHash)) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(likeHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_FINISH:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOADONEDLINESONG:
|
||||||
|
if (mAdapter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//网络歌曲下载完成
|
||||||
|
Bundle downloadedBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
DownloadTask downloadedTask = downloadedBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
String downloadedHash = downloadedTask.getTaskId();
|
||||||
|
if (downloadedTask != null && !TextUtils.isEmpty(downloadedHash)) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(downloadedHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mAudioBroadcastReceiver.registerReceiver(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索
|
||||||
|
*/
|
||||||
|
private void doSearch() {
|
||||||
|
//关闭输入法
|
||||||
|
hideInput(mContext, mSearchEditText);
|
||||||
|
showLoadingView();
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强制隐藏输入法键盘
|
||||||
|
*
|
||||||
|
* @param context Context
|
||||||
|
* @param view EditText
|
||||||
|
*/
|
||||||
|
private void hideInput(Context context, View view) {
|
||||||
|
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setTitleViewId(R.layout.layout_search_title);
|
||||||
|
super.preInitStatusBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
handleLoadData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOADMOREDATA:
|
||||||
|
handleLoadMoreData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载更多数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadMoreData(HttpReturnResult httpReturnResult) {
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.setOnNetWorkErrorListener(new OnNetWorkErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADMOREDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mPage++;
|
||||||
|
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<AudioInfo> lists = (List<AudioInfo>) returnResult.get("rows");
|
||||||
|
int total = (int) returnResult.get("total");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
if (total <= mAdapter.getItemCount() || total == 0) {
|
||||||
|
mRecyclerView.setNoMore(true);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).resetMenuOpenIndex();
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadData(HttpReturnResult httpReturnResult) {
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.refreshComplete(0);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
} else {
|
||||||
|
mDatas.clear();
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<AudioInfo> lists = (List<AudioInfo>) returnResult.get("rows");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).resetMenuOpenIndex();
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
loadRefreshData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOADMOREDATA:
|
||||||
|
|
||||||
|
loadMoreData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载更多数据
|
||||||
|
*/
|
||||||
|
private void loadMoreData() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否有关键字
|
||||||
|
String searchKey = mSearchEditText.getText().toString();
|
||||||
|
HttpReturnResult httpReturnResult = null;
|
||||||
|
if (searchKey == null || searchKey.equals("")) {
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.input_key));
|
||||||
|
httpReturnResult = new HttpReturnResult();
|
||||||
|
httpReturnResult.setStatus(HttpClient.HTTP_OK);
|
||||||
|
List<AudioInfo> audioInfos = new ArrayList<AudioInfo>();
|
||||||
|
Map<String, Object> returnResult = new HashMap<String, Object>();
|
||||||
|
returnResult.put("rows", audioInfos);
|
||||||
|
httpReturnResult.setResult(returnResult);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
int page = mPage + 1;
|
||||||
|
httpReturnResult = apiHttpClient.searchSongList(mContext, searchKey, page, mPageSize, configInfo.isWifi());
|
||||||
|
}
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADMOREDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPage() {
|
||||||
|
mPage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private void loadRefreshData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
resetPage();
|
||||||
|
|
||||||
|
//判断是否有关键字
|
||||||
|
String searchKey = mSearchEditText.getText().toString();
|
||||||
|
HttpReturnResult httpReturnResult = null;
|
||||||
|
if (searchKey == null || searchKey.equals("")) {
|
||||||
|
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.input_key));
|
||||||
|
httpReturnResult = new HttpReturnResult();
|
||||||
|
httpReturnResult.setStatus(HttpClient.HTTP_OK);
|
||||||
|
List<AudioInfo> audioInfos = new ArrayList<AudioInfo>();
|
||||||
|
Map<String, Object> returnResult = new HashMap<String, Object>();
|
||||||
|
returnResult.put("rows", audioInfos);
|
||||||
|
httpReturnResult.setResult(returnResult);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
httpReturnResult = apiHttpClient.searchSongList(mContext, searchKey, mPage, mPageSize, configInfo.isWifi());
|
||||||
|
}
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADREFRESHDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
if (mAudioBroadcastReceiver != null)
|
||||||
|
mAudioBroadcastReceiver.unregisterReceiver(mContext);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
532
app/src/main/java/com/zlm/hp/fragment/SongFragment.java
Normal file
532
app/src/main/java/com/zlm/hp/fragment/SongFragment.java
Normal file
|
|
@ -0,0 +1,532 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
|
||||||
|
import com.github.jdsjlzx.interfaces.OnNetWorkErrorListener;
|
||||||
|
import com.github.jdsjlzx.interfaces.OnRefreshListener;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerView;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
|
||||||
|
import com.zlm.down.entity.DownloadTask;
|
||||||
|
import com.zlm.hp.adapter.AudioAdapter;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.db.util.AudioInfoDB;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.RankInfo;
|
||||||
|
import com.zlm.hp.entity.SpecialInfo;
|
||||||
|
import com.zlm.hp.http.APIHttpClient;
|
||||||
|
import com.zlm.hp.http.HttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.receiver.AudioBroadcastReceiver;
|
||||||
|
import com.zlm.hp.receiver.FragmentReceiver;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲
|
||||||
|
* Created by zhangliangming on 2018-08-11.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SongFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private LRecyclerView mRecyclerView;
|
||||||
|
|
||||||
|
private LRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音频广播
|
||||||
|
*/
|
||||||
|
private AudioBroadcastReceiver mAudioBroadcastReceiver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private ArrayList<AudioInfo> mDatas;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private final int LOADREFRESHDATA = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载更多数据
|
||||||
|
*/
|
||||||
|
private final int LOADMOREDATA = 1;
|
||||||
|
|
||||||
|
private int mPage = 1;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private int mPageSize = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌单
|
||||||
|
*/
|
||||||
|
public static final int SONG_TYPE_SPECIAL = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排行
|
||||||
|
*/
|
||||||
|
public static final int SONG_TYPE_RECOMMEND = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地
|
||||||
|
*/
|
||||||
|
public static final int SONG_TYPE_LOCAL = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最新
|
||||||
|
*/
|
||||||
|
public static final int SONG_TYPE_LAST = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 喜欢
|
||||||
|
*/
|
||||||
|
public static final int SONG_TYPE_LIKE = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最近
|
||||||
|
*/
|
||||||
|
public static final int SONG_TYPE_RECENT = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索
|
||||||
|
*/
|
||||||
|
public static final int SONG_TYPE_SEARCH = 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络歌曲类型
|
||||||
|
*/
|
||||||
|
private int mSongType = SONG_TYPE_RECOMMEND;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲类型key
|
||||||
|
*/
|
||||||
|
public static final String SONGTYPE_KEY = "SONGTYPE_KEY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data key
|
||||||
|
*/
|
||||||
|
public static final String DATA_KEY = "DATA_KEY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* arguments key
|
||||||
|
*/
|
||||||
|
public static final String ARGUMENTS_KEY = "ARGUMENTS_KEY";
|
||||||
|
|
||||||
|
public SongFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static SongFragment newInstance() {
|
||||||
|
SongFragment fragment = new SongFragment();
|
||||||
|
return fragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_song;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
initView(mainView);
|
||||||
|
//showLoadingView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mainView
|
||||||
|
*/
|
||||||
|
private void initView(View mainView) {
|
||||||
|
|
||||||
|
String title = getString(R.string.app_name);
|
||||||
|
Bundle bundle = getArguments();
|
||||||
|
if (bundle != null) {
|
||||||
|
mSongType = bundle.getInt(SONGTYPE_KEY, SONG_TYPE_RECOMMEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mRecyclerView = mainView.findViewById(R.id.recyclerView);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||||
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||||
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
//
|
||||||
|
mDatas = new ArrayList<AudioInfo>();
|
||||||
|
mAdapter = new LRecyclerViewAdapter(new AudioAdapter(mContext, mDatas, mSongType));
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
|
||||||
|
mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
//refresh data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
|
||||||
|
@Override
|
||||||
|
public void onLoadMore() {
|
||||||
|
// load more data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADMOREDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
setRefreshListener(new RefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
showLoadingView();
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
switch (mSongType) {
|
||||||
|
case SONG_TYPE_RECOMMEND:
|
||||||
|
|
||||||
|
RankInfo rankInfo = bundle.getParcelable(DATA_KEY);
|
||||||
|
title = rankInfo.getRankName();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SONG_TYPE_SPECIAL:
|
||||||
|
|
||||||
|
SpecialInfo specialInfo = bundle.getParcelable(DATA_KEY);
|
||||||
|
title = specialInfo.getSpecialName();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SONG_TYPE_LOCAL:
|
||||||
|
case SONG_TYPE_LIKE:
|
||||||
|
case SONG_TYPE_RECENT:
|
||||||
|
title = bundle.getString(DATA_KEY);
|
||||||
|
mRecyclerView.setLoadMoreEnabled(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//显示标题视图
|
||||||
|
LinearLayout titleLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
titleLL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
TextView titleView = mainView.findViewById(R.id.title);
|
||||||
|
titleView.setText(title);
|
||||||
|
//返回
|
||||||
|
ImageView backImg = mainView.findViewById(R.id.backImg);
|
||||||
|
backImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
FragmentReceiver.sendReceiver(mContext, FragmentReceiver.ACTION_CODE_CLOSE_FRAGMENT, null, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//音频广播
|
||||||
|
mAudioBroadcastReceiver = new AudioBroadcastReceiver();
|
||||||
|
mAudioBroadcastReceiver.setReceiverListener(new AudioBroadcastReceiver.AudioReceiverListener() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, final Intent intent, final int code) {
|
||||||
|
mUIHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleAudioBroadcastReceiver(intent, code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAudioBroadcastReceiver(Intent intent, int code) {
|
||||||
|
switch (code) {
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_NULL:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_INIT:
|
||||||
|
|
||||||
|
if (mAdapter != null) {
|
||||||
|
Bundle initBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
if (initBundle == null) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AudioInfo initAudioInfo = initBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(initAudioInfo.getHash());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_LOCAL:
|
||||||
|
if (mSongType == SONG_TYPE_LOCAL) {
|
||||||
|
//歌曲更新
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_LIKE:
|
||||||
|
if (mSongType == SONG_TYPE_LIKE) {
|
||||||
|
//歌曲更新
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
} else {
|
||||||
|
//喜欢/不喜欢
|
||||||
|
Bundle likeBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
String likeHash = likeBundle.getString(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
if (!TextUtils.isEmpty(likeHash)) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(likeHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_UPDATE_RECENT:
|
||||||
|
if (mSongType == SONG_TYPE_RECENT) {
|
||||||
|
//歌曲更新
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOAD_FINISH:
|
||||||
|
case AudioBroadcastReceiver.ACTION_CODE_DOWNLOADONEDLINESONG:
|
||||||
|
if (mAdapter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//网络歌曲下载完成
|
||||||
|
Bundle downloadedBundle = intent.getBundleExtra(AudioBroadcastReceiver.ACTION_BUNDLEKEY);
|
||||||
|
DownloadTask downloadedTask = downloadedBundle.getParcelable(AudioBroadcastReceiver.ACTION_DATA_KEY);
|
||||||
|
String downloadedHash = downloadedTask.getTaskId();
|
||||||
|
if (downloadedTask != null && !TextUtils.isEmpty(downloadedHash)) {
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).reshViewHolder(downloadedHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mAudioBroadcastReceiver.registerReceiver(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
handleLoadData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOADMOREDATA:
|
||||||
|
handleLoadMoreData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载更多数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadMoreData(HttpReturnResult httpReturnResult) {
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.setOnNetWorkErrorListener(new OnNetWorkErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADMOREDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mPage++;
|
||||||
|
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<AudioInfo> lists = (List<AudioInfo>) returnResult.get("rows");
|
||||||
|
int total = (int) returnResult.get("total");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
if (total <= mAdapter.getItemCount() || total == 0) {
|
||||||
|
mRecyclerView.setNoMore(true);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).resetMenuOpenIndex();
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadData(HttpReturnResult httpReturnResult) {
|
||||||
|
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.refreshComplete(0);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
} else {
|
||||||
|
mDatas.clear();
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<AudioInfo> lists = (List<AudioInfo>) returnResult.get("rows");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
((AudioAdapter) (mAdapter.getInnerAdapter())).resetMenuOpenIndex();
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mSongType == SONG_TYPE_LOCAL || mSongType == SONG_TYPE_LIKE || mSongType == SONG_TYPE_RECENT) {
|
||||||
|
mRecyclerView.setLoadMoreEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
loadRefreshData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOADMOREDATA:
|
||||||
|
|
||||||
|
loadMoreData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载更多数据
|
||||||
|
*/
|
||||||
|
private void loadMoreData() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
int page = mPage + 1;
|
||||||
|
HttpReturnResult httpReturnResult = null;
|
||||||
|
|
||||||
|
Bundle bundle = getArguments();
|
||||||
|
|
||||||
|
switch (mSongType) {
|
||||||
|
case SONG_TYPE_RECOMMEND:
|
||||||
|
|
||||||
|
RankInfo rankInfo = bundle.getParcelable(DATA_KEY);
|
||||||
|
httpReturnResult = apiHttpClient.rankSongList(mContext, rankInfo.getRankId(), rankInfo.getRankType(), page, mPageSize, configInfo.isWifi());
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SONG_TYPE_SPECIAL:
|
||||||
|
SpecialInfo specialInfo = bundle.getParcelable(DATA_KEY);
|
||||||
|
httpReturnResult = apiHttpClient.specialSongList(mContext, specialInfo.getSpecialId(), page, mPageSize, configInfo.isWifi());
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADMOREDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPage() {
|
||||||
|
mPage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private void loadRefreshData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
resetPage();
|
||||||
|
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
|
||||||
|
HttpReturnResult httpReturnResult = null;
|
||||||
|
|
||||||
|
Bundle bundle = getArguments();
|
||||||
|
|
||||||
|
switch (mSongType) {
|
||||||
|
case SONG_TYPE_RECOMMEND:
|
||||||
|
|
||||||
|
RankInfo rankInfo = bundle.getParcelable(DATA_KEY);
|
||||||
|
httpReturnResult = apiHttpClient.rankSongList(mContext, rankInfo.getRankId(), rankInfo.getRankType(), mPage, mPageSize, configInfo.isWifi());
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SONG_TYPE_SPECIAL:
|
||||||
|
SpecialInfo specialInfo = bundle.getParcelable(DATA_KEY);
|
||||||
|
httpReturnResult = apiHttpClient.specialSongList(mContext, specialInfo.getSpecialId(), mPage, mPageSize, configInfo.isWifi());
|
||||||
|
|
||||||
|
break;
|
||||||
|
case SONG_TYPE_LOCAL:
|
||||||
|
case SONG_TYPE_LIKE:
|
||||||
|
case SONG_TYPE_RECENT:
|
||||||
|
httpReturnResult = new HttpReturnResult();
|
||||||
|
httpReturnResult.setStatus(HttpClient.HTTP_OK);
|
||||||
|
List<AudioInfo> audioInfos = null;
|
||||||
|
if (mSongType == SONG_TYPE_LOCAL) {
|
||||||
|
audioInfos = AudioInfoDB.getLocalAudios(mContext);
|
||||||
|
} else if (mSongType == SONG_TYPE_LIKE) {
|
||||||
|
audioInfos = AudioInfoDB.getLikeAudios(mContext);
|
||||||
|
} else if (mSongType == SONG_TYPE_RECENT) {
|
||||||
|
audioInfos = AudioInfoDB.getRecentAudios(mContext);
|
||||||
|
}
|
||||||
|
if (audioInfos == null) {
|
||||||
|
audioInfos = new ArrayList<AudioInfo>();
|
||||||
|
}
|
||||||
|
Map<String, Object> returnResult = new HashMap<String, Object>();
|
||||||
|
returnResult.put("rows", audioInfos);
|
||||||
|
httpReturnResult.setResult(returnResult);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADREFRESHDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
if (mAudioBroadcastReceiver != null)
|
||||||
|
mAudioBroadcastReceiver.unregisterReceiver(mContext);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
277
app/src/main/java/com/zlm/hp/fragment/SpecialFragment.java
Normal file
277
app/src/main/java/com/zlm/hp/fragment/SpecialFragment.java
Normal file
|
|
@ -0,0 +1,277 @@
|
||||||
|
package com.zlm.hp.fragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.github.jdsjlzx.interfaces.OnLoadMoreListener;
|
||||||
|
import com.github.jdsjlzx.interfaces.OnNetWorkErrorListener;
|
||||||
|
import com.github.jdsjlzx.interfaces.OnRefreshListener;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerView;
|
||||||
|
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;
|
||||||
|
import com.zlm.hp.adapter.SpecialAdapter;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.entity.SpecialInfo;
|
||||||
|
import com.zlm.hp.http.APIHttpClient;
|
||||||
|
import com.zlm.hp.http.HttpReturnResult;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.util.HttpUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌单
|
||||||
|
* Created by zhangliangming on 2018-08-11.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SpecialFragment extends BaseFragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private LRecyclerView mRecyclerView;
|
||||||
|
|
||||||
|
private LRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private ArrayList<SpecialInfo> mDatas;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private final int LOADREFRESHDATA = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载更多数据
|
||||||
|
*/
|
||||||
|
private final int LOADMOREDATA = 1;
|
||||||
|
|
||||||
|
private int mPage = 1;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private int mPageSize = 20;
|
||||||
|
|
||||||
|
public SpecialFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static SpecialFragment newInstance() {
|
||||||
|
SpecialFragment fragment = new SpecialFragment();
|
||||||
|
return fragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setAddStatusBarView(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_special;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
initView(mainView);
|
||||||
|
//showLoadingView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mainView
|
||||||
|
*/
|
||||||
|
private void initView(View mainView) {
|
||||||
|
mRecyclerView = mainView.findViewById(R.id.recyclerView);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
|
||||||
|
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||||
|
mRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
//
|
||||||
|
mDatas = new ArrayList<SpecialInfo>();
|
||||||
|
mAdapter = new LRecyclerViewAdapter(new SpecialAdapter(mUIHandler,mWorkerHandler,mContext, mDatas));
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
|
||||||
|
mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
//refresh data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
|
||||||
|
@Override
|
||||||
|
public void onLoadMore() {
|
||||||
|
// load more data here
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADMOREDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
setRefreshListener(new RefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
showLoadingView();
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
handleLoadData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOADMOREDATA:
|
||||||
|
handleLoadMoreData((HttpReturnResult) msg.obj);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载更多数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadMoreData(HttpReturnResult httpReturnResult) {
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.setOnNetWorkErrorListener(new OnNetWorkErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADMOREDATA);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
mPage++;
|
||||||
|
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<SpecialInfo> lists = (List<SpecialInfo>) returnResult.get("rows");
|
||||||
|
int total = (int) returnResult.get("total");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
if (total <= mAdapter.getItemCount() || total == 0) {
|
||||||
|
mRecyclerView.setNoMore(true);
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理加载数据
|
||||||
|
*
|
||||||
|
* @param httpReturnResult
|
||||||
|
*/
|
||||||
|
private void handleLoadData(HttpReturnResult httpReturnResult) {
|
||||||
|
if (!httpReturnResult.isSuccessful()) {
|
||||||
|
ToastUtil.showTextToast(mContext, httpReturnResult.getErrorMsg());
|
||||||
|
|
||||||
|
mRecyclerView.refreshComplete(0);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
} else {
|
||||||
|
mDatas.clear();
|
||||||
|
Map<String, Object> returnResult = (Map<String, Object>) httpReturnResult.getResult();
|
||||||
|
List<SpecialInfo> lists = (List<SpecialInfo>) returnResult.get("rows");
|
||||||
|
int pageSize = lists.size();
|
||||||
|
for (int i = 0; i < pageSize; i++) {
|
||||||
|
mDatas.add(lists.get(i));
|
||||||
|
}
|
||||||
|
mRecyclerView.refreshComplete(pageSize);
|
||||||
|
mAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case LOADREFRESHDATA:
|
||||||
|
|
||||||
|
loadRefreshData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case LOADMOREDATA:
|
||||||
|
|
||||||
|
loadMoreData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载更多数据
|
||||||
|
*/
|
||||||
|
private void loadMoreData() {
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
int page = mPage + 1;
|
||||||
|
HttpReturnResult httpReturnResult = apiHttpClient.specialList(mContext, page, mPageSize, configInfo.isWifi());
|
||||||
|
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADMOREDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetPage() {
|
||||||
|
mPage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载刷新数据
|
||||||
|
*/
|
||||||
|
private void loadRefreshData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
resetPage();
|
||||||
|
|
||||||
|
APIHttpClient apiHttpClient = HttpUtil.getHttpClient();
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
HttpReturnResult httpReturnResult = apiHttpClient.specialList(mContext, mPage, mPageSize, configInfo.isWifi());
|
||||||
|
|
||||||
|
//
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = LOADREFRESHDATA;
|
||||||
|
msg.obj = httpReturnResult;
|
||||||
|
mUIHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
mWorkerHandler.sendEmptyMessage(LOADREFRESHDATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
446
app/src/main/java/com/zlm/hp/fragment/tool/EditLrcFragment.java
Normal file
446
app/src/main/java/com/zlm/hp/fragment/tool/EditLrcFragment.java
Normal file
|
|
@ -0,0 +1,446 @@
|
||||||
|
package com.zlm.hp.fragment.tool;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.dou361.dialogui.DialogUIUtils;
|
||||||
|
import com.dou361.dialogui.listener.DialogUIListener;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.fragment.BaseFragment;
|
||||||
|
import com.zlm.hp.lyrics.utils.StringUtils;
|
||||||
|
import com.zlm.hp.lyrics.utils.TimeUtils;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.ui.tool.MakeLrcActivity;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
import com.zlm.libs.widget.MusicSeekBar;
|
||||||
|
|
||||||
|
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
||||||
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌词编辑
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-30 23:29
|
||||||
|
**/
|
||||||
|
public class EditLrcFragment extends BaseFragment {
|
||||||
|
/**
|
||||||
|
* 歌词编辑框
|
||||||
|
*/
|
||||||
|
private EditText mLrcEditText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进度条
|
||||||
|
*/
|
||||||
|
private MusicSeekBar mMusicSeekBar;
|
||||||
|
/**
|
||||||
|
* 播放器
|
||||||
|
*/
|
||||||
|
private IjkMediaPlayer mMediaPlayer;
|
||||||
|
/**
|
||||||
|
* 播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPlayImg;
|
||||||
|
/**
|
||||||
|
* 暂停播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPauseImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否快进
|
||||||
|
*/
|
||||||
|
private boolean isSeekTo = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化歌曲数据
|
||||||
|
*/
|
||||||
|
private final int INITAUDIODATA = 1;
|
||||||
|
private final int AUDIO_PLAY = 2;
|
||||||
|
private final int AUDIO_PLAYING = 3;
|
||||||
|
private final int AUDIO_PAUSE = 4;
|
||||||
|
private final int AUDIO_FINISH = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲信息
|
||||||
|
*/
|
||||||
|
private AudioInfo mAudioInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件回调
|
||||||
|
*/
|
||||||
|
private MakeLrcActivity.MakeLrcListener mMakeLrcListener;
|
||||||
|
|
||||||
|
public EditLrcFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static EditLrcFragment newInstance() {
|
||||||
|
EditLrcFragment fragment = new EditLrcFragment();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_edit_lrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setTitleViewId(R.layout.layout_close_title);
|
||||||
|
super.preInitStatusBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
//显示标题视图
|
||||||
|
LinearLayout titleLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
titleLL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
TextView titleView = mainView.findViewById(R.id.title);
|
||||||
|
titleView.setText(getString(R.string.edit_lrc_text));
|
||||||
|
|
||||||
|
//关闭
|
||||||
|
IconfontTextView backTextView = mainView.findViewById(R.id.closebtn);
|
||||||
|
backTextView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
closeView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//歌词编辑框
|
||||||
|
mLrcEditText = mainView.findViewById(R.id.lrctext_edittext);
|
||||||
|
|
||||||
|
//进度条
|
||||||
|
mMusicSeekBar = mainView.findViewById(R.id.seekBar);
|
||||||
|
mMusicSeekBar.setOnMusicListener(new MusicSeekBar.OnMusicListener() {
|
||||||
|
@Override
|
||||||
|
public String getTimeText() {
|
||||||
|
return TimeUtils.parseMMSSString(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLrcText() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchStart(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchFinish(MusicSeekBar musicSeekBar) {
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
isSeekTo = true;
|
||||||
|
mMediaPlayer.seekTo(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mMusicSeekBar.setTimePopupWindowViewColor(Color.argb(200, 255, 64, 129));
|
||||||
|
|
||||||
|
//播放
|
||||||
|
mPlayImg = mainView.findViewById(R.id.bar_play);
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPlayImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mMediaPlayer == null) {
|
||||||
|
initPlayerData();
|
||||||
|
} else if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.start();
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//暂停
|
||||||
|
mPauseImg = mainView.findViewById(R.id.bar_pause);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
pauseMediaPlayer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//节奏按钮
|
||||||
|
Button playLrc = mainView.findViewById(R.id.goto_play);
|
||||||
|
playLrc.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
String lrcText = mLrcEditText.getText().toString();
|
||||||
|
if (StringUtils.isBlank(lrcText)) {
|
||||||
|
Toast.makeText(mContext, getString(R.string.lrc_null_text), Toast.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
hideInput(mContext,mLrcEditText);
|
||||||
|
pauseMediaPlayer();
|
||||||
|
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.openView(MakeLrcActivity.INDEX_MAKELRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强制隐藏输入法键盘
|
||||||
|
*
|
||||||
|
* @param context Context
|
||||||
|
* @param view EditText
|
||||||
|
*/
|
||||||
|
private void hideInput(Context context, View view) {
|
||||||
|
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停
|
||||||
|
*/
|
||||||
|
private void pauseMediaPlayer() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭界面
|
||||||
|
*/
|
||||||
|
private void closeView() {
|
||||||
|
String tipMsg = getString(R.string.close_lrc_text);
|
||||||
|
DialogUIUtils.showMdAlert(getActivity(), getString(R.string.tip_title), tipMsg, new DialogUIListener() {
|
||||||
|
@Override
|
||||||
|
public void onPositive() {
|
||||||
|
releasePlayer();
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.closeView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}).setCancelable(true, false).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
|
||||||
|
case INITAUDIODATA:
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAY:
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(true);
|
||||||
|
mMusicSeekBar.setMax((int) mMediaPlayer.getDuration());
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAYING:
|
||||||
|
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PAUSE:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
|
||||||
|
mMediaPlayer.pause();
|
||||||
|
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_FINISH:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 播放线程
|
||||||
|
*/
|
||||||
|
private Runnable mPlayRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying() && !isSeekTo) {
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAYING);
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置音频数据
|
||||||
|
*
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
public void setAudioInfo(AudioInfo audioInfo) {
|
||||||
|
audioInfo.setPlayProgress(0);
|
||||||
|
this.mAudioInfo = audioInfo;
|
||||||
|
if (!TextUtils.isEmpty(mAudioInfo.getFilePath())) {
|
||||||
|
mUIHandler.sendEmptyMessage(INITAUDIODATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化音频数据
|
||||||
|
*/
|
||||||
|
public void initPlayerData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMediaPlayer = new IjkMediaPlayer();
|
||||||
|
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
|
mMediaPlayer.setDataSource(mAudioInfo.getFilePath());
|
||||||
|
mMediaPlayer.prepareAsync();
|
||||||
|
//播放器完成回调
|
||||||
|
mMediaPlayer.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() {
|
||||||
|
@Override
|
||||||
|
public void onCompletion(IMediaPlayer mp) {
|
||||||
|
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_FINISH);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnSeekCompleteListener(new IMediaPlayer.OnSeekCompleteListener() {
|
||||||
|
@Override
|
||||||
|
public void onSeekComplete(IMediaPlayer mp) {
|
||||||
|
isSeekTo = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
|
||||||
|
@Override
|
||||||
|
public void onPrepared(IMediaPlayer mp) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
releasePlayer();
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放播放器
|
||||||
|
*/
|
||||||
|
private void releasePlayer() {
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
if (mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.stop();
|
||||||
|
}
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setMakeLrcListener(MakeLrcActivity.MakeLrcListener makeLrcListener) {
|
||||||
|
this.mMakeLrcListener = makeLrcListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置歌词文件
|
||||||
|
*
|
||||||
|
* @param lrcText
|
||||||
|
*/
|
||||||
|
public void setLrcText(String lrcText) {
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.check_lrc_text));
|
||||||
|
mLrcEditText.setText(lrcText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌词内容
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getLrcText() {
|
||||||
|
return mLrcEditText.getText().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,708 @@
|
||||||
|
package com.zlm.hp.fragment.tool;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.dou361.dialogui.DialogUIUtils;
|
||||||
|
import com.dou361.dialogui.listener.DialogUIListener;
|
||||||
|
import com.zlm.hp.adapter.tool.MakeExtraLrcAdapter;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.fragment.BaseFragment;
|
||||||
|
import com.zlm.hp.lyrics.LyricsReader;
|
||||||
|
import com.zlm.hp.lyrics.model.LyricsInfo;
|
||||||
|
import com.zlm.hp.lyrics.model.LyricsLineInfo;
|
||||||
|
import com.zlm.hp.lyrics.model.TranslateLrcLineInfo;
|
||||||
|
import com.zlm.hp.lyrics.model.make.MakeExtraLrcLineInfo;
|
||||||
|
import com.zlm.hp.lyrics.utils.StringUtils;
|
||||||
|
import com.zlm.hp.lyrics.utils.TimeUtils;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.ui.tool.MakeLrcActivity;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
import com.zlm.libs.widget.MusicSeekBar;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
||||||
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 制作额外歌词
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2019-01-01 0:37
|
||||||
|
**/
|
||||||
|
public class MakeExtraLrcFragment extends BaseFragment {
|
||||||
|
|
||||||
|
private TextView mTitleTextView;
|
||||||
|
/**
|
||||||
|
* 进度条
|
||||||
|
*/
|
||||||
|
private MusicSeekBar mMusicSeekBar;
|
||||||
|
/**
|
||||||
|
* 播放器
|
||||||
|
*/
|
||||||
|
private IjkMediaPlayer mMediaPlayer;
|
||||||
|
/**
|
||||||
|
* 播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPlayImg;
|
||||||
|
/**
|
||||||
|
* 暂停播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPauseImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否快进
|
||||||
|
*/
|
||||||
|
private boolean isSeekTo = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化歌曲数据
|
||||||
|
*/
|
||||||
|
private final int INITAUDIODATA = 1;
|
||||||
|
private final int AUDIO_PLAY = 2;
|
||||||
|
private final int AUDIO_PLAYING = 3;
|
||||||
|
private final int AUDIO_PAUSE = 4;
|
||||||
|
private final int AUDIO_FINISH = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载歌词
|
||||||
|
*/
|
||||||
|
private final int MESSAGE_WHAT_LOADLRC = 0;
|
||||||
|
/**
|
||||||
|
* 歌曲信息
|
||||||
|
*/
|
||||||
|
private AudioInfo mAudioInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件回调
|
||||||
|
*/
|
||||||
|
private MakeLrcActivity.MakeLrcListener mMakeLrcListener;
|
||||||
|
/**
|
||||||
|
* 翻译歌词
|
||||||
|
*/
|
||||||
|
public static final int EXTRA_LRC_TYPE_TRANSLATE = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音译歌词
|
||||||
|
*/
|
||||||
|
public static final int EXTRA_LRC_TYPE_TRANSLITERATION = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词类型
|
||||||
|
*/
|
||||||
|
private int mExtraLrcType = EXTRA_LRC_TYPE_TRANSLATE;
|
||||||
|
|
||||||
|
|
||||||
|
private ExtraItemEvent mExtraItemEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词列表
|
||||||
|
*/
|
||||||
|
private ArrayList<MakeExtraLrcLineInfo> mMakeLrcs = new ArrayList<MakeExtraLrcLineInfo>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作歌词list视图
|
||||||
|
*/
|
||||||
|
private RecyclerView mLinearLayoutRecyclerView;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private MakeExtraLrcAdapter mMakeExtraLrcAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private MakeExtraLrcAdapter.ItemEvent mItemEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private LyricsInfo mLyricsInfo;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词路径
|
||||||
|
*/
|
||||||
|
private String mLrcFilePath;
|
||||||
|
|
||||||
|
public MakeExtraLrcFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static MakeExtraLrcFragment newInstance() {
|
||||||
|
MakeExtraLrcFragment fragment = new MakeExtraLrcFragment();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_make_extra_lrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setTitleViewId(R.layout.layout_close_title);
|
||||||
|
super.preInitStatusBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
//显示标题视图
|
||||||
|
LinearLayout titleLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
titleLL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
mTitleTextView = mainView.findViewById(R.id.title);
|
||||||
|
|
||||||
|
if (mExtraLrcType == EXTRA_LRC_TYPE_TRANSLATE) {
|
||||||
|
mTitleTextView.setText(getString(R.string.extra_lrc_1));
|
||||||
|
} else {
|
||||||
|
mTitleTextView.setText(getString(R.string.extra_lrc_2));
|
||||||
|
}
|
||||||
|
|
||||||
|
//关闭
|
||||||
|
IconfontTextView backTextView = mainView.findViewById(R.id.closebtn);
|
||||||
|
backTextView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
closeView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//进度条
|
||||||
|
mMusicSeekBar = mainView.findViewById(R.id.seekBar);
|
||||||
|
mMusicSeekBar.setOnMusicListener(new MusicSeekBar.OnMusicListener() {
|
||||||
|
@Override
|
||||||
|
public String getTimeText() {
|
||||||
|
return TimeUtils.parseMMSSString(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLrcText() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchStart(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchFinish(MusicSeekBar musicSeekBar) {
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
isSeekTo = true;
|
||||||
|
mMediaPlayer.seekTo(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mMusicSeekBar.setTimePopupWindowViewColor(Color.argb(200, 255, 64, 129));
|
||||||
|
|
||||||
|
//播放
|
||||||
|
mPlayImg = mainView.findViewById(R.id.bar_play);
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPlayImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mMediaPlayer == null) {
|
||||||
|
initPlayerData();
|
||||||
|
} else if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.start();
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//暂停
|
||||||
|
mPauseImg = mainView.findViewById(R.id.bar_pause);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
pauseMediaPlayer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
mLinearLayoutRecyclerView = mainView.findViewById(R.id.listview);
|
||||||
|
//初始化内容视图
|
||||||
|
mLinearLayoutRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
|
||||||
|
DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
|
||||||
|
mLinearLayoutRecyclerView.addItemDecoration(divider);
|
||||||
|
|
||||||
|
|
||||||
|
mMakeExtraLrcAdapter = new MakeExtraLrcAdapter(getActivity().getApplicationContext(), mMakeLrcs);
|
||||||
|
mItemEvent = new MakeExtraLrcAdapter.ItemEvent() {
|
||||||
|
@Override
|
||||||
|
public void itemClick(int index) {
|
||||||
|
if (mExtraItemEvent != null) {
|
||||||
|
mExtraItemEvent.itemClick(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
mMakeExtraLrcAdapter.setItemEvent(mItemEvent);
|
||||||
|
mLinearLayoutRecyclerView.setAdapter(mMakeExtraLrcAdapter);
|
||||||
|
|
||||||
|
//预览按钮
|
||||||
|
Button preBtn = mainView.findViewById(R.id.preBtn);
|
||||||
|
preBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
pauseMediaPlayer();
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.openView(MakeLrcActivity.INDEX_PRELRC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停
|
||||||
|
*/
|
||||||
|
private void pauseMediaPlayer() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭界面
|
||||||
|
*/
|
||||||
|
private void closeView() {
|
||||||
|
String tipMsg = getString(R.string.close_lrc_text);
|
||||||
|
DialogUIUtils.showMdAlert(getActivity(), getString(R.string.tip_title), tipMsg, new DialogUIListener() {
|
||||||
|
@Override
|
||||||
|
public void onPositive() {
|
||||||
|
releasePlayer();
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.closeView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}).setCancelable(true, false).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
|
||||||
|
case INITAUDIODATA:
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAY:
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(true);
|
||||||
|
mMusicSeekBar.setMax((int) mMediaPlayer.getDuration());
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAYING:
|
||||||
|
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PAUSE:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
|
||||||
|
mMediaPlayer.pause();
|
||||||
|
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_FINISH:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MESSAGE_WHAT_LOADLRC:
|
||||||
|
mMakeExtraLrcAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 播放线程
|
||||||
|
*/
|
||||||
|
private Runnable mPlayRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying() && !isSeekTo) {
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAYING);
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case MESSAGE_WHAT_LOADLRC:
|
||||||
|
|
||||||
|
loadLrcData();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载歌词数据
|
||||||
|
*/
|
||||||
|
private void loadLrcData() {
|
||||||
|
File lrcFile = new File(mLrcFilePath);
|
||||||
|
LyricsReader lyricsReader = new LyricsReader();
|
||||||
|
lyricsReader.loadLrc(lrcFile);
|
||||||
|
if (lyricsReader.getLrcLineInfos() != null && lyricsReader.getLrcLineInfos().size() > 0) {
|
||||||
|
mLyricsInfo = lyricsReader.getLyricsInfo();
|
||||||
|
TreeMap<Integer, LyricsLineInfo> lrcLineInfos = lyricsReader.getLrcLineInfos();
|
||||||
|
|
||||||
|
List<LyricsLineInfo> extraLrcLineInfos = null;
|
||||||
|
if (mExtraLrcType == EXTRA_LRC_TYPE_TRANSLATE) {
|
||||||
|
//翻译
|
||||||
|
extraLrcLineInfos = lyricsReader.getTranslateLrcLineInfos();
|
||||||
|
} else {
|
||||||
|
//音译
|
||||||
|
extraLrcLineInfos = lyricsReader.getTransliterationLrcLineInfos();
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化数据
|
||||||
|
for (int i = 0; i < lrcLineInfos.size(); i++) {
|
||||||
|
LyricsLineInfo lyricsLineInfo = lrcLineInfos.get(i);
|
||||||
|
MakeExtraLrcLineInfo makeExtraLrcLineInfo = new MakeExtraLrcLineInfo();
|
||||||
|
makeExtraLrcLineInfo.setLyricsLineInfo(lyricsLineInfo);
|
||||||
|
if (extraLrcLineInfos != null && i < extraLrcLineInfos.size()) {
|
||||||
|
if (mExtraLrcType != EXTRA_LRC_TYPE_TRANSLATE) {
|
||||||
|
String extraLyrics = extraLrcLineInfos.get(i).getLineLyrics();
|
||||||
|
String extraLineLyrics = "";
|
||||||
|
if (!StringUtils.isBlank(extraLyrics)) {
|
||||||
|
//音译
|
||||||
|
String[] extraLyricsWords = extraLrcLineInfos.get(i).getLyricsWords();
|
||||||
|
for (int j = 0; j < extraLyricsWords.length; j++) {
|
||||||
|
if (j == 0) {
|
||||||
|
extraLineLyrics += extraLyricsWords[j].trim();
|
||||||
|
} else {
|
||||||
|
extraLineLyrics += "∮" + extraLyricsWords[j].trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
makeExtraLrcLineInfo.setExtraLineLyrics(extraLineLyrics);
|
||||||
|
} else {
|
||||||
|
//翻译
|
||||||
|
String extraLineLyrics = extraLrcLineInfos.get(i).getLineLyrics();
|
||||||
|
if (StringUtils.isNotBlank(extraLineLyrics)) {
|
||||||
|
makeExtraLrcLineInfo.setExtraLineLyrics(extraLineLyrics);
|
||||||
|
} else {
|
||||||
|
makeExtraLrcLineInfo.setExtraLineLyrics("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mMakeLrcs.add(makeExtraLrcLineInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mUIHandler.sendEmptyMessage(MESSAGE_WHAT_LOADLRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置音频数据
|
||||||
|
*
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
public void setAudioInfo(AudioInfo audioInfo) {
|
||||||
|
audioInfo.setPlayProgress(0);
|
||||||
|
this.mAudioInfo = audioInfo;
|
||||||
|
if (!TextUtils.isEmpty(mAudioInfo.getFilePath())) {
|
||||||
|
mUIHandler.sendEmptyMessage(INITAUDIODATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置歌词路径
|
||||||
|
*
|
||||||
|
* @param mLrcFilePath
|
||||||
|
*/
|
||||||
|
public void setLrcFilePath(String mLrcFilePath) {
|
||||||
|
this.mLrcFilePath = mLrcFilePath;
|
||||||
|
if (mLrcFilePath != null && !mLrcFilePath.equals("")) {
|
||||||
|
mWorkerHandler.sendEmptyMessage(MESSAGE_WHAT_LOADLRC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化音频数据
|
||||||
|
*/
|
||||||
|
public void initPlayerData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMediaPlayer = new IjkMediaPlayer();
|
||||||
|
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
|
mMediaPlayer.setDataSource(mAudioInfo.getFilePath());
|
||||||
|
mMediaPlayer.prepareAsync();
|
||||||
|
//播放器完成回调
|
||||||
|
mMediaPlayer.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() {
|
||||||
|
@Override
|
||||||
|
public void onCompletion(IMediaPlayer mp) {
|
||||||
|
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_FINISH);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnSeekCompleteListener(new IMediaPlayer.OnSeekCompleteListener() {
|
||||||
|
@Override
|
||||||
|
public void onSeekComplete(IMediaPlayer mp) {
|
||||||
|
isSeekTo = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
|
||||||
|
@Override
|
||||||
|
public void onPrepared(IMediaPlayer mp) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
releasePlayer();
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放播放器
|
||||||
|
*/
|
||||||
|
private void releasePlayer() {
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
if (mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.stop();
|
||||||
|
}
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraLrcType(int extraLrcType) {
|
||||||
|
this.mExtraLrcType = extraLrcType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMakeLrcListener(MakeLrcActivity.MakeLrcListener makeLrcListener) {
|
||||||
|
this.mMakeLrcListener = makeLrcListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraItemEvent(ExtraItemEvent mExtraItemEvent) {
|
||||||
|
this.mExtraItemEvent = mExtraItemEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param index
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public MakeExtraLrcLineInfo getMakeExtraLrcLineInfo(int index) {
|
||||||
|
if (index >= 0 && index < mMakeLrcs.size()) {
|
||||||
|
return mMakeLrcs.get(index);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存和更新
|
||||||
|
*/
|
||||||
|
public void saveAndUpdate() {
|
||||||
|
mMakeExtraLrcAdapter.saveAndUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌词信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public LyricsInfo getLyricsInfo() {
|
||||||
|
List<TranslateLrcLineInfo> mTranslateLrcLineInfos = new ArrayList<TranslateLrcLineInfo>();
|
||||||
|
List<LyricsLineInfo> transliterationLrcLineInfos = new ArrayList<LyricsLineInfo>();
|
||||||
|
for (int i = 0; i < mMakeLrcs.size(); i++) {
|
||||||
|
MakeExtraLrcLineInfo makeExtraLrcLineInfo = mMakeLrcs.get(i);
|
||||||
|
//原始歌词
|
||||||
|
LyricsLineInfo lyricsLineInfo = makeExtraLrcLineInfo.getLyricsLineInfo();
|
||||||
|
|
||||||
|
if (mExtraLrcType != EXTRA_LRC_TYPE_TRANSLATE) {
|
||||||
|
String[] lyricsWords = lyricsLineInfo.getLyricsWords();
|
||||||
|
//音译
|
||||||
|
LyricsLineInfo transliterationLrcLineInfo = new LyricsLineInfo();
|
||||||
|
String extraLineLyrics = makeExtraLrcLineInfo.getExtraLineLyrics();
|
||||||
|
if (extraLineLyrics == null) {
|
||||||
|
extraLineLyrics = "";
|
||||||
|
} else {
|
||||||
|
extraLineLyrics = extraLineLyrics.trim();
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(extraLineLyrics)) {
|
||||||
|
String[] extraLyricsWords = new String[lyricsWords.length];
|
||||||
|
for (int j = 0; j < extraLyricsWords.length; j++) {
|
||||||
|
extraLyricsWords[j] = "";
|
||||||
|
}
|
||||||
|
transliterationLrcLineInfo.setLyricsWords(extraLyricsWords);
|
||||||
|
} else {
|
||||||
|
String[] extraLyricsWords = extraLineLyrics.split("∮");
|
||||||
|
//歌词字验证
|
||||||
|
if (lyricsWords.length != extraLyricsWords.length) {
|
||||||
|
|
||||||
|
final int finalI = i;
|
||||||
|
|
||||||
|
((LinearLayoutManager) mLinearLayoutRecyclerView.getLayoutManager()).scrollToPositionWithOffset(i, 0);
|
||||||
|
mUIHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(mContext, "第" + String.format("%0" + (mMakeLrcs.size() + "").length() + "d", (finalI + 1)) + "行歌词未完成,请先完成后再预览!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < extraLyricsWords.length; j++) {
|
||||||
|
extraLyricsWords[j] = extraLyricsWords[j].trim();
|
||||||
|
}
|
||||||
|
transliterationLrcLineInfo.setLyricsWords(extraLyricsWords);
|
||||||
|
}
|
||||||
|
transliterationLrcLineInfo.setLineLyrics(extraLineLyrics);
|
||||||
|
transliterationLrcLineInfos.add(transliterationLrcLineInfo);
|
||||||
|
} else {
|
||||||
|
//翻译歌词
|
||||||
|
TranslateLrcLineInfo translateLrcLineInfo = new TranslateLrcLineInfo();
|
||||||
|
String extraLineLyrics = makeExtraLrcLineInfo.getExtraLineLyrics();
|
||||||
|
if (extraLineLyrics == null) {
|
||||||
|
extraLineLyrics = "";
|
||||||
|
} else {
|
||||||
|
extraLineLyrics = extraLineLyrics.trim();
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(extraLineLyrics)) {
|
||||||
|
extraLineLyrics = "";
|
||||||
|
}
|
||||||
|
translateLrcLineInfo.setLineLyrics(extraLineLyrics);
|
||||||
|
mTranslateLrcLineInfos.add(translateLrcLineInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mTranslateLrcLineInfos != null && mTranslateLrcLineInfos.size() > 0) {
|
||||||
|
mLyricsInfo.setTranslateLrcLineInfos(mTranslateLrcLineInfos);
|
||||||
|
}
|
||||||
|
if (transliterationLrcLineInfos != null && transliterationLrcLineInfos.size() > 0) {
|
||||||
|
mLyricsInfo.setTransliterationLrcLineInfos(transliterationLrcLineInfos);
|
||||||
|
}
|
||||||
|
return mLyricsInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上一行歌词
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getPreIndex() {
|
||||||
|
int index = mMakeExtraLrcAdapter.getPreIndex();
|
||||||
|
((LinearLayoutManager) mLinearLayoutRecyclerView.getLayoutManager()).scrollToPositionWithOffset(index, 0);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下一行歌词
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getNextIndex() {
|
||||||
|
int index = mMakeExtraLrcAdapter.getNextIndex();
|
||||||
|
((LinearLayoutManager) mLinearLayoutRecyclerView.getLayoutManager()).scrollToPositionWithOffset(index, 0);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌词数据大小
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getLrcDataSize() {
|
||||||
|
return mMakeLrcs.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public interface ExtraItemEvent {
|
||||||
|
void itemClick(int index);
|
||||||
|
}
|
||||||
|
}
|
||||||
519
app/src/main/java/com/zlm/hp/fragment/tool/MakeLrcFragment.java
Normal file
519
app/src/main/java/com/zlm/hp/fragment/tool/MakeLrcFragment.java
Normal file
|
|
@ -0,0 +1,519 @@
|
||||||
|
package com.zlm.hp.fragment.tool;
|
||||||
|
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.dou361.dialogui.DialogUIUtils;
|
||||||
|
import com.dou361.dialogui.listener.DialogUIListener;
|
||||||
|
import com.zlm.hp.constants.ConfigInfo;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.fragment.BaseFragment;
|
||||||
|
import com.zlm.hp.lyrics.model.LyricsInfo;
|
||||||
|
import com.zlm.hp.lyrics.utils.TimeUtils;
|
||||||
|
import com.zlm.hp.lyrics.widget.make.MakeLyricsView;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.ui.tool.MakeLrcActivity;
|
||||||
|
import com.zlm.hp.util.ColorUtil;
|
||||||
|
import com.zlm.hp.util.ToastUtil;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
import com.zlm.libs.widget.MusicSeekBar;
|
||||||
|
|
||||||
|
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
||||||
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 制作歌词
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-30 23:45
|
||||||
|
**/
|
||||||
|
public class MakeLrcFragment extends BaseFragment {
|
||||||
|
/**
|
||||||
|
* 进度条
|
||||||
|
*/
|
||||||
|
private MusicSeekBar mMusicSeekBar;
|
||||||
|
/**
|
||||||
|
* 播放器
|
||||||
|
*/
|
||||||
|
private IjkMediaPlayer mMediaPlayer;
|
||||||
|
/**
|
||||||
|
* 播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPlayImg;
|
||||||
|
/**
|
||||||
|
* 暂停播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPauseImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制作歌词视图
|
||||||
|
*/
|
||||||
|
private MakeLyricsView mMakeLyricsView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回滚
|
||||||
|
*/
|
||||||
|
private Button mBackPlayBtn;
|
||||||
|
/**
|
||||||
|
* 敲打
|
||||||
|
*/
|
||||||
|
private Button mPlayBtn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否快进
|
||||||
|
*/
|
||||||
|
private boolean isSeekTo = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化歌曲数据
|
||||||
|
*/
|
||||||
|
private final int INITAUDIODATA = 1;
|
||||||
|
private final int AUDIO_PLAY = 2;
|
||||||
|
private final int AUDIO_PLAYING = 3;
|
||||||
|
private final int AUDIO_PAUSE = 4;
|
||||||
|
private final int AUDIO_FINISH = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌曲信息
|
||||||
|
*/
|
||||||
|
private AudioInfo mAudioInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件回调
|
||||||
|
*/
|
||||||
|
private MakeLrcActivity.MakeLrcListener mMakeLrcListener;
|
||||||
|
|
||||||
|
public MakeLrcFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static MakeLrcFragment newInstance() {
|
||||||
|
MakeLrcFragment fragment = new MakeLrcFragment();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_make_lrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setTitleViewId(R.layout.layout_close_title);
|
||||||
|
super.preInitStatusBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
//显示标题视图
|
||||||
|
LinearLayout titleLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
titleLL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
TextView titleView = mainView.findViewById(R.id.title);
|
||||||
|
titleView.setText(getString(R.string.play_lrc_text));
|
||||||
|
|
||||||
|
//关闭
|
||||||
|
IconfontTextView backTextView = mainView.findViewById(R.id.closebtn);
|
||||||
|
backTextView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
closeView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//进度条
|
||||||
|
mMusicSeekBar = mainView.findViewById(R.id.seekBar);
|
||||||
|
mMusicSeekBar.setOnMusicListener(new MusicSeekBar.OnMusicListener() {
|
||||||
|
@Override
|
||||||
|
public String getTimeText() {
|
||||||
|
return TimeUtils.parseMMSSString(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLrcText() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchStart(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchFinish(MusicSeekBar musicSeekBar) {
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
isSeekTo = true;
|
||||||
|
mMakeLyricsView.seekTo(mMusicSeekBar.getProgress());
|
||||||
|
mMediaPlayer.seekTo(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mMusicSeekBar.setTimePopupWindowViewColor(Color.argb(200, 255, 64, 129));
|
||||||
|
|
||||||
|
//返回编辑按钮
|
||||||
|
Button mBackEditBtn = mainView.findViewById(R.id.backEdit);
|
||||||
|
mBackEditBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
String tipMsg = getString(R.string.close_lrc_text);
|
||||||
|
DialogUIUtils.showMdAlert(getActivity(), getString(R.string.tip_title), tipMsg, new DialogUIListener() {
|
||||||
|
@Override
|
||||||
|
public void onPositive() {
|
||||||
|
releasePlayer();
|
||||||
|
|
||||||
|
mMakeLyricsView.initLrcData(true);
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.openView(MakeLrcActivity.INDEX_EDITLRC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}).setCancelable(true, false).show();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//播放
|
||||||
|
mPlayImg = mainView.findViewById(R.id.bar_play);
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPlayImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mMediaPlayer == null) {
|
||||||
|
initPlayerData();
|
||||||
|
} else if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.start();
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//暂停
|
||||||
|
mPauseImg = mainView.findViewById(R.id.bar_pause);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
pauseMediaPlayer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ConfigInfo configInfo = ConfigInfo.obtain();
|
||||||
|
mMakeLyricsView = mainView.findViewById(R.id.makelyricsview);
|
||||||
|
mMakeLyricsView.setPaintLineColor(ColorUtil.parserColor("#888888"));
|
||||||
|
mMakeLyricsView.setFontSize(configInfo.getLrcFontSize());
|
||||||
|
mMakeLyricsView.setPaintColors(new int[]{ColorUtil.parserColor("#888888"), ColorUtil.parserColor("#888888")});
|
||||||
|
mMakeLyricsView.setPaintHLColors(new int[]{ColorUtil.parserColor("#0288d1"), ColorUtil.parserColor("#0288d1")});
|
||||||
|
|
||||||
|
//设置制作歌词回调事件
|
||||||
|
mMakeLyricsView.setOnScrollListener(new MakeLyricsView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public int getScrollStopPlayTime() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
return (int) mMediaPlayer.getCurrentPosition();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCurPlayTime() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
return (int) mMediaPlayer.getCurrentPosition();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void seekTo(int seektoProgress) {
|
||||||
|
isSeekTo = true;
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
mMediaPlayer.seekTo(seektoProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//回滚按钮
|
||||||
|
mBackPlayBtn = mainView.findViewById(R.id.backplayBtn);
|
||||||
|
mBackPlayBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMakeLyricsView.lineLrcBack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//敲打按钮
|
||||||
|
mPlayBtn = mainView.findViewById(R.id.playBtn);
|
||||||
|
mPlayBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMakeLyricsView.lineLrcPlay((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
} else {
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.play_song_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//预览按钮
|
||||||
|
Button preBtn = mainView.findViewById(R.id.preBtn);
|
||||||
|
preBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
LyricsInfo lyricsInfo = mMakeLyricsView.getFinishLyricsInfo();
|
||||||
|
if (lyricsInfo == null) {
|
||||||
|
ToastUtil.showTextToast(mContext, getString(R.string.unfinish_lrc_text));
|
||||||
|
} else {
|
||||||
|
pauseMediaPlayer();
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.openView(MakeLrcActivity.INDEX_PRELRC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 暂停
|
||||||
|
*/
|
||||||
|
private void pauseMediaPlayer() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭界面
|
||||||
|
*/
|
||||||
|
private void closeView() {
|
||||||
|
String tipMsg = getString(R.string.close_lrc_text);
|
||||||
|
DialogUIUtils.showMdAlert(getActivity(), getString(R.string.tip_title), tipMsg, new DialogUIListener() {
|
||||||
|
@Override
|
||||||
|
public void onPositive() {
|
||||||
|
releasePlayer();
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.closeView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}).setCancelable(true, false).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
|
||||||
|
case INITAUDIODATA:
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAY:
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(true);
|
||||||
|
mMusicSeekBar.setMax((int) mMediaPlayer.getDuration());
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAYING:
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PAUSE:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
|
||||||
|
mMediaPlayer.pause();
|
||||||
|
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_FINISH:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 播放线程
|
||||||
|
*/
|
||||||
|
private Runnable mPlayRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying() && !isSeekTo) {
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAYING);
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置音频数据
|
||||||
|
*
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
public void setAudioInfo(AudioInfo audioInfo) {
|
||||||
|
audioInfo.setPlayProgress(0);
|
||||||
|
this.mAudioInfo = audioInfo;
|
||||||
|
if (!TextUtils.isEmpty(mAudioInfo.getFilePath())) {
|
||||||
|
mUIHandler.sendEmptyMessage(INITAUDIODATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置歌词文件
|
||||||
|
*
|
||||||
|
* @param lrcText
|
||||||
|
*/
|
||||||
|
public void setLrcText(String lrcText) {
|
||||||
|
mMakeLyricsView.setMakeLrcComText(lrcText, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取录制完成的歌曲数据
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public LyricsInfo getLyricsInfo() {
|
||||||
|
return mMakeLyricsView.getFinishLyricsInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化音频数据
|
||||||
|
*/
|
||||||
|
public void initPlayerData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMediaPlayer = new IjkMediaPlayer();
|
||||||
|
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
|
mMediaPlayer.setDataSource(mAudioInfo.getFilePath());
|
||||||
|
mMediaPlayer.prepareAsync();
|
||||||
|
//播放器完成回调
|
||||||
|
mMediaPlayer.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() {
|
||||||
|
@Override
|
||||||
|
public void onCompletion(IMediaPlayer mp) {
|
||||||
|
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_FINISH);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnSeekCompleteListener(new IMediaPlayer.OnSeekCompleteListener() {
|
||||||
|
@Override
|
||||||
|
public void onSeekComplete(IMediaPlayer mp) {
|
||||||
|
isSeekTo = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
|
||||||
|
@Override
|
||||||
|
public void onPrepared(IMediaPlayer mp) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
releasePlayer();
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放播放器
|
||||||
|
*/
|
||||||
|
private void releasePlayer() {
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
if (mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.stop();
|
||||||
|
}
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMakeLrcListener(MakeLrcActivity.MakeLrcListener makeLrcListener) {
|
||||||
|
this.mMakeLrcListener = makeLrcListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,488 @@
|
||||||
|
package com.zlm.hp.fragment.tool;
|
||||||
|
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.dou361.dialogui.DialogUIUtils;
|
||||||
|
import com.dou361.dialogui.listener.DialogUIListener;
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.fragment.BaseFragment;
|
||||||
|
import com.zlm.hp.lyrics.LyricsReader;
|
||||||
|
import com.zlm.hp.lyrics.model.LyricsInfo;
|
||||||
|
import com.zlm.hp.lyrics.utils.ColorUtils;
|
||||||
|
import com.zlm.hp.lyrics.utils.TimeUtils;
|
||||||
|
import com.zlm.hp.lyrics.widget.AbstractLrcView;
|
||||||
|
import com.zlm.hp.lyrics.widget.ManyLyricsView;
|
||||||
|
import com.zlm.hp.ui.R;
|
||||||
|
import com.zlm.hp.ui.tool.MakeLrcActivity;
|
||||||
|
import com.zlm.hp.widget.IconfontTextView;
|
||||||
|
import com.zlm.libs.widget.MusicSeekBar;
|
||||||
|
|
||||||
|
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
||||||
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 歌词预览
|
||||||
|
* @author: zhangliangming
|
||||||
|
* @date: 2018-12-30 23:50
|
||||||
|
**/
|
||||||
|
public class PreviewLrcFragment extends BaseFragment {
|
||||||
|
/**
|
||||||
|
* 进度条
|
||||||
|
*/
|
||||||
|
private MusicSeekBar mMusicSeekBar;
|
||||||
|
/**
|
||||||
|
* 播放器
|
||||||
|
*/
|
||||||
|
private IjkMediaPlayer mMediaPlayer;
|
||||||
|
/**
|
||||||
|
* 播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPlayImg;
|
||||||
|
/**
|
||||||
|
* 暂停播放按钮
|
||||||
|
*/
|
||||||
|
private ImageView mPauseImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否快进
|
||||||
|
*/
|
||||||
|
private boolean isSeekTo = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化歌曲数据
|
||||||
|
*/
|
||||||
|
private final int INITAUDIODATA = 1;
|
||||||
|
private final int AUDIO_PLAY = 2;
|
||||||
|
private final int AUDIO_PLAYING = 3;
|
||||||
|
private final int AUDIO_PAUSE = 4;
|
||||||
|
private final int AUDIO_FINISH = 5;
|
||||||
|
|
||||||
|
private final int INITLRCVIEW = 6;
|
||||||
|
/**
|
||||||
|
* 歌曲信息
|
||||||
|
*/
|
||||||
|
private AudioInfo mAudioInfo;
|
||||||
|
|
||||||
|
private LyricsInfo mLyricsInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌词类型
|
||||||
|
*/
|
||||||
|
private int mExtraLrcType = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件回调
|
||||||
|
*/
|
||||||
|
private MakeLrcActivity.MakeLrcListener mMakeLrcListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多行歌词视图
|
||||||
|
*/
|
||||||
|
private ManyLyricsView mManyLyricsView;
|
||||||
|
|
||||||
|
public PreviewLrcFragment() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static PreviewLrcFragment newInstance() {
|
||||||
|
PreviewLrcFragment fragment = new PreviewLrcFragment();
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void isFristVisibleToUser() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int setContentLayoutResID() {
|
||||||
|
return R.layout.fragment_preview_lrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void preInitStatusBar() {
|
||||||
|
setTitleViewId(R.layout.layout_close_title);
|
||||||
|
super.preInitStatusBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initViews(View mainView, Bundle savedInstanceState) {
|
||||||
|
//显示标题视图
|
||||||
|
LinearLayout titleLL = mainView.findViewById(R.id.title_view_parent);
|
||||||
|
titleLL.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
TextView titleView = mainView.findViewById(R.id.title);
|
||||||
|
titleView.setText(getString(R.string.pre_lrc_text));
|
||||||
|
|
||||||
|
//关闭
|
||||||
|
IconfontTextView backTextView = mainView.findViewById(R.id.closebtn);
|
||||||
|
backTextView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
|
||||||
|
closeView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//进度条
|
||||||
|
mMusicSeekBar = mainView.findViewById(R.id.seekBar);
|
||||||
|
mMusicSeekBar.setOnMusicListener(new MusicSeekBar.OnMusicListener() {
|
||||||
|
@Override
|
||||||
|
public String getTimeText() {
|
||||||
|
return TimeUtils.parseMMSSString(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLrcText() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchStart(MusicSeekBar musicSeekBar) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackingTouchFinish(MusicSeekBar musicSeekBar) {
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
isSeekTo = true;
|
||||||
|
mMediaPlayer.seekTo(mMusicSeekBar.getProgress());
|
||||||
|
mManyLyricsView.seekto(mMusicSeekBar.getProgress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mMusicSeekBar.setTimePopupWindowViewColor(Color.argb(200, 255, 64, 129));
|
||||||
|
|
||||||
|
//播放
|
||||||
|
mPlayImg = mainView.findViewById(R.id.bar_play);
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPlayImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mMediaPlayer == null) {
|
||||||
|
initPlayerData();
|
||||||
|
} else if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.start();
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//暂停
|
||||||
|
mPauseImg = mainView.findViewById(R.id.bar_pause);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PAUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//返回编辑
|
||||||
|
Button backMakeLrc = mainView.findViewById(R.id.backMakeLrc);
|
||||||
|
backMakeLrc.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
|
||||||
|
releasePlayer();
|
||||||
|
mManyLyricsView.initLrcData();
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.openView(MakeLrcActivity.INDEX_MAKELRC_BACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//多行歌词视图
|
||||||
|
mManyLyricsView = mainView.findViewById(R.id.manyLyricsView);
|
||||||
|
int paintColor = ColorUtils.parserColor("#555555");
|
||||||
|
mManyLyricsView.setPaintColor(new int[]{paintColor, paintColor}, false);
|
||||||
|
mManyLyricsView.setPaintLineColor(paintColor);
|
||||||
|
int paintHLColor = ColorUtils.parserColor("#0288d1");
|
||||||
|
mManyLyricsView.setPaintHLColor(new int[]{paintHLColor, paintHLColor}, false);
|
||||||
|
mManyLyricsView.setOnLrcClickListener(new ManyLyricsView.OnLrcClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onLrcPlayClicked(int seekProgress) {
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
isSeekTo = true;
|
||||||
|
mMusicSeekBar.setProgress(seekProgress);
|
||||||
|
mMediaPlayer.seekTo(seekProgress);
|
||||||
|
mManyLyricsView.seekto(seekProgress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//完成
|
||||||
|
Button finishBtn = mainView.findViewById(R.id.finishBtn);
|
||||||
|
finishBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
releasePlayer();
|
||||||
|
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.saveLrcData(mLyricsInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
showContentView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭界面
|
||||||
|
*/
|
||||||
|
private void closeView() {
|
||||||
|
String tipMsg = getString(R.string.close_lrc_text);
|
||||||
|
DialogUIUtils.showMdAlert(getActivity(), getString(R.string.tip_title), tipMsg, new DialogUIListener() {
|
||||||
|
@Override
|
||||||
|
public void onPositive() {
|
||||||
|
releasePlayer();
|
||||||
|
if (mMakeLrcListener != null) {
|
||||||
|
mMakeLrcListener.closeView();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegative() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}).setCancelable(true, false).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleUIMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
|
||||||
|
case INITAUDIODATA:
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAY:
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(true);
|
||||||
|
mMusicSeekBar.setMax((int) mMediaPlayer.getDuration());
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
|
||||||
|
//更新歌词
|
||||||
|
if (mManyLyricsView.getLyricsReader() != null && mManyLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC && mManyLyricsView.getLrcPlayerStatus() != AbstractLrcView.LRCPLAYERSTATUS_PLAY) {
|
||||||
|
mManyLyricsView.play((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.INVISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PLAYING:
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
|
||||||
|
//更新歌词
|
||||||
|
if (mManyLyricsView.getLyricsReader() != null && mManyLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC && mManyLyricsView.getLrcPlayerStatus() != AbstractLrcView.LRCPLAYERSTATUS_PLAY) {
|
||||||
|
mManyLyricsView.play((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_PAUSE:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
mMediaPlayer.pause();
|
||||||
|
mMusicSeekBar.setProgress((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
if (mManyLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC) {
|
||||||
|
mManyLyricsView.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AUDIO_FINISH:
|
||||||
|
|
||||||
|
mWorkerHandler.removeCallbacks(mPlayRunnable);
|
||||||
|
|
||||||
|
mPlayImg.setVisibility(View.VISIBLE);
|
||||||
|
mPauseImg.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
mMusicSeekBar.setEnabled(false);
|
||||||
|
mMusicSeekBar.setProgress(0);
|
||||||
|
mMusicSeekBar.setSecondaryProgress(0);
|
||||||
|
mMusicSeekBar.setMax(0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case INITLRCVIEW:
|
||||||
|
|
||||||
|
LyricsReader lyricsReader = new LyricsReader();
|
||||||
|
lyricsReader.setLyricsInfo(mLyricsInfo);
|
||||||
|
|
||||||
|
//加载歌词
|
||||||
|
mManyLyricsView.setLyricsReader(lyricsReader);
|
||||||
|
if (mExtraLrcType == MakeExtraLrcFragment.EXTRA_LRC_TYPE_TRANSLATE && lyricsReader.getTranslateLrcLineInfos() != null && lyricsReader.getTranslateLrcLineInfos().size() > 0) {
|
||||||
|
mManyLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLATELRC);
|
||||||
|
} else if (mExtraLrcType == MakeExtraLrcFragment.EXTRA_LRC_TYPE_TRANSLITERATION && lyricsReader.getTransliterationLrcLineInfos() != null && lyricsReader.getTransliterationLrcLineInfos().size() > 0) {
|
||||||
|
mManyLyricsView.setExtraLrcStatus(AbstractLrcView.EXTRALRCSTATUS_SHOWTRANSLITERATIONLRC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
if (mManyLyricsView.getLrcStatus() == AbstractLrcView.LRCSTATUS_LRC && mManyLyricsView.getLrcPlayerStatus() != AbstractLrcView.LRCPLAYERSTATUS_PLAY)
|
||||||
|
mManyLyricsView.play((int) mMediaPlayer.getCurrentPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 播放线程
|
||||||
|
*/
|
||||||
|
private Runnable mPlayRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying() && !isSeekTo) {
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAYING);
|
||||||
|
mWorkerHandler.postDelayed(mPlayRunnable, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleWorkerMessage(Message msg) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置音频数据
|
||||||
|
*
|
||||||
|
* @param audioInfo
|
||||||
|
*/
|
||||||
|
public void setAudioInfo(AudioInfo audioInfo) {
|
||||||
|
audioInfo.setPlayProgress(0);
|
||||||
|
this.mAudioInfo = audioInfo;
|
||||||
|
if (!TextUtils.isEmpty(mAudioInfo.getFilePath())) {
|
||||||
|
mUIHandler.sendEmptyMessage(INITAUDIODATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置歌词数据
|
||||||
|
*
|
||||||
|
* @param lyricsInfo
|
||||||
|
*/
|
||||||
|
public void setLyricsInfo(LyricsInfo lyricsInfo) {
|
||||||
|
this.mLyricsInfo = lyricsInfo;
|
||||||
|
mUIHandler.sendEmptyMessage(INITLRCVIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化音频数据
|
||||||
|
*/
|
||||||
|
public void initPlayerData() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMediaPlayer = new IjkMediaPlayer();
|
||||||
|
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
|
mMediaPlayer.setDataSource(mAudioInfo.getFilePath());
|
||||||
|
mMediaPlayer.prepareAsync();
|
||||||
|
//播放器完成回调
|
||||||
|
mMediaPlayer.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() {
|
||||||
|
@Override
|
||||||
|
public void onCompletion(IMediaPlayer mp) {
|
||||||
|
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_FINISH);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnSeekCompleteListener(new IMediaPlayer.OnSeekCompleteListener() {
|
||||||
|
@Override
|
||||||
|
public void onSeekComplete(IMediaPlayer mp) {
|
||||||
|
isSeekTo = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMediaPlayer.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() {
|
||||||
|
@Override
|
||||||
|
public void onPrepared(IMediaPlayer mp) {
|
||||||
|
mUIHandler.sendEmptyMessage(AUDIO_PLAY);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
releasePlayer();
|
||||||
|
if (mManyLyricsView != null)
|
||||||
|
mManyLyricsView.release();
|
||||||
|
super.onDestroyView();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 释放播放器
|
||||||
|
*/
|
||||||
|
private void releasePlayer() {
|
||||||
|
|
||||||
|
if (mMediaPlayer != null) {
|
||||||
|
if (mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.stop();
|
||||||
|
}
|
||||||
|
mMediaPlayer.release();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtraLrcType(int extraLrcType) {
|
||||||
|
this.mExtraLrcType = extraLrcType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMakeLrcListener(MakeLrcActivity.MakeLrcListener makeLrcListener) {
|
||||||
|
this.mMakeLrcListener = makeLrcListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
app/src/main/java/com/zlm/hp/handler/WeakRefHandler.java
Normal file
39
app/src/main/java/com/zlm/hp/handler/WeakRefHandler.java
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.zlm.hp.handler;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by zhangliangming on 2018-08-23.
|
||||||
|
*/
|
||||||
|
public class WeakRefHandler<T> extends Handler {
|
||||||
|
private WeakReference<T> mWeakReference;
|
||||||
|
private Callback mCallback;
|
||||||
|
|
||||||
|
public WeakRefHandler(Looper looper, T t, Callback callback) {
|
||||||
|
super(looper);
|
||||||
|
mCallback = callback;
|
||||||
|
mWeakReference = new WeakReference<>(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
if (isAlive() && mCallback != null) {
|
||||||
|
mCallback.handleMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否还存活
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isAlive() {
|
||||||
|
T t = mWeakReference.get();
|
||||||
|
return t != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
232
app/src/main/java/com/zlm/hp/http/APIHttpClient.java
Normal file
232
app/src/main/java/com/zlm/hp/http/APIHttpClient.java
Normal file
|
|
@ -0,0 +1,232 @@
|
||||||
|
package com.zlm.hp.http;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.zlm.hp.entity.AudioInfo;
|
||||||
|
import com.zlm.hp.entity.VideoInfo;
|
||||||
|
import com.zlm.hp.util.NetUtil;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by zhangliangming on 2018-07-29.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public abstract class APIHttpClient {
|
||||||
|
/**
|
||||||
|
* 搜索-歌曲
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param keyword
|
||||||
|
* @param page
|
||||||
|
* @param pagesize
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult searchSongList(Context context, String keyword, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索-专辑
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param keyword
|
||||||
|
* @param page
|
||||||
|
* @param pagesize
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult searchAlbumList(Context context, String keyword, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索-歌单
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param keyword
|
||||||
|
* @param page
|
||||||
|
* @param pagesize
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult searchSpecialList(Context context, String keyword, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌曲详情:只要获取下载路径、图片等信息
|
||||||
|
*
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract Object getSongInfo(Context context, String hash, AudioInfo audioInfo, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音乐新歌榜
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult lastSongList(Context context, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排行榜
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult rankList(Context context, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排行榜/歌曲列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult rankSongList(Context context, String rankid, String ranktype, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音乐.歌单
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult specialList(Context context, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 音乐.歌单/歌曲列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult specialSongList(Context context, String specialid, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手分类
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult singerClassList(Context context, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手分类/歌手列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult singeList(Context context, String classid, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 歌手分类/歌手列表/歌曲列表
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult singeSongList(Context context, String singerid, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 热门搜索
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult searchHotList(Context context, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索-mv
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param keyword
|
||||||
|
* @param page
|
||||||
|
* @param pagesize
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult searchMVList(Context context, String keyword, int page, int pagesize, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取mv歌曲信息:下载地址、图片等
|
||||||
|
*
|
||||||
|
* @param hash
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract Object getMVInfo(Context context, String hash, VideoInfo videoInfo, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌手头像
|
||||||
|
*
|
||||||
|
* @param singerName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult getSingerIcon(Context context, String singerName, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌手写真图片
|
||||||
|
*
|
||||||
|
* @param singerName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult getSingerPicList(Context context, String singerName,boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索-歌词
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param keyword 歌曲名(不为空):singerName + " - " + songName
|
||||||
|
* @param duration 歌曲总时长(毫秒)(不为空)
|
||||||
|
* @param hash 歌曲Hash值
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult searchLyricsList(Context context, String keyword, String duration, String hash, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌词信息
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param id (不为空)
|
||||||
|
* @param accesskey (不为空)
|
||||||
|
* @param askWifi
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult getLyricsInfo(Context context, String id, String accesskey, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取歌词信息
|
||||||
|
*
|
||||||
|
* @param keyword singerName + " - " + songName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract HttpReturnResult getLyricsInfo(Context context, String keyword, String duration, String hash, boolean askWifi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络检测
|
||||||
|
*
|
||||||
|
* @param askWifi 是否需要是wifi环境
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public HttpReturnResult checkNetWork(Context context, boolean askWifi) {
|
||||||
|
HttpReturnResult httpReturnResult = null;
|
||||||
|
if (!NetUtil.isNetworkAvailable(context)) {
|
||||||
|
//网络不可用
|
||||||
|
httpReturnResult = new HttpReturnResult();
|
||||||
|
httpReturnResult.setStatus(HttpReturnResult.STATUS_ERROR_NONET);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (askWifi && !NetUtil.isWifiConnected(context)) {
|
||||||
|
//非wifi环境
|
||||||
|
httpReturnResult = new HttpReturnResult();
|
||||||
|
httpReturnResult.setStatus(HttpReturnResult.STATUS_ERROR_NOWIFI);
|
||||||
|
}
|
||||||
|
return httpReturnResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user