|
|
@ -1,20 +1,35 @@ |
|
|
|
package cc.niushuai.dididone.ui.setting.project; |
|
|
|
package cc.niushuai.dididone.ui.setting.project; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.graphics.Color; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
|
|
|
|
import android.widget.AdapterView; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.mikepenz.iconics.IconicsDrawable; |
|
|
|
|
|
|
|
import com.mikepenz.ionicons_typeface_library.Ionicons; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cc.niushuai.dididone.biz.roomx.DBManager; |
|
|
|
|
|
|
|
import cc.niushuai.dididone.biz.vo.ProjectIcon; |
|
|
|
import cc.niushuai.dididone.databinding.FragmentProjectBinding; |
|
|
|
import cc.niushuai.dididone.databinding.FragmentProjectBinding; |
|
|
|
import cc.niushuai.dididone.ui.base.InitAndSetListener; |
|
|
|
import cc.niushuai.dididone.ui.base.InitAndSetListener; |
|
|
|
|
|
|
|
import cc.niushuai.dididone.util.Toasts; |
|
|
|
|
|
|
|
import cc.niushuai.dididone.util.XLog; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
|
|
|
|
|
|
public class ProjectFragment extends Fragment implements InitAndSetListener { |
|
|
|
public class ProjectFragment extends Fragment implements InitAndSetListener { |
|
|
|
|
|
|
|
|
|
|
|
private FragmentProjectBinding binding; |
|
|
|
private FragmentProjectBinding binding; |
|
|
|
|
|
|
|
private GridViewAdapter4Project gridViewAdapter4Project; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
|
|
@ -34,6 +49,25 @@ public class ProjectFragment extends Fragment implements InitAndSetListener { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void init() { |
|
|
|
public void init() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initProjectGrid(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initProjectGrid() { |
|
|
|
|
|
|
|
gridViewAdapter4Project = new GridViewAdapter4Project(getContext(), getDataList()); |
|
|
|
|
|
|
|
binding.gridProject.setAdapter(gridViewAdapter4Project); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<ProjectIcon> getDataList() { |
|
|
|
|
|
|
|
ArrayList<ProjectIcon> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 最后一个要添加 + 符号
|
|
|
|
|
|
|
|
list.add(defaultAddProject()); |
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ProjectIcon defaultAddProject() { |
|
|
|
|
|
|
|
return new ProjectIcon(0L, "添加", "faw_plus", String.valueOf(Color.BLACK)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -42,5 +76,74 @@ public class ProjectFragment extends Fragment implements InitAndSetListener { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setListeners() { |
|
|
|
public void setListeners() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加点击事件
|
|
|
|
|
|
|
|
this.addGridItemClickListener(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addGridItemClickListener() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.gridProject.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id == 0) { |
|
|
|
|
|
|
|
addProjectClick(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 其他的被点击
|
|
|
|
|
|
|
|
ProjectIcon item = gridViewAdapter4Project.getItem(position); |
|
|
|
|
|
|
|
Toasts.shortShow(getContext(), item.getProjectName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 长按事件 用于删除
|
|
|
|
|
|
|
|
binding.gridProject.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id == 0) { |
|
|
|
|
|
|
|
// 添加被点击 跳过
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProjectIcon item = gridViewAdapter4Project.getItem(position); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog alertDialog = new AlertDialog.Builder(getContext()) |
|
|
|
|
|
|
|
.setTitle(StrUtil.format("确定要删除 [{}]", item.getProjectName())) |
|
|
|
|
|
|
|
.setIcon(new IconicsDrawable(getContext()).icon(Ionicons.Icon.ion_android_warning).color(Color.RED)) |
|
|
|
|
|
|
|
.setPositiveButton("确定", (dialog, which) -> { |
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
|
|
|
deleteProject(item); |
|
|
|
|
|
|
|
// 更新视图
|
|
|
|
|
|
|
|
gridViewAdapter4Project.projectIconList.remove(position); |
|
|
|
|
|
|
|
gridViewAdapter4Project.notifyDataSetChanged(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.setNegativeButton("取消", ((dialog, which) -> dialog.dismiss())) |
|
|
|
|
|
|
|
.create(); |
|
|
|
|
|
|
|
alertDialog.show(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 删除该项内容 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param item |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void deleteProject(ProjectIcon item) { |
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
|
|
|
DBManager.INSTANCE.projectDao().deleteById(item.getId()); |
|
|
|
|
|
|
|
XLog.d("删除项{}, id: {}", item.getProjectName(), item.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 添加 被点击 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void addProjectClick() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|