|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
package cc.niushuai.didicheck; |
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
|
import android.os.Bundle; |
|
|
|
|
import android.view.View; |
|
|
|
|
|
|
|
|
@ -9,14 +10,23 @@ import androidx.viewpager.widget.ViewPager;
@@ -9,14 +10,23 @@ import androidx.viewpager.widget.ViewPager;
|
|
|
|
|
import com.github.clans.fab.FloatingActionButton; |
|
|
|
|
import com.github.clans.fab.FloatingActionMenu; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import cc.niushuai.didicheck.biz.entity.CheckProject; |
|
|
|
|
import cc.niushuai.didicheck.biz.enums.CheckTypeEnum; |
|
|
|
|
import cc.niushuai.didicheck.biz.room.DBManager; |
|
|
|
|
import cc.niushuai.didicheck.databinding.ActivityMainBinding; |
|
|
|
|
import cc.niushuai.didicheck.ui.main.TabsPagerAdapter; |
|
|
|
|
import io.reactivex.Flowable; |
|
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers; |
|
|
|
|
import io.reactivex.functions.Consumer; |
|
|
|
|
import io.reactivex.schedulers.Schedulers; |
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
|
private ActivityMainBinding binding; |
|
|
|
|
private List<CheckProject> checkProjectList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
@ -32,28 +42,68 @@ public class MainActivity extends AppCompatActivity {
@@ -32,28 +42,68 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
ViewPager viewPager = binding.viewPager; |
|
|
|
|
viewPager.setAdapter(tabsPagerAdapter); |
|
|
|
|
|
|
|
|
|
initFloatingActionButtons(tabsPagerAdapter); |
|
|
|
|
|
|
|
|
|
binding.didiCheckMenu.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onMenuToggle(boolean opened) { |
|
|
|
|
if (opened) { |
|
|
|
|
buildFloatActionButtons(checkProjectList, getApplicationContext(), binding.didiCheckMenu, tabsPagerAdapter); |
|
|
|
|
} else { |
|
|
|
|
// 关闭时清除所有button
|
|
|
|
|
binding.didiCheckMenu.removeAllMenuButtons(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void fetchNewestActionButtonData() { |
|
|
|
|
Flowable<List<CheckProject>> listFlowable = DBManager.INSTANCE.checkProjectDao().listAll(); |
|
|
|
|
listFlowable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) |
|
|
|
|
.subscribe(new Consumer<List<CheckProject>>() { |
|
|
|
|
@Override |
|
|
|
|
public void accept(List<CheckProject> checkProjects) throws Exception { |
|
|
|
|
checkProjectList = checkProjects; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initFloatingActionButtons(TabsPagerAdapter tabsPagerAdapter) { |
|
|
|
|
|
|
|
|
|
FloatingActionMenu didiCheckMenu = binding.didiCheckMenu; |
|
|
|
|
FloatingActionButton swimActionButton = new FloatingActionButton(this); |
|
|
|
|
swimActionButton.showButtonInMenu(true); |
|
|
|
|
swimActionButton.show(true); |
|
|
|
|
swimActionButton.setLabelText("游泳"); |
|
|
|
|
swimActionButton.setImageDrawable(this.getResources().getDrawable(R.mipmap.fab_icon_swimming, getTheme())); |
|
|
|
|
swimActionButton.setButtonSize(FloatingActionButton.SIZE_NORMAL); |
|
|
|
|
swimActionButton.setColorNormal(this.getResources().getColor(R.color.white)); |
|
|
|
|
swimActionButton.setColorPressed(this.getResources().getColor(R.color.white)); |
|
|
|
|
swimActionButton.setTag("SWIM_TAG"); |
|
|
|
|
|
|
|
|
|
swimActionButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
|
|
|
|
// 移除所有
|
|
|
|
|
Context context = this; |
|
|
|
|
|
|
|
|
|
// 拉取最新
|
|
|
|
|
fetchNewestActionButtonData(); |
|
|
|
|
// 构建视图
|
|
|
|
|
// buildFloatActionButtons(checkProjectList, this, binding.didiCheckMenu, tabsPagerAdapter);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void buildFloatActionButtons(List<CheckProject> checkProjects, Context context, FloatingActionMenu didiCheckMenu, TabsPagerAdapter tabsPagerAdapter) { |
|
|
|
|
for (CheckProject project : checkProjects) { |
|
|
|
|
|
|
|
|
|
FloatingActionButton actionButton = new FloatingActionButton(context); |
|
|
|
|
actionButton.showButtonInMenu(true); |
|
|
|
|
actionButton.show(true); |
|
|
|
|
actionButton.setTag(project.getName() + project.getId()); |
|
|
|
|
actionButton.setLabelText(project.getName()); |
|
|
|
|
actionButton.setImageDrawable(getResources().getDrawable(R.mipmap.ic_ice_cream, getTheme())); |
|
|
|
|
actionButton.setButtonSize(FloatingActionButton.SIZE_NORMAL); |
|
|
|
|
actionButton.setColorNormal(getResources().getColor(R.color.white)); |
|
|
|
|
actionButton.setColorPressed(getResources().getColor(R.color.white)); |
|
|
|
|
actionButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onClick(View v) { |
|
|
|
|
tabsPagerAdapter.getHomeFragment().add2Top(CheckTypeEnum.QUICK_ADD, "游泳"); |
|
|
|
|
// 打卡完成 关闭动画
|
|
|
|
|
didiCheckMenu.close(true); |
|
|
|
|
// 添加数据
|
|
|
|
|
tabsPagerAdapter.getHomeFragment().add2Top(CheckTypeEnum.QUICK_ADD, actionButton.getLabelText()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
didiCheckMenu.addMenuButton(swimActionButton); |
|
|
|
|
|
|
|
|
|
didiCheckMenu.addMenuButton(actionButton); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |