-
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 pull request #32 from MoyeoRun/feature/common-dialog
[#8] 기본 다이얼로그 추가
- Loading branch information
Showing
8 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/moyerun/moyeorun_android/common/dialog/RoundDialogFragment.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 com.moyerun.moyeorun_android.common.dialog | ||
|
||
import android.app.Dialog | ||
import android.graphics.Color | ||
import android.graphics.drawable.ColorDrawable | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.Window | ||
import androidx.fragment.app.DialogFragment | ||
import com.moyerun.moyeorun_android.common.extension.isActivityDestroyed | ||
|
||
open class RoundDialogFragment : DialogFragment() { | ||
|
||
private var dismissOnPause = false | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
super.onSaveInstanceState(outState) | ||
outState.putBoolean(SAVED_DISMISS_ON_PAUSE, dismissOnPause) | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
if (savedInstanceState != null) { | ||
dismissOnPause = savedInstanceState.getBoolean(SAVED_DISMISS_ON_PAUSE, false) | ||
} | ||
|
||
return object : Dialog(requireContext()) { | ||
override fun show() { | ||
if (context.isActivityDestroyed()) return | ||
super.show() | ||
} | ||
|
||
override fun dismiss() { | ||
if (context.isActivityDestroyed()) return | ||
super.dismiss() | ||
} | ||
}.apply { | ||
requestWindowFeature(Window.FEATURE_NO_TITLE) | ||
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) | ||
val contentView = onCreateView(LayoutInflater.from(context), null, savedInstanceState) | ||
if (contentView != null) { | ||
setContentView(contentView) | ||
} | ||
} | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
if (isCancelable && dismissOnPause) { | ||
dismiss() | ||
} | ||
} | ||
|
||
protected fun setDismissOnPause(dismissOnPause: Boolean) { | ||
this.dismissOnPause = dismissOnPause | ||
} | ||
|
||
companion object { | ||
private const val SAVED_DISMISS_ON_PAUSE = "dismissOnPause" | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/moyerun/moyeorun_android/common/extension/ContextExtension.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.moyerun.moyeorun_android.common.extension | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.content.Context | ||
import android.content.ContextWrapper | ||
|
||
fun Context.isActivityDestroyed(): Boolean { | ||
if (this is Application) return false | ||
val activity = getActivity()?: return true | ||
return activity.isFinishing || activity.isDestroyed | ||
} | ||
|
||
fun Context.getActivity(): Activity? { | ||
return when (this) { | ||
is Activity -> this | ||
is ContextWrapper -> baseContext.getActivity() | ||
else -> null | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/moyerun/moyeorun_android/common/extension/FragmentExtension.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,8 +1,22 @@ | ||
package com.moyerun.moyeorun_android.common.extension | ||
|
||
import android.widget.Toast | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentManager | ||
|
||
fun Fragment.toast(msg: String, isShort: Boolean = false) { | ||
Toast.makeText(context, msg, if (isShort) Toast.LENGTH_SHORT else Toast.LENGTH_LONG).show() | ||
} | ||
|
||
inline fun FragmentManager?.showAllowingStateLoss( | ||
tag: String?, | ||
dialogFragmentFactory: () -> DialogFragment | ||
) { | ||
if (this == null || isDestroyed) { | ||
return | ||
} | ||
val transaction = beginTransaction() | ||
transaction.add(dialogFragmentFactory(), tag) | ||
transaction.commitAllowingStateLoss() | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item> | ||
<shape android:shape="rectangle"> | ||
<corners android:radius="12dp" /> | ||
<solid android:color="@color/main_white" /> | ||
</shape> | ||
</item> | ||
</layer-list> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<resources> | ||
<string name="app_name">MoyeoRun-android</string> | ||
|
||
<!-- Common --> | ||
<string name="cancel">취소</string> | ||
<string name="ok">확인</string> | ||
|
||
</resources> |
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,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="Dialog" /> | ||
|
||
<style name="Dialog.Divider"> | ||
<item name="android:layout_width">match_parent</item> | ||
<item name="android:layout_height">1dp</item> | ||
<item name="android:background">@color/line_dialog_divider</item> | ||
</style> | ||
|
||
<style name="Dialog.Background"> | ||
<item name="android:layout_width">297dp</item> | ||
<item name="android:layout_height">wrap_content</item> | ||
<item name="android:background">@drawable/round_background_12</item> | ||
</style> | ||
|
||
<style name="Dialog.Title" parent="Widget.AppCompat.TextView"> | ||
<item name="android:textColor">@color/text_default_black</item> | ||
<item name="android:textSize">22dp</item> | ||
<item name="android:textStyle">bold</item> | ||
<item name="android:layout_gravity">center</item> | ||
<item name="android:gravity">center</item> | ||
</style> | ||
|
||
<style name="Dialog.Button" parent="Widget.AppCompat.Button"> | ||
<item name="android:minWidth">0dp</item> | ||
<item name="android:minHeight">0dp</item> | ||
<item name="android:paddingVertical">21dp</item> | ||
<item name="android:textSize">16dp</item> | ||
</style> | ||
|
||
<style name="Dialog.Button.Negative"> | ||
<item name="android:textColor">@color/text_default_black</item> | ||
</style> | ||
|
||
<style name="Dialog.Button.Positive"> | ||
<item name="android:textColor">@color/main_blue</item> | ||
</style> | ||
|
||
</resources> |