@Override protected void loadData() { String thread_key = getIntent().getStringExtra(DATA_THREAD_KEY); String thread_id = getIntent().getStringExtra(DATA_THREAD_ID); isFromFreshNews = getIntent().getBooleanExtra(DATA_IS_FROM_FRESH_NEWS, false); if (isFromFreshNews) { mAdapter = new CommentAdapter(this, thread_id, true, this); if (TextUtils.isEmpty(thread_id) || thread_id.equals("0")) { ToastHelper.Short(FORBID_COMMENTS); finish(); } } else { mAdapter = new CommentAdapter(this, thread_key, false, this); if (TextUtils.isEmpty(thread_key) || thread_key.equals("0")) { ToastHelper.Short(FORBID_COMMENTS); finish(); } } mRecyclerView.setAdapter(mAdapter); if (isFromFreshNews) { mAdapter.loadData4FreshNews(); } else { mAdapter.loadData(); } loading.start(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); loadingCircle = (RotateLoading) findViewById(R.id.rotateloading); loadingCircle.start(); menu = (FloatingActionMenu) findViewById(R.id.menu); setStatusBarColor( findViewById(R.id.statusBarBackground), getResources().getColor(R.color.primary_color)); // color navigation bar on android 5 and higher setNavigationBarColor(); // get preferences to get phone number SharedPreferences settingsActivity = getSharedPreferences("PersonalAccount", Context.MODE_PRIVATE); myPhoneNumber = settingsActivity.getString(Constants.PHONE_NUMBER, "null"); // registering broadcasts regFriendLocationBroadcast(); regGettingFriendBroadcast(); regResponseContactSendingBroadcast(); map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); }
public void onLogin(View view) throws InterruptedException { rotateLoading.start(); String login = email.getText().toString().isEmpty() ? " " : email.getText().toString(); String password = pass.getText().toString().isEmpty() ? " " : pass.getText().toString(); Call<LoginResponse> call = API.login(login, password); call.enqueue( new Callback<LoginResponse>() { @Override public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) { Log.d("loginresponse", String.valueOf(response.body())); LoginResponse loginresponse = response.body(); if (loginresponse.success()) { Log.d("loginresponse.getId()", String.valueOf(loginresponse.getId())); SharedPreferences.Editor editor = mSettings.edit(); editor.putBoolean(APP_PREFERENCES_AUTH, true); editor.putInt(APP_PREFERENCES_UID, loginresponse.getId()); editor.apply(); Intent intent = new Intent(MainActivity.this, LanguagesActivity.class); startActivity(intent); } else { rotateLoading.stop(); Toast toast = Toast.makeText( getApplicationContext(), "Неправильный логин или пароль", Toast.LENGTH_LONG); toast.show(); } } @Override public void onFailure(Call<LoginResponse> call, Throwable t) { Log.d("onFailureLogin", "onFailureLogin"); rotateLoading.stop(); Toast toast = Toast.makeText( getApplicationContext(), "Неправильный логин или пароль", Toast.LENGTH_LONG); toast.show(); } }); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); /** 如果可以确定每个item的高度是固定的,设置这个选项可以提高性能 因为新鲜事的大小是不固定的,所以这里设置为false */ mRecyclerView.setHasFixedSize(false); mRecyclerView.setLoadMoreListener( new LoadMoreListener() { @Override public void loadMore() { // 数据加载过程放在mAdapter中,可以更好的实现解耦 mAdapter.loadNextPage(); } }); mSwipeRefreshLayout.setColorSchemeResources( android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); mSwipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mAdapter.loadFirst(); } }); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); mRecyclerView.setOnPauseListenerParams(false, true); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean isLargeMode = sp.getBoolean(SettingFragment.ENABLE_FRESH_BIG, true); mAdapter = new FreshNewsAdapter(getActivity(), mRecyclerView, this, isLargeMode); mRecyclerView.setAdapter(mAdapter); mAdapter.loadFirst(); loading.start(); }