Search in sources :

Example 1 with RefreshLayout

use of com.scwang.smart.refresh.layout.api.RefreshLayout in project Diary by HibaraAi.

the class MainActivity method bindViewAndSetListener.

@SuppressLint("NonConstantResourceId")
private void bindViewAndSetListener() {
    toolbar = findViewById(R.id.main_toolbar);
    SharedPreferences sharedPreferences = BaseUtils.getDefaultSharedPreferences();
    boolean showUsernameInBar = sharedPreferences.getBoolean("showUsernameInBar", false);
    if (showUsernameInBar) {
        CollapsingToolbarLayout toolbarLayout = findViewById(R.id.main_title);
        toolbarLayout.setTitle(MyConfiguration.getInstance().getUsername());
    }
    setSupportActionBar(toolbar);
    drawerLayout = findViewById(R.id.drawer_activity_main);
    navView = findViewById(R.id.nav_view);
    ActionBar actionBar = getSupportActionBar();
    if (null != actionBar) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.nav_home);
        actionBar.setTitle("");
    }
    // 侧滑菜单的按钮事件在这
    navView.setNavigationItemSelectedListener(item -> {
        switch(item.getItemId()) {
            case R.id.nav_mine:
                {
                    BaseUtils.gotoActivity(MainActivity.this, MineGameActivity.class);
                    break;
                }
            case R.id.nav_settings:
                {
                    BaseUtils.gotoActivity(MainActivity.this, SettingsActivity.class);
                    break;
                }
            case R.id.nav_help:
                {
                    BaseUtils.gotoActivity(MainActivity.this, HelpActivity.class);
                    break;
                }
            case R.id.nav_time:
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle("查找指定时间段的日记");
                    builder.setMessage("提示:如果时间段内的日记数量很多,则查找过程可能会很久,尽量缩短查找时间段。\n只选一个日期则查找当天的日记\n");
                    TextView timeOne = new TextView(MainActivity.this);
                    TextView timeTwo = new TextView(MainActivity.this);
                    timeOne.setOnClickListener(v -> {
                        Calendar calendar = Calendar.getInstance();
                        DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, (view, year, month, dayOfMonth) -> {
                            timeOne.setText(year + "-" + (month + 1) + "-" + dayOfMonth);
                        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
                        datePickerDialog.setCancelable(false);
                        datePickerDialog.show();
                    });
                    timeTwo.setOnClickListener(v -> {
                        Calendar calendar = Calendar.getInstance();
                        DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this, (view, year, month, dayOfMonth) -> {
                            timeTwo.setText(year + "-" + (month + 1) + "-" + dayOfMonth);
                        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
                        datePickerDialog.setCancelable(false);
                        datePickerDialog.show();
                    });
                    timeOne.setBackgroundResource(R.drawable.background_input);
                    timeOne.setHint("点击选择日期一");
                    timeTwo.setBackgroundResource(R.drawable.background_input);
                    timeTwo.setHint("点击选择日期二");
                    LinearLayout linearLayout = new LinearLayout(this);
                    linearLayout.setOrientation(LinearLayout.VERTICAL);
                    linearLayout.addView(timeOne);
                    linearLayout.addView(timeTwo);
                    builder.setView(linearLayout);
                    builder.setCancelable(false);
                    builder.setPositiveButton("确定", (dialog1, which) -> {
                        String timeOneStr = timeOne.getText().toString();
                        String timeTwoStr = timeTwo.getText().toString();
                        if (!"".equals(timeOneStr) || !"".equals(timeTwoStr)) {
                            if ("".equals(timeOneStr)) {
                                timeOneStr = timeTwoStr;
                            } else if ("".equals(timeTwoStr)) {
                                timeTwoStr = timeOneStr;
                            }
                            Intent intent = new Intent(MainActivity.this, DiaryListActivity.class);
                            intent.putExtra(DiaryListActivity.OPEN_FROM_TYPE, DiaryListActivity.OPEN_FROM_TIME_AXIS);
                            intent.putExtra(DiaryListActivity.DATE_ONE, timeOneStr);
                            intent.putExtra(DiaryListActivity.DATE_TWO, timeTwoStr);
                            startActivity(intent);
                        } else {
                            BaseUtils.longTipInCoast(MainActivity.this, "一个日期都不选?就是你这种不按照正常逻辑使用软件的人,才导致我们程序员要考虑各种各样的奇怪情况!");
                        }
                    });
                    builder.setNegativeButton("取消", null);
                    builder.show();
                    break;
                }
            case R.id.nav_temp:
                {
                    Intent intent = new Intent(MainActivity.this, DiaryListActivity.class);
                    intent.putExtra(DiaryListActivity.OPEN_FROM_TYPE, DiaryListActivity.OPEN_FROM_TEMP_DIARY);
                    startActivity(intent);
                    break;
                }
            case R.id.nav_asc:
                {
                    Intent intent = new Intent(this, PicturesActivity.class);
                    intent.putExtra(PicturesActivity.OPEN_FROM_TYPE, PicturesActivity.OPEN_FROM_VIDEO);
                    startActivity(intent);
                    break;
                }
            case R.id.nav_label:
                {
                    Intent intent = new Intent(MainActivity.this, DiaryListActivity.class);
                    intent.putExtra(DiaryListActivity.OPEN_FROM_TYPE, DiaryListActivity.OPEN_FROM_LABEL_LIST);
                    startActivity(intent);
                    break;
                }
            case R.id.nav_former_years:
                {
                    Intent intent = new Intent(MainActivity.this, TimeAscActivity.class);
                    intent.putExtra(TimeAscActivity.OPEN_FROM_TYPE, TimeAscActivity.OPEN_FROM_FORMER_YEARS);
                    startActivity(intent);
                    break;
                }
            case R.id.nav_special_day:
                {
                    BaseUtils.gotoActivity(this, SpecialDayActivity.class);
                    break;
                }
            case R.id.nav_pic:
                {
                    BaseUtils.gotoActivity(this, PicturesActivity.class);
                    break;
                }
            default:
                {
                    Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();
                    break;
                }
        }
        return true;
    });
    // 下拉刷新控件及RecyclerView
    recyclerView = findViewById(R.id.main_recyclerview);
    refreshLayout = findViewById(R.id.main_refresh);
    refreshLayout.setRefreshHeader(new BezierRadarHeader(this).setEnableHorizontalDrag(true).setPrimaryColor(Color.parseColor("#FA7298")));
    refreshLayout.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.FixedBehind));
    refreshLayout.setOnRefreshListener(refreshLayout -> {
        refreshDiary();
        refreshLayout.finishRefresh();
    });
    refreshLayout.setOnLoadMoreListener(refreshLayout -> {
        loadMoreDiary();
        refreshLayout.finishLoadMore();
    });
    initNavHeader();
}
Also used : MineGameActivity(cn.snowt.mine.MineGameActivity) AlertDialog(android.app.AlertDialog) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) LoginService(cn.snowt.diary.service.LoginService) Constant(cn.snowt.diary.util.Constant) Uri(android.net.Uri) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) SimpleResult(cn.snowt.diary.util.SimpleResult) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) SpinnerStyle(com.scwang.smart.refresh.layout.constant.SpinnerStyle) DiaryAdapter(cn.snowt.diary.adapter.DiaryAdapter) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ActionBar(androidx.appcompat.app.ActionBar) Manifest(android.Manifest) DatePickerDialog(android.app.DatePickerDialog) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MyConfiguration(cn.snowt.diary.util.MyConfiguration) ContextCompat(androidx.core.content.ContextCompat) DiaryVo(cn.snowt.diary.vo.DiaryVo) R(cn.snowt.diary.R) MineGameActivity(cn.snowt.mine.MineGameActivity) AlertDialog(android.app.AlertDialog) List(java.util.List) Nullable(androidx.annotation.Nullable) TextView(android.widget.TextView) DiaryServiceImpl(cn.snowt.diary.service.impl.DiaryServiceImpl) Toolbar(androidx.appcompat.widget.Toolbar) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DiaryService(cn.snowt.diary.service.DiaryService) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) NavigationView(com.google.android.material.navigation.NavigationView) Intent(android.content.Intent) RefreshLayout(com.scwang.smart.refresh.layout.api.RefreshLayout) PermissionUtils(cn.snowt.diary.util.PermissionUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) Calendar(java.util.Calendar) Toast(android.widget.Toast) Menu(android.view.Menu) Settings(android.provider.Settings) BezierRadarHeader(com.scwang.smart.refresh.header.BezierRadarHeader) Build(android.os.Build) DialogInterface(android.content.DialogInterface) ActivityCompat(androidx.core.app.ActivityCompat) GravityCompat(androidx.core.view.GravityCompat) CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) LoginServiceImpl(cn.snowt.diary.service.impl.LoginServiceImpl) BallPulseFooter(com.scwang.smart.refresh.footer.BallPulseFooter) Color(android.graphics.Color) Glide(com.bumptech.glide.Glide) MyConfigurationServiceImpl(cn.snowt.diary.service.impl.MyConfigurationServiceImpl) SharedPreferences(android.content.SharedPreferences) BaseUtils(cn.snowt.diary.util.BaseUtils) EditText(android.widget.EditText) MyConfigurationService(cn.snowt.diary.service.MyConfigurationService) SharedPreferences(android.content.SharedPreferences) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) Intent(android.content.Intent) BallPulseFooter(com.scwang.smart.refresh.footer.BallPulseFooter) CollapsingToolbarLayout(com.google.android.material.appbar.CollapsingToolbarLayout) TextView(android.widget.TextView) BezierRadarHeader(com.scwang.smart.refresh.header.BezierRadarHeader) ActionBar(androidx.appcompat.app.ActionBar) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 2 with RefreshLayout

use of com.scwang.smart.refresh.layout.api.RefreshLayout in project wanandroid by KnightAndroid.

the class HomeRecommendFragment method initView.

@Override
protected void initView(Bundle savedInstanceState) {
    mDatabind.setClick(new ProxyClick());
    EventBus.getDefault().register(this);
    mSkeletonScreen = Skeleton.bind(mDatabind.flTest).load(R.layout.activity_home_skeleton).duration(1200).angle(0).show();
    bindHeadView();
    mTopArticleAdapter = new TopArticleAdapter(new ArrayList<>());
    SetInitCustomView.initSwipeRecycleview(home_top_article_rv, new LinearLayoutManager(getActivity()), mTopArticleAdapter, false);
    mOfficialAccountAdapter = new OfficialAccountAdapter(new ArrayList<>());
    mHomeArticleAdapter = new HomeArticleAdapter(new ArrayList<>());
    SetInitCustomView.initSwipeRecycleview(mDatabind.homeRecommendArticleBody, new LinearLayoutManager(getActivity()), mHomeArticleAdapter, true);
    topArticleFootView = LayoutInflater.from(getActivity()).inflate(R.layout.home_toparticle_foot, null);
    topArticleFootView.findViewById(R.id.home_ll_seemorearticles).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            HomeArticleLogic.getInstance().setArrowAnimate(mTopArticleAdapter, topArticleFootView.findViewById(R.id.home_iv_toparticlearrow), isShowOnlythree);
            isShowOnlythree = !isShowOnlythree;
        }
    });
    mDatabind.homeIconFab.setBackgroundTintList(ColorUtils.createColorStateList(CacheUtils.getThemeColor(), CacheUtils.getThemeColor()));
    initTopAdapterClick();
    initOfficialAccountClick();
    initArticleListener();
    initTwoLevel();
    mDatabind.homeRefreshLayout.setOnMultiListener(new SimpleMultiListener() {

        @Override
        public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
        }

        @Override
        public void onRefresh(@NonNull RefreshLayout refreshLayout) {
            lazyLoadData();
        }

        @Override
        public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
            if (oldState == RefreshState.TwoLevel) {
                mDatabind.homeTwoLevelContent.animate().alpha(0).setDuration(0);
            } else if (oldState == RefreshState.TwoLevelReleased) {
                openTwoLevel = true;
                mDatabind.homeIconFab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.base_icon_bottom));
            } else if (oldState == RefreshState.TwoLevelFinish) {
                openTwoLevel = false;
                mDatabind.homeIconFab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.base_icon_up));
            }
        }
    });
    mDatabind.homeTwoLevelHeader.setOnTwoLevelListener(new OnTwoLevelListener() {

        @Override
        public boolean onTwoLevel(@NonNull RefreshLayout refreshLayout) {
            mDatabind.homeTwoLevelContent.animate().alpha(1).setDuration(1000);
            return true;
        }
    });
    mDatabind.homeTwoLevelHeader.setEnablePullToCloseTwoLevel(false);
    mDatabind.homeRefreshLayout.setEnableLoadMore(true);
    mDatabind.homeRefreshLayout.setOnLoadMoreListener(this);
}
Also used : RefreshHeader(com.scwang.smart.refresh.layout.api.RefreshHeader) ArrayList(java.util.ArrayList) HomeArticleAdapter(com.knight.wanandroid.module_home.module_adapter.HomeArticleAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) TextView(android.widget.TextView) SetInitCustomView(com.knight.wanandroid.library_widget.SetInitCustomView) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) OfficialAccountAdapter(com.knight.wanandroid.module_home.module_adapter.OfficialAccountAdapter) SimpleMultiListener(com.scwang.smart.refresh.layout.simple.SimpleMultiListener) RefreshLayout(com.scwang.smart.refresh.layout.api.RefreshLayout) OnTwoLevelListener(com.scwang.smart.refresh.header.listener.OnTwoLevelListener) RefreshState(com.scwang.smart.refresh.layout.constant.RefreshState) TopArticleAdapter(com.knight.wanandroid.module_home.module_adapter.TopArticleAdapter)

Example 3 with RefreshLayout

use of com.scwang.smart.refresh.layout.api.RefreshLayout in project wanandroid by KnightAndroid.

the class SquareFragment method initView.

@Override
protected void initView(Bundle savedInstanceState) {
    mDatabind.setClick(new ProcyClick());
    loadLoading(mDatabind.squareSharearticleFreshlayout);
    mHotKeyAdapter = new HotKeyAdapter(new ArrayList<SearchHotKeyEntity>());
    mSquareArticleAdapter = new SquareArticleAdapter(new ArrayList<SquareArticleEntity>());
    initListener();
    FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(getActivity());
    // 方向 主轴为水平方向,起点在左端
    flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);
    // 左对齐
    flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START);
    // flexboxLayoutManager.setAlignItems(AlignItems.CENTER);
    SetInitCustomView.initSwipeRecycleview(mDatabind.squareSearchhotRv, flexboxLayoutManager, mHotKeyAdapter, false);
    SetInitCustomView.initSwipeRecycleview(mDatabind.squareArticleRv, new LinearLayoutManager(getActivity()), mSquareArticleAdapter, true);
    mDatabind.squareSharearticleFreshlayout.setOnRefreshListener(this);
    mDatabind.squareSharearticleFreshlayout.setOnLoadMoreListener(this);
    EventBus.getDefault().register(this);
    View QuestionMenu = LayoutInflater.from(getActivity()).inflate(R.layout.square_question_activity, null);
    mSquareQuestionAdapter = new SquareQuestionAdapter(new ArrayList<>());
    initAdapterListener();
    baserecycleview = QuestionMenu.findViewById(R.id.base_body_rv);
    smartRefreshLayout = (SmartRefreshLayout) QuestionMenu.findViewById(R.id.include_square_question);
    tv_question_title = ((TextView) QuestionMenu.findViewById(R.id.square_question_tv_title));
    tv_question_title.setText(getString(R.string.square_question));
    smartRefreshLayout.setOnRefreshListener(refreshLayout -> {
        questionPage = 1;
        mPresenter.requestSquareQuestion(questionPage);
    });
    smartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
            mPresenter.requestSquareQuestion(questionPage);
        }
    });
    SetInitCustomView.initSwipeRecycleview(baserecycleview, new LinearLayoutManager(getActivity()), mSquareQuestionAdapter, true);
    mDatabind.squareRoot.addView(QuestionMenu);
    LoadSir loadSir = LoadSir.getDefault();
    mViewLoadService = loadSir.register(QuestionMenu.findViewById(R.id.include_square_question), new Callback.OnReloadListener() {

        @Override
        public void onReload(View v) {
            mViewLoadService.showCallback(LoadCallBack.class);
        }
    });
    mViewLoadService.showCallback(LoadCallBack.class);
    mRightLottieAnimation = new RightLottieAnimation.GuillotineBuilder(QuestionMenu, QuestionMenu.findViewById(R.id.square_question_lefticon), mDatabind.squareIvQuestion, mSquareQuestionAdapter).setStartDelay(RIPPLE_DURATION).setActionBarViewForAnimation(mDatabind.squareToolbar).setClosedOnStart(true).setGuillotineListener(new RightLottieListener() {

        @Override
        public void onRightLottieOpened() {
            mDatabind.squareFabUp.setVisibility(View.GONE);
            mViewLoadService.showCallback(LoadCallBack.class);
            mPresenter.requestSquareQuestion(questionPage);
        }

        @Override
        public void onRightLottieClosed() {
            questionPage = 1;
            mDatabind.squareFabUp.setVisibility(View.VISIBLE);
        }
    }).build();
}
Also used : OnLoadMoreListener(com.scwang.smart.refresh.layout.listener.OnLoadMoreListener) RightLottieListener(com.knight.wanandroid.library_widget.lottie.RightLottieListener) HotKeyAdapter(com.knight.wanandroid.module_square.module_adapter.HotKeyAdapter) SquareArticleAdapter(com.knight.wanandroid.module_square.module_adapter.SquareArticleAdapter) FlexboxLayoutManager(com.google.android.flexbox.FlexboxLayoutManager) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) TextView(android.widget.TextView) SetInitCustomView(com.knight.wanandroid.library_widget.SetInitCustomView) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) SquareQuestionAdapter(com.knight.wanandroid.module_square.module_adapter.SquareQuestionAdapter) RefreshLayout(com.scwang.smart.refresh.layout.api.RefreshLayout) SmartRefreshLayout(com.scwang.smart.refresh.layout.SmartRefreshLayout) LoadCallBack(com.knight.wanandroid.library_base.loadsir.LoadCallBack) TextView(android.widget.TextView) LoadSir(com.kingja.loadsir.core.LoadSir)

Example 4 with RefreshLayout

use of com.scwang.smart.refresh.layout.api.RefreshLayout in project xxf_android by NBXXF.

the class BaseApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Log.d("====>app", "app:" + ApplicationInitializer.applicationContext);
    Toast.makeText(this, "yes:" + ApplicationInitializer.applicationContext, Toast.LENGTH_LONG).show();
    INSTANCE = this;
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            Log.e("=============>", "t:" + Thread.currentThread().getName(), throwable);
        }
    });
    XXF.init(new XXF.Builder(this, new ProgressHUDFactory.ProgressHUDProvider() {

        @Override
        public ProgressHUD onCreateProgressHUD(LifecycleOwner lifecycleOwner) {
            if (lifecycleOwner instanceof FragmentActivity) {
                return new XXFLoadingDialog((FragmentActivity) lifecycleOwner);
            } else if (lifecycleOwner instanceof Fragment) {
                return new XXFLoadingDialog(((Fragment) lifecycleOwner).getContext());
            }
            return null;
        }
    }).setUserInfoProvider(new XXFUserInfoProvider() {

        @Override
        public String getUserId() {
            return "xxx_7764";
        }
    }).setErrorHandler(new BiConsumer<Integer, Throwable>() {

        @Override
        public void accept(Integer flag, Throwable throwable) throws Throwable {
            ToastUtils.showToast("error:" + throwable, ToastUtils.ToastType.ERROR, flag);
        }
    }));
    // 可做本module 相关sdk初始化
    // 设置全局的Header构建器
    SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {

        @NonNull
        @Override
        public RefreshHeader createRefreshHeader(@NonNull Context context, @NonNull RefreshLayout layout) {
            return new XXFJumpRefreshHeader(context);
        }
    });
    SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {

        @NonNull
        @Override
        public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
            return new XXFJumpRefreshFooter(context);
        }
    });
    // XXFStateLayout.setDefaultEmptyText(R.string.app_name);
    List<Integer> ignores = new ArrayList<>();
    ignores.addAll(ResourcesUtil.getStringResources(androidx.appcompat.R.class));
    ignores.addAll(ResourcesUtil.getDrawableResources(androidx.appcompat.R.class));
    // ResourcesUtil.checkResources(ignores);
    setVmPolicy();
}
Also used : RefreshHeader(com.scwang.smart.refresh.layout.api.RefreshHeader) XXFJumpRefreshHeader(com.xxf.view.refresh.XXFJumpRefreshHeader) XXFJumpRefreshFooter(com.xxf.view.refresh.XXFJumpRefreshFooter) XXF(com.xxf.arch.XXF) ArrayList(java.util.ArrayList) Fragment(androidx.fragment.app.Fragment) XXFUserInfoProvider(com.xxf.arch.core.XXFUserInfoProvider) XXFLoadingDialog(com.xxf.view.loading.XXFLoadingDialog) DefaultRefreshFooterCreator(com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator) RefreshLayout(com.scwang.smart.refresh.layout.api.RefreshLayout) SmartRefreshLayout(com.scwang.smart.refresh.layout.SmartRefreshLayout) NonNull(androidx.annotation.NonNull) Context(android.content.Context) XXFJumpRefreshFooter(com.xxf.view.refresh.XXFJumpRefreshFooter) RefreshFooter(com.scwang.smart.refresh.layout.api.RefreshFooter) DefaultRefreshHeaderCreator(com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator) XXFJumpRefreshHeader(com.xxf.view.refresh.XXFJumpRefreshHeader) FragmentActivity(androidx.fragment.app.FragmentActivity) BiConsumer(io.reactivex.rxjava3.functions.BiConsumer) LifecycleOwner(androidx.lifecycle.LifecycleOwner)

Example 5 with RefreshLayout

use of com.scwang.smart.refresh.layout.api.RefreshLayout in project iot-device-java by tencentyun.

the class TmeMainActivity method initView.

private void initView() {
    mGetSongBtn = findViewById(R.id.request_song);
    mSearchIv = findViewById(R.id.search);
    mPreIv = findViewById(R.id.iv_pre);
    mNextIv = findViewById(R.id.iv_next);
    mPlayIv = findViewById(R.id.iv_play);
    mPlayModeIv = findViewById(R.id.iv_play_mode);
    mInputEt = findViewById(R.id.input);
    mCurrentSongTv = findViewById(R.id.tv_current_song);
    mPlayList = findViewById(R.id.play_list);
    mSmartRefreshLayout = findViewById(R.id.smart_refreshLayout);
    mTimeTv = findViewById(R.id.tv_time);
    mSeekBar = findViewById(R.id.sb_seek_bar);
    mVolumeSeekBar = findViewById(R.id.sb_volume);
    mSwitch = findViewById(R.id.tb_switch);
    mSpinner = findViewById(R.id.sp_quality);
    mSmartRefreshLayout.setEnableLoadMore(true);
    mSmartRefreshLayout.setRefreshFooter(new ClassicsFooter(this));
    mGetSongBtn.setOnClickListener(this);
    mSearchIv.setOnClickListener(this);
    mPreIv.setOnClickListener(this);
    mNextIv.setOnClickListener(this);
    mPlayIv.setOnClickListener(this);
    mPlayModeIv.setOnClickListener(this);
    mPlayList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mPlayList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    mAdapter = new SongListAdapter(this, mSongList);
    mAdapter.setOnItemClickListener(new SongListAdapter.ItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Song song = mSongList.get(position);
            mCurrentSongTv.setText(song.songName + "-" + song.singerName);
            playSong(position);
        }
    });
    mPlayList.setAdapter(mAdapter);
    mSmartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore(RefreshLayout refreshLayout) {
            refreshLayout.finishLoadMore();
            page++;
            if (operationType == TYPE_SEARCH) {
                doSearch(keyword);
            } else if (operationType == TYPE_SONG_LIST) {
                getSongListById(songListId, songListType);
            }
        }
    });
    mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                TXLog.d(TAG, "seek =" + seekValue);
                seekValue = progress;
                UltimateSongPlayer.getInstance().seekTo(seekValue * 1000);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            mIsSeekBarTouching = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (seekValue >= 60) {
                SongInfo songInfo = UltimateSongPlayer.getInstance().getSongInfo();
                if (songInfo != null && songInfo.isTryListen()) {
                    TmeMainActivity.this.runOnUiThread(() -> ToastUtil.showS("当前歌曲只支持试听60秒~"));
                }
            }
            UltimateSongPlayer.getInstance().seekTo(seekValue * 1000);
            mIsSeekBarTouching = false;
            reportProperty(Common.PROPERTY_PLAY_POSITION, seekValue);
        }
    });
    mVolumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                TXLog.d(TAG, "seek =" + volumeSeekValue);
                volumeSeekValue = progress;
                mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, AudioManager.FLAG_PLAY_SOUND);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            int volume = (int) ((volumeSeekValue / (maxVolume * 1.00)) * Common.TOTOAL_VOLUME_DURATION);
            reportProperty(Common.PROPERTY_VOLUME, volume);
        }
    });
    mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (mDataTemplateSample != null)
                    return;
                mDataTemplateSample = new TmeDataTemplateSample(TmeMainActivity.this, mBrokerURL, mProductID, mDevName, mDevPSK, new SelfMqttActionCallBack(mProductID, mDevName), JSON_FILE_NAME, new SelfDownStreamCallBack(), mAuthCallback);
                mDataTemplateSample.connect();
            } else {
                if (mDataTemplateSample == null)
                    return;
                mDataTemplateSample.disconnect();
                mDataTemplateSample = null;
            }
        }
    });
    mSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, qualityStrArray));
    mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (isGetStatusReply) {
                UltimateSongPlayer.getInstance().changeQuality(qualities[position]);
                isGetStatusReply = false;
            } else {
                if (UltimateSongPlayer.getInstance().getCurrentPlayQuality() == qualities[position]) {
                    return;
                }
                // 当前歌曲详情
                SongInfo songInfo = UltimateSongPlayer.getInstance().getSongInfo();
                if (songInfo == null) {
                    ToastUtil.showS("无法切换音质");
                    parent.setSelection(0);
                    return;
                }
                if (songInfo.isTryListen()) {
                    ToastUtil.showS("试听中,无法切换音质");
                    parent.setSelection(0);
                    return;
                }
                if (songInfo.getSupportQualities().contains(qualities[position])) {
                    UltimateSongPlayer.getInstance().changeQuality(qualities[position]);
                    reportProperty(Common.PROPERTY_RECOMMEND_QUALITY, position);
                } else {
                    parent.setSelection(0);
                    ToastUtil.showS(String.format("当前歌曲不支持%s音质", qualityStrArray[position]));
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
}
Also used : OnLoadMoreListener(com.scwang.smart.refresh.layout.listener.OnLoadMoreListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ClassicsFooter(com.scwang.smart.refresh.footer.ClassicsFooter) Song(com.kugou.ultimatetv.entity.Song) RefreshLayout(com.scwang.smart.refresh.layout.api.RefreshLayout) SmartRefreshLayout(com.scwang.smart.refresh.layout.SmartRefreshLayout) SongListAdapter(com.tencent.iot.explorer.device.tme.adapter.SongListAdapter) SongInfo(com.kugou.ultimatetv.entity.SongInfo) TmeDataTemplateSample(com.tencent.iot.explorer.device.tme.data_template.TmeDataTemplateSample) SeekBar(android.widget.SeekBar) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton)

Aggregations

RefreshLayout (com.scwang.smart.refresh.layout.api.RefreshLayout)7 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)5 View (android.view.View)4 TextView (android.widget.TextView)4 SmartRefreshLayout (com.scwang.smart.refresh.layout.SmartRefreshLayout)4 ArrayList (java.util.ArrayList)4 OnLoadMoreListener (com.scwang.smart.refresh.layout.listener.OnLoadMoreListener)3 ImageView (android.widget.ImageView)2 NonNull (androidx.annotation.NonNull)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 SetInitCustomView (com.knight.wanandroid.library_widget.SetInitCustomView)2 OnRefreshListener (com.scwang.smart.refresh.layout.listener.OnRefreshListener)2 SwipeRecyclerView (com.yanzhenjie.recyclerview.SwipeRecyclerView)2 Manifest (android.Manifest)1 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 DatePickerDialog (android.app.DatePickerDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1