提交 8c68f147 编写于 作者: 门心叼龙's avatar 门心叼龙

plugin init

上级 f19e1c4f
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<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>
\ No newline at end of file
......@@ -9,6 +9,12 @@
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/lib_common" />
<option value="$PROJECT_DIR$/lib_fly_db" />
<option value="$PROJECT_DIR$/lib_refresh_layout" />
<option value="$PROJECT_DIR$/plugin_fly_find" />
<option value="$PROJECT_DIR$/plugin_fly_me" />
<option value="$PROJECT_DIR$/plugin_fly_news" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownEnhProjectSettings">
<AnnotatorSettings targetHasSpaces="true" linkCaseMismatch="true" wikiCaseMismatch="true" wikiLinkHasDashes="true" notUnderWikiHome="true" targetNotWikiPageExt="true" notUnderSourceWikiHome="true" targetNameHasAnchor="true" targetPathHasAnchor="true" wikiLinkHasSlash="true" wikiLinkHasSubdir="true" wikiLinkHasOnlyAnchor="true" linkTargetsWikiHasExt="true" linkTargetsWikiHasBadExt="true" notUnderSameRepo="true" targetNotUnderVcs="false" linkNeedsExt="true" linkHasBadExt="true" linkTargetNeedsExt="true" linkTargetHasBadExt="true" wikiLinkNotInWiki="true" imageTargetNotInRaw="true" repoRelativeAcrossVcsRoots="true" multipleWikiTargetsMatch="true" unresolvedLinkReference="true" linkIsIgnored="true" anchorIsIgnored="true" anchorIsUnresolved="true" anchorLineReferenceIsUnresolved="true" anchorLineReferenceFormat="true" anchorHasDuplicates="true" abbreviationDuplicates="true" abbreviationNotUsed="true" attributeIdDuplicateDefinition="true" attributeIdNotUsed="true" footnoteDuplicateDefinition="true" footnoteUnresolved="true" footnoteDuplicates="true" footnoteNotUsed="true" macroDuplicateDefinition="true" macroUnresolved="true" macroDuplicates="true" macroNotUsed="true" referenceDuplicateDefinition="true" referenceUnresolved="true" referenceDuplicates="true" referenceNotUsed="true" referenceUnresolvedNumericId="true" enumRefDuplicateDefinition="true" enumRefUnresolved="true" enumRefDuplicates="true" enumRefNotUsed="true" enumRefLinkUnresolved="true" enumRefLinkDuplicates="true" simTocUpdateNeeded="true" simTocTitleSpaceNeeded="true" />
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="css" scriptDir="js" plainHtml="false" imageDir="" copyLinkedImages="false" imagePathType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
<component name="MarkdownNavigatorHistory">
<PasteImageHistory checkeredTransparentBackground="false" filename="image" directory="" onPasteImageTargetRef="3" onPasteLinkText="0" onPasteImageElement="1" onPasteLinkElement="1" onPasteReferenceElement="2" cornerRadius="20" borderColor="0" transparentColor="16777215" borderWidth="1" trimTop="0" trimBottom="0" trimLeft="0" trimRight="0" transparent="false" roundCorners="false" showPreview="true" bordered="false" scaled="false" cropped="false" hideInapplicableOperations="false" preserveLinkFormat="false" scale="50" scalingInterpolation="1" transparentTolerance="0" saveAsDefaultOnOK="false" linkFormat="0" addHighlights="false" showHighlightCoordinates="true" showHighlights="false" mouseSelectionAddsHighlight="false" outerFilled="false" outerFillColor="0" outerFillTransparent="true" outerFillAlpha="30">
<highlightList />
<directories />
<filenames />
</PasteImageHistory>
<CopyImageHistory checkeredTransparentBackground="false" filename="image" directory="" onPasteImageTargetRef="3" onPasteLinkText="0" onPasteImageElement="1" onPasteLinkElement="1" onPasteReferenceElement="2" cornerRadius="20" borderColor="0" transparentColor="16777215" borderWidth="1" trimTop="0" trimBottom="0" trimLeft="0" trimRight="0" transparent="false" roundCorners="false" showPreview="true" bordered="false" scaled="false" cropped="false" hideInapplicableOperations="false" preserveLinkFormat="false" scale="50" scalingInterpolation="1" transparentTolerance="0" saveAsDefaultOnOK="false" linkFormat="0" addHighlights="false" showHighlightCoordinates="true" showHighlights="false" mouseSelectionAddsHighlight="false" outerFilled="false" outerFillColor="0" outerFillTransparent="true" outerFillAlpha="30">
<highlightList />
<directories />
<filenames />
</CopyImageHistory>
<PasteLinkHistory onPasteImageTargetRef="3" onPasteTargetRef="1" onPasteLinkText="0" onPasteImageElement="1" onPasteLinkElement="1" onPasteWikiElement="2" onPasteReferenceElement="2" hideInapplicableOperations="false" preserveLinkFormat="false" useHeadingForLinkText="false" linkFormat="0" saveAsDefaultOnOK="false" />
<TableToJsonHistory>
<entries />
</TableToJsonHistory>
<TableSortHistory>
<entries />
</TableSortHistory>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="FlexmarkProjectSettings">
<FlexmarkHtmlSettings flexmarkSpecExampleRendering="0" flexmarkSpecExampleRenderHtml="false">
<flexmarkSectionLanguages>
<option name="1" value="Markdown" />
<option name="2" value="HTML" />
<option name="3" value="flexmark-ast:1" />
</flexmarkSectionLanguages>
</FlexmarkHtmlSettings>
</component>
<component name="MarkdownProjectSettings">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" synchronizePreviewPosition="true" highlightPreviewType="LINE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="true" showSelectionInPreview="true" lastLayoutSetsDefault="false">
<PanelProvider>
<provider providerId="com.vladsch.md.nav.editor.swing.html.panel" providerName="Default - Swing" />
</PanelProvider>
</PreviewSettings>
<ParserSettings gitHubSyntaxChange="false" correctedInvalidSettings="false" emojiShortcuts="1" emojiImages="0">
<PegdownExtensions>
<option name="ANCHORLINKS" value="true" />
<option name="ATXHEADERSPACE" value="true" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="INTELLIJ_DUMMY_IDENTIFIER" value="true" />
<option name="RELAXEDHRULES" value="true" />
<option name="STRIKETHROUGH" value="true" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
</PegdownExtensions>
<ParserOptions>
<option name="COMMONMARK_LISTS" value="true" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="PRODUCTION_SPEC_PARSER" value="true" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" addPageHeader="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" plantUmlConversion="0">
<GeneratorProvider>
<provider providerId="com.vladsch.md.nav.editor.text.html.generator" providerName="Unmodified 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.md.nav.editor.text.html.css" providerName="No Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
<cssUriHistory />
</CssSettings>
</component>
</project>
\ No newline at end of file
<?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>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
apply plugin: 'com.didi.virtualapk.host'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
compileSdkVersion VERSION_COMPILE_SDK
buildToolsVersion VERSION_BUILD_TOOLS
defaultConfig {
applicationId "com.fly.tour"
minSdkVersion 15
targetSdkVersion 29
minSdkVersion VERSION_MIN_SDK
targetSdkVersion VERSION_TARGET_SDK
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.didi.virtualapk:core:0.9.8'
implementation project(':lib_common')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
......@@ -8,7 +8,9 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme"
android:name=".MyApplication"
>
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
package com.fly.tour;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
import com.didi.virtualapk.PluginManager;
import com.fly.tour.common.base.BaseActivity;
import com.fly.tour.entity.MainChannel;
import java.io.File;
public class MainActivity extends BaseActivity {
private Fragment mNewsFragment;
private Fragment mFindFragment;
private Fragment mMeFragment;
private Fragment mCurrFragment;
@Override
public int onBindLayout() {
return R.layout.activity_main;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public void initView() {
loadPlugin(this,"plugin_fly_news-release.apk");
loadPlugin(this,"plugin_fly_find-release.apk");
loadPlugin(this,"plugin_fly_me-release.apk");
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
int i = menuItem.getItemId();
if (i == R.id.navigation_trip) {
switchContent(mCurrFragment, mNewsFragment, MainChannel.NEWS.name);
mCurrFragment = mNewsFragment;
return true;
} else if (i == R.id.navigation_discover) {
switchContent(mCurrFragment, mFindFragment, MainChannel.FIND.name);
mCurrFragment = mFindFragment;
return true;
} else if (i == R.id.navigation_me) {
switchContent(mCurrFragment, mMeFragment, MainChannel.ME.name);
mCurrFragment = mMeFragment;
return true;
}
return false;
}
});
if (PluginManager.getInstance(this).getLoadedPlugin("com.fly.tour.news") == null) {
Toast.makeText(this, "plugin [com.fly.tour.news] not loaded", Toast.LENGTH_SHORT).show();
return;
}
mNewsFragment = Fragment.instantiate(this,"com.fly.tour.news.fragment.MainNewsFragment");
if (PluginManager.getInstance(this).getLoadedPlugin("com.fly.tour.find") == null) {
Toast.makeText(this, "plugin [com.fly.tour.find] not loaded", Toast.LENGTH_SHORT).show();
return;
}
mFindFragment = Fragment.instantiate(this,"com.fly.tour.find.fragment.MainFindFragment");
if (PluginManager.getInstance(this).getLoadedPlugin("com.fly.tour.me") == null) {
Toast.makeText(this, "plugin [com.fly.tour.me] not loaded", Toast.LENGTH_SHORT).show();
return;
}
mMeFragment = Fragment.instantiate(this,"com.fly.tour.me.fragment.MainMeFragment");
mCurrFragment = mNewsFragment;
if (mNewsFragment != null) {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, mNewsFragment, MainChannel.NEWS.name).commit();
}
}
@Override
public void initData() {
}
public void switchContent(Fragment from, Fragment to, String tag) {
if (from == null || to == null) {
return;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (!to.isAdded()) {
transaction.hide(from).add(R.id.frame_content, to, tag).commit();
} else {
transaction.hide(from).show(to).commit();
}
}
private void loadPlugin(Context base,String apkname) {
try {
PluginManager pluginManager = PluginManager.getInstance(base);
File file = new File(base.getFilesDir(), apkname);
java.io.InputStream inputStream = base.getAssets().open(apkname, 2);
java.io.FileOutputStream outputStream = new java.io.FileOutputStream(file);
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
outputStream.write(buf, 0, len);
}
outputStream.close();
inputStream.close();
pluginManager.loadPlugin(file);
Log.i(TAG, "Loaded plugin from assets: " + file);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.fly.tour;
import android.content.Context;
import com.didi.virtualapk.PluginManager;
import com.fly.tour.common.BaseApplication;
import com.fly.tour.common.manager.NewsDBManager;
/**
* Description: <MyApplication><br>
* Author: mxdl<br>
* Date: 2018/12/27<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyApplication extends BaseApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
PluginManager.getInstance(base).init();
}
@Override
public void onCreate() {
super.onCreate();
}
}
package com.fly.tour.entity;
/**
* Description: <主频道类型><br>
* Author: mxdl<br>
* Date: 2018/12/12<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public enum MainChannel {
NEWS(0,"NEWS"), FIND(1,"FIND"),ME(2,"ME");
public int id;
public String name;
MainChannel(int id, String name){
this.id = id;
this.name = name;
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#1976D2" android:state_checked="true"/>
<item android:color="#888888" android:state_checked="false"/>
</selector>
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
......@@ -18,10 +18,10 @@
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
android:offset="0.0"/>
<item
android:color="#00000000"
android:offset="1.0" />
android:offset="1.0"/>
</gradient>
</aapt:attr>
</path>
......@@ -29,6 +29,6 @@
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
android:strokeWidth="1"
android:strokeColor="#00000000"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/tabbar_icon_find_normal"/>
<item android:drawable="@mipmap/tabbar_icon_find_normal" android:state_selected="false"/>
<item android:drawable="@mipmap/tabbar_icon_find_select" android:state_selected="true"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/tabbar_icon_my_normal"/>
<item android:drawable="@mipmap/tabbar_icon_my_normal" android:state_selected="false"/>
<item android:drawable="@mipmap/tabbar_icon_my_select" android:state_selected="true"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@mipmap/tabbar_icon_trip_normal"/>
<item android:drawable="@mipmap/tabbar_icon_trip_normal" android:state_selected="false"/>
<item android:drawable="@mipmap/tabbar_icon_trip_select" android:state_selected="true"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
android:id="@+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_above="@+id/navigation"
/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:menu="@menu/menu_navigation"
app:labelVisibilityMode="labeled"
app:itemTextColor="@color/color_state_menu_navi"
app:itemIconTint="@color/color_state_menu_navi"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SplashActivity">
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_trip"
android:icon="@drawable/ic_bottom_trip"
android:title="@string/title_news"/>
<item
android:id="@+id/navigation_discover"
android:icon="@drawable/ic_bottom_discover"
android:title="@string/title_find"/>
<item
android:id="@+id/navigation_me"
android:icon="@drawable/ic_bottom_my"
android:title="@string/title_my"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
<resources>
<string name="app_name">android-mvp-mvvm-flytour</string>
<string name="app_name">飞旅新闻</string>
<string name="title_news">新闻</string>
<string name="title_find">发现</string>
<string name="title_my">我的</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
......@@ -7,18 +7,30 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.didi.virtualapk:gradle:0.9.8.6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
VERSION_COMPILE_SDK = 28
VERSION_BUILD_TOOLS = '26.0.2'
VERSION_MIN_SDK = 19
VERSION_TARGET_SDK = 28
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/releases/' }
}
}
......
......@@ -23,3 +23,4 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.useDexArchive=false
......@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
此差异已折叠。
android.arch.core:common:1.1.1 11567
android.arch.core:runtime:1.1.1 0
android.arch.lifecycle:common:1.1.1 20618
android.arch.lifecycle:livedata-core:1.1.1 0
android.arch.lifecycle:livedata:1.1.1 0
android.arch.lifecycle:runtime:1.1.1 4096
android.arch.lifecycle:viewmodel:1.1.1 4096
com.android.support.constraint:constraint-layout-solver:1.1.3 120857
com.android.support.constraint:constraint-layout:1.1.3 0
com.android.support:animated-vector-drawable:28.0.0 4096
com.android.support:appcompat-v7:28.0.0 4096
com.android.support:asynclayoutinflater:28.0.0 0
com.android.support:cardview-v7:28.0.0 0
com.android.support:collections:28.0.0 42329
com.android.support:coordinatorlayout:28.0.0 4096
com.android.support:cursoradapter:28.0.0 0
com.android.support:customview:28.0.0 0
com.android.support:design:28.0.0 4096
com.android.support:documentfile:28.0.0 0
com.android.support:drawerlayout:28.0.0 4096
com.android.support:interpolator:28.0.0 0
com.android.support:loader:28.0.0 0
com.android.support:localbroadcastmanager:28.0.0 0
com.android.support:print:28.0.0 4096
com.android.support:recyclerview-v7:28.0.0 4096
com.android.support:slidingpanelayout:28.0.0 0
com.android.support:support-annotations:28.0.0 27865
com.android.support:support-compat:28.0.0 4096
com.android.support:support-core-ui:28.0.0 0
com.android.support:support-core-utils:28.0.0 0
com.android.support:support-fragment:28.0.0 4096
com.android.support:support-vector-drawable:28.0.0 0
com.android.support:swiperefreshlayout:28.0.0 4096
com.android.support:transition:28.0.0 4096
com.android.support:versionedparcelable:28.0.0 4096
com.android.support:viewpager:28.0.0 0
com.didi.virtualapk:core:0.9.8 4096
com.github.lovetuzitong:MultiImageSelector:1.2 4096
com.github.tbruyelle:rxpermissions:0.10.2 0
com.google.code.gson:gson:2.6.1 230882
com.squareup.picasso:picasso:2.4.0 114737
com.trello.rxlifecycle2:rxlifecycle-android:2.2.1 0
com.trello.rxlifecycle2:rxlifecycle-components:2.2.1 0
com.trello.rxlifecycle2:rxlifecycle:2.2.1 9881
io.reactivex.rxjava2:rxandroid:2.0.1 0
io.reactivex.rxjava2:rxjava:2.1.16 2316448
lib_common:debug:unspecified 0
lib_fly_db:debug:unspecified 0
lib_refresh_layout:debug:unspecified 0
org.greenrobot:eventbus:3.1.1 59043
org.reactivestreams:reactive-streams:1.0.2 2097
-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIEWWZdhTANBgkqhkiG9w0BAQsFADBfMQ4wDAYDVQQGDAV6aF9jbjEQMA4G
A1UECBMHYmVpamluZzEQMA4GA1UEBxMHYmVpamluZzENMAsGA1UEChMEZGlkaTEMMAoGA1UECxMD
YXBwMQwwCgYDVQQDEwNyeWcwHhcNMTcwNTA4MDkxOTM0WhcNNDQwOTIzMDkxOTM0WjBfMQ4wDAYD
VQQGDAV6aF9jbjEQMA4GA1UECBMHYmVpamluZzEQMA4GA1UEBxMHYmVpamluZzENMAsGA1UEChME
ZGlkaTEMMAoGA1UECxMDYXBwMQwwCgYDVQQDEwNyeWcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQC6d9Pq0+qedUEuHgYhIuROidDWVMSECAq2+MTlX1kn1gGgAKiAt7P6c864YlFCB8Mq
4Q8R8HR9SMprTD4NPUt7nsf3jQiFSOH0f9PvOI3fWMLNCpUq64GthcwHd3bVqOy6r5h7f3Jd9Pi3
PmkhFs6FwCNaFoPkQioDdnE+8bNKOC53rsx5gqHFzs0xpYYZLz7+tP7OSm9KQe19VBwPOI3MxgPD
6dbEWRNI4FPk6yNC3k9Fq8HrtCzlfapmEsdxpBjrQ3DUeegvtfQhqZtLujj9X894cuoCR05eowoi
6mamKRdRErQ7JMhkUYMwJQvKYLuLr1JElEYHJ5iT46Ph8FVzAgMBAAGjITAfMB0GA1UdDgQWBBQ2
yNaLVuMnjEKQiMSz+/FjbjPYHTANBgkqhkiG9w0BAQsFAAOCAQEAnFXbS07Zu8vphohhZ1nHPeNN
8GGcbSllO7xwbONPng+uTFGldIUhPP9lmKkw/5bA1T/57tjbfmNph9li6MfuwO4CECkG2WTQNpr9
Y8ZcvM0sh3unx9wHkPJQ43Cvp6vCxsaor/ALT4UbTTHtWRpwcZUBxsgdNQDpwM1u0ye5uMd5E/P6
hlsdI0GdtnMdyZrCInwhQbBEHYpSerVyRpCRq9pa72kP865fDB9zCyLSekctvfZBYkEKEMX9QVfs
d9tJ7vxqABxUjNPYWlAxLlRPf/Dz4NDyeYHuTjEZW46NErqJ8GQGqvS+MG4OehqV1SCIQoHkCJQ2
o7w3hv2XVmdozw==
-----END CERTIFICATE-----
apply plugin: 'com.android.library'
android {
compileSdkVersion VERSION_COMPILE_SDK
defaultConfig {
minSdkVersion VERSION_MIN_SDK
targetSdkVersion VERSION_TARGET_SDK
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
api project(":lib_refresh_layout")
api project(':lib_fly_db')
api 'com.android.support:appcompat-v7:28.0.0'
api 'com.android.support:design:28.0.0'
api 'com.android.support:recyclerview-v7:28.0.0'
api 'com.android.support.constraint:constraint-layout:1.1.3'
api 'org.greenrobot:eventbus:3.1.1'
api 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
api 'com.trello.rxlifecycle2:rxlifecycle-android:2.2.1'
api 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
api 'com.google.code.gson:gson:2.6.1'
api 'com.github.tbruyelle:rxpermissions:0.10.2'
api 'com.github.lovetuzitong:MultiImageSelector:1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
# 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
package com.fly.tour.common;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* 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 ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.fly.tour.common.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fly.tour.common">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
package com.fly.tour.common;
import android.app.Application;
import com.fly.tour.common.util.log.KLog;
/**
* Description: <初始化应用程序><br>
* Author: mxdl<br>
* Date: 2018/6/6<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class BaseApplication extends Application {
private static BaseApplication mApplication;
@Override
public void onCreate() {
super.onCreate();
mApplication = this;
}
public static BaseApplication getInstance(){
return mApplication;
}
}
package com.fly.tour.common.base;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;
import com.fly.tour.common.R;
import com.fly.tour.common.event.common.BaseActivityEvent;
import com.fly.tour.common.manager.ActivityManager;
import com.fly.tour.common.mvp.BaseView;
import com.fly.tour.common.util.NetUtil;
import com.fly.tour.common.view.LoadingInitView;
import com.fly.tour.common.view.LoadingTransView;
import com.fly.tour.common.view.NetErrorView;
import com.fly.tour.common.view.NoDataView;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
/**
* Description: <BaseActivity><br>
* Author: mxdl<br>
* Date: 2018/1/16<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseActivity extends RxAppCompatActivity implements BaseView {
protected static final String TAG = BaseActivity.class.getSimpleName();
protected TextView mTxtTitle;
protected Toolbar mToolbar;
protected NetErrorView mNetErrorView;
protected NoDataView mNoDataView;
protected LoadingInitView mLoadingInitView;
protected LoadingTransView mLoadingTransView;
private boolean isrefresh = false;
private ViewStub mViewStubToolbar;
private ViewStub mViewStubContent;
private ViewStub mViewStubInitLoading;
private ViewStub mViewStubTransLoading;
private ViewStub mViewStubNoData;
private ViewStub mViewStubError;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_root);
initCommonView();
initView();
initListener();
initData();
EventBus.getDefault().register(this);
ActivityManager.getInstance().addActivity(this);
}
protected void initCommonView() {
mViewStubToolbar = findViewById(R.id.view_stub_toolbar);
mViewStubContent = findViewById(R.id.view_stub_content);
mViewStubContent = findViewById(R.id.view_stub_content);
mViewStubInitLoading = findViewById(R.id.view_stub_init_loading);
mViewStubTransLoading = findViewById(R.id.view_stub_trans_loading);
mViewStubError = findViewById(R.id.view_stub_error);
mViewStubNoData = findViewById(R.id.view_stub_nodata);
if (enableToolbar()) {
mViewStubToolbar.setLayoutResource(onBindToolbarLayout());
View view = mViewStubToolbar.inflate();
initToolbar(view);
}
mViewStubContent.setLayoutResource(onBindLayout());
mViewStubContent.inflate();
}
protected void initToolbar(View view) {
mToolbar = view.findViewById(R.id.toolbar_root);
mTxtTitle = view.findViewById(R.id.toolbar_title);
if (mToolbar != null) {
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
}
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
if (mTxtTitle != null && !TextUtils.isEmpty(title)) {
mTxtTitle.setText(title);
}
//可以再次覆盖设置title
String tootBarTitle = getTootBarTitle();
if (mTxtTitle != null && !TextUtils.isEmpty(tootBarTitle)) {
mTxtTitle.setText(tootBarTitle);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
ActivityManager.getInstance().finishActivity(this);
}
public int onBindToolbarLayout() {
return R.layout.common_toolbar;
}
public abstract int onBindLayout();
public abstract void initView();
public abstract void initData();
public void initListener() {
}
@Override
public void finishActivity() {
finish();
}
public String getTootBarTitle() {
return "";
}
public boolean enableToolbar() {
return true;
}
public void showInitLoadView() {
showInitLoadView(true);
}
public void hideInitLoadView() {
showInitLoadView(false);
}
@Override
public void showTransLoadingView() {
showTransLoadingView(true);
}
@Override
public void hideTransLoadingView() {
showTransLoadingView(false);
}
public void showNoDataView() {
showNoDataView(true);
}
public void showNoDataView(int resid) {
showNoDataView(true, resid);
}
public void hideNoDataView() {
showNoDataView(false);
}
public void hideNetWorkErrView() {
showNetWorkErrView(false);
}
public void showNetWorkErrView() {
showNetWorkErrView(true);
}
private void showInitLoadView(boolean show) {
if (mLoadingInitView == null) {
View view = mViewStubInitLoading.inflate();
mLoadingInitView = view.findViewById(R.id.view_init_loading);
}
mLoadingInitView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoadingInitView.loading(show);
}
private void showNetWorkErrView(boolean show) {
if (mNetErrorView == null) {
View view = mViewStubError.inflate();
mNetErrorView = view.findViewById(R.id.view_net_error);
mNetErrorView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!NetUtil.checkNetToast()) {
return;
}
hideNetWorkErrView();
initData();
}
});
}
mNetErrorView.setVisibility(show ? View.VISIBLE : View.GONE);
}
private void showNoDataView(boolean show) {
if (mNoDataView == null) {
View view = mViewStubNoData.inflate();
mNoDataView = view.findViewById(R.id.view_no_data);
}
mNoDataView.setVisibility(show ? View.VISIBLE : View.GONE);
}
private void showNoDataView(boolean show, int resid) {
showNoDataView(show);
if (show) {
mNoDataView.setNoDataView(resid);
}
}
private void showTransLoadingView(boolean show) {
if (mLoadingTransView == null) {
View view = mViewStubTransLoading.inflate();
mLoadingTransView = view.findViewById(R.id.view_trans_loading);
}
mLoadingTransView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoadingTransView.loading(show);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public <T> void onEvent(BaseActivityEvent<T> event) {
}
}
package com.fly.tour.common.base;
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 java.util.ArrayList;
import java.util.List;
/**
* Description: <BaseAdapter><br>
* Author: mxdl<br>
* Date: 2018/1/15<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseAdapter<E, VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
protected Context mContext;
protected List<E> mList;
protected OnItemClickListener mItemClickListener;
protected OnItemLongClickListener mOnItemLongClickListener;
public BaseAdapter(Context context) {
mContext = context;
mList = new ArrayList<E>();
}
@NonNull
@Override
public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
int layoutid = onBindLayout();
View view = LayoutInflater.from(mContext).inflate(layoutid, parent, false);
return onCreateHolder(view);
}
//绑定布局文件
protected abstract int onBindLayout();
//创建一个holder
protected abstract VH onCreateHolder(View view);
//绑定数据
protected abstract void onBindData(VH holder, E e,int positon);
@Override
public void onBindViewHolder(@NonNull VH holder, final int position) {
final E e = mList.get(position);
if (mItemClickListener != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mItemClickListener.onItemClick(e,position);
}
});
}
if (mOnItemLongClickListener != null) {
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return mOnItemLongClickListener.onItemLongClick(e,position);
}
});
}
onBindData(holder, e,position);
}
@Override
public int getItemCount() {
return mList.size();
}
public void addAll(List<E> list) {
if (list != null && list.size() > 0) {
mList.addAll(list);
notifyDataSetChanged();
}
}
public void refresh(List<E> list){
mList.clear();
if (list != null && list.size() > 0) {
mList.addAll(list);
}
notifyDataSetChanged();
}
public void remove(int positon) {
mList.remove(positon);
notifyDataSetChanged();
}
public void remove(E e) {
mList.remove(e);
notifyDataSetChanged();
}
public void add(E e) {
mList.add(e);
notifyDataSetChanged();
}
public void addLast(E e) {
add(e);
}
public void addFirst(E e) {
mList.add(0,e);
notifyDataSetChanged();
}
public void clear() {
mList.clear();
notifyDataSetChanged();
}
public List<E> getDataList() {
return mList;
}
public void setItemClickListener(OnItemClickListener itemClickListener) {
mItemClickListener = itemClickListener;
}
public void setOnItemLongClickListener(OnItemLongClickListener onItemLongClickListener) {
mOnItemLongClickListener = onItemLongClickListener;
}
public interface OnItemClickListener<E> {
void onItemClick(E e, int position);
}
public interface OnItemLongClickListener<E> {
boolean onItemLongClick(E e, int postion);
}
@Override
public int getItemViewType(int position) {
return super.getItemViewType(position);
}
public List<E> getListData(){
return mList;
}
}
package com.fly.tour.common.base;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.TextView;
import com.fly.tour.common.R;
import com.fly.tour.common.event.common.BaseFragmentEvent;
import com.fly.tour.common.mvp.BaseView;
import com.fly.tour.common.util.NetUtil;
import com.fly.tour.common.util.log.KLog;
import com.fly.tour.common.view.LoadingInitView;
import com.fly.tour.common.view.LoadingTransView;
import com.fly.tour.common.view.NetErrorView;
import com.fly.tour.common.view.NoDataView;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
/**
* Description: <BaseFragment><br>
* Author: mxdl<br>
* Date: 2018/1/15<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseFragment extends Fragment implements BaseView {
protected static final String TAG = BaseFragment.class.getSimpleName();
protected RxAppCompatActivity mActivity;
protected View mView;
protected TextView mTxtTitle;
protected Toolbar mToolbar;
protected NetErrorView mNetErrorView;
protected NoDataView mNoDataView;
protected LoadingInitView mLoadingInitView;
protected LoadingTransView mLoadingTransView;
private ViewStub mViewStubToolbar;
private ViewStub mViewStubContent;
private ViewStub mViewStubInitLoading;
private ViewStub mViewStubTransLoading;
private ViewStub mViewStubNoData;
private ViewStub mViewStubError;
private boolean isViewCreated = false;
private boolean isViewVisable = false;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity = (RxAppCompatActivity) getActivity();
EventBus.getDefault().register(this);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_root, container, false);
initCommonView(mView);
initView(mView);
initListener();
return mView;
}
public void initCommonView(View view) {
mViewStubToolbar = view.findViewById(R.id.view_stub_toolbar);
mViewStubContent = view.findViewById(R.id.view_stub_content);
mViewStubContent = view.findViewById(R.id.view_stub_content);
mViewStubInitLoading = view.findViewById(R.id.view_stub_init_loading);
mViewStubTransLoading = view.findViewById(R.id.view_stub_trans_loading);
mViewStubNoData = view.findViewById(R.id.view_stub_nodata);
mViewStubError = view.findViewById(R.id.view_stub_error);
if (enableToolbar()) {
mViewStubToolbar.setLayoutResource(onBindToolbarLayout());
View viewTooBbar = mViewStubToolbar.inflate();
initTooBar(viewTooBbar);
}
mViewStubContent.setLayoutResource(onBindLayout());
mViewStubContent.inflate();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
isViewCreated = true;
//如果启用了懒加载就进行懒加载,否则就进行预加载
if (enableLazyData()) {
lazyLoad();
} else {
initData();
}
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
isViewVisable = isVisibleToUser;
//如果启用了懒加载就进行懒加载,
if (enableLazyData() && isViewVisable) {
lazyLoad();
}
}
private void lazyLoad() {
//这里进行双重标记判断,必须确保onCreateView加载完毕且页面可见,才加载数据
KLog.v("MYTAG","lazyLoad start...");
KLog.v("MYTAG","isViewCreated:"+isViewCreated);
KLog.v("MYTAG","isViewVisable"+isViewVisable);
if (isViewCreated && isViewVisable) {
initData();
//数据加载完毕,恢复标记,防止重复加载
isViewCreated = false;
isViewVisable = false;
}
}
//默认不启用懒加载
public boolean enableLazyData() {
return false;
}
@Override
public void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
protected void initTooBar(View view) {
mToolbar = view.findViewById(R.id.toolbar_root);
mTxtTitle = view.findViewById(R.id.toolbar_title);
if (mToolbar != null) {
mActivity.setSupportActionBar(mToolbar);
mActivity.getSupportActionBar().setDisplayShowTitleEnabled(false);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mActivity.onBackPressed();
}
});
}
if (mTxtTitle != null) {
mTxtTitle.setText(getToolbarTitle());
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
public <T> void onEvent(BaseFragmentEvent<T> event) {
}
public abstract int onBindLayout();
public abstract void initView(View view);
public void initView() {
}
public abstract void initData();
public abstract String getToolbarTitle();
public void initListener() {
}
@Override
public void finishActivity() {
mActivity.finish();
}
public boolean enableToolbar() {
return false;
}
public int onBindToolbarLayout() {
return R.layout.common_toolbar;
}
public void showInitLoadView() {
showInitLoadView(true);
}
public void hideInitLoadView() {
showInitLoadView(false);
}
@Override
public void showTransLoadingView() {
showTransLoadingView(true);
}
@Override
public void hideTransLoadingView() {
showTransLoadingView(false);
}
public void showNoDataView() {
showNoDataView(true);
}
public void showNoDataView(int resid) {
showNoDataView(true,resid);
}
public void hideNoDataView() {
showNoDataView(false);
}
public void showNetWorkErrView() {
showNetWorkErrView(true);
}
public void hideNetWorkErrView() {
showNetWorkErrView(false);
}
private void showInitLoadView(boolean show) {
if (mLoadingInitView == null) {
View view = mViewStubInitLoading.inflate();
mLoadingInitView = view.findViewById(R.id.view_init_loading);
}
mLoadingInitView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoadingInitView.loading(show);
}
private void showNetWorkErrView(boolean show) {
if (mNetErrorView == null) {
View view = mViewStubError.inflate();
mNetErrorView = view.findViewById(R.id.view_net_error);
mNetErrorView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!NetUtil.checkNetToast()) {
return;
}
hideNetWorkErrView();
initData();
}
});
}
mNetErrorView.setVisibility(show ? View.VISIBLE : View.GONE);
}
private void showNoDataView(boolean show) {
if (mNoDataView == null) {
View view = mViewStubNoData.inflate();
mNoDataView = view.findViewById(R.id.view_no_data);
}
mNoDataView.setVisibility(show ? View.VISIBLE : View.GONE);
}
private void showNoDataView(boolean show,int resid) {
showNoDataView(show);
if(show){
mNoDataView.setNoDataView(resid);
}
}
private void showTransLoadingView(boolean show) {
if (mLoadingTransView == null) {
View view = mViewStubTransLoading.inflate();
mLoadingTransView = view.findViewById(R.id.view_trans_loading);
}
mLoadingTransView.setVisibility(show ? View.VISIBLE : View.GONE);
mLoadingTransView.loading(show);
}
}
package com.fly.tour.common.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.fly.tour.common.mvp.BaseModel;
import com.fly.tour.common.mvp.BasePresenter;
/**
* Description: <BaseMvpActivity><br>
* Author: mxdl<br>
* Date: 2018/1/16<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseMvpActivity<M extends BaseModel,V,P extends BasePresenter<M,V>> extends BaseActivity {
protected P mPresenter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
mPresenter = initPresenter();
if(mPresenter != null){
mPresenter.attach((V) this);
mPresenter.injectLifecycle(this);
}
super.onCreate(savedInstanceState);
}
public abstract P initPresenter();
@Override
protected void onDestroy() {
super.onDestroy();
if(mPresenter != null){
mPresenter.detach();
}
}
}
package com.fly.tour.common.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.fly.tour.common.mvp.BaseModel;
import com.fly.tour.common.mvp.BasePresenter;
/**
* Description: <BaseMvpFragment><br>
* Author: mxdl<br>
* Date: 2018/1/15<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseMvpFragment<M extends BaseModel,V,P extends BasePresenter<M,V>> extends BaseFragment {
protected P mPresenter;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPresenter = initPresenter();
if(mPresenter != null){
mPresenter.attach((V) this);
mPresenter.injectLifecycle(mActivity);
}
}
@Override
public void onDestroy() {
if(mPresenter != null){
mPresenter.detach();
}
super.onDestroy();
}
public abstract P initPresenter();
}
package com.fly.tour.common.base;
import com.fly.tour.common.mvp.BaseModel;
import com.fly.tour.common.mvp.BaseRefreshPresenter;
import com.fly.tour.common.mvp.BaseRefreshView;
import com.refresh.lib.BaseRefreshLayout;
import com.refresh.lib.DaisyRefreshLayout;
/**
* Description: <下拉刷新、上拉加载更多的Activity><br>
* Author: mxdl<br>
* Date: 2018/2/26<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseRefreshActivity<M extends BaseModel, V extends BaseRefreshView<T>, P extends BaseRefreshPresenter<M, V, T>, T> extends BaseMvpActivity<M, V, P> implements BaseRefreshView<T> {
protected DaisyRefreshLayout mRefreshLayout;
@Override
protected void initCommonView() {
super.initCommonView();
initRefreshView();
}
public void initRefreshView() {
mRefreshLayout = findViewById(onBindRreshLayout());
// 下拉刷新
mRefreshLayout.setOnRefreshListener(new BaseRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
onRefreshEvent();
}
});
// 上拉加载
mRefreshLayout.setOnLoadMoreListener(new BaseRefreshLayout.OnLoadMoreListener() {
@Override
public void onLoadMore() {
onLoadMoreEvent();
}
});
// 自动加载
mRefreshLayout.setOnAutoLoadListener(new BaseRefreshLayout.OnAutoLoadListener() {
@Override
public void onAutoLoad() {
onAutoLoadEvent();
}
});
}
protected abstract int onBindRreshLayout();
@Override
public void enableRefresh(boolean b) {
mRefreshLayout.setEnableRefresh(b);
}
@Override
public void enableLoadMore(boolean b) {
mRefreshLayout.setEnableLoadMore(b);
}
@Override
public void stopRefresh() {
mRefreshLayout.setRefreshing(false);
}
@Override
public void stopLoadMore() {
mRefreshLayout.setLoadMore(false);
}
@Override
public void autoLoadData() {
mRefreshLayout.autoRefresh();
}
}
package com.fly.tour.common.base;
import android.view.View;
import com.fly.tour.common.mvp.BaseModel;
import com.fly.tour.common.mvp.BaseRefreshPresenter;
import com.fly.tour.common.mvp.BaseRefreshView;
import com.fly.tour.common.util.log.KLog;
import com.refresh.lib.BaseRefreshLayout;
import com.refresh.lib.DaisyRefreshLayout;
/**
* Description: <下拉刷新、上拉加载更多的Fragment><br>
* Author: mxdl<br>
* Date: 2018/2/25<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public abstract class BaseRefreshFragment<M extends BaseModel,V extends BaseRefreshView<T>,P extends BaseRefreshPresenter<M,V,T>,T> extends BaseMvpFragment<M,V,P> implements BaseRefreshView<T> {
protected DaisyRefreshLayout mRefreshLayout;
@Override
public void initCommonView(View view) {
super.initCommonView(view);
initRefreshView(view);
}
public void initRefreshView(View view) {
mRefreshLayout = view.findViewById(onBindRreshLayout());
mRefreshLayout.setOnRefreshListener(new BaseRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
onRefreshEvent();
}
});
mRefreshLayout.setOnLoadMoreListener(new BaseRefreshLayout.OnLoadMoreListener() {
@Override
public void onLoadMore() {
onLoadMoreEvent();
}
});
mRefreshLayout.setOnAutoLoadListener(new BaseRefreshLayout.OnAutoLoadListener() {
@Override
public void onAutoLoad() {
onAutoLoadEvent();
}
});
}
protected abstract int onBindRreshLayout();
@Override
public void enableRefresh(boolean b) {
mRefreshLayout.setEnableRefresh(b);
}
@Override
public void enableLoadMore(boolean b) {
mRefreshLayout.setEnableLoadMore(b);
}
@Override
public void stopRefresh() {
mRefreshLayout.setRefreshing(false);
}
@Override
public void stopLoadMore() {
mRefreshLayout.setLoadMore(false);
}
@Override
public void autoLoadData() {
KLog.v("MYTAG","autoLoadData start...");
if(mRefreshLayout != null){
KLog.v("MYTAG","autoLoadData1 start...");
mRefreshLayout.autoRefresh();
}
}
}
package com.fly.tour.common.event;
/**
* Description: <BaseEvent><br>
* Author: mxdl<br>
* Date: 2018/4/4<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class BaseEvent<T> {
private int code;
private T data;
public BaseEvent(int code) {
this.code = code;
}
public BaseEvent(int code, T data) {
this.code = code;
this.data = data;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.fly.tour.common.event;
/**
* Description: <EventCode><br>
* Author: mxdl<br>
* Date: 2018/4/4<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface EventCode {
interface MainCode {
//1000开始
}
interface NewsCode {
//2000开始
}
interface FindCode {
//3000开始
}
interface MeCode {
//4000开始
int NEWS_TYPE_ADD = 4000;
int NEWS_TYPE_DELETE = 4001;
int NEWS_TYPE_UPDATE = 4002;
int NEWS_TYPE_QUERY = 4003;
int news_detail_add = 4004;
}
}
package com.fly.tour.common.event;
/**
* Description: <RequestCode><br>
* Author: mxdl<br>
* Date: 2019/5/27<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface KeyCode {
interface Main {
}
interface News {
String NEWS_TYPE = "newstype";
String NEWS_ID = "newsid";
}
interface Find {
}
interface Me {
}
}
package com.fly.tour.common.event;
/**
* Description: <RequestCode><br>
* Author: mxdl<br>
* Date: 2019/5/27<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface RequestCode {
interface Main {
//1000开始
}
interface News {
//2000开始
}
interface Find {
//3000开始
}
interface Me {
//4000开始
int NEWS_TYPE_ADD = 4000;
}
}
package com.fly.tour.common.event.common;
import com.fly.tour.common.event.BaseEvent;
/**
* Description: <BaseActivityEvent><br>
* Author: mxdl<br>
* Date: 2018/4/4<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class BaseActivityEvent<T> extends BaseEvent<T> {
public BaseActivityEvent(int code) {
super(code);
}
}
package com.fly.tour.common.event.common;
import com.fly.tour.common.event.BaseEvent;
/**
* Description: <BaseFragmentEvent><br>
* Author: mxdl<br>
* Date: 2018/4/4<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class BaseFragmentEvent<T> extends BaseEvent<T> {
public BaseFragmentEvent(int code) {
super(code);
}
}
package com.fly.tour.common.event.me;
import com.fly.tour.common.event.BaseEvent;
/**
* Description: <NewsDetailCurdEvent><br>
* Author: mxdl<br>
* Date: 2019/5/29<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class NewsDetailCurdEvent extends BaseEvent {
public NewsDetailCurdEvent(int code) {
super(code);
}
}
package com.fly.tour.common.event.me;
import com.fly.tour.common.event.BaseEvent;
/**
* Description: <NewsTypeCrudEvent><br>
* Author: mxdl<br>
* Date: 2019/5/29<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class NewsTypeCrudEvent extends BaseEvent {
public NewsTypeCrudEvent(int code) {
super(code);
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册