diff --git a/app/build.gradle b/app/build.gradle index 9e349f5ed2..ace5a02c8f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -89,7 +89,6 @@ android { debuggable true minifyEnabled false zipAlignEnabled false - versionNameSuffix "-debug" signingConfig signingConfigs.debug buildConfigField "String", "UMENG_APPKEY", "\"${DEBUG_UMENG_APPKEY}\"" @@ -139,6 +138,8 @@ android { // internal test dev host internal { dimension "nonsense" + versionNameSuffix "-debug" + buildConfigField "String", "API_HOST", "\"${DEV_API_HOST}\"" buildConfigField "String", "USER_HOST", "\"${DEV_USER_HOST}\"" buildConfigField "String", "COMMENT_HOST", "\"${DEV_COMMENT_HOST}\"" @@ -291,3 +292,31 @@ if (propFile.exists()) { } else { android.buildTypes.release.signingConfig = null } + +// 用于测试读取 META-INF 里的 JSON 的代码 +//task generateMetaJson { +// def resDir = new File(buildDir, 'generated/FILES_FOR_META_INF/') +// def destDir = new File(resDir, 'META-INF/') +// // Add resDir as a resource directory so that it is automatically included in the APK. +// android { +// sourceSets { +// main.resources { +// srcDir resDir +// } +// } +// } +// +// doLast { +// if (!destDir.exists()) destDir.mkdirs() +// copy { +// into destDir +// from new File('generated/FILES_FOR_META_INF/META-INF/halo_skip.json') +// } +// } +//} +//// Specify when put_files_in_META_INF should run +//project.afterEvaluate { +// tasks.findAll { task -> +// task.name.startsWith('merge') && task.name.endsWith('Resources') +// }.each { t -> t.dependsOn generateMetaJson } +//} diff --git a/app/src/main/java/com/gh/common/util/DirectUtils.kt b/app/src/main/java/com/gh/common/util/DirectUtils.kt index e8fc28a564..ca8bb6634a 100644 --- a/app/src/main/java/com/gh/common/util/DirectUtils.kt +++ b/app/src/main/java/com/gh/common/util/DirectUtils.kt @@ -5,8 +5,10 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.text.TextUtils +import com.gh.base.fragment.BaseFragment_TabLayout import com.gh.common.util.EntranceUtils.* import com.gh.gamecenter.* +import com.gh.gamecenter.download.DownloadFragment.Companion.INDEX_UPDATE import com.gh.gamecenter.entity.SubjectData import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity @@ -19,6 +21,31 @@ import com.lightgame.utils.Utils */ object DirectUtils { + @JvmStatic + fun directToSpecificPage(context: Context, type: String, link: String, text: String? = "", entrance: String? = null) { + when (type) { + EntranceUtils.HOST_ARTICLE -> directToArticle(context, id = link, entrance = entrance) + + EntranceUtils.HOST_GAME -> directToGameDetail(context, id = link, entrance = entrance) + + EntranceUtils.HOST_GAME_DOWNLOAD -> directToGameDetail(context, id = link, entrance = entrance, autoDownload = true) + + EntranceUtils.HOST_COLUMN -> directToSubject(context, id = link, subjectName = text, entrance = entrance) + + EntranceUtils.HOST_QUESTION -> directToQuestionDetail(context, id = link, entrance = entrance) + + EntranceUtils.HOST_ANSWER -> directToAnswerDetail(context, id = link, entrance = entrance) + + EntranceUtils.HOST_WEB -> directToWebView(context, url = link, entrance = entrance) + + EntranceUtils.HOST_DOWNLOAD -> directToDownloadManagerAndStartDownload(context, gameId = link, packageName = text, entrance = entrance) + + EntranceUtils.HOST_UPDATE -> directToDownloadManagerAndStartUpdate(context, gameId = link, packageName = text, entrance = entrance) + + EntranceUtils.HOST_LIBAO -> directToGiftDetail(context, giftId = link, entrance = entrance) + } + } + @JvmStatic fun directToArticle(context: Context, id: String, entrance: String? = null) { val bundle = Bundle() @@ -29,11 +56,12 @@ object DirectUtils { } @JvmStatic - fun directToGameDetail(context: Context, id: String, entrance: String? = null) { + fun directToGameDetail(context: Context, id: String, entrance: String? = null, autoDownload: Boolean? = null) { val bundle = Bundle() bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER) bundle.putString(KEY_TO, GameDetailActivity::class.java.simpleName) bundle.putString(KEY_GAMEID, id) + bundle.putBoolean(KEY_AUTO_DOWNLOAD, autoDownload ?: false) EntranceUtils.jumpActivity(context, bundle) } @@ -60,12 +88,35 @@ object DirectUtils { } @JvmStatic - fun directToDownloadManager(context: Context, id: String, packageName: String, entrance: String? = null) { + fun directToDownloadManager(context: Context, entrance: String? = null) { val bundle = Bundle() bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER) bundle.putString(KEY_TO, DownloadManagerActivity.TAG) - bundle.putString(KEY_GAMEID, id) + EntranceUtils.jumpActivity(context, bundle) + } + + @JvmStatic + fun directToDownloadManagerAndStartDownload(context: Context, gameId: String? = "", packageName: String? = "", entrance: String? = null) { + DownloadHelper.createABrandNewDownloadTaskQuietly(gameId, packageName) { + val bundle = Bundle() + bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER) + bundle.putString(KEY_TO, DownloadManagerActivity.TAG) + bundle.putString(KEY_GAMEID, gameId) + bundle.putString(KEY_PACKAGENAME, packageName) + bundle.putBoolean(KEY_AUTO_DOWNLOAD, true) + EntranceUtils.jumpActivity(context, bundle) + } + } + + @JvmStatic + fun directToDownloadManagerAndStartUpdate(context: Context, gameId: String? = "", packageName: String? = "", entrance: String? = null) { + val bundle = Bundle() + bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER) + bundle.putString(KEY_TO, DownloadManagerActivity.TAG) + bundle.putString(KEY_GAMEID, gameId) bundle.putString(KEY_PACKAGENAME, packageName) + bundle.putInt(BaseFragment_TabLayout.PAGE_INDEX, INDEX_UPDATE) + bundle.putBoolean(KEY_AUTO_UPDATE, true) EntranceUtils.jumpActivity(context, bundle) } @@ -145,4 +196,12 @@ object DirectUtils { } } + @JvmStatic + fun directToGiftDetail(context: Context, giftId: String, entrance: String? = null) { + val bundle = Bundle() + bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER) + bundle.putString(EntranceUtils.KEY_TO, LibaoDetailActivity::class.java.simpleName) + bundle.putString(EntranceUtils.KEY_ID, giftId) + EntranceUtils.jumpActivity(context, bundle) + } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/util/DownloadHelper.kt b/app/src/main/java/com/gh/common/util/DownloadHelper.kt new file mode 100644 index 0000000000..e9d26b69e6 --- /dev/null +++ b/app/src/main/java/com/gh/common/util/DownloadHelper.kt @@ -0,0 +1,55 @@ +package com.gh.common.util + +import com.gh.download.DownloadManager +import com.gh.gamecenter.entity.GameEntity +import com.gh.gamecenter.retrofit.Response +import com.gh.gamecenter.retrofit.RetrofitManager +import com.halo.assistant.HaloApp +import io.reactivex.schedulers.Schedulers +import retrofit2.HttpException + +/** + * 不想写这个类的,但是与其在一个糟糕的类里插入同样的代码,我想独立写一个类相较而已还没那么糟糕 + */ +object DownloadHelper { + + @JvmStatic + fun createABrandNewDownloadTaskQuietly(gameId: String? = "", packageName: String? = "") { + createABrandNewDownloadTaskQuietly(gameId, packageName) {} + } + + /** + * 根据 game_id 和 packageName 悄悄地开启一个下载任务,如果可以的话 + * @param block 成功添加下载任务后执行的代码块 + */ + fun createABrandNewDownloadTaskQuietly(gameId: String? = "", packageName: String? = "", block: () -> Unit) { + RetrofitManager.getInstance(HaloApp.getInstance().application) + .api + .getGameDigest(gameId) + .subscribeOn(Schedulers.io()) + .subscribe(object : Response() { + override fun onResponse(response: GameEntity?) { + response?.let { + if (response.getApk().size > 1) { + for (apk in response.getApk()) { + if (packageName == apk.packageName) { + DownloadManager.createDownload(HaloApp.getInstance().application, + apk, response, "", EntranceUtils.ENTRANCE_RECOMMEND, "", null) + block.invoke() + } + } + } else if (response.getApk().size == 1) { + DownloadManager.createDownload(HaloApp.getInstance().application, + response, "", EntranceUtils.ENTRANCE_RECOMMEND, "", null) + block.invoke() + } + } + } + + override fun onFailure(e: HttpException?) { + e?.printStackTrace() + } + }) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/util/EntranceUtils.java b/app/src/main/java/com/gh/common/util/EntranceUtils.java index 1ac8b8e1f7..4b2850601b 100644 --- a/app/src/main/java/com/gh/common/util/EntranceUtils.java +++ b/app/src/main/java/com/gh/common/util/EntranceUtils.java @@ -26,10 +26,14 @@ public class EntranceUtils { public static final String KEY_GAMENAME = "gameName"; public static final String HOST_ARTICLE = "article"; public static final String HOST_GAME = "game"; + public static final String HOST_GAME_DOWNLOAD = "game_download"; public static final String HOST_COLUMN = "column"; public static final String HOST_WEB = "web"; public static final String HOST_QQ = "qq"; public static final String HOST_DOWNLOAD = "download"; + public static final String HOST_UPDATE = "update"; + public static final String HOST_LIBAO = "libao"; + public static final String HOST_COMMUNITY = "community"; public static final String HOST_SUGGESTION = "suggestion"; public static final String HOST_ANSWER = "answer"; public static final String HOST_QUESTION = "question"; @@ -43,6 +47,7 @@ public class EntranceUtils { public static final String ENTRANCE_UMENG = "(友盟推送)"; public static final String ENTRANCE_MIPUSH = "(小米推送)"; public static final String ENTRANCE_DOWNLOAD = "(下载跳转)"; + public static final String ENTRANCE_RECOMMEND = "(落地页)"; public static final String KEY_SUGGEST_HINT_TYPE = "suggestHintType"; public static final String KEY_PACKAGENAME = "packageName"; public static final String KEY_PLATFORM = "platform"; @@ -89,6 +94,8 @@ public class EntranceUtils { public static final String KEY_USER_ID = "user_id"; public static final String KEY_QUESTION_TAG = "question_tag"; public static final String KEY_COLUMN_ID = "column_id"; + public static final String KEY_AUTO_DOWNLOAD = "auto_download"; + public static final String KEY_AUTO_UPDATE = "auto_update"; public static void jumpActivity(Context context, Bundle bundle) { diff --git a/app/src/main/java/com/gh/common/util/GsonUtils.kt b/app/src/main/java/com/gh/common/util/GsonUtils.kt index e771821478..398f7e20a4 100644 --- a/app/src/main/java/com/gh/common/util/GsonUtils.kt +++ b/app/src/main/java/com/gh/common/util/GsonUtils.kt @@ -11,6 +11,7 @@ class GsonUtils private constructor() { val mGson: Gson = Gson() companion object { + @JvmStatic fun getInstance(): GsonUtils { return Inner.anotherSingle } @@ -32,4 +33,13 @@ class GsonUtils private constructor() { fun toJson(any: Any): String { return mGson.toJson(any) } +} + +// Use Kotlin Extension to do the same trick. +inline fun String.fromObject(): T { + return GsonUtils.getInstance().mGson.fromJson(this, T::class.java) +} + +inline fun T.toJson(): String { + return GsonUtils.getInstance().mGson.toJson(this) } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 9284ccf4d0..98098929ef 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -39,6 +39,7 @@ import com.gh.common.util.DataLogUtils; import com.gh.common.util.DataUtils; import com.gh.common.util.DeviceUtils; import com.gh.common.util.DialogUtils; +import com.gh.common.util.DirectUtils; import com.gh.common.util.EntranceUtils; import com.gh.common.util.GameUtils; import com.gh.common.util.GsonUtils; @@ -51,9 +52,11 @@ import com.gh.download.DownloadManager; import com.gh.gamecenter.db.info.GameInfo; import com.gh.gamecenter.db.info.InstallInfo; import com.gh.gamecenter.entity.ApkEntity; +import com.gh.gamecenter.entity.CommunityEntity; import com.gh.gamecenter.entity.GameDigestEntity; import com.gh.gamecenter.entity.GameEntity; import com.gh.gamecenter.entity.GameUpdateEntity; +import com.gh.gamecenter.entity.InnerMetaInfoEntity; import com.gh.gamecenter.entity.SettingsEntity; import com.gh.gamecenter.eventbus.EBNetworkState; import com.gh.gamecenter.eventbus.EBPackage; @@ -95,7 +98,10 @@ import org.greenrobot.eventbus.ThreadMode; import org.json.JSONArray; import org.json.JSONObject; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Enumeration; @@ -137,6 +143,7 @@ public class MainActivity extends BaseActivity { private static final int SKIP_SETTING_REQUEST = 14; private boolean isSkipped; public static boolean isNewFirstLaunch; + public static boolean openCommunityWithDefaultIdForTheFirsTime; // 是否根据 META-INFO 里的 JSON 自动选择默认的社区 ID Runnable skipRun = new Runnable() { @Override @@ -966,36 +973,59 @@ public class MainActivity extends BaseActivity { // 获取META-INF中的plugin_update 文件,判断是否从游戏插件中下载的app,是则获取游戏id,启动游戏更新,下载该游戏 private void getPluginUpdate() { - ApplicationInfo appinfo = getApplicationInfo(); - String sourceDir = appinfo.sourceDir; - ZipFile zipfile = null; - try { - zipfile = new ZipFile(sourceDir); - Enumeration entries = zipfile.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = ((ZipEntry) entries.nextElement()); - String entryName = entry.getName(); - if (entryName.contains("gh_assist")) { // TODO: 20/09/17 统一入口 - String packageName = entryName.substring(entryName.lastIndexOf("_") + 1); - Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class); - intent.putExtra("currentItem", 1); - intent.putExtra("packageName", packageName); - intent.putExtra(EntranceUtils.KEY_ENTRANCE, "(游戏插件)"); - startActivity(intent); - break; + HaloApp.getInstance().getMainExecutor().execute(() -> { + ApplicationInfo appinfo = getApplicationInfo(); + String sourceDir = appinfo.sourceDir; + ZipFile zipfile = null; + + try { + zipfile = new ZipFile(sourceDir); + Enumeration entries = zipfile.entries(); + + while (entries.hasMoreElements()) { + ZipEntry entry = ((ZipEntry) entries.nextElement()); + String entryName = entry.getName(); + if (entryName.contains("gh_assist")) { // TODO: 20/09/17 统一入口 + String packageName = entryName.substring(entryName.lastIndexOf("_") + 1); + Intent intent = new Intent(MainActivity.this, DownloadManagerActivity.class); + intent.putExtra("currentItem", 1); + intent.putExtra("packageName", packageName); + intent.putExtra(EntranceUtils.KEY_ENTRANCE, "(游戏插件)"); + startActivity(intent); + break; + } else if (entryName.contains("halo_skip.json")) { + InputStream in = zipfile.getInputStream(entry); + if (in != null) { + final Gson gson = new Gson(); + final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + + InnerMetaInfoEntity info = gson.fromJson(reader, InnerMetaInfoEntity.class); + if (info != null) { + if (EntranceUtils.HOST_COMMUNITY.equals(info.getType())) { + openCommunityWithDefaultIdForTheFirsTime = true; + UserManager.getInstance().setCommunityData(new CommunityEntity(info.getLink(), info.getText())); + runOnUiThread(() -> { + mMainWrapperFragment.setCurrentItem(MainWrapperFragment.INDEX_ASK); + }); + } else { + DirectUtils.directToSpecificPage(this, info.getType(), info.getLink(), info.getText(), EntranceUtils.KEY_PLUGIN); + } + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (zipfile != null) { + try { + zipfile.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (zipfile != null) { - try { - zipfile.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } + }); } // 连接上网络事件 diff --git a/app/src/main/java/com/gh/gamecenter/SkipActivity.java b/app/src/main/java/com/gh/gamecenter/SkipActivity.java index 96713146c1..f9d0f8fe88 100644 --- a/app/src/main/java/com/gh/gamecenter/SkipActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SkipActivity.java @@ -20,7 +20,6 @@ import static com.gh.common.util.EntranceUtils.HOST_QUESTION; import static com.gh.common.util.EntranceUtils.HOST_SUGGESTION; import static com.gh.common.util.EntranceUtils.KEY_GAME_NAME; import static com.gh.common.util.EntranceUtils.KEY_NAME; -import static com.gh.common.util.EntranceUtils.KEY_PACKAGENAME; import static com.gh.common.util.EntranceUtils.KEY_PLATFORM; import static com.gh.common.util.EntranceUtils.KEY_VERSION; @@ -57,7 +56,7 @@ public class SkipActivity extends BaseActivity { DirectUtils.directToArticle(this, id, ENTRANCE_BROWSER); break; case HOST_GAME: - DirectUtils.directToGameDetail(this, id, ENTRANCE_BROWSER); + DirectUtils.directToGameDetail(this, id, ENTRANCE_BROWSER, false); break; case HOST_COLUMN: DirectUtils.directToSubject(this, id, uri.getQueryParameter(KEY_NAME), ENTRANCE_BROWSER); @@ -72,7 +71,7 @@ public class SkipActivity extends BaseActivity { DirectUtils.directToFeedback(this, content, ENTRANCE_BROWSER); break; case HOST_DOWNLOAD: - DirectUtils.directToDownloadManager(this, id, uri.getQueryParameter(KEY_PACKAGENAME), ENTRANCE_BROWSER); + DirectUtils.directToDownloadManager(this, ENTRANCE_BROWSER); break; case HOST_ANSWER: DirectUtils.directToAnswerDetail(this, id, ENTRANCE_BROWSER); diff --git a/app/src/main/java/com/gh/gamecenter/download/DownloadFragment.java b/app/src/main/java/com/gh/gamecenter/download/DownloadFragment.java deleted file mode 100644 index 94309dd319..0000000000 --- a/app/src/main/java/com/gh/gamecenter/download/DownloadFragment.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.gh.gamecenter.download; - -import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; - -import com.gh.base.fragment.BaseFragment_TabLayout; -import com.gh.download.DownloadManager; -import com.gh.gamecenter.DownloadManagerActivity; -import com.gh.gamecenter.R; -import com.gh.gamecenter.eventbus.EBDownloadChanged; -import com.gh.gamecenter.eventbus.EBMiPush; -import com.gh.gamecenter.eventbus.EBSkip; -import com.gh.gamecenter.eventbus.EBUISwitch; -import com.gh.gamecenter.manager.PackageManager; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.List; - -/** - * @author CsHeng - * @Date 30/06/2017 - * @Time 11:11 AM - */ - -public class DownloadFragment extends BaseFragment_TabLayout { - - public static final int INDEX_DOWNLOAD = 0; - public static final int INDEX_UPDATE = 1; - public static final int INDEX_KC = 2; - - TextView mDownloadNumber; - TextView mUpdateNumber; - - private Runnable mRunnable = new Runnable() { - @Override - public void run() { - mViewPager.setCurrentItem(DownloadManagerActivity.INDEX_DOWNLOAD); - } - }; - - @Override - protected void initFragmentList(List fragments) { - fragments.add(new GameDownloadFragment()); - fragments.add(new GameUpdateFragment()); - fragments.add(new FileSendFragment()); - } - - @Override - protected void initTabTitleList(List tabTitleList) { - tabTitleList.add(getString(R.string.download_game)); - tabTitleList.add(getString(R.string.download_tab_update)); - tabTitleList.add(getString(R.string.download_send_traffic_free)); - } - - @Override - protected View provideTabView(int position, String tabTitle) { - if (position == INDEX_KC) { - return super.provideTabView(position, tabTitle); - } - - View view = LayoutInflater.from(getContext()).inflate(R.layout.tab_item_download_number, null); - ((TextView) view.findViewById(R.id.tab_download_title)).setText(tabTitle); - if (INDEX_DOWNLOAD == position) { - mDownloadNumber = view.findViewById(R.id.tab_download_number); - } else if (INDEX_UPDATE == position) { - mUpdateNumber = view.findViewById(R.id.tab_download_number); - } - return view; - } - - @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - setNavigationTitle(getString(R.string.title_downloadmanager)); - } - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - int updateSize = PackageManager.INSTANCE.getUpdateList().size(); - if (updateSize != 0) { - mUpdateNumber.setVisibility(View.VISIBLE); - mUpdateNumber.setText(String.valueOf(updateSize)); - } else { - mUpdateNumber.setVisibility(View.GONE); - } - - int downloadSize = DownloadManager.getInstance(getContext()).getAll().size(); - if (downloadSize != 0) { - mDownloadNumber.setVisibility(View.VISIBLE); - mDownloadNumber.setText(String.valueOf(downloadSize)); - } else { - mDownloadNumber.setVisibility(View.GONE); - } - - } - - - @Override - public void onPageSelected(int index) { - EventBus.getDefault().post(new EBUISwitch(DownloadManagerActivity.TAG, index)); - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBMiPush mipush) { - if ("plugin_install".equals(mipush.getFrom())) { - mViewPager.setCurrentItem(DownloadManagerActivity.INDEX_DOWNLOAD); - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBDownloadChanged changed) { - if ("download".equals(changed.getType())) { - if (changed.getVisibility() == View.VISIBLE) { - mDownloadNumber.setVisibility(View.VISIBLE); - } else if (changed.getVisibility() == View.GONE) { - mDownloadNumber.setVisibility(View.GONE); - } else if (changed.getVisibility() == View.INVISIBLE) { - mDownloadNumber.setVisibility(View.INVISIBLE); - } - mDownloadNumber.setText(String.valueOf(changed.getSize())); - } else if ("update".equals(changed.getType())) { - if (changed.getSize() == -1) { - int number = Integer.valueOf(mUpdateNumber.getText().toString()); - if (number == 1) { - mUpdateNumber.setVisibility(View.GONE); - } else { - mUpdateNumber.setText(String.valueOf(number - 1)); - } - } else { - if (changed.getSize() != 0) { - if (changed.getVisibility() == View.VISIBLE) { - mUpdateNumber.setVisibility(View.VISIBLE); - } else if (changed.getVisibility() == View.GONE) { - mUpdateNumber.setVisibility(View.GONE); - } else if (changed.getVisibility() == View.INVISIBLE) { - mUpdateNumber.setVisibility(View.INVISIBLE); - } - mUpdateNumber.setText(String.valueOf(changed.getSize())); - } else { - mUpdateNumber.setVisibility(View.GONE); - } - } - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBSkip skip) { - if (DownloadManagerActivity.TAG.equals(skip.getType())) { - if (skip.getCurrentItem() == DownloadManagerActivity.INDEX_UPDATE) { - if (getView() != null) { - getView().postDelayed(mRunnable, 300); - } - } - } - } - -} diff --git a/app/src/main/java/com/gh/gamecenter/download/DownloadFragment.kt b/app/src/main/java/com/gh/gamecenter/download/DownloadFragment.kt new file mode 100644 index 0000000000..6e55df3b21 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/download/DownloadFragment.kt @@ -0,0 +1,141 @@ +package com.gh.gamecenter.download + +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.widget.TextView +import com.gh.base.fragment.BaseFragment_TabLayout +import com.gh.download.DownloadManager +import com.gh.gamecenter.DownloadManagerActivity +import com.gh.gamecenter.R +import com.gh.gamecenter.eventbus.EBDownloadChanged +import com.gh.gamecenter.eventbus.EBMiPush +import com.gh.gamecenter.eventbus.EBSkip +import com.gh.gamecenter.eventbus.EBUISwitch +import com.gh.gamecenter.manager.PackageManager +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode + +class DownloadFragment : BaseFragment_TabLayout() { + + companion object { + val INDEX_DOWNLOAD = 0 + val INDEX_UPDATE = 1 + val INDEX_KC = 2 + } + + lateinit var mDownloadNumber: TextView + lateinit var mUpdateNumber: TextView + + override fun initFragmentList(fragments: MutableList) { + fragments.add(GameDownloadFragment()) + fragments.add(GameUpdateFragment()) + fragments.add(FileSendFragment()) + } + + override fun initTabTitleList(tabTitleList: MutableList) { + tabTitleList.add(getString(R.string.download_game)) + tabTitleList.add(getString(R.string.download_tab_update)) + tabTitleList.add(getString(R.string.download_send_traffic_free)) + } + + override fun provideTabView(position: Int, tabTitle: String): View? { + if (position == INDEX_KC) { + return super.provideTabView(position, tabTitle) + } + + val view = LayoutInflater.from(context).inflate(R.layout.tab_item_download_number, null) + (view.findViewById(R.id.tab_download_title) as TextView).text = tabTitle + if (INDEX_DOWNLOAD == position) { + mDownloadNumber = view.findViewById(R.id.tab_download_number) + } else if (INDEX_UPDATE == position) { + mUpdateNumber = view.findViewById(R.id.tab_download_number) + } + return view + } + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + setNavigationTitle(getString(R.string.title_downloadmanager)) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val updateSize = PackageManager.getUpdateList().size + if (updateSize != 0) { + mUpdateNumber.visibility = View.VISIBLE + mUpdateNumber.text = updateSize.toString() + } else { + mUpdateNumber.visibility = View.GONE + } + + val downloadSize = DownloadManager.getInstance(context).all.size + if (downloadSize != 0) { + mDownloadNumber.visibility = View.VISIBLE + mDownloadNumber.text = downloadSize.toString() + } else { + mDownloadNumber.visibility = View.GONE + } + } + + override fun onPageSelected(index: Int) { + EventBus.getDefault().post(EBUISwitch(DownloadManagerActivity.TAG, index)) + } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onEventMainThread(mipush: EBMiPush) { + if ("plugin_install" == mipush.from) { + mViewPager.currentItem = DownloadManagerActivity.INDEX_DOWNLOAD + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onEventMainThread(changed: EBDownloadChanged) { + if ("download" == changed.type) { + if (changed.visibility == View.VISIBLE) { + mDownloadNumber.visibility = View.VISIBLE + } else if (changed.visibility == View.GONE) { + mDownloadNumber.visibility = View.GONE + } else if (changed.visibility == View.INVISIBLE) { + mDownloadNumber.visibility = View.INVISIBLE + } + mDownloadNumber.text = changed.size.toString() + } else if ("update" == changed.type) { + if (changed.size == -1) { + val number = Integer.valueOf(mUpdateNumber.text.toString()) + if (number == 1) { + mUpdateNumber.visibility = View.GONE + } else { + mUpdateNumber.text = (number - 1).toString() + } + } else { + if (changed.size != 0) { + if (changed.visibility == View.VISIBLE) { + mUpdateNumber.visibility = View.VISIBLE + } else if (changed.visibility == View.GONE) { + mUpdateNumber.visibility = View.GONE + } else if (changed.visibility == View.INVISIBLE) { + mUpdateNumber.visibility = View.INVISIBLE + } + mUpdateNumber.text = changed.size.toString() + } else { + mUpdateNumber.visibility = View.GONE + } + } + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onEventMainThread(skip: EBSkip) { + if (DownloadManagerActivity.TAG == skip.type) { + if (skip.currentItem == DownloadManagerActivity.INDEX_UPDATE) { + if (view != null) { + view!!.postDelayed({ mViewPager.currentItem = DownloadManagerActivity.INDEX_DOWNLOAD }, 300) + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragment.java b/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragment.java index 40672ba4fd..b31eb6e2e5 100644 --- a/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragment.java +++ b/app/src/main/java/com/gh/gamecenter/download/GameUpdateFragment.java @@ -53,7 +53,7 @@ public class GameUpdateFragment extends BaseFragment { super.initView(view); Intent intent = getActivity().getIntent(); String packageName = intent.getStringExtra("packageName"); - boolean isUpdate = intent.getBooleanExtra("isPushIntent", false); + boolean isUpdate = intent.getBooleanExtra(EntranceUtils.KEY_AUTO_UPDATE, false); String entrance = intent.getStringExtra(EntranceUtils.KEY_ENTRANCE); mGameUpdateLoading = (LinearLayout) view.findViewById(R.id.gameupdate_ll_loading); diff --git a/app/src/main/java/com/gh/gamecenter/entity/InnerMetaInfoEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/InnerMetaInfoEntity.kt new file mode 100644 index 0000000000..796e8d0142 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/entity/InnerMetaInfoEntity.kt @@ -0,0 +1,5 @@ +package com.gh.gamecenter.entity + +data class InnerMetaInfoEntity(var link: String? = "", + var type: String? = "", + var text: String? = "") \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java index a9995345f5..cf68549073 100644 --- a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java +++ b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java @@ -206,4 +206,8 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable { getDiscoveryData(true); } } + + public void setCurrentItem(int page) { + mViewPager.setCurrentItem(page, false); + } } diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.java b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.java index f9b32c6b57..e2d8ff4ce4 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.java +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailFragment.java @@ -71,7 +71,6 @@ import retrofit2.HttpException; */ public class GameDetailFragment extends NormalFragment { - public static final int INDEX_DYNAMIC = 0; public static final int INDEX_DESCRIPTION = 1; public static final String SKIP_XINXI = "skipXinxi"; @@ -120,6 +119,7 @@ public class GameDetailFragment extends NormalFragment { private boolean mIsTouchScreen = false; private boolean mIsShowKaifuHint; private boolean mIsScrollToKaiFu; + private boolean mAutoDownload; private boolean mSwitchToFirstTabInStartup; private int mCurVpPosition; @@ -168,7 +168,6 @@ public class GameDetailFragment extends NormalFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); -// setNavigationTitle(""); mViewPager.setScrollable(true); @@ -176,13 +175,13 @@ public class GameDetailFragment extends NormalFragment { mGameId = args.getString(EntranceUtils.KEY_GAMEID); mSwitchToFirstTabInStartup = args.getBoolean(EntranceUtils.KEY_TARGET); + mAutoDownload = args.getBoolean(EntranceUtils.KEY_AUTO_DOWNLOAD); if (mGameId == null) { mGameEntity = args.getParcelable(GameEntity.TAG); mTraceEvent = args.getParcelable(EntranceUtils.KEY_TRACE_EVENT); if (mGameEntity != null) { mGameId = mGameEntity.getId(); -// setNavigationTitle(mGameEntity.getName()); title = mGameEntity.getName(); } } @@ -228,20 +227,17 @@ public class GameDetailFragment extends NormalFragment { } }); - mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { - @Override - public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - int total = appBarLayout.getTotalScrollRange(); - if (Math.abs(verticalOffset) > total / 2) { - setNavigationTitle(mGameEntity != null ? mGameEntity.getName() : ""); - } else { - setNavigationTitle(""); - } + mAppBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> { + int total = appBarLayout.getTotalScrollRange(); + if (Math.abs(verticalOffset) > total / 2) { + setNavigationTitle(mGameEntity != null ? mGameEntity.getName() : ""); + } else { + setNavigationTitle(""); + } - if (Math.abs(verticalOffset) == total && mIsScrollToKaiFu) { - mIsScrollToKaiFu = false; - EventBus.getDefault().post(new EBReuse(SCROLL_TO_KAIFU)); - } + if (Math.abs(verticalOffset) == total && mIsScrollToKaiFu) { + mIsScrollToKaiFu = false; + EventBus.getDefault().post(new EBReuse(SCROLL_TO_KAIFU)); } }); @@ -431,7 +427,8 @@ public class GameDetailFragment extends NormalFragment { mViewPager.setAdapter(BaseFragmentPagerAdapter.newInstance(getChildFragmentManager(), list)); initGameDetailTop(); - DetailDownloadUtils.detailInitDownload(getDetailViewHolder(), true); + DetailViewHolder viewHolder = getDetailViewHolder(); + DetailDownloadUtils.detailInitDownload(viewHolder, true); if (mGameDetailEntity.getMe() == null || !mGameDetailEntity.getMe().isGameConcerned()) { if (new InstallManager(getContext()).findInstallById(mGameEntity.getId()) == null) { @@ -439,6 +436,11 @@ public class GameDetailFragment extends NormalFragment { } } + if (mAutoDownload) { + viewHolder.mDownloadPb.performClick(); + mAutoDownload = false; + } + if (mSwitchToFirstTabInStartup) mViewPager.setCurrentItem(0); } }); @@ -573,40 +575,32 @@ public class GameDetailFragment extends NormalFragment { } }); } else { - DialogUtils.showCancelDialog(getContext(), new DialogUtils.ConfirmListener() { - @Override - public void onConfirm() { - // 取消关注 - ConcernUtils.INSTANCE.deleteConcernData(getContext(), mGameEntity.getId() - , new ConcernUtils.onConcernListener() { - @Override - public void onSuccess() { - Map kv = new HashMap<>(); - kv.put("状态", "取消关注"); - DataUtils.onEvent(getContext(), "游戏关注", mGameEntity.getName(), kv); + DialogUtils.showCancelDialog(getContext(), () -> { + // 取消关注 + ConcernUtils.INSTANCE.deleteConcernData(getContext(), mGameEntity.getId() + , new ConcernUtils.onConcernListener() { + @Override + public void onSuccess() { + Map kv = new HashMap<>(); + kv.put("状态", "取消关注"); + DataUtils.onEvent(getContext(), "游戏关注", mGameEntity.getName(), kv); - DataCollectionUtils.uploadConcern(getContext(), - mGameEntity.getName(), mGameEntity.getId(), "取消关注"); + DataCollectionUtils.uploadConcern(getContext(), + mGameEntity.getName(), mGameEntity.getId(), "取消关注"); - mGameConcern.setText(getString(R.string.concern)); - mGameConcern.setBackgroundResource(R.drawable.button_normal_style); - mGameConcern.setTextColor(0xffffffff); - mGameConcern.setEnabled(true); - } + mGameConcern.setText(getString(R.string.concern)); + mGameConcern.setBackgroundResource(R.drawable.button_normal_style); + mGameConcern.setTextColor(0xffffffff); + mGameConcern.setEnabled(true); + } - @Override - public void onError() { - mGameConcern.setEnabled(true); - toast(R.string.cancel_concern_failure); - } - }); - } - }, new DialogUtils.CancelListener() { - @Override - public void onCancel() { - mGameConcern.setEnabled(true); - } - }); + @Override + public void onError() { + mGameConcern.setEnabled(true); + toast(R.string.cancel_concern_failure); + } + }); + }, () -> mGameConcern.setEnabled(true)); } }); break; diff --git a/app/src/main/java/com/gh/gamecenter/qa/AskFragment.java b/app/src/main/java/com/gh/gamecenter/qa/AskFragment.java index 998b5b1126..808a27a9b3 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/AskFragment.java +++ b/app/src/main/java/com/gh/gamecenter/qa/AskFragment.java @@ -147,7 +147,8 @@ public class AskFragment extends BaseFragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - if (MainActivity.isNewFirstLaunch || UserManager.getInstance().getCommunity() == null + if ((MainActivity.isNewFirstLaunch && !MainActivity.openCommunityWithDefaultIdForTheFirsTime) + || UserManager.getInstance().getCommunity() == null || TextUtils.isEmpty(UserManager.getInstance().getCommunity().getId())) { showCommunitiesSelectFragment(true); } else {