-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[setting]: Add Core Module && Kotlin Version up
- Loading branch information
Showing
38 changed files
with
911 additions
and
30 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
11 changes: 11 additions & 0 deletions
11
build-logic/convention/src/main/kotlin/com/hmh/hamyeonham/plugin/AndroidFeaturePlugin.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,11 @@ | ||
package com.hmh.hamyeonham.plugin | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
class AndroidFeaturePlugin : Plugin<Project> { | ||
override fun apply(target: Project) = with(target) { | ||
plugins.apply("com.android.library") | ||
configureAndroidCommonPlugin() | ||
} | ||
} |
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 @@ | ||
/build |
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,18 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
hmh("feature") | ||
hmh("compose") | ||
} | ||
|
||
android { | ||
namespace = "com.hmh.hamyeonham.common" | ||
|
||
defaultConfig { | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(libs.fragment.ktx) | ||
implementation(libs.retrofit) | ||
} |
Empty file.
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
32 changes: 32 additions & 0 deletions
32
core/common/src/main/java/com/hmh/hamyeonham/common/activity/ActivityExt.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 com.hmh.hamyeonham.common.activity | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.commit | ||
|
||
fun AppCompatActivity.showLoading() { | ||
supportFragmentManager.commit(allowStateLoss = true) { | ||
add(LoadingProgressIndicator.newInstance(), LoadingProgressIndicator.TAG) | ||
} | ||
} | ||
|
||
fun AppCompatActivity.hideLoading() { | ||
supportFragmentManager.findFragmentByTag(LoadingProgressIndicator.TAG)?.let { fragment -> | ||
supportFragmentManager.commit(allowStateLoss = true) { | ||
remove(fragment) | ||
} | ||
} | ||
} | ||
|
||
fun AppCompatActivity.showError() { | ||
supportFragmentManager.commit(allowStateLoss = true) { | ||
add(ErrorFullScreenDialogFragment.newInstance(), ErrorFullScreenDialogFragment.TAG) | ||
} | ||
} | ||
|
||
fun AppCompatActivity.hideError() { | ||
supportFragmentManager.findFragmentByTag(ErrorFullScreenDialogFragment.TAG)?.let { fragment -> | ||
supportFragmentManager.commit(allowStateLoss = true) { | ||
remove(fragment) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
core/common/src/main/java/com/hmh/hamyeonham/common/ad/AdName.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 com.hmh.hamyeonham.common.ad | ||
|
||
enum class AdName(val adName: String) { | ||
ALBUM_EDIT_COVER_REWARD_01("AlbumEditCover_reward_01") | ||
} |
18 changes: 18 additions & 0 deletions
18
core/common/src/main/java/com/hmh/hamyeonham/common/compose/Border.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,18 @@ | ||
package com.hmh.hamyeonham.common.compose | ||
|
||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.drawBehind | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.Dp | ||
|
||
fun Modifier.bottomBorder(borderWidth: Dp, color: Color): Modifier = drawBehind { | ||
val strokeWidth = borderWidth.value * density | ||
val y = size.height - strokeWidth / 2 | ||
drawLine( | ||
color, | ||
Offset(0f, y), | ||
Offset(size.width, y), | ||
strokeWidth | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
core/common/src/main/java/com/hmh/hamyeonham/common/compose/DefaultPreview.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,11 @@ | ||
package com.hmh.hamyeonham.common.compose | ||
|
||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
@Preview( | ||
name = "phone", | ||
device = "spec:shape=Normal,width=360,height=760,unit=dp,dpi=480", | ||
showBackground = true, | ||
backgroundColor = 0xFFFFFF | ||
) | ||
annotation class DefaultPreview |
68 changes: 68 additions & 0 deletions
68
core/common/src/main/java/com/hmh/hamyeonham/common/context/ContextExt.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 com.hmh.hamyeonham.common.context | ||
|
||
import android.app.Dialog | ||
import android.content.Context | ||
import android.graphics.Point | ||
import android.os.Build | ||
import android.view.View | ||
import android.view.WindowInsets | ||
import android.view.WindowManager | ||
import android.widget.Toast | ||
import androidx.annotation.ColorRes | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.core.content.ContextCompat | ||
import com.google.android.material.snackbar.Snackbar | ||
|
||
fun Context.toast(message: String) { | ||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
fun Context.longToast(message: String) { | ||
Toast.makeText(this, message, Toast.LENGTH_LONG).show() | ||
} | ||
|
||
fun Context.snackBar(anchorView: View, message: () -> String) { | ||
Snackbar.make(anchorView, message(), Snackbar.LENGTH_SHORT).show() | ||
} | ||
|
||
fun Context.stringOf(@StringRes resId: Int) = getString(resId) | ||
|
||
fun Context.colorOf(@ColorRes resId: Int) = ContextCompat.getColor(this, resId) | ||
|
||
fun Context.drawableOf(@DrawableRes resId: Int) = ContextCompat.getDrawable(this, resId) | ||
|
||
fun Context.dialogWidthPercent(dialog: Dialog?, percent: Double = 0.8) { | ||
val deviceSize = getDeviceSize() | ||
dialog?.window?.run { | ||
val params = attributes | ||
params.width = (deviceSize[0] * percent).toInt() | ||
attributes = params | ||
} | ||
} | ||
|
||
fun Context.getDeviceSize(): IntArray { | ||
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
val windowMetrics = windowManager.currentWindowMetrics | ||
val windowInsets = windowMetrics.windowInsets | ||
|
||
val insets = windowInsets.getInsetsIgnoringVisibility( | ||
WindowInsets.Type.navigationBars() or WindowInsets.Type.displayCutout() | ||
) | ||
val insetsWidth = insets.right + insets.left | ||
val insetsHeight = insets.top + insets.bottom | ||
|
||
val bounds = windowMetrics.bounds | ||
|
||
return intArrayOf(bounds.width() - insetsWidth, bounds.height() - insetsHeight) | ||
} else { | ||
val display = windowManager.defaultDisplay | ||
val size = Point() | ||
|
||
display?.getSize(size) | ||
|
||
return intArrayOf(size.x, size.y) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
core/common/src/main/java/com/hmh/hamyeonham/common/fragment/FragmentExt.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.hmh.hamyeonham.common.fragment | ||
|
||
import android.view.View | ||
import android.widget.Toast | ||
import androidx.annotation.ColorRes | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.commit | ||
import androidx.lifecycle.lifecycleScope | ||
import com.google.android.material.snackbar.Snackbar | ||
|
||
fun Fragment.toast(message: String) { | ||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
fun Fragment.longToast(message: String) { | ||
Toast.makeText(requireContext(), message, Toast.LENGTH_LONG).show() | ||
} | ||
|
||
fun Fragment.snackBar(anchorView: View, message: () -> String) { | ||
Snackbar.make(anchorView, message(), Snackbar.LENGTH_SHORT).show() | ||
} | ||
|
||
fun Fragment.stringOf(@StringRes resId: Int, formatArgs: Any? = null) = getString(resId, formatArgs) | ||
|
||
fun Fragment.colorOf(@ColorRes resId: Int) = ContextCompat.getColor(requireContext(), resId) | ||
|
||
fun Fragment.drawableOf(@DrawableRes resId: Int) = | ||
ContextCompat.getDrawable(requireContext(), resId) | ||
|
||
fun Fragment.showLoading() { | ||
childFragmentManager.commit(allowStateLoss = true) { | ||
add(LoadingProgressIndicator.newInstance(), LoadingProgressIndicator.TAG) | ||
} | ||
} | ||
|
||
fun Fragment.hideLoading() { | ||
childFragmentManager.findFragmentByTag(LoadingProgressIndicator.TAG)?.let { fragment -> | ||
childFragmentManager.commit(allowStateLoss = true) { | ||
remove(fragment) | ||
} | ||
} | ||
} | ||
|
||
val Fragment.viewLifeCycle | ||
get() = viewLifecycleOwner.lifecycle | ||
|
||
val Fragment.viewLifeCycleScope | ||
get() = viewLifecycleOwner.lifecycleScope |
20 changes: 20 additions & 0 deletions
20
core/common/src/main/java/com/hmh/hamyeonham/common/image/BitampRequestBody.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,20 @@ | ||
package com.hmh.hamyeonham.common.image | ||
|
||
import android.graphics.Bitmap | ||
import okhttp3.MediaType | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.RequestBody | ||
import okio.BufferedSink | ||
|
||
class BitmapRequestBody( | ||
private val bitmap: Bitmap, | ||
private val bytes: Long, | ||
private val compressRate: Int = 100 | ||
) : RequestBody() { | ||
override fun contentLength() = bytes | ||
override fun contentType(): MediaType = "image/jpeg".toMediaType() | ||
|
||
override fun writeTo(sink: BufferedSink) { | ||
bitmap.compress(Bitmap.CompressFormat.JPEG, compressRate, sink.outputStream()) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
core/common/src/main/java/com/hmh/hamyeonham/common/image/ContentUriReqeustBody.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,77 @@ | ||
package com.hmh.hamyeonham.common.image | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import android.net.Uri | ||
import android.provider.MediaStore | ||
import okhttp3.MediaType | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody | ||
import okio.BufferedSink | ||
import java.io.ByteArrayOutputStream | ||
|
||
class ContentUriRequestBody( | ||
context: Context, | ||
private val uri: Uri? | ||
) : RequestBody() { | ||
private val contentResolver = context.contentResolver | ||
|
||
private var fileName = "" | ||
private var size = -1L | ||
private var compressedImage: ByteArray? = null | ||
|
||
init { | ||
if (uri != null) { | ||
contentResolver.query( | ||
uri, | ||
arrayOf(MediaStore.Images.Media.SIZE, MediaStore.Images.Media.DISPLAY_NAME), | ||
null, | ||
null, | ||
null | ||
)?.use { cursor -> | ||
if (cursor.moveToFirst()) { | ||
size = | ||
cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE)) | ||
fileName = | ||
cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME)) | ||
} | ||
} | ||
|
||
// Compress bitmap | ||
compressBitmap() | ||
} | ||
} | ||
|
||
private fun compressBitmap() { | ||
if (uri != null) { | ||
val originalBitmap = BitmapFactory.decodeStream(contentResolver.openInputStream(uri)) | ||
val outputStream = ByteArrayOutputStream() | ||
val imageSizeMb = size / (1024 * 1024.toDouble()) | ||
outputStream.use { | ||
val compressRate = ((3 / imageSizeMb) * 100).toInt() | ||
originalBitmap.compress( | ||
Bitmap.CompressFormat.JPEG, | ||
if (imageSizeMb >= 3) compressRate else 100, | ||
it | ||
) | ||
} | ||
compressedImage = outputStream.toByteArray() | ||
size = compressedImage?.size?.toLong() ?: -1L | ||
} | ||
} | ||
|
||
private fun getFileName() = fileName | ||
|
||
override fun contentLength(): Long = size | ||
|
||
override fun contentType(): MediaType? = | ||
uri?.let { contentResolver.getType(it)?.toMediaTypeOrNull() } | ||
|
||
override fun writeTo(sink: BufferedSink) { | ||
compressedImage?.let(sink::write) | ||
} | ||
|
||
fun toFormData(name: String) = MultipartBody.Part.createFormData(name, getFileName(), this) | ||
} |
Oops, something went wrong.