-
Notifications
You must be signed in to change notification settings - Fork 20
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 #6 from Semper-Viventem/release
Release 0.1.2
- Loading branch information
Showing
29 changed files
with
737 additions
and
80 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
39 changes: 0 additions & 39 deletions
39
sample/src/main/kotlin/ru/semper_viventem/backdropview/MainActivity.kt
This file was deleted.
Oops, something went wrong.
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
81 changes: 81 additions & 0 deletions
81
sample/src/main/kotlin/ru/semper_viventem/backdropview/ui/MainActivity.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,81 @@ | ||
package ru.semper_viventem.backdropview.ui | ||
|
||
import android.os.Bundle | ||
import android.support.annotation.IdRes | ||
import android.support.v4.app.Fragment | ||
import android.support.v7.app.AppCompatActivity | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
import ru.semper_viventem.backdrop.BackdropBehavior | ||
import ru.semper_viventem.backdropview.R | ||
import ru.semper_viventem.backdropview.findBehavior | ||
import ru.semper_viventem.backdropview.ui.gallery.GalleryScreen | ||
import ru.semper_viventem.backdropview.ui.list.ListScreen | ||
import ru.semper_viventem.backdropview.ui.text.TextScreen | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
private const val ARG_LAST_MENU_ITEM = "last_menu_item" | ||
|
||
private const val MENU_GALLERY = R.id.menuGallery | ||
private const val MENU_TEXT = R.id.menuText | ||
private const val MENU_LIST = R.id.menuList | ||
|
||
private const val FRAGMENT_CONTAINER = R.id.foregroundContainer | ||
|
||
private const val DEFAULT_ITEM = MENU_GALLERY | ||
} | ||
|
||
private lateinit var backdropBehavior: BackdropBehavior | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
backdropBehavior = foregroundContainer.findBehavior() | ||
with(backdropBehavior) { | ||
attacheBackContainer(R.id.backContainer) | ||
attacheToolbar(R.id.toolbar) | ||
} | ||
with(toolbar) { | ||
setTitle(R.string.app_name) | ||
} | ||
|
||
navigationView.setNavigationItemSelectedListener { item -> | ||
checkMenuPosition(item.itemId) | ||
backdropBehavior.close() | ||
true | ||
} | ||
|
||
val currentItem = savedInstanceState?.getInt(ARG_LAST_MENU_ITEM) ?: DEFAULT_ITEM | ||
navigationView.setCheckedItem(currentItem) | ||
checkMenuPosition(navigationView.checkedItem!!.itemId) | ||
} | ||
|
||
override fun onBackPressed() { | ||
if (!backdropBehavior.close()) { | ||
finish() | ||
} | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
outState.putInt(ARG_LAST_MENU_ITEM, navigationView.checkedItem!!.itemId) | ||
|
||
super.onSaveInstanceState(outState) | ||
} | ||
|
||
private fun checkMenuPosition(@IdRes menuItemId: Int) { | ||
when (menuItemId) { | ||
MENU_GALLERY -> showPage(GalleryScreen()) | ||
MENU_TEXT -> showPage(TextScreen()) | ||
MENU_LIST -> showPage(ListScreen()) | ||
} | ||
} | ||
|
||
private fun showPage(page: Fragment) { | ||
supportFragmentManager | ||
.beginTransaction() | ||
.replace(FRAGMENT_CONTAINER, page) | ||
.commit() | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
sample/src/main/kotlin/ru/semper_viventem/backdropview/ui/common/BaseListAdapter.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,76 @@ | ||
package ru.semper_viventem.backdropview.ui.common | ||
|
||
import android.support.v7.util.DiffUtil | ||
import android.support.v7.widget.RecyclerView | ||
|
||
/** | ||
* Easy to use base adapter for lists with single item type. | ||
* @author Dmitriy Gorbunov (@dmdevgo) | ||
*/ | ||
abstract class BaseListAdapter<T, VH> : RecyclerView.Adapter<VH>() where VH : RecyclerView.ViewHolder, VH : BaseListAdapter.Bindable<T> { | ||
|
||
private var items: MutableList<T> = mutableListOf() | ||
|
||
override fun onBindViewHolder(holder: VH, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
override fun getItemCount() = items.size | ||
|
||
fun getItem(position: Int) = items[position] | ||
|
||
fun getItems(): List<T> { | ||
return items | ||
} | ||
|
||
fun addItems(list: List<T>) { | ||
val positionStart = items.size | ||
items.addAll(list) | ||
notifyItemRangeInserted(positionStart, list.size) | ||
} | ||
|
||
fun setItems(list: List<T>) { | ||
items.clear() | ||
items.addAll(list) | ||
notifyDataSetChanged() | ||
} | ||
|
||
fun updateItems(list: List<T>, diffCallback: DiffItemsCallback<T>) { | ||
if (items.isEmpty()) { | ||
setItems(list) | ||
} else { | ||
val diffResult = DiffUtil.calculateDiff(DiffCallback(items, list, diffCallback)) | ||
items.clear() | ||
items.addAll(list) | ||
diffResult.dispatchUpdatesTo(this) | ||
} | ||
} | ||
|
||
interface Bindable<in T> { | ||
fun bind(item: T) | ||
} | ||
|
||
interface DiffItemsCallback<in T> { | ||
fun areItemsTheSame(oldItem: T, newItem: T): Boolean | ||
fun areContentsTheSame(oldItem: T, newItem: T): Boolean | ||
} | ||
|
||
private class DiffCallback<in T>( | ||
private val oldList: List<T>, | ||
private val newList: List<T>, | ||
private val diffItemsCallback: DiffItemsCallback<T> | ||
) : DiffUtil.Callback() { | ||
|
||
override fun getOldListSize() = oldList.size | ||
|
||
override fun getNewListSize() = newList.size | ||
|
||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return diffItemsCallback.areItemsTheSame(oldList[oldItemPosition], newList[newItemPosition]) | ||
} | ||
|
||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return diffItemsCallback.areContentsTheSame(oldList[oldItemPosition], newList[newItemPosition]) | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
sample/src/main/kotlin/ru/semper_viventem/backdropview/ui/common/Screen.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,32 @@ | ||
package ru.semper_viventem.backdropview.ui.common | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.support.v4.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
|
||
|
||
abstract class Screen : Fragment { | ||
|
||
constructor(): super() | ||
|
||
constructor(args: Bundle) : super() { | ||
arguments = args | ||
} | ||
|
||
abstract val layoutId: Int | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(layoutId, container, false) | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
|
||
onInitView(view!!) | ||
} | ||
|
||
abstract fun onInitView(view: View) | ||
} |
Oops, something went wrong.