-
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 branch '6/rough_ui' of https://github.com/hometerview/Android i…
…nto develop � Conflicts: � app/build.gradle � app/src/main/AndroidManifest.xml � app/src/main/java/com/ftw/hometerview/di/api/NetworkModule.kt
- Loading branch information
Showing
294 changed files
with
11,610 additions
and
112 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/ftw/hometerview/adapter/AnimationAdapter.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 com.ftw.hometerview.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.ftw.hometerview.R | ||
|
||
class AnimationAdapter(var guideImgaeList: List<Int>, var guideTextList: List<String>) : RecyclerView.Adapter<AnimationAdapter.AnimationViewHolder>() { | ||
|
||
inner class AnimationViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
var imageViewIcon = itemView.findViewById<ImageView>(R.id.imageView_icon) | ||
var guideText = itemView.findViewById<TextView>(R.id.guide_text) | ||
|
||
fun onBind(res: Int, text: String) { | ||
imageViewIcon.setImageResource(res) | ||
guideText.text = text | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AnimationViewHolder { | ||
var view = LayoutInflater.from(parent.context).inflate(R.layout.list_item_guide, parent, false) | ||
return AnimationViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: AnimationViewHolder, position: Int) { | ||
holder.onBind(guideImgaeList[position], guideTextList[position]) | ||
} | ||
|
||
override fun getItemCount(): Int = guideImgaeList.size | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/ftw/hometerview/adapter/DiffCallback.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,26 @@ | ||
package com.ftw.hometerview.adapter | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.recyclerview.widget.DiffUtil | ||
|
||
internal class DiffCallback : DiffUtil.ItemCallback<RecyclerItem>() { | ||
|
||
override fun areItemsTheSame( | ||
oldItem: RecyclerItem, | ||
newItem: RecyclerItem | ||
): Boolean { | ||
val oldData = oldItem.data | ||
val newData = newItem.data | ||
return oldData == newData | ||
} | ||
|
||
@SuppressLint("DiffUtilEquals") | ||
override fun areContentsTheSame( | ||
oldItem: RecyclerItem, | ||
newItem: RecyclerItem | ||
): Boolean { | ||
val oldData = oldItem.data | ||
val newData = newItem.data | ||
return oldData == newData | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/ftw/hometerview/adapter/DividerItemDecoration.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,51 @@ | ||
package com.ftw.hometerview.adapter | ||
|
||
import android.content.Context | ||
import android.graphics.Canvas | ||
import android.graphics.Paint | ||
import android.graphics.Rect | ||
import android.view.View | ||
import androidx.annotation.ColorInt | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.view.children | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.ftw.hometerview.R | ||
|
||
class DividerItemDecoration( | ||
context: Context, | ||
@ColorInt private val colorResId: Int = com.ftw.hometerview.design.R.color.gray_200 | ||
) : RecyclerView.ItemDecoration() { | ||
|
||
private val dividerHeight: Int = context.resources.getDimensionPixelSize(R.dimen.dp_size_1) | ||
private val horizontalMargin: Int = context.resources.getDimensionPixelSize(R.dimen.dp_size_14) | ||
|
||
private val paint = Paint().apply { | ||
this.color = ContextCompat.getColor(context, colorResId) | ||
} | ||
|
||
override fun getItemOffsets( | ||
outRect: Rect, | ||
view: View, | ||
parent: RecyclerView, | ||
state: RecyclerView.State | ||
) { | ||
outRect.set(0, 0, 0, dividerHeight) | ||
} | ||
|
||
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { | ||
c.save() | ||
parent.children | ||
.forEach { children -> | ||
c.drawRect( | ||
Rect( | ||
children.left + horizontalMargin, | ||
children.bottom + dividerHeight, | ||
children.right - horizontalMargin, | ||
children.bottom | ||
), | ||
paint | ||
) | ||
} | ||
c.restore() | ||
} | ||
} |
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,9 @@ | ||
package com.ftw.hometerview.adapter | ||
|
||
import androidx.annotation.LayoutRes | ||
|
||
data class RecyclerItem( | ||
val data: Any, | ||
@LayoutRes val layoutId: Int, | ||
val variableId: Int | ||
) |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/ftw/hometerview/adapter/RecyclerAdapter.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,54 @@ | ||
package com.ftw.hometerview.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
class DataBindingRecyclerAdapter : ListAdapter<RecyclerItem, BindingViewHolder>( | ||
DiffCallback() | ||
) { | ||
override fun getItemViewType(position: Int): Int { | ||
return getItem(position).layoutId | ||
} | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): BindingViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding: ViewDataBinding = DataBindingUtil.inflate(inflater, viewType, parent, false) | ||
return BindingViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: BindingViewHolder, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
} | ||
|
||
class BindingViewHolder( | ||
private val binding: ViewDataBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(item: RecyclerItem) { | ||
val isVariableFound = binding.setVariable(item.variableId, item.data) | ||
if (isVariableFound.not()) { | ||
throw IllegalStateException( | ||
buildErrorMessage(item.variableId, binding) | ||
) | ||
} | ||
if (binding.hasPendingBindings()) { | ||
binding.executePendingBindings() | ||
} | ||
} | ||
} | ||
|
||
private fun buildErrorMessage( | ||
variableId: Int, | ||
binding: ViewDataBinding | ||
): String { | ||
val variableName = DataBindingUtil.convertBrIdToString(variableId) | ||
val className = binding::class.simpleName | ||
return "Failed to find variable='$variableName' in the following databinding layout: $className" | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/ftw/hometerview/adapter/SpacingItemDecoration.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,29 @@ | ||
package com.ftw.hometerview.adapter | ||
|
||
import android.content.Context | ||
import android.graphics.Rect | ||
import android.view.View | ||
import androidx.annotation.DimenRes | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.ftw.hometerview.R | ||
|
||
class SpacingItemDecoration( | ||
context: Context, | ||
@DimenRes private val spacingResId: Int = R.dimen.dp_size_16 | ||
) : RecyclerView.ItemDecoration() { | ||
|
||
private val dividerHeight: Int = context.resources.getDimensionPixelSize(spacingResId) | ||
|
||
override fun getItemOffsets( | ||
outRect: Rect, | ||
view: View, | ||
parent: RecyclerView, | ||
state: RecyclerView.State | ||
) { | ||
outRect.set(0, 0, 0, dividerHeight) | ||
|
||
if (parent.getChildAdapterPosition(view) == 0) { | ||
outRect.top = dividerHeight | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/ftw/hometerview/bindingadapter/RecyclerDataBinding.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,22 @@ | ||
package com.ftw.hometerview.bindingadapter | ||
|
||
import androidx.databinding.BindingAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.ftw.hometerview.adapter.DataBindingRecyclerAdapter | ||
import com.ftw.hometerview.adapter.RecyclerItem | ||
|
||
@BindingAdapter("items") | ||
fun setRecyclerViewItems( | ||
recyclerView: RecyclerView, | ||
items: List<RecyclerItem>? | ||
) { | ||
var adapter = (recyclerView.adapter as? DataBindingRecyclerAdapter) | ||
if (adapter == null) { | ||
adapter = DataBindingRecyclerAdapter() | ||
recyclerView.adapter = adapter | ||
} | ||
|
||
adapter.submitList( | ||
items.orEmpty() | ||
) | ||
} |
Oops, something went wrong.