Compare commits
185 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 526538a2a4 | |||
| f84b3a6be1 | |||
| 78f3b286ad | |||
| 83246b49dc | |||
| bb2ac7753f | |||
| 8120b06403 | |||
| 03575b169c | |||
| 5932c7b0a7 | |||
| aac03abf14 | |||
| e1e51131fb | |||
| cb5747a2fb | |||
| d5c8df3d1b | |||
| dad84e1d5a | |||
| 4ad03c196c | |||
| 7168f5391d | |||
| 2c5a21ec2a | |||
| e80af77b8d | |||
| 2ef43e821c | |||
| 42e6b88220 | |||
| a4a280ed34 | |||
| 94c3f0e4aa | |||
| 52783ccefc | |||
| 1926236d0b | |||
| 446ee1d145 | |||
| 5fb5f10d9a | |||
| 6da8d873d3 | |||
| db23aecad9 | |||
| 31bd279b4b | |||
| 8b2d249ea6 | |||
| ab817169e8 | |||
| 408e44636e | |||
| 6145092086 | |||
| a038fae17c | |||
| 779b844138 | |||
| 3fe52c36ef | |||
| fa0c843126 | |||
| 6e0047c632 | |||
| 66d2ae99a6 | |||
| b636bed83b | |||
| 16fc9c0b09 | |||
| ee3b06d4aa | |||
| ccc367a376 | |||
| 054d0c74fc | |||
| 5d9554a46d | |||
| 47a77a5085 | |||
| ef3854ae8d | |||
| 9b0a95aa54 | |||
| 26bc1299ff | |||
| 74c9cfc5b6 | |||
| a930a795db | |||
| 0a5e201936 | |||
| 0989a27fdb | |||
| e9a8b80476 | |||
| 36b0676bfc | |||
| 8702440474 | |||
| 3413100602 | |||
| 882f5bc28e | |||
| 1ffb36e1a3 | |||
| b02ded094f | |||
| 36d9f9100c | |||
| 83d695ee94 | |||
| 4d76cf46f9 | |||
| fa5a1daf68 | |||
| 4563261c52 | |||
| ab5f323159 | |||
| 17aed59317 | |||
| 788817f485 | |||
| 8dfe0cd068 | |||
| 2674ba9d99 | |||
| c7c74de382 | |||
| 60c5b9cb9d | |||
| 5c309142f3 | |||
| 098c4f7f3c | |||
| ac5deca5ae | |||
| 82d4c1c94a | |||
| 9118119901 | |||
| 02d61989fd | |||
| eb826dc612 | |||
| d5dd930932 | |||
| 04ebf421a1 | |||
| 93d9a2ebc1 | |||
| b7697742c6 | |||
| a21543ff79 | |||
| 218f234a18 | |||
| 815d895729 | |||
| 6c4bdef80d | |||
| 6cd801287c | |||
| dd7b93615d | |||
| 682b57597a | |||
| 2de0b6311f | |||
| d3195411bb | |||
| e0527b00d5 | |||
| 9d27c3cac4 | |||
| 8e681a9639 | |||
| 48ade5861a | |||
| 28e55fa01a | |||
| 64288af285 | |||
| 27f9f88c37 | |||
| 32da86ec5c | |||
| da440cdea8 | |||
| 6c651cff01 | |||
| a153e18059 | |||
| 48275aff5f | |||
| b5747cab84 | |||
| 5d22031a32 | |||
| 340123aec2 | |||
| e1827395b5 | |||
| bfb6940402 | |||
| f7c096cd9d | |||
| aa15ce42ce | |||
| cebdc97b83 | |||
| 3cfdbca8f5 | |||
| 0645c32a45 | |||
| 2a985eb6aa | |||
| 647bc29ef1 | |||
| b9a074aceb | |||
| 8207e510dd | |||
| 1348a58175 | |||
| 4b5b2fd3bd | |||
| 8bb852e2ff | |||
| 51b3c0d789 | |||
| 5e7a5a4a38 | |||
| 65a4de0e33 | |||
| b5d8e1cd2e | |||
| c11aede298 | |||
| 0db8171898 | |||
| a24482d9b3 | |||
| 7662fe3645 | |||
| 0950fe64cc | |||
| b25e85ddb1 | |||
| deedd0d413 | |||
| 07a7908486 | |||
| 1eea91a6d0 | |||
| 3fbba5d164 | |||
| 30295699b6 | |||
| 37ca59a1e5 | |||
| 6b0e854f26 | |||
| 7ad972dd23 | |||
| c2168eaf02 | |||
| 60625a7bff | |||
| 43ee952763 | |||
| 8720c63f63 | |||
| 6778142d62 | |||
| e6b6e00bf2 | |||
| a91cee40ba | |||
| c03b6521d5 | |||
| c33ff5fa20 | |||
| 281d98edcd | |||
| 7b84e36387 | |||
| 71a122b671 | |||
| f113328619 | |||
| ad9d8259e6 | |||
| 75834b7668 | |||
| 6ac86c9ce6 | |||
| 8e3b5ae664 | |||
| f22d8b5a47 | |||
| 2260a72c1d | |||
| 4ead5238bc | |||
| 851f6f1940 | |||
| 63f69a6bd5 | |||
| 01800715f8 | |||
| 157b1b8d8b | |||
| ffcd191135 | |||
| 769097544e | |||
| adc93021e7 | |||
| a3f5b5c2c0 | |||
| c08a312111 | |||
| 3c71d9ae93 | |||
| fe8205adae | |||
| 75c332ade1 | |||
| e0202ccda5 | |||
| 275da32584 | |||
| 2f6f508a56 | |||
| 9b7e8841c4 | |||
| 48653665b3 | |||
| 5e1a68de63 | |||
| caa9dd4db4 | |||
| cb891bc063 | |||
| 2ee3adef14 | |||
| 53618e0117 | |||
| 7c6a2e9767 | |||
| c44aa52f5f | |||
| 7f6efad8c8 | |||
| f9d82d163f | |||
| 42d0f3cf74 |
@ -63,4 +63,7 @@
|
||||
- ~~把 ListViewModel 的数据结构类型转换方式换为抽象方法,让继承的类实现,避免出现无响应的问题~~
|
||||
|
||||
- ~~rxjava2 如果接口返回为空 会发生异常:java.lang.NullPointerException: Null is not a valid element (答案编辑) 解决方法->com.gh.gamecenter.retrofit.Response~~
|
||||
- constraintLayout 1.1.2 导致布局出现异常(问题编辑标签选择弹窗)
|
||||
- constraintLayout 1.1.2 导致布局出现异常(问题编辑标签选择弹窗)
|
||||
|
||||
- 搞清楚 GameManager 的用途,看能不能去掉
|
||||
- 重构一下 MainActivity
|
||||
@ -178,9 +178,15 @@ rebuildChannel {
|
||||
// releaseOutputDir = Release渠道包输出目录
|
||||
}
|
||||
|
||||
repositories {
|
||||
flatDir {
|
||||
dirs 'libs/aars'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation fileTree(include: '*.jar', dir: 'libs')
|
||||
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
|
||||
|
||||
debugImplementation "com.squareup.leakcanary:leakcanary-android:${leakcanary}"
|
||||
debugImplementation "com.facebook.stetho:stetho:${stetho}"
|
||||
@ -254,8 +260,16 @@ dependencies {
|
||||
implementation "com.scwang.smartrefresh:SmartRefreshLayout:${smartRefreshLayout}"
|
||||
implementation "net.cachapa.expandablelayout:expandablelayout:${expandableLayout}"
|
||||
|
||||
// 用于比较 versionName 是大于小于或等于
|
||||
implementation "com.g00fy2:versioncompare:${versioncompare}"
|
||||
|
||||
implementation "top.zibin:Luban:${luban}"
|
||||
|
||||
// for video streaming
|
||||
implementation "cn.jzvd:jiaozivideoplayer:${jiaoziVideoView}"
|
||||
implementation "com.danikula:videocache:${videoCache}"
|
||||
|
||||
implementation project(':libraries:gid')
|
||||
implementation project(':libraries:LGLibrary')
|
||||
implementation project(':libraries:MTA')
|
||||
implementation project(':libraries:QQShare')
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
<uses-permission android:name = "android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name = "android.permission.READ_LOGS" />
|
||||
<uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name = "android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
|
||||
<supports-screens
|
||||
android:anyDensity = "true"
|
||||
@ -69,7 +70,6 @@
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.SplashScreenActivity"
|
||||
android:configChanges = "keyboardHidden|orientation|screenSize"
|
||||
android:noHistory = "true"
|
||||
android:screenOrientation = "portrait"
|
||||
android:theme = "@style/AppGuideTheme" >
|
||||
<intent-filter >
|
||||
@ -176,6 +176,7 @@
|
||||
android:screenOrientation = "portrait" />
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.GameDetailActivity"
|
||||
android:configChanges = "orientation|screenSize|keyboardHidden"
|
||||
android:screenOrientation = "portrait" />
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.SuggestSelectActivity"
|
||||
@ -343,6 +344,34 @@
|
||||
android:name = "com.gh.gamecenter.personalhome.question.PersonalQuestionActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.qa.article.edit.ArticleEditActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.qa.article.MyArticleActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.qa.article.draft.ArticleDraftActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.qa.article.detail.ArticleDetailActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.qa.draft.CommunityDraftWrapperActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.gamedetail.rating.edit.RatingEditActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<activity
|
||||
android:name = "com.gh.gamecenter.qa.comment.CommentActivity"
|
||||
android:screenOrientation = "portrait"
|
||||
android:theme = "@style/Theme.Transparent"
|
||||
android:windowSoftInputMode = "adjustNothing" />
|
||||
|
||||
<!-- 使用小米/华为推送弹窗功能提高推送成功率-->
|
||||
<activity
|
||||
@ -366,15 +395,15 @@
|
||||
android:name = ".CommonActivity"
|
||||
android:screenOrientation = "portrait" />
|
||||
|
||||
<receiver android:name = "com.gh.gamecenter.receiver.InstallAndUninstallReceiver" >
|
||||
<intent-filter >
|
||||
<action android:name = "android.intent.action.PACKAGE_ADDED" />
|
||||
<action android:name = "android.intent.action.PACKAGE_REMOVED" />
|
||||
<action android:name = "android.intent.action.PACKAGE_REPLACED" />
|
||||
|
||||
<data android:scheme = "package" />
|
||||
</intent-filter >
|
||||
</receiver >
|
||||
<provider
|
||||
android:name = "android.support.v4.content.FileProvider"
|
||||
android:authorities = "${applicationId}"
|
||||
android:exported = "false"
|
||||
android:grantUriPermissions = "true" >
|
||||
<meta-data
|
||||
android:name = "android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource = "@xml/provider_paths" />
|
||||
</provider >
|
||||
|
||||
<receiver
|
||||
android:name = "com.gh.gamecenter.receiver.DownloadReceiver"
|
||||
@ -390,11 +419,6 @@
|
||||
<action android:name = "com.gh.gamecenter.INSTALL" />
|
||||
</intent-filter >
|
||||
</receiver >
|
||||
<receiver android:name = "com.gh.gamecenter.receiver.NetworkStateReceiver" >
|
||||
<intent-filter >
|
||||
<action android:name = "android.net.conn.CONNECTIVITY_CHANGE" />
|
||||
</intent-filter >
|
||||
</receiver >
|
||||
|
||||
<receiver
|
||||
android:name = "com.gh.gamecenter.receiver.ActivitySkipReceiver"
|
||||
@ -411,30 +435,30 @@
|
||||
</receiver >
|
||||
|
||||
<!--魅族push应用定义消息receiver声明 -->
|
||||
<receiver android:name="com.gh.gamecenter.receiver.MeizuPushReceiver">
|
||||
<intent-filter>
|
||||
<receiver android:name = "com.gh.gamecenter.receiver.MeizuPushReceiver" >
|
||||
<intent-filter >
|
||||
<!-- 接收push消息 -->
|
||||
<action android:name="com.meizu.flyme.push.intent.MESSAGE" />
|
||||
<action android:name = "com.meizu.flyme.push.intent.MESSAGE" />
|
||||
<!-- 接收register消息 -->
|
||||
<action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK" />
|
||||
<action android:name = "com.meizu.flyme.push.intent.REGISTER.FEEDBACK" />
|
||||
<!-- 接收unregister消息-->
|
||||
<action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK" />
|
||||
<action android:name = "com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK" />
|
||||
<!-- 兼容低版本Flyme3推送服务配置 -->
|
||||
<action android:name="com.meizu.c2dm.intent.REGISTRATION" />
|
||||
<action android:name="com.meizu.c2dm.intent.RECEIVE" />
|
||||
<action android:name = "com.meizu.c2dm.intent.REGISTRATION" />
|
||||
<action android:name = "com.meizu.c2dm.intent.RECEIVE" />
|
||||
|
||||
<category android:name="${applicationId}"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<category android:name = "${applicationId}" />
|
||||
</intent-filter >
|
||||
</receiver >
|
||||
|
||||
<receiver
|
||||
android:name="com.gh.common.im.ImReceiver"
|
||||
android:enabled="true">
|
||||
<intent-filter android:priority="2147483647">
|
||||
<action android:name="com.gh.im"/>
|
||||
<action android:name="action_finish"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
android:name = "com.gh.common.im.ImReceiver"
|
||||
android:enabled = "true" >
|
||||
<intent-filter android:priority = "2147483647" >
|
||||
<action android:name = "com.gh.im" />
|
||||
<action android:name = "action_finish" />
|
||||
</intent-filter >
|
||||
</receiver >
|
||||
|
||||
<service android:name = "com.gh.base.GHUmengNotificationService" />
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ document.addEventListener("selectionchange", function() { RE.backuprange(); });
|
||||
|
||||
// Initializations
|
||||
RE.callback = function() {
|
||||
window.location.href = "re-callback://" + encodeURI(RE.getHtml());
|
||||
window.location.href = "re-callback://" + encodeURIComponent(RE.getHtml());
|
||||
}
|
||||
|
||||
RE.setHtml = function(contents) {
|
||||
@ -226,6 +226,15 @@ RE.replaceTbImage = function(imgRuleFlag, gifRuleFlag) {
|
||||
bigImg.style.cssText = "max-width: 20%; margin:15px 0 0 0; height: auto;"
|
||||
img.parentNode.insertBefore(bigImg, img.parentNode.childNodes[0]);
|
||||
i++;
|
||||
|
||||
if(img.parentNode != null) {
|
||||
img.parentNode.style.cssText += "text-align: left;"
|
||||
}
|
||||
|
||||
if(img.parentNode != null && img.parentNode.parentNode != null) {
|
||||
img.parentNode.parentNode.style.cssText += "text-align: left;"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Window;
|
||||
|
||||
import com.gh.common.util.DataUtils;
|
||||
@ -208,4 +209,16 @@ public abstract class BaseActivity extends BaseToolBarActivity implements EasyPe
|
||||
public void onPermissionsGranted(int requestCode, List<String> perms) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String mergeEntranceAndPath(String entrance, String path) {
|
||||
if (TextUtils.isEmpty(entrance) && TextUtils.isEmpty(path)) return "";
|
||||
if (TextUtils.isEmpty(entrance) && !TextUtils.isEmpty(path)) {
|
||||
return StringUtils.buildString("(", path, ")");
|
||||
}
|
||||
if (!TextUtils.isEmpty(entrance) && TextUtils.isEmpty(path)) {
|
||||
return entrance;
|
||||
}
|
||||
return StringUtils.buildString(entrance, "+(", path, ")");
|
||||
}
|
||||
}
|
||||
|
||||
112
app/src/main/java/com/gh/base/BaseActivity_TabLayout.java
Normal file
112
app/src/main/java/com/gh/base/BaseActivity_TabLayout.java
Normal file
@ -0,0 +1,112 @@
|
||||
package com.gh.base;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.base.adapter.FragmentAdapter;
|
||||
import com.gh.common.view.TabIndicatorView;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.lightgame.view.NoScrollableViewPager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by khy on 15/03/18.
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity_TabLayout extends BaseActivity implements ViewPager.OnPageChangeListener {
|
||||
|
||||
public static final String PAGE_INDEX = "PAGE_INDEX";
|
||||
|
||||
@BindView(R.id.activity_tab_layout)
|
||||
protected TabLayout mTabLayout;
|
||||
@BindView(R.id.activity_view_pager)
|
||||
protected NoScrollableViewPager mViewPager;
|
||||
@BindView(R.id.activity_tab_indicator)
|
||||
protected TabIndicatorView mTabIndicatorView;
|
||||
|
||||
protected List<Fragment> mFragmentsList;
|
||||
|
||||
protected List<String> mTabTitleList;
|
||||
|
||||
protected int mCheckedIndex = 0;
|
||||
|
||||
protected abstract void initFragmentList(List<Fragment> fragments);
|
||||
|
||||
protected abstract void initTabTitleList(List<String> tabTitleList);
|
||||
|
||||
protected int provideIndicatorWidth() {
|
||||
return 65;
|
||||
}
|
||||
|
||||
protected View provideTabView(int position, String tabTitle) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_tablayout_viewpager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
List<Fragment> fragments = getSupportFragmentManager().getFragments();
|
||||
if (fragments != null) {
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getIntent() != null) mCheckedIndex = getIntent().getIntExtra(PAGE_INDEX, 0);
|
||||
mFragmentsList = new ArrayList<>();
|
||||
initFragmentList(mFragmentsList);
|
||||
mTabTitleList = new ArrayList<>();
|
||||
initTabTitleList(mTabTitleList);
|
||||
|
||||
mViewPager.setOffscreenPageLimit(mFragmentsList.size());
|
||||
mViewPager.addOnPageChangeListener(this);
|
||||
mViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), mFragmentsList, mTabTitleList));
|
||||
mViewPager.setCurrentItem(mCheckedIndex);
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
mTabIndicatorView.setupWithTabLayout(mTabLayout);
|
||||
mTabIndicatorView.setupWithViewPager(mViewPager);
|
||||
mTabIndicatorView.setIndicatorWidth(provideIndicatorWidth());
|
||||
|
||||
for (int i = 0; i < mTabLayout.getTabCount(); i++) {
|
||||
TabLayout.Tab tab = mTabLayout.getTabAt(i);
|
||||
if (tab == null) continue;
|
||||
View tabView = provideTabView(i, tab.getText() != null ? tab.getText().toString() : "");
|
||||
if (tabView == null) continue;
|
||||
tab.setCustomView(tabView);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -157,7 +157,7 @@ class GHUmengNotificationService : UmengMessageService() {
|
||||
EntranceUtils.jumpActivity(context, bundle)
|
||||
|
||||
DataUtils.onMtaEvent(context, "消息弹窗",
|
||||
type, "")
|
||||
type, "Does not contains any parameter.")
|
||||
|
||||
Notifier.hide()
|
||||
})
|
||||
|
||||
@ -55,7 +55,7 @@ public abstract class BaseFragment_TabLayout extends NormalFragment implements V
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.fragment_taglyout_viewpager;
|
||||
return R.layout.fragment_tablayout_viewpager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,20 +1,60 @@
|
||||
package com.gh.common
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
/**
|
||||
* 统计用户在当前 Fragment 的停留时间,在 onViewDestroy 或 onDestroy 里获取 elapsedTime 即可,单位为秒
|
||||
*/
|
||||
class TimeElapsedHelper(var fragment: Fragment) {
|
||||
class TimeElapsedHelper(val fragment: Fragment?, val activity: Activity?) {
|
||||
|
||||
constructor(fragment: Fragment) : this(fragment, null)
|
||||
|
||||
constructor(activity: Activity) : this(null, activity)
|
||||
|
||||
private var isWorking = false
|
||||
|
||||
var elapsedTime: Int = 0
|
||||
|
||||
init {
|
||||
fragment.fragmentManager?.registerFragmentLifecycleCallbacks(
|
||||
activity?.application?.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
|
||||
override fun onActivityStarted(a: Activity?) {
|
||||
}
|
||||
|
||||
override fun onActivitySaveInstanceState(a: Activity?, outState: Bundle?) {
|
||||
}
|
||||
|
||||
override fun onActivityStopped(a: Activity?) {
|
||||
}
|
||||
|
||||
override fun onActivityCreated(a: Activity?, savedInstanceState: Bundle?) {
|
||||
}
|
||||
|
||||
override fun onActivityPaused(a: Activity?) {
|
||||
if (activity == a) {
|
||||
pauseCounting()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResumed(a: Activity?) {
|
||||
if (activity == a) {
|
||||
resumeCounting()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityDestroyed(a: Activity?) {
|
||||
if (activity == a) {
|
||||
HaloApp.getInstance().application.unregisterActivityLifecycleCallbacks(this)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
fragment?.fragmentManager?.registerFragmentLifecycleCallbacks(
|
||||
object : FragmentManager.FragmentLifecycleCallbacks() {
|
||||
override fun onFragmentResumed(fm: FragmentManager?, f: Fragment?) {
|
||||
if (f === fragment) {
|
||||
|
||||
@ -42,7 +42,7 @@ public class Config {
|
||||
public static final String UMENG_APPKEY = BuildConfig.UMENG_APPKEY;
|
||||
public static final String UMENG_MESSAGE_SECRET = BuildConfig.UMENG_MESSAGE_SECRET;
|
||||
public static final String BUGLY_APPID = BuildConfig.BUGLY_APPID;
|
||||
public static final String PATCH_VERSION_NAME = BuildConfig.PATCH_VERSION_NAME; // 补丁包版本 对应关于->版本号
|
||||
public static final String PATCH_VERSION_NAME = BuildConfig.PATCH_VERSION_NAME; // 补丁包版本 对应关于->版本号 使用:PackageUtils.getPatchVersionName()
|
||||
// http://www.ghzs666.com/article/${articleId}.html
|
||||
public static final String URL_ARTICLE = "http://www.ghzs666.com/article/"; // TODO ghzs/ghzs666 统一
|
||||
public static final String PATCHES = "patches";
|
||||
|
||||
@ -15,6 +15,10 @@ public class Constants {
|
||||
public static final String USER_TOKEN_KEY = "userTokenKey";
|
||||
public static final String USER_INFO_KEY = "userInfoKey";
|
||||
|
||||
public static final String DEVICE_KEY = "deviceKey";
|
||||
|
||||
public static final String XPOSED_INSTALLER_PACKAGE_NAME = "de.robv.android.xposed.installer";
|
||||
|
||||
// 最近显示的弹窗信息
|
||||
public static final String SP_LAST_OPENING_ID = "last_opening_dialog_id";
|
||||
public static final String SP_LAST_OPENING_TIME = "last_opening_dialog_time";
|
||||
|
||||
@ -24,7 +24,6 @@ import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.GameViewUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.KaiFuUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.NumberUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
@ -40,6 +39,7 @@ import com.gh.gamecenter.databinding.KaifuDetailItemRowBinding;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.KaiFuCalendarEntity;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.eventbus.EBReuse;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
@ -48,7 +48,6 @@ import com.lightgame.utils.Utils;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -317,15 +316,13 @@ public class BindingAdapters {
|
||||
progressBar.setText("暂无下载");
|
||||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.NONE);
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(progressBar.getContext(), gameEntity);
|
||||
String status = GameUtils.getDownloadBtnText(progressBar.getContext(), gameEntity, PluginLocation.only_game);
|
||||
switch (status) {
|
||||
case "插件化":
|
||||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.PLUGIN);
|
||||
break;
|
||||
case "打开":
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
status = "启动";
|
||||
}
|
||||
case "启动":
|
||||
progressBar.setDownloadType(DownloadProgressBar.DownloadType.LAUNCH_OR_OPEN);
|
||||
break;
|
||||
default:
|
||||
@ -387,13 +384,8 @@ public class BindingAdapters {
|
||||
case NORMAL:
|
||||
case PLUGIN:
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
if (NetworkUtils.isWifiConnected(v.getContext())) {
|
||||
download(progressBar, gameEntity, traceEvent);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(v.getContext(), () -> {
|
||||
download(progressBar, gameEntity, traceEvent);
|
||||
});
|
||||
}
|
||||
DialogUtils.checkDownload(v.getContext(), gameEntity.getApk().get(0).getSize(),
|
||||
isSubscribe -> download(progressBar, gameEntity, traceEvent, isSubscribe));
|
||||
} else {
|
||||
DownloadDialog.getInstance(v.getContext()).showPopupWindow(v, gameEntity,
|
||||
"(我的光环:我的游戏)", "我的光环-我的游戏:" + gameEntity.getName(), traceEvent);
|
||||
@ -416,13 +408,14 @@ public class BindingAdapters {
|
||||
PackageUtils.launchSetup(v.getContext(), downloadEntity.getPath());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 开始下载
|
||||
private static void download(DownloadProgressBar progressBar, GameEntity
|
||||
gameEntity, ExposureEvent traceEvent) {
|
||||
gameEntity, ExposureEvent traceEvent, boolean isSubscribe) {
|
||||
String str = progressBar.getText();
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
@ -444,6 +437,7 @@ public class BindingAdapters {
|
||||
gameEntity,
|
||||
method,
|
||||
StringUtils.buildString("(我的光环:我的游戏)"), "我的光环-我的游戏:" + gameEntity.getName(),
|
||||
isSubscribe,
|
||||
downloadExposureEvent);
|
||||
|
||||
progressBar.setProgress(0);
|
||||
|
||||
@ -48,8 +48,7 @@ class ExposureListener(var fragment: Fragment, var exposable: IExposable) : Recy
|
||||
}
|
||||
|
||||
/**
|
||||
* Check disappearMap items together with according data in displayMap,
|
||||
* log any items displayed long enough to be called a EXPOSURE
|
||||
* Just commit the exposureEvent that is stored in listItem.
|
||||
*/
|
||||
private fun commitExposure(visibleState: ExposureThrottleBus.VisibleState) {
|
||||
|
||||
|
||||
@ -3,11 +3,11 @@ package com.gh.common.exposure
|
||||
import android.app.Application
|
||||
import com.aliyun.sls.android.sdk.LogException
|
||||
import com.aliyun.sls.android.sdk.model.LogGroup
|
||||
import com.gh.common.exposure.aliyun.LGLOG
|
||||
import com.gh.common.exposure.aliyun.LGLOGClient
|
||||
import com.gh.common.exposure.meta.MetaUtil
|
||||
import com.gh.common.exposure.time.TimeUtil
|
||||
import com.gh.gamecenter.BuildConfig
|
||||
import com.gh.loghub.LgLOG
|
||||
import com.gh.loghub.LoghubHelper
|
||||
import com.google.gson.Gson
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.concurrent.fixedRateTimer
|
||||
@ -18,10 +18,6 @@ import kotlin.concurrent.fixedRateTimer
|
||||
*/
|
||||
object ExposureManager {
|
||||
|
||||
private var TAG: String = ExposureManager::class.java.simpleName
|
||||
|
||||
private const val ACCESS_KEY_ID = "LTAIV3i0sNc4TPK1"
|
||||
private const val ACCESS_KEY_SECRET = "8dKtTPeE5WYA6ZCeuIBcIVp7eB0ir4"
|
||||
private const val ENDPOINT = "cn-qingdao.log.aliyuncs.com"
|
||||
private const val PROJECT = "ghzs"
|
||||
private const val STORE_SIZE = 100
|
||||
@ -29,7 +25,7 @@ object ExposureManager {
|
||||
|
||||
private var LOG_STORE = BuildConfig.EXPOSURE_REPO
|
||||
|
||||
private lateinit var client: LGLOGClient
|
||||
private var loghubHelper = LoghubHelper.getInstance()
|
||||
private lateinit var db: ExposureEventDao
|
||||
private val storeSet = hashSetOf<ExposureEvent>()
|
||||
private val storeOpThread = Executors.newSingleThreadExecutor()
|
||||
@ -40,9 +36,13 @@ object ExposureManager {
|
||||
/**
|
||||
* Must be called early to init object then real use (for example in Application)
|
||||
*/
|
||||
@JvmStatic
|
||||
fun init(application: Application) {
|
||||
|
||||
client = LGLOGClient(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET, PROJECT)
|
||||
MetaUtil.init(application)
|
||||
TimeUtil.init()
|
||||
|
||||
loghubHelper.init(ENDPOINT, PROJECT, LOG_STORE) { TimeUtil.currentTimeMillis() }
|
||||
db = ExposureDatabase.buildDatabase(application).logHubEventDao()
|
||||
|
||||
storeOpThread.execute {
|
||||
@ -53,9 +53,6 @@ object ExposureManager {
|
||||
fixedRateTimer(name = "ExposureManager-Store-Checker", initialDelay = 500, period = STORE_FORCE_UPLOAD_PERIOD) {
|
||||
checkAndUploadFromDatabase(true)
|
||||
}
|
||||
|
||||
MetaUtil.init(application)
|
||||
TimeUtil.init()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +101,6 @@ object ExposureManager {
|
||||
exposureCache.add(event.id)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +109,7 @@ object ExposureManager {
|
||||
*/
|
||||
private fun upload(event: ExposureEvent) {
|
||||
storeOpThread.execute {
|
||||
client.PostLog(buildLogGroup(event), LOG_STORE)
|
||||
loghubHelper.uploadLogGroup(buildLogGroup(event))
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,7 +118,7 @@ object ExposureManager {
|
||||
*/
|
||||
private fun upload(eventList: List<ExposureEvent>) {
|
||||
storeOpThread.execute {
|
||||
client.PostLog(buildLogGroup(eventList), LOG_STORE)
|
||||
loghubHelper.uploadLogGroup(buildLogGroup(eventList))
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +130,7 @@ object ExposureManager {
|
||||
if (storeSet.size < STORE_SIZE && !isForceUpload || storeSet.size == 0) return@execute
|
||||
val uploaded = storeSet.toList()
|
||||
try {
|
||||
client.PostLog(buildLogGroup(uploaded), LOG_STORE)
|
||||
loghubHelper.uploadLogGroup(buildLogGroup(uploaded))
|
||||
} catch (exception: LogException) {
|
||||
// Return to insure no logs lost because of online commit failure
|
||||
return@execute
|
||||
@ -144,8 +140,8 @@ object ExposureManager {
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildLog(event: ExposureEvent): LGLOG {
|
||||
val log = LGLOG()
|
||||
private fun buildLog(event: ExposureEvent): LgLOG {
|
||||
val log = LgLOG(TimeUtil.currentTime())
|
||||
|
||||
log.PutContent("id", event.id)
|
||||
log.PutContent("payload", gson.toJson(event.payload))
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
package com.gh.common.exposure.aliyun;
|
||||
|
||||
import com.aliyun.sls.android.sdk.model.Log;
|
||||
import com.gh.common.exposure.time.TimeUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Extend to change __time__ field in mContent to use the correct time from TimeUtil
|
||||
*/
|
||||
public class LGLOG extends Log {
|
||||
|
||||
private Map<String, Object> mContent = new HashMap<String, Object>();
|
||||
|
||||
public LGLOG() {
|
||||
mContent.put("__time__", TimeUtil.INSTANCE.currentTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void PutTime(int time) {
|
||||
mContent.put("__time__", time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void PutContent(String key, String value) {
|
||||
if (key == null || key.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
mContent.put(key, "");
|
||||
} else {
|
||||
mContent.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> GetContent() {
|
||||
return mContent;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
package com.gh.common.exposure.aliyun;
|
||||
|
||||
import com.aliyun.sls.android.sdk.LOGClient;
|
||||
import com.aliyun.sls.android.sdk.LogException;
|
||||
import com.gh.common.exposure.time.TimeUtil;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Extend to override GetHttpHeadersFrom, so we can change "Date" header attribute using
|
||||
* correct time from TimeUtil.
|
||||
* And accordingly, the value of "Authorization" attribute should also be re-calculate
|
||||
* since the sign became different as before.
|
||||
*/
|
||||
public class LGLOGClient extends LOGClient {
|
||||
|
||||
private String mAccessKeyID;
|
||||
private String mAccessKeySecret;
|
||||
private String mAccessToken;
|
||||
|
||||
public LGLOGClient(String endPoint, String accessKeyID, String accessKeySecret, String projectName) {
|
||||
super(endPoint, accessKeyID, accessKeySecret, projectName);
|
||||
this.mAccessKeyID = accessKeyID;
|
||||
this.mAccessKeySecret = accessKeySecret;
|
||||
this.mAccessToken = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> GetHttpHeadersFrom(String logStoreName, byte[] body, byte[] bodyZipped) throws LogException {
|
||||
|
||||
Map<String, String> headers = super.GetHttpHeadersFrom(logStoreName, body, bodyZipped);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); // 设置时区为GMT
|
||||
String str = sdf.format(new Date(TimeUtil.INSTANCE.currentTimeMillis()));
|
||||
headers.put("Date", str);
|
||||
|
||||
StringBuilder signStringBuf = new StringBuilder("POST" + "\n").
|
||||
append(headers.get("Content-MD5") + "\n").
|
||||
append(headers.get("Content-Type") + "\n").
|
||||
append(headers.get("Date") + "\n");
|
||||
String token = mAccessToken;
|
||||
if (token != null && token != "") {
|
||||
headers.put("x-acs-security-token", token);
|
||||
signStringBuf.append("x-acs-security-token:" + headers.get("x-acs-security-token") + "\n");
|
||||
}
|
||||
signStringBuf.append("x-log-apiversion:0.6.0\n").
|
||||
append("x-log-bodyrawsize:" + headers.get("x-log-bodyrawsize") + "\n").
|
||||
append("x-log-compresstype:deflate\n").
|
||||
append("x-log-signaturemethod:hmac-sha1\n").
|
||||
append("/logstores/" + logStoreName + "/shards/lb");
|
||||
String signString = signStringBuf.toString();
|
||||
try {
|
||||
String sign = hmac_sha1(signString, mAccessKeySecret);
|
||||
headers.put("Authorization", "LOG " + mAccessKeyID + ":" + sign);
|
||||
} catch (Exception e) {
|
||||
throw new LogException("LogClientError", "fail to get encode signature", e, "");
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -17,6 +17,7 @@ data class Meta(
|
||||
val network: String? = "",
|
||||
val ip: String? = "",
|
||||
val os: String? = "",
|
||||
val gid: String? = "",
|
||||
val channel: String? = "",
|
||||
val appVersion: String? = "",
|
||||
val userId: String? = "",
|
||||
|
||||
@ -12,6 +12,7 @@ import android.telephony.TelephonyManager
|
||||
import android.text.TextUtils
|
||||
import com.gh.gamecenter.BuildConfig
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.leon.channel.helper.ChannelReaderUtil
|
||||
import java.io.File
|
||||
|
||||
@ -28,7 +29,7 @@ object MetaUtil {
|
||||
|
||||
fun refreshMeta() {
|
||||
m = Meta(getMac(), getIMEI(), getModel(), getManufacturer(), getAndroidId(), getAndroidSDK(),
|
||||
getAndroidVersion(), getNetwork(), getIP(), getOS(), getChannel(), BuildConfig.VERSION_NAME, UserManager.getInstance().userId, BuildConfig.EXPOSURE_VERSION)
|
||||
getAndroidVersion(), getNetwork(), getIP(), getOS(), HaloApp.getInstance().gid, getChannel(), BuildConfig.VERSION_NAME, UserManager.getInstance().userId, BuildConfig.EXPOSURE_VERSION)
|
||||
}
|
||||
|
||||
fun getMeta(): Meta {
|
||||
|
||||
@ -9,7 +9,11 @@ object TimeUtil {
|
||||
}
|
||||
|
||||
fun currentTime(): Int {
|
||||
return ( ( corrector.delta + System.currentTimeMillis() ) / 1000 ).toInt()
|
||||
return if (::corrector.isInitialized) {
|
||||
((corrector.delta + System.currentTimeMillis()) / 1000).toInt()
|
||||
} else {
|
||||
(System.currentTimeMillis() / 1000).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
43
app/src/main/java/com/gh/common/observer/VolumeObserver.kt
Normal file
43
app/src/main/java/com/gh/common/observer/VolumeObserver.kt
Normal file
@ -0,0 +1,43 @@
|
||||
package com.gh.common.observer
|
||||
|
||||
import android.content.Context
|
||||
import android.database.ContentObserver
|
||||
import android.media.AudioManager
|
||||
import android.os.Handler
|
||||
|
||||
class VolumeObserver(var context: Context, handler: Handler, var callback: MuteCallback? = null)
|
||||
: ContentObserver(handler) {
|
||||
var previousVolume: Int = 0
|
||||
|
||||
init {
|
||||
val audio = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
previousVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||
}
|
||||
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
super.onChange(selfChange)
|
||||
|
||||
val audio = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
val currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC)
|
||||
|
||||
val delta = previousVolume - currentVolume
|
||||
|
||||
if (delta != 0) {
|
||||
if (currentVolume == 0) {
|
||||
callback?.onMute(true)
|
||||
} else {
|
||||
callback?.onMute(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (delta > 0) {
|
||||
previousVolume = currentVolume
|
||||
} else if (delta < 0) {
|
||||
previousVolume = currentVolume
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface MuteCallback {
|
||||
fun onMute(isMute: Boolean)
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package com.gh.common.repository
|
||||
|
||||
import com.gh.common.util.RandomUtils
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.tencent.bugly.beta.tinker.TinkerManager.getApplication
|
||||
import io.reactivex.Observable
|
||||
|
||||
// 热门卡牌的仓库
|
||||
object RemenkapaiRepository {
|
||||
|
||||
var remenkapaiList = arrayListOf<GameEntity>()
|
||||
|
||||
@JvmStatic
|
||||
fun getRemenkapai(size: Int): Observable<List<GameEntity>> {
|
||||
return if (remenkapaiList.isEmpty()) {
|
||||
RetrofitManager.getInstance(getApplication()).api.remenkapai
|
||||
.map { gameList -> filterEntityWithoutApk(gameList) }
|
||||
.map { pickRandomSizeEntity(size) }
|
||||
} else {
|
||||
Observable.create { emitter -> emitter.onNext(pickRandomSizeEntity(size)) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择随机数量的热门卡牌
|
||||
*/
|
||||
private fun pickRandomSizeEntity(size: Int): List<GameEntity> {
|
||||
val randomGameList = arrayListOf<GameEntity>()
|
||||
val randomArray = RandomUtils.getRandomArray(size, remenkapaiList.size)
|
||||
for (i in randomArray) {
|
||||
randomGameList.add(remenkapaiList[i])
|
||||
}
|
||||
return randomGameList
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤没有 Apk 的实体
|
||||
*/
|
||||
private fun filterEntityWithoutApk(gameList: List<GameEntity>): List<GameEntity> {
|
||||
val realGameList = arrayListOf<GameEntity>()
|
||||
for (gameEntity in gameList) {
|
||||
val apk = gameEntity.getApk()
|
||||
if (apk.size != 0) {
|
||||
realGameList.add(gameEntity)
|
||||
}
|
||||
}
|
||||
remenkapaiList = realGameList
|
||||
return remenkapaiList
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,7 +19,7 @@ import retrofit2.HttpException
|
||||
object CollectionUtils {
|
||||
|
||||
enum class CollectionType {
|
||||
toolkit, article, answer
|
||||
toolkit, article, answer, communityArticle
|
||||
}
|
||||
|
||||
fun postCollection(context: Context, content: String, type: CollectionType, listener: OnCollectionListener) {
|
||||
@ -28,6 +28,7 @@ object CollectionUtils {
|
||||
CollectionType.article -> RetrofitManager.getInstance(context).getApi().postCollectionArticle(UserManager.getInstance().userId, content)
|
||||
CollectionType.toolkit -> RetrofitManager.getInstance(context).getApi().postCollectionTools(UserManager.getInstance().userId, content)
|
||||
CollectionType.answer -> RetrofitManager.getInstance(context).getApi().postCollectionAnswer(UserManager.getInstance().userId, content)
|
||||
else -> return
|
||||
}
|
||||
postCollection
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -36,7 +37,6 @@ object CollectionUtils {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
listener.onSuccess()
|
||||
if(type != CollectionType.answer)
|
||||
EventBus.getDefault().post(EBCollectionChanged(content, true, type))
|
||||
}
|
||||
|
||||
@ -66,6 +66,7 @@ object CollectionUtils {
|
||||
CollectionType.article -> postCollection = RetrofitManager.getInstance(context).getApi().deletaCollectionArticle(UserManager.getInstance().userId, id)
|
||||
CollectionType.toolkit -> postCollection = RetrofitManager.getInstance(context).getApi().deleteCollectionTools(UserManager.getInstance().userId, id)
|
||||
CollectionType.answer -> postCollection = RetrofitManager.getInstance(context).getApi().deleteCollectionAnswer(UserManager.getInstance().userId, id)
|
||||
else -> return
|
||||
}
|
||||
postCollection
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -74,7 +75,6 @@ object CollectionUtils {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
super.onResponse(response)
|
||||
listener.onSuccess()
|
||||
if(type != CollectionType.answer)
|
||||
EventBus.getDefault().post(EBCollectionChanged(id, false, type))
|
||||
}
|
||||
|
||||
|
||||
209
app/src/main/java/com/gh/common/util/CommentHelper.kt
Normal file
209
app/src/main/java/com/gh/common/util/CommentHelper.kt
Normal file
@ -0,0 +1,209 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.text.TextUtils
|
||||
import android.view.Window
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.gh.common.util.CommentUtils.copyText
|
||||
import com.gh.gamecenter.CommentDetailActivity
|
||||
import com.gh.gamecenter.MessageDetailActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.OnCommentCallBackListener
|
||||
import com.gh.gamecenter.entity.CommentEntity
|
||||
import com.lightgame.utils.Utils
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
object CommentHelper {
|
||||
|
||||
// TODO 合并这两个方法的共同部分
|
||||
@JvmStatic
|
||||
fun showCommunityArticleCommentOptions(
|
||||
context: Context,
|
||||
commentEntity: CommentEntity,
|
||||
showConversation: Boolean,
|
||||
articleId: String,
|
||||
communityId: String,
|
||||
listener: OnCommentCallBackListener?) {
|
||||
val dialogOptions = ArrayList<String>()
|
||||
|
||||
if (commentEntity.me == null || !commentEntity.me?.isAnswerCommented!!) {
|
||||
dialogOptions.add("回复")
|
||||
}
|
||||
|
||||
dialogOptions.add("复制")
|
||||
dialogOptions.add("举报")
|
||||
|
||||
if (commentEntity.parentUser != null && showConversation) {
|
||||
dialogOptions.add("查看对话")
|
||||
}
|
||||
|
||||
val dialog: Dialog
|
||||
|
||||
dialog = createOptionsSelectDialog(context, dialogOptions) {
|
||||
when (it) {
|
||||
"回复" -> {
|
||||
CheckLoginUtils.checkLogin(context) {
|
||||
if (listener != null) {
|
||||
listener.onCommentCallback(commentEntity)
|
||||
} else if (!TextUtils.isEmpty(commentEntity.id)) {
|
||||
context.startActivity(MessageDetailActivity.getMessageDetailIntent(context, commentEntity, commentEntity.id))
|
||||
} else {
|
||||
Utils.toast(context, "缺少关键属性")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"复制" -> copyText(commentEntity.content, context)
|
||||
|
||||
"举报" -> CheckLoginUtils.checkLogin(context) {
|
||||
showReportTypeDialog(context) { reportType ->
|
||||
PostCommentUtils.reportCommunityArticleComment(context, communityId, articleId, commentEntity.id, reportType,
|
||||
object : PostCommentUtils.PostCommentListener {
|
||||
override fun postSuccess(response: JSONObject?) {
|
||||
Utils.toast(context, "感谢您的举报")
|
||||
}
|
||||
|
||||
override fun postFailed(error: Throwable?) {
|
||||
if (error == null) {
|
||||
Utils.toast(context, "举报失败,请稍后重试")
|
||||
} else {
|
||||
Utils.toast(context, "举报失败,${error.message}")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
"查看对话" -> {
|
||||
context.startActivity(CommentDetailActivity
|
||||
.getCommunityArticleCommentIntent(context, articleId, commentEntity.id, communityId, null))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun showAnswerCommentOptions(
|
||||
context: Context,
|
||||
commentEntity: CommentEntity,
|
||||
showConversation: Boolean,
|
||||
answerId: String,
|
||||
listener: OnCommentCallBackListener?) {
|
||||
val dialogOptions = ArrayList<String>()
|
||||
|
||||
if (commentEntity.me == null || !commentEntity.me?.isAnswerCommented!!) {
|
||||
dialogOptions.add("回复")
|
||||
}
|
||||
|
||||
dialogOptions.add("复制")
|
||||
dialogOptions.add("举报")
|
||||
|
||||
if (commentEntity.parentUser != null && showConversation) {
|
||||
dialogOptions.add("查看对话")
|
||||
}
|
||||
|
||||
val dialog: Dialog
|
||||
|
||||
dialog = createOptionsSelectDialog(context, dialogOptions) {
|
||||
when (it) {
|
||||
"回复" -> {
|
||||
CheckLoginUtils.checkLogin(context) {
|
||||
if (listener != null) {
|
||||
listener.onCommentCallback(commentEntity)
|
||||
} else if (!TextUtils.isEmpty(commentEntity.id)) {
|
||||
context.startActivity(MessageDetailActivity.getMessageDetailIntent(context, commentEntity, commentEntity.id))
|
||||
} else {
|
||||
Utils.toast(context, "缺少关键属性")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"复制" -> copyText(commentEntity.content, context)
|
||||
|
||||
"举报" -> CheckLoginUtils.checkLogin(context) {
|
||||
showReportTypeDialog(context) { reportType ->
|
||||
PostCommentUtils.postAnswerReportData(context, commentEntity.id, answerId, reportType,
|
||||
object : PostCommentUtils.PostCommentListener {
|
||||
override fun postSuccess(response: JSONObject?) {
|
||||
Utils.toast(context, "感谢您的举报")
|
||||
}
|
||||
|
||||
override fun postFailed(error: Throwable?) {
|
||||
if (error == null) {
|
||||
Utils.toast(context, "举报失败,请稍后重试")
|
||||
} else {
|
||||
Utils.toast(context, "举报失败,${error.message}")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
"查看对话" -> {
|
||||
context.startActivity(CommentDetailActivity
|
||||
.getAnswerCommentIntent(context, commentEntity.id, answerId, null))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private fun showReportTypeDialog(context: Context, reportCallback: (reportType: String) -> Unit) {
|
||||
val reportTypes = arrayListOf("垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息", "违法有害信息", "其它")
|
||||
|
||||
val dialog = createOptionsSelectDialog(context, reportTypes) {
|
||||
val jsonObject = JSONObject()
|
||||
try {
|
||||
jsonObject.put("reason", it)
|
||||
reportCallback.invoke(jsonObject.toString())
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun createOptionsSelectDialog(
|
||||
context: Context,
|
||||
dialogOptions: ArrayList<String>,
|
||||
clickCallback: (text: String) -> Unit): Dialog {
|
||||
val dialog = Dialog(context)
|
||||
|
||||
val container = LinearLayout(context)
|
||||
container.orientation = LinearLayout.VERTICAL
|
||||
container.setBackgroundColor(Color.WHITE)
|
||||
container.setPadding(0, DisplayUtils.dip2px(context, 12f), 0, DisplayUtils.dip2px(context, 12f))
|
||||
|
||||
for (s in dialogOptions) {
|
||||
val reportTv = TextView(context)
|
||||
reportTv.text = s
|
||||
reportTv.textSize = 17f
|
||||
reportTv.setTextColor(ContextCompat.getColor(context, R.color.title))
|
||||
reportTv.setBackgroundResource(R.drawable.textview_white_style)
|
||||
val widthPixels = context.resources.displayMetrics.widthPixels
|
||||
reportTv.layoutParams = LinearLayout.LayoutParams(widthPixels * 9 / 10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT)
|
||||
reportTv.setPadding(DisplayUtils.dip2px(context, 20f), DisplayUtils.dip2px(context, 12f),
|
||||
0, DisplayUtils.dip2px(context, 12f))
|
||||
container.addView(reportTv)
|
||||
|
||||
reportTv.setOnClickListener {
|
||||
dialog.cancel()
|
||||
clickCallback.invoke(reportTv.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
dialog.setContentView(container)
|
||||
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ import android.app.Dialog;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
@ -19,8 +20,11 @@ import com.gh.gamecenter.adapter.OnCommentCallBackListener;
|
||||
import com.gh.gamecenter.adapter.viewholder.CommentViewHolder;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
import com.gh.gamecenter.entity.MeEntity;
|
||||
import com.gh.gamecenter.entity.RatingComment;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
@ -33,6 +37,11 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
/**
|
||||
@ -71,6 +80,109 @@ public class CommentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void showGameCommentOptions(final Context context, final RatingComment comment, final String gameId) {
|
||||
|
||||
final Dialog dialog = new Dialog(context);
|
||||
|
||||
LinearLayout container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
container.setPadding(0, DisplayUtils.dip2px(context, 12), 0, DisplayUtils.dip2px(context, 12));
|
||||
|
||||
List<String> dialogType = new ArrayList<>();
|
||||
|
||||
dialogType.add("复制");
|
||||
dialogType.add("举报");
|
||||
|
||||
|
||||
for (String s : dialogType) {
|
||||
final TextView reportTv = new TextView(context);
|
||||
reportTv.setText(s);
|
||||
reportTv.setTextSize(17);
|
||||
reportTv.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
reportTv.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 12),
|
||||
0, DisplayUtils.dip2px(context, 12));
|
||||
container.addView(reportTv);
|
||||
|
||||
reportTv.setOnClickListener(v -> {
|
||||
dialog.cancel();
|
||||
switch (reportTv.getText().toString()) {
|
||||
case "复制":
|
||||
copyText(comment.getContent(), context);
|
||||
break;
|
||||
case "举报":
|
||||
CheckLoginUtils.checkLogin(context, () -> showGameCommentReportDialog(gameId, comment, context));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(container);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static void showGameCommentReportDialog(final String gameId, final RatingComment comment, final Context context) {
|
||||
final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息",
|
||||
"违法有害信息", "其它"};
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
|
||||
final Dialog reportTypeDialog = new Dialog(context);
|
||||
LinearLayout container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setPadding(0, DisplayUtils.dip2px(context, 12), 0, DisplayUtils.dip2px(context, 12));
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
|
||||
for (final String s : arrReportType) {
|
||||
TextView reportTypeTv = new TextView(context);
|
||||
reportTypeTv.setText(s);
|
||||
reportTypeTv.setTextSize(17);
|
||||
reportTypeTv.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
reportTypeTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
reportTypeTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
reportTypeTv.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 12),
|
||||
0, DisplayUtils.dip2px(context, 12));
|
||||
container.addView(reportTypeTv);
|
||||
|
||||
reportTypeTv.setOnClickListener(v -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("reason", s);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.reportGameComment(gameId, comment.getId(), body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(@Nullable ResponseBody response) {
|
||||
Utils.toast(context, "感谢您的举报");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nullable HttpException e) {
|
||||
Utils.toast(context, "举报失败,请先检查网络设置");
|
||||
}
|
||||
});
|
||||
|
||||
reportTypeDialog.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
reportTypeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
reportTypeDialog.setContentView(container);
|
||||
reportTypeDialog.show();
|
||||
}
|
||||
|
||||
|
||||
public static void showReportDialog(final CommentEntity commentEntity, final Context context, final boolean showConversation,
|
||||
final OnCommentCallBackListener listener, final String newsId) {
|
||||
|
||||
@ -144,125 +256,134 @@ public class CommentUtils {
|
||||
|
||||
}
|
||||
|
||||
public static void showAnswerCommentOptions(final CommentEntity commentEntity, final Context context,
|
||||
final OnCommentCallBackListener listener, final String id, boolean showConversation, String answerId) {
|
||||
// public static void showAnswerCommentOptions(final CommentEntity commentEntity, final Context context,
|
||||
// final OnCommentCallBackListener listener, final String id,
|
||||
// boolean showConversation, String answerId, String articleId, String articleCommunityId) {
|
||||
//
|
||||
// final Dialog dialog = new Dialog(context);
|
||||
//
|
||||
// LinearLayout container = new LinearLayout(context);
|
||||
// container.setOrientation(LinearLayout.VERTICAL);
|
||||
// container.setBackgroundColor(Color.WHITE);
|
||||
// container.setPadding(0, DisplayUtils.dip2px(context, 12), 0, DisplayUtils.dip2px(context, 12));
|
||||
//
|
||||
// List<String> dialogType = new ArrayList<>();
|
||||
//
|
||||
// if (commentEntity.getMe() == null || !commentEntity.getMe().isAnswerCommented()) {
|
||||
// dialogType.add("回复");
|
||||
// }
|
||||
//
|
||||
// dialogType.add("复制");
|
||||
// dialogType.add("举报");
|
||||
//
|
||||
// if (commentEntity.getParentUser() != null && showConversation) {
|
||||
// dialogType.add("查看对话");
|
||||
// }
|
||||
//
|
||||
// for (String s : dialogType) {
|
||||
// final TextView reportTv = new TextView(context);
|
||||
// reportTv.setText(s);
|
||||
// reportTv.setTextSize(17);
|
||||
// reportTv.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
// reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
// int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
// reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
||||
// LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
// reportTv.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 12),
|
||||
// 0, DisplayUtils.dip2px(context, 12));
|
||||
// container.addView(reportTv);
|
||||
//
|
||||
// reportTv.setOnClickListener(v -> {
|
||||
// dialog.cancel();
|
||||
// switch (reportTv.getText().toString()) {
|
||||
// case "回复":
|
||||
// CheckLoginUtils.checkLogin(context, () -> {
|
||||
// if (listener != null) {
|
||||
// listener.onCommentCallback(commentEntity);
|
||||
// } else if (!TextUtils.isEmpty(id)) {
|
||||
// context.startActivity(MessageDetailActivity.getMessageDetailIntent(context, commentEntity, id));
|
||||
// } else {
|
||||
// Utils.toast(context, "缺少关键属性");
|
||||
// }
|
||||
// });
|
||||
// break;
|
||||
// case "复制":
|
||||
// copyText(commentEntity.getContent(), context);
|
||||
// break;
|
||||
// case "举报":
|
||||
// CheckLoginUtils.checkLogin(context, () -> showAnswerReportDialog(answerId, commentEntity, context));
|
||||
// break;
|
||||
// case "查看对话":
|
||||
// if (TextUtils.isEmpty(articleId)) {
|
||||
// context.startActivity(CommentDetailActivity.getAnswerCommentIntent(context, commentEntity.getId(), answerId, null));
|
||||
// } else {
|
||||
// context.startActivity(CommentDetailActivity.getCommunityArticleCommentIntent(context, articleId, commentEntity.getId(), articleCommunityId, null));
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
// dialog.setContentView(container);
|
||||
// dialog.show();
|
||||
// }
|
||||
|
||||
final Dialog dialog = new Dialog(context);
|
||||
|
||||
LinearLayout container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
container.setPadding(0, DisplayUtils.dip2px(context, 12), 0, DisplayUtils.dip2px(context, 12));
|
||||
|
||||
List<String> dialogType = new ArrayList<>();
|
||||
|
||||
if (commentEntity.getMe() == null || !commentEntity.getMe().isAnswerCommented()) {
|
||||
dialogType.add("回复");
|
||||
}
|
||||
|
||||
dialogType.add("复制");
|
||||
dialogType.add("举报");
|
||||
|
||||
if (commentEntity.getParentUser() != null && showConversation) {
|
||||
dialogType.add("查看对话");
|
||||
}
|
||||
|
||||
for (String s : dialogType) {
|
||||
final TextView reportTv = new TextView(context);
|
||||
reportTv.setText(s);
|
||||
reportTv.setTextSize(17);
|
||||
reportTv.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
reportTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
reportTv.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 12),
|
||||
0, DisplayUtils.dip2px(context, 12));
|
||||
container.addView(reportTv);
|
||||
|
||||
reportTv.setOnClickListener(v -> {
|
||||
dialog.cancel();
|
||||
switch (reportTv.getText().toString()) {
|
||||
case "回复":
|
||||
CheckLoginUtils.checkLogin(context, () -> {
|
||||
if (listener != null) {
|
||||
listener.onCommentCallback(commentEntity);
|
||||
} else if (!TextUtils.isEmpty(id)) {
|
||||
context.startActivity(MessageDetailActivity.getMessageDetailIntent(context, commentEntity, id));
|
||||
} else {
|
||||
Utils.toast(context, "缺少关键属性");
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "复制":
|
||||
copyText(commentEntity.getContent(), context);
|
||||
break;
|
||||
case "举报":
|
||||
CheckLoginUtils.checkLogin(context, () -> showAnswerReportDialog(answerId, commentEntity, context));
|
||||
break;
|
||||
case "查看对话":
|
||||
context.startActivity(CommentDetailActivity.getAnswerCommentIntent(context, commentEntity.getId(), answerId));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(container);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private static void showAnswerReportDialog(final String answerId, final CommentEntity commentEntity, final Context context) {
|
||||
final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息",
|
||||
"违法有害信息", "其它"};
|
||||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
|
||||
final Dialog reportTypeDialog = new Dialog(context);
|
||||
LinearLayout container = new LinearLayout(context);
|
||||
container.setOrientation(LinearLayout.VERTICAL);
|
||||
container.setPadding(0, DisplayUtils.dip2px(context, 12), 0, DisplayUtils.dip2px(context, 12));
|
||||
container.setBackgroundColor(Color.WHITE);
|
||||
|
||||
for (final String s : arrReportType) {
|
||||
TextView reportTypeTv = new TextView(context);
|
||||
reportTypeTv.setText(s);
|
||||
reportTypeTv.setTextSize(17);
|
||||
reportTypeTv.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
reportTypeTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
reportTypeTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
reportTypeTv.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 12),
|
||||
0, DisplayUtils.dip2px(context, 12));
|
||||
container.addView(reportTypeTv);
|
||||
|
||||
reportTypeTv.setOnClickListener(v -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
try {
|
||||
jsonObject.put("reason", s);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PostCommentUtils.postAnswerReportData(context, commentEntity.getId(), answerId, jsonObject.toString(),
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
Utils.toast(context, "感谢您的举报");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFailed(Throwable error) {
|
||||
Utils.toast(context, error.toString());
|
||||
}
|
||||
});
|
||||
reportTypeDialog.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
reportTypeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
reportTypeDialog.setContentView(container);
|
||||
reportTypeDialog.show();
|
||||
}
|
||||
// private static void showAnswerReportDialog(final String answerId, final CommentEntity commentEntity, final Context context) {
|
||||
// final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息",
|
||||
// "违法有害信息", "其它"};
|
||||
// int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||||
//
|
||||
// final Dialog reportTypeDialog = new Dialog(context);
|
||||
// LinearLayout container = new LinearLayout(context);
|
||||
// container.setOrientation(LinearLayout.VERTICAL);
|
||||
// container.setPadding(0, DisplayUtils.dip2px(context, 12), 0, DisplayUtils.dip2px(context, 12));
|
||||
// container.setBackgroundColor(Color.WHITE);
|
||||
//
|
||||
// for (final String s : arrReportType) {
|
||||
// TextView reportTypeTv = new TextView(context);
|
||||
// reportTypeTv.setText(s);
|
||||
// reportTypeTv.setTextSize(17);
|
||||
// reportTypeTv.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||||
// reportTypeTv.setBackgroundResource(R.drawable.textview_white_style);
|
||||
// reportTypeTv.setLayoutParams(new LinearLayout.LayoutParams((widthPixels * 9) / 10,
|
||||
// LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
// reportTypeTv.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 12),
|
||||
// 0, DisplayUtils.dip2px(context, 12));
|
||||
// container.addView(reportTypeTv);
|
||||
//
|
||||
// reportTypeTv.setOnClickListener(v -> {
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// try {
|
||||
// jsonObject.put("reason", s);
|
||||
// } catch (JSONException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// PostCommentUtils.postAnswerReportData(context, commentEntity.getId(), answerId, jsonObject.toString(),
|
||||
// new PostCommentUtils.PostCommentListener() {
|
||||
// @Override
|
||||
// public void postSuccess(JSONObject response) {
|
||||
// Utils.toast(context, "感谢您的举报");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void postFailed(Throwable error) {
|
||||
// if (error != null) {
|
||||
// Utils.toast(context, "举报失败" + error.getMessage());
|
||||
// } else {
|
||||
// Utils.toast(context, "举报失败,请稍候重试");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// reportTypeDialog.cancel();
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// reportTypeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
// reportTypeDialog.setContentView(container);
|
||||
// reportTypeDialog.show();
|
||||
// }
|
||||
|
||||
private static void showReportTypeDialog(final CommentEntity commentEntity, final Context context) {
|
||||
final String[] arrReportType = new String[]{"垃圾广告营销", "恶意攻击谩骂", "淫秽色情信息",
|
||||
@ -329,11 +450,11 @@ public class CommentUtils {
|
||||
}
|
||||
commentEntity.setVote(commentEntity.getVote() + 1);
|
||||
commentLikeCountTv.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
commentLikeIv.setImageResource(R.drawable.ic_like_select);
|
||||
commentLikeIv.setImageResource(R.drawable.vote_icon_select);
|
||||
commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
|
||||
PostCommentUtils.addCommentVoto(context, commentEntity.getId(),
|
||||
PostCommentUtils.addCommentVote(context, commentEntity.getId(),
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
@ -347,7 +468,7 @@ public class CommentUtils {
|
||||
|
||||
commentEntity.setVote(commentEntity.getVote() - 1);
|
||||
commentLikeCountTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||||
commentLikeIv.setImageResource(R.drawable.ic_like_unselect);
|
||||
commentLikeIv.setImageResource(R.drawable.vote_icon_unselect);
|
||||
commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
if (commentEntity.getVote() == 0) {
|
||||
commentLikeCountTv.setVisibility(View.GONE);
|
||||
@ -375,7 +496,8 @@ public class CommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void postVoteToAnswerComment(final Context context, String answerId, final CommentEntity commentEntity,
|
||||
public static void postVoteToAnswerComment(final Context context, String answerId, String articleId,
|
||||
String articleCommunityId, final CommentEntity commentEntity,
|
||||
final TextView commentLikeCountTv, final ImageView commentLikeIv, final OnVoteListener listener) {
|
||||
CheckLoginUtils.checkLogin(context, () -> {
|
||||
if (commentLikeCountTv.getCurrentTextColor() == ContextCompat.getColor(context, R.color.theme)) {
|
||||
@ -384,11 +506,11 @@ public class CommentUtils {
|
||||
}
|
||||
commentEntity.setVote(commentEntity.getVote() + 1);
|
||||
commentLikeCountTv.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
commentLikeIv.setImageResource(R.drawable.ic_like_select);
|
||||
commentLikeIv.setImageResource(R.drawable.vote_icon_select);
|
||||
commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
|
||||
PostCommentUtils.voteAnswerComment(context, answerId, commentEntity.getId(),
|
||||
PostCommentUtils.voteAnswerComment(context, answerId, articleId, articleCommunityId, commentEntity.getId(),
|
||||
new PostCommentUtils.PostCommentListener() {
|
||||
@Override
|
||||
public void postSuccess(JSONObject response) {
|
||||
@ -402,7 +524,7 @@ public class CommentUtils {
|
||||
|
||||
commentEntity.setVote(commentEntity.getVote() - 1);
|
||||
commentLikeCountTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||||
commentLikeIv.setImageResource(R.drawable.ic_like_unselect);
|
||||
commentLikeIv.setImageResource(R.drawable.vote_icon_unselect);
|
||||
commentLikeCountTv.setText(String.valueOf(commentEntity.getVote()));
|
||||
if (commentEntity.getVote() == 0) {
|
||||
commentLikeCountTv.setVisibility(View.GONE);
|
||||
@ -435,14 +557,14 @@ public class CommentUtils {
|
||||
public static void setCommentUserView(Context mContext, CommentViewHolder holder, CommentEntity entity) {
|
||||
MeEntity userDataEntity = entity.getMe();
|
||||
holder.commentLikeCountTv.setTextColor(ContextCompat.getColor(mContext, R.color.hint));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_unselect);
|
||||
holder.commentLikeIv.setImageResource(R.drawable.vote_icon_unselect);
|
||||
|
||||
if (entity.getVote() == 0) {
|
||||
holder.commentLikeCountTv.setVisibility(View.GONE);
|
||||
} else { // 检查是否已点赞
|
||||
if (userDataEntity != null && (userDataEntity.isCommentVoted() || userDataEntity.isAnswerCommentVoted())) {
|
||||
holder.commentLikeCountTv.setTextColor(ContextCompat.getColor(mContext, R.color.theme));
|
||||
holder.commentLikeIv.setImageResource(R.drawable.ic_like_select);
|
||||
holder.commentLikeIv.setImageResource(R.drawable.vote_icon_select);
|
||||
}
|
||||
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
|
||||
holder.commentLikeCountTv.setText(NumberUtils.transSimpleCount(entity.getVote()));
|
||||
|
||||
45
app/src/main/java/com/gh/common/util/CommunityHelper.kt
Normal file
45
app/src/main/java/com/gh/common/util/CommunityHelper.kt
Normal file
@ -0,0 +1,45 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import com.gh.gamecenter.qa.entity.AskGameSelectEntity
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.halo.assistant.HaloApp
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
/**
|
||||
* 用于判断社区跳转前社区是否可用
|
||||
*/
|
||||
object CommunityHelper {
|
||||
|
||||
private var availableCommunityList = listOf<AskGameSelectEntity>()
|
||||
|
||||
@JvmStatic
|
||||
fun getAvailableCommunityList() {
|
||||
RetrofitManager.getInstance(HaloApp.getInstance().application).api
|
||||
.getAskGameSelect(HaloApp.getInstance().channel
|
||||
, UrlFilterUtils.getFilterQuery("status", "opened"), 1, 100)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(object : Response<List<AskGameSelectEntity>>() {
|
||||
override fun onResponse(response: List<AskGameSelectEntity>?) {
|
||||
if (response != null && response.isNotEmpty()) {
|
||||
availableCommunityList = response
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isCommunityAvailable(communityId: String?): Boolean {
|
||||
communityId?.let {
|
||||
if (availableCommunityList.isEmpty()) return true
|
||||
for (entity in availableCommunityList) {
|
||||
if (communityId == entity.id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,9 +21,6 @@ import retrofit2.HttpException
|
||||
object ConcernUtils {
|
||||
|
||||
fun postConcernGameId(context: Context, gameId: String, listener: onConcernListener?) {
|
||||
// val params = JSONArray()
|
||||
// params.put(gameId)
|
||||
// val body = RequestBody.create(MediaType.parse("application/json"), params.toString())
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postConcern(UserManager.getInstance().userId, gameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
@ -115,17 +115,7 @@ public class DataUtils {
|
||||
// if (CommonDebug.IS_DEBUG && (kv == null || kv.length % 2 != 0)) {
|
||||
// throw new IllegalStateException("onEvent kv 必须不为空且数量为偶数");
|
||||
// }
|
||||
Properties prop = new Properties();
|
||||
for (int i = 0; i < kv.length; i++) {
|
||||
if (i % 2 != 0 && i != 0) {
|
||||
String key = kv[i - 1];
|
||||
String value = kv[i];
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) {
|
||||
prop.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
StatService.trackCustomKVEvent(context, eventId, prop);
|
||||
MtaHelper.onEvent(eventId, kv);
|
||||
}
|
||||
|
||||
public static void onEvent(Context var0, String var1, String var2) {
|
||||
@ -199,11 +189,19 @@ public class DataUtils {
|
||||
onEvent(context, "游戏下载", gameName, kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("版本", platform);
|
||||
kv2.put("状态", status);
|
||||
kv2.put("位置", entrance);
|
||||
kv2.put("游戏分平台", gameName + "-" + platform);
|
||||
kv2.put("光环助手版本", BuildConfig.VERSION_NAME);
|
||||
|
||||
if (status.equals("开始")) {
|
||||
kv2.put("版本", entrance + "-开始");
|
||||
kv2.put("游戏分平台", gameName + "-" + platform + "-开始");
|
||||
kv2.put("光环助手版本", BuildConfig.VERSION_NAME + "-开始");
|
||||
} else {
|
||||
kv2.put("版本", platform);
|
||||
kv2.put("游戏分平台", gameName + "-" + platform);
|
||||
kv2.put("光环助手版本", BuildConfig.VERSION_NAME);
|
||||
}
|
||||
|
||||
onEvent(context, "游戏下载位置", gameName, kv2);
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import com.gh.common.view.DownloadProgressBar;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.DetailViewHolder;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
|
||||
@ -33,15 +34,13 @@ public class DetailDownloadUtils {
|
||||
viewHolder.mDownloadPb.setText(TextUtils.isEmpty(viewHolder.downloadOffText) ? "暂无下载" : viewHolder.downloadOffText);
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.NONE);
|
||||
} else {
|
||||
String status = GameUtils.getDownloadBtnText(viewHolder.context, viewHolder.gameEntity);
|
||||
String status = GameUtils.getDownloadBtnText(viewHolder.context, viewHolder.gameEntity, PluginLocation.only_game);
|
||||
switch (status) {
|
||||
case "插件化":
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.PLUGIN);
|
||||
break;
|
||||
case "打开":
|
||||
if (viewHolder.gameEntity.getApk().size() == 1) {
|
||||
status = "启动";
|
||||
}
|
||||
case "启动":
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.LAUNCH_OR_OPEN);
|
||||
break;
|
||||
default:
|
||||
@ -73,10 +72,18 @@ public class DetailDownloadUtils {
|
||||
switch (downloadEntity.getStatus()) {
|
||||
case downloading:
|
||||
case pause:
|
||||
viewHolder.mDownloadPb.setText(R.string.downloading);
|
||||
if (downloadEntity.isPluggable() && PackageManager.INSTANCE.isInstalled(downloadEntity.getPackageName())) {
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.DOWNLOADING_PLUGIN);
|
||||
} else {
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.DOWNLOADING_NORMAL);
|
||||
}
|
||||
break;
|
||||
case timeout:
|
||||
case neterror:
|
||||
case waiting:
|
||||
viewHolder.mDownloadPb.setText(R.string.downloading);
|
||||
case subscribe:
|
||||
viewHolder.mDownloadPb.setText(R.string.waiting);
|
||||
if (downloadEntity.isPluggable() && PackageManager.INSTANCE.isInstalled(downloadEntity.getPackageName())) {
|
||||
viewHolder.mDownloadPb.setDownloadType(DownloadProgressBar.DownloadType.DOWNLOADING_PLUGIN);
|
||||
} else {
|
||||
|
||||
@ -201,7 +201,7 @@ public class DeviceUtils {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return "无网络";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
@ -24,10 +25,12 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.gamecenter.AboutActivity;
|
||||
import com.gh.gamecenter.KcSelectGameActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
@ -350,10 +353,61 @@ public class DialogUtils {
|
||||
}, null);
|
||||
}
|
||||
|
||||
public static void showDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", "取消", "确定", listener, cancelListener);
|
||||
public static void checkDownload(Context context, String size, CheckDownloadCallBack callBack) {
|
||||
if (!NetworkUtils.isNetworkConnected(context)) {
|
||||
showNoConnectionDownloadDialog(context, null,
|
||||
() -> callBack.onResponse(true));
|
||||
} else if (NetworkUtils.isWifiConnected(context) || filter4GorSize(context, size)) {
|
||||
callBack.onResponse(false);
|
||||
} else {
|
||||
showDownloadDialog(context,
|
||||
() -> callBack.onResponse(false),
|
||||
() -> callBack.onResponse(true));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean filter4GorSize(Context context, String size) {
|
||||
try {
|
||||
if (TextUtils.isEmpty(size)) {
|
||||
return false;
|
||||
}
|
||||
String mb = size.toUpperCase().replaceAll("MB", "").trim();
|
||||
Float i = Float.valueOf(mb);
|
||||
if (NetworkUtils.isWifiOr4GConnected(context) && i <= 50) {
|
||||
Utils.toast(context, "当前使用移动流量下载");
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void checkResumeDownload(Context context, CheckDownloadCallBack callBack) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
callBack.onResponse(false);
|
||||
} else {
|
||||
showResumeDownloadDialog(context, () -> {
|
||||
callBack.onResponse(false);
|
||||
}, () -> {
|
||||
callBack.onResponse(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void showNoConnectionDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||||
showWarningDialog(context, "下载提示", "网络异常,请检查手机网络状态", "连上WiFi后自动下载", "关闭", listener, cancelListener);
|
||||
}
|
||||
|
||||
public static void showDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||||
showWarningDialog(context, "下载提示", "当前正在使用移动网络,立即下载会消耗手机流量", "连上WiFi后自动下载", "立即下载", listener, cancelListener);
|
||||
}
|
||||
|
||||
public static void showResumeDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||||
showWarningDialog(context, "下载提示", "当前正在使用移动网络,继续下载会消耗手机流量", "连上WiFi后自动下载", "继续下载", listener, cancelListener);
|
||||
}
|
||||
|
||||
|
||||
public static void showDownloadDialog(Context context, ConfirmListener listener) {
|
||||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", listener);
|
||||
}
|
||||
@ -701,6 +755,32 @@ public class DialogUtils {
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public static void showLowVersionDialog(Context context) {
|
||||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||||
|
||||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||||
|
||||
contentTv.setText("链接超出范围,请检查升级至最新版本的光环助手");
|
||||
titleTv.setText("提示");
|
||||
negativeTv.setText("关闭");
|
||||
positiveTv.setText("检查升级");
|
||||
|
||||
negativeTv.setOnClickListener(view -> dialog.dismiss());
|
||||
|
||||
positiveTv.setOnClickListener(view -> {
|
||||
context.startActivity(AboutActivity.getIntent(context, true));
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public interface ConfirmListener {
|
||||
void onConfirm();
|
||||
}
|
||||
@ -709,4 +789,9 @@ public class DialogUtils {
|
||||
void onCancel();
|
||||
}
|
||||
|
||||
|
||||
public interface CheckDownloadCallBack {
|
||||
void onResponse(boolean isSubscribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,17 +6,22 @@ import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import com.gh.base.fragment.BaseFragment_TabLayout
|
||||
import com.gh.common.AppExecutor
|
||||
import com.gh.common.util.EntranceUtils.*
|
||||
import com.gh.gamecenter.*
|
||||
import com.gh.gamecenter.download.DownloadFragment.Companion.INDEX_UPDATE
|
||||
import com.gh.gamecenter.entity.CommunityEntity
|
||||
import com.gh.gamecenter.entity.LinkEntity
|
||||
import com.gh.gamecenter.entity.SubjectData
|
||||
import com.gh.gamecenter.eventbus.EBReuse
|
||||
import com.gh.gamecenter.eventbus.EBSkip
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.qa.AskFragment
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity
|
||||
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
|
||||
import com.gh.gamecenter.qa.column.detail.AskColumnDetailActivity
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity
|
||||
import com.gh.gamecenter.qa.subject.CommunitySubjectActivity
|
||||
import com.gh.gamecenter.subject.refactor.SubjectActivity
|
||||
import com.gh.gamecenter.suggest.SuggestType
|
||||
import com.lightgame.utils.Util_System_ClipboardManager
|
||||
@ -58,6 +63,39 @@ object DirectUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到特定页面,只支持App内部跳转
|
||||
*/
|
||||
@JvmStatic
|
||||
fun directToLinkPage(context: Context, linkEntity: LinkEntity, entrance: String, path: String) {
|
||||
when (linkEntity.type) {
|
||||
"article", "news" -> {
|
||||
NewsUtils.statNewsViews(context, linkEntity.link) // 统计阅读量
|
||||
context.startActivity(NewsDetailActivity.getIntentById(context, linkEntity.link, entrance))
|
||||
}
|
||||
|
||||
"game" -> GameDetailActivity.startGameDetailActivity(context, linkEntity.link, entrance)
|
||||
|
||||
"column" -> SubjectActivity.startSubjectActivity(context, linkEntity.link, linkEntity.text, false, entrance)
|
||||
|
||||
"question" -> context.startActivity(QuestionsDetailActivity.getIntent(context, linkEntity.link, entrance, path))
|
||||
|
||||
"answer" -> context.startActivity(AnswerDetailActivity.getIntent(context, linkEntity.link, entrance, path))
|
||||
|
||||
"community" -> directToCommunity(context, CommunityEntity(linkEntity.link!!, linkEntity.text!!))
|
||||
|
||||
"community_article" -> context.startActivity(ArticleDetailActivity.getIntent(context, linkEntity.community!!, linkEntity.link!!, entrance, path))
|
||||
|
||||
"community_column" -> context.startActivity(CommunitySubjectActivity.getIntent(context, linkEntity.community!!, linkEntity.link, entrance))
|
||||
|
||||
"community_special_column" -> context.startActivity(AskColumnDetailActivity.getIntentByColumnId(context, linkEntity.link, linkEntity.community!!, entrance, path))
|
||||
|
||||
"web" -> directToWebView(context, url = linkEntity.link!!, entrance = entrance)
|
||||
|
||||
else -> DialogUtils.showLowVersionDialog(context)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到文章详情
|
||||
*/
|
||||
@ -242,7 +280,21 @@ object DirectUtils {
|
||||
context.startActivity(intent)
|
||||
}
|
||||
UserManager.getInstance().setCommunityData(community)
|
||||
EventBus.getDefault().post(EBSkip(MainActivity.EB_SKIP_GAMEFRAGMENT, 1))
|
||||
EventBus.getDefault().post(EBReuse(AskFragment.EB_RETRY_PAGE))
|
||||
|
||||
// 这里换个线程操作是为了做一点延时
|
||||
AppExecutor.ioExecutor.execute {
|
||||
EventBus.getDefault().post(EBSkip(MainActivity.EB_SKIP_GAMEFRAGMENT, 1))
|
||||
EventBus.getDefault().post(EBReuse(AskFragment.EB_RETRY_PAGE))
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun directToCommunityArticle(context: Context, articleId: String?, communityId: String?, entrance: String?) {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(KEY_ENTRANCE, entrance ?: ENTRANCE_BROWSER)
|
||||
bundle.putString(EntranceUtils.KEY_TO, ArticleDetailActivity::class.java.name)
|
||||
bundle.putString(EntranceUtils.KEY_COMMUNITY_ARTICLE_ID, articleId)
|
||||
bundle.putParcelable(EntranceUtils.KEY_COMMUNITY_DATA, CommunityEntity(id = communityId!!))
|
||||
EntranceUtils.jumpActivity(context, bundle)
|
||||
}
|
||||
}
|
||||
@ -29,13 +29,13 @@ object DownloadHelper {
|
||||
for (apk in response.getApk()) {
|
||||
if (packageName == apk.packageName) {
|
||||
DownloadManager.createDownload(HaloApp.getInstance().application,
|
||||
apk, response, "", EntranceUtils.ENTRANCE_RECOMMEND, "", null)
|
||||
apk, response, "", EntranceUtils.ENTRANCE_RECOMMEND, "", false, null)
|
||||
block.invoke()
|
||||
}
|
||||
}
|
||||
} else if (response.getApk().size == 1) {
|
||||
DownloadManager.createDownload(HaloApp.getInstance().application,
|
||||
response, "", EntranceUtils.ENTRANCE_RECOMMEND, "", null)
|
||||
response, "", EntranceUtils.ENTRANCE_RECOMMEND, "", false, null)
|
||||
block.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.viewholder.GameViewHolder;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.lightgame.download.DownloadConfig;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
@ -95,7 +96,13 @@ public class DownloadItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder, boolean isShowPlatform) {
|
||||
public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder,
|
||||
boolean isShowPlatform) {
|
||||
updateItem(context, gameEntity, holder, isShowPlatform, PluginLocation.only_game);
|
||||
}
|
||||
|
||||
public static void updateItem(Context context, GameEntity gameEntity, GameViewHolder holder,
|
||||
boolean isShowPlatform, PluginLocation pluginLocation) {
|
||||
|
||||
// 控制是否显示下载按钮
|
||||
if (!Config.isShowDownload(gameEntity.getId()) || context.getString(R.string.app_name).equals(gameEntity.getName())) {
|
||||
@ -119,17 +126,16 @@ public class DownloadItemUtils {
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.button_gray));
|
||||
holder.gameDownloadBtn.setClickable(false);
|
||||
} else if (gameEntity.getApk().size() == 1) {
|
||||
updateNormalItem(context, holder, gameEntity, isShowPlatform);
|
||||
updateNormalItem(context, holder, gameEntity, isShowPlatform, pluginLocation);
|
||||
} else {
|
||||
// updateNormalItem(context, holder, gameEntity, isShowPlatform);
|
||||
updatePluginItem(context, holder, gameEntity, isShowPlatform);
|
||||
updatePluginItem(context, holder, gameEntity, isShowPlatform, pluginLocation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 更新正常的条目,只有一个apk包
|
||||
static void updateNormalItem(Context context, GameViewHolder holder, GameEntity gameEntity,
|
||||
boolean isShowPlatform) {
|
||||
boolean isShowPlatform, PluginLocation pluginLocation) {
|
||||
|
||||
final ArrayMap<String, DownloadEntity> entryMap = gameEntity.getEntryMap();
|
||||
final ApkEntity apkEntity = gameEntity.getApk().get(0);
|
||||
@ -143,74 +149,21 @@ public class DownloadItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn, pluginLocation);
|
||||
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
holder.gameInfo.setVisibility(View.GONE);
|
||||
|
||||
holder.gameDownloadBtn.setTextColor(Color.WHITE);
|
||||
|
||||
final String packageName = apkEntity.getPackageName();
|
||||
|
||||
if (gameEntity.isPluggable()) {
|
||||
holder.gameDownloadBtn.setText(R.string.pluggable);
|
||||
setwhat(context, holder, apkEntity, packageName);
|
||||
} else if (PackageManager.INSTANCE.isInstalled(packageName)) {
|
||||
if (PackageManager.INSTANCE.isCanUpdate(gameEntity.getId(), packageName)) {
|
||||
holder.gameDownloadBtn.setText(R.string.update);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
} else {
|
||||
Object gh_id = PackageUtils.getMetaData(context, packageName, "gh_id");
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(context, packageName)) {
|
||||
holder.gameDownloadBtn.setText(R.string.pluggable);
|
||||
setwhat(context, holder, apkEntity, packageName);
|
||||
} else if (gh_id == null || gh_id.equals(gameEntity.getId())) {
|
||||
holder.gameDownloadBtn.setText(R.string.launch);
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.detail_download_open_style);
|
||||
} else {
|
||||
holder.gameDownloadBtn.setText(R.string.download);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
holder.gameDownloadBtn.setText(R.string.download);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_download_style);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 这个干什么鬼?
|
||||
*
|
||||
* @param context
|
||||
* @param holder
|
||||
* @param apkEntity
|
||||
* @param packageName
|
||||
*/
|
||||
public static void setwhat(Context context, GameViewHolder holder, ApkEntity apkEntity, String packageName) {
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(context).getDownloadEntityByPackageName(packageName);
|
||||
if (downloadEntity == null || downloadEntity.getUrl().equals(apkEntity.getUrl())) {
|
||||
holder.gameDownloadBtn.setClickable(true);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else {
|
||||
holder.gameDownloadBtn.setClickable(false);
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_pause_up);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新插件的条目,有多个apk包
|
||||
static void updatePluginItem(Context context, GameViewHolder holder, GameEntity gameEntity,
|
||||
boolean isShowPlatform) {
|
||||
|
||||
GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn);
|
||||
private static void updatePluginItem(Context context, GameViewHolder holder, GameEntity gameEntity,
|
||||
boolean isShowPlatform, PluginLocation pluginLocation) {
|
||||
|
||||
ArrayMap<String, DownloadEntity> entryMap = gameEntity.getEntryMap();
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntity downloadEntity;
|
||||
|
||||
LinkedBlockingQueue<String> queue = DownloadManager.getInstance(context).getQueue(gameEntity.getName());
|
||||
DownloadEntity downloadEntity;
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntity = entryMap.get(queue.peek());
|
||||
} else {
|
||||
@ -224,6 +177,8 @@ public class DownloadItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
GameUtils.setDownloadBtnStatus(context, gameEntity, holder.gameDownloadBtn, pluginLocation);
|
||||
|
||||
holder.gameDes.setVisibility(View.VISIBLE);
|
||||
holder.gameProgressbar.setVisibility(View.GONE);
|
||||
holder.gameInfo.setVisibility(View.GONE);
|
||||
@ -274,7 +229,8 @@ public class DownloadItemUtils {
|
||||
}
|
||||
} else if (status.equals(DownloadStatus.pause)
|
||||
|| status.equals(DownloadStatus.timeout)
|
||||
|| status.equals(DownloadStatus.neterror)) {
|
||||
|| status.equals(DownloadStatus.neterror)
|
||||
|| status.equals(DownloadStatus.subscribe)) {
|
||||
holder.gameProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (isShowPlatform && platform != null) {
|
||||
holder.gameDownloadSpeed.setText(String.format("%s - 暂停", platform));
|
||||
@ -284,7 +240,11 @@ public class DownloadItemUtils {
|
||||
holder.gameDownloadPercentage.setText(downloadEntity.getPercent() + "%");
|
||||
|
||||
if (isNormal) {
|
||||
holder.gameDownloadBtn.setText(R.string.downloading);
|
||||
if (status.equals(DownloadStatus.pause)) {
|
||||
holder.gameDownloadBtn.setText(R.string.downloading);
|
||||
} else {
|
||||
holder.gameDownloadBtn.setText(R.string.waiting);
|
||||
}
|
||||
holder.gameDownloadBtn.setBackgroundResource(R.drawable.game_item_btn_downloading_style);
|
||||
holder.gameDownloadBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.text_downloading_style));
|
||||
}
|
||||
@ -360,21 +320,15 @@ public class DownloadItemUtils {
|
||||
String str = downloadBtn.getText().toString();
|
||||
switch (str) {
|
||||
case "下载":
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
download(context, gameEntity, downloadBtn, entrance, location, traceEvent);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, () -> download(context, gameEntity, downloadBtn, entrance, location, traceEvent));
|
||||
}
|
||||
DialogUtils.checkDownload(context, gameEntity.getApk().get(0).getSize(),
|
||||
isSubscribe -> download(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent));
|
||||
break;
|
||||
case "插件化":
|
||||
if (entrance.contains("我的游戏")) {
|
||||
DataUtils.onMtaEvent(context, "我的游戏_启动", "插件化", gameEntity.getName());
|
||||
}
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
plugin(context, gameEntity, downloadBtn, entrance, location, traceEvent);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, () -> plugin(context, gameEntity, downloadBtn, entrance, location, traceEvent));
|
||||
}
|
||||
DialogUtils.checkDownload(context, gameEntity.getApk().get(0).getSize(),
|
||||
isSubscribe -> plugin(context, gameEntity, downloadBtn, entrance, location, isSubscribe, traceEvent));
|
||||
break;
|
||||
case "安装":
|
||||
install(context, gameEntity, position, adapter);
|
||||
@ -387,6 +341,7 @@ public class DownloadItemUtils {
|
||||
|
||||
PackageUtils.launchApplicationByPackageName(context, gameEntity.getApk().get(0).getPackageName());
|
||||
break;
|
||||
case "等待中":
|
||||
case "下载中":
|
||||
context.startActivity(
|
||||
DownloadManagerActivity.getDownloadMangerIntent(context, gameEntity.getApk().get(0).getUrl(), entrance + "+(" + location.split(":")[0] + ")"));
|
||||
@ -395,11 +350,8 @@ public class DownloadItemUtils {
|
||||
if (entrance.contains("我的游戏")) {
|
||||
DataUtils.onMtaEvent(context, "我的游戏_启动", "更新", gameEntity.getName());
|
||||
}
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
update(context, gameEntity, entrance, location, traceEvent);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(context, () -> update(context, gameEntity, entrance, location, traceEvent));
|
||||
}
|
||||
DialogUtils.checkDownload(context, gameEntity.getApk().get(0).getSize(),
|
||||
isSubscribe -> update(context, gameEntity, entrance, location, isSubscribe, traceEvent));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -410,6 +362,7 @@ public class DownloadItemUtils {
|
||||
TextView downloadBtn,
|
||||
String entrance,
|
||||
String location,
|
||||
boolean isSubscribe,
|
||||
@Nullable ExposureEvent traceEvent) {
|
||||
String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
@ -417,7 +370,7 @@ public class DownloadItemUtils {
|
||||
|
||||
ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(gameEntity, gameEntity.getApk().get(0).getPlatform(), traceEvent, ExposureUtils.DownloadType.DOWNLOAD);
|
||||
|
||||
DownloadManager.createDownload(context, gameEntity, context.getString(R.string.download), entrance, location, downloadExposureEvent);
|
||||
DownloadManager.createDownload(context, gameEntity, context.getString(R.string.download), entrance, location, isSubscribe, downloadExposureEvent);
|
||||
Utils.toast(context, gameEntity.getName() + "已加入下载队列");
|
||||
|
||||
downloadBtn.setText(R.string.downloading);
|
||||
@ -432,14 +385,14 @@ public class DownloadItemUtils {
|
||||
|
||||
//插件化
|
||||
private static void plugin(Context context, GameEntity gameEntity, TextView downloadBtn, String entrance,
|
||||
String location, @Nullable ExposureEvent traceEvent) {
|
||||
String location, boolean isSubscribe, @Nullable ExposureEvent traceEvent) {
|
||||
String msg = FileUtils.isCanDownload(context, gameEntity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
DataUtils.onGameDownloadEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), entrance, "下载开始", "插件化");
|
||||
|
||||
ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(gameEntity, gameEntity.getApk().get(0).getPlatform(), traceEvent, ExposureUtils.DownloadType.PLUGIN_DOWNLOAD);
|
||||
|
||||
DownloadManager.createDownload(context, gameEntity, "插件化", entrance, location, downloadExposureEvent);
|
||||
DownloadManager.createDownload(context, gameEntity, "插件化", entrance, location, isSubscribe, downloadExposureEvent);
|
||||
Utils.toast(context, gameEntity.getName() + "已加入下载队列");
|
||||
|
||||
downloadBtn.setText(R.string.downloading);
|
||||
@ -473,10 +426,11 @@ public class DownloadItemUtils {
|
||||
}
|
||||
|
||||
//更新
|
||||
private static void update(Context context, GameEntity gameEntity, String entrance, String location, @Nullable ExposureEvent traceEvent) {
|
||||
private static void update(Context context, GameEntity gameEntity, String entrance, String location,
|
||||
boolean isSubscribe, @Nullable ExposureEvent traceEvent) {
|
||||
DataUtils.onGameUpdateEvent(context, gameEntity.getName(), gameEntity.getApk().get(0).getPlatform(), "下载开始");
|
||||
ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(gameEntity, gameEntity.getApk().get(0).getPlatform(), traceEvent, ExposureUtils.DownloadType.UPDATE);
|
||||
DownloadManager.createDownload(context, gameEntity, "更新", entrance, location, downloadExposureEvent);
|
||||
DownloadManager.createDownload(context, gameEntity, "更新", entrance, location, isSubscribe, downloadExposureEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ public class EntranceUtils {
|
||||
public static final String KEY_URL = "url";
|
||||
public static final String KEY_GAMENAME = "gameName";
|
||||
public static final String HOST_ARTICLE = "article";
|
||||
public static final String HOST_COMMUNITY_ARTICLE = "community.article";
|
||||
public static final String HOST_GAME = "game";
|
||||
public static final String HOST_GAME_DOWNLOAD = "game_download";
|
||||
public static final String HOST_COLUMN = "column";
|
||||
@ -40,6 +41,7 @@ public class EntranceUtils {
|
||||
public static final String KEY_DATA = "data";
|
||||
public static final String KEY_MESSAGE = "message";
|
||||
public static final String KEY_TYPE = "type";
|
||||
public static final String KEY_LINK = "link";
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_ENTRANCE = "entrance";
|
||||
public static final String KEY_TARGET = "target";
|
||||
@ -60,6 +62,7 @@ public class EntranceUtils {
|
||||
public static final String KEY_CURRENTITEM = "currentItem";
|
||||
public static final String KEY_COMMENTID = "commentId";
|
||||
public static final String KEY_PATH = "path";
|
||||
public static final String KEY_OUTER_INFO = "outerInfo";
|
||||
public static final String KEY_OLDERUSER = "isOldUser";
|
||||
public static final String KEY_SEARCHKEY = "searchKey";
|
||||
public static final String KEY_HINT = "hint";
|
||||
@ -101,7 +104,12 @@ public class EntranceUtils {
|
||||
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 final String KEY_SEARCH_SUGGEST_HINT = "search_suggest_hint";
|
||||
public static final String KEY_HIDE_SUGGEST_HINT = "hide_suggest_hint";
|
||||
public static final String KEY_COMMUNITY_ARTICLE_ID = "communityArticleId";
|
||||
public static final String KEY_ARTICLE_COMMENT_ID = "articleCommentId";
|
||||
public static final String KEY_DEVICE_NAME = "deviceName";
|
||||
public static final String KEY_SHOW_ARTICLE_COMMENT = "showArticleComment";
|
||||
public static final String KEY_RATING_STAR_COUNT = "ratingStarCount";
|
||||
|
||||
public static void jumpActivity(Context context, Bundle bundle) {
|
||||
|
||||
|
||||
80
app/src/main/java/com/gh/common/util/Extensions.kt
Normal file
80
app/src/main/java/com/gh/common/util/Extensions.kt
Normal file
@ -0,0 +1,80 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentActivity
|
||||
import android.support.v4.view.ViewPager
|
||||
|
||||
/**
|
||||
* 创建以 activity 为观察者上下文的 viewModel
|
||||
*/
|
||||
inline fun <reified VM : ViewModel> FragmentActivity.viewModelProvider(
|
||||
provider: ViewModelProvider.Factory
|
||||
) =
|
||||
ViewModelProviders.of(this, provider).get(VM::class.java)
|
||||
|
||||
/**
|
||||
* 创建以 fragment 为观察者上下文的 viewModel
|
||||
*/
|
||||
inline fun <reified VM : ViewModel> Fragment.viewModelProvider(
|
||||
provider: ViewModelProvider.Factory
|
||||
) =
|
||||
ViewModelProviders.of(this, provider).get(VM::class.java)
|
||||
|
||||
/**
|
||||
*
|
||||
* ViewPager Extensions
|
||||
*
|
||||
*/
|
||||
fun ViewPager.doOnPageSelected(action: (position: Int) -> Unit) = addOnPageChangeListener(onSelected = action)
|
||||
|
||||
fun ViewPager.addOnPageChangeListener(onSelected: ((position: Int) -> Unit)? = null) {
|
||||
val listener = object : ViewPager.OnPageChangeListener {
|
||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
onSelected?.invoke(position)
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
addOnPageChangeListener(listener)
|
||||
}
|
||||
|
||||
fun Application.ActivityLifecycleCallbacks(callBack: () -> Unit) {
|
||||
val listener = object : Application.ActivityLifecycleCallbacks {
|
||||
override fun onActivityStarted(activity: Activity?) {
|
||||
}
|
||||
|
||||
override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {
|
||||
}
|
||||
|
||||
override fun onActivityStopped(activity: Activity?) {
|
||||
}
|
||||
|
||||
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
|
||||
}
|
||||
|
||||
override fun onActivityPaused(activity: Activity?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity?) {
|
||||
|
||||
}
|
||||
|
||||
override fun onActivityDestroyed(activity: Activity?) {
|
||||
|
||||
}
|
||||
}
|
||||
registerActivityLifecycleCallbacks(listener)
|
||||
}
|
||||
@ -12,6 +12,7 @@ import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameCollectionEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.download.DownloadStatus;
|
||||
@ -46,13 +47,13 @@ public class GameUtils {
|
||||
/**
|
||||
* 设置下载按钮状态
|
||||
*/
|
||||
public static void setDownloadBtnStatus(Context context, GameEntity gameEntity, TextView downloadBtn) {
|
||||
String status = getDownloadBtnText(context, gameEntity);
|
||||
public static void setDownloadBtnStatus(Context context, GameEntity gameEntity, TextView downloadBtn, PluginLocation pluginLocation) {
|
||||
String status = getDownloadBtnText(context, gameEntity, pluginLocation);
|
||||
downloadBtn.setTextColor(Color.WHITE);
|
||||
downloadBtn.setText(status);
|
||||
if ("插件化".equals(status)) {
|
||||
downloadBtn.setBackgroundResource(R.drawable.game_item_btn_plugin_style);
|
||||
} else if ("打开".equals(status)) {
|
||||
} else if ("打开".equals(status) || "启动".equals(status)) {
|
||||
downloadBtn.setBackgroundResource(R.drawable.detail_downloading_normal_style);
|
||||
downloadBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||||
} else {
|
||||
@ -63,7 +64,7 @@ public class GameUtils {
|
||||
/**
|
||||
* 获取下载按钮文案
|
||||
*/
|
||||
public static String getDownloadBtnText(Context context, GameEntity gameEntity) {
|
||||
public static String getDownloadBtnText(Context context, GameEntity gameEntity, PluginLocation pluginLocation) {
|
||||
int doneCount = 0; // 下载完成数量
|
||||
int pluginCount = 0; // 可插件化数量
|
||||
int updateCount = 0; // 可更新数量
|
||||
@ -97,7 +98,8 @@ public class GameUtils {
|
||||
gh_id = PackageUtils.getMetaData(context, apkEntity.getPackageName(), "gh_id");
|
||||
if (gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(context, apkEntity.getPackageName())) {
|
||||
&& !PackageUtils.isSignature(context, apkEntity.getPackageName())
|
||||
&& apkEntity.isShowPlugin(pluginLocation)) {
|
||||
pluginCount++;
|
||||
} else if (gh_id == null || gh_id.equals(gameEntity.getId())) {
|
||||
installCount++;
|
||||
@ -111,7 +113,11 @@ public class GameUtils {
|
||||
} else if (updateCount != 0) {
|
||||
return "更新";
|
||||
} else if (installCount != 0) {
|
||||
return "打开";
|
||||
if (gameEntity.getApk().size() == 1) {
|
||||
return "启动";
|
||||
} else {
|
||||
return "打开";
|
||||
}
|
||||
} else {
|
||||
return "下载";
|
||||
}
|
||||
@ -135,6 +141,7 @@ public class GameUtils {
|
||||
gameUpdateEntity.setPluggable(true);
|
||||
gameUpdateEntity.setTag(gameEntity.getTag());
|
||||
gameUpdateEntity.setBrief(gameEntity.getBrief());
|
||||
gameUpdateEntity.setPlugin(apkEntity.getPlugin());
|
||||
return gameUpdateEntity;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Siebe Projects samples.
|
||||
*
|
||||
* Siebe Projects samples is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the Lesser GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Siebe Projects samples is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* Lesser GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the Lesser GNU General Public License
|
||||
* along with Siebe Projects samples. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gh.common.util;
|
||||
|
||||
/**
|
||||
* The observer that will be notified when the height of
|
||||
* the keyboard has changed
|
||||
*/
|
||||
public interface KeyboardHeightObserver {
|
||||
|
||||
/**
|
||||
* Called when the keyboard height has changed, 0 means keyboard is closed,
|
||||
* >= 1 means keyboard is opened.
|
||||
*
|
||||
* @param height The height of the keyboard in pixels
|
||||
* @param orientation The orientation either: Configuration.ORIENTATION_PORTRAIT or
|
||||
* Configuration.ORIENTATION_LANDSCAPE
|
||||
*/
|
||||
void onKeyboardHeightChanged(int height, int orientation);
|
||||
}
|
||||
170
app/src/main/java/com/gh/common/util/KeyboardHeightProvider.java
Normal file
170
app/src/main/java/com/gh/common/util/KeyboardHeightProvider.java
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* This file is part of Siebe Projects samples.
|
||||
*
|
||||
* Siebe Projects samples is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the Lesser GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Siebe Projects samples is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* Lesser GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the Lesser GNU General Public License
|
||||
* along with Siebe Projects samples. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.widget.PopupWindow;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
/**
|
||||
* The keyboard height provider, this class uses a PopupWindow
|
||||
* to calculate the window height when the floating keyboard is opened and closed.
|
||||
*/
|
||||
public class KeyboardHeightProvider extends PopupWindow {
|
||||
|
||||
/** The tag for logging purposes */
|
||||
private final static String TAG = "sample_KeyboardHeightProvider";
|
||||
|
||||
/** The keyboard height observer */
|
||||
private KeyboardHeightObserver observer;
|
||||
|
||||
/** The cached landscape height of the keyboard */
|
||||
private int keyboardLandscapeHeight;
|
||||
|
||||
/** The cached portrait height of the keyboard */
|
||||
private int keyboardPortraitHeight;
|
||||
|
||||
/** The view that is used to calculate the keyboard height */
|
||||
private View popupView;
|
||||
|
||||
/** The parent view */
|
||||
private View parentView;
|
||||
|
||||
/** The root activity that uses this KeyboardHeightProvider */
|
||||
private Activity activity;
|
||||
|
||||
/**
|
||||
* Construct a new KeyboardHeightProvider
|
||||
*
|
||||
* @param activity The parent activity
|
||||
*/
|
||||
public KeyboardHeightProvider(Activity activity) {
|
||||
super(activity);
|
||||
this.activity = activity;
|
||||
|
||||
LayoutInflater inflator = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||||
this.popupView = inflator.inflate(R.layout.popupwindow, null, false);
|
||||
setContentView(popupView);
|
||||
|
||||
setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_RESIZE | LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
|
||||
|
||||
parentView = activity.findViewById(android.R.id.content);
|
||||
|
||||
setWidth(0);
|
||||
setHeight(LayoutParams.MATCH_PARENT);
|
||||
|
||||
popupView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
|
||||
if (popupView != null) {
|
||||
handleOnGlobalLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the KeyboardHeightProvider, this must be called after the onResume of the Activity.
|
||||
* PopupWindows are not allowed to be registered before the onResume has finished
|
||||
* of the Activity.
|
||||
*/
|
||||
public void start() {
|
||||
|
||||
if (!isShowing() && parentView.getWindowToken() != null) {
|
||||
setBackgroundDrawable(new ColorDrawable(0));
|
||||
showAtLocation(parentView, Gravity.NO_GRAVITY, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the keyboard height provider,
|
||||
* this provider will not be used anymore.
|
||||
*/
|
||||
public void close() {
|
||||
this.observer = null;
|
||||
dismiss();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the keyboard height observer to this provider. The
|
||||
* observer will be notified when the keyboard height has changed.
|
||||
* For example when the keyboard is opened or closed.
|
||||
*
|
||||
* @param observer The observer to be added to this provider.
|
||||
*/
|
||||
public void setKeyboardHeightObserver(KeyboardHeightObserver observer) {
|
||||
this.observer = observer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the screen orientation
|
||||
*
|
||||
* @return the screen orientation
|
||||
*/
|
||||
private int getScreenOrientation() {
|
||||
return activity.getResources().getConfiguration().orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Popup window itself is as big as the window of the Activity.
|
||||
* The keyboard can then be calculated by extracting the popup view bottom
|
||||
* from the activity window height.
|
||||
*/
|
||||
private void handleOnGlobalLayout() {
|
||||
|
||||
Point screenSize = new Point();
|
||||
activity.getWindowManager().getDefaultDisplay().getSize(screenSize);
|
||||
|
||||
Rect rect = new Rect();
|
||||
popupView.getWindowVisibleDisplayFrame(rect);
|
||||
|
||||
// REMIND, you may like to change this using the fullscreen size of the phone
|
||||
// and also using the status bar and navigation bar heights of the phone to calculate
|
||||
// the keyboard height. But this worked fine on a Nexus.
|
||||
int orientation = getScreenOrientation();
|
||||
int keyboardHeight = screenSize.y - rect.bottom;
|
||||
|
||||
if (keyboardHeight == 0) {
|
||||
notifyKeyboardHeightChanged(0, orientation);
|
||||
}
|
||||
else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
this.keyboardPortraitHeight = keyboardHeight;
|
||||
notifyKeyboardHeightChanged(keyboardPortraitHeight, orientation);
|
||||
}
|
||||
else {
|
||||
this.keyboardLandscapeHeight = keyboardHeight;
|
||||
notifyKeyboardHeightChanged(keyboardLandscapeHeight, orientation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void notifyKeyboardHeightChanged(int height, int orientation) {
|
||||
if (observer != null) {
|
||||
observer.onKeyboardHeightChanged(height, orientation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,9 +2,11 @@ package com.gh.common.util;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.entity.CommunityEntity;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.qa.entity.Questions;
|
||||
import com.gh.loghub.LogHubUtils;
|
||||
@ -20,6 +22,24 @@ import org.json.JSONObject;
|
||||
*/
|
||||
public class LogUtils {
|
||||
|
||||
public static void uploadCommunityArticle(String tracers, String articleId, String articleTitle,
|
||||
int readTime, CommunityEntity community) {
|
||||
JSONObject object = new JSONObject();
|
||||
try {
|
||||
object.put("subject", "community_article");
|
||||
object.put("community_id", community.getId());
|
||||
object.put("community_name", community.getName());
|
||||
object.put("article_id", articleId);
|
||||
object.put("article_name", articleTitle);
|
||||
object.put("tracers", tracers);
|
||||
object.put("read", readTime);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
upload(HaloApp.getInstance().getApplication(), object);
|
||||
}
|
||||
|
||||
public static void uploadDevice(LunchType launchType) {
|
||||
JSONObject object = new JSONObject();
|
||||
Application application = HaloApp.getInstance().getApplication();
|
||||
@ -29,6 +49,7 @@ public class LogUtils {
|
||||
object.put("launch_type", launchType.name());
|
||||
object.put("network", DeviceUtils.getNetwork(application));
|
||||
object.put("device_model", android.os.Build.MODEL);
|
||||
object.put("manufacture", Build.MANUFACTURER);
|
||||
object.put("device_system", android.os.Build.VERSION.RELEASE);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -72,42 +93,6 @@ public class LogUtils {
|
||||
upload(HaloApp.getInstance().getApplication(), object);
|
||||
}
|
||||
|
||||
|
||||
public static void uploadQuestions(Context context, String tracers, Questions questions) {
|
||||
if (context == null) return;
|
||||
JSONObject object = new JSONObject();
|
||||
try {
|
||||
object.put("community_id", UserManager.getInstance().getCommunity().getId());
|
||||
object.put("community_name", UserManager.getInstance().getCommunity().getName());
|
||||
object.put("question_id", questions.getId());
|
||||
object.put("question_name", questions.getTitle());
|
||||
object.put("subject", "question");
|
||||
object.put("tracers", tracers);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
upload(context, object);
|
||||
}
|
||||
|
||||
public static void uploadAnswers(Context context, String tracers, Questions questions, String answerId) {
|
||||
if (context == null) return;
|
||||
JSONObject object = new JSONObject();
|
||||
try {
|
||||
object.put("community_id", UserManager.getInstance().getCommunity().getId());
|
||||
object.put("community_name", UserManager.getInstance().getCommunity().getName());
|
||||
object.put("question_id", questions.getId());
|
||||
object.put("question_name", questions.getTitle());
|
||||
object.put("subject", "answer");
|
||||
object.put("tracers", tracers);
|
||||
object.put("answer_id", answerId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
upload(context, object);
|
||||
}
|
||||
|
||||
public static void uploadSearch(Context context, String searchKey) {
|
||||
if (TextUtils.isEmpty(searchKey) || context == null) return;
|
||||
|
||||
@ -178,6 +163,7 @@ public class LogUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
LogHubUtils.uploadLog(DeviceUtils.getIPAddress(context), object);
|
||||
// 暂时除了曝光外的数据都是扔到 community 这个库的,要是不是这个这个库的话这里要改一下
|
||||
LogHubUtils.uploadLog(DeviceUtils.getIPAddress(context), object, "community");
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,8 @@ import com.lightgame.utils.Utils;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
@ -107,17 +109,32 @@ public class LoginUtils {
|
||||
public static void userPostErrorToast(String errorString, Context context, boolean isQuestion) {
|
||||
if (TextUtils.isEmpty(errorString)) {
|
||||
Utils.toast(context, R.string.post_failure_hint);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject errorJson = new JSONObject(errorString);
|
||||
Iterator<String> iterator = errorJson.keys();
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
if ("toast".equals(key)) {
|
||||
Utils.toast(context, errorJson.get(key).toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int errorCode = errorJson.getInt("code");
|
||||
switch (errorCode) {
|
||||
case 403018:
|
||||
Utils.toast(context, R.string.comment_failed_unable);
|
||||
case 403050:
|
||||
case 403053:
|
||||
case 403048:
|
||||
case 403049:
|
||||
case 403057:
|
||||
case 403045:
|
||||
case 403046:
|
||||
case 403054:
|
||||
Utils.toast(context, R.string.comment_failed_userbanned);
|
||||
break;
|
||||
case 403051:
|
||||
@ -135,12 +152,6 @@ public class LoginUtils {
|
||||
case 403021:
|
||||
Utils.toast(context, R.string.comment_failed_illegal);
|
||||
break;
|
||||
case 403045:
|
||||
Utils.toast(context, R.string.deny_edit_question);
|
||||
break;
|
||||
case 403046:
|
||||
Utils.toast(context, R.string.deny_edit_answer);
|
||||
break;
|
||||
case 403047:
|
||||
Utils.toast(context, R.string.deny_vote_answer);
|
||||
break;
|
||||
@ -300,7 +311,8 @@ public class LoginUtils {
|
||||
Utils.toast(context, "403202");
|
||||
break;
|
||||
case 400213:
|
||||
Utils.toast(context, "昵称违规");
|
||||
case 403016:
|
||||
Utils.toast(context, "内容违规,请修改后再保存");
|
||||
break;
|
||||
case 403801:
|
||||
Utils.toast(context, "获取验证码太频繁,请稍后再试");
|
||||
|
||||
55
app/src/main/java/com/gh/common/util/MtaHelper.kt
Normal file
55
app/src/main/java/com/gh/common/util/MtaHelper.kt
Normal file
@ -0,0 +1,55 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import android.os.Build
|
||||
import android.text.TextUtils
|
||||
import com.gh.gamecenter.BuildConfig
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.utils.Util_System_Phone_State
|
||||
import com.tencent.stat.StatService
|
||||
import java.util.*
|
||||
|
||||
object MtaHelper {
|
||||
|
||||
@JvmStatic
|
||||
fun onEvent(eventId: String, vararg kv: String?) {
|
||||
val prop = Properties()
|
||||
for (i in kv.indices) {
|
||||
if (i % 2 != 0) {
|
||||
val key = kv[i - 1]
|
||||
val value = kv[i]
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) {
|
||||
prop.setProperty(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
StatService.trackCustomKVEvent(HaloApp.getInstance().application, eventId, prop)
|
||||
}
|
||||
|
||||
/**
|
||||
* 这个方法除了记录传进来的入参还会附带一些基本的设备信息
|
||||
*/
|
||||
@JvmStatic
|
||||
fun onEventWithBasicDeviceInfo(eventId: String, vararg kv: String) {
|
||||
val prop = Properties()
|
||||
for (i in kv.indices) {
|
||||
if (i % 2 != 0) {
|
||||
val key = kv[i - 1]
|
||||
val value = kv[i]
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) {
|
||||
prop.setProperty(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prop.setProperty("光环版本", BuildConfig.VERSION_NAME)
|
||||
prop.setProperty("网络状态", DeviceUtils.getNetwork(HaloApp.getInstance().application))
|
||||
prop.setProperty("IMEI", Util_System_Phone_State.getDeviceId(HaloApp.getInstance().application))
|
||||
prop.setProperty("机型", Build.MODEL)
|
||||
prop.setProperty("厂商", Build.MANUFACTURER)
|
||||
prop.setProperty("Android版本", Build.VERSION.RELEASE)
|
||||
prop.setProperty("GID", HaloApp.getInstance().gid)
|
||||
|
||||
StatService.trackCustomKVEvent(HaloApp.getInstance().application, eventId, prop)
|
||||
}
|
||||
|
||||
}
|
||||
46
app/src/main/java/com/gh/common/util/PackageHelper.kt
Normal file
46
app/src/main/java/com/gh/common/util/PackageHelper.kt
Normal file
@ -0,0 +1,46 @@
|
||||
package com.gh.common.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import com.gh.common.AppExecutor
|
||||
import com.gh.common.constant.Config
|
||||
import com.halo.assistant.HaloApp
|
||||
|
||||
object PackageHelper {
|
||||
|
||||
// 黑名单包名,用于区分像 Xposed Installer 那些工具的包名
|
||||
var excludePackageNameList = arrayListOf<String>()
|
||||
|
||||
var localPackageNameSet = hashSetOf<String>()
|
||||
|
||||
@JvmStatic
|
||||
fun refreshLocalPackageList() {
|
||||
AppExecutor.ioExecutor.execute {
|
||||
localPackageNameSet = getAllPackageName(HaloApp.getInstance().application)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun initExcludePackageName() {
|
||||
Config.getSettings()?.gameCommentBlackList?.let {
|
||||
excludePackageNameList = ArrayList(it)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取所有已安装的软件的包名、版本(非系统应用)
|
||||
*/
|
||||
private fun getAllPackageName(context: Context): HashSet<String> {
|
||||
val list = HashSet<String>()
|
||||
val packageInfos = context.applicationContext.packageManager.getInstalledPackages(0)
|
||||
for (packageInfo in packageInfos) {
|
||||
if (packageInfo.applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM == 0) {
|
||||
if (context.packageName != packageInfo.packageName) {
|
||||
list.add(packageInfo.packageName)
|
||||
}
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,9 +11,12 @@ import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.g00fy2.versioncompare.Version;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
@ -42,10 +45,14 @@ public class PackageUtils {
|
||||
|
||||
List<GameUpdateEntity> updateList = new ArrayList<>();
|
||||
|
||||
boolean isAPluginGame = false;
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
// 判断是否gh_version是否存在
|
||||
String gh_version = (String) PackageUtils.getMetaData(context, apkEntity.getPackageName(), "gh_version");
|
||||
if (gh_version != null && apkEntity.getGhVersion() != null) {
|
||||
|
||||
// 确定这是一个插件游戏
|
||||
if (!isAPluginGame) isAPluginGame = true;
|
||||
gh_version = gh_version.substring(2);
|
||||
if (Long.parseLong(gh_version) < Long.parseLong(apkEntity.getGhVersion()) && apkEntity.getForce()) {
|
||||
GameUpdateEntity updateEntity = new GameUpdateEntity();
|
||||
@ -66,6 +73,41 @@ public class PackageUtils {
|
||||
}
|
||||
}
|
||||
|
||||
// 不是插件游戏
|
||||
if (!isAPluginGame) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApkNormal()) {
|
||||
|
||||
String versionFromRequest = apkEntity.getVersion();
|
||||
String versionFromInstalledApp = getVersionByPackage(context, apkEntity.getPackageName());
|
||||
|
||||
// 是否需要显示更新
|
||||
boolean shouldShouldUpdate = apkEntity.getForce();
|
||||
|
||||
if (shouldShouldUpdate && !TextUtils.isEmpty(versionFromRequest) && !TextUtils.isEmpty(versionFromInstalledApp)) {
|
||||
|
||||
// 根据版本判断是否需要更新
|
||||
shouldShouldUpdate = new Version(versionFromRequest).isHigherThan(versionFromInstalledApp);
|
||||
|
||||
if (shouldShouldUpdate) {
|
||||
GameUpdateEntity updateEntity = new GameUpdateEntity();
|
||||
updateEntity.setId(gameEntity.getId());
|
||||
updateEntity.setName(gameEntity.getName());
|
||||
updateEntity.setIcon(gameEntity.getIcon());
|
||||
updateEntity.setPackageName(apkEntity.getPackageName());
|
||||
updateEntity.setSize(apkEntity.getSize());
|
||||
updateEntity.setVersion(apkEntity.getVersion());
|
||||
updateEntity.setGhVersion(apkEntity.getGhVersion());
|
||||
updateEntity.setUrl(apkEntity.getUrl());
|
||||
updateEntity.setPlatform(apkEntity.getPlatform());
|
||||
updateEntity.setEtag(apkEntity.getEtag());
|
||||
updateEntity.setBrief(gameEntity.getBrief());
|
||||
updateEntity.setTag(gameEntity.getTag());
|
||||
updateList.add(updateEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updateList;
|
||||
}
|
||||
|
||||
@ -108,6 +150,17 @@ public class PackageUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean compareSignatureBetweenInstalledAppWithApk(Context context, String packageName, String apkFilePath) {
|
||||
try {
|
||||
Signature sig = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures[0];
|
||||
Signature releaseSig = context.getPackageManager().getPackageArchiveInfo(apkFilePath, PackageManager.GET_SIGNATURES).signatures[0];
|
||||
return sig.hashCode() == releaseSig.hashCode();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 解析签名
|
||||
*/
|
||||
@ -159,6 +212,11 @@ public class PackageUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 由于新增了非插件的也能更新的功能,倘若两个签名一样的话就不走下面的光环签名判断了
|
||||
if (compareSignatureBetweenInstalledAppWithApk(context, packageName, path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String signature = getApkSignatureByPackageName(context, packageName);
|
||||
return publicKey.equals(signature);
|
||||
}
|
||||
@ -172,7 +230,15 @@ public class PackageUtils {
|
||||
if ("smartisan".equals(Build.MANUFACTURER)) {
|
||||
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, new File(path));
|
||||
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
|
||||
installIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
} else {
|
||||
installIntent.setDataAndType(uri, "application/vnd.android.package-archive");
|
||||
}
|
||||
InstallUtils.getInstance(context).addInstall(getPackageNameByPath(context, path));
|
||||
return installIntent;
|
||||
}
|
||||
@ -228,7 +294,7 @@ public class PackageUtils {
|
||||
|
||||
/**
|
||||
* 数据统计或反馈用PatchVersionName
|
||||
* 判断助手是否是第一次启动或版本更新提交的版本号用AppVersionName{@link PackageUtils#getVersionName(Context)}
|
||||
* 判断助手是否是第一次启动或版本更新提交的版本号用AppVersionName{@link PackageUtils#getVersionName()}
|
||||
*
|
||||
* @return 补丁包版本号
|
||||
*/
|
||||
@ -239,15 +305,8 @@ public class PackageUtils {
|
||||
/*
|
||||
* 返回光环助手的版本信息
|
||||
*/
|
||||
public static String getVersionName(Context context) {
|
||||
try {
|
||||
PackageInfo pkgInfo = context.getApplicationContext().getPackageManager().getPackageInfo(
|
||||
context.getPackageName(), 0);
|
||||
return pkgInfo.versionName;
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
public static String getVersionName() {
|
||||
return BuildConfig.VERSION_NAME;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.CommentEntity;
|
||||
@ -57,27 +58,33 @@ public class PostCommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void addAnswerComment(final Context context, final String answerId, final String content,
|
||||
public static void addAnswerComment(final Context context, final String answerId, final String articleId,
|
||||
final String articleCommunityId, final String content,
|
||||
final CommentEntity commentEntity,
|
||||
final PostCommentListener listener) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), content);
|
||||
Observable<ResponseBody> observable;
|
||||
if (commentEntity != null) {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postReplyToAnswerComment(answerId, commentEntity.getId(), body);
|
||||
if (!TextUtils.isEmpty(articleId)) {
|
||||
if (commentEntity != null) {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postReplyToCommunityArticleComment(articleCommunityId,
|
||||
articleId, commentEntity.getId(), body);
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postCommentToCommunityArticle(articleCommunityId, articleId, body);
|
||||
}
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postNewCommentToAnswer(answerId, body);
|
||||
if (commentEntity != null) {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postReplyToAnswerComment(answerId, commentEntity.getId(), body);
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postNewCommentToAnswer(answerId, body);
|
||||
}
|
||||
}
|
||||
observable.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse() {
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
if (response.length() != 0) {
|
||||
if (listener != null) {
|
||||
listener.postSuccess(response);
|
||||
}
|
||||
} else {
|
||||
Utils.toast(context, R.string.post_failure_hint);
|
||||
public void onResponse(ResponseBody response) {
|
||||
if (listener != null) {
|
||||
listener.postSuccess(new JSONObject());// 不需要返回
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,10 +97,18 @@ public class PostCommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void voteAnswerComment(final Context context,final String answerId, final String commentId,
|
||||
final PostCommentListener listener) {
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postVoteAnswerComment(answerId,commentId)
|
||||
public static void voteAnswerComment(final Context context, final String answerId, String articleId, String articleCommunityId,
|
||||
final String commentId, final PostCommentListener listener) {
|
||||
|
||||
|
||||
Observable<ResponseBody> observable;
|
||||
|
||||
if (!TextUtils.isEmpty(answerId)) {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postVoteAnswerComment(answerId, commentId);
|
||||
} else {
|
||||
observable = RetrofitManager.getInstance(context).getApi().postVoteCommunityArticleComment(articleCommunityId, articleId, commentId);
|
||||
}
|
||||
observable
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@ -113,7 +128,7 @@ public class PostCommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void addCommentVoto(final Context context, final String commentId,
|
||||
public static void addCommentVote(final Context context, final String commentId,
|
||||
final PostCommentListener listener) {
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postCommentVote(commentId)
|
||||
@ -157,7 +172,7 @@ public class PostCommentUtils {
|
||||
}
|
||||
|
||||
public static void postAnswerReportData(final Context context, final String commentId, final String answerId, final String reportData,
|
||||
final PostCommentListener listener) {
|
||||
final PostCommentListener listener) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), reportData);
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postReportOfAnswerComment(answerId, commentId, body)
|
||||
@ -176,6 +191,30 @@ public class PostCommentUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void reportCommunityArticleComment(final Context context,
|
||||
final String communityId,
|
||||
final String articleId,
|
||||
final String commentId,
|
||||
final String reportData,
|
||||
final PostCommentListener listener) {
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), reportData);
|
||||
RetrofitManager.getInstance(context).getApi()
|
||||
.postCommunityArticleCommentReport(communityId, articleId, commentId, body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
listener.postSuccess(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
listener.postFailed(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface PostCommentListener {
|
||||
void postSuccess(JSONObject response);
|
||||
|
||||
|
||||
@ -85,7 +85,8 @@ public class ShareUtils {
|
||||
tools,
|
||||
askInvite,
|
||||
askNormal, // 问答问题/答案
|
||||
shareGh
|
||||
shareGh,
|
||||
communityArticle
|
||||
}
|
||||
|
||||
private String[] arrLabel = {"微信好友", "朋友圈", "QQ好友", "QQ空间", "新浪微博", "短信", "复制链接", "取消"};
|
||||
@ -228,6 +229,7 @@ public class ShareUtils {
|
||||
mSummary += "(光环加速版)";
|
||||
break;
|
||||
case askNormal:
|
||||
case communityArticle:
|
||||
mTitle += " - 光环助手";
|
||||
break;
|
||||
}
|
||||
@ -258,13 +260,14 @@ public class ShareUtils {
|
||||
mSummary += "(光环加速版)";
|
||||
break;
|
||||
case askNormal:
|
||||
case communityArticle:
|
||||
mTitle += " - 光环助手";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
msg.title = mTitle;
|
||||
msg.description = mSummary;
|
||||
msg.description = !TextUtils.isEmpty(mSummary) && mSummary.length() > 1024 ? mSummary.substring(0, 1024) : mSummary;
|
||||
|
||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
req.transaction = buildTransaction("webpage");
|
||||
@ -358,6 +361,7 @@ public class ShareUtils {
|
||||
mSummary += "(光环加速版)";
|
||||
break;
|
||||
case askNormal:
|
||||
case communityArticle:
|
||||
mTitle += " - 光环助手";
|
||||
break;
|
||||
}
|
||||
@ -396,6 +400,7 @@ public class ShareUtils {
|
||||
msg.title = mSummary;
|
||||
break;
|
||||
case askNormal:
|
||||
case communityArticle:
|
||||
msg.title = mTitle + " - 光环助手";
|
||||
break;
|
||||
default:
|
||||
@ -446,6 +451,7 @@ public class ShareUtils {
|
||||
break;
|
||||
case askInvite:
|
||||
case askNormal:
|
||||
case communityArticle:
|
||||
smsBody = mTitle + " - 光环助手" + shareUrl;
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -47,6 +47,14 @@ public class StringUtils {
|
||||
return displayName + "(" + description + ")";
|
||||
}
|
||||
|
||||
public static String eliminateHtmlContent(String s) {
|
||||
if (TextUtils.isEmpty(s)) return "";
|
||||
|
||||
s = Html.fromHtml(s).toString();
|
||||
s = s.replace("\n", "");
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取字符串部分长度,超出的以 "..." 代替
|
||||
*
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
package com.gh.common.view;
|
||||
|
||||
import android.text.Spannable;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class CustomLinkMovementMethod extends LinkMovementMethod {
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
|
||||
boolean b = super.onTouchEvent(widget, buffer, event);
|
||||
//解决点击事件冲突问题
|
||||
if (!b && event.getAction() == MotionEvent.ACTION_UP) {
|
||||
ViewParent parent = widget.getParent();//处理widget的父控件点击事件
|
||||
if (parent instanceof ViewGroup) {
|
||||
return ((ViewGroup) parent).performClick();
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
public static CustomLinkMovementMethod getInstance() {
|
||||
if (sInstance == null)
|
||||
sInstance = new CustomLinkMovementMethod();
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
private static CustomLinkMovementMethod sInstance;
|
||||
|
||||
}
|
||||
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@ -24,6 +25,7 @@ import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.adapter.OnCollectionCallBackListener;
|
||||
import com.gh.gamecenter.adapter.PlatformPagerAdapter;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.ApkLink;
|
||||
import com.gh.gamecenter.entity.GameCollectionEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
@ -122,12 +124,17 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
this.location = location;
|
||||
this.traceEvent = traceEvent;
|
||||
|
||||
gameApk = sortApk(new ArrayList<>(gameEntity.getApk()));
|
||||
|
||||
gameApk = gameEntity.getApk();
|
||||
if (gameEntity.getCollection() != null) {
|
||||
mergeApkCollection(gameEntity);
|
||||
}
|
||||
|
||||
if (gameEntity.getApkLink() != null) {
|
||||
mergeApkLink(gameEntity);
|
||||
}
|
||||
|
||||
sortApk();
|
||||
|
||||
// 一个自定义的布局,作为显示的内容
|
||||
View contentView = View.inflate(mContext, R.layout.game_download_dialog, null);
|
||||
|
||||
@ -193,79 +200,121 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
DownloadManager.getInstance(mContext).addObserver(dataWatcher);
|
||||
}
|
||||
|
||||
private ArrayList<ApkEntity> sortApk(ArrayList<ApkEntity> apkList) {
|
||||
private void sortApk() {
|
||||
for (ApkEntity apkEntity : gameApk) {
|
||||
GameCollectionEntity apkCollection = apkEntity.getApkCollection();
|
||||
if (apkCollection != null) {
|
||||
List<ApkEntity> saveApkEntity = apkCollection.getSaveApkEntity();
|
||||
if (saveApkEntity != null) {
|
||||
for (ApkEntity entity : saveApkEntity) {
|
||||
int sortValue = getSortValue(entity);
|
||||
if (apkEntity.getOrder() < sortValue) {
|
||||
apkEntity.setOrder(sortValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
apkEntity.setOrder(getSortValue(apkEntity));
|
||||
}
|
||||
|
||||
Comparator<ApkEntity> comparator = (lhs, rhs) -> rhs.getOrder() - lhs.getOrder();
|
||||
Collections.sort(gameApk, comparator);
|
||||
}
|
||||
|
||||
private int getSortValue(ApkEntity apkEntity) {
|
||||
/*
|
||||
* 安装插件 10
|
||||
* 插件化下载中 9
|
||||
* 插件化 8
|
||||
* 安装更新 7
|
||||
* 更新下载中 6
|
||||
* 更新 5
|
||||
* 安装 4
|
||||
* 下载中 3
|
||||
* 启动 2
|
||||
* 默认(有图片)1
|
||||
* 默认(无图片)0
|
||||
*/
|
||||
* 插件化下载中 9
|
||||
* 插件化 8
|
||||
* 安装更新 7
|
||||
* 更新下载中 6
|
||||
* 更新 5
|
||||
* 安装 4
|
||||
* 下载中 3
|
||||
* 启动 2
|
||||
* 默认(有图片)1
|
||||
* 默认(无图片)0
|
||||
*/
|
||||
|
||||
DownloadEntity downloadEntity;
|
||||
String packageName;
|
||||
Object gh_id;
|
||||
for (ApkEntity apkEntity : apkList) {
|
||||
downloadEntity = DownloadManager.getInstance(mContext).getDownloadEntityByUrl(apkEntity.getUrl());
|
||||
if (downloadEntity == null) {
|
||||
packageName = apkEntity.getPackageName();
|
||||
if (PackageManager.INSTANCE.isInstalled(packageName)) {
|
||||
gh_id = PackageUtils.getMetaData(mContext, packageName, "gh_id");
|
||||
if (gh_id == null || gh_id.equals(gameEntity.getId())) {
|
||||
if (!PackageUtils.isSignature(mContext, packageName)) {
|
||||
apkEntity.setOrder(8);
|
||||
} else if (PackageManager.INSTANCE.isCanUpdate(gameEntity.getId(), packageName)) {
|
||||
apkEntity.setOrder(5);
|
||||
} else {
|
||||
apkEntity.setOrder(2);
|
||||
}
|
||||
continue;
|
||||
String packageName = apkEntity.getPackageName();
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(mContext).getDownloadEntityByUrl(apkEntity.getUrl());
|
||||
if (downloadEntity == null) {
|
||||
if (!TextUtils.isEmpty(packageName) && PackageManager.INSTANCE.isInstalled(packageName)) {
|
||||
gh_id = PackageUtils.getMetaData(mContext, packageName, "gh_id");
|
||||
if (gh_id == null || gh_id.equals(gameEntity.getId())) {
|
||||
if (!PackageUtils.isSignature(mContext, packageName)) {
|
||||
return 8;
|
||||
} else if (PackageManager.INSTANCE.isCanUpdate(gameEntity.getId(), packageName)) {
|
||||
return 5;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
apkEntity.setOrder(1);
|
||||
}
|
||||
if (apkEntity.getOrder() < 1) apkEntity.setOrder(1);
|
||||
|
||||
String platform = apkEntity.getPlatform();
|
||||
int id = PlatformUtils.getInstance(mContext).getPlatformPic(platform);
|
||||
if (id == 0) {
|
||||
String path = PlatformUtils.getInstance(mContext).getPlatformPicUrl(platform);
|
||||
if (path == null) {
|
||||
apkEntity.setOrder(0);
|
||||
}
|
||||
String platform = apkEntity.getPlatform();
|
||||
int id = PlatformUtils.getInstance(mContext).getPlatformPic(platform);
|
||||
if (id == 0) {
|
||||
String path = PlatformUtils.getInstance(mContext).getPlatformPicUrl(platform);
|
||||
if (path == null) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
return 10;
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
return 7;
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
} else {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
apkEntity.setOrder(10);
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
apkEntity.setOrder(7);
|
||||
} else {
|
||||
apkEntity.setOrder(4);
|
||||
}
|
||||
if (downloadEntity.isPluggable()) {
|
||||
return 9;
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
return 6;
|
||||
} else {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
apkEntity.setOrder(9);
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
apkEntity.setOrder(6);
|
||||
} else {
|
||||
apkEntity.setOrder(3);
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<ApkEntity> comparator = new Comparator<ApkEntity>() {
|
||||
@Override
|
||||
public int compare(ApkEntity lhs, ApkEntity rhs) {
|
||||
return rhs.getOrder() - lhs.getOrder();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 合并ApkLink
|
||||
private void mergeApkLink(GameEntity gameEntity) {
|
||||
for (ApkLink apkLink : gameEntity.getApkLink()) {
|
||||
if (!TextUtils.isEmpty(apkLink.getCollection())) {
|
||||
for (int i = 0; i < gameApk.size(); i++) {
|
||||
ApkEntity apkEntity = gameApk.get(i);
|
||||
GameCollectionEntity apkCollection = apkEntity.getApkCollection();
|
||||
if (apkCollection != null && apkCollection.getSaveApkEntity() != null) {
|
||||
List<ApkEntity> saveApkEntity = apkCollection.getSaveApkEntity();
|
||||
if (apkLink.getCollection().equals(apkCollection.getId())) {
|
||||
ApkEntity element = new ApkEntity();
|
||||
element.setApkLink(apkLink);
|
||||
if (saveApkEntity.size() > apkLink.getSort()) {
|
||||
saveApkEntity.add(apkLink.getSort(), element);
|
||||
} else {
|
||||
saveApkEntity.add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ApkEntity element = new ApkEntity();
|
||||
element.setApkLink(apkLink);
|
||||
if (gameApk.size() > apkLink.getSort()) {
|
||||
gameApk.add(apkLink.getSort(), element);
|
||||
} else {
|
||||
gameApk.add(element);
|
||||
}
|
||||
}
|
||||
};
|
||||
Collections.sort(apkList, comparator);
|
||||
return apkList;
|
||||
}
|
||||
}
|
||||
|
||||
// 合并ApkCollection
|
||||
@ -289,6 +338,7 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
List<ApkEntity> saveApkList = new ArrayList<>();
|
||||
saveApkList.add(apkEntity);
|
||||
collectionEntity.setSaveApkEntity(saveApkList);
|
||||
collectionEntity.setId(gameCollectionEntity.getId());
|
||||
collectionEntity.setName(gameCollectionEntity.getName());
|
||||
collectionEntity.setIcon(gameCollectionEntity.getIcon());
|
||||
collectionEntity.setColor(gameCollectionEntity.getColor());
|
||||
@ -363,7 +413,7 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
DisplayUtils.dip2px(mContext, 6), DisplayUtils.dip2px(mContext, 6));
|
||||
if (i == 0) {
|
||||
lparams.leftMargin = 0;
|
||||
imageView.setImageResource(R.drawable.oval_hint_up);
|
||||
imageView.setImageResource(R.drawable.download_oval_hint_up);
|
||||
} else {
|
||||
lparams.leftMargin = DisplayUtils.dip2px(mContext, 9);
|
||||
imageView.setImageResource(R.drawable.oval_hint_gray_bg);
|
||||
@ -467,7 +517,7 @@ public class DownloadDialog implements OnCollectionCallBackListener {
|
||||
for (int i = 0, size = linearLayout.getChildCount(); i < size; i++) {
|
||||
if (i == position % size) {
|
||||
((ImageView) linearLayout.getChildAt(i))
|
||||
.setImageResource(R.drawable.oval_hint_up);
|
||||
.setImageResource(R.drawable.download_oval_hint_up);
|
||||
} else {
|
||||
((ImageView) linearLayout.getChildAt(i))
|
||||
.setImageResource(R.drawable.oval_hint_gray_bg);
|
||||
|
||||
@ -7,7 +7,6 @@ import android.text.Layout;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextPaint;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
@ -26,16 +25,14 @@ public class ExpendTextView extends android.support.v7.widget.AppCompatTextView
|
||||
private boolean mInitLayout = false;
|
||||
private boolean mOpenLayout = false;
|
||||
|
||||
private ExpandCallback mExpandCallback;
|
||||
|
||||
public ExpendTextView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ExpendTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ExpendTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mMaxLines = getMaxLines();
|
||||
}
|
||||
@ -55,6 +52,10 @@ public class ExpendTextView extends android.support.v7.widget.AppCompatTextView
|
||||
this.mExpendText = text;
|
||||
}
|
||||
|
||||
public void setExpandCallback(ExpandCallback callback) {
|
||||
this.mExpandCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(CharSequence text, BufferType type) {
|
||||
mInitLayout = true;
|
||||
@ -103,11 +104,18 @@ public class ExpendTextView extends android.support.v7.widget.AppCompatTextView
|
||||
setMaxLines(Integer.MAX_VALUE);
|
||||
setText(mSnapshotText);
|
||||
|
||||
if (mExpandCallback != null) {
|
||||
mExpandCallback.onExpand();
|
||||
}
|
||||
}
|
||||
}, length - mExpendText.length(), length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
setText(msp);
|
||||
setMovementMethod(LinkMovementMethod.getInstance());
|
||||
setMovementMethod(CustomLinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public interface ExpandCallback {
|
||||
void onExpand();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
298
app/src/main/java/com/gh/common/view/PlayerView.kt
Normal file
298
app/src/main/java/com/gh/common/view/PlayerView.kt
Normal file
@ -0,0 +1,298 @@
|
||||
package com.gh.common.view
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||
import android.media.AudioManager
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v4.app.FragmentManager
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import cn.jzvd.JZDataSource
|
||||
import cn.jzvd.JZUtils
|
||||
import cn.jzvd.Jzvd
|
||||
import cn.jzvd.JzvdStd
|
||||
import com.gh.common.observer.MuteCallback
|
||||
import com.gh.common.observer.VolumeObserver
|
||||
import com.gh.common.util.DialogUtils
|
||||
import com.gh.common.util.MtaHelper
|
||||
import com.gh.common.util.NetworkUtils
|
||||
import com.gh.gamecenter.R
|
||||
import com.halo.assistant.HaloApp
|
||||
import java.util.*
|
||||
|
||||
class PlayerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : JzvdStd(context, attrs) {
|
||||
|
||||
var showAlertDialogForTheFistTime: Boolean = true
|
||||
|
||||
var gameName: String = ""
|
||||
|
||||
lateinit var muteIv: ImageView
|
||||
lateinit var rotateIv: ImageView
|
||||
|
||||
val muteCallback = object : MuteCallback {
|
||||
override fun onMute(isMute: Boolean) {
|
||||
if (isMute) {
|
||||
muteIv.setImageResource(R.drawable.ic_volume_off)
|
||||
} else {
|
||||
muteIv.setImageResource(R.drawable.ic_volume_on)
|
||||
}
|
||||
}
|
||||
}
|
||||
var volumeObserver = VolumeObserver(context, Handler(), muteCallback)
|
||||
|
||||
override fun init(context: Context?) {
|
||||
super.init(context)
|
||||
|
||||
muteIv = findViewById(R.id.mute)
|
||||
rotateIv = findViewById(R.id.rotate)
|
||||
|
||||
muteIv.setOnClickListener(this)
|
||||
rotateIv.setOnClickListener(this)
|
||||
|
||||
Jzvd.WIFI_TIP_DIALOG_SHOWED = true
|
||||
}
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (v.id == R.id.start || v.id == R.id.thumb) {
|
||||
if (Jzvd.CURRENT_STATE_PLAYING != currentState) {
|
||||
if ((currentScreen == SCREEN_WINDOW_NORMAL || currentScreen == SCREEN_WINDOW_LIST)) {
|
||||
MtaHelper.onEvent("游戏详情", "视频_点击播放", gameName)
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏详情", "视频全屏_点击播放", gameName)
|
||||
}
|
||||
} else {
|
||||
MtaHelper.onEvent("游戏详情", "视频_点击暂停", gameName)
|
||||
}
|
||||
|
||||
if (showAlertDialogForTheFistTime
|
||||
&& !NetworkUtils.isWifiConnected(context)
|
||||
&& currentState != Jzvd.CURRENT_STATE_PLAYING) {
|
||||
showNetworkAlertDialog()
|
||||
} else {
|
||||
super.onClick(v)
|
||||
}
|
||||
} else {
|
||||
super.onClick(v)
|
||||
when (v.id) {
|
||||
R.id.rotate -> {
|
||||
if (Jzvd.FULLSCREEN_ORIENTATION != SCREEN_ORIENTATION_LANDSCAPE) {
|
||||
Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||
JZUtils.setRequestedOrientation(context, Jzvd.FULLSCREEN_ORIENTATION)
|
||||
} else {
|
||||
Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
JZUtils.setRequestedOrientation(context, Jzvd.FULLSCREEN_ORIENTATION)
|
||||
}
|
||||
MtaHelper.onEvent("游戏详情", "视频全屏_点击旋转", gameName)
|
||||
}
|
||||
R.id.mute -> {
|
||||
toggleMute()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.player_view
|
||||
}
|
||||
|
||||
private fun toggleMute() {
|
||||
HaloApp.getInstance().isMute = !HaloApp.getInstance().isMute
|
||||
if (HaloApp.getInstance().isMute) {
|
||||
mute()
|
||||
} else {
|
||||
unmute()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNetworkAlertDialog() {
|
||||
DialogUtils.showAlertDialog(context,
|
||||
"播放视频",
|
||||
"您当前使用的网络为2G/3G/4G,播放视频将会消耗移动流量,确定播放?",
|
||||
"确定",
|
||||
"取消",
|
||||
DialogUtils.ConfirmListener {
|
||||
showAlertDialogForTheFistTime = false
|
||||
startButton.performClick()
|
||||
},
|
||||
null
|
||||
).show()
|
||||
}
|
||||
|
||||
private fun mute() {
|
||||
muteIv.setImageResource(R.drawable.ic_volume_off)
|
||||
// 安卓 6.0 以上 toggle 静音接口,以下将声音置为 0% 或 60%
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0)
|
||||
} else {
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0)
|
||||
}
|
||||
MtaHelper.onEvent("游戏详情", "视频_点击静音", gameName)
|
||||
}
|
||||
|
||||
private fun unmute() {
|
||||
muteIv.setImageResource(R.drawable.ic_volume_on)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE, 0)
|
||||
} else {
|
||||
mAudioManager.setStreamVolume(
|
||||
AudioManager.STREAM_MUSIC,
|
||||
60 * mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
|
||||
0)
|
||||
}
|
||||
MtaHelper.onEvent("游戏详情", "视频_解除静音", gameName)
|
||||
}
|
||||
|
||||
override fun onStatePlaying() {
|
||||
super.onStatePlaying()
|
||||
// 默认加载完显示播放信息
|
||||
if (currentScreen != Jzvd.SCREEN_WINDOW_FULLSCREEN) {
|
||||
changeUiToPlayingShow()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClickUiToggle() {
|
||||
// 仅在全屏状态下才会 toggle 播放信息
|
||||
if (currentScreen == Jzvd.SCREEN_WINDOW_FULLSCREEN) {
|
||||
if (bottomContainer.visibility != View.VISIBLE) {
|
||||
setSystemTimeAndBattery()
|
||||
clarity.text = jzDataSource.currentKey.toString()
|
||||
}
|
||||
if (currentState == Jzvd.CURRENT_STATE_PREPARING) {
|
||||
changeUiToPreparing()
|
||||
if (bottomContainer.visibility == View.VISIBLE) {
|
||||
} else {
|
||||
setSystemTimeAndBattery()
|
||||
}
|
||||
} else if (currentState == Jzvd.CURRENT_STATE_PLAYING) {
|
||||
if (bottomContainer.visibility == View.VISIBLE) {
|
||||
changeUiToPlayingClear()
|
||||
} else {
|
||||
changeUiToPlayingShow()
|
||||
}
|
||||
} else if (currentState == Jzvd.CURRENT_STATE_PAUSE) {
|
||||
if (bottomContainer.visibility == View.VISIBLE) {
|
||||
changeUiToPauseClear()
|
||||
} else {
|
||||
changeUiToPauseShow()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 小界面播放中或者准备中的时候点击直接进入全屏
|
||||
when (currentState) {
|
||||
Jzvd.CURRENT_STATE_PLAYING,
|
||||
Jzvd.CURRENT_STATE_PREPARING -> {
|
||||
startWindowFullscreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setUp(jzDataSource: JZDataSource?, screen: Int) {
|
||||
super.setUp(jzDataSource, screen)
|
||||
batteryTimeLayout.visibility = View.INVISIBLE
|
||||
|
||||
// 初始化隐藏和置换一些原有资源
|
||||
if (currentScreen == SCREEN_WINDOW_NORMAL || currentScreen == SCREEN_WINDOW_LIST) {
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
totalTimeTextView.visibility = View.INVISIBLE
|
||||
|
||||
muteIv.visibility = View.VISIBLE
|
||||
rotateIv.visibility = View.GONE
|
||||
|
||||
// 将右下角的按钮变成静音与否
|
||||
if (HaloApp.getInstance().isMute) {
|
||||
mute()
|
||||
} else {
|
||||
unmute()
|
||||
}
|
||||
} else {
|
||||
progressBar.visibility = View.VISIBLE
|
||||
totalTimeTextView.visibility = View.VISIBLE
|
||||
|
||||
muteIv.visibility = View.GONE
|
||||
rotateIv.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateStartImage() {
|
||||
when (currentState) {
|
||||
Jzvd.CURRENT_STATE_PLAYING -> {
|
||||
if (currentScreen == SCREEN_WINDOW_NORMAL || currentScreen == SCREEN_WINDOW_LIST) {
|
||||
startButton.visibility = View.INVISIBLE
|
||||
} else {
|
||||
startButton.visibility = View.VISIBLE
|
||||
startButton.setImageResource(cn.jzvd.R.drawable.jz_click_pause_selector)
|
||||
replayTextView.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
Jzvd.CURRENT_STATE_ERROR -> {
|
||||
startButton.visibility = View.INVISIBLE
|
||||
replayTextView.visibility = View.INVISIBLE
|
||||
}
|
||||
Jzvd.CURRENT_STATE_AUTO_COMPLETE -> {
|
||||
startButton.visibility = View.VISIBLE
|
||||
startButton.setImageResource(cn.jzvd.R.drawable.jz_click_replay_selector)
|
||||
replayTextView.visibility = View.VISIBLE
|
||||
}
|
||||
else -> {
|
||||
startButton.setImageResource(cn.jzvd.R.drawable.jz_click_play_selector)
|
||||
replayTextView.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun playOnThisJzvd() {
|
||||
super.playOnThisJzvd()
|
||||
|
||||
if (HaloApp.getInstance().isMute) {
|
||||
mute()
|
||||
}
|
||||
|
||||
// 处理从全屏跳转回小界面
|
||||
Jzvd.FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
if (currentScreen == SCREEN_WINDOW_NORMAL || currentScreen == SCREEN_WINDOW_LIST) {
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
totalTimeTextView.visibility = View.INVISIBLE
|
||||
MtaHelper.onEvent("游戏详情", "视频全屏_点击后退", gameName)
|
||||
} else {
|
||||
progressBar.visibility = View.VISIBLE
|
||||
totalTimeTextView.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
override fun startWindowFullscreen() {
|
||||
super.startWindowFullscreen()
|
||||
unmute()
|
||||
MtaHelper.onEvent("游戏详情", "视频_点击进入全屏", gameName)
|
||||
}
|
||||
|
||||
override fun startDismissControlViewTimer() {
|
||||
// 仅在全屏是才自动隐藏播放信息
|
||||
cancelDismissControlViewTimer()
|
||||
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
|
||||
DISMISS_CONTROL_VIEW_TIMER = Timer()
|
||||
mDismissControlViewTimerTask = DismissControlViewTimerTask()
|
||||
DISMISS_CONTROL_VIEW_TIMER.schedule(mDismissControlViewTimerTask, 3000)
|
||||
}
|
||||
}
|
||||
|
||||
fun observeVolume(fragment: Fragment?) {
|
||||
fragment?.context?.applicationContext?.contentResolver?.registerContentObserver(
|
||||
android.provider.Settings.System.CONTENT_URI, true, volumeObserver)
|
||||
|
||||
fragment?.fragmentManager?.registerFragmentLifecycleCallbacks(
|
||||
object : FragmentManager.FragmentLifecycleCallbacks() {
|
||||
override fun onFragmentPaused(fm: FragmentManager?, f: Fragment?) {
|
||||
if (f === fragment) {
|
||||
fragment.context?.applicationContext?.contentResolver?.unregisterContentObserver(volumeObserver)
|
||||
fragment.fragmentManager?.unregisterFragmentLifecycleCallbacks(this)
|
||||
}
|
||||
}
|
||||
}, false)
|
||||
}
|
||||
|
||||
}
|
||||
@ -95,6 +95,7 @@ public class RichEditor extends WebView {
|
||||
private OnTextChangeListener mTextChangeListener;
|
||||
private OnDecorationStateListener mDecorationStateListener;
|
||||
private AfterInitialLoadListener mLoadListener;
|
||||
private WebChromeClientListener mChromeClientListener;
|
||||
|
||||
public RichEditor(Context context) {
|
||||
this(context, null);
|
||||
@ -119,8 +120,8 @@ public class RichEditor extends WebView {
|
||||
setVerticalScrollBarEnabled(false);
|
||||
setHorizontalScrollBarEnabled(false);
|
||||
getSettings().setJavaScriptEnabled(true);
|
||||
setWebChromeClient(new WebChromeClient());
|
||||
setWebViewClient(createWebviewClient());
|
||||
setWebChromeClient(new WebChromeClient()); // 不要重写这个方法否则无法加载
|
||||
setWebViewClient(createWebViewClient());
|
||||
if (BuildConfig.DEBUG && Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
setWebContentsDebuggingEnabled(true);
|
||||
}
|
||||
@ -129,7 +130,7 @@ public class RichEditor extends WebView {
|
||||
applyAttributes(context, attrs);
|
||||
}
|
||||
|
||||
protected EditorWebViewClient createWebviewClient() {
|
||||
protected EditorWebViewClient createWebViewClient() {
|
||||
return new EditorWebViewClient();
|
||||
}
|
||||
|
||||
@ -145,6 +146,10 @@ public class RichEditor extends WebView {
|
||||
mLoadListener = listener;
|
||||
}
|
||||
|
||||
public void setChromeClientListener(WebChromeClientListener chromeClientListener) {
|
||||
mChromeClientListener = chromeClientListener;
|
||||
}
|
||||
|
||||
private void callback(String text) {
|
||||
mContents = text.replaceFirst(CALLBACK_SCHEME, "");
|
||||
if (mTextChangeListener != null) {
|
||||
@ -233,7 +238,7 @@ public class RichEditor extends WebView {
|
||||
}
|
||||
|
||||
public String getHtml() {
|
||||
return mContents;
|
||||
return TextUtils.isEmpty(mContents) ? "" : mContents;
|
||||
}
|
||||
|
||||
public void setEditorFontColor(int color) {
|
||||
@ -407,6 +412,10 @@ public class RichEditor extends WebView {
|
||||
if (mLoadListener != null) {
|
||||
mLoadListener.onAfterInitialLoad(isReady);
|
||||
}
|
||||
|
||||
if (mChromeClientListener != null) {
|
||||
mChromeClientListener.onPageFinished(view, url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -427,7 +436,18 @@ public class RichEditor extends WebView {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mChromeClientListener != null) {
|
||||
return mChromeClientListener.shouldOverrideUrlLoading(view, url);
|
||||
}
|
||||
|
||||
return super.shouldOverrideUrlLoading(view, url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface WebChromeClientListener {
|
||||
void onPageFinished(WebView view, String url);
|
||||
|
||||
boolean shouldOverrideUrlLoading(WebView view, String url);
|
||||
}
|
||||
}
|
||||
@ -10,10 +10,7 @@ import com.gh.base.fragment.BaseDialogFragment
|
||||
import com.gh.common.TimeElapsedHelper
|
||||
import com.gh.common.constant.Constants.SP_LAST_OPENING_ID
|
||||
import com.gh.common.constant.Constants.SP_LAST_OPENING_TIME
|
||||
import com.gh.common.util.DataUtils
|
||||
import com.gh.common.util.DirectUtils
|
||||
import com.gh.common.util.EntranceUtils
|
||||
import com.gh.common.util.edit
|
||||
import com.gh.common.util.*
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.databinding.DialogWelcomeBinding
|
||||
import com.gh.gamecenter.entity.CommunityEntity
|
||||
@ -64,8 +61,9 @@ class WelcomeDialog : BaseDialogFragment() {
|
||||
DirectUtils.directToQqConversation(context!!, mWelcomeEntity?.link!!)
|
||||
}
|
||||
EntranceUtils.HOST_COMMUNITY -> {
|
||||
DirectUtils.directToCommunity(context!!, CommunityEntity( mWelcomeEntity?.link!!, mWelcomeEntity?.text!!))
|
||||
DirectUtils.directToCommunity(context!!, CommunityEntity(mWelcomeEntity?.link!!, mWelcomeEntity?.text!!))
|
||||
}
|
||||
else -> DialogUtils.showLowVersionDialog(context)
|
||||
}
|
||||
|
||||
mDismissByClickImage = true
|
||||
|
||||
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
abstract class BaseDrawable extends Drawable implements TintableDrawable {
|
||||
|
||||
protected int mAlpha = 0xFF;
|
||||
protected ColorFilter mColorFilter;
|
||||
protected ColorStateList mTintList;
|
||||
protected PorterDuff.Mode mTintMode = PorterDuff.Mode.SRC_IN;
|
||||
protected PorterDuffColorFilter mTintFilter;
|
||||
|
||||
private DummyConstantState mConstantState = new DummyConstantState();
|
||||
|
||||
@Override
|
||||
public int getAlpha() {
|
||||
return mAlpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
if (mAlpha != alpha) {
|
||||
mAlpha = alpha;
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ColorFilter getColorFilter() {
|
||||
return mColorFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setColorFilter(@Nullable ColorFilter colorFilter) {
|
||||
mColorFilter = colorFilter;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setTint(@ColorInt int tintColor) {
|
||||
setTintList(ColorStateList.valueOf(tintColor));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setTintList(@Nullable ColorStateList tint) {
|
||||
mTintList = tint;
|
||||
if (updateTintFilter()) {
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setTintMode(@NonNull PorterDuff.Mode tintMode) {
|
||||
mTintMode = tintMode;
|
||||
if (updateTintFilter()) {
|
||||
invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStateful() {
|
||||
return mTintList != null && mTintList.isStateful();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onStateChange(int[] state) {
|
||||
return updateTintFilter();
|
||||
}
|
||||
|
||||
private boolean updateTintFilter() {
|
||||
|
||||
if (mTintList == null || mTintMode == null) {
|
||||
boolean hadTintFilter = mTintFilter != null;
|
||||
mTintFilter = null;
|
||||
return hadTintFilter;
|
||||
}
|
||||
|
||||
int tintColor = mTintList.getColorForState(getState(), Color.TRANSPARENT);
|
||||
// They made PorterDuffColorFilter.setColor() and setMode() @hide.
|
||||
mTintFilter = new PorterDuffColorFilter(tintColor, mTintMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
// Be safe.
|
||||
return PixelFormat.TRANSLUCENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
|
||||
Rect bounds = getBounds();
|
||||
if (bounds.width() == 0 || bounds.height() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int saveCount = canvas.save();
|
||||
canvas.translate(bounds.left, bounds.top);
|
||||
onDraw(canvas, bounds.width(), bounds.height());
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
|
||||
protected ColorFilter getColorFilterForDrawing() {
|
||||
return mColorFilter != null ? mColorFilter : mTintFilter;
|
||||
}
|
||||
|
||||
protected abstract void onDraw(Canvas canvas, int width, int height);
|
||||
|
||||
// Workaround LayerDrawable.ChildDrawable which calls getConstantState().newDrawable()
|
||||
// without checking for null.
|
||||
// We are never inflated from XML so the protocol of ConstantState does not apply to us. In
|
||||
// order to make LayerDrawable happy, we return ourselves from DummyConstantState.newDrawable().
|
||||
|
||||
@Override
|
||||
public ConstantState getConstantState() {
|
||||
return mConstantState;
|
||||
}
|
||||
|
||||
private class DummyConstantState extends ConstantState {
|
||||
|
||||
@Override
|
||||
public int getChangingConfigurations() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Drawable newDrawable() {
|
||||
return BaseDrawable.this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.ClipDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
class ClipDrawableCompat extends ClipDrawable implements TintableDrawable {
|
||||
|
||||
private static final String TAG = ClipDrawableCompat.class.getSimpleName();
|
||||
|
||||
private Drawable mDrawable;
|
||||
|
||||
private DummyConstantState mConstantState = new DummyConstantState();
|
||||
|
||||
public ClipDrawableCompat(Drawable drawable, int gravity, int orientation) {
|
||||
super(drawable, gravity, orientation);
|
||||
|
||||
mDrawable = drawable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Drawable getDrawable() {
|
||||
return mDrawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTint(int tintColor) {
|
||||
if (mDrawable instanceof TintableDrawable) {
|
||||
//noinspection RedundantCast
|
||||
((TintableDrawable) mDrawable).setTint(tintColor);
|
||||
} else {
|
||||
Log.w(TAG, "Drawable did not implement TintableDrawable, it won't be tinted below" +
|
||||
" Lollipop");
|
||||
super.setTint(tintColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTintList(ColorStateList tint) {
|
||||
if (mDrawable instanceof TintableDrawable) {
|
||||
//noinspection RedundantCast
|
||||
((TintableDrawable) mDrawable).setTintList(tint);
|
||||
} else {
|
||||
Log.w(TAG, "Drawable did not implement TintableDrawable, it won't be tinted below" +
|
||||
" Lollipop");
|
||||
super.setTintList(tint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTintMode(PorterDuff.Mode tintMode) {
|
||||
if (mDrawable instanceof TintableDrawable) {
|
||||
//noinspection RedundantCast
|
||||
((TintableDrawable) mDrawable).setTintMode(tintMode);
|
||||
} else {
|
||||
Log.w(TAG, "Drawable did not implement TintableDrawable, it won't be tinted below" +
|
||||
" Lollipop");
|
||||
super.setTintMode(tintMode);
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround LayerDrawable.ChildDrawable which calls getConstantState().newDrawable()
|
||||
// without checking for null.
|
||||
// We are never inflated from XML so the protocol of ConstantState does not apply to us. In
|
||||
// order to make LayerDrawable happy, we return ourselves from DummyConstantState.newDrawable().
|
||||
|
||||
@Override
|
||||
public ConstantState getConstantState() {
|
||||
return mConstantState;
|
||||
}
|
||||
|
||||
private class DummyConstantState extends ConstantState {
|
||||
|
||||
@Override
|
||||
public int getChangingConfigurations() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Drawable newDrawable() {
|
||||
return ClipDrawableCompat.this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,662 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.TintTypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RatingBar;
|
||||
|
||||
import com.gh.common.view.materialratingbar.internal.DrawableCompat;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
|
||||
// AppCompatRatingBar will add undesired measuring behavior.
|
||||
@SuppressLint("AppCompatCustomView")
|
||||
public class MaterialRatingBar extends RatingBar {
|
||||
|
||||
private static final String TAG = MaterialRatingBar.class.getSimpleName();
|
||||
|
||||
private TintInfo mProgressTintInfo = new TintInfo();
|
||||
|
||||
private MaterialRatingDrawable mDrawable;
|
||||
|
||||
private OnRatingChangeListener mOnRatingChangeListener;
|
||||
private float mLastKnownRating;
|
||||
|
||||
public MaterialRatingBar(Context context) {
|
||||
super(context);
|
||||
|
||||
init(null, 0);
|
||||
}
|
||||
|
||||
public MaterialRatingBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
init(attrs, 0);
|
||||
}
|
||||
|
||||
public MaterialRatingBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
init(attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@SuppressWarnings("RestrictedApi")
|
||||
private void init(AttributeSet attrs, int defStyleAttr) {
|
||||
|
||||
Context context = getContext();
|
||||
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
|
||||
R.styleable.MaterialRatingBar, defStyleAttr, 0);
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_progressTint)) {
|
||||
mProgressTintInfo.mProgressTintList = a.getColorStateList(
|
||||
R.styleable.MaterialRatingBar_mrb_progressTint);
|
||||
mProgressTintInfo.mHasProgressTintList = true;
|
||||
}
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_progressTintMode)) {
|
||||
mProgressTintInfo.mProgressTintMode = DrawableCompat.parseTintMode(a.getInt(
|
||||
R.styleable.MaterialRatingBar_mrb_progressTintMode, -1), null);
|
||||
mProgressTintInfo.mHasProgressTintMode = true;
|
||||
}
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_secondaryProgressTint)) {
|
||||
mProgressTintInfo.mSecondaryProgressTintList = a.getColorStateList(
|
||||
R.styleable.MaterialRatingBar_mrb_secondaryProgressTint);
|
||||
mProgressTintInfo.mHasSecondaryProgressTintList = true;
|
||||
}
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_secondaryProgressTintMode)) {
|
||||
mProgressTintInfo.mSecondaryProgressTintMode = DrawableCompat.parseTintMode(a.getInt(
|
||||
R.styleable.MaterialRatingBar_mrb_secondaryProgressTintMode, -1), null);
|
||||
mProgressTintInfo.mHasSecondaryProgressTintMode = true;
|
||||
}
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_progressBackgroundTint)) {
|
||||
mProgressTintInfo.mProgressBackgroundTintList = a.getColorStateList(
|
||||
R.styleable.MaterialRatingBar_mrb_progressBackgroundTint);
|
||||
mProgressTintInfo.mHasProgressBackgroundTintList = true;
|
||||
}
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_progressBackgroundTintMode)) {
|
||||
mProgressTintInfo.mProgressBackgroundTintMode = DrawableCompat.parseTintMode(a.getInt(
|
||||
R.styleable.MaterialRatingBar_mrb_progressBackgroundTintMode, -1), null);
|
||||
mProgressTintInfo.mHasProgressBackgroundTintMode = true;
|
||||
}
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_indeterminateTint)) {
|
||||
mProgressTintInfo.mIndeterminateTintList = a.getColorStateList(
|
||||
R.styleable.MaterialRatingBar_mrb_indeterminateTint);
|
||||
mProgressTintInfo.mHasIndeterminateTintList = true;
|
||||
}
|
||||
if (a.hasValue(R.styleable.MaterialRatingBar_mrb_indeterminateTintMode)) {
|
||||
mProgressTintInfo.mIndeterminateTintMode = DrawableCompat.parseTintMode(a.getInt(
|
||||
R.styleable.MaterialRatingBar_mrb_indeterminateTintMode, -1), null);
|
||||
mProgressTintInfo.mHasIndeterminateTintMode = true;
|
||||
}
|
||||
boolean fillBackgroundStars = a.getBoolean(
|
||||
R.styleable.MaterialRatingBar_mrb_fillBackgroundStars, isIndicator());
|
||||
a.recycle();
|
||||
|
||||
mDrawable = new MaterialRatingDrawable(getContext(), fillBackgroundStars);
|
||||
mDrawable.setStarCount(getNumStars());
|
||||
setProgressDrawable(mDrawable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumStars(int numStars) {
|
||||
super.setNumStars(numStars);
|
||||
|
||||
// mDrawable can be null during super class initialization.
|
||||
if (mDrawable != null) {
|
||||
mDrawable.setStarCount(numStars);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
int height = getMeasuredHeight();
|
||||
int width = Math.round(height * mDrawable.getTileRatio() * getNumStars());
|
||||
setMeasuredDimension(View.resolveSizeAndState(width, widthMeasureSpec, 0), height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressDrawable(Drawable d) {
|
||||
super.setProgressDrawable(d);
|
||||
|
||||
// mProgressTintInfo can be null during super class initialization.
|
||||
if (mProgressTintInfo != null) {
|
||||
applyProgressTints();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndeterminateDrawable(Drawable d) {
|
||||
super.setIndeterminateDrawable(d);
|
||||
|
||||
// mProgressTintInfo can be null during super class initialization.
|
||||
if (mProgressTintInfo != null) {
|
||||
applyIndeterminateTint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportProgressTintList()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ColorStateList getProgressTintList() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportProgressTintList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportProgressTintList(ColorStateList)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setProgressTintList(@Nullable ColorStateList tint) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportProgressTintList(tint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportProgressTintMode()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public PorterDuff.Mode getProgressTintMode() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportProgressTintMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportProgressTintMode(PorterDuff.Mode)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportProgressTintMode(tintMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportSecondaryProgressTintList()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ColorStateList getSecondaryProgressTintList() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportSecondaryProgressTintList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportSecondaryProgressTintList(ColorStateList)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setSecondaryProgressTintList(@Nullable ColorStateList tint) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportSecondaryProgressTintList(tint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportSecondaryProgressTintMode()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public PorterDuff.Mode getSecondaryProgressTintMode() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportSecondaryProgressTintMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportSecondaryProgressTintMode(PorterDuff.Mode)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setSecondaryProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportSecondaryProgressTintMode(tintMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportProgressBackgroundTintList()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ColorStateList getProgressBackgroundTintList() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportProgressBackgroundTintList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportProgressBackgroundTintList(ColorStateList)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setProgressBackgroundTintList(@Nullable ColorStateList tint) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportProgressBackgroundTintList(tint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportProgressBackgroundTintMode()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public PorterDuff.Mode getProgressBackgroundTintMode() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportProgressBackgroundTintMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportProgressBackgroundTintMode(PorterDuff.Mode)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setProgressBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportProgressBackgroundTintMode(tintMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportIndeterminateTintList()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public ColorStateList getIndeterminateTintList() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportIndeterminateTintList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportIndeterminateTintList(ColorStateList)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setIndeterminateTintList(@Nullable ColorStateList tint) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportIndeterminateTintList(tint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getSupportIndeterminateTintMode()} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public PorterDuff.Mode getIndeterminateTintMode() {
|
||||
logRatingBarTintWarning();
|
||||
return getSupportIndeterminateTintMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setSupportIndeterminateTintMode(PorterDuff.Mode)} instead.
|
||||
*/
|
||||
@Override
|
||||
public void setIndeterminateTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
logRatingBarTintWarning();
|
||||
setSupportIndeterminateTintMode(tintMode);
|
||||
}
|
||||
|
||||
private void logRatingBarTintWarning() {
|
||||
if (getContext().getApplicationInfo().minSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return;
|
||||
}
|
||||
Log.w(TAG, "Non-support version of tint method called, this is error-prone and will crash" +
|
||||
" below Lollipop if you are calling it as a method of RatingBar instead of" +
|
||||
" MaterialRatingBar");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getProgressTintList()
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getSupportProgressTintList() {
|
||||
return mProgressTintInfo.mProgressTintList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setProgressTintList(ColorStateList)
|
||||
*/
|
||||
public void setSupportProgressTintList(@Nullable ColorStateList tint) {
|
||||
mProgressTintInfo.mProgressTintList = tint;
|
||||
mProgressTintInfo.mHasProgressTintList = true;
|
||||
|
||||
applyPrimaryProgressTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getProgressTintMode()
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getSupportProgressTintMode() {
|
||||
return mProgressTintInfo.mProgressTintMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setProgressTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setSupportProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mProgressTintInfo.mProgressTintMode = tintMode;
|
||||
mProgressTintInfo.mHasProgressTintMode = true;
|
||||
|
||||
applyPrimaryProgressTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getSecondaryProgressTintList()
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getSupportSecondaryProgressTintList() {
|
||||
return mProgressTintInfo.mSecondaryProgressTintList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setSecondaryProgressTintList(ColorStateList)
|
||||
*/
|
||||
public void setSupportSecondaryProgressTintList(@Nullable ColorStateList tint) {
|
||||
mProgressTintInfo.mSecondaryProgressTintList = tint;
|
||||
mProgressTintInfo.mHasSecondaryProgressTintList = true;
|
||||
|
||||
applySecondaryProgressTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getSecondaryProgressTintMode()
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getSupportSecondaryProgressTintMode() {
|
||||
return mProgressTintInfo.mSecondaryProgressTintMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setSecondaryProgressTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setSupportSecondaryProgressTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mProgressTintInfo.mSecondaryProgressTintMode = tintMode;
|
||||
mProgressTintInfo.mHasSecondaryProgressTintMode = true;
|
||||
|
||||
applySecondaryProgressTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getProgressBackgroundTintList()
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getSupportProgressBackgroundTintList() {
|
||||
return mProgressTintInfo.mProgressBackgroundTintList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setProgressBackgroundTintList(ColorStateList)
|
||||
*/
|
||||
public void setSupportProgressBackgroundTintList(@Nullable ColorStateList tint) {
|
||||
mProgressTintInfo.mProgressBackgroundTintList = tint;
|
||||
mProgressTintInfo.mHasProgressBackgroundTintList = true;
|
||||
|
||||
applyProgressBackgroundTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getProgressBackgroundTintMode()
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getSupportProgressBackgroundTintMode() {
|
||||
return mProgressTintInfo.mProgressBackgroundTintMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setProgressBackgroundTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setSupportProgressBackgroundTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mProgressTintInfo.mProgressBackgroundTintMode = tintMode;
|
||||
mProgressTintInfo.mHasProgressBackgroundTintMode = true;
|
||||
|
||||
applyProgressBackgroundTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getIndeterminateTintList()
|
||||
*/
|
||||
@Nullable
|
||||
public ColorStateList getSupportIndeterminateTintList() {
|
||||
return mProgressTintInfo.mIndeterminateTintList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setIndeterminateTintList(ColorStateList)
|
||||
*/
|
||||
public void setSupportIndeterminateTintList(@Nullable ColorStateList tint) {
|
||||
mProgressTintInfo.mIndeterminateTintList = tint;
|
||||
mProgressTintInfo.mHasIndeterminateTintList = true;
|
||||
|
||||
applyIndeterminateTint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#getIndeterminateTintMode()
|
||||
*/
|
||||
@Nullable
|
||||
public PorterDuff.Mode getSupportIndeterminateTintMode() {
|
||||
return mProgressTintInfo.mIndeterminateTintMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see RatingBar#setIndeterminateTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
public void setSupportIndeterminateTintMode(@Nullable PorterDuff.Mode tintMode) {
|
||||
mProgressTintInfo.mIndeterminateTintMode = tintMode;
|
||||
mProgressTintInfo.mHasIndeterminateTintMode = true;
|
||||
|
||||
applyIndeterminateTint();
|
||||
}
|
||||
|
||||
private void applyProgressTints() {
|
||||
if (getProgressDrawable() == null) {
|
||||
return;
|
||||
}
|
||||
applyPrimaryProgressTint();
|
||||
applyProgressBackgroundTint();
|
||||
applySecondaryProgressTint();
|
||||
}
|
||||
|
||||
private void applyPrimaryProgressTint() {
|
||||
if (getProgressDrawable() == null) {
|
||||
return;
|
||||
}
|
||||
if (mProgressTintInfo.mHasProgressTintList || mProgressTintInfo.mHasProgressTintMode) {
|
||||
Drawable target = getTintTargetFromProgressDrawable(android.R.id.progress, true);
|
||||
if (target != null) {
|
||||
applyTintForDrawable(target, mProgressTintInfo.mProgressTintList,
|
||||
mProgressTintInfo.mHasProgressTintList, mProgressTintInfo.mProgressTintMode,
|
||||
mProgressTintInfo.mHasProgressTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applySecondaryProgressTint() {
|
||||
if (getProgressDrawable() == null) {
|
||||
return;
|
||||
}
|
||||
if (mProgressTintInfo.mHasSecondaryProgressTintList
|
||||
|| mProgressTintInfo.mHasSecondaryProgressTintMode) {
|
||||
Drawable target = getTintTargetFromProgressDrawable(android.R.id.secondaryProgress,
|
||||
false);
|
||||
if (target != null) {
|
||||
applyTintForDrawable(target, mProgressTintInfo.mSecondaryProgressTintList,
|
||||
mProgressTintInfo.mHasSecondaryProgressTintList,
|
||||
mProgressTintInfo.mSecondaryProgressTintMode,
|
||||
mProgressTintInfo.mHasSecondaryProgressTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyProgressBackgroundTint() {
|
||||
if (getProgressDrawable() == null) {
|
||||
return;
|
||||
}
|
||||
if (mProgressTintInfo.mHasProgressBackgroundTintList
|
||||
|| mProgressTintInfo.mHasProgressBackgroundTintMode) {
|
||||
Drawable target = getTintTargetFromProgressDrawable(android.R.id.background, false);
|
||||
if (target != null) {
|
||||
applyTintForDrawable(target, mProgressTintInfo.mProgressBackgroundTintList,
|
||||
mProgressTintInfo.mHasProgressBackgroundTintList,
|
||||
mProgressTintInfo.mProgressBackgroundTintMode,
|
||||
mProgressTintInfo.mHasProgressBackgroundTintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable getTintTargetFromProgressDrawable(int layerId, boolean shouldFallback) {
|
||||
Drawable progressDrawable = getProgressDrawable();
|
||||
if (progressDrawable == null) {
|
||||
return null;
|
||||
}
|
||||
progressDrawable.mutate();
|
||||
Drawable layerDrawable = null;
|
||||
if (progressDrawable instanceof LayerDrawable) {
|
||||
layerDrawable = ((LayerDrawable) progressDrawable).findDrawableByLayerId(layerId);
|
||||
}
|
||||
if (layerDrawable == null && shouldFallback) {
|
||||
layerDrawable = progressDrawable;
|
||||
}
|
||||
return layerDrawable;
|
||||
}
|
||||
|
||||
private void applyIndeterminateTint() {
|
||||
Drawable indeterminateDrawable = getIndeterminateDrawable();
|
||||
if (indeterminateDrawable == null) {
|
||||
return;
|
||||
}
|
||||
if (mProgressTintInfo.mHasIndeterminateTintList
|
||||
|| mProgressTintInfo.mHasIndeterminateTintMode) {
|
||||
indeterminateDrawable.mutate();
|
||||
applyTintForDrawable(indeterminateDrawable, mProgressTintInfo.mIndeterminateTintList,
|
||||
mProgressTintInfo.mHasIndeterminateTintList,
|
||||
mProgressTintInfo.mIndeterminateTintMode,
|
||||
mProgressTintInfo.mHasIndeterminateTintMode);
|
||||
}
|
||||
}
|
||||
|
||||
// Progress drawables in this library has already rewritten tint related methods for
|
||||
// compatibility.
|
||||
@SuppressLint("NewApi")
|
||||
private void applyTintForDrawable(Drawable drawable, ColorStateList tintList,
|
||||
boolean hasTintList, PorterDuff.Mode tintMode,
|
||||
boolean hasTintMode) {
|
||||
|
||||
if (hasTintList || hasTintMode) {
|
||||
|
||||
if (hasTintList) {
|
||||
if (drawable instanceof TintableDrawable) {
|
||||
//noinspection RedundantCast
|
||||
((TintableDrawable) drawable).setTintList(tintList);
|
||||
} else {
|
||||
logDrawableTintWarning();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
drawable.setTintList(tintList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasTintMode) {
|
||||
if (drawable instanceof TintableDrawable) {
|
||||
//noinspection RedundantCast
|
||||
((TintableDrawable) drawable).setTintMode(tintMode);
|
||||
} else {
|
||||
logDrawableTintWarning();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
drawable.setTintMode(tintMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The drawable (or one of its children) may not have been
|
||||
// stateful before applying the tint, so let's try again.
|
||||
if (drawable.isStateful()) {
|
||||
drawable.setState(getDrawableState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logDrawableTintWarning() {
|
||||
Log.w(TAG, "Drawable did not implement TintableDrawable, it won't be tinted below" +
|
||||
" Lollipop");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the listener that is listening for rating change events.
|
||||
*
|
||||
* @return The listener, may be null.
|
||||
*/
|
||||
public OnRatingChangeListener getOnRatingChangeListener() {
|
||||
return mOnRatingChangeListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the listener to be called when the rating changes.
|
||||
*
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public void setOnRatingChangeListener(OnRatingChangeListener listener) {
|
||||
mOnRatingChangeListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void setSecondaryProgress(int secondaryProgress) {
|
||||
super.setSecondaryProgress(secondaryProgress);
|
||||
|
||||
// HACK: Check and call our listener here because this method is always called by
|
||||
// updateSecondaryProgress() from onProgressRefresh().
|
||||
float rating = getRating();
|
||||
if (mOnRatingChangeListener != null && rating != mLastKnownRating) {
|
||||
mOnRatingChangeListener.onRatingChanged(this, rating);
|
||||
}
|
||||
mLastKnownRating = rating;
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback that notifies clients when the rating has been changed. This includes changes that
|
||||
* were initiated by the user through a touch gesture or arrow key/trackball as well as changes
|
||||
* that were initiated programmatically. This callback <strong>will</strong> be called
|
||||
* continuously while the user is dragging, different from framework's
|
||||
* {@link OnRatingBarChangeListener}.
|
||||
*/
|
||||
public interface OnRatingChangeListener {
|
||||
|
||||
/**
|
||||
* Notification that the rating has changed. This <strong>will</strong> be called
|
||||
* continuously while the user is dragging, different from framework's
|
||||
* {@link OnRatingBarChangeListener}.
|
||||
*
|
||||
* @param ratingBar The RatingBar whose rating has changed.
|
||||
* @param rating The current rating. This will be in the range 0..numStars.
|
||||
*/
|
||||
void onRatingChanged(MaterialRatingBar ratingBar, float rating);
|
||||
}
|
||||
|
||||
private static class TintInfo {
|
||||
|
||||
public ColorStateList mProgressTintList;
|
||||
public PorterDuff.Mode mProgressTintMode;
|
||||
public boolean mHasProgressTintList;
|
||||
public boolean mHasProgressTintMode;
|
||||
|
||||
public ColorStateList mSecondaryProgressTintList;
|
||||
public PorterDuff.Mode mSecondaryProgressTintMode;
|
||||
public boolean mHasSecondaryProgressTintList;
|
||||
public boolean mHasSecondaryProgressTintMode;
|
||||
|
||||
public ColorStateList mProgressBackgroundTintList;
|
||||
public PorterDuff.Mode mProgressBackgroundTintMode;
|
||||
public boolean mHasProgressBackgroundTintList;
|
||||
public boolean mHasProgressBackgroundTintMode;
|
||||
|
||||
public ColorStateList mIndeterminateTintList;
|
||||
public PorterDuff.Mode mIndeterminateTintMode;
|
||||
public boolean mHasIndeterminateTintList;
|
||||
public boolean mHasIndeterminateTintMode;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.support.v7.content.res.AppCompatResources;
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.gh.common.view.materialratingbar.internal.ThemeUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
|
||||
public class MaterialRatingDrawable extends LayerDrawable {
|
||||
|
||||
public MaterialRatingDrawable(Context context, boolean fillBackgroundStars) {
|
||||
super(new Drawable[]{
|
||||
createLayerDrawableWithTintAttrRes(fillBackgroundStars ?
|
||||
R.drawable.ic_star
|
||||
: R.drawable.ic_star_border, fillBackgroundStars ?
|
||||
R.attr.colorControlHighlight : R.attr.colorControlNormal, context),
|
||||
fillBackgroundStars ? createClippedLayerDrawableWithTintColor(
|
||||
R.drawable.ic_star, Color.TRANSPARENT, context)
|
||||
: createClippedLayerDrawableWithTintAttrRes(
|
||||
R.drawable.ic_star_border, R.attr.colorControlActivated,
|
||||
context),
|
||||
createClippedLayerDrawableWithTintAttrRes(R.drawable.ic_star,
|
||||
R.attr.colorControlActivated, context)
|
||||
});
|
||||
|
||||
setId(0, android.R.id.background);
|
||||
setId(1, android.R.id.secondaryProgress);
|
||||
setId(2, android.R.id.progress);
|
||||
}
|
||||
|
||||
private static Drawable createLayerDrawableWithTintColor(int tileRes, int tintColor,
|
||||
Context context) {
|
||||
TileDrawable drawable = new TileDrawable(AppCompatResources.getDrawable(context,
|
||||
tileRes));
|
||||
drawable.mutate();
|
||||
//noinspection RedundantCast
|
||||
((TintableDrawable) drawable).setTint(tintColor);
|
||||
return drawable;
|
||||
}
|
||||
|
||||
private static Drawable createLayerDrawableWithTintAttrRes(int tileRes, int tintAttrRes,
|
||||
Context context) {
|
||||
int tintColor = ThemeUtils.getColorFromAttrRes(tintAttrRes, context);
|
||||
return createLayerDrawableWithTintColor(tileRes, tintColor, context);
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
private static Drawable createClippedLayerDrawableWithTintColor(int tileResId, int tintColor,
|
||||
Context context) {
|
||||
return new ClipDrawableCompat(createLayerDrawableWithTintColor(tileResId, tintColor,
|
||||
context), Gravity.LEFT, ClipDrawableCompat.HORIZONTAL);
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
private static Drawable createClippedLayerDrawableWithTintAttrRes(int tileResId,
|
||||
int tintAttrRes,
|
||||
Context context) {
|
||||
return new ClipDrawableCompat(createLayerDrawableWithTintAttrRes(tileResId, tintAttrRes,
|
||||
context), Gravity.LEFT, ClipDrawableCompat.HORIZONTAL);
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
private static Drawable createClippedTransparentLayerDrawable() {
|
||||
return new ClipDrawableCompat(new TileDrawable(new ColorDrawable(Color.TRANSPARENT)),
|
||||
Gravity.LEFT, ClipDrawableCompat.HORIZONTAL);
|
||||
}
|
||||
|
||||
public float getTileRatio() {
|
||||
Drawable drawable = getTileDrawableByLayerId(android.R.id.progress).getDrawable();
|
||||
return (float) drawable.getIntrinsicWidth() / drawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
public void setStarCount(int count) {
|
||||
getTileDrawableByLayerId(android.R.id.background).setTileCount(count);
|
||||
getTileDrawableByLayerId(android.R.id.secondaryProgress).setTileCount(count);
|
||||
getTileDrawableByLayerId(android.R.id.progress).setTileCount(count);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private TileDrawable getTileDrawableByLayerId(int id) {
|
||||
Drawable layerDrawable = findDrawableByLayerId(id);
|
||||
switch (id) {
|
||||
case android.R.id.background:
|
||||
return (TileDrawable) layerDrawable;
|
||||
case android.R.id.secondaryProgress:
|
||||
case android.R.id.progress: {
|
||||
ClipDrawableCompat clipDrawable = (ClipDrawableCompat) layerDrawable;
|
||||
return (TileDrawable) clipDrawable.getDrawable();
|
||||
}
|
||||
default:
|
||||
// Should never reach here.
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
class TileDrawable extends BaseDrawable {
|
||||
|
||||
private Drawable mDrawable;
|
||||
private int mTileCount = -1;
|
||||
|
||||
public TileDrawable(Drawable drawable) {
|
||||
mDrawable = drawable;
|
||||
}
|
||||
|
||||
public Drawable getDrawable() {
|
||||
return mDrawable;
|
||||
}
|
||||
|
||||
public int getTileCount() {
|
||||
return mTileCount;
|
||||
}
|
||||
|
||||
public void setTileCount(int tileCount) {
|
||||
mTileCount = tileCount;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Drawable mutate() {
|
||||
mDrawable = mDrawable.mutate();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas, int width, int height) {
|
||||
|
||||
mDrawable.setAlpha(mAlpha);
|
||||
ColorFilter colorFilter = getColorFilterForDrawing();
|
||||
if (colorFilter != null) {
|
||||
mDrawable.setColorFilter(colorFilter);
|
||||
}
|
||||
|
||||
int tileHeight = mDrawable.getIntrinsicHeight();
|
||||
float scale = (float) height / tileHeight;
|
||||
canvas.scale(scale, scale);
|
||||
|
||||
float scaledWidth = width / scale;
|
||||
if (mTileCount < 0) {
|
||||
int tileWidth = mDrawable.getIntrinsicWidth();
|
||||
for (int x = 0; x < scaledWidth; x += tileWidth) {
|
||||
mDrawable.setBounds(x, 0, x + tileWidth, tileHeight);
|
||||
mDrawable.draw(canvas);
|
||||
}
|
||||
} else {
|
||||
float tileWidth = scaledWidth / mTileCount;
|
||||
for (int i = 0; i < mTileCount; ++i) {
|
||||
int drawableWidth = mDrawable.getIntrinsicWidth();
|
||||
float tileCenter = tileWidth * (i + 0.5f);
|
||||
float drawableWidthHalf = (float) drawableWidth / 2;
|
||||
mDrawable.setBounds(Math.round(tileCenter - drawableWidthHalf), 0,
|
||||
Math.round(tileCenter + drawableWidthHalf), tileHeight);
|
||||
mDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A {@code Drawable} that is tintable.
|
||||
*/
|
||||
public interface TintableDrawable {
|
||||
|
||||
/**
|
||||
* Specifies tint color for this drawable.
|
||||
* <p>
|
||||
* A Drawable's drawing content will be blended together with its tint
|
||||
* before it is drawn to the screen. This functions similarly to
|
||||
* {@link Drawable#setColorFilter(int, PorterDuff.Mode)}.
|
||||
* </p>
|
||||
* <p>
|
||||
* To clear the tint, pass {@code null} to
|
||||
* {@link #setTintList(ColorStateList)}.
|
||||
* </p>
|
||||
* <p class="note"><strong>Note:</strong> Setting a color filter via
|
||||
* {@link Drawable#setColorFilter(ColorFilter)} or
|
||||
* {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint.
|
||||
* </p>
|
||||
*
|
||||
* @param tintColor Color to use for tinting this drawable
|
||||
* @see #setTintList(ColorStateList)
|
||||
* @see #setTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
void setTint(@ColorInt int tintColor);
|
||||
|
||||
/**
|
||||
* Specifies tint color for this drawable as a color state list.
|
||||
* <p>
|
||||
* A Drawable's drawing content will be blended together with its tint
|
||||
* before it is drawn to the screen. This functions similarly to
|
||||
* {@link Drawable#setColorFilter(int, PorterDuff.Mode)}.
|
||||
* </p>
|
||||
* <p class="note"><strong>Note:</strong> Setting a color filter via
|
||||
* {@link Drawable#setColorFilter(ColorFilter)} or
|
||||
* {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint.
|
||||
* </p>
|
||||
*
|
||||
* @param tint Color state list to use for tinting this drawable, or
|
||||
* {@code null} to clear the tint
|
||||
* @see #setTint(int)
|
||||
* @see #setTintMode(PorterDuff.Mode)
|
||||
*/
|
||||
void setTintList(@Nullable ColorStateList tint);
|
||||
|
||||
/**
|
||||
* Specifies a tint blending mode for this drawable.
|
||||
* <p>
|
||||
* Defines how this drawable's tint color should be blended into the drawable
|
||||
* before it is drawn to screen. Default tint mode is {@link PorterDuff.Mode#SRC_IN}.
|
||||
* </p>
|
||||
* <p class="note"><strong>Note:</strong> Setting a color filter via
|
||||
* {@link Drawable#setColorFilter(ColorFilter)} or
|
||||
* {@link Drawable#setColorFilter(int, PorterDuff.Mode)} overrides tint.
|
||||
* </p>
|
||||
*
|
||||
* @param tintMode A Porter-Duff blending mode
|
||||
* @see #setTint(int)
|
||||
* @see #setTintList(ColorStateList)
|
||||
*/
|
||||
void setTintMode(@NonNull PorterDuff.Mode tintMode);
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar.internal;
|
||||
|
||||
import android.graphics.PorterDuff;
|
||||
|
||||
public class DrawableCompat {
|
||||
|
||||
/**
|
||||
* Parses a {@link PorterDuff.Mode} from a tintMode attribute's enum value.
|
||||
*/
|
||||
public static PorterDuff.Mode parseTintMode(int value, PorterDuff.Mode defaultMode) {
|
||||
switch (value) {
|
||||
case 3: return PorterDuff.Mode.SRC_OVER;
|
||||
case 5: return PorterDuff.Mode.SRC_IN;
|
||||
case 9: return PorterDuff.Mode.SRC_ATOP;
|
||||
case 14: return PorterDuff.Mode.MULTIPLY;
|
||||
case 15: return PorterDuff.Mode.SCREEN;
|
||||
case 16: return PorterDuff.Mode.ADD;
|
||||
default: return defaultMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.gh.common.view.materialratingbar.internal;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
|
||||
public class ThemeUtils {
|
||||
|
||||
private ThemeUtils() {}
|
||||
|
||||
public static int getColorFromAttrRes(int attrRes, Context context) {
|
||||
TypedArray a = context.obtainStyledAttributes(new int[] { attrRes });
|
||||
try {
|
||||
return a.getColor(0, 0);
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
public static float getFloatFromAttrRes(int attrRes, Context context) {
|
||||
TypedArray a = context.obtainStyledAttributes(new int[] { attrRes });
|
||||
try {
|
||||
return a.getFloat(0, 0);
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.common.exposure.ExposureEvent;
|
||||
import com.gh.common.util.AppDebugConfig;
|
||||
@ -186,8 +187,9 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
String method,
|
||||
String entrance,
|
||||
String location,
|
||||
boolean isSubscribe,
|
||||
@Nullable ExposureEvent traceEvent) {
|
||||
createDownload(context, gameEntity.getApk().get(0), gameEntity, method, entrance, location, traceEvent);
|
||||
createDownload(context, gameEntity.getApk().get(0), gameEntity, method, entrance, location, isSubscribe, traceEvent);
|
||||
}
|
||||
|
||||
public static void createDownload(final Context context,
|
||||
@ -196,15 +198,21 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
String method,
|
||||
String entrance,
|
||||
String location,
|
||||
boolean isSubscribe,
|
||||
@Nullable ExposureEvent traceEvent) {
|
||||
|
||||
// 安装指引
|
||||
if ("Huawei".equalsIgnoreCase(MANUFACTURER) || "Oppo".equalsIgnoreCase(MANUFACTURER)) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final SharedPreferences.Editor edit = sp.edit();
|
||||
if (sp.getBoolean("InstallHint" + PackageUtils.getVersionName(context), true)) {
|
||||
DialogUtils.showInstallHintDialog(context,
|
||||
() -> edit.putBoolean("InstallHint" + PackageUtils.getVersionName(context), false).apply());
|
||||
if (sp.getBoolean("InstallHint" + PackageUtils.getVersionName(), true)) {
|
||||
try {
|
||||
DialogUtils.showInstallHintDialog(context,
|
||||
() -> edit.putBoolean("InstallHint" + PackageUtils.getVersionName(), false).apply());
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
edit.putBoolean("InstallHint" + PackageUtils.getVersionName(), false).apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +244,11 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
}
|
||||
downloadEntity.setPlugin(gameEntity.getTag() != null && gameEntity.getTag().size() != 0);
|
||||
|
||||
DownloadManager.getInstance(context).add(downloadEntity);
|
||||
if (isSubscribe) {
|
||||
DownloadManager.getInstance(context).subscribe(downloadEntity);
|
||||
} else {
|
||||
DownloadManager.getInstance(context).add(downloadEntity);
|
||||
}
|
||||
|
||||
if (AppDebugConfig.IS_DEBUG) {
|
||||
AppDebugConfig.logMethodWithParams(DownloadManager.class, apkEntity.getUrl(), downloadEntity.getUrl(), method, entrance, location);
|
||||
@ -270,6 +282,27 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "add");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个下载任务(WiFi时自动下载)
|
||||
*
|
||||
* @param downloadEntity
|
||||
*/
|
||||
public void subscribe(DownloadEntity downloadEntity) {
|
||||
if (downloadEntity != null) {
|
||||
String url = downloadEntity.getUrl();
|
||||
checkDownloadEntryRecordValidate(url);
|
||||
if (isFileCompleted(url)) {
|
||||
downloadEntity.setStatus(DownloadStatus.done);
|
||||
DataChanger.INSTANCE.notifyDataChanged(downloadEntity);
|
||||
} else if (!isTaskDownloading(url)) {
|
||||
mContext.startService(getIntent(downloadEntity, DownloadStatus.subscribe));
|
||||
}
|
||||
put(url, System.currentTimeMillis());
|
||||
putStatus(url, DownloadStatus.subscribe);
|
||||
}
|
||||
Utils.log(DownloadManager.class.getSimpleName(), "subscribe");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据url到本地sqlite数据库中查找并获取该文件的保存路径, 并检查改路径下文件是否存在,不存在则删除该条无效记录
|
||||
*
|
||||
@ -327,6 +360,7 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
* @return null表示下载列表中不存在该任务,否则返回下载任务
|
||||
*/
|
||||
public DownloadEntity getDownloadEntityByUrl(String url) {
|
||||
if (TextUtils.isEmpty(url)) return null;
|
||||
return mDownloadDao.get(url);
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
package com.gh.download;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.gh.common.util.AppDebugConfig;
|
||||
@ -28,7 +30,9 @@ public class DownloadNotification {
|
||||
public static final String ACTION_INSTALL = "com.gh.gamecenter.INSTALL";
|
||||
public static final String ACTION_DOWNLOAD = "com.gh.gamecenter.DOWNLOAD";
|
||||
public static final int ICON = R.drawable.logo;
|
||||
private static final int NOTIFY_ID = 0x123;
|
||||
public static final int NOTIFY_ID = 0x123;
|
||||
public static final int WAIT_NOTIFY_ID = 0x124;
|
||||
private static final String CHANNEL_ID = "Halo_Download";
|
||||
|
||||
private static NotificationManager getNotificationManager(Context context) {
|
||||
return (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
@ -37,6 +41,12 @@ public class DownloadNotification {
|
||||
//TODO 下载重构
|
||||
public static void showDownloadDoneNotification(Context context, DownloadEntity downloadEntity) {
|
||||
final NotificationManager manager = getNotificationManager(context);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_LOW);
|
||||
manager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(EntranceUtils.KEY_PATH, downloadEntity.getPath());
|
||||
intent.setAction(ACTION_INSTALL);
|
||||
@ -57,7 +67,8 @@ public class DownloadNotification {
|
||||
}
|
||||
title = "下载完成,点击立即安装";
|
||||
}
|
||||
final Notification notification = new NotificationCompat.Builder(context)
|
||||
|
||||
final Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.logo)
|
||||
.setTicker(title)
|
||||
.setContentTitle(text)
|
||||
@ -84,7 +95,11 @@ public class DownloadNotification {
|
||||
downloadingSize++;
|
||||
}
|
||||
}
|
||||
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationManager nManager = getNotificationManager(context);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_LOW);
|
||||
nManager.createNotificationChannel(channel);
|
||||
}
|
||||
if (downloadingSize == 0) {
|
||||
nManager.cancel(NOTIFY_ID);
|
||||
} else {
|
||||
@ -92,7 +107,7 @@ public class DownloadNotification {
|
||||
intent.setAction(ACTION_DOWNLOAD);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, NOTIFY_ID,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification notification = new NotificationCompat.Builder(context)
|
||||
Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
|
||||
.setSmallIcon(ICON)
|
||||
.setTicker("点击查看")
|
||||
.setContentTitle("正在下载" + downloadingSize + "个游戏")
|
||||
@ -104,4 +119,28 @@ public class DownloadNotification {
|
||||
}
|
||||
}
|
||||
|
||||
public static void showWaitingNotification(Context context) {
|
||||
if (AppDebugConfig.IS_DEBUG) {
|
||||
AppDebugConfig.logMethodWithParams(DownloadNotification.class, context);
|
||||
}
|
||||
|
||||
NotificationManager nManager = getNotificationManager(context);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_ID, NotificationManager.IMPORTANCE_LOW);
|
||||
nManager.createNotificationChannel(channel);
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ACTION_DOWNLOAD);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, NOTIFY_ID,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification notification = new NotificationCompat.Builder(context, CHANNEL_ID)
|
||||
.setSmallIcon(ICON)
|
||||
.setTicker("连接WiFi后自动恢复下载")
|
||||
.setContentTitle("下载已暂停")
|
||||
.setContentText("连接WiFi后自动恢复下载")
|
||||
.setContentIntent(pendingIntent).build();
|
||||
notification.flags = Notification.FLAG_AUTO_CANCEL;
|
||||
if (nManager != null) nManager.notify(WAIT_NOTIFY_ID, notification);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.collection.CollectionWrapperFragment;
|
||||
|
||||
/**
|
||||
@ -12,13 +14,10 @@ import com.gh.gamecenter.collection.CollectionWrapperFragment;
|
||||
public class CollectionActivity extends NormalActivity {
|
||||
|
||||
@NonNull
|
||||
public static Intent getCollectionActivity(Context context) {
|
||||
// Bundle args = new Bundle();
|
||||
// args.putInt(BaseFragment_TabLayout.PAGE_INDEX, CollectionWrapperFragment.INDEX_TOOL);
|
||||
// return new IntentFactory.Builder(context)
|
||||
// .setActivity(CollectionActivity.class)
|
||||
// .setFragment(CollectionWrapperFragment.class).setArgs(args).build();
|
||||
return getTargetIntent(context, CollectionActivity.class, CollectionWrapperFragment.class);
|
||||
public static Intent getCollectionActivity(Context context, String entrance) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return getTargetIntent(context, CollectionActivity.class, CollectionWrapperFragment.class, bundle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,8 +5,10 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.entity.LinkEntity;
|
||||
import com.gh.gamecenter.entity.MessageEntity;
|
||||
import com.gh.gamecenter.qa.answer.detail.comment.AnswerCommentConversationFragment;
|
||||
import com.gh.gamecenter.qa.comment.CommentActivity;
|
||||
import com.gh.gamecenter.qa.comment.CommentConversationFragment;
|
||||
import com.halo.assistant.fragment.comment.CommentDetailFragment;
|
||||
|
||||
/**
|
||||
@ -19,20 +21,32 @@ public class CommentDetailActivity extends NormalActivity {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(EntranceUtils.KEY_COMMENTID, commentId);
|
||||
args.putParcelable(MessageEntity.Article.TAG, article);
|
||||
// return new IntentFactory.Builder(context)
|
||||
// .setActivity(CommentDetailActivity.class)
|
||||
// .setFragment(CommentDetailFragment.class).setArgs(args).build();
|
||||
return getTargetIntent(context, CommentDetailActivity.class, CommentDetailFragment.class, args);
|
||||
}
|
||||
|
||||
public static Intent getAnswerCommentIntent(Context context, String commentId, String answerId) {
|
||||
public static Intent getAnswerCommentIntent(Context context,
|
||||
String commentId,
|
||||
String answerId,
|
||||
LinkEntity linkEntity) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(EntranceUtils.KEY_COMMENTID, commentId);
|
||||
args.putString(EntranceUtils.KEY_ANSWER_ID, answerId);
|
||||
// return new IntentFactory.Builder(context)
|
||||
// .setActivity(CommentDetailActivity.class)
|
||||
// .setFragment(CommentDetailFragment.class).setArgs(args).build();
|
||||
return getTargetIntent(context, CommentDetailActivity.class, AnswerCommentConversationFragment.class, args);
|
||||
args.putParcelable(EntranceUtils.KEY_LINK, linkEntity);
|
||||
return getTargetIntent(context, CommentDetailActivity.class, CommentConversationFragment.class, args);
|
||||
}
|
||||
|
||||
|
||||
public static Intent getCommunityArticleCommentIntent(Context context,
|
||||
String articleId,
|
||||
String articleCommentId,
|
||||
String articleCommunityId,
|
||||
LinkEntity linkEntity) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(CommentActivity.ARTICLE_ID, articleId);
|
||||
args.putString(EntranceUtils.KEY_ARTICLE_COMMENT_ID, articleCommentId);
|
||||
args.putString(CommentActivity.ARTICLE_COMMUNITY_ID, articleCommunityId);
|
||||
args.putParcelable(EntranceUtils.KEY_LINK, linkEntity);
|
||||
return getTargetIntent(context, CommentDetailActivity.class, CommentConversationFragment.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@ import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.gamedetail.GameDetailFragment;
|
||||
|
||||
import cn.jzvd.Jzvd;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/3/24.
|
||||
* 游戏详情适配器
|
||||
@ -79,4 +81,11 @@ public class GameDetailActivity extends NormalActivity {
|
||||
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (Jzvd.backPress()) {
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import android.support.annotation.Nullable;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -30,10 +31,12 @@ import com.gh.base.AppUncaughtHandler;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.fragment.BaseFragment_ViewPager;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.exposure.ExposureUtils;
|
||||
import com.gh.common.exposure.meta.MetaUtil;
|
||||
import com.gh.common.im.ImManager;
|
||||
import com.gh.common.util.ClassUtils;
|
||||
import com.gh.common.util.CommunityHelper;
|
||||
import com.gh.common.util.ConcernUtils;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
import com.gh.common.util.DataLogUtils;
|
||||
@ -46,12 +49,14 @@ import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.GameUtils;
|
||||
import com.gh.common.util.GsonUtils;
|
||||
import com.gh.common.util.LogUtils;
|
||||
import com.gh.common.util.MtaHelper;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.TrafficUtils;
|
||||
import com.gh.common.util.UrlFilterUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadNotification;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.db.info.InstallInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
@ -75,6 +80,7 @@ import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.gh.gamecenter.manager.UpdateManager;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.normal.NormalFragment;
|
||||
import com.gh.gamecenter.qa.AskFragment;
|
||||
import com.gh.gamecenter.retrofit.ObservableUtil;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
@ -137,6 +143,7 @@ public class MainActivity extends BaseActivity {
|
||||
public final static String EB_SKIP_GAMEFRAGMENT = "GameFragment";
|
||||
|
||||
public final static String SHOULD_INIT_IM = "should_init_im";
|
||||
public final static String SWITCH_TO_COMMUNITY = "switch_to_community";
|
||||
|
||||
private MainWrapperFragment mMainWrapperFragment;
|
||||
|
||||
@ -202,30 +209,21 @@ public class MainActivity extends BaseActivity {
|
||||
toast("该链接已失效!请联系管理员。");
|
||||
|
||||
EventBus.getDefault().post(new EBShowDialog("notfound", downloadEntity.getName()));
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "下载失败弹窗",
|
||||
MtaHelper.onEventWithBasicDeviceInfo("下载失败弹窗",
|
||||
"游戏", downloadEntity.getName(),
|
||||
"平台", downloadEntity.getPlatform(),
|
||||
"光环版本", BuildConfig.VERSION_NAME,
|
||||
"网络状态", DeviceUtils.getNetwork(getApplication()),
|
||||
"IMEI", Util_System_Phone_State.getDeviceId(getApplication()),
|
||||
"机型", Build.MODEL,
|
||||
"厂商", Build.MANUFACTURER,
|
||||
"Android版本", Build.VERSION.RELEASE);
|
||||
"平台", downloadEntity.getPlatform());
|
||||
return;
|
||||
} else if (DownloadStatus.neterror.equals(downloadEntity.getStatus())
|
||||
|| DownloadStatus.timeout.equals(downloadEntity.getStatus())) {
|
||||
|
||||
DownloadNotification.showWaitingNotification(MainActivity.this); // 系统通知
|
||||
|
||||
toast("网络不稳定,下载任务已暂停");
|
||||
DataLogUtils.uploadNeterrorLog(MainActivity.this, downloadEntity);
|
||||
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "下载自动暂停",
|
||||
MtaHelper.onEventWithBasicDeviceInfo("下载自动暂停",
|
||||
"游戏", downloadEntity.getName(),
|
||||
"平台", downloadEntity.getPlatform(),
|
||||
"光环版本", BuildConfig.VERSION_NAME,
|
||||
"网络状态", DeviceUtils.getNetwork(getApplication()),
|
||||
"IMEI", Util_System_Phone_State.getDeviceId(getApplication()),
|
||||
"机型", Build.MODEL,
|
||||
"厂商", Build.MANUFACTURER,
|
||||
"Android版本", Build.VERSION.RELEASE);
|
||||
"平台", downloadEntity.getPlatform());
|
||||
}
|
||||
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
|
||||
if (downloadEntity.getName().contains(getString(R.string.app_name))) {
|
||||
@ -274,23 +272,13 @@ public class MainActivity extends BaseActivity {
|
||||
android.content.pm.PackageManager pm = getApplicationContext().getPackageManager();
|
||||
PackageInfo packageInfo = pm.getPackageArchiveInfo(downloadEntity.getPath(), android.content.pm.PackageManager.GET_ACTIVITIES);
|
||||
if (packageInfo == null) {
|
||||
DataUtils.onMtaEvent(getApplication(), "解析包错误分析"
|
||||
MtaHelper.onEventWithBasicDeviceInfo("解析包错误分析"
|
||||
, "游戏名字", downloadEntity.getName() + ":"
|
||||
+ PlatformUtils.getInstance(getApplicationContext()).getPlatformName(downloadEntity.getPlatform())
|
||||
, "网络状态", DeviceUtils.getNetwork(getApplication())
|
||||
, "用户机型", Build.MODEL
|
||||
, "设备IMEI", Util_System_Phone_State.getDeviceId(getApplication()));
|
||||
+ PlatformUtils.getInstance(getApplicationContext()).getPlatformName(downloadEntity.getPlatform()));
|
||||
|
||||
DataUtils.onMtaEvent(
|
||||
getApplication(),
|
||||
MtaHelper.onEventWithBasicDeviceInfo(
|
||||
"解析包错误_新",
|
||||
"游戏", downloadEntity.getName() + "-" + PlatformUtils.getInstance(getApplicationContext()).getPlatformName(downloadEntity.getPlatform()),
|
||||
"光环版本", BuildConfig.VERSION_NAME,
|
||||
"网络状态", DeviceUtils.getNetwork(getApplication()),
|
||||
"IMEI", Util_System_Phone_State.getDeviceId(getApplication()),
|
||||
"机型", Build.MODEL,
|
||||
"厂商", Build.MANUFACTURER,
|
||||
"Android版本", Build.VERSION.RELEASE);
|
||||
"游戏", downloadEntity.getName() + ":" + PlatformUtils.getInstance(getApplicationContext()).getPlatformName(downloadEntity.getPlatform()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -468,6 +456,9 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
PackageManager.INSTANCE.initData(list);
|
||||
|
||||
// 忽略 xposed 安装器
|
||||
list.remove(Constants.XPOSED_INSTALLER_PACKAGE_NAME);
|
||||
|
||||
//应用上报
|
||||
uploadAppList();
|
||||
|
||||
@ -572,62 +563,60 @@ public class MainActivity extends BaseActivity {
|
||||
* 更新安装列表数据
|
||||
*/
|
||||
private void update() {
|
||||
HaloApp.getInstance().getMainExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final List<String> installed = new ArrayList<>();
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true);
|
||||
List<InstallInfo> concernList = mInstallManager.getAllInstall();
|
||||
for (InstallInfo concernEntity : concernList) {
|
||||
concernEntity.setTime(System.currentTimeMillis());
|
||||
int quantity = 0;
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (String packageName : concernEntity.getPackageNames().keySet()) {
|
||||
if (PackageManager.INSTANCE.isInstalled(packageName)) {
|
||||
quantity++;
|
||||
packageNames.put(packageName, true);
|
||||
installed.add(packageName);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
HaloApp.getInstance().getMainExecutor().execute(() -> {
|
||||
final List<String> installed = new ArrayList<>();
|
||||
TrafficUtils spy = TrafficUtils.getInstance(getApplicationContext(), true);
|
||||
List<InstallInfo> concernList = mInstallManager.getAllInstall();
|
||||
for (InstallInfo concernEntity : concernList) {
|
||||
concernEntity.setTime(System.currentTimeMillis());
|
||||
int quantity = 0;
|
||||
HashMap<String, Boolean> packageNames = new HashMap<>();
|
||||
for (String packageName : concernEntity.getPackageNames().keySet()) {
|
||||
if (PackageManager.INSTANCE.isInstalled(packageName)) {
|
||||
quantity++;
|
||||
packageNames.put(packageName, true);
|
||||
installed.add(packageName);
|
||||
} else {
|
||||
packageNames.put(packageName, false);
|
||||
}
|
||||
concernEntity.setPackageNames(packageNames);
|
||||
concernEntity.setInstalledQuantity(quantity);
|
||||
int weight = 0;
|
||||
long traffic = spy.getTraffic(new ArrayList<>(concernEntity.getPackageNames().keySet()));
|
||||
concernEntity.setTraffic(traffic);
|
||||
if (traffic > 0) {
|
||||
weight++;
|
||||
}
|
||||
concernEntity.setWeight(weight);
|
||||
mInstallManager.updateInstall(concernEntity);
|
||||
}
|
||||
|
||||
// 更新用户已安装游戏
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONArray(installed).toString());
|
||||
RetrofitManager.getInstance(MainActivity.this).getApi().putPackage(UserManager.getInstance().getUserId(), body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
|
||||
handler.postDelayed(() -> DataCollectionUtils.uploadUser(MainActivity.this), 1000);
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
concernEntity.setPackageNames(packageNames);
|
||||
concernEntity.setInstalledQuantity(quantity);
|
||||
int weight = 0;
|
||||
long traffic = spy.getTraffic(new ArrayList<>(concernEntity.getPackageNames().keySet()));
|
||||
concernEntity.setTraffic(traffic);
|
||||
if (traffic > 0) {
|
||||
weight++;
|
||||
}
|
||||
concernEntity.setWeight(weight);
|
||||
mInstallManager.updateInstall(concernEntity);
|
||||
}
|
||||
|
||||
// 更新用户已安装游戏
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONArray(installed).toString());
|
||||
RetrofitManager.getInstance(MainActivity.this).getApi().putPackage(UserManager.getInstance().getUserId(), body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(new Response<ResponseBody>());
|
||||
|
||||
handler.postDelayed(() -> DataCollectionUtils.uploadUser(MainActivity.this), 1000);
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
});
|
||||
}
|
||||
|
||||
private void checkGameUpdate() {
|
||||
List<InstallInfo> infos = mInstallManager.getAllInstall();
|
||||
ArrayList<String> packageList = PackageUtils.getAllPackageName(this);
|
||||
for (InstallInfo info : infos) {
|
||||
for (String packageName : info.getPackageNames().keySet()) {
|
||||
if (info.getPackageNames().get(packageName)
|
||||
&& PackageUtils.getMetaData(this, packageName, "gh_version") != null) {
|
||||
&& packageList.contains(packageName)) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
}
|
||||
@ -722,7 +711,7 @@ public class MainActivity extends BaseActivity {
|
||||
DataCollectionManager.getInstance(getApplicationContext()).upload();
|
||||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(this), true);
|
||||
isNewFirstLaunch = sp.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(), true);
|
||||
|
||||
isSkipped = false;
|
||||
|
||||
@ -747,7 +736,7 @@ public class MainActivity extends BaseActivity {
|
||||
if (isNewFirstLaunch) {
|
||||
LogUtils.uploadDevice(DeviceTokenUtils.getLaunchType());
|
||||
getPluginUpdate();
|
||||
sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(this), false).apply();
|
||||
sp.edit().putBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(), false).apply();
|
||||
|
||||
checkDevice(); // 根据设备信息判断用户是否是新用户
|
||||
}
|
||||
@ -769,12 +758,16 @@ public class MainActivity extends BaseActivity {
|
||||
Config.setExceptionMsg(this, null);
|
||||
AppUncaughtHandler.reportException(this, new Throwable(message));
|
||||
DialogUtils.showWarningDialog(this, "发生闪退", "光环助手刚刚发生了闪退,马上反馈以帮助我们更好地修复问题?(只需简单描述你刚才的操作)"
|
||||
, "暂不", "马上反馈", new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
SuggestionActivity.startSuggestionActivity(MainActivity.this, SuggestType.crash, null, null);
|
||||
}
|
||||
}, null);
|
||||
, "暂不", "马上反馈",
|
||||
() -> {
|
||||
SuggestionActivity.startSuggestionActivity(MainActivity.this, SuggestType.crash, "APP闪退:");
|
||||
MtaHelper.onEventWithBasicDeviceInfo(
|
||||
"闪退弹窗",
|
||||
"玩家操作", "点击反馈");
|
||||
},
|
||||
() -> MtaHelper.onEventWithBasicDeviceInfo(
|
||||
"闪退弹窗",
|
||||
"玩家操作", "点击关闭"));
|
||||
}
|
||||
|
||||
checkTinkerPath();
|
||||
@ -787,14 +780,35 @@ public class MainActivity extends BaseActivity {
|
||||
handler.postDelayed(ImManager::attachIm, 1000);
|
||||
}
|
||||
|
||||
// 获取可用(没有被隐藏的)的社区列表
|
||||
CommunityHelper.getAvailableCommunityList();
|
||||
|
||||
handler.postDelayed(this::switchToCommunityTabAndRefresh, 800);
|
||||
|
||||
// 执行跳转事件
|
||||
handler.postDelayed(skipRun, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
switchToCommunityTabAndRefresh();
|
||||
}
|
||||
|
||||
private void switchToCommunityTabAndRefresh() {
|
||||
// 跳转到问答社区并刷新
|
||||
if (getIntent().getBooleanExtra(SWITCH_TO_COMMUNITY, false)) {
|
||||
getIntent().putExtra(SWITCH_TO_COMMUNITY, false);
|
||||
Log.e("Switch", "true");
|
||||
EventBus.getDefault().post(new EBSkip(MainActivity.EB_SKIP_GAMEFRAGMENT, 1));
|
||||
EventBus.getDefault().post(new EBReuse(AskFragment.EB_RETRY_PAGE));
|
||||
}
|
||||
}
|
||||
|
||||
private void getGhzsSettings() {
|
||||
String channel = HaloApp.getInstance().getChannel();
|
||||
RetrofitManager.getInstance(this)
|
||||
.getApi().getSettings(PackageUtils.getVersionName(this), channel)
|
||||
.getApi().getSettings(PackageUtils.getVersionName(), channel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<SettingsEntity>() {
|
||||
@ -822,7 +836,9 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
for (DownloadEntity downloadEntity : DownloadManager.getInstance(this).getAll()) {
|
||||
if (DownloadStatus.neterror.equals(downloadEntity.getStatus()) ||
|
||||
DownloadStatus.timeout.equals(downloadEntity.getStatus())) {
|
||||
DownloadStatus.timeout.equals(downloadEntity.getStatus()) ||
|
||||
DownloadStatus.subscribe.equals(downloadEntity.getStatus())) {
|
||||
DownloadManager.getInstance(this).put(downloadEntity.getUrl(), System.currentTimeMillis());
|
||||
Message msg = Message.obtain();
|
||||
msg.what = DownloadConfig.CONTINUE_DOWNLOAD_TASK;
|
||||
msg.obj = downloadEntity.getUrl();
|
||||
@ -949,15 +965,12 @@ public class MainActivity extends BaseActivity {
|
||||
"<font color='#ff0000'>读取应用列表</font>”选择为打开" +
|
||||
"“<font color='#ff0000'>允许</font>”,否则光环助手将无法帮您安装插件加速版的游戏");
|
||||
DialogUtils.showWarningDialog(this, "提示", content, "忽略", "去开启",
|
||||
new DialogUtils.ConfirmListener() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
// 跳转应用信息界面
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivityForResult(intent, SKIP_SETTING_REQUEST);
|
||||
}
|
||||
() -> {
|
||||
// 跳转应用信息界面
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivityForResult(intent, SKIP_SETTING_REQUEST);
|
||||
}, null);
|
||||
} else {
|
||||
getInstalledListFromServer();
|
||||
@ -1072,14 +1085,15 @@ public class MainActivity extends BaseActivity {
|
||||
mDownloadEntity.getUrl(), false); // 默认不删除安装包 sp.getBoolean("autodelete", true)
|
||||
}
|
||||
|
||||
if (sp.getBoolean("concerngame", true)) { //设置页面控制是否安装后自动关注
|
||||
GameManager gameManager = new GameManager(getApplicationContext());
|
||||
GameInfo gameInfo = gameManager.findGame(packageName);
|
||||
if (gameInfo != null) {
|
||||
mInstallManager.updateByEntity(gameInfo);
|
||||
}
|
||||
GameManager gameManager = new GameManager(getApplicationContext());
|
||||
GameInfo gameInfo = gameManager.findGame(packageName);
|
||||
if (gameInfo != null) {
|
||||
mInstallManager.updateByEntity(gameInfo);
|
||||
}
|
||||
|
||||
if (sp.getBoolean("concerngame", true)) { //设置页面控制是否安装后自动关注
|
||||
// 安装后关注游戏
|
||||
DownloadEntity finalDownloadEntity = mDownloadEntity;
|
||||
RetrofitManager.getInstance(this).getApi().getGameDigestByPackageName(UrlFilterUtils.getFilterQuery("package", packageName))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -1087,21 +1101,20 @@ public class MainActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onResponse(List<GameDigestEntity> response) {
|
||||
for (GameDigestEntity gameDigestEntity : response) {
|
||||
GameInfo gameInfo = new GameInfo();
|
||||
gameInfo.setId(gameDigestEntity.getId());
|
||||
gameInfo.setPackageName(packageName);
|
||||
gameInfo.setGameName(gameDigestEntity.getName());
|
||||
concernGame(gameDigestEntity.getId(), packageName);
|
||||
|
||||
if (PackageUtils.getMetaData(getApplicationContext(),
|
||||
packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(gameDigestEntity.getId())) { // 关注游戏
|
||||
ConcernUtils.INSTANCE.postConcernGameId(MainActivity.this, gameDigestEntity.getId(), null);
|
||||
if (finalDownloadEntity != null && gameDigestEntity.getId().equals(finalDownloadEntity.getGameId())) {
|
||||
ConcernUtils.INSTANCE.postConcernGameId(MainActivity.this, gameDigestEntity.getId(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PackageUtils.getMetaData(getApplicationContext(),
|
||||
packageName, "gh_version") != null) {
|
||||
checkGameUpdate(packageName);
|
||||
}
|
||||
|
||||
// 更新已安装游戏
|
||||
RetrofitManager.getInstance(MainActivity.this).getApi()
|
||||
.postPackage(UserManager.getInstance().getUserId(), packageName)
|
||||
|
||||
@ -13,9 +13,11 @@ import com.gh.gamecenter.message.MessageNormalFragment;
|
||||
|
||||
public class MessageInviteActivity extends NormalActivity {
|
||||
|
||||
public static Intent getIntent(Context context, String messageType) {
|
||||
public static Intent getIntent(Context context, String messageType, String outerInfo, String entrance) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_MESSAGE_TYPE, messageType);
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
bundle.putString(EntranceUtils.KEY_OUTER_INFO, outerInfo);
|
||||
return getTargetIntent(context, MessageInviteActivity.class, MessageNormalFragment.class, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,9 @@ package com.gh.gamecenter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.gamecenter.message.KeFuFragment;
|
||||
|
||||
/**
|
||||
@ -16,7 +18,9 @@ public class MessageKeFuActivity extends NormalActivity {
|
||||
return getTargetIntent(this, MessageKeFuActivity.class, KeFuFragment.class);
|
||||
}
|
||||
|
||||
public static Intent getIntent(Context context) {
|
||||
return getTargetIntent(context, MessageKeFuActivity.class, KeFuFragment.class);
|
||||
public static Intent getIntent(Context context, String entrance) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
return getTargetIntent(context, MessageKeFuActivity.class, KeFuFragment.class, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,9 +13,11 @@ import com.gh.gamecenter.message.MessageNormalFragment;
|
||||
|
||||
public class MessageVoteActivity extends NormalActivity {
|
||||
|
||||
public static Intent getIntent(Context context, String messageType) {
|
||||
public static Intent getIntent(Context context, String messageType, String outerInfo, String entrance) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
|
||||
bundle.putString(EntranceUtils.KEY_MESSAGE_TYPE, messageType);
|
||||
bundle.putString(EntranceUtils.KEY_OUTER_INFO, outerInfo);
|
||||
return getTargetIntent(context, MessageVoteActivity.class, MessageNormalFragment.class, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -55,6 +56,7 @@ import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
@ -209,14 +211,14 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
return intent;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// super.onActivityResult(requestCode, resultCode, data);
|
||||
// // 刷新评论数
|
||||
// if (resultCode == 1001 ) {
|
||||
// adapter.commentChange(data.getExtras().getInt("commentNum"));
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == ViewImageActivity.REQUEST_FOR_VIEWED_IMAGE && resultCode == Activity.RESULT_OK) {
|
||||
HashSet<Integer> imageSet = (HashSet<Integer>) data.getExtras().get(ViewImageActivity.VIEWED_IMAGE);
|
||||
adapter.replaceDefaultImage(imageSet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ -565,7 +567,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
|
||||
handler.postDelayed(runnable, 1000);
|
||||
} else if (v == mDetailCommentLl) {
|
||||
CheckLoginUtils.checkLogin(this, () -> {
|
||||
Intent intent = MessageDetailActivity.getIntentById(NewsDetailActivity.this, adapter.getNewsDetailEntity().getId(), null, true
|
||||
Intent intent = MessageDetailActivity.getIntentById(NewsDetailActivity.this, adapter.getId(), null, true
|
||||
, mEntrance + "(新闻详情[" + adapter.getTitle() + "])");
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
@ -9,6 +9,7 @@ import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import com.gh.common.util.DataUtils
|
||||
import com.gh.common.util.EntranceUtils
|
||||
import com.gh.common.util.StringUtils
|
||||
import com.gh.gamecenter.baselist.ListActivity
|
||||
import com.gh.gamecenter.baselist.LoadStatus
|
||||
import com.gh.gamecenter.entity.PersonalHistoryEntity
|
||||
@ -32,7 +33,7 @@ class PersonalHomeActivity : ListActivity<PersonalHistoryEntity, PersonalHomeVie
|
||||
private var mUserId: String? = ""
|
||||
|
||||
override fun provideListAdapter(): PersonalHomeAdapter {
|
||||
if (mAdapter == null) mAdapter = PersonalHomeAdapter(this, mListViewModel)
|
||||
if (mAdapter == null) mAdapter = PersonalHomeAdapter(this, mListViewModel, mEntrance)
|
||||
return mAdapter!!
|
||||
}
|
||||
|
||||
@ -56,6 +57,10 @@ class PersonalHomeActivity : ListActivity<PersonalHistoryEntity, PersonalHomeVie
|
||||
mUnreadViewModel?.liveData?.observe(this, Observer {
|
||||
mAdapter?.setMessageUnreadData(it)
|
||||
})
|
||||
|
||||
mPath = intent.getStringExtra(EntranceUtils.KEY_PATH)
|
||||
mUserId = intent.getStringExtra(EntranceUtils.KEY_USER_ID)
|
||||
|
||||
mListViewModel.personalDataLD.observe(this, Observer {
|
||||
if (mListViewModel.userId == UserManager.getInstance().userId) {
|
||||
val data = mUserViewModel?.loginObsUserinfo?.value?.data
|
||||
@ -63,6 +68,8 @@ class PersonalHomeActivity : ListActivity<PersonalHistoryEntity, PersonalHomeVie
|
||||
it?.name = data.name!!
|
||||
it?.introduce = data.introduce
|
||||
}
|
||||
|
||||
trackMtaEvent(it?.name)
|
||||
mAdapter?.personalData = it
|
||||
mAdapter?.notifyDataSetChanged()
|
||||
})
|
||||
@ -98,12 +105,10 @@ class PersonalHomeActivity : ListActivity<PersonalHistoryEntity, PersonalHomeVie
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
trackMtaEvent()
|
||||
}
|
||||
|
||||
private fun trackMtaEvent() {
|
||||
DataUtils.onMtaEvent(this, "个人主页", mPath, mUserId)
|
||||
private fun trackMtaEvent(name: String? = "") {
|
||||
DataUtils.onMtaEvent(this, "个人主页", mPath, StringUtils.combineTwoString(name, mUserId))
|
||||
}
|
||||
|
||||
override fun onLoadRefresh() {
|
||||
@ -134,11 +139,12 @@ class PersonalHomeActivity : ListActivity<PersonalHistoryEntity, PersonalHomeVie
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun startTargetActivity(context: Context, userId: String?, path: String?) {
|
||||
fun startTargetActivity(context: Context, userId: String?, entrance: String, path: String?) {
|
||||
if (!userId.isNullOrEmpty()) {
|
||||
val intent = Intent(context, PersonalHomeActivity::class.java)
|
||||
intent.putExtra(EntranceUtils.KEY_USER_ID, userId)
|
||||
intent.putExtra(EntranceUtils.KEY_PATH, path)
|
||||
intent.putExtra(EntranceUtils.KEY_ENTRANCE, "$entrance+($path)")
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,8 +4,10 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.StrictMode;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
@ -113,6 +115,12 @@ public class ShareCardActivity extends BaseActivity {
|
||||
String qrBody = "http://www.ghzs666.com/article/" + newsId + ".html?source=appshare200";
|
||||
QRCodeUtils.setQRCode(this, qrBody, mShareQrCodeDv);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
|
||||
StrictMode.setVmPolicy(builder.build());
|
||||
builder.detectFileUriExposure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -6,7 +6,9 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.StrictMode;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
@ -176,6 +178,13 @@ public class ShareCardPicActivity extends BaseActivity {
|
||||
String qrBody = "http://www.ghzs666.com/article/" + newsId + ".html?source=appshare200";
|
||||
QRCodeUtils.setQRCode(this, qrBody, mShareQrCodeDv);
|
||||
}
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
|
||||
StrictMode.setVmPolicy(builder.build());
|
||||
builder.detectFileUriExposure();
|
||||
}
|
||||
}
|
||||
|
||||
private void setContentImage(String url) {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
@ -7,7 +8,9 @@ import android.text.TextUtils;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DirectUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.gamecenter.entity.CommunityEntity;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.lightgame.config.CommonDebug;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
@ -16,6 +19,7 @@ import static com.gh.common.util.EntranceUtils.HOST_ANSWER;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_ARTICLE;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_COLUMN;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_COMMUNITY;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_COMMUNITY_ARTICLE;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_DOWNLOAD;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_GAME;
|
||||
import static com.gh.common.util.EntranceUtils.HOST_QUESTION;
|
||||
@ -81,10 +85,26 @@ public class SkipActivity extends BaseActivity {
|
||||
DirectUtils.directToAnswerDetail(this, id, ENTRANCE_BROWSER, "浏览器");
|
||||
break;
|
||||
case HOST_QUESTION:
|
||||
DirectUtils.directToQuestionDetail(this, id, ENTRANCE_BROWSER,"浏览器");
|
||||
DirectUtils.directToQuestionDetail(this, id, ENTRANCE_BROWSER, "浏览器");
|
||||
break;
|
||||
case HOST_COMMUNITY:
|
||||
DirectUtils.directToCommunity(this, new CommunityEntity(id, name));
|
||||
Intent intent;
|
||||
UserManager.getInstance().setCommunityData(new CommunityEntity(id, name));
|
||||
// 把切换放到 MainActivity 处理
|
||||
if (RunningUtils.isRunning(this)
|
||||
&& MainActivity.class.getName().equals(RunningUtils.getBaseActivity(this))) {
|
||||
intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.putExtra(MainActivity.SWITCH_TO_COMMUNITY, true);
|
||||
} else {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(MainActivity.SWITCH_TO_COMMUNITY, true);
|
||||
intent = SplashScreenActivity.getSplashScreenIntent(this, bundle);
|
||||
}
|
||||
startActivity(intent);
|
||||
break;
|
||||
case HOST_COMMUNITY_ARTICLE:
|
||||
DirectUtils.directToCommunityArticle(this, uri.getQueryParameter("articleId"), uri.getQueryParameter("communityId"), ENTRANCE_BROWSER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DeviceTokenUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
@ -29,6 +30,10 @@ import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.manager.FilterManager;
|
||||
import com.gh.gamecenter.user.UserRepository;
|
||||
import com.gh.gid.GidCallback;
|
||||
import com.gh.gid.GidHelper;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.download.DownloadEntity;
|
||||
import com.lightgame.download.FileUtils;
|
||||
import com.lightgame.utils.AppManager;
|
||||
import com.lightgame.utils.Utils;
|
||||
@ -86,7 +91,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
isNewFirstLaunch = mSharedPreferences.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(getApplicationContext()), true);
|
||||
isNewFirstLaunch = mSharedPreferences.getBoolean("isNewFirstLaunchV" + PackageUtils.getVersionName(), true);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
@ -111,6 +116,15 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
if (isNewFirstLaunch) {
|
||||
setTheme(R.style.AppGuideTheme);
|
||||
|
||||
// 删除更新后的光环助手包
|
||||
List<DownloadEntity> all = DownloadManager.getInstance(this).getAll();
|
||||
for (DownloadEntity downloadEntity : all) {
|
||||
if (downloadEntity.getPackageName().equals(getPackageName())) {
|
||||
DownloadManager.getInstance(this).cancel(downloadEntity.getUrl(), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setTheme(R.style.AppFullScreenTheme);
|
||||
}
|
||||
@ -157,6 +171,8 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
|
||||
// 跳转到主界面
|
||||
private void launch() {
|
||||
getUniqueId();
|
||||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
|
||||
if (bundle != null) intent.putExtras(bundle);
|
||||
@ -164,6 +180,24 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
finish();
|
||||
}
|
||||
|
||||
private void getUniqueId() {
|
||||
GidHelper.getInstance().registerDevice(new GidCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s) {
|
||||
Utils.log("Gid", s);
|
||||
// Utils.toast(SplashScreenActivity.this, "光环ID -> " + s);
|
||||
mSharedPreferences.edit().putString(Constants.DEVICE_KEY, s).apply();
|
||||
|
||||
HaloApp.getInstance().setGid(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String s) {
|
||||
Utils.log("Gid", s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
@ -178,9 +212,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
// 获取过滤包
|
||||
filterManager.getFilterFromServer(0);
|
||||
|
||||
// 检查是否存在旧版本光环助手包
|
||||
checkOldGhFile();
|
||||
|
||||
// 更新过滤表,获取自动刷新的cd,获取版本对应表
|
||||
String time = mSharedPreferences.getString("refresh_time", null);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
@ -220,6 +251,8 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
private void checkAndRequestPermission() {
|
||||
if (EasyPermissions.hasPermissions(this, mPermissions)) {
|
||||
launch();
|
||||
// 检查是否有旧版本光环,有就删掉
|
||||
HaloApp.getInstance().getMainExecutor().execute(this::checkOldGhFile);
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this, mPermissions, REQUEST_PERMISSION_TAG);
|
||||
}
|
||||
@ -252,7 +285,7 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
int index = name.indexOf("_");
|
||||
if (index != -1) {
|
||||
float version = Float.valueOf(name.substring(name.indexOf("V") + 1, index));
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersionName(getApplicationContext()));
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersionName());
|
||||
if (version <= currentVersion && file.delete()) {
|
||||
Utils.log(file.getName() + " file delete success.");
|
||||
}
|
||||
|
||||
@ -4,12 +4,17 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.DirectUtils;
|
||||
import com.gh.gamecenter.entity.SettingsEntity;
|
||||
import com.gh.gamecenter.suggest.SuggestType;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
@ -19,6 +24,11 @@ public class SuggestSelectActivity extends BaseActivity {
|
||||
|
||||
public final static int SUGGEST_TYPE_REQUEST = 11; // 只要进入反馈页面(下一个), 无论怎么回退当前页面都会退出
|
||||
|
||||
@BindView(R.id.suggest_qqun)
|
||||
public TextView qQun;
|
||||
|
||||
private SettingsEntity mSettings;
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context) {
|
||||
Intent intent = new Intent(context, SuggestSelectActivity.class);
|
||||
@ -42,6 +52,12 @@ public class SuggestSelectActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setNavigationTitle(getString(R.string.title_suggest_select));
|
||||
|
||||
mSettings = Config.getSettings();
|
||||
if (mSettings != null && mSettings.getSupport() != null &&
|
||||
!TextUtils.isEmpty(mSettings.getSupport().getqQun())) {
|
||||
qQun.setText(mSettings.getSupport().getqQun());
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick({R.id.suggest_type1, R.id.suggest_type2, R.id.suggest_type3, R.id.suggest_type4,
|
||||
@ -68,7 +84,12 @@ public class SuggestSelectActivity extends BaseActivity {
|
||||
type = SuggestType.articleCollect;
|
||||
break;
|
||||
case R.id.suggest_qqun_rl:
|
||||
DirectUtils.directToQqGroup(this, "vd754P2_uNUJqDcgX4V-pyXEGZZVH0DE"); // Q群:367541038 KEY
|
||||
String groupNumber = "vd754P2_uNUJqDcgX4V-pyXEGZZVH0DE";
|
||||
if (mSettings != null && mSettings.getSupport() != null &&
|
||||
!TextUtils.isEmpty(mSettings.getSupport().getqQunKey())) {
|
||||
groupNumber = mSettings.getSupport().getqQunKey();
|
||||
}
|
||||
DirectUtils.directToQqGroup(this, groupNumber); // Q群:367541038 KEY
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,6 @@ import com.gh.gamecenter.suggest.SuggestSelectGameAdapter;
|
||||
import com.gh.gamecenter.suggest.SuggestType;
|
||||
import com.google.gson.Gson;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.config.CommonDebug;
|
||||
import com.lightgame.utils.Util_System_Keyboard;
|
||||
import com.lightgame.utils.Util_System_Phone_State;
|
||||
import com.lightgame.utils.Utils;
|
||||
@ -140,7 +139,7 @@ public class SuggestionActivity extends BaseActivity implements OnRequestCallBac
|
||||
private SuggestType mSuggestType;
|
||||
|
||||
private String mGameInfo;
|
||||
private String mSearchGameHint;
|
||||
private String mHideHint;
|
||||
|
||||
private boolean mAgreePostPic;
|
||||
|
||||
@ -165,7 +164,7 @@ public class SuggestionActivity extends BaseActivity implements OnRequestCallBac
|
||||
public static void startSuggestionActivity(Context context, SuggestType suggestType, String hint) {
|
||||
Intent intent = new Intent(context, SuggestionActivity.class);
|
||||
intent.putExtra(EntranceUtils.KEY_SUGGESTTYPE, suggestType);
|
||||
intent.putExtra(EntranceUtils.KEY_SEARCH_SUGGEST_HINT, hint);
|
||||
intent.putExtra(EntranceUtils.KEY_HIDE_SUGGEST_HINT, hint);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@ -219,7 +218,7 @@ public class SuggestionActivity extends BaseActivity implements OnRequestCallBac
|
||||
}
|
||||
String suggestContent = extras.getString(EntranceUtils.KEY_CONTENT);
|
||||
String suggestHintType = extras.getString(EntranceUtils.KEY_SUGGEST_HINT_TYPE);
|
||||
mSearchGameHint = extras.getString(EntranceUtils.KEY_SEARCH_SUGGEST_HINT, "");
|
||||
mHideHint = extras.getString(EntranceUtils.KEY_HIDE_SUGGEST_HINT, "");
|
||||
mFunctionTypeName = getResources().getStringArray(R.array.suggest_function_type);
|
||||
|
||||
setNavigationTitle("意见反馈-" + mSuggestType.getType());
|
||||
@ -567,8 +566,7 @@ public class SuggestionActivity extends BaseActivity implements OnRequestCallBac
|
||||
params.put("suggestion_type", mSuggestType.getType());
|
||||
String message;
|
||||
if (mSuggestType == SuggestType.gameCollect) {
|
||||
message = mSearchGameHint + mGameInfo + "," + mSuggestContentEt.getText().toString().trim();
|
||||
params.put("message", message);
|
||||
message = mGameInfo + "," + mSuggestContentEt.getText().toString().trim();
|
||||
} else if (mSuggestType == SuggestType.functionSuggest) {
|
||||
String typeName;
|
||||
if (mFunctionType == 3) {
|
||||
@ -576,15 +574,15 @@ public class SuggestionActivity extends BaseActivity implements OnRequestCallBac
|
||||
} else {
|
||||
typeName = mFunctionTypeName[mFunctionType];
|
||||
}
|
||||
message = mSearchGameHint + mGameInfo + "," + typeName + "," + mSuggestContentEt.getText().toString().trim();
|
||||
params.put("message", message);
|
||||
message = mGameInfo + "," + typeName + "," + mSuggestContentEt.getText().toString().trim();
|
||||
} else {
|
||||
message = mSuggestContentEt.getText().toString().trim();
|
||||
params.put("message", mSuggestContentEt.getText().toString().trim());
|
||||
if (mSuggestType == SuggestType.crash) {
|
||||
params.put("log", readFromFile());
|
||||
}
|
||||
}
|
||||
message = mHideHint + message;
|
||||
params.put("message", message);
|
||||
|
||||
JSONObject jsonObject = new JSONObject(params);
|
||||
|
||||
@ -630,20 +628,29 @@ public class SuggestionActivity extends BaseActivity implements OnRequestCallBac
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
try {
|
||||
if (CommonDebug.IS_DEBUG && e != null) {
|
||||
String string = e.response().errorBody().string();
|
||||
Utils.log("sendSuggestion::onFailure->" + string);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if (postDialog != null) {
|
||||
postDialog.dismissAllowingStateLoss();
|
||||
}
|
||||
|
||||
try {
|
||||
if (e != null && e.code() == 403) {
|
||||
String string = e.response().errorBody().string();
|
||||
JSONObject object = new JSONObject(string);
|
||||
int code = object.getInt("code");
|
||||
if (code == 403052) {
|
||||
DialogUtils.showAlertDialog(SuggestionActivity.this, "提醒", "你已经提交过相同的反馈了"
|
||||
, "关闭提交", "返回修改", () -> {
|
||||
setResult(SUGGEST_TYPE_REQUEST);
|
||||
finish();
|
||||
}, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
toast("提交失败,请检查网络状态");
|
||||
}
|
||||
});
|
||||
|
||||
@ -10,6 +10,7 @@ import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
@ -76,12 +77,12 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
|
||||
@BindView(R.id.image_detail_page)
|
||||
Gh_ViewPager mViewPager;
|
||||
@BindView(R.id.image_detail_slide)
|
||||
View mSlideLine;
|
||||
@BindView(R.id.image_detail_progress)
|
||||
TextView mProgressHint;
|
||||
|
||||
private RelativeLayout.LayoutParams rparams;
|
||||
@BindView(R.id.image_mask)
|
||||
View mIndicatorMask;
|
||||
@BindView(R.id.image_indicator_tv)
|
||||
TextView mIndicatorTv;
|
||||
|
||||
private ViewImageAdapter adapter;
|
||||
|
||||
@ -95,7 +96,6 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
private HashSet<Integer> mViewedSet; // 让调用者知道该图片是否被看过了
|
||||
private Map<String, ImageInfoEntity> mImageInfoMap;
|
||||
|
||||
private int width;
|
||||
private int mLimitWidth;
|
||||
|
||||
private boolean isOrientation;
|
||||
@ -108,7 +108,6 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
return checkIntent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_viewimage;
|
||||
@ -117,8 +116,8 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mViewedSet = new HashSet();
|
||||
mImageInfoMap = new HashMap();
|
||||
mViewedSet = new HashSet<>();
|
||||
mImageInfoMap = new HashMap<>();
|
||||
|
||||
// init data
|
||||
int current = 0;
|
||||
@ -133,6 +132,9 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
isOrientation = savedInstanceState.getBoolean("isOrientation");
|
||||
}
|
||||
|
||||
if (urls.size() > 1) mIndicatorMask.setVisibility(View.VISIBLE);
|
||||
mIndicatorTv.setText(String.format("%d/%d", current + 1, urls.size()));
|
||||
|
||||
mImagePipeline = Fresco.getImagePipeline();
|
||||
|
||||
// init slide
|
||||
@ -144,13 +146,6 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
} else {
|
||||
mLimitWidth = widthPixels;
|
||||
}
|
||||
width = widthPixels / urls.size();
|
||||
rparams = new RelativeLayout.LayoutParams(width, DisplayUtils.dip2px(getApplicationContext(), 1));
|
||||
rparams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
rparams.bottomMargin = DisplayUtils.dip2px(getApplicationContext(), 10);
|
||||
rparams.leftMargin = width * current;
|
||||
mSlideLine.setLayoutParams(rparams);
|
||||
|
||||
// init viewPage
|
||||
adapter = new ViewImageAdapter();
|
||||
mViewPager.setAdapter(adapter);
|
||||
@ -212,8 +207,6 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
public void onPageScrolled(int position, float positionOffset,
|
||||
int positionOffsetPixels) {
|
||||
if (positionOffset != 0) {
|
||||
rparams.leftMargin = (int) (width * (positionOffset + position));
|
||||
mSlideLine.setLayoutParams(rparams);
|
||||
mProgressHint.setVisibility(View.GONE);
|
||||
} else {
|
||||
String url = urls.get(position);
|
||||
@ -249,6 +242,7 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
zoomDraweeView.reset(); // 重置矩阵,还原图片
|
||||
}
|
||||
}
|
||||
mIndicatorTv.setText(String.format("%d/%d", position + 1, urls.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -286,7 +280,6 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
} else {
|
||||
imageView.setImageURI(url); // 加载原图
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ViewImageAdapter extends PagerAdapter implements OnSingleTapListener {
|
||||
@ -299,8 +292,9 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
return urls.size();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
||||
String url = urls.get(position);
|
||||
|
||||
Gh_RelativeLayout view = (Gh_RelativeLayout) View.inflate(container.getContext(), R.layout.viewimage_normal_item, null);
|
||||
@ -435,18 +429,18 @@ public class ViewImageActivity extends BaseActivity implements OnPageChangeListe
|
||||
MessageShareUtils.refreshImage(new File(savePath), ViewImageActivity.this);
|
||||
} catch (IOException e) {
|
||||
Utils.log("图片保存失败:" + e.toString());
|
||||
System.out.println(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
container.removeView((View) object);
|
||||
object = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isViewFromObject(View view, Object object) {
|
||||
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
|
||||
return view == object;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package com.gh.gamecenter.adapter;
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@ -143,16 +144,20 @@ public class CommentDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
private void initCommentViewHolder(final CommentViewHolder holder, int position) {
|
||||
final CommentEntity commentEntity = mCommentList.get(position);
|
||||
|
||||
holder.commentLine.setVisibility(View.GONE);
|
||||
holder.commentLineBottom.setVisibility(View.VISIBLE);
|
||||
holder.commentLine.setVisibility(View.VISIBLE);
|
||||
holder.commentLineBottom.setVisibility(View.GONE);
|
||||
|
||||
CommentUtils.setCommentUserView(mContext, holder, commentEntity);
|
||||
|
||||
CommentUtils.setCommentTime(holder.commentTimeTv, commentEntity.getTime());
|
||||
if (commentEntity.getParent() != null) {
|
||||
holder.commentContentTv.setText("@" + commentEntity.getParent().getUser().getName() + ": " + commentEntity.getContent());
|
||||
|
||||
holder.commentContentTv.setText(commentEntity.getContent());
|
||||
if (commentEntity.getParent() != null && !TextUtils.isEmpty(commentEntity.getParent().getUser().getName())) {
|
||||
holder.quoteContainer.setVisibility(View.VISIBLE);
|
||||
holder.quoteAuthorTv.setText(String.format("@%s", commentEntity.getParent().getUser().getName()));
|
||||
holder.quoteContentTv.setText(commentEntity.getParent().getComment());
|
||||
} else {
|
||||
holder.commentContentTv.setText(commentEntity.getContent());
|
||||
holder.quoteContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.commentLikeIv.setOnClickListener(new View.OnClickListener() {
|
||||
@ -169,9 +174,14 @@ public class CommentDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
}
|
||||
});
|
||||
|
||||
holder.commentUserIconDv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, commentEntity.getUser().getId(), "文章-评论详情"));
|
||||
holder.commentUserNameTv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, commentEntity.getUser().getId(), "文章-评论详情"));
|
||||
holder.commentUserIconDv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, commentEntity.getUser().getId(), "", "文章-评论详情"));
|
||||
holder.commentUserNameTv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, commentEntity.getUser().getId(), "", "文章-评论详情"));
|
||||
|
||||
if (commentEntity.getPriority() != 0) {
|
||||
holder.commentBadge.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.commentBadge.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void initFooterViewHolder(FooterViewHolder holder) {
|
||||
|
||||
@ -6,21 +6,17 @@
|
||||
package com.gh.gamecenter.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.common.util.DataLogUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DirectUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NewsUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.gamecenter.GameDetailActivity;
|
||||
import com.gh.gamecenter.NewsDetailActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.SlideEntity;
|
||||
import com.gh.gamecenter.subject.refactor.SubjectActivity;
|
||||
import com.gh.gamecenter.entity.LinkEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -33,7 +29,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
|
||||
private Context mContext;
|
||||
// private List<Integer> imageIdList;
|
||||
private List<SlideEntity> mSlideEntityList;
|
||||
private List<LinkEntity> mSlideEntityList;
|
||||
|
||||
private int mSize;
|
||||
private boolean mIsInfiniteLoop;
|
||||
@ -42,7 +38,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
|
||||
// private ImageIndicator indicator;
|
||||
|
||||
public ImagePagerAdapter(Context context, List<SlideEntity> slideEntityList, boolean isInfiniteLoop, String source) {
|
||||
public ImagePagerAdapter(Context context, List<LinkEntity> slideEntityList, boolean isInfiniteLoop, String source) {
|
||||
mContext = context;
|
||||
mSlideEntityList = slideEntityList;
|
||||
mSize = getSize(slideEntityList);
|
||||
@ -50,7 +46,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
mSource = source;
|
||||
}
|
||||
|
||||
public int getSize(List<SlideEntity> sourceList) {
|
||||
public int getSize(List<LinkEntity> sourceList) {
|
||||
return sourceList == null ? 0 : sourceList.size();
|
||||
}
|
||||
|
||||
@ -69,7 +65,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
int index = getPosition(position);
|
||||
if (index >= mSlideEntityList.size()) return view;
|
||||
|
||||
final SlideEntity slideEntity = mSlideEntityList.get(index);
|
||||
final LinkEntity slideEntity = mSlideEntityList.get(index);
|
||||
|
||||
ImageUtils.display(mContext.getResources(), (SimpleDraweeView) view,
|
||||
slideEntity.getImage(), R.drawable.preload);
|
||||
@ -80,32 +76,17 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
|
||||
// 首页轮播图数据统计
|
||||
DataLogUtils.uploadLunbotuLog(mContext, slideEntity.getType(),
|
||||
slideEntity.getName(), String.valueOf(getPosition(position) % mSlideEntityList.size() + 1));
|
||||
slideEntity.getText(), String.valueOf(getPosition(position) % mSlideEntityList.size() + 1));
|
||||
|
||||
String entrance = StringUtils.buildString("(游戏-专题:滚动图["
|
||||
, slideEntity.getName()
|
||||
, slideEntity.getText()
|
||||
, "=", slideEntity.getType()
|
||||
, "=", String.valueOf(getPosition(position) + 1)
|
||||
, "])");
|
||||
|
||||
DataUtils.onMtaEvent(mContext, "轮播图", mSource, String.valueOf(position));
|
||||
DataUtils.onMtaEvent(mContext, "轮播图", mSource, String.valueOf(getPosition(position) % mSlideEntityList.size() + 1));
|
||||
|
||||
switch (slideEntity.getType()) {
|
||||
case "game":
|
||||
GameDetailActivity.startGameDetailActivity(mContext, slideEntity.getLink(), entrance);
|
||||
break;
|
||||
case "news":
|
||||
// 统计阅读量
|
||||
NewsUtils.statNewsViews(mContext, slideEntity.getLink());
|
||||
|
||||
Intent intent = NewsDetailActivity.getIntentById(mContext, slideEntity.getLink(), entrance);
|
||||
mContext.startActivity(intent);
|
||||
break;
|
||||
case "column":
|
||||
SubjectActivity.startSubjectActivity(mContext, slideEntity.getLink(),
|
||||
slideEntity.getName(), false, entrance);
|
||||
break;
|
||||
}
|
||||
DirectUtils.directToLinkPage(mContext, slideEntity, entrance, "首页游戏");
|
||||
|
||||
});
|
||||
|
||||
@ -137,7 +118,7 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void checkResetData(List<SlideEntity> list) {
|
||||
public void checkResetData(List<LinkEntity> list) {
|
||||
if (mSlideEntityList != list) {
|
||||
mSlideEntityList = list;
|
||||
mSize = getSize(list);
|
||||
|
||||
@ -399,6 +399,7 @@ public class InstallFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
|
||||
private void initGameNormal(final GameNormalSwipeViewHolder holder, final GameEntity gameEntity, final int i) {
|
||||
|
||||
gameEntity.setCollection(new ArrayList<>()); // 清空集合,防止下载按钮会因为存在集合而清空合集包的状态判断
|
||||
holder.initServerType(gameEntity, mContext);
|
||||
|
||||
holder.swipeText.setPadding(0, 0, DisplayUtils.dip2px(mContext, 15), 0);
|
||||
|
||||
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -38,6 +39,7 @@ import com.gh.gamecenter.retrofit.OkHttpCache;
|
||||
import com.gh.gamecenter.retrofit.Response;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@ -137,7 +139,7 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
return;
|
||||
}
|
||||
isLoading = true;
|
||||
RetrofitManager.getInstance(mContext).getApi().getComment(mConcernEntity.getId(), 10, mPage)
|
||||
RetrofitManager.getInstance(mContext).getApi().getComment(mConcernEntity.getId(), 10, mPage, Utils.getTime(mContext))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<List<CommentEntity>>() {
|
||||
@ -271,7 +273,6 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
mContext.getResources().getDisplayMetrics().widthPixels - DisplayUtils.dip2px(mContext, 34));
|
||||
}
|
||||
|
||||
// viewHolder.thumb.setImageURI(mConcernEntity.getGameIcon());
|
||||
ImageUtils.display(viewHolder.thumb, mConcernEntity.getGameIcon());
|
||||
viewHolder.title.setText(mConcernEntity.getGameName());
|
||||
NewsUtils.setNewsPublishOn(viewHolder.time, mConcernEntity.getTime());
|
||||
@ -369,11 +370,13 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (commentEntity.getParent() != null) {
|
||||
holder.commentContentTv.setText(StringUtils.buildString("回复", commentEntity.getParent().getUser().getName(),
|
||||
": ", commentEntity.getContent()));
|
||||
holder.commentContentTv.setText(commentEntity.getContent());
|
||||
if (commentEntity.getParent() != null && !TextUtils.isEmpty(commentEntity.getParent().getUser().getName())) {
|
||||
holder.quoteContainer.setVisibility(View.VISIBLE);
|
||||
holder.quoteAuthorTv.setText(String.format("@%s", commentEntity.getParent().getUser().getName()));
|
||||
holder.quoteContentTv.setText(commentEntity.getParent().getComment());
|
||||
} else {
|
||||
holder.commentContentTv.setText(commentEntity.getContent());
|
||||
holder.quoteContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
CommentUtils.setCommentUserView(mContext, holder, commentEntity);
|
||||
@ -416,8 +419,14 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
}
|
||||
});
|
||||
|
||||
holder.commentUserNameTv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, finalCommentEntity.getUser().getId(), "文章-评论详情"));
|
||||
holder.commentUserIconDv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, finalCommentEntity.getUser().getId(), "文章-评论详情"));
|
||||
holder.commentUserNameTv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, finalCommentEntity.getUser().getId(), mEntrance, "文章-评论详情"));
|
||||
holder.commentUserIconDv.setOnClickListener(v -> PersonalHomeActivity.startTargetActivity(mContext, finalCommentEntity.getUser().getId(), mEntrance, "文章-评论详情"));
|
||||
|
||||
if (commentEntity.getPriority() != 0) {
|
||||
holder.commentBadge.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.commentBadge.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void initFooterViewHolder(final FooterViewHolder viewHolder) {
|
||||
@ -536,12 +545,22 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
|
||||
// 往位置0添加评论
|
||||
public void addNormalComment(CommentEntity commentEntity) {
|
||||
mNormalCommentList.add(0, commentEntity);
|
||||
mNormalCommentList.add(findTheLastPriorComment(), commentEntity);
|
||||
}
|
||||
|
||||
public void addCommentCount() {
|
||||
mConcernEntity.setCommentnum(mConcernEntity.getCommentnum() + 1);
|
||||
notifyItemChanged(0);
|
||||
mConcernEntity.setCommentnum(mConcernEntity.getCommentnum());
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public int findTheLastPriorComment() {
|
||||
int lastPriorityPosition = 0;
|
||||
for (int i = 0; i < mNormalCommentList.size(); i++) {
|
||||
if (mNormalCommentList.get(i).getPriority() != 0) {
|
||||
lastPriorityPosition = i + 1;
|
||||
}
|
||||
}
|
||||
return lastPriorityPosition;
|
||||
}
|
||||
|
||||
public int getHotCommentListSize() {
|
||||
|
||||
@ -22,9 +22,9 @@ import com.gh.common.exposure.ExposureUtils;
|
||||
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.DisplayUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.download.DownloadManager;
|
||||
@ -34,8 +34,10 @@ import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.VoteActivity;
|
||||
import com.gh.gamecenter.adapter.viewholder.PlatformViewHolder;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.ApkLink;
|
||||
import com.gh.gamecenter.entity.CollectionCloseEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.PluginLocation;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
import com.halo.assistant.HaloApp;
|
||||
import com.lightgame.adapter.BaseRecyclerAdapter;
|
||||
@ -130,13 +132,14 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (viewHolder.mDownloadItemTvStatus.getVisibility() == View.GONE) {
|
||||
ApkLink apkLink = apkEntity.getApkLink();
|
||||
if (apkLink != null) {
|
||||
String entrance = mEntrance + "(" + apkLink.getName() + ")";
|
||||
DirectUtils.directToLinkPage(mContext, apkLink.getLinkEntity(), entrance, "下载多平台弹窗");
|
||||
} else if (viewHolder.mDownloadItemTvStatus.getVisibility() == View.GONE) {
|
||||
//下载游戏
|
||||
if (NetworkUtils.isWifiConnected(mContext)) {
|
||||
download(apkEntity, viewHolder.mDownloadItemTvStatus, "下载");
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(mContext, () -> download(apkEntity, viewHolder.mDownloadItemTvStatus, "下载"));
|
||||
}
|
||||
DialogUtils.checkDownload(mContext, apkEntity.getSize(),
|
||||
isSubscribe -> download(apkEntity, viewHolder.mDownloadItemTvStatus, "下载", isSubscribe));
|
||||
} else {
|
||||
String status = viewHolder.mDownloadItemTvStatus.getText().toString();
|
||||
switch (status) {
|
||||
@ -160,123 +163,42 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
install(apkEntity, viewHolder.getAdapterPosition());
|
||||
break;
|
||||
case "插件化":
|
||||
if (NetworkUtils.isWifiConnected(mContext)) {
|
||||
download(apkEntity, viewHolder.mDownloadItemTvStatus, "插件化");
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(mContext, () -> download(apkEntity, viewHolder.mDownloadItemTvStatus, "插件化"));
|
||||
}
|
||||
DialogUtils.checkDownload(mContext, apkEntity.getSize(),
|
||||
isSubscribe -> download(apkEntity, viewHolder.mDownloadItemTvStatus, "插件化", isSubscribe));
|
||||
break;
|
||||
case "安装插件":
|
||||
showPluginDialog(apkEntity, PlatformAdapter.this, viewHolder.getAdapterPosition());
|
||||
break;
|
||||
case "更新":
|
||||
if (NetworkUtils.isWifiConnected(mContext)) {
|
||||
update(apkEntity);
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(mContext, () -> update(apkEntity));
|
||||
}
|
||||
DialogUtils.checkDownload(mContext, apkEntity.getSize(), isSubscribe -> update(apkEntity, isSubscribe));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object gh_id = PackageUtils.getMetaData(mContext, apkEntity.getPackageName(), "gh_id");
|
||||
if (PackageManager.INSTANCE.isInstalled(apkEntity.getPackageName())
|
||||
&& (gh_id == null || gh_id.equals(mGameEntity.getId()))) {
|
||||
// 已安装
|
||||
viewHolder.mDownloadItemIvPic.setVisibility(View.GONE);
|
||||
ApkLink apkLink = apkEntity.getApkLink();
|
||||
if (apkLink != null) {
|
||||
viewHolder.mDownloadItemIvPic.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvHint.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemProgressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvName.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvStatus.setVisibility(View.VISIBLE);
|
||||
|
||||
int color = Color.parseColor(PlatformUtils.getInstance(mContext)
|
||||
.getPlatformColor(apkEntity.getPlatform()));
|
||||
viewHolder.itemView.setBackgroundDrawable(getGradientDrawable(color));
|
||||
|
||||
viewHolder.mDownloadItemTvName.setTextColor(color);
|
||||
viewHolder.mDownloadItemTvName.setText(PlatformUtils
|
||||
.getInstance(mContext).getPlatformName(apkEntity.getPlatform()));
|
||||
|
||||
viewHolder.mDownloadItemProgressbar.setProgressDrawable(getLayerDrawable(color));
|
||||
|
||||
DownloadEntity downloadEntity = mEntryMap.get(apkEntity.getUrl());
|
||||
if (downloadEntity == null) {
|
||||
viewHolder.mDownloadItemProgressbar.setProgress(1000);
|
||||
if (mGameEntity.getTag() != null && mGameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(mContext, apkEntity.getPackageName())) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.pluggable);
|
||||
downloadEntity = DownloadManager.getInstance(mContext).getDownloadEntityByPackageName(apkEntity.getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(apkEntity.getUrl())) {
|
||||
viewHolder.itemView.setClickable(true);
|
||||
viewHolder.mDownloadItemProgressbar.setProgress(1000);
|
||||
} else {
|
||||
viewHolder.itemView.setClickable(false);
|
||||
viewHolder.mDownloadItemProgressbar.setProgress(0);
|
||||
}
|
||||
} else if (PackageManager.INSTANCE.isCanUpdate(mGameEntity.getId(), apkEntity.getPackageName())) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.update);
|
||||
} else {
|
||||
if (mOnCollectionCallBackListener == null) {
|
||||
viewHolder.mDownloadItemTvStatus.setText("已安装");
|
||||
} else {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.launch);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
viewHolder.mDownloadItemProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (downloadEntity.isPluggable()) {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText("安装插件");
|
||||
} else {
|
||||
viewHolder.mDownloadItemTvStatus.setText("插件化下载中");
|
||||
}
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText("安装更新");
|
||||
} else {
|
||||
viewHolder.mDownloadItemTvStatus.setText("更新下载中");
|
||||
}
|
||||
}
|
||||
}
|
||||
viewHolder.mDownloadItemTvName.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemTvStatus.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemProgressbar.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemTvHint.setText(apkLink.getName());
|
||||
ImageUtils.display(viewHolder.mDownloadItemIvPic, apkLink.getIcon());
|
||||
viewHolder.itemView.setBackgroundDrawable(new ColorDrawable(0));
|
||||
} else {
|
||||
// 未安装
|
||||
DownloadEntity downloadEntity = mEntryMap.get(apkEntity.getUrl());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.cancel)
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.hijack)
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.notfound)) {
|
||||
String path = PlatformUtils.getInstance(mContext)
|
||||
.getPlatformPicUrl(apkEntity.getPlatform());
|
||||
|
||||
viewHolder.mDownloadItemIvPic.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvHint.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvName.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvStatus.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemProgressbar.setVisibility(View.GONE);
|
||||
viewHolder.itemView.setBackgroundColor(0x00ffffff);
|
||||
viewHolder.mDownloadItemTvHint.setText(
|
||||
PlatformUtils.getInstance(mContext).getPlatformName(apkEntity.getPlatform()));
|
||||
|
||||
if (TextUtils.isEmpty(path)) {
|
||||
int id = PlatformUtils.getInstance(mContext).getPlatformPic(
|
||||
apkEntity.getPlatform());
|
||||
ImageUtils.display(viewHolder.mDownloadItemIvPic, id);
|
||||
} else {
|
||||
ImageUtils.displayIcon(viewHolder.mDownloadItemIvPic, path);
|
||||
}
|
||||
} else {
|
||||
Object gh_id = PackageUtils.getMetaData(mContext, apkEntity.getPackageName(), "gh_id");
|
||||
if (PackageManager.INSTANCE.isInstalled(apkEntity.getPackageName())
|
||||
&& (gh_id == null || gh_id.equals(mGameEntity.getId()))) {
|
||||
// 已安装
|
||||
viewHolder.mDownloadItemIvPic.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemTvHint.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemProgressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvName.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvStatus.setVisibility(View.VISIBLE);
|
||||
|
||||
int color = Color.parseColor(PlatformUtils.getInstance(
|
||||
mContext).getPlatformColor(apkEntity.getPlatform()));
|
||||
int color = Color.parseColor(PlatformUtils.getInstance(mContext)
|
||||
.getPlatformColor(apkEntity.getPlatform()));
|
||||
viewHolder.itemView.setBackgroundDrawable(getGradientDrawable(color));
|
||||
|
||||
viewHolder.mDownloadItemTvName.setTextColor(color);
|
||||
@ -284,17 +206,103 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
.getInstance(mContext).getPlatformName(apkEntity.getPlatform()));
|
||||
|
||||
viewHolder.mDownloadItemProgressbar.setProgressDrawable(getLayerDrawable(color));
|
||||
viewHolder.mDownloadItemProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status.equals(DownloadStatus.pause)
|
||||
|| status.equals(DownloadStatus.timeout)
|
||||
|| status.equals(DownloadStatus.neterror)
|
||||
|| status.equals(DownloadStatus.downloading)
|
||||
|| status.equals(DownloadStatus.waiting)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.downloading);
|
||||
} else if (status.equals(DownloadStatus.done)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.install);
|
||||
DownloadEntity downloadEntity = mEntryMap.get(apkEntity.getUrl());
|
||||
if (downloadEntity == null) {
|
||||
viewHolder.mDownloadItemProgressbar.setProgress(1000);
|
||||
if (mGameEntity.getTag() != null && mGameEntity.getTag().size() != 0
|
||||
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
|
||||
&& !PackageUtils.isSignature(mContext, apkEntity.getPackageName())
|
||||
&& apkEntity.isShowPlugin(PluginLocation.only_game)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.pluggable);
|
||||
downloadEntity = DownloadManager.getInstance(mContext).getDownloadEntityByPackageName(apkEntity.getPackageName());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getUrl().equals(apkEntity.getUrl())) {
|
||||
viewHolder.itemView.setClickable(true);
|
||||
viewHolder.mDownloadItemProgressbar.setProgress(1000);
|
||||
} else {
|
||||
viewHolder.itemView.setClickable(false);
|
||||
viewHolder.mDownloadItemProgressbar.setProgress(0);
|
||||
}
|
||||
} else if (PackageManager.INSTANCE.isCanUpdate(mGameEntity.getId(), apkEntity.getPackageName())) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.update);
|
||||
} else {
|
||||
if (mOnCollectionCallBackListener == null) {
|
||||
viewHolder.mDownloadItemTvStatus.setText("已安装");
|
||||
} else {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.launch);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
viewHolder.mDownloadItemProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
if (downloadEntity.isPluggable()) {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText("安装插件");
|
||||
} else {
|
||||
viewHolder.mDownloadItemTvStatus.setText("插件化下载中");
|
||||
}
|
||||
} else if (downloadEntity.isUpdate()) {
|
||||
if (downloadEntity.getStatus().equals(DownloadStatus.done)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText("安装更新");
|
||||
} else {
|
||||
viewHolder.mDownloadItemTvStatus.setText("更新下载中");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 未安装
|
||||
DownloadEntity downloadEntity = mEntryMap.get(apkEntity.getUrl());
|
||||
if (downloadEntity == null
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.cancel)
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.hijack)
|
||||
|| downloadEntity.getStatus().equals(DownloadStatus.notfound)) {
|
||||
String path = PlatformUtils.getInstance(mContext)
|
||||
.getPlatformPicUrl(apkEntity.getPlatform());
|
||||
|
||||
viewHolder.mDownloadItemIvPic.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvHint.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvName.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvStatus.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemProgressbar.setVisibility(View.GONE);
|
||||
viewHolder.itemView.setBackgroundColor(0x00ffffff);
|
||||
viewHolder.mDownloadItemTvHint.setText(
|
||||
PlatformUtils.getInstance(mContext).getPlatformName(apkEntity.getPlatform()));
|
||||
|
||||
if (TextUtils.isEmpty(path)) {
|
||||
int id = PlatformUtils.getInstance(mContext).getPlatformPic(
|
||||
apkEntity.getPlatform());
|
||||
ImageUtils.display(viewHolder.mDownloadItemIvPic, id);
|
||||
} else {
|
||||
ImageUtils.displayIcon(viewHolder.mDownloadItemIvPic, path);
|
||||
}
|
||||
} else {
|
||||
viewHolder.mDownloadItemIvPic.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemTvHint.setVisibility(View.GONE);
|
||||
viewHolder.mDownloadItemProgressbar.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvName.setVisibility(View.VISIBLE);
|
||||
viewHolder.mDownloadItemTvStatus.setVisibility(View.VISIBLE);
|
||||
|
||||
int color = Color.parseColor(PlatformUtils.getInstance(
|
||||
mContext).getPlatformColor(apkEntity.getPlatform()));
|
||||
viewHolder.itemView.setBackgroundDrawable(getGradientDrawable(color));
|
||||
|
||||
viewHolder.mDownloadItemTvName.setTextColor(color);
|
||||
viewHolder.mDownloadItemTvName.setText(PlatformUtils
|
||||
.getInstance(mContext).getPlatformName(apkEntity.getPlatform()));
|
||||
|
||||
viewHolder.mDownloadItemProgressbar.setProgressDrawable(getLayerDrawable(color));
|
||||
viewHolder.mDownloadItemProgressbar.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status.equals(DownloadStatus.pause)
|
||||
|| status.equals(DownloadStatus.timeout)
|
||||
|| status.equals(DownloadStatus.neterror)
|
||||
|| status.equals(DownloadStatus.downloading)
|
||||
|| status.equals(DownloadStatus.waiting)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.downloading);
|
||||
} else if (status.equals(DownloadStatus.done)) {
|
||||
viewHolder.mDownloadItemTvStatus.setText(R.string.install);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -353,13 +361,13 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
}
|
||||
|
||||
// 下载游戏
|
||||
public void download(ApkEntity apkEntity, TextView mDownloadItemTvStatus, String method) {
|
||||
public void download(ApkEntity apkEntity, TextView mDownloadItemTvStatus, String method, boolean isSubscribe) {
|
||||
String msg = FileUtils.isCanDownload(mContext, apkEntity.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
String platform = PlatformUtils.getInstance(HaloApp.getInstance().getApplication()).getPlatformName(apkEntity.getPlatform());
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("游戏", mGameEntity.getName() + "-" + platform);
|
||||
kv.put("游戏", mGameEntity.getName() + ":" + platform);
|
||||
kv.put("用户机型", Build.MODEL);
|
||||
kv.put("设备IMEI", Util_System_Phone_State.getDeviceId(HaloApp.getInstance().getApplication()));
|
||||
kv.put("网络状态", DeviceUtils.getNetwork(HaloApp.getInstance().getApplication()));
|
||||
@ -371,11 +379,11 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
DataUtils.onEvent(mContext, "游戏下载", mGameEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("版本", apkEntity.getPlatform());
|
||||
kv2.put("版本", apkEntity.getPlatform() + "-开始");
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", mEntrance + "-开始");
|
||||
kv2.put("游戏分平台", mGameEntity.getName() + "-" + platform);
|
||||
kv2.put("光环助手版本", BuildConfig.VERSION_NAME);
|
||||
kv2.put("游戏分平台", mGameEntity.getName() + ":" + platform + "-开始");
|
||||
kv2.put("光环助手版本", BuildConfig.VERSION_NAME + "-开始");
|
||||
DataUtils.onEvent(mContext, "游戏下载位置", mGameEntity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
@ -392,7 +400,7 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
|
||||
ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(mGameEntity, apkEntity.getPlatform(), mTraceEvent, ExposureUtils.DownloadType.PLUGIN_DOWNLOAD);
|
||||
|
||||
DownloadManager.createDownload(mContext, apkEntity, mGameEntity, method, mEntrance, mLocation, downloadExposureEvent);
|
||||
DownloadManager.createDownload(mContext, apkEntity, mGameEntity, method, mEntrance, mLocation, isSubscribe, downloadExposureEvent);
|
||||
// DownloadManager.getInstance(mContext).putStatus(apkEntity.getUrl(), "downloading");
|
||||
|
||||
mDownloadItemTvStatus.setText("0.0%");
|
||||
@ -462,7 +470,7 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
}
|
||||
|
||||
// 下载可更新游戏
|
||||
private void update(ApkEntity apkEntity) {
|
||||
private void update(ApkEntity apkEntity, boolean isSubscribe) {
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", apkEntity.getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
@ -470,7 +478,7 @@ public class PlatformAdapter extends BaseRecyclerAdapter<PlatformViewHolder> {
|
||||
|
||||
ExposureEvent downloadExposureEvent = ExposureUtils.logADownloadExposureEvent(mGameEntity, apkEntity.getPlatform(), mTraceEvent, ExposureUtils.DownloadType.PLUGIN_UPDATE);
|
||||
|
||||
DownloadManager.createDownload(mContext, apkEntity, mGameEntity, "更新", mEntrance, mLocation, downloadExposureEvent);
|
||||
DownloadManager.createDownload(mContext, apkEntity, mGameEntity, "更新", mEntrance, mLocation, isSubscribe, downloadExposureEvent);
|
||||
}
|
||||
|
||||
private GradientDrawable getGradientDrawable(int color) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -33,6 +34,15 @@ public class CommentViewHolder extends BaseRecyclerViewHolder {
|
||||
public TextView commentUserNameTv;
|
||||
@BindView(R.id.comment_line_bottom)
|
||||
public View commentLineBottom;
|
||||
@BindView(R.id.comment_badge)
|
||||
public View commentBadge;
|
||||
|
||||
@BindView(R.id.comment_quote_container)
|
||||
public ViewGroup quoteContainer;
|
||||
@BindView(R.id.comment_quote_author_tv)
|
||||
public TextView quoteAuthorTv;
|
||||
@BindView(R.id.comment_quote_content_tv)
|
||||
public TextView quoteContentTv;
|
||||
|
||||
public CommentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
@ -10,7 +10,6 @@ import com.gh.common.exposure.ExposureEvent;
|
||||
import com.gh.common.exposure.ExposureUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.StringUtils;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
@ -84,6 +83,7 @@ public class DetailViewHolder {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 这个 switch 纯粹是为了 MTA 统计用的
|
||||
switch (mViewHolder.mDownloadPb.getDownloadType()) {
|
||||
case DOWNLOADING_PLUGIN:
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "插件化中", mGameEntity.getName());
|
||||
@ -100,9 +100,6 @@ public class DetailViewHolder {
|
||||
case PLUGIN:
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "插件化", mGameEntity.getName());
|
||||
break;
|
||||
case LAUNCH_OR_OPEN:
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "启动", mGameEntity.getName());
|
||||
break;
|
||||
case INSTALL_PLUGIN:
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "安装插件化", mGameEntity.getName());
|
||||
break;
|
||||
@ -110,6 +107,15 @@ public class DetailViewHolder {
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "安装", mGameEntity.getName());
|
||||
break;
|
||||
}
|
||||
// 由于部分状态不包含在 downloadType 里,所以还是需要手动获取下载按钮文字判断点击时的状态
|
||||
String downloadText = mViewHolder.mDownloadPb.getText();
|
||||
if (downloadText.contains("打开")) {
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "打开", mGameEntity.getName());
|
||||
} else if (downloadText.contains("启动")) {
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "启动", mGameEntity.getName());
|
||||
} else if (downloadText.contains("更新")) {
|
||||
DataUtils.onMtaEvent(HaloApp.getInstance().getApplication(), "游戏详情", "更新", mGameEntity.getName());
|
||||
}
|
||||
|
||||
switch (mViewHolder.mDownloadPb.getDownloadType()) {
|
||||
case DOWNLOADING_PLUGIN:
|
||||
@ -125,11 +131,7 @@ public class DetailViewHolder {
|
||||
case NORMAL:
|
||||
case PLUGIN:
|
||||
if (mGameEntity.getApk().size() == 1) {
|
||||
if (NetworkUtils.isWifiConnected(mViewHolder.context)) {
|
||||
download();
|
||||
} else {
|
||||
DialogUtils.showDownloadDialog(mViewHolder.context, this::download);
|
||||
}
|
||||
DialogUtils.checkDownload(mViewHolder.context, mGameEntity.getApk().get(0).getSize(), this::download);
|
||||
} else {
|
||||
DownloadDialog.getInstance(mViewHolder.context).showPopupWindow(v, mGameEntity,
|
||||
StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"), mName + ":" + mTitle, mTraceEvent);
|
||||
@ -156,7 +158,7 @@ public class DetailViewHolder {
|
||||
}
|
||||
}
|
||||
|
||||
private void download() {
|
||||
private void download(boolean isSubscribe) {
|
||||
String str = mViewHolder.mDownloadPb.getText();
|
||||
String method;
|
||||
if (str.contains("更新")) {
|
||||
@ -182,6 +184,7 @@ public class DetailViewHolder {
|
||||
method,
|
||||
StringUtils.buildString(mEntrance, "+(", mName, "[", mTitle, "])"),
|
||||
mName + ":" + mTitle,
|
||||
isSubscribe,
|
||||
downloadExposureEvent);
|
||||
|
||||
mViewHolder.mDownloadPb.setProgress(0);
|
||||
|
||||
@ -2,6 +2,8 @@ package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
@ -18,6 +20,10 @@ public class GameDetailIntroViewHolder extends BaseRecyclerViewHolder {
|
||||
public RecyclerView introGallery;
|
||||
@BindView(R.id.gamedetail_item_intro_content)
|
||||
public TextView introContent;
|
||||
@BindView(R.id.gamedetail_item_intro_expand_rl)
|
||||
public RelativeLayout expandRl;
|
||||
@BindView(R.id.gamedetail_item_intro_expand_iv)
|
||||
public ImageView expandIv;
|
||||
|
||||
public GameDetailIntroViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
@ -2,6 +2,7 @@ package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
@ -22,6 +23,8 @@ public class GameDetailPluginViewHolder extends BaseRecyclerViewHolder {
|
||||
public View gamedetailPluginLine;
|
||||
@BindView(R.id.gamedetail_plugin_title)
|
||||
public TextView gamedetailPluginTitle;
|
||||
@BindView(R.id.gamedetail_plugin_expand_iv)
|
||||
public ImageView gamedetailPluginExpandIv;
|
||||
|
||||
public GameDetailPluginViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/8.
|
||||
*/
|
||||
public class GameDetailTopViewHolder extends BaseRecyclerViewHolder {
|
||||
|
||||
@BindView(R.id.gamedetail_iv_thumb)
|
||||
public SimpleDraweeView gamedetailThumb;
|
||||
@BindView(R.id.gamedetail_tv_name)
|
||||
public TextView gamedetailName;
|
||||
@BindView(R.id.gamedetail_tv_info)
|
||||
public TextView gamedetailInfo;
|
||||
@BindView(R.id.gamedetail_tv_concern)
|
||||
public TextView gamedetailConcern;
|
||||
|
||||
public GameDetailTopViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/8.
|
||||
*/
|
||||
public class GameGalleryViewHolder extends BaseRecyclerViewHolder {
|
||||
|
||||
@BindView(R.id.screenshot_item_iv)
|
||||
public SimpleDraweeView screenshotIv;
|
||||
|
||||
public GameGalleryViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.gh.gamecenter.adapter.viewholder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.base.BaseRecyclerViewHolder;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/9/8.
|
||||
*/
|
||||
public class NewsDetailGameViewHolder extends BaseRecyclerViewHolder {
|
||||
|
||||
@BindView(R.id.game_iv_thumb)
|
||||
public SimpleDraweeView gameThumb;
|
||||
@BindView(R.id.game_tv_name)
|
||||
public TextView gameName;
|
||||
@BindView(R.id.game_tv_info)
|
||||
public TextView gameInfo;
|
||||
@BindView(R.id.game_tv_concern)
|
||||
public TextView gameConcern;
|
||||
@BindView(R.id.game_iv_libao)
|
||||
public View libaoIcon;
|
||||
@BindView(R.id.game_server_type)
|
||||
public TextView gameServerType;
|
||||
|
||||
public NewsDetailGameViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
}
|
||||
@ -111,7 +111,8 @@ public abstract class ListFragment<T, VM extends BaseListViewModel /* 该泛型
|
||||
|
||||
if (isAutomaticLoad()) mListViewModel.load(LoadType.NORMAL);
|
||||
|
||||
mListRv.addItemDecoration(getItemDecoration());
|
||||
RecyclerView.ItemDecoration itemDecoration = getItemDecoration();
|
||||
if (itemDecoration != null) mListRv.addItemDecoration(itemDecoration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,7 +124,7 @@ public abstract class ListFragment<T, VM extends BaseListViewModel /* 该泛型
|
||||
mListRefresh.setOnRefreshListener(this);
|
||||
}
|
||||
mLayoutManager = new LinearLayoutManager(getContext());
|
||||
((DefaultItemAnimator)mListRv.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
((DefaultItemAnimator) mListRv.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||
mListRv.setLayoutManager(mLayoutManager);
|
||||
mListRv.setAdapter(provideListAdapter());
|
||||
mListRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
|
||||
@ -52,7 +52,7 @@ class CategoryDirectoryAdapter(context: Context, var categoryTitle: String) : Li
|
||||
binding.containerUnexpandable.removeAllViews()
|
||||
val unexpandableSize = if (it.size > 6) 6 else it.size
|
||||
val unexpandableCategoryList = it.subList(0, unexpandableSize)
|
||||
unexpandableCategoryList.forEachIndexed({ index, c ->
|
||||
unexpandableCategoryList.forEachIndexed { index, c ->
|
||||
when (index % 3) {
|
||||
0 -> {
|
||||
val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)
|
||||
@ -70,7 +70,7 @@ class CategoryDirectoryAdapter(context: Context, var categoryTitle: String) : Li
|
||||
1 -> subCategoryView?.setCenterCategory(c)
|
||||
2 -> subCategoryView?.setRightCategory(c)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (it.size > 7) {
|
||||
val extraCategoryList = it.subList(6, it.size)
|
||||
@ -102,7 +102,7 @@ class CategoryDirectoryAdapter(context: Context, var categoryTitle: String) : Li
|
||||
}
|
||||
}
|
||||
|
||||
extraCategoryList.forEachIndexed({ index, c ->
|
||||
extraCategoryList.forEachIndexed { index, c ->
|
||||
when (index % 3) {
|
||||
0 -> {
|
||||
subCategoryView = SubCategoryView(binding.root.context)
|
||||
@ -120,7 +120,7 @@ class CategoryDirectoryAdapter(context: Context, var categoryTitle: String) : Li
|
||||
1 -> subCategoryView?.setCenterCategory(c)
|
||||
2 -> subCategoryView?.setRightCategory(c)
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
binding.ivToggle.visibility = View.GONE
|
||||
binding.containerExpandable.removeAllViews()
|
||||
|
||||
@ -17,8 +17,6 @@ import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.eventbus.*
|
||||
import com.gh.gamecenter.info.InfoToolWrapperFragment
|
||||
import com.gh.gamecenter.subject.SubjectListFragment
|
||||
import com.gh.gamecenter.subject.SubjectTileFragment
|
||||
import com.lightgame.OnTitleClickListener
|
||||
import com.lightgame.download.DataWatcher
|
||||
import com.lightgame.download.DownloadEntity
|
||||
@ -54,6 +52,11 @@ class CategoryListFragment : BaseFragment<String>(), OnTitleClickListener {
|
||||
|
||||
private var page = 1
|
||||
|
||||
companion object {
|
||||
const val OPEN_APPBAR = "openAppBar"
|
||||
const val KEY_LISTORDER = "listOrder"
|
||||
}
|
||||
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private val dataWatcher = object : DataWatcher() {
|
||||
override fun onDataChanged(downloadEntity: DownloadEntity) {
|
||||
@ -70,11 +73,6 @@ class CategoryListFragment : BaseFragment<String>(), OnTitleClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
fun newInstance(bundle: Bundle): SubjectListFragment {
|
||||
val fragment = SubjectListFragment()
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int {
|
||||
return R.layout.fragment_subject
|
||||
@ -87,7 +85,7 @@ class CategoryListFragment : BaseFragment<String>(), OnTitleClickListener {
|
||||
mName = arguments?.getString(EntranceUtils.KEY_NAME)
|
||||
mIsOrder = arguments?.getBoolean(EntranceUtils.KEY_ORDER)!!
|
||||
mType = arguments.getString(EntranceUtils.KEY_TYPE)
|
||||
mListOrder = arguments.getString(SubjectTileFragment.KEY_LISTORDER)
|
||||
mListOrder = arguments.getString(CategoryListFragment.KEY_LISTORDER)
|
||||
mTagType = arguments.getString(EntranceUtils.KEY_TAGTYPE)
|
||||
mEntrance = arguments.getString(EntranceUtils.KEY_ENTRANCE)
|
||||
mTitle = arguments.getString(EntranceUtils.KEY_CATEGORY_TITLE)
|
||||
@ -119,7 +117,7 @@ class CategoryListFragment : BaseFragment<String>(), OnTitleClickListener {
|
||||
val position = mLayoutManager!!.findFirstCompletelyVisibleItemPosition()
|
||||
if (mScrollTop && position == 0 && newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
mScrollTop = false
|
||||
EventBus.getDefault().post(EBReuse(SubjectTileFragment.OPEN_APPBAR))
|
||||
EventBus.getDefault().post(EBReuse(CategoryListFragment.OPEN_APPBAR))
|
||||
}
|
||||
|
||||
if (!mCategoryAdapter!!.isRemove && mCategoryAdapter!!.isLoaded && newState == RecyclerView.SCROLL_STATE_IDLE
|
||||
@ -132,7 +130,7 @@ class CategoryListFragment : BaseFragment<String>(), OnTitleClickListener {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
val position = mLayoutManager!!.findFirstCompletelyVisibleItemPosition()
|
||||
if (position == 0 && Math.abs(dy) > 10) {
|
||||
EventBus.getDefault().post(EBReuse(SubjectTileFragment.OPEN_APPBAR))
|
||||
EventBus.getDefault().post(EBReuse(CategoryListFragment.OPEN_APPBAR))
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -252,7 +250,7 @@ class CategoryListFragment : BaseFragment<String>(), OnTitleClickListener {
|
||||
|
||||
override fun onTitleClick() {
|
||||
if (mLayoutManager!!.findFirstCompletelyVisibleItemPosition() == 0 || mCategoryAdapter!!.itemCount == 0) {
|
||||
EventBus.getDefault().post(EBReuse(SubjectTileFragment.OPEN_APPBAR))
|
||||
EventBus.getDefault().post(EBReuse(CategoryListFragment.OPEN_APPBAR))
|
||||
} else {
|
||||
mLayoutManager!!.smoothScrollToPosition(mRvSubject, null, 0)
|
||||
mScrollTop = true
|
||||
|
||||
@ -21,9 +21,12 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> {
|
||||
|
||||
private OnListClickListener mListClickListener;
|
||||
|
||||
public AnswerAdapter(Context context, OnListClickListener listClickListener) {
|
||||
private String mEntrance;
|
||||
|
||||
public AnswerAdapter(Context context, OnListClickListener listClickListener, String entrance) {
|
||||
super(context);
|
||||
mListClickListener = listClickListener;
|
||||
mEntrance = entrance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,7 +54,7 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> {
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
switch (getItemViewType(position)) {
|
||||
case ItemViewType.ITEM_BODY:
|
||||
((AnswerViewHolder) holder).initCollectionAnswerViewHolder(mEntityList.get(position));
|
||||
((AnswerViewHolder) holder).initCollectionAnswerViewHolder(mEntityList.get(position), mEntrance);
|
||||
break;
|
||||
case ItemViewType.ITEM_FOOTER:
|
||||
FooterViewHolder footerViewHolder = (FooterViewHolder) holder;
|
||||
|
||||
@ -2,7 +2,6 @@ package com.gh.gamecenter.collection;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.gh.common.util.LogUtils;
|
||||
import com.gh.common.util.CollectionUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.gamecenter.R;
|
||||
@ -10,6 +9,7 @@ import com.gh.gamecenter.baselist.ListAdapter;
|
||||
import com.gh.gamecenter.baselist.ListFragment;
|
||||
import com.gh.gamecenter.baselist.LoadType;
|
||||
import com.gh.gamecenter.baselist.NormalListViewModel;
|
||||
import com.gh.gamecenter.eventbus.EBCollectionChanged;
|
||||
import com.gh.gamecenter.manager.UserManager;
|
||||
import com.gh.gamecenter.qa.answer.detail.AnswerDetailActivity;
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity;
|
||||
@ -17,6 +17,9 @@ import com.gh.gamecenter.qa.entity.Questions;
|
||||
import com.gh.gamecenter.qa.questions.detail.QuestionsDetailActivity;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
@ -31,7 +34,7 @@ public class AnswerFragment extends ListFragment<AnswerEntity, NormalListViewMod
|
||||
|
||||
@Override
|
||||
protected ListAdapter provideListAdapter() {
|
||||
return mAdapter == null ? mAdapter = new AnswerAdapter(getContext(), this) : mAdapter;
|
||||
return mAdapter == null ? mAdapter = new AnswerAdapter(getContext(), this, mEntrance) : mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,7 +45,6 @@ public class AnswerFragment extends ListFragment<AnswerEntity, NormalListViewMod
|
||||
@Override
|
||||
public void onListClick(View view, int position, Object data) {
|
||||
AnswerEntity entity;
|
||||
String tracers = mEntrance + "+(回答)";
|
||||
switch (view.getId()) {
|
||||
case R.id.footerview_item:
|
||||
if (mAdapter.isNetworkError()) {
|
||||
@ -53,7 +55,7 @@ public class AnswerFragment extends ListFragment<AnswerEntity, NormalListViewMod
|
||||
case R.id.ask_answer_item_content:
|
||||
entity = (AnswerEntity) data;
|
||||
if (entity.getActive()) {
|
||||
startActivity(AnswerDetailActivity.getIntent(getContext(), entity.getId(), tracers, "我的收藏-回答"));
|
||||
startActivity(AnswerDetailActivity.getIntent(getContext(), entity.getId(), mEntrance, "我的收藏-回答"));
|
||||
} else {
|
||||
showDeleteDialog(entity.getId());
|
||||
}
|
||||
@ -61,8 +63,7 @@ public class AnswerFragment extends ListFragment<AnswerEntity, NormalListViewMod
|
||||
case R.id.ask_answer_item_title:
|
||||
entity = (AnswerEntity) data;
|
||||
Questions questions = entity.getQuestions();
|
||||
startActivity(QuestionsDetailActivity.getIntent(getContext(), questions.getId(), tracers, "我的收藏-回答"));
|
||||
LogUtils.uploadQuestions(getContext(), tracers, questions);
|
||||
startActivity(QuestionsDetailActivity.getIntent(getContext(), questions.getId(), mEntrance, "我的收藏-回答"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -86,4 +87,12 @@ public class AnswerFragment extends ListFragment<AnswerEntity, NormalListViewMod
|
||||
}
|
||||
}), null);
|
||||
}
|
||||
|
||||
// 收藏事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBCollectionChanged changed) {
|
||||
if (changed.getCollectionType().equals(CollectionUtils.CollectionType.answer)) {
|
||||
mListViewModel.load(LoadType.REFRESH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
package com.gh.gamecenter.collection
|
||||
|
||||
import com.gh.base.BaseRecyclerViewHolder
|
||||
import com.gh.gamecenter.databinding.CollectionComunityArticleItemBinding
|
||||
|
||||
class CollectionCommunityArticleViewHolder(val binding: CollectionComunityArticleItemBinding):BaseRecyclerViewHolder<Any>(binding.root)
|
||||
@ -30,15 +30,20 @@ public class CollectionWrapperFragment extends BaseFragment_TabLayout {
|
||||
@Override
|
||||
protected void initTabTitleList(List<String> tabTitleList) {
|
||||
tabTitleList.add(getString(R.string.answer));
|
||||
tabTitleList.add(getString(R.string.collection_toolkit));
|
||||
tabTitleList.add(getString(R.string.collection_article));
|
||||
tabTitleList.add(getString(R.string.collection_toolkit));
|
||||
tabTitleList.add(getString(R.string.collection_info));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initFragmentList(List<Fragment> fragments) {
|
||||
fragments.add(new AnswerFragment());
|
||||
fragments.add(new CommunityArticleFragment());
|
||||
fragments.add(new ToolsFragment());
|
||||
fragments.add(new ArticleFragment());
|
||||
for (Fragment fragment : mFragmentsList) {
|
||||
fragment.setArguments(getArguments());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
package com.gh.gamecenter.collection
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Paint
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.gh.common.constant.ItemViewType
|
||||
import com.gh.common.util.DialogUtils
|
||||
import com.gh.gamecenter.PersonalHomeActivity
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
|
||||
import com.gh.gamecenter.baselist.ListAdapter
|
||||
import com.gh.gamecenter.databinding.CollectionComunityArticleItemBinding
|
||||
import com.gh.gamecenter.qa.article.detail.ArticleDetailActivity
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
|
||||
class CommunityArticleAdapter(context: Context,
|
||||
private val mViewModel: CommunityArticleViewModel,
|
||||
private val mEntrance: String) : ListAdapter<ArticleEntity>(context) {
|
||||
|
||||
override fun areItemsTheSame(oldItem: ArticleEntity?, newItem: ArticleEntity?): Boolean {
|
||||
return oldItem?.id == newItem?.id
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
if (position == itemCount - 1) return ItemViewType.ITEM_FOOTER
|
||||
return ItemViewType.ITEM_BODY
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val view: View
|
||||
return when (viewType) {
|
||||
ItemViewType.ITEM_FOOTER -> {
|
||||
view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false)
|
||||
FooterViewHolder(view)
|
||||
}
|
||||
else -> {
|
||||
view = mLayoutInflater.inflate(R.layout.collection_comunity_article_item, parent, false)
|
||||
CollectionCommunityArticleViewHolder(CollectionComunityArticleItemBinding.bind(view))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = if (mEntityList.size == 0) 0 else mEntityList.size + 1
|
||||
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (holder is CollectionCommunityArticleViewHolder) {
|
||||
val path = "我的收藏-文章"
|
||||
val entity = mEntityList[position]
|
||||
holder.binding.data = entity
|
||||
|
||||
if (entity.active) {
|
||||
holder.binding.content.paint.flags = Paint.ANTI_ALIAS_FLAG
|
||||
holder.binding.content.setTextColor(ContextCompat.getColor(mContext, R.color.title))
|
||||
} else {
|
||||
holder.binding.content.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
|
||||
holder.binding.content.setTextColor(ContextCompat.getColor(mContext, R.color.hint))
|
||||
}
|
||||
holder.itemView.setOnClickListener {
|
||||
if (entity.active) {
|
||||
mContext.startActivity(ArticleDetailActivity.getIntent(mContext, entity.community, entity.id, mEntrance, path))
|
||||
} else {
|
||||
DialogUtils.showCancelAlertDialog(mContext, "提示", "内容已被删除,是否取消收藏?", "取消收藏", "暂不", {
|
||||
mViewModel.deleteCollection(entity.community.id, entity.id)
|
||||
}, null)
|
||||
}
|
||||
}
|
||||
holder.binding.userIconContainer.setOnClickListener {
|
||||
PersonalHomeActivity.startTargetActivity(mContext, entity.user.id, mEntrance, path)
|
||||
}
|
||||
|
||||
holder.binding.userName.setOnClickListener {
|
||||
PersonalHomeActivity.startTargetActivity(mContext, entity.user.id, mEntrance, path)
|
||||
}
|
||||
} else if (holder is FooterViewHolder) {
|
||||
holder.initItemPadding()
|
||||
holder.initFooterViewHolder(mViewModel, mIsLoading, isNetworkError, mIsOver)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package com.gh.gamecenter.collection
|
||||
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import com.gh.common.util.CollectionUtils
|
||||
import com.gh.gamecenter.baselist.ListFragment
|
||||
import com.gh.gamecenter.baselist.LoadType
|
||||
import com.gh.gamecenter.eventbus.EBCollectionChanged
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import io.reactivex.Observable
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
class CommunityArticleFragment : ListFragment<ArticleEntity, CommunityArticleViewModel>() {
|
||||
|
||||
var mAdapter: CommunityArticleAdapter? = null
|
||||
|
||||
override fun provideListAdapter(): CommunityArticleAdapter {
|
||||
if (mAdapter == null) {
|
||||
mAdapter = CommunityArticleAdapter(context!!, mListViewModel, mEntrance)
|
||||
}
|
||||
return mAdapter!!
|
||||
}
|
||||
|
||||
override fun provideListViewModel(): CommunityArticleViewModel {
|
||||
return ViewModelProviders.of(this).get(CommunityArticleViewModel::class.java)
|
||||
}
|
||||
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<ArticleEntity>> {
|
||||
return RetrofitManager.getInstance(context).api.getCollectionCommunityArticle(UserManager.getInstance().userId, page)
|
||||
}
|
||||
|
||||
// 收藏事件
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onEventMainThread(changed: EBCollectionChanged) {
|
||||
if (changed.collectionType == CollectionUtils.CollectionType.communityArticle) {
|
||||
mListViewModel.load(LoadType.REFRESH)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.gh.gamecenter.collection
|
||||
|
||||
import android.app.Application
|
||||
import anet.channel.util.Utils.context
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.baselist.ListViewModel
|
||||
import com.gh.gamecenter.manager.UserManager
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.lightgame.utils.Utils
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.HttpException
|
||||
|
||||
|
||||
class CommunityArticleViewModel(application: Application) : ListViewModel<ArticleEntity, ArticleEntity>(application) {
|
||||
|
||||
|
||||
override fun provideDataObservable(page: Int): Observable<MutableList<ArticleEntity>>? {
|
||||
return RetrofitManager.getInstance(context).api.getCollectionCommunityArticle(UserManager.getInstance().userId, page)
|
||||
}
|
||||
|
||||
override fun mergeResultLiveData() {
|
||||
mResultLiveData.addSource<List<ArticleEntity>>(mListLiveData) { mResultLiveData.postValue(it) }
|
||||
}
|
||||
|
||||
|
||||
fun deleteCollection(communityId: String, articleId: String) {
|
||||
RetrofitManager.getInstance(getApplication()).api
|
||||
.deleteCommunityArticleFavorites(UserManager.getInstance().userId, communityId, articleId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onResponse(response: ResponseBody?) {
|
||||
Utils.toast(getApplication(), R.string.collection_cancel)
|
||||
|
||||
val value = mResultLiveData.value
|
||||
if (value != null) {
|
||||
for (i in 0 until value.size) {
|
||||
val data = value[i]
|
||||
if (data.id == articleId) {
|
||||
value.remove(data)
|
||||
mResultLiveData.postValue(value)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(e: HttpException?) {
|
||||
Utils.toast(getApplication(), R.string.collection_cancel_failure)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user