Commit 96ad7691 by amateur

1

1 parent d52336cc
......@@ -16,6 +16,7 @@ android {
buildConfigField "String", "API_HOST", "\"http://new.ynyc6666.com/shop/server/\""
buildConfigField "String", "WX_APPID", "\"1234567890\""
buildConfigField "boolean", "SHOW_INPUT", "true"
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
......@@ -28,6 +29,7 @@ android {
zipAlignEnabled true //是否设置zip对齐优化
shrinkResources true // 移除无用的resource文件
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "SHOW_INPUT", "false"
}
pro { // 预生产
resValue "string", "app_name", "Nafmii-pro"
......
......@@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.polysoft.nafmii.BuildConfig;
import com.polysoft.nafmii.R;
import com.polysoft.nafmii.utils.IntentUtils;
import com.polysoft.nafmii.utils.SpUtils;
......@@ -77,7 +78,11 @@ public class GuideActivity extends BaseActivity implements View.OnClickListener
public void onClick(View v) {
if (v.getId() == R.id.guide_btn_gohome) {
SpUtils.putBoolean("isFirstRun", true);
IntentUtils.startActivity(this, HomeActivity.class);
if (BuildConfig.SHOW_INPUT) {
IntentUtils.startActivity(this, InputUrlActivity.class);
} else {
IntentUtils.startActivity(this, HomeActivity.class);
}
}
}
......
......@@ -10,7 +10,8 @@ import androidx.fragment.app.FragmentManager;
import com.polysoft.nafmii.R;
import com.polysoft.nafmii.bean.MenuBean;
import com.polysoft.nafmii.enums.ModulesEnum;
import com.polysoft.nafmii.fragment.ModulesFragmentMgr;
import com.polysoft.nafmii.activity.home.ModulesFragmentMgr;
import com.polysoft.nafmii.utils.SpUtils;
import java.util.HashMap;
import java.util.Iterator;
......@@ -56,7 +57,7 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene
this.modulesMgr.showInitFragment(new ModulesEnum[]{
ModulesEnum.HOME, ModulesEnum.MEMBER,
ModulesEnum.LEARN, ModulesEnum.MY
});
}, getIntent().getStringExtra(ModulesEnum.HOME.name));
}
......
......@@ -48,8 +48,9 @@ public class InputUrlActivity extends AppCompatActivity {
private void jumpHome() {
EditText input = findViewById(R.id.input_url);
String url = input.getText().toString();
if (!TextUtils.isEmpty(url)) {
if (TextUtils.isEmpty(url)) {
ToastUtils.showLong("url 不能为空");
return;
}
RadioButton button1 = findViewById(R.id.input_channel_1);
......
package com.polysoft.nafmii.fragment;
package com.polysoft.nafmii.activity.home;
import android.text.TextUtils;
......@@ -8,6 +8,7 @@ import androidx.fragment.app.FragmentTransaction;
import com.polysoft.nafmii.bean.MenuBean;
import com.polysoft.nafmii.enums.ModulesEnum;
import com.polysoft.nafmii.fragment.WebViewFragment;
import com.polysoft.nafmii.webview.IWebview;
import java.util.List;
......@@ -22,18 +23,22 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
public ModulesFragmentMgr(FragmentManager manager, int containerId) {
this.manager = manager;
this.containerId = containerId;
manager.addOnBackStackChangedListener(this);
}
public void addChangeModuleLsitener(OnChangeModuleListener listener) {
this.changeListener = listener;
}
public void showInitFragment(ModulesEnum[] modules) {
for (int i = 0; i < modules.length; i++) {
public void showInitFragment(ModulesEnum[] modules, String url) {
WebViewFragment fragment = this.addModuleFragment(modules[0], url);
for (int i = 1; i < modules.length; i++) {
this.addModuleFragment(modules[i]);
}
WebViewFragment fragment = this.findFragment(modules[0]);
// WebViewFragment fragment = this.findFragment(modules[0]);
FragmentTransaction transaction = this.manager.beginTransaction();
transaction.show(fragment).commitNow();
this.setCurrentModule(modules[0]);
......@@ -44,15 +49,12 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
public boolean onBackStack() {
WebViewFragment fragment = getCurrentFragment();
IWebview webview = fragment.getWebview();
if (null != webview && webview.canGoBack()) {
return false;
}
if (this.manager.getBackStackEntryCount() > 0) {
this.manager.addOnBackStackChangedListener(this);
this.manager.popBackStack();
return false;
}
......@@ -61,7 +63,7 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
public void showModule(ModulesEnum module) {
if (module == this.currentModule) {
return ;
return;
}
WebViewFragment fragment = this.findFragment(module);
if (!module.fmtKey.equals(this.currentModule.fmtKey)) {
......@@ -69,10 +71,7 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
transaction.hide(this.getCurrentFragment());
transaction.addToBackStack("").show(fragment).commit();
} else {
IWebview webview = fragment.getWebview();
if (null != webview) {
webview.loadUrl(module.webUrl);
}
fragment.getWebview().loadUrl(module.webUrl);
}
this.setCurrentModule(module);
}
......@@ -80,9 +79,9 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
public void showModule(MenuBean bean) {
ModulesEnum module = ModulesEnum.findModule(bean.getModuleName());
WebViewFragment fragment = this.findFragment(module);
if (!TextUtils.isEmpty(bean.getUrl())) {
IWebview webview = fragment.getWebview();
webview.loadUrl(bean.getUrl());
fragment.getWebview().loadUrl(bean.getUrl());
}
if (!module.fmtKey.equals(this.currentModule.fmtKey)) {
FragmentTransaction transaction = this.manager.beginTransaction();
......@@ -93,18 +92,18 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
}
public WebViewFragment findFragment(ModulesEnum module) {
WebViewFragment fragment = (WebViewFragment) this.manager.findFragmentByTag(module.fmtKey);
if (null == fragment) {
return this.addModuleFragment(module);
}
return fragment;
return this.addModuleFragment(module);
}
private WebViewFragment addModuleFragment(ModulesEnum module) {
return addModuleFragment(module, null);
}
private WebViewFragment addModuleFragment(ModulesEnum module, String url) {
WebViewFragment fragment = (WebViewFragment) this.manager.findFragmentByTag(module.fmtKey);
if (null == fragment) {
FragmentTransaction transaction = this.manager.beginTransaction();
fragment = WebViewFragment.newInstances(module.webUrl);
fragment = WebViewFragment.newInstances(!TextUtils.isEmpty(url) ? url : module.webUrl);
transaction.add(this.containerId, fragment, module.fmtKey).hide(fragment).commitNow();
}
return fragment;
......@@ -124,7 +123,7 @@ public class ModulesFragmentMgr implements FragmentManager.OnBackStackChangedLis
for (int i = 0; i < fragments.size(); i++) {
Fragment fragment = fragments.get(i);
if (fragment.isVisible()) {
setCurrentModule(ModulesEnum.findModule(fragment.getTag()));
this.setCurrentModule(ModulesEnum.findModule(fragment.getTag()));
return;
}
}
......
package com.polysoft.nafmii.constants;
public class JsApi {
public static final String API_ROUTE = "changeRoute";
}
......@@ -2,10 +2,10 @@ package com.polysoft.nafmii.enums;
public enum ModulesEnum {
HOME("home", "home", "file:///android_asset/dist/index.html"),
MEMBER("member", "home","file:///android_asset/dict/index.html"),
HOME("home", "home", "file:///android_asset/dist/index.html#/"),
MEMBER("member", "home","file:///android_asset/dist/index.html#/home"),
LEARN("learn", "learn", "http://debugtbs.qq.com"),
MY("my", "home","file:///android_asset/dist/index.html/#/user/center");
MY("my", "home","file:///android_asset/dist/index.html#/user/center");
public final String name;
public final String fmtKey;
......
......@@ -19,8 +19,10 @@ import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.DrawableImageViewTarget;
import com.bumptech.glide.request.transition.Transition;
import com.polysoft.nafmii.BuildConfig;
import com.polysoft.nafmii.R;
import com.polysoft.nafmii.activity.HomeActivity;
import com.polysoft.nafmii.activity.InputUrlActivity;
import com.polysoft.nafmii.utils.IntentUtils;
public class AdvertisementFragment extends Fragment implements View.OnClickListener {
......@@ -69,7 +71,7 @@ public class AdvertisementFragment extends Fragment implements View.OnClickListe
String picture = item.getString("picture");
String url = item.getString("url");
Glide.with(getContext()).load(picture).into(new DrawableImageViewTarget(this.mImgView){
Glide.with(getContext()).load(picture).into(new DrawableImageViewTarget(this.mImgView) {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
super.onResourceReady(resource, transition);
......@@ -98,7 +100,11 @@ public class AdvertisementFragment extends Fragment implements View.OnClickListe
private synchronized void gotoHome() {
if (null != getActivity() && !getActivity().isFinishing()) {
IntentUtils.startActivity(getActivity(), HomeActivity.class);
if (BuildConfig.SHOW_INPUT) {
IntentUtils.startActivity(getActivity(), InputUrlActivity.class);
} else {
IntentUtils.startActivity(getActivity(), HomeActivity.class);
}
}
}
}
......@@ -2,6 +2,8 @@ package com.polysoft.nafmii.webview;
public interface IWebview {
void callJs(String methodName, String json);
void loadUrl(String url);
String getUrl();
......
......@@ -45,6 +45,11 @@ public class WebviewHandler implements IWebview {
}
@Override
public void callJs(String methodName, String json) {
this.java2js.callJs(methodName, json);
}
@Override
public void loadUrl(String url) {
if (TextUtils.isEmpty(url) || url.equals(this.getUrl())) {
return;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!