-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26e2c04
commit 0bfc7f5
Showing
15 changed files
with
279 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package cn.super12138.todo.views.all | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import android.view.WindowManager | ||
import androidx.lifecycle.Observer | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import cn.super12138.todo.ToDoApplication | ||
import cn.super12138.todo.databinding.ActivityAllTasksBinding | ||
import cn.super12138.todo.logic.Repository | ||
import cn.super12138.todo.views.BaseActivity | ||
import me.zhanghai.android.fastscroll.FastScrollerBuilder | ||
|
||
class AllTasksActivity : BaseActivity() { | ||
private lateinit var binding: ActivityAllTasksBinding | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
val isSecureMode = Repository.getPreferenceBoolean(this, "secure_mode", false) | ||
when (isSecureMode) { | ||
true -> window.setFlags( | ||
WindowManager.LayoutParams.FLAG_SECURE, | ||
WindowManager.LayoutParams.FLAG_SECURE | ||
) | ||
|
||
false -> window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) | ||
} | ||
|
||
binding = ActivityAllTasksBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
val viewModel = ViewModelProvider(this)[AllTasksViewModel::class.java] | ||
|
||
val layoutManager = LinearLayoutManager(ToDoApplication.context) | ||
binding.allTasksList.layoutManager = layoutManager | ||
val adapter = AllTasksAdapter(viewModel.todoListAll) | ||
binding.allTasksList.adapter = adapter | ||
|
||
FastScrollerBuilder(binding.allTasksList).apply { | ||
useMd2Style() | ||
build() | ||
} | ||
|
||
binding.toolbar.setNavigationOnClickListener { | ||
finish() | ||
} | ||
|
||
viewModel.emptyTipVis.observe(this, Observer { visibility -> | ||
if (visibility == View.VISIBLE) { | ||
binding.allTasksList.alpha = 1f | ||
binding.allTasksList.animate().alpha(0f).duration = 200 | ||
binding.allTasksList.visibility = View.GONE | ||
|
||
binding.emptyTip.alpha = 0f | ||
binding.emptyTip.visibility = View.VISIBLE | ||
binding.emptyTip.animate().alpha(1f).duration = 200 | ||
} else { | ||
binding.allTasksList.alpha = 0f | ||
binding.allTasksList.visibility = View.VISIBLE | ||
binding.allTasksList.animate().alpha(1f).duration = 200 | ||
|
||
binding.emptyTip.alpha = 1f | ||
binding.emptyTip.animate().alpha(0f).duration = 200 | ||
binding.emptyTip.visibility = View.GONE | ||
} | ||
}) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cn.super12138.todo.views.all | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import cn.super12138.todo.R | ||
import cn.super12138.todo.logic.model.ToDo | ||
|
||
class AllTasksAdapter(private val todoList: MutableList<ToDo>) : | ||
RecyclerView.Adapter<AllTasksAdapter.ViewHolder>() { | ||
|
||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { | ||
val todoContext: TextView = view.findViewById(R.id.todo_content_all) | ||
val todoSubject: TextView = view.findViewById(R.id.todo_subject_all) | ||
} | ||
|
||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = LayoutInflater.from(parent.context) | ||
.inflate(R.layout.item_all_tasks, parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val todo = todoList[position] | ||
holder.todoContext.text = todo.content | ||
holder.todoSubject.text = todo.subject | ||
if (!todo.isAnimated) { | ||
holder.itemView.alpha = 0f | ||
holder.itemView.animate().alpha(1f).duration = 200 | ||
todo.isAnimated = true | ||
} | ||
} | ||
|
||
override fun getItemCount() = todoList.size | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/kotlin/cn/super12138/todo/views/all/AllTasksViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cn.super12138.todo.views.all | ||
|
||
import android.view.View | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import cn.super12138.todo.logic.Repository | ||
import cn.super12138.todo.logic.model.ToDo | ||
import kotlinx.coroutines.launch | ||
|
||
class AllTasksViewModel : ViewModel() { | ||
val emptyTipVis = MutableLiveData<Int>(View.VISIBLE) | ||
val todoListAll = ArrayList<ToDo>() | ||
|
||
init { | ||
loadToDos() | ||
} | ||
|
||
private fun loadToDos() { | ||
viewModelScope.launch { | ||
val todos = Repository.getAll() | ||
var count = 0 | ||
for (todo in todos) { | ||
todoListAll.add(ToDo(todo.uuid, todo.content, todo.subject)) | ||
count++ | ||
} | ||
if (count == 0) { | ||
emptyTipVis.value = View.VISIBLE | ||
} else { | ||
emptyTipVis.value = View.GONE | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:autoMirrored="true" | ||
android:tint="?attr/colorControlNormal" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M4,10.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM4,4.5c-0.83,0 -1.5,0.67 -1.5,1.5S3.17,7.5 4,7.5 5.5,6.83 5.5,6 4.83,4.5 4,4.5zM4,16.5c-0.83,0 -1.5,0.68 -1.5,1.5s0.68,1.5 1.5,1.5 1.5,-0.68 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM7,19h14v-2L7,17v2zM7,13h14v-2L7,11v2zM7,5v2h14L21,5L7,5z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true" | ||
tools:context=".views.about.AboutActivity"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:fitsSystemWindows="true" | ||
app:liftOnScroll="true" | ||
app:liftOnScrollTargetViewId="@+id/all_tasks_list"> | ||
|
||
<com.google.android.material.appbar.MaterialToolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
app:navigationIcon="@drawable/ic_arrow_back" | ||
app:title="@string/all_tasks_label" /> | ||
|
||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/all_tasks_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fillViewport="true" | ||
android:visibility="gone" | ||
app:layout_behavior="@string/appbar_scrolling_view_behavior"> | ||
|
||
</androidx.recyclerview.widget.RecyclerView> | ||
|
||
|
||
<TextView | ||
android:id="@+id/empty_tip" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="20dp" | ||
android:gravity="center" | ||
android:text="@string/no_tasks" | ||
android:textSize="14sp" | ||
android:visibility="visible" /> | ||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" | ||
style="?attr/materialCardViewElevatedStyle" | ||
android:layout_width="match_parent" | ||
android:layout_height="80dp" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginTop="5dp" | ||
android:layout_marginRight="10dp" | ||
android:layout_marginBottom="5dp"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_weight="1" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/todo_content_all" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="15dp" | ||
android:layout_marginTop="18dp" | ||
android:ellipsize="marquee" | ||
android:singleLine="true" | ||
android:textColor="?android:attr/textColorPrimary" | ||
android:textSize="20sp" /> | ||
|
||
<TextView | ||
android:id="@+id/todo_subject_all" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="15dp" | ||
android:singleLine="true" | ||
android:textColor="?android:attr/textColorPrimary" | ||
android:textSize="11sp" /> | ||
</LinearLayout> | ||
</com.google.android.material.card.MaterialCardView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.