-
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.
Merge pull request #19 from mrtry/develop
Ver 1.1.0
- Loading branch information
Showing
49 changed files
with
901 additions
and
65 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
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
7 changes: 4 additions & 3 deletions
7
app/src/main/java/io/github/mrtry/todolist/app/splash/viewmodel/SplashViewModel.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
144 changes: 144 additions & 0 deletions
144
app/src/main/java/io/github/mrtry/todolist/app/todo/ui/EditTaskDialogFragment.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,144 @@ | ||
package io.github.mrtry.todolist.app.todo.ui | ||
|
||
import android.os.Bundle | ||
import android.view.KeyEvent | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.activity.addCallback | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.Fragment | ||
import io.github.mrtry.todolist.R | ||
import io.github.mrtry.todolist.app.todo.ui.navigator.EditTaskNavigator | ||
import io.github.mrtry.todolist.app.todo.viewmodel.EditTaskViewModel | ||
import io.github.mrtry.todolist.databinding.FragmentEditTaskBinding | ||
import io.github.mrtry.todolist.di.Injectable | ||
import io.github.mrtry.todolist.di.component.EditTaskComponent | ||
import io.github.mrtry.todolist.di.component.ToDoComponent | ||
import io.github.mrtry.todolist.di.module.FragmentModule | ||
import io.github.mrtry.todolist.di.scope.FragmentScope | ||
import io.github.mrtry.todolist.di.utils.ComponentUtils | ||
import io.github.mrtry.todolist.misc.extension.observeNonNull | ||
import io.github.mrtry.todolist.misc.ui.binding.Bindable | ||
import io.github.mrtry.todolist.task.entity.Task | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.cancelChildren | ||
import javax.inject.Inject | ||
|
||
|
||
private const val KEY_TASK = "KEY_TASK" | ||
|
||
class EditTaskDialogFragment : DialogFragment(), Injectable<EditTaskComponent>, Bindable<FragmentEditTaskBinding> { | ||
companion object { | ||
val TAG: String = EditTaskDialogFragment::class.java.simpleName | ||
|
||
fun newInstance(task: Task): EditTaskDialogFragment { | ||
val fragment = EditTaskDialogFragment() | ||
val args = Bundle() | ||
args.putParcelable(KEY_TASK, task) | ||
fragment.arguments = args | ||
return fragment | ||
} | ||
} | ||
|
||
override val viewBinding: FragmentEditTaskBinding by lazy { | ||
FragmentEditTaskBinding.inflate(layoutInflater) | ||
} | ||
|
||
override lateinit var component: EditTaskComponent | ||
|
||
@Inject | ||
lateinit var viewModel: EditTaskViewModel | ||
|
||
@Inject | ||
lateinit var navigator: EditTaskNavigator | ||
|
||
@Inject | ||
lateinit var coroutineScope: CoroutineScope | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NORMAL, R.style.Widget_FullScreenDialog) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
super.onCreateView(inflater, container, savedInstanceState) | ||
return viewBinding.root | ||
} | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
component = ComponentUtils.getComponent<ToDoComponent>(requireActivity()) | ||
.plusEditTaskComponent(FragmentModule(this)) | ||
component.inject(this) | ||
|
||
savedInstanceState?.let { | ||
viewModel.onRestoreInstanceState(it) | ||
} | ||
|
||
with(viewBinding) { | ||
viewModel = this@EditTaskDialogFragment.viewModel | ||
lifecycleOwner = this@EditTaskDialogFragment | ||
} | ||
|
||
requireActivity().onBackPressedDispatcher.addCallback(this) { | ||
navigator.showSavingAlert() | ||
} | ||
|
||
// DialogFragmentのcancel()を無効にして、back pressをハンドリングする | ||
// see: https://stackoverflow.com/a/7622065 | ||
isCancelable = false | ||
dialog?.setOnKeyListener { _, keyCode, event -> | ||
if (keyCode == KeyEvent.KEYCODE_BACK && event.action === KeyEvent.ACTION_UP) { | ||
navigator.onBackPressed() | ||
true | ||
} else false | ||
} | ||
|
||
viewModel.title.observeNonNull(this@EditTaskDialogFragment) { | ||
with(viewBinding.toolbar) { | ||
menu.getItem(0).isEnabled = it.isNotEmpty() | ||
invalidate() | ||
} | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
with(viewBinding.toolbar) { | ||
setNavigationOnClickListener { | ||
navigator.onBackPressed() | ||
} | ||
|
||
inflateMenu(R.menu.menu_fragment_edit_task) | ||
setOnMenuItemClickListener { | ||
this@EditTaskDialogFragment.viewModel.onSaveClick() | ||
true | ||
} | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
dialog?.window?.setLayout( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.MATCH_PARENT | ||
) | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
super.onSaveInstanceState(outState) | ||
viewModel.onSaveInstanceState(outState) | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
coroutineScope.coroutineContext.cancelChildren() | ||
} | ||
} | ||
|
||
@FragmentScope | ||
class EditTaskDialogFragmentValueHolder | ||
@Inject constructor(fragment: Fragment) { | ||
val task: Task = fragment.requireArguments().getParcelable(KEY_TASK)!! | ||
} |
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
17 changes: 17 additions & 0 deletions
17
app/src/main/java/io/github/mrtry/todolist/app/todo/ui/menu/ToDoMenuAction.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,17 @@ | ||
package io.github.mrtry.todolist.app.todo.ui.menu | ||
|
||
import io.github.mrtry.todolist.R | ||
import io.github.mrtry.todolist.di.component.ToDoComponent | ||
import io.github.mrtry.todolist.misc.ui.menu.MenuAction | ||
|
||
enum class ToDoMenuAction(override val menuId: Int) : MenuAction<ToDoMenuActionHandler, ToDoComponent> { | ||
LOGOUT(R.id.menu_logout) { | ||
override fun getActionHandler(component: ToDoComponent): ToDoMenuActionHandler = | ||
component.toDoMenuLogoutActionHandler | ||
}; | ||
|
||
companion object { | ||
fun valueOf(menuId: Int) = | ||
values().first { it.menuId == menuId } | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/io/github/mrtry/todolist/app/todo/ui/menu/ToDoMenuActionHandler.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,5 @@ | ||
package io.github.mrtry.todolist.app.todo.ui.menu | ||
|
||
import io.github.mrtry.todolist.misc.ui.menu.ActionHandler | ||
|
||
interface ToDoMenuActionHandler : ActionHandler |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/io/github/mrtry/todolist/app/todo/ui/menu/ToDoMenuLogoutActionHandler.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,21 @@ | ||
package io.github.mrtry.todolist.app.todo.ui.menu | ||
|
||
import io.github.mrtry.todolist.app.todo.ui.navigator.ToDoNavigator | ||
import io.github.mrtry.todolist.auth.repository.AccountRepository | ||
import io.github.mrtry.todolist.di.scope.ActivityScope | ||
import javax.inject.Inject | ||
|
||
@ActivityScope | ||
class ToDoMenuLogoutActionHandler | ||
@Inject constructor( | ||
private val repository: AccountRepository, | ||
private val navigator: ToDoNavigator | ||
) : ToDoMenuActionHandler { | ||
override fun handleAction(): Boolean { | ||
navigator.showLogoutAlert() { | ||
repository.logout() | ||
navigator.navigateToSplash() | ||
} | ||
return true | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/io/github/mrtry/todolist/app/todo/ui/navigator/EditTaskNavigator.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 io.github.mrtry.todolist.app.todo.ui.navigator | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.Fragment | ||
import com.google.android.material.snackbar.Snackbar | ||
import io.github.mrtry.todolist.R | ||
import io.github.mrtry.todolist.databinding.FragmentEditTaskBinding | ||
import io.github.mrtry.todolist.di.scope.FragmentScope | ||
import io.github.mrtry.todolist.misc.ui.navigator.AbsFragmentNavigator | ||
import javax.inject.Inject | ||
|
||
@FragmentScope | ||
class EditTaskNavigator | ||
@Inject constructor( | ||
activity: AppCompatActivity, | ||
private val fragment: Fragment | ||
) : AbsFragmentNavigator(activity, fragment) { | ||
fun dismissDialog() { | ||
(fragment as DialogFragment).dismiss() | ||
} | ||
|
||
fun showSavingAlert() { | ||
showAlert( | ||
R.string.edit_task_fragment_alert_confirm, | ||
R.string.edit_task_fragment_alert_label_positive, | ||
{ _, _ -> dismissDialog() } | ||
) | ||
} | ||
|
||
override fun showSnackBar(messageId: Int, length: Int) { | ||
Snackbar.make(getFragmentBindingAs<FragmentEditTaskBinding>().container, messageId, length).show() | ||
} | ||
} |
Oops, something went wrong.