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
bbdc6c9
commit 6e0c07f
Showing
17 changed files
with
335 additions
and
148 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
60 changes: 60 additions & 0 deletions
60
app/src/main/java/hidaka/kotlinstudy/todo/fragment/MainFragment.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,60 @@ | ||
package hidaka.kotlinstudy.todo.fragment | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.google.android.material.floatingactionbutton.FloatingActionButton | ||
import hidaka.kotlinstudy.todo.MainActivity | ||
import hidaka.kotlinstudy.todo.R | ||
import hidaka.kotlinstudy.todo.pagesList | ||
import hidaka.kotlinstudy.todo.ui.PageNewActivity | ||
import hidaka.kotlinstudy.todo.ui_component.PagesRecyclerViewComponent | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
*/ | ||
class MainFragment : Fragment() { | ||
|
||
private lateinit var pagesRecyclerView: RecyclerView | ||
private lateinit var pagesRecyclerViewComponent: PagesRecyclerViewComponent | ||
private lateinit var floatingActionButton: FloatingActionButton | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_main, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
pagesRecyclerView = view.findViewById<RecyclerView>(R.id.main_recycler_view).also { | ||
pagesRecyclerViewComponent = | ||
PagesRecyclerViewComponent(pagesList, it.context, ::startActivity) | ||
|
||
it.setHasFixedSize(true) | ||
it.layoutManager = pagesRecyclerViewComponent.viewManager | ||
it.adapter = pagesRecyclerViewComponent.viewAdapter | ||
} | ||
floatingActionButton = | ||
view.findViewById<FloatingActionButton>(R.id.main_floating_action_button).also { it -> | ||
it.setOnClickListener { | ||
fabClickCallback() | ||
} | ||
} | ||
} | ||
|
||
private fun fabClickCallback() { | ||
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | ||
(requireActivity() as MainActivity).navigateToPageNew() | ||
} | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
app/src/main/java/hidaka/kotlinstudy/todo/fragment/PageDetailFragment.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,68 @@ | ||
package hidaka.kotlinstudy.todo.fragment | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.lifecycle.Lifecycle | ||
import com.google.android.material.floatingactionbutton.FloatingActionButton | ||
import hidaka.kotlinstudy.todo.R | ||
import hidaka.kotlinstudy.todo.model.Page | ||
import hidaka.kotlinstudy.todo.ui.PageDetailActivity | ||
import hidaka.kotlinstudy.todo.ui_component.PagesRecyclerViewComponent | ||
import java.text.DateFormat | ||
import java.util.* | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
*/ | ||
class PageDetailFragment : Fragment() { | ||
|
||
private lateinit var pageTitle: TextView | ||
private lateinit var pageUpdatedAt: TextView | ||
private lateinit var pageContent: TextView | ||
private lateinit var floatingActionButton: FloatingActionButton | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_page_detail, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
val page: Page? = | ||
arguments?.getParcelable(PagesRecyclerViewComponent.PUT_EXTRA_KEY_PAGE_DETAIL) | ||
|
||
pageTitle = view.findViewById<TextView>(R.id.page_detail_title).also { | ||
it.text = page?.title | ||
} | ||
pageUpdatedAt = view.findViewById<TextView>(R.id.page_detail_updated_at).also { | ||
it.text = getString( | ||
R.string.page_detail_activity_updated_at_label, | ||
DateFormat.getDateInstance(DateFormat.LONG).format(page?.updatedAt ?: Date()) | ||
) | ||
} | ||
pageContent = view.findViewById<TextView>(R.id.page_detail_fragment_host).also { | ||
it.text = page?.content | ||
} | ||
floatingActionButton = | ||
view.findViewById<FloatingActionButton>(R.id.page_detail_floating_action_button).also { | ||
it.setOnClickListener { | ||
fabClickCallback() | ||
} | ||
} | ||
} | ||
|
||
private fun fabClickCallback() { | ||
if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | ||
(requireActivity() as PageDetailActivity).navigateToPageEdit() | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/hidaka/kotlinstudy/todo/fragment/PageEditFragment.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,24 @@ | ||
package hidaka.kotlinstudy.todo.fragment | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import hidaka.kotlinstudy.todo.R | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
*/ | ||
class PageEditFragment : Fragment() { | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_page_edit, container, false) | ||
} | ||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/hidaka/kotlinstudy/todo/fragment/PageNewFragment.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,23 @@ | ||
package hidaka.kotlinstudy.todo.fragment | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import hidaka.kotlinstudy.todo.R | ||
|
||
/** | ||
* A simple [Fragment] subclass. | ||
*/ | ||
class PageNewFragment : Fragment() { | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_page_new, container, false) | ||
} | ||
|
||
} |
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
15 changes: 14 additions & 1 deletion
15
app/src/main/java/hidaka/kotlinstudy/todo/ui/PageNewActivity.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 |
---|---|---|
@@ -1,13 +1,26 @@ | ||
package hidaka.kotlinstudy.todo.ui | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import hidaka.kotlinstudy.todo.R | ||
import hidaka.kotlinstudy.todo.fragment.PageNewFragment | ||
|
||
class PageNewActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_page_new) | ||
|
||
if (savedInstanceState == null) { | ||
val fragment = PageNewFragment() | ||
|
||
// Intent extras and Fragment Args are both of type android.os.Bundle. | ||
fragment.arguments = intent.extras | ||
|
||
supportFragmentManager | ||
.beginTransaction() | ||
.add(R.id.page_new_fragment_host, fragment) | ||
.commit() | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,4 @@ | ||
<?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" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/main_recycler_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.google.android.material.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/main_floating_action_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|end" | ||
android:layout_margin="16dp" | ||
android:clickable="true" | ||
android:focusable="true" | ||
android:src="@drawable/ic_add_black_24dp" /> | ||
</androidx.coordinatorlayout.widget.CoordinatorLayout> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/main_fragment_host" | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent" /> |
Oops, something went wrong.