重构专题页面相关逻辑

其他toolbar逻辑移除
This commit is contained in:
CsHeng
2017-12-19 11:20:47 +08:00
parent a705f0ec53
commit c2bc52e474
66 changed files with 1183 additions and 1209 deletions

View File

@ -2,12 +2,17 @@ package com.gh.base;
import android.os.Bundle;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.gh.gamecenter.R;
import com.lightgame.BaseAppCompatActivity;
import com.lightgame.OnTitleClickListener;
import java.util.List;
/**
* Created by csheng on 15-10-12.
@ -42,6 +47,17 @@ public abstract class BaseToolBarActivity extends BaseAppCompatActivity {
setSupportActionBar(mToolbar);
mToolbar.findViewById(R.id.actionbar_rl_back).setOnClickListener(v -> onBackPressed());
mTitleTv = findViewById(R.id.actionbar_tv_title);
mTitleTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final List<Fragment> fragmentList = getSupportFragmentManager().getFragments();
for (Fragment fragment : fragmentList) {
if (fragment instanceof OnTitleClickListener) {
((OnTitleClickListener) fragment).onTitleClick();
}
}
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);

View File

@ -15,6 +15,7 @@ import com.gh.base.BaseToolBarActivity;
import com.gh.base.OnListClickListener;
import com.gh.base.OnRequestCallBackListener;
import com.gh.gamecenter.eventbus.EBMiPush;
import com.lightgame.OnTitleClickListener;
import com.lightgame.utils.RuntimeUtils;
import com.lightgame.utils.Utils;
@ -37,7 +38,7 @@ import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE;
* Fragment 基类
*/
public abstract class BaseFragment<T> extends Fragment implements OnRequestCallBackListener<T>,
View.OnClickListener, OnListClickListener {
View.OnClickListener, OnListClickListener, OnTitleClickListener {
protected View mCachedView;
@ -186,9 +187,17 @@ public abstract class BaseFragment<T> extends Fragment implements OnRequestCallB
// 将所有的Fragment都置为隐藏状态。
protected void hideFragments(FragmentTransaction transaction) {
List<Fragment> list = getChildFragmentManager().getFragments();
if (list != null) {
for (Fragment fragment : list) {
transaction.hide(fragment);
for (Fragment fragment : list) {
transaction.hide(fragment);
}
}
@Override
public void onTitleClick() {
List<Fragment> list = getChildFragmentManager().getFragments();
for (Fragment fragment : list) {
if (fragment instanceof OnTitleClickListener) {
((OnTitleClickListener) fragment).onTitleClick();
}
}
}

View File

@ -6,7 +6,7 @@ import android.content.Intent;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.entity.CommentEntity;
import com.gh.gamecenter.entity.ConcernEntity;
import com.gh.gamecenter.message.CommentDetailFragment;
import com.gh.gamecenter.message.MessageDetailFragment;
import com.halo.assistant.ui.IntentFactory;
/**
@ -27,7 +27,7 @@ public class MessageDetailActivity extends CommonActivity {
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(MessageDetailActivity.class)
.setFragment(CommentDetailFragment.class).build();
.setFragment(MessageDetailFragment.class).build();
}
public static Intent getIntentByEntity(Context context, ConcernEntity concernEntity, String entrance) {
@ -38,7 +38,7 @@ public class MessageDetailActivity extends CommonActivity {
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(MessageDetailActivity.class)
.setFragment(CommentDetailFragment.class).build();
.setFragment(MessageDetailFragment.class).build();
}
public static Intent getIntentById(Context context, String newsId, Integer commentNum, Boolean openSoftInput, String entrance) {
@ -51,7 +51,7 @@ public class MessageDetailActivity extends CommonActivity {
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(MessageDetailActivity.class)
.setFragment(CommentDetailFragment.class).build();
.setFragment(MessageDetailFragment.class).build();
}
}

View File

@ -413,9 +413,9 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
mNewsCollection.setVisibility(View.VISIBLE);
NewsDetailEntity newsDetailEntity = adapter.getNewsDetailEntity();
if (newsDetailEntity.getUserData() != null && newsDetailEntity.getUserData().isArticleFavorite()) {
mNewsCollection.setImageResource(R.drawable.detail_collection_select);
mNewsCollection.setImageResource(R.drawable.menu_ic_collect_select);
} else {
mNewsCollection.setImageResource(R.drawable.detail_collection_unselect);
mNewsCollection.setImageResource(R.drawable.menu_ic_collect_unselect);
}
}
@ -582,7 +582,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
public void onSuccess() {
newsDetailEntity.getUserData().setArticleFavorite(false);
mNewsCollection.setEnabled(true);
mNewsCollection.setImageResource(R.drawable.detail_collection_unselect);
mNewsCollection.setImageResource(R.drawable.menu_ic_collect_unselect);
toast(getString(R.string.collection_cancel));
}
@ -608,7 +608,7 @@ public class NewsDetailActivity extends BaseActivity implements OnClickListener,
}
userData.setArticleFavorite(true);
mNewsCollection.setEnabled(true);
mNewsCollection.setImageResource(R.drawable.detail_collection_select);
mNewsCollection.setImageResource(R.drawable.menu_ic_collect_select);
toast(getString(R.string.collection_success));
}

View File

@ -1,216 +1,33 @@
package com.gh.gamecenter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gh.base.BaseActivity;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.adapter.VPFragmentAdapter;
import com.gh.gamecenter.entity.SubjectHeadEntity;
import com.gh.gamecenter.eventbus.EBReuse;
import com.gh.gamecenter.retrofit.JSONObjectResponse;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.gh.gamecenter.subject.OnSubjectTitleListener;
import com.gh.gamecenter.subject.SubjectFragment;
import com.gh.gamecenter.subject.SubjectTileFragment;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.HttpException;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import static com.gh.gamecenter.R.id.actionbar_tv_title;
import com.gh.gamecenter.subject.SubjectWrapperFragment;
import com.halo.assistant.ui.IntentFactory;
/**
* Created by khy on 2017/4/29.
*/
public class SubjectActivity extends BaseActivity implements OnSubjectTitleListener {
@BindView(R.id.subject_viewpager)
ViewPager mViewPager;
@BindView(R.id.subject_tab)
TabLayout mTabLayout;
@BindView(R.id.reuse_ll_loading)
LinearLayout mLoading;
@BindView(R.id.subject_tiled)
FrameLayout mSubjectTiled;
@BindView(R.id.reuse_no_connection)
View mNoConn;
@BindView(R.id.actionbar_tv_title)
TextView mActionBarTitle;
private String mId;
private String mName;
private Bundle mBundle;
private SubjectTileFragment mTileFragment;
@Deprecated
public class SubjectActivity extends CommonActivity {
/**
* 启动专题页面
*/
public static void startSubjectActivity(Context context, String id, String name, boolean isOrder, String entrance) {
Intent intent = new Intent(context, SubjectActivity.class);
intent.putExtra(EntranceUtils.KEY_ID, id);
intent.putExtra(EntranceUtils.KEY_NAME, name);
intent.putExtra(EntranceUtils.KEY_ORDER, isOrder);
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
context.startActivity(intent);
Bundle args = new Bundle();
args.putString(EntranceUtils.KEY_ID, id);
args.putString(EntranceUtils.KEY_NAME, name);
args.putBoolean(EntranceUtils.KEY_ORDER, isOrder);
args.putString(EntranceUtils.KEY_ENTRANCE, entrance);
new IntentFactory.Builder(context)
.setArgs(args)
.setActivity(SubjectActivity.class)
.setFragment(SubjectWrapperFragment.class).start();
}
@Override
protected int getLayoutId() {
return R.layout.activity_subject;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBundle = getIntent().getExtras();
if (getIntent().getBundleExtra(EntranceUtils.KEY_DATA) != null) {
mBundle = getIntent().getBundleExtra(EntranceUtils.KEY_DATA);
}
mId = mBundle.getString(EntranceUtils.KEY_ID);
mName = mBundle.getString(EntranceUtils.KEY_NAME);
setNavigationTitle(mName);
if (TextUtils.isEmpty(mName) && !TextUtils.isEmpty(mId)) {
getSubjectName(mId);
} else {
loadSubjectType();
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mTileFragment != null) mTileFragment.onTouchEvent(ev);
return super.dispatchTouchEvent(ev);
}
@OnClick({actionbar_tv_title, R.id.reuse_no_connection})
public void onClick(View view) {
switch (view.getId()) {
case actionbar_tv_title:
if (mTileFragment != null)
EventBus.getDefault().post(new EBReuse(SubjectFragment.SCROLL_TOP));
break;
case R.id.reuse_no_connection:
mNoConn.setVisibility(View.GONE);
mLoading.setVisibility(View.VISIBLE);
loadSubjectType();
break;
}
}
private void getSubjectName(String id) {
RetrofitManager.getInstance(this).getApi()
.getSubjectName(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new JSONObjectResponse() {
@Override
public void onResponse(JSONObject response) {
try {
String name = response.getString("name");
mActionBarTitle.setText(name);
mBundle.putString(EntranceUtils.KEY_NAME, name);
loadSubjectType();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(HttpException e) {
super.onFailure(e);
mActionBarTitle.setText("专题");
mBundle.putString(EntranceUtils.KEY_NAME, "专题");
loadSubjectType();
}
});
}
private void loadSubjectType() {
RetrofitManager.getInstance(this).getApi()
.getColumnSettings(mId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<SubjectHeadEntity>() {
@Override
public void onResponse(SubjectHeadEntity response) {
super.onResponse(response);
mLoading.setVisibility(View.GONE);
List<String> content = response.getTypeEntity().getContent();
content.add(0, "全部");
initView(response);
}
@Override
public void onFailure(HttpException e) {
super.onFailure(e);
mLoading.setVisibility(View.GONE);
mNoConn.setVisibility(View.VISIBLE);
}
});
}
private void initView(SubjectHeadEntity headEntity) {
if ("tile".equals(headEntity.getTypeEntity().getLayout())) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Bundle clone = (Bundle) mBundle.clone();
clone.putString(EntranceUtils.KEY_TAGTYPE, headEntity.getTag());
clone.putStringArrayList("contentTitle", new ArrayList<>(headEntity.getTypeEntity().getContent()));
mTileFragment = new SubjectTileFragment();
mTileFragment.setArguments(clone);
transaction.add(R.id.subject_tiled, mTileFragment);
transaction.commit();
} else {
List<String> tag = headEntity.getTypeEntity().getContent();
if (tag.size() > 1) {
mTabLayout.setVisibility(View.VISIBLE);
}
List<Fragment> fragments = new ArrayList<>();
for (String s : tag) {
mTabLayout.addTab(mTabLayout.newTab().setText(s));
Bundle clone = (Bundle) mBundle.clone();
clone.putString(EntranceUtils.KEY_TYPE, s);
clone.putString(EntranceUtils.KEY_TAGTYPE, headEntity.getTag());
fragments.add(SubjectFragment.newInstance(clone));
}
VPFragmentAdapter adapter =
new VPFragmentAdapter(getSupportFragmentManager(), fragments, tag);
mViewPager.setAdapter(adapter);
mTabLayout.setupWithViewPager(mViewPager);
// mTabLayout.setTabsFromPagerAdapter(adapter);
}
}
@Override
public void onChange(String title) {
mActionBarTitle.setText(title);
}
}

View File

@ -1,349 +1,29 @@
package com.gh.gamecenter;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
import com.gh.base.BaseActivity;
import com.gh.base.OnRequestCallBackListener;
import com.gh.common.util.CheckLoginUtils;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.adapter.VoteAdapter;
import com.gh.gamecenter.entity.UserDataEntity;
import com.gh.gamecenter.entity.VersionVoteEntity;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.lightgame.utils.Util_System_Keyboard;
import com.lightgame.utils.Utils;
import org.json.JSONException;
import org.json.JSONObject;
import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.HttpException;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import com.halo.assistant.fragment.VoteFragment;
import com.halo.assistant.ui.IntentFactory;
/**
* Created by khy on 2017/4/11.
* 求版本投票页面
*/
public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener,
VoteAdapter.OnAddVoteListener, OnRequestCallBackListener<String> {
@BindView(R.id.vote_rv)
RecyclerView mVoteRv;
@BindView(R.id.vote_refresh)
SwipeRefreshLayout mVoteRefresh;
@BindView(R.id.vote_loading)
ProgressBarCircularIndeterminate mVoteLoading;
@BindView(R.id.reuse_no_connection)
LinearLayout mNoConnection;
@BindView(R.id.vote_add_tv)
TextView mAddTv;
private VoteAdapter mAdapter;
private String mGameId;
Runnable runnable = new Runnable() {
@Override
public void run() {
mAdapter = new VoteAdapter(VoteActivity.this, VoteActivity.this, VoteActivity.this, mGameId);
mVoteRv.setAdapter(mAdapter);
}
};
private LinearLayoutManager layoutManager;
@Deprecated
public class VoteActivity extends CommonActivity {
@NonNull
public static Intent getIntent(Context context, String gameName, String gameId) {
Intent intent = new Intent(context, VoteActivity.class);
intent.putExtra(EntranceUtils.KEY_GAMENAME, gameName);
intent.putExtra(EntranceUtils.KEY_GAMEID, gameId);
return intent;
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(VoteActivity.class)
.setFragment(VoteFragment.class).build();
}
@Override
protected int getLayoutId() {
return R.layout.activity_vote;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String gameName = getIntent().getExtras().getString(EntranceUtils.KEY_GAMENAME);
mGameId = getIntent().getExtras().getString(EntranceUtils.KEY_GAMEID);
setNavigationTitle(getString(R.string.title_vote_formatable, gameName));
layoutManager = new LinearLayoutManager(this);
mVoteRv.setLayoutManager(layoutManager);
mAdapter = new VoteAdapter(this, this, this, mGameId);
mVoteRv.setAdapter(mAdapter);
mVoteRefresh.setColorSchemeResources(R.color.theme);
mVoteRefresh.setOnRefreshListener(this);
mAddTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckLoginUtils.checkLogin(VoteActivity.this, new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
showAddVoteDialog();
}
});
}
});
mVoteRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE && mAdapter.isLoaded() && !mAdapter.isRemove()
&& mAdapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1) {
mAdapter.getVersionVote(mAdapter.getItemCount() - 1);
}
}
});
}
@Override
public void loadDone() {
mVoteRefresh.setRefreshing(false);
mVoteLoading.setVisibility(View.GONE);
mVoteRv.setVisibility(View.VISIBLE);
mAddTv.setVisibility(View.GONE);
}
@Override
public void loadDone(final String obj) {
CheckLoginUtils.checkLogin(VoteActivity.this, new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
postVersionVote(obj, false); // 投票
}
});
}
@Override
public void loadError() {
mVoteRefresh.setRefreshing(false);
mNoConnection.setVisibility(View.VISIBLE);
mVoteRv.setVisibility(View.GONE);
mAddTv.setVisibility(View.GONE);
}
@Override
public void loadEmpty() {
mVoteRefresh.setRefreshing(false);
mAddTv.setVisibility(View.VISIBLE);
mVoteLoading.setVisibility(View.GONE);
}
private void showAddVoteDialog() {
final Dialog dialog = new Dialog(VoteActivity.this);
View view = View.inflate(VoteActivity.this, R.layout.dialog_modify_nickname, null);
TextView title = (TextView) view.findViewById(R.id.dialog_nickname_title);
title.setText(R.string.vote_input_hint);
final EditText mEdtInput = (EditText) view.findViewById(R.id.dialog_nickname_input);
mEdtInput.setHint("");
mEdtInput.setSelection(mEdtInput.getText().length());
mEdtInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
String nickname = mEdtInput.getText().toString().trim();
if (TextUtils.isEmpty(nickname)) {
Utils.toast(VoteActivity.this, getString(R.string.vote_empty_hint));
return true;
}
postVersionVote(nickname, true);
dialog.dismiss();
return true;
}
return false;
}
});
// 取消按钮
TextView cancel = (TextView) view.findViewById(R.id.dialog_nickname_cancel);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
// 确定按钮
TextView confirm = (TextView) view.findViewById(R.id.dialog_nickname_confirm);
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String nickname = mEdtInput.getText().toString().trim();
if (TextUtils.isEmpty(nickname)) {
Utils.toast(VoteActivity.this, getString(R.string.vote_empty_hint));
return;
}
postVersionVote(nickname, true);
dialog.dismiss();
}
});
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Util_System_Keyboard.hideSoftKeyboard(VoteActivity.this);
}
});
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();
mVoteRv.postDelayed(new Runnable() {
@Override
public void run() {
Util_System_Keyboard.showSoftKeyboard(VoteActivity.this, mEdtInput);
}
}, 300);
}
private void postVersionVote(final String name, final boolean isNewVote) {
if (isNewVote) {
for (VersionVoteEntity voteEntity : mAdapter.getDataList()) {
if (name.equals(voteEntity.getName())) {
UserDataEntity userDataEntity = voteEntity.getUserData();
if (userDataEntity != null && userDataEntity.isVersionRequested()) {
Utils.toast(this, getString(R.string.vote_success));
return;
}
}
}
}
final Dialog waitDialog = DialogUtils.showWaitDialog(VoteActivity.this, getString(R.string.vote_post));
JSONObject object = new JSONObject();
try {
object.put("name", name);
} catch (JSONException e) {
e.printStackTrace();
}
final RequestBody body = RequestBody.create(MediaType.parse("application/json"), object.toString());
RetrofitManager.getInstance(this).getApi()
.postVersionVote(body, mGameId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<ResponseBody>() {
@Override
public void onResponse(ResponseBody response) {
super.onResponse(response);
waitDialog.dismiss();
try {
String string = response.string();
JSONObject responseObject = new JSONObject(string);
boolean cast = responseObject.getBoolean("cast");
String id = responseObject.getString("_id");
if (cast) {
Utils.toast(VoteActivity.this, getString(R.string.vote_success));
} else {
if (isNewVote) {
Utils.toast(VoteActivity.this, "已经存在相同的选项");
} else {
Utils.toast(VoteActivity.this, "你已经投过了");
}
}
if (!TextUtils.isEmpty(id)) {
mAdapter.voteCallBack(cast, isNewVote, id, name);
if (isNewVote) {
mVoteRv.scrollToPosition(mAdapter.getItemCount() - 1);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(HttpException e) {
super.onFailure(e);
if (e != null && e.code() == 403) {
try {
String string = e.response().errorBody().string();
JSONObject errorJson = new JSONObject(string);
String detail = errorJson.getString("detail");
if ("illegal".equals(detail)) {
Utils.toast(VoteActivity.this, getString(R.string.vote_illegal_hint));
}
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
toast(getString(R.string.post_failure_hint));
}
waitDialog.dismiss();
}
});
}
@OnClick(R.id.reuse_no_connection)
public void reconnection() { // 重新连接
mVoteRv.setVisibility(View.VISIBLE);
mVoteLoading.setVisibility(View.VISIBLE);
mNoConnection.setVisibility(View.GONE);
mVoteRefresh.postDelayed(runnable, 1000);
}
@Override
public void onRefresh() {
mVoteRefresh.postDelayed(runnable, 1000);
}
@Override
public void addVote() {
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
showAddVoteDialog();
}
});
}
}

View File

@ -2,101 +2,44 @@ package com.gh.gamecenter;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.gh.base.BaseActivity;
import com.gh.common.util.CheckLoginUtils;
import com.gh.common.util.CollectionUtils;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.common.util.ShareUtils;
import com.gh.gamecenter.entity.CommentnumEntity;
import com.gh.gamecenter.entity.ConcernEntity;
import com.gh.gamecenter.entity.NewsEntity;
import com.gh.gamecenter.entity.ToolBoxEntity;
import com.gh.gamecenter.entity.UserDataEntity;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.google.gson.Gson;
import com.jakewharton.rxbinding.view.RxView;
import com.tencent.tauth.Tencent;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import butterknife.BindView;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
import com.halo.assistant.fragment.WebFragment;
import com.halo.assistant.ui.IntentFactory;
/**
* Created by khy on 2016/10/18.
*/
public class WebActivity extends BaseActivity implements View.OnClickListener{
@BindView(R.id.news_webview)
WebView webView;
@BindView(R.id.web_progressbar)
ProgressBar progressBar;
@BindView(R.id.web_comment)
TextView webComment;
@BindView(R.id.news_bottom)
RelativeLayout newsBottom;
@BindView(R.id.actionbar_tv_title)
TextView newsTitle;
View mShareIv;
ImageView mCollectionIv;
private static final int WEB_COMMENT_REQUEST = 9; // 刷新文章web页面评论数
private static final String KEY_ISTOOLS = "isTools";
private static final String KEY_ISCOLLECTIONTOOLS = "isCollectionTools";
private ToolBoxEntity mToolBoxEntity;
private String newsId;
private int commentNum;
private boolean mIsTools;
private boolean mIsCollectionTools;
@Deprecated
public class WebActivity extends CommonActivity {
@NonNull
public static Intent getWebIntent(Context context) {
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra(EntranceUtils.KEY_GAMENAME, context.getString(R.string.disclaimer_title));
intent.putExtra(EntranceUtils.KEY_URL, context.getString(R.string.disclaimer_url));
return intent;
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(WebActivity.class)
.setFragment(WebFragment.class).build();
}
@NonNull
public static void startWebByCollectionTools(Context context, ToolBoxEntity toolBoxEntity, boolean isCollectionTools) {
public static Intent getWebByCollectionTools(Context context, ToolBoxEntity toolBoxEntity, boolean isCollectionTools) {
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra(EntranceUtils.KEY_URL, toolBoxEntity.getUrl());
intent.putExtra(KEY_ISTOOLS, true);
intent.putExtra(WebFragment.KEY_ISTOOLS, true);
// intent.putExtra("gameName", toolBoxEntity.getName());
intent.putExtra(ToolBoxEntity.TAG, toolBoxEntity);
intent.putExtra(KEY_ISCOLLECTIONTOOLS, isCollectionTools);
context.startActivity(intent);
intent.putExtra(WebFragment.KEY_ISCOLLECTIONTOOLS, isCollectionTools);
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(WebActivity.class)
.setFragment(WebFragment.class).build();
}
@NonNull
@ -106,7 +49,10 @@ public class WebActivity extends BaseActivity implements View.OnClickListener{
intent.putExtra(EntranceUtils.KEY_GAMENAME, concernEntity.getGameName());
intent.putExtra(EntranceUtils.KEY_NEWSID, concernEntity.getId());
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
return intent;
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(WebActivity.class)
.setFragment(WebFragment.class).build();
}
@NonNull
@ -116,287 +62,20 @@ public class WebActivity extends BaseActivity implements View.OnClickListener{
intent.putExtra(EntranceUtils.KEY_GAMENAME, newsEntity.getGameName());
intent.putExtra(EntranceUtils.KEY_NEWSID, newsEntity.getId());
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
return intent;
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(WebActivity.class)
.setFragment(WebFragment.class).build();
}
@NonNull
public static Intent getIntentByUrl(Context context, String url) {
Intent intent = new Intent(context, WebActivity.class);
intent.putExtra(EntranceUtils.KEY_URL, url);
return intent;
}
@Override
protected int getLayoutId() {
return R.layout.activity_web;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// 刷新评论数
if (resultCode == WEB_COMMENT_REQUEST && newsId != null && data != null && data.getExtras() != null) {
webComment.setText( getString(R.string.web_newscomment_count, data.getExtras().getInt("commentNum")));
} else if (requestCode == com.tencent.connect.common.Constants.REQUEST_QQ_SHARE
|| requestCode == com.tencent.connect.common.Constants.REQUEST_QZONE_SHARE) {
Tencent.onActivityResultData(requestCode, resultCode, data, ShareUtils.getInstance(this).QqShareListener);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String webUrl;
String webTitle;
mIsTools = getIntent().getBooleanExtra(KEY_ISTOOLS, false);
if (getIntent().getBundleExtra(EntranceUtils.KEY_DATA) != null) {
Bundle data = getIntent().getBundleExtra(EntranceUtils.KEY_DATA);
webUrl = data.getString(EntranceUtils.KEY_URL);
webTitle = "";
} else {
webUrl = getIntent().getStringExtra(EntranceUtils.KEY_URL);
webTitle = getIntent().getStringExtra(EntranceUtils.KEY_GAMENAME);
newsId = getIntent().getStringExtra(EntranceUtils.KEY_NEWSID);
}
// 增加actionBar Button
RelativeLayout reuse_actionbar = findViewById(R.id.reuse_actionbar);
mShareIv = LayoutInflater.from(this).inflate(R.layout.menu_action_share, reuse_actionbar, false); // 绑定parentView 否则会丢失宽高
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mShareIv.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
reuse_actionbar.addView(mShareIv, params);
mCollectionIv = (ImageView) LayoutInflater.from(this).inflate(R.layout.menu_action_collection, reuse_actionbar, false);
RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) mCollectionIv.getLayoutParams();
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params2.addRule(RelativeLayout.CENTER_VERTICAL);
params2.setMargins(0, 0 ,params.width, 0);
reuse_actionbar.addView(mCollectionIv, params2);
if (mIsTools) {
mToolBoxEntity = getIntent().getParcelableExtra(ToolBoxEntity.TAG);
mIsCollectionTools = getIntent().getBooleanExtra(KEY_ISCOLLECTIONTOOLS, false);
mShareIv.setVisibility(View.VISIBLE);
mCollectionIv.setVisibility(View.VISIBLE);
initCollection();
} else {
mShareIv.setVisibility(View.GONE);
mCollectionIv.setVisibility(View.GONE);
}
setNavigationTitle(webTitle);
webView.loadUrl(webUrl);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
//用webview打开url
webView.setWebViewClient(new WebViewClient() {
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, String url) {
// view.loadUrl(url);
// return true;
// }
// @Override
// public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
// 广告拦截操作
// if (!url.contains(xxxx)) {
// return new WebResourceResponse(null, null, null);
// }
// return null;
// }
});
// 页面里的下载跳转到自带浏览器
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
//设置加载进度条
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
progressBar.setProgress(newProgress);
if (newProgress == 100) {
progressBar.setVisibility(View.GONE);
if (newsBottom.getVisibility() == View.GONE && newsId != null) {
newsBottom.setVisibility(View.VISIBLE);
}
} else {
if (progressBar.getVisibility() == View.GONE) {
progressBar.setVisibility(View.VISIBLE);
}
}
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (TextUtils.isEmpty(newsId) && TextUtils.isEmpty(newsTitle.getText().toString()) && !mIsTools) {
newsTitle.setEllipsize(TextUtils.TruncateAt.END);
newsTitle.setPadding(DisplayUtils.dip2px(getApplication(), 30), 0, DisplayUtils.dip2px(getApplication(), 30), 0);
newsTitle.setSingleLine();
newsTitle.setText(title);
}
}
});
if (newsId != null) {
getNewsCommentNum();
}
if (mShareIv != null && mToolBoxEntity != null) {
RxView.clicks(mShareIv)
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
showShare(mToolBoxEntity.getUrl(), mToolBoxEntity.getDes(), mToolBoxEntity.getIcon(), mToolBoxEntity.getName(), null, true);
}
});
}
if (mIsCollectionTools && mToolBoxEntity != null) {
getToolsById(); // 对比查看是否修改
}
webComment.setOnClickListener(this);
mCollectionIv.setOnClickListener(this);
}
private void initCollection() {
if (mToolBoxEntity != null) {
mCollectionIv.setVisibility(View.VISIBLE);
if (mToolBoxEntity.getUserData() != null && mToolBoxEntity.getUserData().isToolkitFavorite()) {
mCollectionIv.setImageResource(R.drawable.detail_collection_select);
} else {
mCollectionIv.setImageResource(R.drawable.detail_collection_unselect);
}
}
}
private void getToolsById() {
RetrofitManager.getInstance(this)
.getApi()
.getToolBoxById(mToolBoxEntity.getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<List<ToolBoxEntity>>() {
@Override
public void onResponse(List<ToolBoxEntity> response) {
super.onResponse(response);
if (response.size() == 0) return;
ToolBoxEntity toolBoxEntity = response.get(0);
Gson gson = new Gson();
String newEntity = gson.toJson(toolBoxEntity);
String entity = gson.toJson(mToolBoxEntity);
if (!newEntity.equals(entity)) {
CollectionUtils.INSTANCE.patchCollection(WebActivity.this, toolBoxEntity.getId(), CollectionUtils.CollectionType.toolkit);
}
}
});
}
public void getNewsCommentNum() {
RetrofitManager.getInstance(this).getApi()
.getNewsCommentnum(newsId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<List<CommentnumEntity>>() {
@Override
public void onNext(List<CommentnumEntity> response) {
super.onNext(response);
if (response.size() > 0 && response.get(0).getNum() > 0) {
commentNum = response.get(0).getNum();
webComment.setText("查看评论(" + response.get(0).getNum() + "");
}
}
});
}
public void onClick(View v) {
if (v == webComment) {
Intent intent = MessageDetailActivity.getIntentById(this, newsId, commentNum, null, mEntrance + "+(光环浏览器)");
startActivityForResult(intent, WEB_COMMENT_REQUEST);
} else if (v == mCollectionIv) {
CheckLoginUtils.checkLogin(this, new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
mCollectionIv.setEnabled(false);
if (mToolBoxEntity.getUserData() != null && mToolBoxEntity.getUserData().isToolkitFavorite()) {
CollectionUtils.INSTANCE.deleteCollection(WebActivity.this, mToolBoxEntity.getId(),
CollectionUtils.CollectionType.toolkit,
new CollectionUtils.OnCollectionListener() {
@Override
public void onSuccess() {
mToolBoxEntity.getUserData().setToolkitFavorite(false);
mCollectionIv.setEnabled(true);
mCollectionIv.setImageResource(R.drawable.detail_collection_unselect);
toast(getString(R.string.collection_cancel));
}
@Override
public void onError() {
mCollectionIv.setEnabled(true);
toast(getString(R.string.collection_cancel_failure));
}
});
} else {
Map<String, String> map = new HashMap<>();
map.put("_id", mToolBoxEntity.getId());
CollectionUtils.INSTANCE.postCollection(WebActivity.this, new JSONObject(map).toString(),
CollectionUtils.CollectionType.toolkit,
new CollectionUtils.OnCollectionListener() {
@Override
public void onSuccess() {
UserDataEntity userData = mToolBoxEntity.getUserData();
if (userData == null) {
userData = new UserDataEntity();
mToolBoxEntity.setUserData(userData);
}
userData.setToolkitFavorite(true);
mCollectionIv.setEnabled(true);
mCollectionIv.setImageResource(R.drawable.detail_collection_select);
toast(getString(R.string.collection_success));
}
@Override
public void onError() {
mCollectionIv.setEnabled(true);
toast(getString(R.string.collection_failure));
}
});
}
}
});
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
webView.goBack();// 返回前一个页面
return true;
}
return super.onKeyDown(keyCode, event);
return new IntentFactory.Builder(context)
.setArgs(intent.getExtras())
.setActivity(WebActivity.class)
.setFragment(WebFragment.class).build();
}
}

View File

@ -12,10 +12,10 @@ import android.view.ViewGroup;
import com.facebook.drawee.view.SimpleDraweeView;
import com.gh.common.util.DataLogUtils;
import com.gh.gamecenter.DataUtils;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.NewsUtils;
import com.gh.common.util.StringUtils;
import com.gh.gamecenter.DataUtils;
import com.gh.gamecenter.GameDetailActivity;
import com.gh.gamecenter.NewsDetailActivity;
import com.gh.gamecenter.R;
@ -103,8 +103,8 @@ public class ImagePagerAdapter extends RecyclingPagerAdapter {
mContext.startActivity(intent);
break;
case "column":
SubjectActivity.startSubjectActivity(mContext, slideEntity.getLink(), slideEntity.getName()
, false, entrance);
SubjectActivity.startSubjectActivity(mContext, slideEntity.getLink(),
slideEntity.getName(), false, entrance);
break;
}

View File

@ -8,7 +8,6 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import com.gh.base.OnRequestCallBackListener;
@ -323,7 +322,7 @@ public class ToolBoxRvAdapter extends BaseRecyclerAdapter {
Intent intent = NewsDetailActivity.getIntentById(mContext, newsId, "工具箱列表");
mContext.startActivity(intent);
} else {
WebActivity.startWebByCollectionTools(mContext, toolBoxEntity, false);
mContext.startActivity(WebActivity.getWebByCollectionTools(mContext, toolBoxEntity, false));
}
}
});

View File

@ -1,33 +0,0 @@
package com.gh.gamecenter.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.List;
public class VPFragmentAdapter extends FragmentPagerAdapter {
private List<Fragment> mFragments;
private List<String> mTitles;
public VPFragmentAdapter(FragmentManager fm, List<Fragment> fragments, List<String> titles) {
super(fm);
mFragments = fragments;
mTitles = titles;
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mTitles.get(position);
}
}

View File

@ -48,8 +48,8 @@ public class VoteAdapter extends BaseRecyclerAdapter<ViewHolder> {
private String mGameId;
public VoteAdapter(Context context, OnRequestCallBackListener onRequestCallBackListener
, OnAddVoteListener addVoteListener, String gameId) {
public VoteAdapter(Context context, OnRequestCallBackListener onRequestCallBackListener,
OnAddVoteListener addVoteListener, String gameId) {
super(context);
this.mCallBackListener = onRequestCallBackListener;

View File

@ -163,7 +163,7 @@ public class ToolsFragment extends BaseFragment implements SwipeRefreshLayout.On
Intent intent = NewsDetailActivity.getIntentById(getContext(), newsId, true, "(收藏:工具箱)");
getContext().startActivity(intent);
} else {
WebActivity.startWebByCollectionTools(getContext(), toolBoxEntity, true);
startActivity(WebActivity.getWebByCollectionTools(getContext(), toolBoxEntity, true));
}
}
}

View File

@ -169,7 +169,7 @@ public class SearchToolbarFragment extends BaseFragment implements View.OnClickL
private void initActionBar(View view) {
if (getActivity().getActionBar() != null) {
getActivity().getActionBar().setCustomView(R.layout.search_actionbar);
getActivity().getActionBar().setCustomView(R.layout.toolbar_search);
}
mDownloadView.setOnClickListener(this);

View File

@ -80,7 +80,7 @@ public class GameDetailToolsAdapter extends BaseRecyclerAdapter {
Intent intent = NewsDetailActivity.getIntentById(mContext, newsId, "游戏详情-工具箱");
mContext.startActivity(intent);
} else {
WebActivity.startWebByCollectionTools(mContext, toolBoxEntity, false);
mContext.startActivity(WebActivity.getWebByCollectionTools(mContext, toolBoxEntity, false));
}
}
});

View File

@ -64,9 +64,11 @@ import static com.gh.gamecenter.personal.PersonalFragment.LOGIN_TAG;
/**
* Created by CsHeng on 18/12/2017.
* 消息详情界面--评论详情
* 消息详情界面--评论详情--对话详情
*/
public class CommentDetailFragment extends BaseFragment implements OnCommentCallBackListener, OnBackPressedListener {
public class MessageDetailFragment extends BaseFragment implements OnCommentCallBackListener, OnBackPressedListener {
public static final int REQUEST_UPDATE_COMMENT = 9; // 刷新文章web页面评论数
@BindView(R.id.message_detail_rv)
RecyclerView mMessageDetailRv;

View File

@ -1,9 +0,0 @@
package com.gh.gamecenter.subject;
/**
* Created by khy on 23/11/17.
*/
public interface OnSubjectTitleListener {
void onChange(String title);
}

View File

@ -48,7 +48,7 @@ import rx.functions.Func1;
import rx.schedulers.Schedulers;
public class SubjectAdapter extends BaseRecyclerAdapter<ViewHolder> {
class SubjectAdapter extends BaseRecyclerAdapter<ViewHolder> {
private OnRequestCallBackListener mOnRequestCallBackListener;
@ -68,7 +68,7 @@ public class SubjectAdapter extends BaseRecyclerAdapter<ViewHolder> {
private boolean mIsOrder;
private boolean mIsLoaded;
public SubjectAdapter(Context context, OnRequestCallBackListener listener, String type, String id
SubjectAdapter(Context context, OnRequestCallBackListener listener, String type, String id
, String name, String entrance, String order, String tagType, boolean isOrder) {
super(context);
this.mOnRequestCallBackListener = listener;

View File

@ -6,9 +6,7 @@ import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
import com.gh.base.fragment.BaseFragment;
import com.gh.common.util.ApkActiveUtils;
import com.gh.common.util.DownloadItemUtils;
@ -24,6 +22,7 @@ import com.gh.gamecenter.eventbus.EBPackage;
import com.gh.gamecenter.eventbus.EBReuse;
import com.gh.gamecenter.eventbus.EBUISwitch;
import com.gh.gamecenter.info.InfoToolWrapperFragment;
import com.lightgame.OnTitleClickListener;
import com.lightgame.download.DataWatcher;
import com.lightgame.download.DownloadEntity;
@ -37,21 +36,22 @@ import butterknife.BindView;
/**
* Created by khy on 2017/5/3.
* <p>
* 专题变更时加载的专题列表
*/
public class SubjectFragment extends BaseFragment {
public class SubjectListFragment extends BaseFragment implements OnTitleClickListener {
@BindView(R.id.subject_list)
RecyclerView subject_list;
RecyclerView mRvSubject;
@BindView(R.id.subject_pb_loading)
ProgressBarCircularIndeterminate subject_pb_loading;
View mPbSubject;
@BindView(R.id.reuse_no_connection)
LinearLayout reuse_no_connection;
View reuse_no_connection;
@BindView(R.id.reuse_none_data)
LinearLayout mNoData;
View mNoData;
private SubjectAdapter adapter;
private LinearLayoutManager layoutManager;
private SubjectAdapter mSubjectAdapter;
private LinearLayoutManager mLayoutManager;
private String mId;
private String mName;
@ -65,29 +65,26 @@ public class SubjectFragment extends BaseFragment {
private int page = 1;
public final static String SCROLL_TOP = "scrollTop";
// 黄壮华 添加观察者 修改2015/8/15
private DataWatcher dataWatcher = new DataWatcher() {
@Override
public void onDataChanged(DownloadEntity downloadEntity) {
ArrayList<Integer> locationList = adapter.getLocationMap().get(downloadEntity.getPackageName());
ArrayList<Integer> locationList = mSubjectAdapter.getLocationMap().get(downloadEntity.getPackageName());
if (locationList != null) {
GameEntity gameEntity;
for (int location : locationList) {
gameEntity = adapter.getSubjectList().get(location);
gameEntity = mSubjectAdapter.getSubjectList().get(location);
if (gameEntity != null) {
DownloadItemUtils.processDate(getContext(), gameEntity, downloadEntity,
adapter, location);
mSubjectAdapter, location);
}
}
}
}
};
public static SubjectFragment newInstance(Bundle bundle) {
SubjectFragment fragment = new SubjectFragment();
public static SubjectListFragment newInstance(Bundle bundle) {
SubjectListFragment fragment = new SubjectListFragment();
fragment.setArguments(bundle);
return fragment;
}
@ -112,43 +109,43 @@ public class SubjectFragment extends BaseFragment {
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
subject_pb_loading.setVisibility(View.VISIBLE);
subject_list.setVisibility(View.VISIBLE);
mPbSubject.setVisibility(View.VISIBLE);
mRvSubject.setVisibility(View.VISIBLE);
reuse_no_connection.setVisibility(View.GONE);
adapter = new SubjectAdapter(getContext(), SubjectFragment.this, mType, mId, mName, mEntrance, mListOrder, mTagType, mIsOrder);
subject_list.setAdapter(adapter);
mSubjectAdapter = new SubjectAdapter(getContext(), SubjectListFragment.this, mType, mId, mName, mEntrance, mListOrder, mTagType, mIsOrder);
mRvSubject.setAdapter(mSubjectAdapter);
}
});
layoutManager = new LinearLayoutManager(getContext());
mLayoutManager = new LinearLayoutManager(getContext());
((DefaultItemAnimator) subject_list.getItemAnimator()).setSupportsChangeAnimations(false);
subject_list.addItemDecoration(new VerticalItemDecoration(getContext(), 8, true));
subject_list.setHasFixedSize(true);
subject_list.setLayoutManager(layoutManager);
adapter = new SubjectAdapter(getContext(), this, mType, mId, mName, mEntrance, mListOrder, mTagType, mIsOrder);
subject_list.setAdapter(adapter);
((DefaultItemAnimator) mRvSubject.getItemAnimator()).setSupportsChangeAnimations(false);
mRvSubject.addItemDecoration(new VerticalItemDecoration(getContext(), 8, true));
mRvSubject.setHasFixedSize(true);
mRvSubject.setLayoutManager(mLayoutManager);
mSubjectAdapter = new SubjectAdapter(getContext(), this, mType, mId, mName, mEntrance, mListOrder, mTagType, mIsOrder);
mRvSubject.setAdapter(mSubjectAdapter);
subject_list.addOnScrollListener(new RecyclerView.OnScrollListener() {
mRvSubject.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int position = layoutManager.findFirstCompletelyVisibleItemPosition();
int position = mLayoutManager.findFirstCompletelyVisibleItemPosition();
if (mScorllTop && position == 0 && newState == RecyclerView.SCROLL_STATE_IDLE) {
mScorllTop = false;
EventBus.getDefault().post(new EBReuse(SubjectTileFragment.OPEN_APPBAR));
}
if (!adapter.isRemove() && adapter.isLoaded() && newState == RecyclerView.SCROLL_STATE_IDLE
&& adapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1) {
adapter.initList(page);
if (!mSubjectAdapter.isRemove() && mSubjectAdapter.isLoaded() && newState == RecyclerView.SCROLL_STATE_IDLE
&& mSubjectAdapter.getItemCount() == mLayoutManager.findLastVisibleItemPosition() + 1) {
mSubjectAdapter.initList(page);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int position = layoutManager.findFirstCompletelyVisibleItemPosition();
int position = mLayoutManager.findFirstCompletelyVisibleItemPosition();
if (position == 0 && Math.abs(dy) > 10) {
EventBus.getDefault().post(new EBReuse(SubjectTileFragment.OPEN_APPBAR));
}
@ -156,22 +153,10 @@ public class SubjectFragment extends BaseFragment {
});
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBReuse reuse) {
if (SCROLL_TOP.equals(reuse.getType())) {
if (layoutManager.findFirstCompletelyVisibleItemPosition() == 0 || adapter.getItemCount() == 0) {
EventBus.getDefault().post(new EBReuse(SubjectTileFragment.OPEN_APPBAR));
} else {
layoutManager.smoothScrollToPosition(subject_list, null, 0);
mScorllTop = true;
}
}
}
@Override
public void onResume() {
if (isEverPause && adapter != null) {
adapter.notifyDataSetChanged();
if (isEverPause && mSubjectAdapter != null) {
mSubjectAdapter.notifyDataSetChanged();
}
DownloadManager.getInstance(getContext()).addObserver(dataWatcher);
super.onResume();
@ -186,19 +171,19 @@ public class SubjectFragment extends BaseFragment {
@Override
public void loadDone() {
mNoData.setVisibility(View.GONE);
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
subject_pb_loading.setVisibility(View.GONE);
if (mPbSubject != null && mPbSubject.getVisibility() == View.VISIBLE) {
mPbSubject.setVisibility(View.GONE);
}
page++;
}
@Override
public void loadError() {
if (subject_pb_loading != null && subject_pb_loading.getVisibility() == View.VISIBLE) {
subject_pb_loading.setVisibility(View.GONE);
if (mPbSubject != null && mPbSubject.getVisibility() == View.VISIBLE) {
mPbSubject.setVisibility(View.GONE);
}
toast(getContext().getString(R.string.loading_failed_hint));
subject_list.setVisibility(View.GONE);
mRvSubject.setVisibility(View.GONE);
reuse_no_connection.setVisibility(View.VISIBLE);
mNoData.setVisibility(View.GONE);
}
@ -216,15 +201,15 @@ public class SubjectFragment extends BaseFragment {
if ("delete".equals(status.getStatus())) {
DownloadManager.getInstance(getContext()).removePlatform(status.getName(), status.getPlatform());
ArrayList<Integer> locationList = adapter.getLocationMap().get(status.getPackageName());
ArrayList<Integer> locationList = mSubjectAdapter.getLocationMap().get(status.getPackageName());
if (locationList != null) {
GameEntity gameEntity;
for (int location : locationList) {
gameEntity = adapter.getSubjectList().get(location);
gameEntity = mSubjectAdapter.getSubjectList().get(location);
if (gameEntity != null && gameEntity.getEntryMap() != null) {
gameEntity.getEntryMap().remove(status.getPlatform());
}
adapter.notifyItemChanged(location);
mSubjectAdapter.notifyItemChanged(location);
}
}
}
@ -232,11 +217,11 @@ public class SubjectFragment extends BaseFragment {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBPackage busFour) {
ArrayList<Integer> locationList = adapter.getLocationMap().get(busFour.getPackageName());
ArrayList<Integer> locationList = mSubjectAdapter.getLocationMap().get(busFour.getPackageName());
if (locationList != null) {
GameEntity gameEntity;
for (int location : locationList) {
gameEntity = adapter.getSubjectList().get(location);
gameEntity = mSubjectAdapter.getSubjectList().get(location);
ApkActiveUtils.filterHideApk(gameEntity);
if ("安装".equals(busFour.getType())) {
for (ApkEntity apkEntity : gameEntity.getApk()) {
@ -244,12 +229,12 @@ public class SubjectFragment extends BaseFragment {
if (gameEntity.getEntryMap() != null) {
gameEntity.getEntryMap().remove(apkEntity.getPlatform());
}
adapter.notifyItemChanged(location);
mSubjectAdapter.notifyItemChanged(location);
break;
}
}
} else if ("卸载".equals(busFour.getType())) {
adapter.notifyItemChanged(location);
mSubjectAdapter.notifyItemChanged(location);
}
}
}
@ -260,11 +245,11 @@ public class SubjectFragment extends BaseFragment {
public void onEventMainThread(EBNetworkState busNetworkState) {
if (busNetworkState.isNetworkConnected()) {
if (reuse_no_connection.getVisibility() == View.VISIBLE) {
subject_list.setVisibility(View.VISIBLE);
subject_pb_loading.setVisibility(View.VISIBLE);
mRvSubject.setVisibility(View.VISIBLE);
mPbSubject.setVisibility(View.VISIBLE);
reuse_no_connection.setVisibility(View.GONE);
adapter = new SubjectAdapter(getContext(), this, mType, mId, mName, mEntrance, mListOrder, mTagType, mIsOrder);
subject_list.setAdapter(adapter);
mSubjectAdapter = new SubjectAdapter(getContext(), this, mType, mId, mName, mEntrance, mListOrder, mTagType, mIsOrder);
mRvSubject.setAdapter(mSubjectAdapter);
}
}
}
@ -274,11 +259,21 @@ public class SubjectFragment extends BaseFragment {
public void onEventMainThread(EBUISwitch busNine) {
if (InfoToolWrapperFragment.EB_NEWSFRAGMENT_TAG.equals(busNine.getFrom())) {
if (busNine.getPosition() == 0) {
if (subject_pb_loading.getVisibility() == View.VISIBLE) {
adapter.initList(1);
if (mPbSubject.getVisibility() == View.VISIBLE) {
mSubjectAdapter.initList(1);
}
}
}
}
@Override
public void onTitleClick() {
if (mLayoutManager.findFirstCompletelyVisibleItemPosition() == 0 || mSubjectAdapter.getItemCount() == 0) {
EventBus.getDefault().post(new EBReuse(SubjectTileFragment.OPEN_APPBAR));
} else {
mLayoutManager.smoothScrollToPosition(mRvSubject, null, 0);
mScorllTop = true;
}
}
}

View File

@ -1,12 +1,11 @@
package com.gh.gamecenter.subject;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.DefaultItemAnimator;
@ -15,11 +14,9 @@ import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.gh.base.fragment.BaseFragment;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.common.util.StringUtils;
import com.gh.gamecenter.R;
@ -30,7 +27,6 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
@ -39,7 +35,8 @@ import butterknife.OnClick;
* Created by khy on 27/05/17.
*/
public class SubjectTileFragment extends BaseFragment implements SubjectTypeAdapter.OnSelectTypeListener {
public class SubjectTileFragment extends BaseFragment implements SubjectTypeAdapter.OnSelectTypeListener,
View.OnTouchListener {
@BindView(R.id.subject_type_list)
RecyclerView mSubjectRv;
@ -50,8 +47,6 @@ public class SubjectTileFragment extends BaseFragment implements SubjectTypeAdap
@BindView(R.id.subject_tabbar_new_tv)
TextView mTabbarNewTv;
private OnSubjectTitleListener mSubjectTitleListener;
public final static String OPEN_APPBAR = "openAppBar";
public final static String KEY_LISTORDER = "listOrder";
@ -75,9 +70,8 @@ public class SubjectTileFragment extends BaseFragment implements SubjectTypeAdap
if (fragmentByTag != null) {
transaction.show(fragmentByTag);
} else {
fragmentByTag = new SubjectFragment();
Bundle mBundle = getActivity().getIntent().getExtras();
Bundle clone = (Bundle) mBundle.clone();
fragmentByTag = new SubjectListFragment();
Bundle clone = (Bundle) getArguments().clone();
clone.putString(EntranceUtils.KEY_TAGTYPE, mTagType);
clone.putString(KEY_LISTORDER, mListOrder);
clone.putString(EntranceUtils.KEY_TYPE, mType);
@ -94,13 +88,6 @@ public class SubjectTileFragment extends BaseFragment implements SubjectTypeAdap
return R.layout.fragment_subject_tiled;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnSubjectTitleListener)
mSubjectTitleListener = (OnSubjectTitleListener) context;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -138,11 +125,9 @@ public class SubjectTileFragment extends BaseFragment implements SubjectTypeAdap
if (!TextUtils.isEmpty(mName)) {
int totalScrollRange = appBarLayout.getTotalScrollRange();
if (Math.abs(verticalOffset) < totalScrollRange / 2) {
if (mSubjectTitleListener != null)
mSubjectTitleListener.onChange(mName);
setNavigationTitle(mName);
} else if (Math.abs(verticalOffset) == totalScrollRange && totalScrollRange != 0) {
if (mSubjectTitleListener != null)
mSubjectTitleListener.onChange(StringUtils.buildString(mName, "-", mType, ""));
setNavigationTitle(StringUtils.buildString(mName, "-", mType, ""));
}
}
}
@ -150,15 +135,23 @@ public class SubjectTileFragment extends BaseFragment implements SubjectTypeAdap
}
public void onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.setOnTouchListener(this);
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
mIsTouchScreen = true;
break;
return true;
case MotionEvent.ACTION_UP:
mIsTouchScreen = false;
break;
return true;
}
return false;
}
@Subscribe(threadMode = ThreadMode.MAIN)

View File

@ -0,0 +1,176 @@
package com.gh.gamecenter.subject;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import com.gh.base.fragment.BaseFragment;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.SubjectHeadEntity;
import com.gh.gamecenter.retrofit.JSONObjectResponse;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.lightgame.adapter.BaseFragmentPagerAdapter;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.HttpException;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
* Created by CsHeng on 18/12/2017.
*/
public class SubjectWrapperFragment extends BaseFragment {
@BindView(R.id.subject_viewpager)
ViewPager mViewPager;
@BindView(R.id.subject_tab)
TabLayout mTabLayout;
@BindView(R.id.reuse_ll_loading)
LinearLayout mLoading;
@BindView(R.id.reuse_no_connection)
View mNoConn;
private String mId;
private String mName;
@Override
protected int getLayoutId() {
return R.layout.fragment_subject_wrapper;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (getArguments().getBundle(EntranceUtils.KEY_DATA) != null) {
args = getArguments().getBundle(EntranceUtils.KEY_DATA);
}
mId = args.getString(EntranceUtils.KEY_ID);
mName = args.getString(EntranceUtils.KEY_NAME);
setNavigationTitle(mName);
if (TextUtils.isEmpty(mName) && !TextUtils.isEmpty(mId)) {
getSubjectName(mId);
} else {
loadSubjectType();
}
}
@OnClick(R.id.reuse_no_connection)
public void onClick(View view) {
switch (view.getId()) {
case R.id.reuse_no_connection:
mNoConn.setVisibility(View.GONE);
mLoading.setVisibility(View.VISIBLE);
loadSubjectType();
break;
}
}
private void getSubjectName(String id) {
RetrofitManager.getInstance(getContext()).getApi()
.getSubjectName(id)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new JSONObjectResponse() {
@Override
public void onResponse(JSONObject response) {
try {
String name = response.getString("name");
setNavigationTitle(name);
getArguments().putString(EntranceUtils.KEY_NAME, name);
loadSubjectType();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(HttpException e) {
super.onFailure(e);
setNavigationTitle("专题");
getArguments().putString(EntranceUtils.KEY_NAME, "专题");
loadSubjectType();
}
});
}
private void loadSubjectType() {
RetrofitManager.getInstance(getContext()).getApi()
.getColumnSettings(mId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<SubjectHeadEntity>() {
@Override
public void onResponse(SubjectHeadEntity response) {
super.onResponse(response);
mLoading.setVisibility(View.GONE);
List<String> content = response.getTypeEntity().getContent();
content.add(0, "全部");
initView(response);
}
@Override
public void onFailure(HttpException e) {
super.onFailure(e);
mLoading.setVisibility(View.GONE);
mNoConn.setVisibility(View.VISIBLE);
}
});
}
private void initView(SubjectHeadEntity headEntity) {
SubjectHeadEntity.TypeEntity typeEntity = headEntity.getTypeEntity();
if (typeEntity == null) {
return;
}
if ("tile".equals(typeEntity.getLayout())) {
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
Bundle clone = (Bundle) getArguments().clone();
clone.putString(EntranceUtils.KEY_TAGTYPE, headEntity.getTag());
clone.putStringArrayList("contentTitle", new ArrayList<>(typeEntity.getContent()));
SubjectTileFragment tileFragment = new SubjectTileFragment();
tileFragment.setArguments(clone);
transaction.add(R.id.subject_tiled, tileFragment);
transaction.commit();
} else {
List<String> tagList = typeEntity.getContent();
if (tagList.size() > 1) {
mTabLayout.setVisibility(View.VISIBLE);
}
List<Fragment> fragments = new ArrayList<>();
for (String tag : tagList) {
mTabLayout.addTab(mTabLayout.newTab().setText(tag));
Bundle clone = (Bundle) getArguments().clone();
clone.putString(EntranceUtils.KEY_TYPE, tag);
clone.putString(EntranceUtils.KEY_TAGTYPE, headEntity.getTag());
fragments.add(SubjectListFragment.newInstance(clone));
}
BaseFragmentPagerAdapter adapter =
BaseFragmentPagerAdapter.newInstance(getChildFragmentManager(), fragments, tagList);
mViewPager.setAdapter(adapter);
mTabLayout.setupWithViewPager(mViewPager);
// mTabLayout.setTabsFromPagerAdapter(adapter);
}
}
}

View File

@ -0,0 +1,338 @@
package com.halo.assistant.fragment;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
import com.gh.base.fragment.BaseFragment;
import com.gh.common.util.CheckLoginUtils;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.adapter.VoteAdapter;
import com.gh.gamecenter.entity.UserDataEntity;
import com.gh.gamecenter.entity.VersionVoteEntity;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.lightgame.utils.Util_System_Keyboard;
import com.lightgame.utils.Utils;
import org.json.JSONException;
import org.json.JSONObject;
import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.HttpException;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
* Created by CsHeng on 18/12/2017.
*/
public class VoteFragment extends BaseFragment<String> implements SwipeRefreshLayout.OnRefreshListener,
VoteAdapter.OnAddVoteListener {
@BindView(R.id.vote_rv)
RecyclerView mVoteRv;
@BindView(R.id.vote_refresh)
SwipeRefreshLayout mVoteRefresh;
@BindView(R.id.vote_loading)
ProgressBarCircularIndeterminate mVoteLoading;
@BindView(R.id.reuse_no_connection)
LinearLayout mNoConnection;
@BindView(R.id.vote_add_tv)
TextView mAddTv;
private VoteAdapter mAdapter;
private String mGameId;
Runnable runnable = new Runnable() {
@Override
public void run() {
mAdapter = new VoteAdapter(getContext(), VoteFragment.this, VoteFragment.this, mGameId);
mVoteRv.setAdapter(mAdapter);
}
};
private LinearLayoutManager layoutManager;
@Override
protected int getLayoutId() {
return R.layout.fragment_vote;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
String gameName = args.getString(EntranceUtils.KEY_GAMENAME);
mGameId = args.getString(EntranceUtils.KEY_GAMEID);
setNavigationTitle(getString(R.string.title_vote_formatable, gameName));
layoutManager = new LinearLayoutManager(getContext());
mVoteRv.setLayoutManager(layoutManager);
mAdapter = new VoteAdapter(getContext(), this, this, mGameId);
mVoteRv.setAdapter(mAdapter);
mVoteRefresh.setColorSchemeResources(R.color.theme);
mVoteRefresh.setOnRefreshListener(this);
mAddTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckLoginUtils.checkLogin(getContext(), new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
showAddVoteDialog();
}
});
}
});
mVoteRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE && mAdapter.isLoaded() && !mAdapter.isRemove()
&& mAdapter.getItemCount() == layoutManager.findLastVisibleItemPosition() + 1) {
mAdapter.getVersionVote(mAdapter.getItemCount() - 1);
}
}
});
}
@Override
public void loadDone() {
mVoteRefresh.setRefreshing(false);
mVoteLoading.setVisibility(View.GONE);
mVoteRv.setVisibility(View.VISIBLE);
mAddTv.setVisibility(View.GONE);
}
@Override
public void loadDone(final String obj) {
CheckLoginUtils.checkLogin(getContext(), new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
postVersionVote(obj, false); // 投票
}
});
}
@Override
public void loadError() {
mVoteRefresh.setRefreshing(false);
mNoConnection.setVisibility(View.VISIBLE);
mVoteRv.setVisibility(View.GONE);
mAddTv.setVisibility(View.GONE);
}
@Override
public void loadEmpty() {
mVoteRefresh.setRefreshing(false);
mAddTv.setVisibility(View.VISIBLE);
mVoteLoading.setVisibility(View.GONE);
}
private void showAddVoteDialog() {
final Dialog dialog = new Dialog(getContext());
View view = View.inflate(getContext(), R.layout.dialog_modify_nickname, null);
TextView title = (TextView) view.findViewById(R.id.dialog_nickname_title);
title.setText(R.string.vote_input_hint);
final EditText mEdtInput = (EditText) view.findViewById(R.id.dialog_nickname_input);
mEdtInput.setHint("");
mEdtInput.setSelection(mEdtInput.getText().length());
mEdtInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
String nickname = mEdtInput.getText().toString().trim();
if (TextUtils.isEmpty(nickname)) {
Utils.toast(getContext(), getString(R.string.vote_empty_hint));
return true;
}
postVersionVote(nickname, true);
dialog.dismiss();
return true;
}
return false;
}
});
// 取消按钮
TextView cancel = (TextView) view.findViewById(R.id.dialog_nickname_cancel);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
// 确定按钮
TextView confirm = (TextView) view.findViewById(R.id.dialog_nickname_confirm);
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String nickname = mEdtInput.getText().toString().trim();
if (TextUtils.isEmpty(nickname)) {
Utils.toast(getContext(), getString(R.string.vote_empty_hint));
return;
}
postVersionVote(nickname, true);
dialog.dismiss();
}
});
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Util_System_Keyboard.hideSoftKeyboard(getActivity());
}
});
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();
mVoteRv.postDelayed(new Runnable() {
@Override
public void run() {
Util_System_Keyboard.showSoftKeyboard(getContext(), mEdtInput);
}
}, 300);
}
private void postVersionVote(final String name, final boolean isNewVote) {
if (isNewVote) {
for (VersionVoteEntity voteEntity : mAdapter.getDataList()) {
if (name.equals(voteEntity.getName())) {
UserDataEntity userDataEntity = voteEntity.getUserData();
if (userDataEntity != null && userDataEntity.isVersionRequested()) {
toast(R.string.vote_success);
return;
}
}
}
}
final Dialog waitDialog = DialogUtils.showWaitDialog(getContext(), getString(R.string.vote_post));
JSONObject object = new JSONObject();
try {
object.put("name", name);
} catch (JSONException e) {
e.printStackTrace();
}
final RequestBody body = RequestBody.create(MediaType.parse("application/json"), object.toString());
RetrofitManager.getInstance(getContext()).getApi()
.postVersionVote(body, mGameId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<ResponseBody>() {
@Override
public void onResponse(ResponseBody response) {
super.onResponse(response);
waitDialog.dismiss();
try {
String string = response.string();
JSONObject responseObject = new JSONObject(string);
boolean cast = responseObject.getBoolean("cast");
String id = responseObject.getString("_id");
if (cast) {
Utils.toast(getContext(), getString(R.string.vote_success));
} else {
if (isNewVote) {
Utils.toast(getContext(), "已经存在相同的选项");
} else {
Utils.toast(getContext(), "你已经投过了");
}
}
if (!TextUtils.isEmpty(id)) {
mAdapter.voteCallBack(cast, isNewVote, id, name);
if (isNewVote) {
mVoteRv.scrollToPosition(mAdapter.getItemCount() - 1);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(HttpException e) {
super.onFailure(e);
if (e != null && e.code() == 403) {
try {
String string = e.response().errorBody().string();
JSONObject errorJson = new JSONObject(string);
String detail = errorJson.getString("detail");
if ("illegal".equals(detail)) {
Utils.toast(getContext(), getString(R.string.vote_illegal_hint));
}
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
toast(getString(R.string.post_failure_hint));
}
waitDialog.dismiss();
}
});
}
@OnClick(R.id.reuse_no_connection)
public void reconnection() { // 重新连接
mVoteRv.setVisibility(View.VISIBLE);
mVoteLoading.setVisibility(View.VISIBLE);
mNoConnection.setVisibility(View.GONE);
mVoteRefresh.postDelayed(runnable, 1000);
}
@Override
public void onRefresh() {
mVoteRefresh.postDelayed(runnable, 1000);
}
@Override
public void addVote() {
CheckLoginUtils.checkLogin(getActivity(), new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
showAddVoteDialog();
}
});
}
}

View File

@ -0,0 +1,354 @@
package com.halo.assistant.fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.gh.base.BaseActivity;
import com.gh.base.fragment.BaseFragment;
import com.gh.common.util.CheckLoginUtils;
import com.gh.common.util.CollectionUtils;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.common.util.ShareUtils;
import com.gh.gamecenter.MessageDetailActivity;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.CommentnumEntity;
import com.gh.gamecenter.entity.ToolBoxEntity;
import com.gh.gamecenter.entity.UserDataEntity;
import com.gh.gamecenter.message.MessageDetailFragment;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.google.gson.Gson;
import com.lightgame.listeners.OnBackPressedListener;
import com.tencent.tauth.Tencent;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.BindView;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
* Created by CsHeng on 18/12/2017.
* 网页浏览器页面
*/
public class WebFragment extends BaseFragment implements OnBackPressedListener {
public static final String KEY_ISTOOLS = "isTools";
public static final String KEY_ISCOLLECTIONTOOLS = "isCollectionTools";
@BindView(R.id.news_webview)
WebView webView;
@BindView(R.id.web_progressbar)
ProgressBar progressBar;
@BindView(R.id.web_comment)
TextView webComment;
@BindView(R.id.news_bottom)
RelativeLayout newsBottom;
@BindView(R.id.actionbar_tv_title)
TextView newsTitle;
MenuItem mMenuShare;
MenuItem mMenuCollect;
private ToolBoxEntity mToolBoxEntity;
private String newsId;
private int commentNum;
private boolean mIsTools;
private boolean mIsCollectionTools;
@Override
protected int getLayoutId() {
return R.layout.fragment_web;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case MessageDetailFragment.REQUEST_UPDATE_COMMENT:
webComment.setText(getString(R.string.web_newscomment_count, data.getExtras().getInt("commentNum")));
break;
case com.tencent.connect.common.Constants.REQUEST_QQ_SHARE:
case com.tencent.connect.common.Constants.REQUEST_QZONE_SHARE:
Tencent.onActivityResultData(requestCode, resultCode, data, ShareUtils.getInstance(getActivity()).QqShareListener);
break;
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_web, menu);
mMenuShare = menu.findItem(R.id.menu_share);
mMenuCollect = menu.findItem(R.id.menu_collect);
mMenuShare.setVisible(mIsTools);
mMenuCollect.setVisible(mIsTools);
if (mIsTools) {
mToolBoxEntity = getArguments().getParcelable(ToolBoxEntity.TAG);
mIsCollectionTools = getArguments().getBoolean(KEY_ISCOLLECTIONTOOLS, false);
if (mToolBoxEntity != null && mToolBoxEntity.getUserData() != null && mToolBoxEntity.getUserData().isToolkitFavorite()) {
mMenuCollect.setIcon(R.drawable.menu_ic_collect_select);
} else {
mMenuCollect.setIcon(R.drawable.menu_ic_collect_unselect);
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_share:
if (mMenuShare != null && mToolBoxEntity != null) {
if (getActivity() instanceof BaseActivity) {
((BaseActivity) getActivity()).showShare(
mToolBoxEntity.getUrl(), mToolBoxEntity.getDes(),
mToolBoxEntity.getIcon(), mToolBoxEntity.getName(),
null, true);
}
}
break;
case R.id.menu_collect:
CheckLoginUtils.checkLogin(getActivity(), new CheckLoginUtils.OnLoggenInListener() {
@Override
public void onLoggedIn() {
mMenuCollect.setEnabled(false);
if (mToolBoxEntity.getUserData() != null && mToolBoxEntity.getUserData().isToolkitFavorite()) {
CollectionUtils.INSTANCE.deleteCollection(getContext(), mToolBoxEntity.getId(),
CollectionUtils.CollectionType.toolkit,
new CollectionUtils.OnCollectionListener() {
@Override
public void onSuccess() {
mToolBoxEntity.getUserData().setToolkitFavorite(false);
mMenuCollect.setEnabled(true);
mMenuCollect.setIcon(R.drawable.menu_ic_collect_unselect);
toast(getString(R.string.collection_cancel));
}
@Override
public void onError() {
mMenuCollect.setEnabled(true);
toast(getString(R.string.collection_cancel_failure));
}
});
} else {
Map<String, String> map = new HashMap<>();
map.put("_id", mToolBoxEntity.getId());
CollectionUtils.INSTANCE.postCollection(getContext(), new JSONObject(map).toString(),
CollectionUtils.CollectionType.toolkit,
new CollectionUtils.OnCollectionListener() {
@Override
public void onSuccess() {
UserDataEntity userData = mToolBoxEntity.getUserData();
if (userData == null) {
userData = new UserDataEntity();
mToolBoxEntity.setUserData(userData);
}
userData.setToolkitFavorite(true);
mMenuCollect.setEnabled(true);
mMenuCollect.setIcon(R.drawable.menu_ic_collect_select);
toast(getString(R.string.collection_success));
}
@Override
public void onError() {
mMenuCollect.setEnabled(true);
toast(getString(R.string.collection_failure));
}
});
}
}
});
break;
}
//TODO concern item only
return super.onOptionsItemSelected(item);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
String webUrl;
String webTitle;
Bundle args = getArguments();
mIsTools = args.getBoolean(KEY_ISTOOLS, false);
if (args.getBundle(EntranceUtils.KEY_DATA) != null) {
Bundle data = args.getBundle(EntranceUtils.KEY_DATA);
webUrl = data.getString(EntranceUtils.KEY_URL);
webTitle = "";
} else {
webUrl = args.getString(EntranceUtils.KEY_URL);
webTitle = args.getString(EntranceUtils.KEY_GAMENAME);
newsId = args.getString(EntranceUtils.KEY_NEWSID);
}
setNavigationTitle(webTitle);
webView.loadUrl(webUrl);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setSupportZoom(true);
//用webview打开url
webView.setWebViewClient(new WebViewClient() {
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, String url) {
// view.loadUrl(url);
// return true;
// }
// @Override
// public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
// 广告拦截操作
// if (!url.contains(xxxx)) {
// return new WebResourceResponse(null, null, null);
// }
// return null;
// }
});
// 页面里的下载跳转到自带浏览器
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
//设置加载进度条
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
progressBar.setProgress(newProgress);
if (newProgress == 100) {
progressBar.setVisibility(View.GONE);
if (newsBottom.getVisibility() == View.GONE && newsId != null) {
newsBottom.setVisibility(View.VISIBLE);
}
} else {
if (progressBar.getVisibility() == View.GONE) {
progressBar.setVisibility(View.VISIBLE);
}
}
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (TextUtils.isEmpty(newsId) && TextUtils.isEmpty(newsTitle.getText().toString()) && !mIsTools) {
newsTitle.setEllipsize(TextUtils.TruncateAt.END);
newsTitle.setPadding(DisplayUtils.dip2px(getContext(), 30), 0, DisplayUtils.dip2px(getContext(), 30), 0);
newsTitle.setSingleLine();
newsTitle.setText(title);
}
}
});
if (newsId != null) {
getNewsCommentNum();
}
if (mIsCollectionTools && mToolBoxEntity != null) {
getToolsById(); // 对比查看是否修改
}
}
private void getToolsById() {
RetrofitManager.getInstance(getContext())
.getApi()
.getToolBoxById(mToolBoxEntity.getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<List<ToolBoxEntity>>() {
@Override
public void onResponse(List<ToolBoxEntity> response) {
super.onResponse(response);
if (response.size() == 0) return;
ToolBoxEntity toolBoxEntity = response.get(0);
Gson gson = new Gson();
String newEntity = gson.toJson(toolBoxEntity);
String entity = gson.toJson(mToolBoxEntity);
if (!newEntity.equals(entity)) {
CollectionUtils.INSTANCE.patchCollection(getContext(), toolBoxEntity.getId(), CollectionUtils.CollectionType.toolkit);
}
}
});
}
public void getNewsCommentNum() {
RetrofitManager.getInstance(getContext()).getApi()
.getNewsCommentnum(newsId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<List<CommentnumEntity>>() {
@Override
public void onNext(List<CommentnumEntity> response) {
super.onNext(response);
if (response.size() > 0 && response.get(0).getNum() > 0) {
commentNum = response.get(0).getNum();
webComment.setText("查看评论(" + response.get(0).getNum() + "");
}
}
});
}
@OnClick(R.id.web_comment)
public void onWebClick(View v) {
if (v == webComment) {
Intent intent = MessageDetailActivity.getIntentById(getContext(), newsId, commentNum, null, mEntrance + "+(光环浏览器)");
startActivityForResult(intent, MessageDetailFragment.REQUEST_UPDATE_COMMENT);
}
}
@Override
public boolean onHandleBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
return true;
}
return false;
}
}

View File

@ -36,7 +36,7 @@ import retrofit2.HttpException;
/**
* Created by CsHeng on 14/12/2017.
* <p>
* 评论详情页面
* 评论详情页面-查看对话详情
* TODO: 16/11/17 时间比较紧 先暂时这么做 最好发表评论那块和评论详情整合
*/
public class CommentDetailFragment extends BaseFragment implements OnCommentCallBackListener {