Skip to content

Commit

Permalink
Merge pull request #13 from Keyneez/feature/#12-chore-initial-setting
Browse files Browse the repository at this point in the history
[CHORE/#12] 기초 세팅
  • Loading branch information
0zlrlo committed Apr 10, 2023
2 parents 47f5d20 + 5cada1a commit 9d218dc
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".presentation.main.MainActivity"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.release.keyneez
package com.release.keyneez.presentation.main

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.kakao.sdk.common.util.Utility
import com.release.keyneez.R
import timber.log.Timber

class MainActivity : AppCompatActivity() {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/release/keyneez/util/DiffCallback.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.release.keyneez.util

import androidx.recyclerview.widget.DiffUtil

class DiffCallback<T : Any>(
val onItemsTheSame: (T, T) -> Boolean,
val onContentsTheSame: (T, T) -> Boolean
) : DiffUtil.ItemCallback<T>() {
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean =
onItemsTheSame(oldItem, newItem)

override fun areContentsTheSame(oldItem: T, newItem: T): Boolean =
onContentsTheSame(oldItem, newItem)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.release.keyneez.util

import android.os.SystemClock
import android.view.View

class OnSingleClickListener(
private var interval: Int = 600,
private var onSingleClick: (View) -> Unit
) : View.OnClickListener {

private var lastClickTime: Long = 0

override fun onClick(v: View) {
val elapsedRealtime = SystemClock.elapsedRealtime()
if ((elapsedRealtime - lastClickTime) < interval) {
return
}
lastClickTime = elapsedRealtime
onSingleClick(v)
}
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/release/keyneez/util/UiState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.release.keyneez.util

sealed class UiState {
object Success : UiState()
data class Failure(val code: Int?) : UiState()
object Error : UiState()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.release.keyneez.util.binding

import android.os.Bundle
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

abstract class BindingActivity<T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int
) : AppCompatActivity() {
protected lateinit var binding: T

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, layoutRes)
binding.lifecycleOwner = this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.release.keyneez.util.binding

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.release.keyneez.R

abstract class BindingFragment<T : ViewDataBinding>(
@LayoutRes private val layoutRes: Int
) : Fragment() {
private var _binding: T? = null
protected val binding get() = _binding ?: error(getString(R.string.binding_error))

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = DataBindingUtil.inflate(inflater, layoutRes, container, false)
binding.lifecycleOwner = viewLifecycleOwner
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.release.keyneez.util.extension

import android.app.Activity
import android.view.View

/** hide keyboard from activity window */
fun Activity.hideKeyboard() {
hideKeyboard(currentFocus ?: View(this))
}
29 changes: 29 additions & 0 deletions app/src/main/java/com/release/keyneez/util/extension/ContextExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.release.keyneez.util.extension

import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import com.google.android.material.snackbar.Snackbar

/** hide keyboard from window */
fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}

/** Make a Snackbar to display a message for 1.5 seconds */
fun Context.showSnackbar(view: View, msg: String) {
Snackbar.make(view, msg, Toast.LENGTH_SHORT).show()
}

/** Make a Toast to display a message for 1.5 seconds */
fun Context.showToast(msg: String) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}

fun Context.dpToPx(dp: Int): Int {
val scale = resources.displayMetrics.density
return (dp * scale).toInt()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.release.keyneez.util.extension

import androidx.lifecycle.MutableLiveData

fun <T> MutableLiveData<T>.notifyObserver() {
this.value = this.value
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/release/keyneez/util/extension/ViewExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.release.keyneez.util.extension

import android.view.View
import com.google.android.material.snackbar.Snackbar
import com.release.keyneez.util.OnSingleClickListener

/** Register a callback to be invoked when this view is clicked. If this view was clicked within 1 second, the callback will not be invoked. */
fun View.setOnSingleClickListener(onSingleClick: (View) -> Unit) {
setOnClickListener(OnSingleClickListener { onSingleClick(it) })
}

/** Make a Snackbar to display a message for 1.5 seconds */
fun View.showSnackbar(message: String) {
Snackbar.make(this, message, Snackbar.LENGTH_SHORT).show()
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".presentation.main.MainActivity">

<TextView
android:layout_width="wrap_content"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<resources>
<string name="app_name">Keyneez</string>

// common
<string name="binding_error">Binding not initialized to reference the view.</string>

// search
<string name="search_content">제목, 키워드</string>
<string name="search_result">검색결과</string>
Expand Down

0 comments on commit 9d218dc

Please sign in to comment.