2019-04-02 17:41:53 +08:00
|
|
|
|
package com.novelbook.android;
|
|
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
import android.support.design.widget.BottomNavigationView;
|
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
|
import android.support.v7.widget.AppCompatSpinner;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.support.design.widget.NavigationView;
|
|
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
|
import android.support.v7.app.ActionBarDrawerToggle;
|
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuItem;
|
2019-04-15 23:26:24 +08:00
|
|
|
|
import android.widget.RadioButton;
|
2019-04-14 23:17:31 +08:00
|
|
|
|
import android.widget.RadioGroup;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
2019-04-14 23:17:31 +08:00
|
|
|
|
import com.novelbook.android.Fragments.BasicFragment;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
import com.novelbook.android.Fragments.Fragment_Shelf;
|
|
|
|
|
import com.novelbook.android.Fragments.Fragment_bookStore;
|
2019-04-28 00:18:56 +08:00
|
|
|
|
import com.novelbook.android.Fragments.Fragment_booklist;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
import com.novelbook.android.Fragments.Fragment_paihang;
|
2019-04-21 10:57:20 +08:00
|
|
|
|
import com.novelbook.android.netsubscribe.BookSubscribe;
|
|
|
|
|
import com.novelbook.android.netutils.OnSuccessAndFaultListener;
|
|
|
|
|
import com.novelbook.android.netutils.OnSuccessAndFaultSub;
|
2019-05-05 23:31:19 +08:00
|
|
|
|
import com.novelbook.android.service.ServiceDownload;
|
2019-04-18 17:19:42 +08:00
|
|
|
|
import com.novelbook.android.utils.Config;
|
2019-04-14 23:17:31 +08:00
|
|
|
|
import com.novelbook.android.utils.Constants;
|
2019-04-23 22:45:08 +08:00
|
|
|
|
import com.novelbook.android.utils.GsonUtil;
|
2019-04-21 10:57:20 +08:00
|
|
|
|
import com.novelbook.android.utils.PageFactory;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-04-12 23:02:31 +08:00
|
|
|
|
|
2019-04-21 10:57:20 +08:00
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
import butterknife.BindView;
|
2019-04-14 23:17:31 +08:00
|
|
|
|
import butterknife.OnClick;
|
|
|
|
|
|
2019-04-10 22:19:06 +08:00
|
|
|
|
public class Main2Activity extends Activity_base
|
2019-04-02 17:41:53 +08:00
|
|
|
|
implements NavigationView.OnNavigationItemSelectedListener{//} , BasicFragment.OnFragmentInteractionListener {
|
|
|
|
|
public MyApp app ;
|
|
|
|
|
public static String TAG ="com.novelbook.android.Main2Activity";
|
2019-04-16 23:11:00 +08:00
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
// @BindView(R.id.fab)
|
|
|
|
|
// FloatingActionButton fab ;
|
|
|
|
|
@BindView(R.id.nav_view )
|
|
|
|
|
NavigationView navigationView;
|
|
|
|
|
@BindView(R.id.navigation )
|
|
|
|
|
BottomNavigationView botoomNavigation;
|
2019-04-14 23:17:31 +08:00
|
|
|
|
@BindView(R.id.rgSex)
|
|
|
|
|
RadioGroup rgSex;
|
2019-05-13 00:18:07 +08:00
|
|
|
|
// @BindView(R.id.tvUser)
|
|
|
|
|
// TextView tvUser;
|
|
|
|
|
|
2019-04-15 23:26:24 +08:00
|
|
|
|
private Config config;
|
2019-04-10 22:19:06 +08:00
|
|
|
|
@Override
|
|
|
|
|
public int getLayoutRes() {
|
|
|
|
|
return R.layout.activity_main2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void initViews() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2019-05-11 23:21:57 +08:00
|
|
|
|
getHostPolicy();
|
2019-04-02 17:41:53 +08:00
|
|
|
|
super.onCreate(savedInstanceState);
|
2019-04-25 02:01:18 +08:00
|
|
|
|
//PageFactory.createPageFactory(this);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
app =(MyApp) getApplicationContext();
|
|
|
|
|
// requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
|
2019-04-15 23:26:24 +08:00
|
|
|
|
config =Config.getInstance();
|
2019-04-10 22:19:06 +08:00
|
|
|
|
// ButterKnife.bind(this);
|
|
|
|
|
|
2019-04-15 23:26:24 +08:00
|
|
|
|
initialSexOption();
|
2019-05-13 00:18:07 +08:00
|
|
|
|
checkUpdate(true);
|
2019-04-25 02:01:18 +08:00
|
|
|
|
// getSearchTabTtitle();
|
2019-04-10 22:19:06 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-15 23:26:24 +08:00
|
|
|
|
void initialSexOption(){
|
|
|
|
|
Constants.SEX = config.getSexOption();
|
|
|
|
|
rgSex.clearCheck();
|
|
|
|
|
// ((RadioButton) rgSex.getChildAt(0)).setChecked(Constants.SEX ==1);
|
|
|
|
|
// ((RadioButton) rgSex.getChildAt(1)).setChecked(Constants.SEX ==2);
|
|
|
|
|
((RadioButton) rgSex.getChildAt(Constants.SEX-1)).setChecked(true);
|
|
|
|
|
Log.d(TAG, "onCreate: sexoption is" + Constants.SEX);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-10 22:19:06 +08:00
|
|
|
|
@Override
|
|
|
|
|
protected void setTitle() {
|
2019-04-11 18:05:41 +08:00
|
|
|
|
setTitle("");
|
2019-05-13 00:18:07 +08:00
|
|
|
|
|
2019-04-10 22:19:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void initData() {
|
2019-04-02 17:41:53 +08:00
|
|
|
|
creatToolbar();
|
|
|
|
|
setupNavi();
|
|
|
|
|
showHome();
|
2019-05-13 00:18:07 +08:00
|
|
|
|
// tvUser.setText(this.getPackageName());
|
2019-04-02 17:41:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String currentActiveFragment;
|
|
|
|
|
private void showFragment(Fragment fragment, String fragmentTag)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
FragmentManager fm = getSupportFragmentManager();
|
|
|
|
|
FragmentTransaction ft = fm.beginTransaction();
|
|
|
|
|
|
|
|
|
|
if (findViewById(R.id.realtabcontent) != null) { //realtabcontent
|
|
|
|
|
|
|
|
|
|
ft.replace(R.id.realtabcontent, fragment,fragmentTag);
|
|
|
|
|
|
|
|
|
|
ft.addToBackStack(null); //add to backstack.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try{
|
|
|
|
|
ft.add(R.id.realtabcontent, fragment,fragmentTag);
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
// Utils.logStackTrace(e, dTAG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentActiveFragment =fragmentTag;
|
|
|
|
|
// ft.setTransition(2500);//TRANSIT_FRAGMENT_OPEN
|
|
|
|
|
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
|
|
|
|
|
|
|
|
|
ft.commitAllowingStateLoss();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ActionBarDrawerToggle toggle;
|
|
|
|
|
private void creatToolbar() {
|
|
|
|
|
|
|
|
|
|
// toolbar= (Toolbar) findViewById(R.id.toolbar);
|
2019-04-11 18:05:41 +08:00
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
setSupportActionBar(toolbar);
|
2019-04-26 00:31:07 +08:00
|
|
|
|
getSupportActionBar().setHomeButtonEnabled(false);
|
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
// toolbar.setNavigationIcon(R.mipmap.ic_launcher_round);//设置导航栏图标
|
|
|
|
|
// toolbar.setLogo(R.mipmap.ic_launcher);//设置app logo
|
|
|
|
|
// toolbar.setTitle("Title");//设置主标题
|
|
|
|
|
// setTitle("titleaa");
|
|
|
|
|
// toolbar.setSubtitle("Subtitle");//设置子标题
|
2019-04-16 23:11:00 +08:00
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
int menuItemId = item.getItemId();
|
2019-04-20 00:26:49 +08:00
|
|
|
|
/* if (menuItemId == R.id.menuFenlei) {
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(Main2Activity.this, activity_cates.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
|
2019-04-20 00:26:49 +08:00
|
|
|
|
}else */
|
|
|
|
|
|
|
|
|
|
if(menuItemId == R.id.menuMore) {
|
2019-04-02 17:41:53 +08:00
|
|
|
|
showShelfMoreSheet();
|
|
|
|
|
}
|
|
|
|
|
else if(menuItemId == R.id.menuFinshi) {
|
|
|
|
|
udateShelfZhengli();
|
2019-04-15 23:26:24 +08:00
|
|
|
|
} if(menuItemId==R.id.menuSearch){
|
|
|
|
|
Intent intent = new Intent(Main2Activity.this,Activity_Search.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
}
|
2019-04-28 00:18:56 +08:00
|
|
|
|
if(menuItemId==R.id.menuHistory){
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(Main2Activity.this,Activity_paihangbang.class);
|
|
|
|
|
intent.putExtra(Activity_paihangbang.EXTR_HISTORY,"yes");
|
|
|
|
|
intent.putExtra(Activity_paihangbang.EXTR_TITLE,"我曾经看过的书");
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-04-16 23:11:00 +08:00
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
|
getMenuInflater().inflate(R.menu.main, menu);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-04-16 23:11:00 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
private void udateShelfZhengli() {
|
|
|
|
|
switchShelfZhengli(true);
|
|
|
|
|
}
|
|
|
|
|
Fragment_Shelf fragment_shelf;
|
|
|
|
|
public void setShelfFragment(Fragment_Shelf fragment_shelf){
|
|
|
|
|
this.fragment_shelf=fragment_shelf;
|
|
|
|
|
}
|
|
|
|
|
private void showShelfMoreSheet() {
|
|
|
|
|
{
|
|
|
|
|
if(fragment_shelf!=null)
|
|
|
|
|
fragment_shelf.showShelfMoreSheet();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setupNavi() {
|
|
|
|
|
|
|
|
|
|
//drawer
|
2019-05-13 00:18:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
navigationView = (NavigationView) findViewById(R.id.nav_view);
|
|
|
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
|
toggle = new ActionBarDrawerToggle(
|
|
|
|
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
|
|
|
|
drawer.addDrawerListener(toggle);
|
|
|
|
|
toggle.syncState();
|
|
|
|
|
|
2019-05-13 00:18:07 +08:00
|
|
|
|
// TextView tvuser= (TextView) navigationView. findViewById(R.id.tvUser);
|
|
|
|
|
// tvuser.setText(this.getPackageName());
|
2019-04-02 17:41:53 +08:00
|
|
|
|
// mTextMessage = (TextView) findViewById(R.id.message);
|
|
|
|
|
botoomNavigation = (BottomNavigationView) findViewById(R.id.navigation);
|
|
|
|
|
botoomNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBackPressed() {
|
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
|
} else {
|
|
|
|
|
super.onBackPressed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 23:11:00 +08:00
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-04-15 23:26:24 +08:00
|
|
|
|
/* @Override
|
2019-04-02 17:41:53 +08:00
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
|
if (id == R.id.action_settings) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-15 23:26:24 +08:00
|
|
|
|
if(id==R.id.menuSearch){
|
|
|
|
|
Intent intent = new Intent(this,Activity_Search.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
2019-04-15 23:26:24 +08:00
|
|
|
|
}*/
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
@SuppressWarnings("StatementWithEmptyBody")
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onNavigationItemSelected(MenuItem item) {
|
|
|
|
|
// Handle navigation view item clicks here.
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
|
|
if (id == R.id.nav_camera) {
|
|
|
|
|
// Handle the camera action
|
|
|
|
|
} else if (id == R.id.nav_gallery) {
|
2019-04-28 00:18:56 +08:00
|
|
|
|
Intent intent = new Intent(Main2Activity.this,Activity_paihangbang.class);
|
|
|
|
|
intent.putExtra(Activity_paihangbang.EXTR_HISTORY,"yes");
|
|
|
|
|
intent.putExtra(Activity_paihangbang.EXTR_TITLE,"我曾经看过的书");
|
|
|
|
|
startActivity(intent);
|
2019-05-05 23:31:19 +08:00
|
|
|
|
} else if (id == R.id.nav_huancun) {
|
|
|
|
|
startDownloadService();
|
|
|
|
|
Intent intent = new Intent(Main2Activity.this,Activity_cache.class);
|
|
|
|
|
startActivity(intent);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
} else if (id == R.id.nav_manage) {
|
|
|
|
|
|
|
|
|
|
} else if (id == R.id.nav_share) {
|
|
|
|
|
|
|
|
|
|
} else if (id == R.id.nav_send) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
|
|
drawer.closeDrawer(GravityCompat.START);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-05-05 23:31:19 +08:00
|
|
|
|
private void startDownloadService() {
|
|
|
|
|
Intent serviceIntent = new Intent(this, ServiceDownload.class);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-05-05 23:31:19 +08:00
|
|
|
|
startService(serviceIntent);
|
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
|
|
|
|
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.navigation_home:
|
|
|
|
|
//mTextMessage.setText(R.string.title_home);
|
|
|
|
|
bottomSelectedIndex =0;
|
|
|
|
|
showHome();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.navigation_dashboard:
|
|
|
|
|
// mTextMessage.setText(R.string.title_dashboard);
|
|
|
|
|
bottomSelectedIndex=1;
|
|
|
|
|
showBookStore();
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.navigation_notifications:
|
|
|
|
|
bottomSelectedIndex=2;
|
|
|
|
|
// mTextMessage.setText(R.string.title_notifications);
|
|
|
|
|
showPaihang();
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@BindView(R.id.sexSelect)
|
|
|
|
|
AppCompatSpinner spinner;
|
|
|
|
|
@BindView(R.id.toolbarTitle)
|
|
|
|
|
TextView txtTitle;
|
|
|
|
|
private int bottomSelectedIndex;
|
|
|
|
|
|
|
|
|
|
public void swithToolbarItems( ) {
|
|
|
|
|
|
|
|
|
|
Log.e( TAG, "swithToolbarItems: " );
|
2019-04-11 18:20:10 +08:00
|
|
|
|
boolean showToggle =true;//bottomSelectedIndex !=1;
|
2019-04-02 17:41:53 +08:00
|
|
|
|
boolean showSpinner = bottomSelectedIndex ==1;
|
|
|
|
|
boolean showTitle = bottomSelectedIndex !=1;
|
|
|
|
|
String title = bottomSelectedIndex==0?"我的书架":"排行榜";
|
2019-04-11 18:20:10 +08:00
|
|
|
|
// txtTitle.setVisibility(View.GONE);
|
2019-04-26 00:31:07 +08:00
|
|
|
|
toggle.setDrawerIndicatorEnabled(showToggle);
|
|
|
|
|
toggle.syncState();
|
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-04-14 23:17:31 +08:00
|
|
|
|
//spinner.setVisibility( showSpinner?View.VISIBLE:View.GONE);
|
|
|
|
|
rgSex.setVisibility( showSpinner?View.VISIBLE:View.GONE);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
supportInvalidateOptionsMenu();
|
|
|
|
|
//invalidateOptionsMenu();
|
|
|
|
|
|
|
|
|
|
if(bottomSelectedIndex==1) {
|
|
|
|
|
title ="";
|
|
|
|
|
}
|
2019-04-11 18:05:41 +08:00
|
|
|
|
txtTitle.setText(title);
|
2019-04-11 18:20:10 +08:00
|
|
|
|
// this.setTitle(title);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
Log.e(TAG, "onPrepareOptionsMenu");
|
|
|
|
|
|
|
|
|
|
menu.findItem(R.id.menuFinshi).setVisible(false);
|
|
|
|
|
// menu.findItem(R.id.menuSearch).setVisible(true);
|
|
|
|
|
if(bottomSelectedIndex==0) {
|
|
|
|
|
menu.findItem(R.id.menuFinshi).setVisible(isShelfZhengli);
|
|
|
|
|
if(isShelfZhengli){
|
2019-04-20 00:26:49 +08:00
|
|
|
|
// menu.findItem(R.id.menuFenlei).setVisible(false);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
menu.findItem(R.id.menuMore).setVisible(false);
|
|
|
|
|
menu.findItem(R.id.menuSearch).setVisible(false);
|
2019-04-28 00:18:56 +08:00
|
|
|
|
menu.findItem(R.id.menuHistory).setVisible(false);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
}else {
|
2019-04-20 00:26:49 +08:00
|
|
|
|
// menu.findItem(R.id.menuFenlei).setVisible(false);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
menu.findItem(R.id.menuMore).setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else if(bottomSelectedIndex==1) {
|
2019-04-20 00:26:49 +08:00
|
|
|
|
// menu.findItem(R.id.menuFenlei).setVisible(true);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
menu.findItem(R.id.menuMore).setVisible(false);
|
|
|
|
|
|
|
|
|
|
}else if(bottomSelectedIndex==2) {
|
2019-04-20 00:26:49 +08:00
|
|
|
|
// menu.findItem(R.id.menuFenlei).setVisible(false);
|
2019-04-02 17:41:53 +08:00
|
|
|
|
menu.findItem(R.id.menuMore).setVisible(false);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.onPrepareOptionsMenu(menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showHome() {
|
|
|
|
|
|
|
|
|
|
Fragment_Shelf fragment_Shelf = (Fragment_Shelf) getSupportFragmentManager()
|
|
|
|
|
.findFragmentByTag(Fragment_Shelf.getFTag());
|
|
|
|
|
if(fragment_Shelf==null) fragment_Shelf =new Fragment_Shelf();
|
|
|
|
|
showFragment(fragment_Shelf,Fragment_Shelf.getFTag());
|
|
|
|
|
swithToolbarItems();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void showBookStore() {
|
|
|
|
|
Fragment_bookStore fragment = (Fragment_bookStore) getSupportFragmentManager()
|
|
|
|
|
.findFragmentByTag(Fragment_bookStore.getFTag());
|
|
|
|
|
if(fragment ==null) fragment =new Fragment_bookStore();
|
|
|
|
|
showFragment(fragment , Fragment_bookStore.getFTag());
|
|
|
|
|
swithToolbarItems();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void showOther() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showPaihang(){
|
|
|
|
|
|
|
|
|
|
Fragment_paihang fragment = (Fragment_paihang) getSupportFragmentManager()
|
|
|
|
|
.findFragmentByTag(Fragment_paihang.getFTag());
|
|
|
|
|
if(fragment ==null) fragment =new Fragment_paihang();
|
|
|
|
|
showFragment(fragment ,Fragment_paihang.getFTag());
|
|
|
|
|
swithToolbarItems( );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long firstTime =0;
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
|
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
|
if( navigationView.isShown()){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
int cnt=0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long secondTime = System.currentTimeMillis();
|
|
|
|
|
if (secondTime - firstTime > 800) {//如果两次按键时间间隔大于800毫秒,则不退出
|
|
|
|
|
String msg= "再按一次将退出" ;
|
|
|
|
|
Toast.makeText( this, msg, Toast.LENGTH_SHORT).show();
|
|
|
|
|
firstTime = secondTime;//更新firstTime
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
// return super.onKeyUp(keyCode, event);
|
|
|
|
|
|
|
|
|
|
// return super.onKeyUp(keyCode, event);
|
|
|
|
|
// return false;
|
|
|
|
|
finish();
|
|
|
|
|
app.exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try{
|
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e){
|
|
|
|
|
Log.d("mainActivity","onkeyup出错" );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
// swithToolbarItems( );
|
|
|
|
|
// setTitle("title on resume");
|
2019-05-13 00:18:07 +08:00
|
|
|
|
// checkUpdate(true);
|
|
|
|
|
// getHostPolicy();
|
2019-04-02 17:41:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-21 10:57:20 +08:00
|
|
|
|
@Override
|
|
|
|
|
public void fillData() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setSexOption(){
|
2019-04-15 23:26:24 +08:00
|
|
|
|
int s = rgSex.getCheckedRadioButtonId() == R.id.radioButtonBoy ?1:2;
|
|
|
|
|
if(s!= Constants.SEX){
|
|
|
|
|
Constants.SEX=s;
|
|
|
|
|
config.setSexOption(s);
|
|
|
|
|
Fragment current = getSupportFragmentManager().findFragmentById(R.id.realtabcontent);
|
|
|
|
|
if (current != null && current instanceof BasicFragment){
|
2019-04-21 10:57:20 +08:00
|
|
|
|
|
2019-04-28 22:56:27 +08:00
|
|
|
|
((Fragment_bookStore)current).onSexSwitch();
|
2019-04-21 10:57:20 +08:00
|
|
|
|
|
2019-04-15 23:26:24 +08:00
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-04-15 23:26:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-14 23:17:31 +08:00
|
|
|
|
|
|
|
|
|
@OnClick({R.id.radioButtonBoy,R.id.radioButtonGirl})
|
|
|
|
|
void Onclick(View view){
|
2019-04-15 23:26:24 +08:00
|
|
|
|
|
2019-04-14 23:17:31 +08:00
|
|
|
|
switch (view.getId()) {
|
|
|
|
|
case R.id.radioButtonBoy:
|
2019-04-15 23:26:24 +08:00
|
|
|
|
setSexOption();
|
2019-04-14 23:17:31 +08:00
|
|
|
|
break;
|
|
|
|
|
case R.id.radioButtonGirl:
|
|
|
|
|
|
2019-04-15 23:26:24 +08:00
|
|
|
|
setSexOption();
|
2019-04-14 23:17:31 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
public void hideBottomNavi(){
|
|
|
|
|
botoomNavigation.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isShelfZhengli =false;
|
|
|
|
|
public void switchShelfZhengli(boolean finished){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(finished) {
|
|
|
|
|
isShelfZhengli = false;
|
|
|
|
|
swithToolbarItems();
|
|
|
|
|
botoomNavigation.setVisibility(View.VISIBLE);
|
|
|
|
|
fragment_shelf.initReceyleView();
|
2019-04-26 00:31:07 +08:00
|
|
|
|
toggle.setDrawerIndicatorEnabled(true);
|
|
|
|
|
toggle.syncState();
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
toggle.setDrawerIndicatorEnabled(false);
|
2019-04-26 00:31:07 +08:00
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
toggle.syncState();
|
2019-04-26 00:31:07 +08:00
|
|
|
|
|
2019-04-02 17:41:53 +08:00
|
|
|
|
supportInvalidateOptionsMenu();
|
|
|
|
|
isShelfZhengli = true;
|
|
|
|
|
botoomNavigation.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-21 10:57:20 +08:00
|
|
|
|
//----get master domain
|
|
|
|
|
|
2019-04-28 22:56:27 +08:00
|
|
|
|
private void getHostPolicy(){ //TODO: get masterdomain info
|
2019-04-21 10:57:20 +08:00
|
|
|
|
BookSubscribe.getMastDomain(new OnSuccessAndFaultSub(new OnSuccessAndFaultListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
|
|
|
|
|
|
// mFirstPage= gson.fromJson(result, FirstPage.class);
|
|
|
|
|
try {
|
|
|
|
|
JSONObject jsonObject = new JSONObject(result);
|
2019-05-11 23:21:57 +08:00
|
|
|
|
String resultstr = jsonObject.getString("hosts");
|
|
|
|
|
Config config =Config.createConfig(Main2Activity.this);
|
|
|
|
|
config.setBaseUrl(resultstr);
|
|
|
|
|
// config.setRootUrl( jsonObject.getString("masterDomains"));
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
2019-04-21 10:57:20 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
handler.sendEmptyMessage(1);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFault(String errorMsg) {
|
|
|
|
|
//失败
|
|
|
|
|
Log.d(TAG, "error on get firstpage: " + errorMsg);
|
|
|
|
|
handler.sendEmptyMessage(2);
|
|
|
|
|
}
|
|
|
|
|
}, this));
|
|
|
|
|
}
|
2019-04-02 17:41:53 +08:00
|
|
|
|
|
|
|
|
|
}
|