Search in sources :

Example 1 with BezierRadarHeader

use of com.scwang.smart.refresh.header.BezierRadarHeader 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 BezierRadarHeader

use of com.scwang.smart.refresh.header.BezierRadarHeader in project Diary by HibaraAi.

the class TimeAscActivity method bindViewAndSetListener.

@SuppressLint("NonConstantResourceId")
private void bindViewAndSetListener() {
    setSupportActionBar(findViewById(R.id.default_toolbar_inc));
    actionBar = getSupportActionBar();
    if (null != actionBar) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("时间升序浏览");
    }
    fab = findViewById(R.id.asc_fab);
    fab.setOnClickListener(v -> {
        recyclerView.scrollToPosition(0);
        BaseUtils.shortTipInSnack(this.recyclerView, "已返回顶部 OvO");
    });
    recyclerView = findViewById(R.id.asc_recyclerview);
    refreshLayout = findViewById(R.id.asc_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();
    });
}
Also used : BezierRadarHeader(com.scwang.smart.refresh.header.BezierRadarHeader) BallPulseFooter(com.scwang.smart.refresh.footer.BallPulseFooter) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 Manifest (android.Manifest)1 AlertDialog (android.app.AlertDialog)1 DatePickerDialog (android.app.DatePickerDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Color (android.graphics.Color)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Settings (android.provider.Settings)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1